@koalaauto/agentchannel 3.36.1 → 3.36.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.
@@ -44,7 +44,17 @@ export interface CodexSandboxInput {
44
44
  tmpDir?: string;
45
45
  /** tests: take the roots as given (no real-path or existence lookup on this machine) */
46
46
  exists?: boolean;
47
+ /** the runner's files with secrets (secretPaths): denied where the whole disk is readable (Windows) */
48
+ denyRead?: string[];
49
+ /** the user's real home: its credential folders are denied where the whole disk is readable (Windows) */
50
+ realHome?: string;
51
+ platform?: NodeJS.Platform;
47
52
  }
53
+ /**
54
+ * What a Windows run may not read in the user's home: credentials of other tools, the user's own Codex and Claude config, and
55
+ * AgentChannel's home (every agent's key on this machine). Windows Codex reads the whole disk (below), so these are denied.
56
+ */
57
+ export declare const WINDOWS_HOME_DENY: string[];
48
58
  /**
49
59
  * The sandbox of every run but a `perm=full` work run, as Codex `--config` overrides: a permission profile (Codex >= 0.138)
50
60
  * matching what Claude runs get (claudePermOptions; the levels are in scope.ts). Live-tested with codex 0.165 on Linux.
@@ -1,5 +1,5 @@
1
1
  import { execFileSync } from 'node:child_process';
2
- import { closeSync, openSync, readdirSync, readSync, statSync } from 'node:fs';
2
+ import { closeSync, existsSync, openSync, readdirSync, readSync, statSync } from 'node:fs';
3
3
  import { join } from 'node:path';
4
4
  import { readable, systemPaths } from './scope.js';
5
5
  import { KILL_GRACE_MS } from './procgroup.js';
@@ -45,6 +45,14 @@ export function codexThreadOptions(perm, cwd, model, mode = 'work') {
45
45
  }
46
46
  /** The permission profile the runner defines for its runs (a name the user's own config does not use). */
47
47
  export const CODEX_PROFILE = 'agentchannel';
