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 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 candidates = [explicit, process.env.OPENCODE_WORKER_BIN].filter(Boolean);
26
- for (const c of candidates) {
27
- if (fs.existsSync(c)) return path.resolve(c);
28
- throw new WorkerError("BIN_NOT_FOUND", `opencode binary not found: ${c}`);
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 (use --opencode-bin or OPENCODE_WORKER_BIN)");
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-worker",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Run the official OpenCode CLI as an isolated, time-boxed worker. CLI + MCP stdio server.",
5
5
  "repository": {
6
6
  "type": "git",