@koalaauto/agentchannel 3.27.0 → 3.27.1

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/dist/src/cli.js CHANGED
@@ -1655,7 +1655,7 @@ async function runCommand(p, io) {
1655
1655
  if (runtime === 'kiro')
1656
1656
  return (await import('./kirocheck.js')).probeKiro({ env });
1657
1657
  const { probeEnvironment } = await import('./envcheck.js');
1658
- return probeEnvironment(runtime === 'codex' ? 'codex' : 'claude', { env });
1658
+ return probeEnvironment(runtime === 'codex' ? 'codex' : 'claude', { env, hub: cfg.hub });
1659
1659
  },
1660
1660
  });
1661
1661
  io.err(`ach run: agent ${me.name}, runtime ${runtime}, perm min(${me.perm_level}, ${perm}), dir ${dir}` +
@@ -52,6 +52,7 @@ export declare function runDoctor(o: {
52
52
  /** the sandbox probe (tests) */
53
53
  sandbox?: (tool: 'claude' | 'codex', o: {
54
54
  env: NodeJS.ProcessEnv;
55
+ hub?: string;
55
56
  }) => Promise<import('./sandboxcheck.js').SandboxStatus>;
56
57
  /** Tests: the kiro runtime's machine check (kiro-cli and KIRO_API_KEY). */
57
58
  kiro?: (o: {
@@ -313,10 +313,10 @@ export async function runDoctor(o) {
313
313
  const { probeSandbox } = await import('./sandboxcheck.js');
314
314
  const tools = runtime === 'kiro' ? [] : runtime === 'codex' ? ['codex'] : runtime === 'claude' ? ['claude'] : [...(claude ? ['claude'] : []), ...(codexPath || bundled ? ['codex'] : [])];
315
315
  for (const t of tools) {
316
- const st = await (o.sandbox ?? probeSandbox)(t, { env });
316
+ const st = await (o.sandbox ?? probeSandbox)(t, { env, hub: cfg.hub });
317
317
  const name = `${t} sandbox`;
318
318
  if (st.ok)
319
- add(name, st.unverified ? 'info' : 'ok', st.unverified ? `not checked: ${st.detail ?? 'unknown'}` : 'starts, and stops writes outside the task directory');
319
+ add(name, st.unverified ? 'info' : 'ok', st.unverified ? `not checked: ${st.detail ?? 'unknown'}` : `starts, and stops writes outside the task directory${t === 'codex' && cfg.hub ? ', and reaches the hub' : ''}`);
320
320
  else
321
321
  add(name, runtime ? 'fail' : 'warn', `${st.fix?.en ?? st.detail ?? st.problem}${runtime ? ' The background runner takes no tasks until this is fixed.' : ''}`, 'machine', st.fix?.commands.length ? st.fix.commands.join('\n ') : st.fix?.en);
322
322
  }
@@ -54,6 +54,8 @@ export declare function userBin(name: string, env?: NodeJS.ProcessEnv): string |
54
54
  export declare function onPath(name: string, env?: NodeJS.ProcessEnv): boolean;
55
55
  /** This CLI's entry file (dist/src/cli.js). */
56
56
  export declare function thisCliPath(): string;
57
+ /** The CLI a runner shim (writeAchShim in cli.ts) runs, or undefined when `f` is not such a shim. */
58
+ export declare function shimTarget(f: string): string | undefined;
57
59
  /**
58
60
  * Which AgentChannel an `ach` executable is, without running it: follow the
59
61
  * symlink (npm global bins are symlinks) up to the nearest package.json.
@@ -1,4 +1,4 @@
1
- import { accessSync, constants, readFileSync, realpathSync } from 'node:fs';
1
+ import { accessSync, constants, readFileSync, realpathSync, statSync } from 'node:fs';
2
2
  import { delimiter, dirname, join } from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  import { PKG_NAME, VERSION } from './version.js';
@@ -125,6 +125,22 @@ export function onPath(name, env = process.env) {
125
125
  export function thisCliPath() {
126
126
  return fileURLToPath(new URL('./cli.js', import.meta.url));
127
127
  }
128
+ /** The CLI a runner shim (writeAchShim in cli.ts) runs, or undefined when `f` is not such a shim. */
129
+ export function shimTarget(f) {
130
+ let s;
131
+ try {
132
+ if (statSync(f).size > 4096)
133
+ return undefined; // a shim is one line; never read a large binary
134
+ s = readFileSync(f, 'utf8');
135
+ }
136
+ catch {
137
+ return undefined;
138
+ }
139
+ // `exec '<node>' '<cli.js>' "$@"`, both single-quoted by shq ('\'' for a quote inside)
140
+ const q = `'((?:[^']|'\\\\'')*)'`;
141
+ const m = new RegExp(`^#!/bin/sh\\nexec ${q} ${q} "\\$@"\\n?$`).exec(s);
142
+ return m ? m[2].replace(/'\\''/g, "'") : undefined;
143
+ }
128
144
  function real(p) {
129
145
  try {
130
146
  return realpathSync(p);
@@ -139,7 +155,10 @@ function real(p) {
139
155
  * `ours` = it is this very CLI.
140
156
  */
141
157
  export function identifyAch(path, self = thisCliPath()) {
142
- const r = real(path);
158
+ // the runner's PATH shim (writeAchShim: `exec <node> <cli.js>`) is that CLI: identify its target, not the script
159
+ const sh = real(path);
160
+ const target = sh ? shimTarget(sh) : undefined;
161
+ const r = target ? real(target) : sh;
143
162
  const ours = !!r && r === real(self);
144
163
  let d = r ? dirname(r) : undefined;
145
164
  for (let i = 0; d && i < 6; i++, d = dirname(d)) {
@@ -24,6 +24,8 @@ export type SandboxProblem =
24
24
  | 'unsupported'
25
25
  /** the tool is not logged in on this machine (envcheck.ts): not the sandbox, but the same "takes no tasks" state */
26
26
  | 'not-logged-in'
27
+ /** Codex's sandbox starts but has no network although the runner asks for it: the agent's `ach` cannot reach the hub (`detail`: the host) */
28
+ | 'no-network'
27
29
  /** anything else: `detail` has the first line of the error */
28
30
  | 'failed';
29
31
  export interface SandboxFix {
@@ -86,9 +88,16 @@ export interface ProbeOptions {
86
88
  home?: string;
87
89
  /** the Codex CLI (default: codexCommand()) */
88
90
  codex?: string[];
91
+ /** the hub URL: when set, a Codex probe also checks that a sandboxed command reaches it (work runs call `ach` from there) */
92
+ hub?: string;
89
93
  }
90
94
  /** Probe `tool`'s sandbox on this machine. Never throws. */
91
95
  export declare function probeSandbox(tool: SandboxTool, o?: ProbeOptions): Promise<SandboxStatus>;
96
+ /**
97
+ * A node one-liner: resolve `host` and open a TCP connection to `port`. Exit 0 connected, 5 the name does not resolve, 6 the
98
+ * connection fails or takes over 8 s. No HTTP: what matters is whether the sandbox lets the agent's `ach` out at all.
99
+ */
100
+ export declare const NET_SCRIPT: string;
92
101
  /** Lets the system bubblewrap (only that path) create user namespaces under Ubuntu's AppArmor rule; never machine-wide. */
93
102
  export declare const BWRAP_APPARMOR: string;
94
103
  /** The fix for a failed probe on this host. */
@@ -100,7 +100,7 @@ export async function probeSandbox(tool, o = {}) {
100
100
  const platform = o.platform ?? process.platform;
101
101
  const host = o.host ?? detectHost(env, platform);
102
102
  const run = o.run ?? defaultRun;
103
- const st = await probe(tool, { env, platform, host, run, home: o.home ?? homedir(), codex: o.codex });
103
+ const st = await probe(tool, { env, platform, host, run, home: o.home ?? homedir(), codex: o.codex, hub: o.hub });
104
104
  if (!st.ok)
105
105
  st.fix = sandboxFix(st, host);
106
106
  return st;
@@ -130,6 +130,7 @@ async function probe(tool, o) {
130
130
  const sh = ['/bin/sh', '-c', probeScript(), 'probe', dir, outside];
131
131
  try {
132
132
  let r;
133
+ let codex;
133
134
  if (tool === 'claude' && platform === 'linux') {
134
135
  // what Claude Code's sandbox does: a new session, no network, the filesystem read-only except the work directory
135
136
  r = await run(host.bwrap, ['--new-session', '--die-with-parent', '--unshare-net', '--ro-bind', '/', '/', '--dev', '/dev', '--proc', '/proc', '--bind', dir, dir, '--', ...sh], { env });
@@ -140,7 +141,7 @@ async function probe(tool, o) {
140
141
  r = await run('/usr/bin/sandbox-exec', ['-p', profile, ...sh], { env });
141
142
  }
142
143
  else {
143
- const codex = o.codex ?? codexCommand(env);
144
+ codex = o.codex ?? codexCommand(env);
144
145
  if (!codex)
145
146
  return { tool, ok: true, unverified: true, detail: 'Codex was not found' };
146
147
  const cmd = platform === 'win32' ? ['cmd', '/c', `type nul > "${join(dir, 'ok')}" && (type nul > "${outside}" && exit 4 || exit 0)`] : sh;
@@ -152,8 +153,9 @@ async function probe(tool, o) {
152
153
  }
153
154
  if (existsSync(outside) || r.code === 4)
154
155
  return { tool, ok: false, problem: 'not-enforced', detail: `a sandboxed command could write ${outside}` };
156
+ // await: the finally below removes `dir`, the network check's cwd
155
157
  if (r.code === 0 && existsSync(join(dir, 'ok')))
156
- return { tool, ok: true };
158
+ return codex && o.hub ? await probeNetwork(tool, codex, o.hub, dir, run, env) : { tool, ok: true };
157
159
  const err = `${r.stderr}\n${r.stdout}`;
158
160
  if (r.code === 127 && platform === 'linux' && tool === 'claude')
159
161
  return { tool, ok: false, problem: 'missing', missing: ['bubblewrap'] };
@@ -164,6 +166,44 @@ async function probe(tool, o) {
164
166
  rmSync(outside, { force: true });
165
167
  }
166
168
  }
169
+ /**
170
+ * A node one-liner: resolve `host` and open a TCP connection to `port`. Exit 0 connected, 5 the name does not resolve, 6 the
171
+ * connection fails or takes over 8 s. No HTTP: what matters is whether the sandbox lets the agent's `ach` out at all.
172
+ */
173
+ export const NET_SCRIPT = "const[h,p]=process.argv.slice(1);require('dns').lookup(h,(e)=>{if(e)process.exit(5);" +
174
+ "const s=require('net').connect(+p,h,()=>process.exit(0));s.on('error',()=>process.exit(6));setTimeout(()=>process.exit(6),8000)})";
175
+ const PROXY_VARS = ['HTTPS_PROXY', 'https_proxy', 'HTTP_PROXY', 'http_proxy', 'ALL_PROXY', 'all_proxy'];
176
+ /**
177
+ * Work runs keep Codex's network on (codexThreadOptions) because the agent reports through `ach`. Codex settings on the machine
178
+ * can still turn it off (live: TASK-20, every `ach complete` failed with EAI_AGAIN and the task failed without its result).
179
+ * Connect to the hub from inside `codex sandbox` with the runner's network setting; compare with the same check outside, so a
180
+ * hub that is down or a machine that is offline is not blamed on the sandbox. Behind a proxy a direct connection proves
181
+ * nothing, so it is not checked.
182
+ */
183
+ async function probeNetwork(tool, codex, hub, dir, run, env) {
184
+ let host;
185
+ let port;
186
+ try {
187
+ const u = new URL(hub);
188
+ host = u.hostname.replace(/^\[|\]$/g, '');
189
+ port = u.port || (u.protocol === 'http:' ? '80' : '443');
190
+ }
191
+ catch {
192
+ return { tool, ok: true };
193
+ }
194
+ if (PROXY_VARS.some((k) => env[k]))
195
+ return { tool, ok: true, unverified: true, detail: 'a proxy is set: the sandbox network was not checked' };
196
+ const check = [process.execPath, '-e', NET_SCRIPT, host, port];
197
+ const outside = await run(check[0], check.slice(1), { env });
198
+ if (outside.code !== 0)
199
+ return { tool, ok: true, unverified: true, detail: `${host} is not reachable from this machine either: the sandbox network was not checked` };
200
+ const inside = await run(codex[0], [...codex.slice(1), 'sandbox', '-c', 'sandbox_mode="workspace-write"', '-c', 'sandbox_workspace_write.network_access=true', '--', ...check], { env, cwd: dir });
201
+ if (inside.code === 0)
202
+ return { tool, ok: true };
203
+ if (inside.code === 5 || inside.code === 6)
204
+ return { tool, ok: false, problem: 'no-network', detail: host };
205
+ return { tool, ok: true, unverified: true, detail: `the sandbox network check did not run: ${firstLine(`${inside.stderr}\n${inside.stdout}`) || `exit ${inside.code}`}` };
206
+ }
167
207
  const INSTALL = {
168
208
  apt: (p) => `sudo apt-get install -y ${p.join(' ')}`,
169
209
  dnf: (p) => `sudo dnf install -y ${p.join(' ')}`,
@@ -196,6 +236,18 @@ export function sandboxFix(st, host) {
196
236
  zh: '这台机器的内核不允许用户命名空间,沙箱需要它。请让管理这台机器的人开启(user.max_user_namespaces)。',
197
237
  commands: [],
198
238
  };
239
+ case 'no-network': {
240
+ const h = st.detail ?? 'the hub';
241
+ return {
242
+ en: `${name}'s sandbox has no network on this machine, so the agent's \`ach\` cannot reach ${h} and every task fails without its result. ` +
243
+ `The runner asks Codex for network; a Codex setting here turns it off: check ~/.codex/config.toml and requirements.toml ` +
244
+ `(default_permissions, [permissions.*.network], sandbox_workspace_write.network_access), then run \`ach doctor\`.`,
245
+ zh: `${name} 的沙箱在这台机器上没有网络,智能体的 \`ach\` 连不上 ${h},每个任务都会失败且交不回结果。` +
246
+ `runner 已经要求 Codex 打开网络,是本机的 Codex 设置把它关了:检查 ~/.codex/config.toml 和 requirements.toml` +
247
+ `(default_permissions、[permissions.*.network]、sandbox_workspace_write.network_access),改完再运行 \`ach doctor\`。`,
248
+ commands: [],
249
+ };
250
+ }
199
251
  case 'not-enforced':
200
252
  return { en: `${name}'s sandbox started but did not stop a write outside its directory: do not run this agent here.`, zh: `${name} 的沙箱能启动,但没有拦住目录外的写入:不要在这台机器上运行这个智能体。`, commands: [] };
201
253
  case 'missing':
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "3.27.0";
1
+ export declare const VERSION = "3.27.1";
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.27.0';
1
+ export const VERSION = '3.27.1';
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.27.0",
3
+ "version": "3.27.1",
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",