48
+ /**
49
+ * What a Windows run may not read in the user's home: credentials of other tools, the user's own Codex and Claude config, and
50
+ * AgentChannel's home (every agent's key on this machine). Windows Codex reads the whole disk (below), so these are denied.
51
+ */
52
+ export const WINDOWS_HOME_DENY = [
53
+ join('.config', 'agentchannel'), '.ssh', '.aws', '.azure', '.gnupg', '.kube', '.docker', join('.config', 'gh'), '.codex', '.claude', '.claude.json',
54
+ '.git-credentials', '.npmrc', '.netrc', join('AppData', 'Roaming', 'gh'), join('AppData', 'Roaming', 'GitHub CLI'),
55
+ ];
48
56
  function hostOf(url) {
49
57
  try {
50
58
  return url ? new URL(url).hostname.replace(/^\[|\]$/g, '').toLowerCase() : undefined;
@@ -73,13 +81,28 @@ function inlineTable(t) {
73
81
  export function codexSandboxOverrides(o) {
74
82
  const work = (o.mode ?? 'work') === 'work';
75
83
  const write = work && o.perm === 'workdir';
76
- const sys = o.systemRoots && o.systemDeny ? undefined : systemPaths();
77
- const roots = [...(o.readRoots ?? []), ...(o.systemRoots ?? sys.read)];
78
- const fs = { ':minimal': 'read' };
79
- for (const r of o.exists ? roots : readable(roots))
80
- fs[r] = 'read';
81
- for (const r of o.systemDeny ?? sys.deny)
82
- fs[r] = 'deny';
84
+ const fs = {};
85
+ if ((o.platform ?? process.platform) === 'win32') {
86
+ // Windows: Codex's elevated sandbox, the only one that limits reads, requires the whole disk readable (`:root`) and enforces
87
+ // denied paths instead (codex 0.165 validate_elevated_filesystem_policy: "requires effective `:root` read access"). So
88
+ // the disk is readable but the runner's secrets and the home's credential folders; a more specific path wins, so the
89
+ // read roots (the ach shim, attachments, linked repos) and the work directory stay readable inside a denied folder.
90
+ fs[':root'] = 'read';
91
+ const deny = [...(o.denyRead ?? []), ...(o.realHome ? WINDOWS_HOME_DENY.map((d) => join(o.realHome, d)) : [])];
92
+ for (const r of o.exists ? deny : deny.filter((p) => existsSync(p)))
93
+ fs[r] = 'deny';
94
+ for (const r of o.exists ? (o.readRoots ?? []) : readable(o.readRoots ?? []))
95
+ fs[r] = 'read';
96
+ }
97
+ else {
98
+ const sys = o.systemRoots && o.systemDeny ? undefined : systemPaths();
99
+ const roots = [...(o.readRoots ?? []), ...(o.systemRoots ?? sys.read)];
100
+ fs[':minimal'] = 'read';
101
+ for (const r of o.exists ? roots : readable(roots))
102
+ fs[r] = 'read';
103
+ for (const r of o.systemDeny ?? sys.deny)
104
+ fs[r] = 'deny';
105
+ }
83
106
  for (const r of o.tmpDir ? (o.exists ? [o.tmpDir] : readable([o.tmpDir])) : [])
84
107
  fs[r] = 'write';
85
108
  fs[':workspace_roots'] = { '.': write ? 'write' : 'read' };
@@ -291,6 +314,9 @@ export class CodexAdapter {
291
314
  tmpDir: opts.tmpDir,
292
315
  hub: opts.hub,
293
316
  netAllow: opts.netAllow,
317
+ // the run's own Codex home holds a link to the user's Codex login: never readable from inside (Windows reads the disk)
318
+ denyRead: [...(opts.denyReadPaths ?? []), ...(opts.env.CODEX_HOME ? [opts.env.CODEX_HOME] : [])],
319
+ realHome: opts.realHome,
294
320
  });
295
321
  const codex = new Codex(codexClientOptions(opts.env, sandbox));
296
322
  const thread = opts.resume ? codex.resumeThread(opts.resume, to) : codex.startThread(to);
@@ -75,8 +75,14 @@ export declare function onPath(name: string, env: NodeJS.ProcessEnv): string | u
75
75
  export declare function pkgFor(distro: string[] | undefined): PkgManager | undefined;
76
76
  /** Read the machine (Linux files; elsewhere only the platform matters). */
77
77
  export declare function detectHost(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): Host;
78
- /** The Codex CLI the runner's SDK uses (the @openai/codex package next to this CLI), else `codex` on PATH. */
79
- export declare function codexCommand(env?: NodeJS.ProcessEnv): string[] | undefined;
78
+ /**
79
+ * The Codex CLI the runner's SDK uses: the @openai/codex package found from @openai/codex-sdk, as the SDK finds it (npm may not
80
+ * place it next to this CLI), else `codex` on PATH. On Windows a PATH `codex.cmd` (an npm shim) is run as node and its script:
81
+ * Node cannot start a .cmd without a shell (spawn EINVAL, echo-duck-pr's startup check).
82
+ */
83
+ export declare function codexCommand(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): string[] | undefined;
84
+ /** `codex` on PATH; on Windows codex.exe, else an npm `codex.cmd` shim as node and its script (see codexCommand). */
85
+ export declare function codexOnPath(env: NodeJS.ProcessEnv, platform?: NodeJS.Platform): string[] | undefined;
80
86
  /** What a failed sandbox start said, as a problem. */
81
87
  export declare function classify(stderr: string, host: Host): SandboxProblem;
82
88
  export interface ProbeOptions {
@@ -4,6 +4,7 @@ import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'no
4
4
  import { createRequire } from 'node:module';
5
5
  import { homedir, tmpdir } from 'node:os';
6
6
  import { delimiter, dirname, join } from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
7
8
  import { codexSandboxOverrides } from './adapters/codex.js';
8
9
  import { linkWindowsSandbox, unlinkWindowsSandbox, WINDOWS_ELEVATED_CONFIG } from './codexhome.js';
9
10
  import { toolchainReadRoots } from './adapters/paths.js';
@@ -14,7 +15,9 @@ export const defaultRun = (file, args, opts) => new Promise((res) => {
14
15
  });
15
16
  });
16
17
  export function onPath(name, env) {
17
- for (const d of (env.PATH ?? '').split(delimiter)) {
18
+ // Windows spells it Path in a plain copy of the environment
19
+ const path = env.PATH ?? Object.entries(env).find(([k]) => k.toLowerCase() === 'path')?.[1] ?? '';
20
+ for (const d of path.split(delimiter)) {
18
21
  if (!d)
19
22
  continue;
20
23
  const f = join(d, name);
@@ -61,19 +64,39 @@ export function detectHost(env = process.env, platform = process.platform) {
61
64
  h.socat = onPath('socat', env);
62
65
  return h;
63
66
  }
64
- /** The Codex CLI the runner's SDK uses (the @openai/codex package next to this CLI), else `codex` on PATH. */
65
- export function codexCommand(env = process.env) {
66
- try {
67
- const req = createRequire(import.meta.url);
68
- const f = join(dirname(req.resolve('@openai/codex/package.json')), 'bin', 'codex.js');
69
- if (existsSync(f))
70
- return [process.execPath, f];
67
+ /**
68
+ * The Codex CLI the runner's SDK uses: the @openai/codex package found from @openai/codex-sdk, as the SDK finds it (npm may not
69
+ * place it next to this CLI), else `codex` on PATH. On Windows a PATH `codex.cmd` (an npm shim) is run as node and its script:
70
+ * Node cannot start a .cmd without a shell (spawn EINVAL, echo-duck-pr's startup check).
71
+ */
72
+ export function codexCommand(env = process.env, platform = process.platform) {
73
+ const from = [() => import.meta.url, () => fileURLToPath(import.meta.resolve('@openai/codex-sdk'))];
74
+ for (const base of from) {
75
+ try {
76
+ const f = join(dirname(createRequire(base()).resolve('@openai/codex/package.json')), 'bin', 'codex.js');
77
+ if (existsSync(f))
78
+ return [process.execPath, f];
79
+ }
80
+ catch {
81
+ /* not found from there */
82
+ }
71
83
  }
72
- catch {
73
- /* not installed next to us */
84
+ return codexOnPath(env, platform);
85
+ }
86
+ /** `codex` on PATH; on Windows codex.exe, else an npm `codex.cmd` shim as node and its script (see codexCommand). */
87
+ export function codexOnPath(env, platform = process.platform) {
88
+ if (platform !== 'win32') {
89
+ const p = onPath('codex', env);
90
+ return p ? [p] : undefined;
74
91
  }
75
- const p = onPath(process.platform === 'win32' ? 'codex.cmd' : 'codex', env);
76
- return p ? [p] : undefined;
92
+ const exe = onPath('codex.exe', env);
93
+ if (exe)
94
+ return [exe];
95
+ const shim = onPath('codex.cmd', env);
96
+ if (!shim)
97
+ return undefined;
98
+ const js = join(dirname(shim), 'node_modules', '@openai', 'codex', 'bin', 'codex.js');
99
+ return existsSync(js) ? [process.execPath, js] : [shim];
77
100
  }
78
101
  /** What a failed sandbox start said, as a problem. */
79
102
  export function classify(stderr, host) {
@@ -177,7 +200,7 @@ async function probe(tool, o) {
177
200
  codexHome = probeCodexHome(o.codexHome, platform);
178
201
  const cenv = { ...runEnv, CODEX_HOME: codexHome };
179
202
  // the work directory is the cwd; the sandbox is the one a work run gets (codexSandboxOverrides)
180
- r = await run(codex[0], [...codex.slice(1), 'sandbox', ...codexProbeConfig(dir, o.home, o.hub), '--', ...cmd], { env: cenv, cwd: dir });
203
+ r = await run(codex[0], [...codex.slice(1), 'sandbox', ...codexProbeConfig(dir, o.home, o.hub, platform), '--', ...cmd], { env: cenv, cwd: dir });
181
204
  if (r.code !== 0 && /unrecognized subcommand|unexpected argument|Usage: codex \[OPTIONS\]/i.test(r.stderr)) {
182
205
  return { tool, ok: true, unverified: true, detail: 'this Codex has no `codex sandbox` command' };
183
206
  }
@@ -214,8 +237,8 @@ async function probe(tool, o) {
214
237
  }
215
238
  }
216
239
  /** `-c` arguments for `codex sandbox`: the profile of a `workdir` work run in `dir` (with the toolchain: the network check runs node). */
217
- function codexProbeConfig(dir, home, hub) {
218
- return codexSandboxOverrides({ perm: 'workdir', mode: 'work', cwd: dir, readRoots: toolchainReadRoots(home), hub }).flatMap((c) => ['-c', c]);
240
+ function codexProbeConfig(dir, home, hub, platform = process.platform) {
241
+ return codexSandboxOverrides({ perm: 'workdir', mode: 'work', cwd: dir, readRoots: toolchainReadRoots(home), hub, realHome: home, platform }).flatMap((c) => ['-c', c]);
219
242
  }
220
243
  /**
221
244
  * A node one-liner: resolve `host` and open a TCP connection to `port`. Exit 0 connected, 5 the name does not resolve, 6 the
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "3.36.1";
1
+ export declare const VERSION = "3.36.3";
2
2
  /** The npm package (scripts/release.mjs keeps it and VERSION in step with package.json). */
3
3
  export declare const PKG_NAME = "@koalaauto/agentchannel";
4
4
  /**
@@ -1,4 +1,4 @@
1
- export const VERSION = '3.36.1';
1
+ export const VERSION = '3.36.3';
2
2
  /** The npm package (scripts/release.mjs keeps it and VERSION in step with package.json). */
3
3
  export const PKG_NAME = '@koalaauto/agentchannel';
4
4
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koalaauto/agentchannel",
3
- "version": "3.36.1",
3
+ "version": "3.36.3",
4
4
  "description": "Hand work between your team's agents (Claude Code, Codex) and follow it in one panel: the ach CLI, MCP server and runner for AgentChannel v2",
5
5
  "keywords": [
6
6
  "agentchannel",