@koalaauto/agentchannel 3.26.7 → 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}` +
@@ -20,6 +20,8 @@ export interface Agent {
20
20
  former_names?: string[];
21
21
  /** P2: domains the agent's sandbox may reach ("*" = any; admin-only). */
22
22
  net_allow?: string[];
23
+ /** The repo names its runner can work in, as the runner reported them (empty: never reported). */
24
+ repos?: string[];
23
25
  }
24
26
  export interface Task {
25
27
  id: string;
@@ -423,6 +425,8 @@ export declare class Client {
423
425
  traces(taskId: string): Promise<any>;
424
426
  /** The worker cannot run on its machine (not logged in, sandbox broken): the task goes back to submitted, not failed. */
425
427
  release(taskId: string, reason: string, run_id?: string): Promise<any>;
428
+ /** The repo names this runner can work in (never local paths): the directory shows them, and the hub refuses a task for another repo. */
429
+ reportRepos(repos: string[]): Promise<any>;
426
430
  reportSetup(sandbox: {
427
431
  tool: string;
428
432
  problem: string;
@@ -371,6 +371,10 @@ export class Client {
371
371
  async release(taskId, reason, run_id) {
372
372
  return this.ach('POST', `/tasks/${enc(taskId)}/release`, { reason, ...(run_id ? { run_id } : {}) });
373
373
  }
374
+ /** The repo names this runner can work in (never local paths): the directory shows them, and the hub refuses a task for another repo. */
375
+ async reportRepos(repos) {
376
+ return this.ach('PUT', '/me/repos', { repos });
377
+ }
374
378
  async reportSetup(sandbox) {
375
379
  return this.ach('PUT', '/me/setup', { sandbox });
376
380
  }
@@ -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)) {
package/dist/src/mcp.js CHANGED
@@ -178,7 +178,7 @@ export function buildMcpServer(client, o = {}) {
178
178
  }
179
179
  return task.run_id;
180
180
  }
181
- server.registerTool('list_agents', { description: 'List the team\'s agents (name, owner, runtime, what they are good at). Use it to pick who to hand work to.', inputSchema: {} }, async () => wrap(() => client.agents()));
181
+ server.registerTool('list_agents', { description: 'List the team\'s agents (name, owner, runtime, what they are good at, the repos their runner works in). Use it to pick who to hand work to; a task\'s repo must be one of the receiver\'s repos when it lists any.', inputSchema: {} }, async () => wrap(() => client.agents()));
182
182
  server.registerTool('send_task', {
183
183
  description: `Hand a piece of work to another agent as a task. The receiving agent is woken on its machine (or its owner picks it up interactively) and works in a fresh git worktree. ${TASK_FIELDS_HELP} ${HANDOFF_HELP}`,
184
184
  inputSchema: {
@@ -4,7 +4,7 @@ import { type Perm } from '../perm.js';
4
4
  import { RunnerState } from './state.js';
5
5
  import type { Workspace } from './workspace.js';
6
6
  import { type SandboxStatus } from '../sandboxcheck.js';
7
- export type RunnerClient = Pick<Client, 'me' | 'inbox' | 'claim' | 'getTask' | 'postMessage' | 'complete' | 'fail' | 'usage' | 'heartbeat' | 'answerRun' | 'endRun'> & Partial<Pick<Client, 'download' | 'channelPosts' | 'mentionRun' | 'mentionEnd' | 'mentionUsage' | 'promptSize' | 'reportSetup' | 'release' | 'putTrace'>>;
7
+ export type RunnerClient = Pick<Client, 'me' | 'inbox' | 'claim' | 'getTask' | 'postMessage' | 'complete' | 'fail' | 'usage' | 'heartbeat' | 'answerRun' | 'endRun'> & Partial<Pick<Client, 'download' | 'channelPosts' | 'mentionRun' | 'mentionEnd' | 'mentionUsage' | 'promptSize' | 'reportSetup' | 'reportRepos' | 'release' | 'putTrace'>>;
8
8
  export interface RunnerOptions {
9
9
  client: RunnerClient;
10
10
  adapter: RuntimeAdapter;
@@ -192,6 +192,11 @@ export declare class Runner {
192
192
  tick(): Promise<void>;
193
193
  /** design §27: probe the sandbox when due, tell the hub when the answer changes; true = take nothing new. */
194
194
  private sandboxBlocked;
195
+ /** Tell the hub which repo names this runner knows, so a task for another repo is refused when it is sent. Tried on every
196
+ * poll until the hub has it: a hub that was unreachable at start would otherwise keep the previous list until a restart. */
197
+ private reposReported;
198
+ private reportRepos;
199
+ private reposLogged;
195
200
  private notifyBudget;
196
201
  /**
197
202
  * Cancel running jobs whose task went terminal; forget parked runs of
@@ -411,6 +411,32 @@ export class Runner {
411
411
  }
412
412
  return !st.ok;
413
413
  }
414
+ /** Tell the hub which repo names this runner knows, so a task for another repo is refused when it is sent. Tried on every
415
+ * poll until the hub has it: a hub that was unreachable at start would otherwise keep the previous list until a restart. */
416
+ reposReported = false;
417
+ async reportRepos() {
418
+ if (this.reposReported)
419
+ return;
420
+ const names = this.o.workspace.repoNames?.();
421
+ if (!names?.length || !this.o.client.reportRepos) {
422
+ this.reposReported = true;
423
+ return;
424
+ }
425
+ try {
426
+ await this.o.client.reportRepos(names);
427
+ this.reposReported = true;
428
+ }
429
+ catch (e) {
430
+ // an older hub without /me/repos: nothing is checked there, which is how it was
431
+ if (e instanceof HubError && e.status === 404)
432
+ this.reposReported = true;
433
+ else if (!this.reposLogged) {
434
+ this.reposLogged = true;
435
+ this.log(`repos report: ${e?.message ?? e} (trying again with the next poll)`);
436
+ }
437
+ }
438
+ }
439
+ reposLogged = false;
414
440
  async notifyBudget(t, me) {
415
441
  if (this.state.runs.budgetNotified[t.id])
416
442
  return;
@@ -1421,6 +1447,7 @@ export class Runner {
1421
1447
  while (!this.stopped) {
1422
1448
  let wait = this.o.intervalMs;
1423
1449
  try {
1450
+ await this.reportRepos();
1424
1451
  await this.tick();
1425
1452
  }
1426
1453
  catch (e) {
@@ -15,6 +15,8 @@ export interface Workspace {
15
15
  * task's links.base adds or changes relative to the runner's HEAD.
16
16
  */
17
17
  sensitiveChanges?(task: Task): Promise<string[]>;
18
+ /** The repo names a task may name (links.repo, links.repos): the runner tells the hub, which refuses others when sent. */
19
+ repoNames?(): string[];
18
20
  /**
19
21
  * Cross-repo: the task's links.repos (besides the primary repo), made readable.
20
22
  * Unknown names throw (the task fails with the message).
@@ -41,6 +43,7 @@ export declare class GitWorkspace implements Workspace {
41
43
  constructor(dir: string, home: string, log?: (s: string) => void, repos?: Record<string, string>);
42
44
  /** The local repo a task works in (P3). */
43
45
  repoDir(task: Task): string;
46
+ repoNames(): string[];
44
47
  /** Map a repo name to its local path, or fail with the names this runner knows. */
45
48
  lookup(r: unknown, what: string): string;
46
49
  /** Where read-only checkouts of a task's other repos go (next to, not inside, its worktree). */
@@ -65,6 +65,9 @@ export class GitWorkspace {
65
65
  return this.dir;
66
66
  return this.lookup(r, 'links.repo');
67
67
  }
68
+ repoNames() {
69
+ return [...new Set([...Object.keys(this.repos), basename(this.dir)])].filter((n) => REPO_NAME_RE.test(n)).sort();
70
+ }
68
71
  /** Map a repo name to its local path, or fail with the names this runner knows. */
69
72
  lookup(r, what) {
70
73
  if (typeof r !== 'string' || !REPO_NAME_RE.test(r))
@@ -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.26.7";
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.26.7';
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.26.7",
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",