@sagentlab/navarch-runtime 0.1.54 → 0.1.55

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.
@@ -1,9 +1,14 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.openCodeAdapter = void 0;
4
7
  exports.runOpenCodeAdapter = runOpenCodeAdapter;
5
8
  const node_child_process_1 = require("node:child_process");
6
9
  const node_fs_1 = require("node:fs");
10
+ const node_os_1 = __importDefault(require("node:os"));
11
+ const node_path_1 = __importDefault(require("node:path"));
7
12
  const config_cjs_1 = require("../config.cjs");
8
13
  const kill_agent_cjs_1 = require("../kill-agent.cjs");
9
14
  /**
@@ -30,7 +35,7 @@ async function runOpenCodeAdapter(options) {
30
35
  };
31
36
  }
32
37
  const env = { ...options.env };
33
- await prepareOpenCodeConfig(options.mcpConfigPath, env);
38
+ await prepareOpenCodeConfig(options.mcpConfigPath, env, Boolean(options.dockerExec));
34
39
  const args = ["run", options.prompt];
35
40
  // Provider failures may only appear in logs, absent from assistant events.
36
41
  if (!hasArg(options.extraArgs, "--print-logs"))
@@ -57,7 +62,7 @@ async function runOpenCodeAdapter(options) {
57
62
  function hasArg(args, ...flags) {
58
63
  return args.some((arg) => flags.some((flag) => arg === flag || arg.startsWith(`${flag}=`)));
59
64
  }
60
- async function prepareOpenCodeConfig(mcpConfigPath, env) {
65
+ async function prepareOpenCodeConfig(mcpConfigPath, env, inDocker) {
61
66
  if (!mcpConfigPath) {
62
67
  throw new Error("OpenCode requires a per-session MCP config path for isolated execution.");
63
68
  }
@@ -101,6 +106,11 @@ async function prepareOpenCodeConfig(mcpConfigPath, env) {
101
106
  permissions: [
102
107
  { action: "*", resource: "*", effect: "allow" },
103
108
  { action: "external_directory", resource: "*", effect: "deny" },
109
+ ...(await openCodeManagedDirectories(env, inDocker)).map((resource) => ({
110
+ action: "external_directory",
111
+ resource,
112
+ effect: "allow",
113
+ })),
104
114
  { action: "question", resource: "*", effect: "deny" },
105
115
  ],
106
116
  };
@@ -117,6 +127,39 @@ async function prepareOpenCodeConfig(mcpConfigPath, env) {
117
127
  env.OPENCODE_DISABLE_PROJECT_CONFIG = "true";
118
128
  env.XDG_CONFIG_HOME = xdgConfigHome;
119
129
  }
130
+ /**
131
+ * OpenCode's own scratch locations: `os.tmpdir()/opencode` and the data dir's
132
+ * truncated tool-output and background-shell output files. OpenCode grants
133
+ * itself `external_directory` access to these, but config rules are appended
134
+ * after its grants and the last matching rule wins, so the blanket deny above
135
+ * would otherwise hide a background command's log from the agent. Inside the
136
+ * sandbox container the Linux defaults apply (`~` expands to the OpenCode
137
+ * process's home); on the host they follow the child environment, plus the
138
+ * canonical temp path since OpenCode canonicalizes before matching (macOS
139
+ * `/var` -> `/private/var`).
140
+ */
141
+ async function openCodeManagedDirectories(env, inDocker) {
142
+ if (inDocker) {
143
+ return [
144
+ "/tmp/opencode/*",
145
+ "~/.local/share/opencode/tool-output/*",
146
+ "~/.local/share/opencode/shell/*/*",
147
+ ];
148
+ }
149
+ const tmpRoot = env.TMPDIR || process.env.TMPDIR || node_os_1.default.tmpdir();
150
+ const tmpRoots = [tmpRoot, await node_fs_1.promises.realpath(tmpRoot).catch(() => tmpRoot)];
151
+ const dataHome = env.XDG_DATA_HOME ||
152
+ process.env.XDG_DATA_HOME ||
153
+ node_path_1.default.join(env.HOME || node_os_1.default.homedir(), ".local", "share");
154
+ const data = node_path_1.default.join(dataHome, "opencode");
155
+ return [
156
+ ...new Set([
157
+ ...tmpRoots.map((root) => node_path_1.default.join(root, "opencode", "*")),
158
+ node_path_1.default.join(data, "tool-output", "*"),
159
+ node_path_1.default.join(data, "shell", "*", "*"),
160
+ ]),
161
+ ];
162
+ }
120
163
  function safeEnvSegment(value) {
121
164
  return value.toUpperCase().replace(/[^A-Z0-9_]/g, "_");
122
165
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sagentlab/navarch-runtime",
3
- "version": "0.1.54",
3
+ "version": "0.1.55",
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",