@koalaauto/agentchannel 3.35.0 → 3.35.2

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
@@ -18,6 +18,7 @@ export { VERSION } from './version.js';
18
18
  import { VERSION } from './version.js';
19
19
  import { bootGuard, markHealthy, SelfUpdater, superviseSelf, UPDATE_EXIT_CODE } from './selfupdate.js';
20
20
  import { installProxy } from './netproxy.js';
21
+ import { inheritedEnv } from './env.js';
21
22
  /** At a terminal, a command that replaces an agent's key says what that cuts off and asks (default no). --yes skips it; scripts are not asked. */
22
23
  async function confirmKeyRotation(io, v, agentName) {
23
24
  if (!io.ask || v.yes || v.json)
@@ -1630,6 +1631,14 @@ async function runCommand(p, io) {
1630
1631
  throw new UsageError(`run: ${e.message}`);
1631
1632
  }
1632
1633
  // keeps this runner on the hub's release: waits for the runs in flight, installs, exits UPDATE_EXIT_CODE so the service restarts
1634
+ const passEnv = (Array.isArray(v['pass-env']) ? v['pass-env'] : []).flatMap(splitList);
1635
+ const baseEnv = (() => {
1636
+ const shim = writeAchShim(home);
1637
+ // macOS: the real git and python3 of the developer tools before the /usr/bin shims (scope.ts developerDir)
1638
+ const dev = developerDir();
1639
+ const path = [shim, dev ? `${dev}/usr/bin` : undefined, env.PATH].filter(Boolean).join(delimiter);
1640
+ return shim || dev ? { ...env, PATH: path } : env;
1641
+ })();
1633
1642
  const runner = new Runner({
1634
1643
  client: c,
1635
1644
  adapter,
@@ -1647,7 +1656,7 @@ async function runCommand(p, io) {
1647
1656
  secrets: [cfg.key ?? ''].filter(Boolean),
1648
1657
  publicUrl: env.ACH_PUBLIC_URL || undefined,
1649
1658
  onClientTooOld: () => void updater?.nudge(),
1650
- passEnv: (Array.isArray(v['pass-env']) ? v['pass-env'] : []).flatMap(splitList),
1659
+ passEnv,
1651
1660
  startInfo: await (async () => {
1652
1661
  const { startedByService } = await import('./servicefix.js');
1653
1662
  const service = !startedByService(me.name, process.platform, env) ? '' : process.platform === 'darwin' ? 'launchd' : 'systemd';
@@ -1660,20 +1669,15 @@ async function runCommand(p, io) {
1660
1669
  ...(service === 'systemd' ? { linger: lingers(env) } : {}),
1661
1670
  };
1662
1671
  })(),
1663
- baseEnv: (() => {
1664
- const shim = writeAchShim(home);
1665
- // macOS: the real git and python3 of the developer tools before the /usr/bin shims (scope.ts developerDir)
1666
- const dev = developerDir();
1667
- const path = [shim, dev ? `${dev}/usr/bin` : undefined, env.PATH].filter(Boolean).join(delimiter);
1668
- return shim || dev ? { ...env, PATH: path } : env;
1669
- })(),
1672
+ baseEnv,
1670
1673
  log: io.err,
1671
1674
  sandboxCheck: async () => {
1672
1675
  // kiro runs in Kiro's cloud sandbox: what this machine needs is kiro-cli and its key
1673
1676
  if (runtime === 'kiro')
1674
1677
  return (await import('./kirocheck.js')).probeKiro({ env });
1675
1678
  const { probeEnvironment } = await import('./envcheck.js');
1676
- return probeEnvironment(runtime === 'codex' ? 'codex' : 'claude', { env, hub: cfg.hub });
1679
+ // the sandboxed command gets the vars a run gets, so one a run cannot start without shows here (TASK-59)
1680
+ return probeEnvironment(runtime === 'codex' ? 'codex' : 'claude', { env, hub: cfg.hub, runEnv: inheritedEnv(baseEnv, passEnv) });
1677
1681
  },
1678
1682
  });
1679
1683
  io.err(`ach run: agent ${me.name}, runtime ${runtime}, perm min(${me.perm_level}, ${perm}), dir ${dir}` +
package/dist/src/env.d.ts CHANGED
@@ -6,6 +6,13 @@ export declare const STRIPPED_ENV: readonly ["CLAUDECODE", "CLAUDE_CODE_SESSION_
6
6
  * sockets) is dropped unless the runner names it with `--pass-env NAME`.
7
7
  */
8
8
  export declare const ENV_ALLOWLIST: readonly ["PATH", "HOME", "LANG", "TERM", "SHELL", "USER", "TMPDIR"];
9
+ /**
10
+ * Windows adds the system vars programs cannot start without: Codex's sandbox
11
+ * refuses to start with no LOCALAPPDATA (TASK-59), cmd needs ComSpec and
12
+ * SystemRoot, PATHEXT finds `.cmd` shims. No secrets among them. USERPROFILE,
13
+ * TEMP and TMP are set to the run's scratch home by prepareAgentHome.
14
+ */
15
+ export declare const WINDOWS_ENV_ALLOWLIST: readonly ["SystemRoot", "SystemDrive", "windir", "ComSpec", "PATHEXT", "OS", "LOCALAPPDATA", "APPDATA", "ProgramData", "ProgramFiles", "ProgramFiles(x86)", "ProgramW6432", "CommonProgramFiles", "CommonProgramFiles(x86)", "CommonProgramW6432", "USERNAME", "USERDOMAIN", "COMPUTERNAME", "NUMBER_OF_PROCESSORS", "PROCESSOR_ARCHITECTURE", "PSModulePath"];
9
16
  /**
10
17
  * Never passed, even with --pass-env: runner credentials and the Claude Code
11
18
  * nesting / messaging / socket / host-auth vars of the parent session.
@@ -28,4 +35,9 @@ export interface AgentEnvInput {
28
35
  passEnv?: string[];
29
36
  }
30
37
  /** Env for a spawned agent: allowlisted parent vars + --pass-env names + task-scoped ACH vars. */
31
- export declare function buildAgentEnv(base: NodeJS.ProcessEnv | Record<string, string | undefined>, a: AgentEnvInput): Record<string, string>;
38
+ /**
39
+ * The parent vars a spawned agent inherits: the allowlist, the platform's system vars and the --pass-env names. The runner's
40
+ * startup check runs the runtime with these too, so a var a run cannot do without fails there, not in the first task (TASK-59).
41
+ */
42
+ export declare function inheritedEnv(base: NodeJS.ProcessEnv | Record<string, string | undefined>, passEnv?: string[], platform?: NodeJS.Platform): Record<string, string>;
43
+ export declare function buildAgentEnv(base: NodeJS.ProcessEnv | Record<string, string | undefined>, a: AgentEnvInput, platform?: NodeJS.Platform): Record<string, string>;
package/dist/src/env.js CHANGED
@@ -12,6 +12,28 @@ export const STRIPPED_ENV = [
12
12
  * sockets) is dropped unless the runner names it with `--pass-env NAME`.
13
13
  */
14
14
  export const ENV_ALLOWLIST = ['PATH', 'HOME', 'LANG', 'TERM', 'SHELL', 'USER', 'TMPDIR'];
15
+ /**
16
+ * Windows adds the system vars programs cannot start without: Codex's sandbox
17
+ * refuses to start with no LOCALAPPDATA (TASK-59), cmd needs ComSpec and
18
+ * SystemRoot, PATHEXT finds `.cmd` shims. No secrets among them. USERPROFILE,
19
+ * TEMP and TMP are set to the run's scratch home by prepareAgentHome.
20
+ */
21
+ export const WINDOWS_ENV_ALLOWLIST = [
22
+ 'SystemRoot', 'SystemDrive', 'windir', 'ComSpec', 'PATHEXT', 'OS',
23
+ 'LOCALAPPDATA', 'APPDATA', 'ProgramData', 'ProgramFiles', 'ProgramFiles(x86)', 'ProgramW6432',
24
+ 'CommonProgramFiles', 'CommonProgramFiles(x86)', 'CommonProgramW6432',
25
+ 'USERNAME', 'USERDOMAIN', 'COMPUTERNAME', 'NUMBER_OF_PROCESSORS', 'PROCESSOR_ARCHITECTURE', 'PSModulePath',
26
+ ];
27
+ /** Windows env names ignore case (`Path`): the exact name first, then any spelling. */
28
+ function lookup(base, k, win) {
29
+ if (base[k] !== undefined || !win)
30
+ return base[k];
31
+ const lower = k.toLowerCase();
32
+ for (const [name, v] of Object.entries(base))
33
+ if (v !== undefined && name.toLowerCase() === lower)
34
+ return v;
35
+ return undefined;
36
+ }
15
37
  /**
16
38
  * Never passed, even with --pass-env: runner credentials and the Claude Code
17
39
  * nesting / messaging / socket / host-auth vars of the parent session.
@@ -26,14 +48,23 @@ export function neverPass(name) {
26
48
  return /^CLAUDE_CODE_.*(SESSION|ENTRYPOINT|EXECPATH|SSE|PORT|SOCK|IPC|MESSAG|HOST|OAUTH|TOKEN|AUTH|BRIDGE|REMOTE)/.test(name);
27
49
  }
28
50
  /** Env for a spawned agent: allowlisted parent vars + --pass-env names + task-scoped ACH vars. */
29
- export function buildAgentEnv(base, a) {
51
+ /**
52
+ * The parent vars a spawned agent inherits: the allowlist, the platform's system vars and the --pass-env names. The runner's
53
+ * startup check runs the runtime with these too, so a var a run cannot do without fails there, not in the first task (TASK-59).
54
+ */
55
+ export function inheritedEnv(base, passEnv = [], platform = process.platform) {
30
56
  const env = {};
31
- for (const k of [...ENV_ALLOWLIST, ...(a.passEnv ?? [])]) {
32
- const v = base[k];
57
+ const win = platform === 'win32';
58
+ for (const k of [...ENV_ALLOWLIST, ...(win ? WINDOWS_ENV_ALLOWLIST : []), ...passEnv]) {
59
+ const v = lookup(base, k, win);
33
60
  if (v === undefined || neverPass(k))
34
61
  continue;
35
62
  env[k] = v;
36
63
  }
64
+ return env;
65
+ }
66
+ export function buildAgentEnv(base, a, platform = process.platform) {
67
+ const env = inheritedEnv(base, a.passEnv, platform);
37
68
  env.ACH_HUB = a.hub;
38
69
  env.ACH_RUN_TOKEN = a.runToken;
39
70
  env.ACH_TASK_ID = a.taskId;
@@ -148,14 +148,16 @@ export declare const CODEX_WORKER_CONFIG: string;
148
148
  * refreshed login stays the user's. Sessions of the run stay in this home, so
149
149
  * a resumed run of the same task finds its thread.
150
150
  */
151
- export declare function prepareCodexHome(home: string, realCodexHome?: string): string;
151
+ export declare function prepareCodexHome(home: string, realCodexHome?: string, platform?: NodeJS.Platform): string;
152
+ /** The user's real home: HOME, or USERPROFILE on Windows, where HOME is usually not set. */
153
+ export declare function realHomeOf(env: NodeJS.ProcessEnv | Record<string, string | undefined>, platform?: NodeJS.Platform): string | undefined;
152
154
  /**
153
155
  * B1: a per-task scratch HOME for spawned agents, so `~/.config/agentchannel`
154
156
  * (agent key file, admin session, runner state) is not reachable through
155
157
  * $HOME. Runtime config (.claude, .codex) is linked, the git identity
156
158
  * (.gitconfig) copied; npm keeps the real cache via npm_config_cache.
157
159
  */
158
- export declare function prepareAgentHome(root: string, agentName: string, key: string, realHome?: string, realCodexHome?: string): {
160
+ export declare function prepareAgentHome(root: string, agentName: string, key: string, realHome?: string, realCodexHome?: string, platform?: NodeJS.Platform): {
159
161
  home: string;
160
162
  env: Record<string, string>;
161
163
  };
@@ -1,5 +1,5 @@
1
1
  import { randomBytes } from 'node:crypto';
2
- import { appendFileSync, copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, rmSync, symlinkSync, unlinkSync, writeFileSync } from 'node:fs';
2
+ import { appendFileSync, copyFileSync, existsSync, linkSync, lstatSync, mkdirSync, readdirSync, readFileSync, rmSync, symlinkSync, unlinkSync, writeFileSync } from 'node:fs';
3
3
  import { tmpdir } from 'node:os';
4
4
  import { dirname, join } from 'node:path';
5
5
  import { gitCommonDir } from '../adapters/index.js';
@@ -124,7 +124,7 @@ export const CODEX_WORKER_CONFIG = [
124
124
  * refreshed login stays the user's. Sessions of the run stay in this home, so
125
125
  * a resumed run of the same task finds its thread.
126
126
  */
127
- export function prepareCodexHome(home, realCodexHome) {
127
+ export function prepareCodexHome(home, realCodexHome, platform = process.platform) {
128
128
  const dir = join(home, '.codex');
129
129
  try {
130
130
  // an older scratch home linked the whole ~/.codex: replace the link
@@ -152,19 +152,31 @@ export function prepareCodexHome(home, realCodexHome) {
152
152
  symlinkSync(src, dst);
153
153
  }
154
154
  catch {
155
- /* best effort: codex then reports "not logged in" */
155
+ // Windows makes file symlinks only with developer mode or admin; a hard link needs neither
156
+ if (platform === 'win32') {
157
+ try {
158
+ linkSync(src, dst);
159
+ }
160
+ catch {
161
+ /* best effort: codex then reports "not logged in" */
162
+ }
163
+ }
156
164
  }
157
165
  }
158
166
  }
159
167
  return dir;
160
168
  }
169
+ /** The user's real home: HOME, or USERPROFILE on Windows, where HOME is usually not set. */
170
+ export function realHomeOf(env, platform = process.platform) {
171
+ return env.HOME || (platform === 'win32' ? env.USERPROFILE : undefined) || undefined;
172
+ }
161
173
  /**
162
174
  * B1: a per-task scratch HOME for spawned agents, so `~/.config/agentchannel`
163
175
  * (agent key file, admin session, runner state) is not reachable through
164
176
  * $HOME. Runtime config (.claude, .codex) is linked, the git identity
165
177
  * (.gitconfig) copied; npm keeps the real cache via npm_config_cache.
166
178
  */
167
- export function prepareAgentHome(root, agentName, key, realHome, realCodexHome) {
179
+ export function prepareAgentHome(root, agentName, key, realHome, realCodexHome, platform = process.platform) {
168
180
  const safe = (x) => x.replace(/[^A-Za-z0-9_.-]/g, '_').slice(0, 80);
169
181
  const home = join(root, safe(agentName), safe(key));
170
182
  mkdirSync(home, { recursive: true, mode: 0o700 });
@@ -173,11 +185,14 @@ export function prepareAgentHome(root, agentName, key, realHome, realCodexHome)
173
185
  const tmp = join(home, 'tmp');
174
186
  mkdirSync(tmp, { recursive: true, mode: 0o700 });
175
187
  const env = { HOME: home, TMPDIR: tmp };
188
+ // Windows programs find the home in USERPROFILE and the temporary directory in TEMP/TMP
189
+ if (platform === 'win32')
190
+ Object.assign(env, { USERPROFILE: home, TEMP: tmp, TMP: tmp });
176
191
  if (!realHome) {
177
- env.CODEX_HOME = prepareCodexHome(home, realCodexHome);
192
+ env.CODEX_HOME = prepareCodexHome(home, realCodexHome, platform);
178
193
  return { home, env };
179
194
  }
180
- for (const name of runtimeHomeLinks()) {
195
+ for (const name of runtimeHomeLinks(platform)) {
181
196
  const src = join(realHome, name);
182
197
  const dst = join(home, name);
183
198
  if (!existsSync(src))
@@ -188,7 +203,8 @@ export function prepareAgentHome(root, agentName, key, realHome, realCodexHome)
188
203
  catch {
189
204
  try {
190
205
  mkdirSync(dirname(dst), { recursive: true, mode: 0o700 });
191
- symlinkSync(src, dst);
206
+ // a junction links a Windows directory without developer mode or admin
207
+ symlinkSync(src, dst, platform === 'win32' && lstatSync(src).isDirectory() ? 'junction' : undefined);
192
208
  }
193
209
  catch {
194
210
  /* best effort */
@@ -207,7 +223,7 @@ export function prepareAgentHome(root, agentName, key, realHome, realCodexHome)
207
223
  const npmCache = join(realHome, '.npm');
208
224
  if (existsSync(npmCache))
209
225
  env.npm_config_cache = npmCache;
210
- env.CODEX_HOME = prepareCodexHome(home, realCodexHome || join(realHome, '.codex'));
226
+ env.CODEX_HOME = prepareCodexHome(home, realCodexHome || join(realHome, '.codex'), platform);
211
227
  return { home, env };
212
228
  }
213
229
  /** How long the runner trusts its copy of the agent's record before reading it again. */
@@ -1248,7 +1264,7 @@ export class Runner {
1248
1264
  }
1249
1265
  /** Readable roots for the spawned agent besides its cwd (S4). */
1250
1266
  readRoots(cwd, readRepos = [], taskId) {
1251
- const home = (this.o.baseEnv ?? process.env).HOME;
1267
+ const home = realHomeOf(this.o.baseEnv ?? process.env);
1252
1268
  return [
1253
1269
  ...toolchainReadRoots(home || undefined),
1254
1270
  ...[developerDir()].filter((d) => !!d),
@@ -1323,7 +1339,7 @@ export class Runner {
1323
1339
  });
1324
1340
  // B1: HOME is a per-task scratch dir (never the runner's own home).
1325
1341
  const baseEnv = this.o.baseEnv ?? process.env;
1326
- const realHome = baseEnv.HOME || undefined;
1342
+ const realHome = realHomeOf(baseEnv);
1327
1343
  Object.assign(env, prepareAgentHome(this.o.agentHomesDir ?? join(tmpdir(), 'ach-homes'), me.name, taskId, realHome, baseEnv.CODEX_HOME || undefined).env);
1328
1344
  // a read-only GitHub token issued by the hub for this run (see githubToken)
1329
1345
  const gh = await this.githubToken(rec);
@@ -90,6 +90,8 @@ export interface ProbeOptions {
90
90
  codex?: string[];
91
91
  /** the hub URL: when set, a Codex probe also checks that a sandboxed command reaches it (work runs call `ach` from there) */
92
92
  hub?: string;
93
+ /** the env a run's runtime gets (inheritedEnv); the sandboxed commands run with it. Default: env */
94
+ runEnv?: NodeJS.ProcessEnv;
93
95
  }
94
96
  /** Probe `tool`'s sandbox on this machine. Never throws. */
95
97
  export declare function probeSandbox(tool: SandboxTool, o?: ProbeOptions): Promise<SandboxStatus>;
@@ -113,13 +113,13 @@ export async function probeSandbox(tool, o = {}) {
113
113
  const platform = o.platform ?? process.platform;
114
114
  const host = o.host ?? detectHost(env, platform);
115
115
  const run = o.run ?? defaultRun;
116
- const st = await probe(tool, { env, platform, host, run, home: o.home ?? homedir(), codex: o.codex, hub: o.hub });
116
+ const st = await probe(tool, { env, platform, host, run, home: o.home ?? homedir(), codex: o.codex, hub: o.hub, runEnv: o.runEnv ?? env });
117
117
  if (!st.ok)
118
118
  st.fix = sandboxFix(st, host);
119
119
  return st;
120
120
  }
121
121
  async function probe(tool, o) {
122
- const { platform, host, run, env } = o;
122
+ const { platform, host, run, env, runEnv } = o;
123
123
  if (platform === 'win32') {
124
124
  if (tool === 'claude')
125
125
  return { tool, ok: false, problem: 'windows-native' };
@@ -152,12 +152,12 @@ async function probe(tool, o) {
152
152
  let codex;
153
153
  if (tool === 'claude' && platform === 'linux') {
154
154
  // what Claude Code's sandbox does: a new session, no network, the filesystem read-only except the work directory
155
- r = await run(host.bwrap, ['--new-session', '--die-with-parent', '--unshare-net', '--ro-bind', '/', '/', '--dev', '/dev', '--proc', '/proc', '--bind', dir, dir, '--', ...sh], { env });
155
+ r = await run(host.bwrap, ['--new-session', '--die-with-parent', '--unshare-net', '--ro-bind', '/', '/', '--dev', '/dev', '--proc', '/proc', '--bind', dir, dir, '--', ...sh], { env: runEnv });
156
156
  }
157
157
  else if (tool === 'claude') {
158
158
  const q = (p) => JSON.stringify(p);
159
159
  const profile = `(version 1)(allow default)(deny file-write* (subpath ${q(o.home)}))(allow file-write* (subpath ${q(dir)}))`;
160
- r = await run('/usr/bin/sandbox-exec', ['-p', profile, ...sh], { env });
160
+ r = await run('/usr/bin/sandbox-exec', ['-p', profile, ...sh], { env: runEnv });
161
161
  }
162
162
  else {
163
163
  codex = o.codex ?? codexCommand(env);
@@ -167,7 +167,7 @@ async function probe(tool, o) {
167
167
  if (canary)
168
168
  writeFileSync(canary, 'probe\n', { mode: 0o600 });
169
169
  codexHome = probeCodexHome();
170
- const cenv = { ...env, CODEX_HOME: codexHome };
170
+ const cenv = { ...runEnv, CODEX_HOME: codexHome };
171
171
  // the work directory is the cwd; the sandbox is the one a work run gets (codexSandboxOverrides)
172
172
  r = await run(codex[0], [...codex.slice(1), 'sandbox', ...codexProbeConfig(dir, o.home, o.hub), '--', ...cmd], { env: cenv, cwd: dir });
173
173
  if (r.code !== 0 && /unrecognized subcommand|unexpected argument|Usage: codex \[OPTIONS\]/i.test(r.stderr)) {
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "3.35.0";
1
+ export declare const VERSION = "3.35.2";
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.35.0';
1
+ export const VERSION = '3.35.2';
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.35.0",
3
+ "version": "3.35.2",
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",