@koalaauto/agentchannel 3.36.2 → 3.36.4
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
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
fs[
|
|
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);
|
|
@@ -81,6 +81,8 @@ export declare function detectHost(env?: NodeJS.ProcessEnv, platform?: NodeJS.Pl
|
|
|
81
81
|
* Node cannot start a .cmd without a shell (spawn EINVAL, echo-duck-pr's startup check).
|
|
82
82
|
*/
|
|
83
83
|
export declare function codexCommand(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): string[] | undefined;
|
|
84
|
+
/** The native Codex the SDK starts (@openai/codex-sdk findCodexPath): @openai/codex from the SDK, its platform package's binary. */
|
|
85
|
+
export declare function sdkCodexBinary(platform?: NodeJS.Platform, arch?: string): string | undefined;
|
|
84
86
|
/** `codex` on PATH; on Windows codex.exe, else an npm `codex.cmd` shim as node and its script (see codexCommand). */
|
|
85
87
|
export declare function codexOnPath(env: NodeJS.ProcessEnv, platform?: NodeJS.Platform): string[] | undefined;
|
|
86
88
|
/** What a failed sandbox start said, as a problem. */
|
package/dist/src/sandboxcheck.js
CHANGED
|
@@ -70,6 +70,10 @@ export function detectHost(env = process.env, platform = process.platform) {
|
|
|
70
70
|
* Node cannot start a .cmd without a shell (spawn EINVAL, echo-duck-pr's startup check).
|
|
71
71
|
*/
|
|
72
72
|
export function codexCommand(env = process.env, platform = process.platform) {
|
|
73
|
+
// first the very binary a run starts (the SDK's own lookup), so the check runs what the runs run
|
|
74
|
+
const native = sdkCodexBinary(platform);
|
|
75
|
+
if (native)
|
|
76
|
+
return [native];
|
|
73
77
|
const from = [() => import.meta.url, () => fileURLToPath(import.meta.resolve('@openai/codex-sdk'))];
|
|
74
78
|
for (const base of from) {
|
|
75
79
|
try {
|
|
@@ -83,6 +87,29 @@ export function codexCommand(env = process.env, platform = process.platform) {
|
|
|
83
87
|
}
|
|
84
88
|
return codexOnPath(env, platform);
|
|
85
89
|
}
|
|
90
|
+
const CODEX_TARGETS = {
|
|
91
|
+
'linux-x64': ['x86_64-unknown-linux-musl', '@openai/codex-linux-x64'],
|
|
92
|
+
'linux-arm64': ['aarch64-unknown-linux-musl', '@openai/codex-linux-arm64'],
|
|
93
|
+
'darwin-x64': ['x86_64-apple-darwin', '@openai/codex-darwin-x64'],
|
|
94
|
+
'darwin-arm64': ['aarch64-apple-darwin', '@openai/codex-darwin-arm64'],
|
|
95
|
+
'win32-x64': ['x86_64-pc-windows-msvc', '@openai/codex-win32-x64'],
|
|
96
|
+
'win32-arm64': ['aarch64-pc-windows-msvc', '@openai/codex-win32-arm64'],
|
|
97
|
+
};
|
|
98
|
+
/** The native Codex the SDK starts (@openai/codex-sdk findCodexPath): @openai/codex from the SDK, its platform package's binary. */
|
|
99
|
+
export function sdkCodexBinary(platform = process.platform, arch = process.arch) {
|
|
100
|
+
const t = CODEX_TARGETS[`${platform}-${arch}`];
|
|
101
|
+
if (!t)
|
|
102
|
+
return undefined;
|
|
103
|
+
try {
|
|
104
|
+
const codexPkg = createRequire(fileURLToPath(import.meta.resolve('@openai/codex-sdk'))).resolve('@openai/codex/package.json');
|
|
105
|
+
const vendor = join(dirname(createRequire(codexPkg).resolve(`${t[1]}/package.json`)), 'vendor');
|
|
106
|
+
const bin = join(vendor, t[0], 'bin', platform === 'win32' ? 'codex.exe' : 'codex');
|
|
107
|
+
return existsSync(bin) ? bin : undefined;
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
86
113
|
/** `codex` on PATH; on Windows codex.exe, else an npm `codex.cmd` shim as node and its script (see codexCommand). */
|
|
87
114
|
export function codexOnPath(env, platform = process.platform) {
|
|
88
115
|
if (platform !== 'win32') {
|
|
@@ -116,7 +143,9 @@ const PROBE_NOISE = /^warning\b|proceeding, even though/i;
|
|
|
116
143
|
function firstLine(s) {
|
|
117
144
|
const lines = s.split('\n').map((l) => l.trim()).filter(Boolean);
|
|
118
145
|
const real = lines.filter((l) => !PROBE_NOISE.test(l));
|
|
119
|
-
|
|
146
|
+
// a Node stack trace: the `Error: message` line, not the source line above it (`throw new Error(`)
|
|
147
|
+
const thrown = real.find((l) => /^(\w+)?Error\b[^(]*:\s*\S/.test(l));
|
|
148
|
+
return (thrown ?? real.find((l) => !/\bthrow\b|^at\s/.test(l) && /error|fail|denied|refus|cannot|not (found|permitted|allowed)|requires|missing/i.test(l)) ?? real[0] ?? lines[0] ?? '').slice(0, 300);
|
|
120
149
|
}
|
|
121
150
|
/**
|
|
122
151
|
* The two writes: inside the sandbox's directory (must work) and in the home directory (must be refused). With a third
|
|
@@ -200,7 +229,7 @@ async function probe(tool, o) {
|
|
|
200
229
|
codexHome = probeCodexHome(o.codexHome, platform);
|
|
201
230
|
const cenv = { ...runEnv, CODEX_HOME: codexHome };
|
|
202
231
|
// the work directory is the cwd; the sandbox is the one a work run gets (codexSandboxOverrides)
|
|
203
|
-
r = await run(codex[0], [...codex.slice(1), 'sandbox', ...codexProbeConfig(dir, o.home, o.hub), '--', ...cmd], { env: cenv, cwd: dir });
|
|
232
|
+
r = await run(codex[0], [...codex.slice(1), 'sandbox', ...codexProbeConfig(dir, o.home, o.hub, platform), '--', ...cmd], { env: cenv, cwd: dir });
|
|
204
233
|
if (r.code !== 0 && /unrecognized subcommand|unexpected argument|Usage: codex \[OPTIONS\]/i.test(r.stderr)) {
|
|
205
234
|
return { tool, ok: true, unverified: true, detail: 'this Codex has no `codex sandbox` command' };
|
|
206
235
|
}
|
|
@@ -237,8 +266,8 @@ async function probe(tool, o) {
|
|
|
237
266
|
}
|
|
238
267
|
}
|
|
239
268
|
/** `-c` arguments for `codex sandbox`: the profile of a `workdir` work run in `dir` (with the toolchain: the network check runs node). */
|
|
240
|
-
function codexProbeConfig(dir, home, hub) {
|
|
241
|
-
return codexSandboxOverrides({ perm: 'workdir', mode: 'work', cwd: dir, readRoots: toolchainReadRoots(home), hub }).flatMap((c) => ['-c', c]);
|
|
269
|
+
function codexProbeConfig(dir, home, hub, platform = process.platform) {
|
|
270
|
+
return codexSandboxOverrides({ perm: 'workdir', mode: 'work', cwd: dir, readRoots: toolchainReadRoots(home), hub, realHome: home, platform }).flatMap((c) => ['-c', c]);
|
|
242
271
|
}
|
|
243
272
|
/**
|
|
244
273
|
* A node one-liner: resolve `host` and open a TCP connection to `port`. Exit 0 connected, 5 the name does not resolve, 6 the
|
|
@@ -299,6 +328,15 @@ export const BWRAP_APPARMOR = `printf '%s\\n' 'abi <abi/4.0>,' 'include <tunable
|
|
|
299
328
|
/** The fix for a failed probe on this host. */
|
|
300
329
|
export function sandboxFix(st, host) {
|
|
301
330
|
const name = st.tool === 'claude' ? 'Claude Code' : 'Codex';
|
|
331
|
+
// the Codex package came without its platform binary (an optional dependency npm skipped): runs cannot start either
|
|
332
|
+
if (st.tool === 'codex' && /Missing optional dependency @openai\/codex-/i.test(st.detail ?? '')) {
|
|
333
|
+
const cmd = 'npm install -g @koalaauto/agentchannel@latest';
|
|
334
|
+
return {
|
|
335
|
+
en: `Codex's program for this system is missing from the install: run \`${cmd}\`, then restart the runner.`,
|
|
336
|
+
zh: `安装里缺少这个系统的 Codex 程序:执行 \`${cmd}\`,再重启 runner。`,
|
|
337
|
+
commands: [cmd],
|
|
338
|
+
};
|
|
339
|
+
}
|
|
302
340
|
// Windows Codex: the run's read limits need the elevated sandbox, set up once per user with administrator approval
|
|
303
341
|
if (st.tool === 'codex' && /requires the elevated Windows sandbox/i.test(st.detail ?? '')) {
|
|
304
342
|
const cmd = 'ach doctor --codex-sandbox-setup';
|
package/dist/src/version.d.ts
CHANGED
package/dist/src/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koalaauto/agentchannel",
|
|
3
|
-
"version": "3.36.
|
|
3
|
+
"version": "3.36.4",
|
|
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",
|