forge-delegate 1.0.8 → 1.0.9
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/lib.mjs +20 -0
- package/package.json +1 -1
package/lib.mjs
CHANGED
|
@@ -25,6 +25,25 @@ export function detectOpencode() {
|
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
// The startup warning on stderr is easy for an MCP client to swallow, and a v1
|
|
29
|
+
// binary does not fail loudly: `run` reads the v2 flags as a help request and
|
|
30
|
+
// exits 0. Check once per process, then refuse to spawn instead of returning
|
|
31
|
+
// "(no output)" and letting it look like the model had nothing to say.
|
|
32
|
+
let opencodeGate;
|
|
33
|
+
function requireOpencodeV2() {
|
|
34
|
+
opencodeGate ??= detectOpencode();
|
|
35
|
+
return opencodeGate.then((oc) => {
|
|
36
|
+
if (!oc.found)
|
|
37
|
+
throw new Error("opencode not found on PATH — install it from https://opencode.ai");
|
|
38
|
+
if (!oc.supported)
|
|
39
|
+
throw new Error(
|
|
40
|
+
`opencode ${oc.version?.raw ?? "(unknown version)"} is too old — forge-delegate requires opencode 2 or newer ` +
|
|
41
|
+
`(v2 removed the CLI flags it uses). Run: opencode upgrade`
|
|
42
|
+
);
|
|
43
|
+
return oc;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
28
47
|
const CONFIG_DIR = join(homedir(), ".forge-delegate");
|
|
29
48
|
const AUTH_PATH = join(homedir(), ".local/share/opencode/auth.json");
|
|
30
49
|
const OPENCODE_CONFIG_PATH = join(homedir(), ".config/opencode/opencode.json");
|
|
@@ -191,6 +210,7 @@ export function parseEvents(stdout) {
|
|
|
191
210
|
}
|
|
192
211
|
|
|
193
212
|
export async function opencodeRun(model, prompt, opts = {}) {
|
|
213
|
+
await requireOpencodeV2();
|
|
194
214
|
const started = Date.now();
|
|
195
215
|
const variant = opts.variant ?? (await pickVariant(model));
|
|
196
216
|
const timeoutMs = opts.timeoutMs ?? OPENCODE_TIMEOUT;
|
package/package.json
CHANGED