@sagentlab/navarch-runtime 0.1.57 → 0.1.58

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.
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.openCodeAdapter = void 0;
7
7
  exports.runOpenCodeAdapter = runOpenCodeAdapter;
8
+ exports.resetOpenCodeLogLevelCache = resetOpenCodeLogLevelCache;
8
9
  const node_child_process_1 = require("node:child_process");
9
10
  const node_fs_1 = require("node:fs");
10
11
  const node_os_1 = __importDefault(require("node:os"));
@@ -36,12 +37,15 @@ async function runOpenCodeAdapter(options) {
36
37
  }
37
38
  const env = { ...options.env };
38
39
  await prepareOpenCodeConfig(options.mcpConfigPath, env, Boolean(options.dockerExec));
40
+ const binaryKey = `${options.dockerExec ? "docker:" : ""}${options.bin ?? "opencode"}`;
41
+ const defaultLogLevel = !hasArg(options.extraArgs, "--log-level");
42
+ const logLevel = defaultLogLevel ? (openCodeLogLevels.get(binaryKey) ?? "ERROR") : null;
39
43
  const args = ["run", options.prompt];
40
44
  // Provider failures may only appear in logs, absent from assistant events.
41
45
  if (!hasArg(options.extraArgs, "--print-logs"))
42
46
  args.push("--print-logs");
43
- if (!hasArg(options.extraArgs, "--log-level"))
44
- args.push("--log-level", "ERROR");
47
+ if (logLevel)
48
+ args.push("--log-level", logLevel);
45
49
  if (!hasArg(options.extraArgs, "--format"))
46
50
  args.push("--format", "json");
47
51
  args.push(...options.extraArgs);
@@ -54,11 +58,33 @@ async function runOpenCodeAdapter(options) {
54
58
  args.push("--model", options.reasoningEffort ? `${options.model}#${options.reasoningEffort}` : options.model);
55
59
  }
56
60
  const runOptions = { ...options, env };
57
- const raw = runOptions.dockerExec
58
- ? await runViaDocker(runOptions, args)
59
- : await runOnHost(runOptions, args);
61
+ const run = (runArgs) => runOptions.dockerExec ? runViaDocker(runOptions, runArgs) : runOnHost(runOptions, runArgs);
62
+ let raw = await run(args);
63
+ if (logLevel && raw.exitCode !== 0 && isLogLevelRejection(raw.stderr)) {
64
+ // The CLI rejected our default before starting any work, so one retry with
65
+ // the other spelling is side-effect free. Remember what this binary takes.
66
+ const alternate = logLevel === "ERROR" ? "error" : "ERROR";
67
+ args[args.indexOf("--log-level") + 1] = alternate;
68
+ raw = await run(args);
69
+ if (!(raw.exitCode !== 0 && isLogLevelRejection(raw.stderr))) {
70
+ openCodeLogLevels.set(binaryKey, alternate);
71
+ }
72
+ }
60
73
  return attachOpenCodeOutput(raw);
61
74
  }
75
+ /**
76
+ * OpenCode V1 (yargs) and 2.0.x up to at least 2.0.6 accept only `ERROR`;
77
+ * later V2 releases (Effect CLI, e.g. 2.0.17) accept only `error`. Neither
78
+ * accepts both, so the adapter learns the spelling per binary.
79
+ */
80
+ const openCodeLogLevels = new Map();
81
+ function isLogLevelRejection(stderr) {
82
+ return /invalid value/i.test(stderr) && /--log-level|argument: log-level/i.test(stderr);
83
+ }
84
+ /** Test hook: forget learned log-level spellings. */
85
+ function resetOpenCodeLogLevelCache() {
86
+ openCodeLogLevels.clear();
87
+ }
62
88
  function hasArg(args, ...flags) {
63
89
  return args.some((arg) => flags.some((flag) => arg === flag || arg.startsWith(`${flag}=`)));
64
90
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sagentlab/navarch-runtime",
3
- "version": "0.1.57",
3
+ "version": "0.1.58",
4
4
  "description": "Navarch machine-side session manager: claims delivery tasks and runs them through local coding agents.",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",