opencode-worker 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/lib/worker.mjs +11 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,8 @@ Run the official OpenCode CLI as an isolated, time-boxed worker. One package, tw
|
|
|
5
5
|
- `opencode-worker run` — CLI, prints one JSON result
|
|
6
6
|
- `opencode-worker mcp` — MCP stdio server (async jobs)
|
|
7
7
|
|
|
8
|
-
No dependencies. Node ≥ 20. OpenCode is **not** bundled: pass `--opencode-bin`, set `OPENCODE_WORKER_BIN`, or have `opencode` on `PATH
|
|
8
|
+
No dependencies. Node ≥ 20. OpenCode is **not** bundled: pass `--opencode-bin`, set `OPENCODE_WORKER_BIN`, or have `opencode` on `PATH` (checked in that order).
|
|
9
|
+
A set-but-empty `--opencode-bin`/`OPENCODE_WORKER_BIN` fails with `BIN_EMPTY` instead of falling back to `PATH`; this usually means a shell variable was not expanded in your MCP config.
|
|
9
10
|
|
|
10
11
|
## Safety defaults
|
|
11
12
|
|
package/lib/worker.mjs
CHANGED
|
@@ -22,14 +22,20 @@ export class WorkerError extends Error {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export function resolveOpencodeBin(explicit) {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
const sources = [
|
|
26
|
+
["--opencode-bin", explicit],
|
|
27
|
+
["OPENCODE_WORKER_BIN", process.env.OPENCODE_WORKER_BIN],
|
|
28
|
+
];
|
|
29
|
+
for (const [name, value] of sources) {
|
|
30
|
+
if (value === undefined || value === null) continue;
|
|
31
|
+
// A set-but-empty value is almost always an unexpanded shell variable; never fall back to PATH silently.
|
|
32
|
+
if (value.trim() === "") throw new WorkerError("BIN_EMPTY", `${name} is set but empty; give the absolute path to the opencode binary`);
|
|
33
|
+
if (!fs.existsSync(value)) throw new WorkerError("BIN_NOT_FOUND", `opencode binary not found at ${name}=${value}`);
|
|
34
|
+
return path.resolve(value);
|
|
29
35
|
}
|
|
30
36
|
const which = spawnSync("/usr/bin/env", ["which", "opencode"], { encoding: "utf8" });
|
|
31
37
|
if (which.status === 0 && which.stdout.trim()) return which.stdout.trim();
|
|
32
|
-
throw new WorkerError("BIN_NOT_FOUND", "opencode not found (
|
|
38
|
+
throw new WorkerError("BIN_NOT_FOUND", "opencode not found on PATH (set OPENCODE_WORKER_BIN or --opencode-bin)");
|
|
33
39
|
}
|
|
34
40
|
|
|
35
41
|
function opencodeVersion(bin) {
|