@koalaauto/agentchannel 3.28.0 → 3.30.0

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.
@@ -25,8 +25,6 @@ export interface ClaudePermInput {
25
25
  readRoots?: string[];
26
26
  denyReadPaths?: string[];
27
27
  home?: string;
28
- /** B1: the AgentChannel home, denied to sandboxed commands (allowRead re-allows cwd and read roots). */
29
- achHome?: string;
30
28
  /** P2: hub `net_allow` of the agent; see sandboxNetwork(). */
31
29
  netAllow?: string[];
32
30
  /** program paths (default: systemPaths() of this machine) */
@@ -142,6 +142,8 @@ export function claudePermOptions(perm, o) {
142
142
  };
143
143
  const common = {
144
144
  ...base,
145
+ // pre-approved at every level: without that, Claude Code does not offer Glob and Grep to the model at workdir (live
146
+ // test). The PreToolUse hook checks them; the SDK's notice that canUseTool is shadowed for them is expected.
145
147
  allowedTools: ['Read', 'Glob', 'Grep', ...achTools],
146
148
  sandbox,
147
149
  hooks: { PreToolUse: [pathPolicyHook(pol)] },
@@ -236,7 +238,6 @@ export class ClaudeAdapter {
236
238
  readRoots: opts.readRoots,
237
239
  denyReadPaths: opts.denyReadPaths,
238
240
  home: opts.realHome ?? opts.env.HOME,
239
- achHome: opts.achHome,
240
241
  tmpDir: opts.tmpDir,
241
242
  netAllow: opts.netAllow,
242
243
  }),
@@ -55,9 +55,19 @@ function darwinUserTemp() {
55
55
  * command; live test, macOS 26). The real binaries in <dir>/usr/bin run clean, so agents get that directory on PATH.
56
56
  * Undefined elsewhere, or when the tools are not installed.
57
57
  */
58
- export function developerDir(platform = process.platform, run = () => execFileSync('xcode-select', ['-p'], { encoding: 'utf8', timeout: 5000 }), exists = existsSync) {
58
+ export function developerDir(platform = process.platform, run, exists = existsSync) {
59
59
  if (platform !== 'darwin')
60
60
  return undefined;
61
+ // this machine's answer, once: the runner asks for every run
62
+ if (!run && devDirCache)
63
+ return devDirCache.value;
64
+ const v = devDirOf(run ?? (() => execFileSync('xcode-select', ['-p'], { encoding: 'utf8', timeout: 5000 })), exists);
65
+ if (!run)
66
+ devDirCache = { value: v };
67
+ return v;
68
+ }
69
+ let devDirCache;
70
+ function devDirOf(run, exists) {
61
71
  try {
62
72
  const d = run().trim();
63
73
  return d && exists(`${d}/usr/bin/git`) ? d : undefined;
@@ -27,8 +27,6 @@ export interface AdapterRunOptions {
27
27
  * scratch dir, so path policies use this one.
28
28
  */
29
29
  realHome?: string;
30
- /** B1: the AgentChannel home (~/.config/agentchannel): denied to the sandbox except the read roots under it. */
31
- achHome?: string;
32
30
  /** Paths the agent must never read (runner config / state with secrets). */
33
31
  denyReadPaths?: string[];
34
32
  /** Readable besides cwd and program paths: toolchain, git common dir, attachments, linked repos (see readRoots()). */
package/dist/src/cli.js CHANGED
@@ -1644,6 +1644,18 @@ async function runCommand(p, io) {
1644
1644
  publicUrl: env.ACH_PUBLIC_URL || undefined,
1645
1645
  onClientTooOld: () => void updater?.nudge(),
1646
1646
  passEnv: (Array.isArray(v['pass-env']) ? v['pass-env'] : []).flatMap(splitList),
1647
+ startInfo: await (async () => {
1648
+ const { startedByService } = await import('./servicefix.js');
1649
+ const service = !startedByService(me.name, process.platform, env) ? '' : process.platform === 'darwin' ? 'launchd' : 'systemd';
1650
+ return {
1651
+ dir,
1652
+ ...(env.AGENTCHANNEL_HOME ? { home: home } : {}),
1653
+ ...(Object.keys(repoFlags).length ? { repos: repoFlags } : {}),
1654
+ ...(v['interactive-first'] ? { interactive_first: true } : {}),
1655
+ service,
1656
+ ...(service === 'systemd' ? { linger: lingers(env) } : {}),
1657
+ };
1658
+ })(),
1647
1659
  baseEnv: (() => {
1648
1660
  const shim = writeAchShim(home);
1649
1661
  // macOS: the real git and python3 of the developer tools before the /usr/bin shims (scope.ts developerDir)
@@ -1839,7 +1851,7 @@ async function installService(p, io, o) {
1839
1851
  const linger = platform === 'linux' && load && !failed ? lingers(env) : true;
1840
1852
  const logs = platform === 'linux' ? `journalctl --user -u ${basename(f.path)} -f` : join(o.home, 'logs', 'runner.log');
1841
1853
  if (v.json) {
1842
- io.out(JSON.stringify({ path: f.path, started: load && !failed, ...(failed ? { error: failed } : {}), start: f.start, stop: f.stop, retired, ...(kept.length ? { kept } : {}) }, null, 2));
1854
+ io.out(JSON.stringify({ path: f.path, started: load && !failed, ...(failed ? { error: failed } : {}), start: f.start, stop: f.stop, retired, ...(kept.length ? { kept } : {}), ...(linger ? {} : { linger: false }) }, null, 2));
1843
1855
  return failed ? 1 : 0;
1844
1856
  }
1845
1857
  io.out([
@@ -427,12 +427,13 @@ export declare class Client {
427
427
  release(taskId: string, reason: string, run_id?: string): Promise<any>;
428
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
429
  reportRepos(repos: string[]): Promise<any>;
430
- /** How this runner runs tasks: its --perm, the tool, and the NAMES of the variables it hands its agents (never values). */
430
+ /** How this runner runs tasks: its --perm, the tool, and the NAMES of the variables it hands its agents (never values); and how
431
+ * it was started (directory, home, --repo paths, its supervisor), which the owner's page turns into the line that restarts it. */
431
432
  reportRunner(r: {
432
433
  perm: string;
433
434
  runtime: string;
434
435
  pass_env: string[];
435
- }): Promise<any>;
436
+ } & Partial<import('./runner/runner.js').RunnerStartInfo>): Promise<any>;
436
437
  reportSetup(sandbox: {
437
438
  tool: string;
438
439
  problem: string;
@@ -375,7 +375,8 @@ export class Client {
375
375
  async reportRepos(repos) {
376
376
  return this.ach('PUT', '/me/repos', { repos });
377
377
  }
378
- /** How this runner runs tasks: its --perm, the tool, and the NAMES of the variables it hands its agents (never values). */
378
+ /** How this runner runs tasks: its --perm, the tool, and the NAMES of the variables it hands its agents (never values); and how
379
+ * it was started (directory, home, --repo paths, its supervisor), which the owner's page turns into the line that restarts it. */
379
380
  async reportRunner(r) {
380
381
  return this.ach('PUT', '/me/runner', r);
381
382
  }
@@ -118,3 +118,5 @@ export interface SetupResult {
118
118
  }
119
119
  /** Run (or, with --dry-run, only print) the setup after `ach join`. */
120
120
  export declare function runSetup(io: SetupIo, o: SetupOptions): Promise<SetupResult>;
121
+ /** The Linux command that lets a user's services outlive their logins. */
122
+ export declare const LINGER_CMD = "sudo loginctl enable-linger \"$USER\"";
@@ -212,7 +212,7 @@ export async function runSetup(io, o) {
212
212
  continue;
213
213
  }
214
214
  if (s.id === 'service') {
215
- const ok = await installService(io, s.commands[0]);
215
+ const ok = await installService(io, s.commands[0], zh, !!o.yes);
216
216
  (ok ? result.ran : result.failed).push('service');
217
217
  continue;
218
218
  }
@@ -261,7 +261,7 @@ async function fixSandbox(io, s, before, probe, zh) {
261
261
  return ok;
262
262
  }
263
263
  /** `ach run --install-service --json`: it writes the unit and starts it (not under ACH_SERVICE_DIR: tests). */
264
- async function installService(io, argv) {
264
+ async function installService(io, argv, zh = false, yes = false) {
265
265
  const r = await io.exec(argv[0], [...argv.slice(1), '--json'], io.env);
266
266
  let f = {};
267
267
  try {
@@ -276,8 +276,39 @@ async function installService(io, argv) {
276
276
  return false;
277
277
  }
278
278
  io.out(f.started ? ` installed and started ${f.path}` : ` wrote ${f.path}; start it with: ${(f.start ?? []).join(' && ')}`);
279
+ if (f.linger === false)
280
+ await keepAfterLogout(io, zh, yes);
279
281
  return true;
280
282
  }
283
+ /** The Linux command that lets a user's services outlive their logins. */
284
+ export const LINGER_CMD = 'sudo loginctl enable-linger "$USER"';
285
+ /**
286
+ * Linux: a user service stops when that user's last login ends (an SSH session closing) unless the user lingers. The runner
287
+ * then stops with it and nobody notices until tasks pile up (2026-11-10). In a terminal: ask, then run it there (sudo asks for
288
+ * the password); with no terminal (an agent ran the join line) only say it: sudo would wait for a password nobody can type.
289
+ */
290
+ async function keepAfterLogout(io, zh, yes) {
291
+ const why = zh
292
+ ? ' 注意:这台 Linux 机器上,你退出登录(比如关掉 SSH)后后台运行器会跟着停掉。'
293
+ : ' Note: on this Linux machine the background runner stops when you log out (an SSH session closing).';
294
+ // no terminal to type a sudo password in (an agent ran the line): say it, run nothing
295
+ if (!io.runTty || (!io.ask && !yes)) {
296
+ io.out(`${why}\n ${zh ? '让它一直运行:' : 'To keep it running:'} ${LINGER_CMD}`);
297
+ return;
298
+ }
299
+ // --yes: the line was the consent, as for the other steps
300
+ if (!yes) {
301
+ const q = zh ? '现在让它在退出登录后也继续运行?会运行(可能要输入你的系统密码):' : 'Keep it running after you log out? This runs (it may ask for your password):';
302
+ if (!yesNo(await io.ask(`${why}\n ${q}\n ${LINGER_CMD}\n [Y/n] `))) {
303
+ io.out(` ${zh ? '跳过了。之后要开启:' : 'Skipped. Later:'} ${LINGER_CMD}`);
304
+ return;
305
+ }
306
+ }
307
+ else
308
+ io.out(`${why}\n ${zh ? '运行:' : 'Running:'} ${LINGER_CMD}`);
309
+ const code = await io.runTty(LINGER_CMD);
310
+ io.out(code === 0 ? (zh ? ' 好了:退出登录后它也会继续运行。' : ' Done: it keeps running after you log out.') : ` failed (exit ${code}): ${LINGER_CMD}`);
311
+ }
281
312
  /** --dry-run: print what would be run (nothing is run, not even read-only probes). */
282
313
  function printOnly(io, d, plan, o) {
283
314
  const zh = o.zh;
@@ -28,6 +28,11 @@ export interface RunnerOptions {
28
28
  cfSecret?: string;
29
29
  /** Extra env var names passed to spawned agents (`--pass-env`). */
30
30
  passEnv?: string[];
31
+ /**
32
+ * How this runner was started, for the owner's page: the panel turns it into the one line that brings a stopped runner back
33
+ * (paths and flags, never a command line: a key that leaked must not be able to put a command in front of the owner).
34
+ */
35
+ startInfo?: RunnerStartInfo;
31
36
  baseEnv?: NodeJS.ProcessEnv;
32
37
  log?: (s: string) => void;
33
38
  newRunId?: () => string;
@@ -55,6 +60,19 @@ export interface RunnerOptions {
55
60
  /** A machine that checked out is checked again this often (default 6 h), so a login that expired is found before a task is taken. */
56
61
  okRecheckMs?: number;
57
62
  }
63
+ export interface RunnerStartInfo {
64
+ /** --dir, absolute. */
65
+ dir: string;
66
+ /** AGENTCHANNEL_HOME when it is not the default home. */
67
+ home?: string;
68
+ /** --repo name=path given on the command line (config.json's repos need nothing). */
69
+ repos?: Record<string, string>;
70
+ interactive_first?: boolean;
71
+ /** The supervisor that started this process: it brings the runner back after updates and reboots. '' = started by hand. */
72
+ service: 'systemd' | 'launchd' | '';
73
+ /** Linux service whose user does not linger: it stops when that user's last login ends (an SSH session). */
74
+ linger?: boolean;
75
+ }
58
76
  export type Job = {
59
77
  kind: 'work';
60
78
  taskId: string;
@@ -454,7 +454,7 @@ export class Runner {
454
454
  return;
455
455
  }
456
456
  try {
457
- await this.o.client.reportRunner({ perm: this.o.perm, runtime, pass_env: [...new Set(this.o.passEnv ?? [])] });
457
+ await this.o.client.reportRunner({ perm: this.o.perm, runtime, pass_env: [...new Set(this.o.passEnv ?? [])], ...(this.o.startInfo ?? {}) });
458
458
  this.runnerReported = true;
459
459
  }
460
460
  catch (e) {
@@ -1221,7 +1221,7 @@ export class Runner {
1221
1221
  const home = (this.o.baseEnv ?? process.env).HOME;
1222
1222
  return [
1223
1223
  ...toolchainReadRoots(home || undefined),
1224
- ...(developerDir() ? [developerDir()] : []),
1224
+ ...[developerDir()].filter((d) => !!d),
1225
1225
  ...gitCommonDir(cwd),
1226
1226
  join(this.o.home, 'bin'),
1227
1227
  ...readRepos.flatMap((r) => r.roots),
@@ -1325,7 +1325,6 @@ export class Runner {
1325
1325
  hub: this.o.hub,
1326
1326
  denyReadPaths: secretPaths(this.o.home),
1327
1327
  ...(realHome ? { realHome } : {}),
1328
- achHome: this.o.home,
1329
1328
  // from the run's scratch HOME only its git identity: the runtime's own config there is for the tool, which runs outside
1330
1329
  // the sandbox, and a read-only HOME would cover its writable TMPDIR inside it
1331
1330
  readRoots: [...this.readRoots(rec.workdir, rec.readRepos, rec.taskId), ...(env.HOME ? [join(env.HOME, '.gitconfig')] : [])],
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "3.28.0";
1
+ export declare const VERSION = "3.30.0";
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.28.0';
1
+ export const VERSION = '3.30.0';
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.28.0",
3
+ "version": "3.30.0",
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",