Skip to content

Commit a676630

Browse files
author
chenbo
committed
Treat missing sidecar plugin as doctor warning
1 parent 868a34d commit a676630

2 files changed

Lines changed: 43 additions & 6 deletions

File tree

src/cli/opencode-plusplus-commands.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,28 @@ export async function runOpenCodePlusplusDoctor(repo = "."): Promise<OpenCodePlu
7272
const sidecarPluginCheck = sidecar.checks.find((check) => check.name.endsWith("opencode-plusplus.ts"));
7373
const pluginPath = path.join(root, OPENCODE_SIDECAR_PLUGIN_PATH);
7474
const versionCheck = buildOpenCodePlusplusVersionCheck(pluginPath);
75+
const pluginExists = existsSync(pluginPath);
76+
const hookChecks = sidecar.checks.filter((check) => ["file.edited hook", "session.idle hook", "tool.execute.after hook"].includes(check.name));
7577
const sidecarChecks: OpencodeDoctorCheck[] = [
7678
versionCheck,
7779
{
7880
id: "sidecar-plugin",
7981
label: "OpenCode++ sidecar plugin",
80-
status: sidecarPluginCheck?.status === "pass" ? "pass" : "fail",
81-
details: sidecarPluginCheck?.details ?? "sidecar plugin check unavailable"
82+
status: sidecarPluginCheck?.status === "pass" ? "pass" : pluginExists ? "fail" : "warn",
83+
details:
84+
sidecarPluginCheck?.status === "pass"
85+
? sidecarPluginCheck.details
86+
: pluginExists
87+
? (sidecarPluginCheck?.details ?? "sidecar plugin check unavailable")
88+
: `not generated yet; run \`opencode-plusplus\` to create ${OPENCODE_SIDECAR_PLUGIN_PATH}`
8289
},
8390
{
8491
id: "sidecar-hooks",
8592
label: "Sidecar hooks",
86-
status: sidecar.checks.filter((check) => ["file.edited hook", "session.idle hook"].includes(check.name)).every((check) => check.status === "pass")
87-
? "pass"
88-
: "fail",
89-
details: "checks file.edited and session.idle hooks"
93+
status: pluginExists ? (hookChecks.length > 0 && hookChecks.every((check) => check.status === "pass") ? "pass" : "fail") : "warn",
94+
details: pluginExists
95+
? "checks file.edited, session.idle, and tool.execute.after hooks"
96+
: "plugin not generated yet; hooks unavailable until first launch"
9097
},
9198
{
9299
id: "sidecar-latest",

test/opencode-launcher.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,36 @@ test("OpenCode++ doctor reports CLI/plugin version consistency", async () => {
176176
}
177177
});
178178

179+
test("OpenCode++ doctor treats a missing sidecar plugin as first-run warning", async () => {
180+
const root = mkdtempSync(path.join(tmpdir(), "opencode-plusplus-doctor-first-run-"));
181+
const bin = path.join(root, "bin");
182+
const oldPath = process.env.PATH;
183+
try {
184+
mkdirSync(bin, { recursive: true });
185+
writeFakeOpenCode(bin);
186+
process.env.PATH = `${bin}${path.delimiter}${oldPath ?? ""}`;
187+
mkdirSync(path.join(root, ".agent-context"), { recursive: true });
188+
writeFileSync(path.join(root, "package.json"), JSON.stringify({ scripts: { test: "node -e 1" } }), "utf8");
189+
runGit(root, ["init"]);
190+
runGit(root, ["checkout", "-b", "main"]);
191+
runGit(root, ["config", "user.email", "opencode-plusplus@example.com"]);
192+
runGit(root, ["config", "user.name", "OpenCode Plus Plus"]);
193+
runGit(root, ["add", "."]);
194+
runGit(root, ["commit", "-m", "initial"]);
195+
196+
const report = await runOpenCodePlusplusDoctor(root);
197+
198+
assert.equal(report.checks.filter((check) => check.id.startsWith("sidecar-") && check.status === "fail").length, 0);
199+
assert.equal(report.checks.find((check) => check.id === "opencode-plusplus-version")?.status, "warn");
200+
assert.equal(report.checks.find((check) => check.id === "sidecar-plugin")?.status, "warn");
201+
assert.equal(report.checks.find((check) => check.id === "sidecar-hooks")?.status, "warn");
202+
assert.match(report.checks.find((check) => check.id === "sidecar-plugin")?.details ?? "", /run `opencode-plusplus`/);
203+
} finally {
204+
process.env.PATH = oldPath;
205+
rmSync(root, { recursive: true, force: true });
206+
}
207+
});
208+
179209
test("OpenCode sidecar records tool execution evidence into event logs and traces", () => {
180210
const root = mkdtempSync(path.join(tmpdir(), "opencode-plusplus-sidecar-record-tool-"));
181211
try {

0 commit comments

Comments
 (0)