@koalaauto/agentchannel 3.35.0 → 3.35.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/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,4 @@ 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
+ 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,10 +48,11 @@ 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
+ export function buildAgentEnv(base, a, platform = process.platform) {
30
52
  const env = {};
31
- for (const k of [...ENV_ALLOWLIST, ...(a.passEnv ?? [])]) {
32
- const v = base[k];
53
+ const win = platform === 'win32';
54
+ for (const k of [...ENV_ALLOWLIST, ...(win ? WINDOWS_ENV_ALLOWLIST : []), ...(a.passEnv ?? [])]) {
55
+ const v = lookup(base, k, win);
33
56
  if (v === undefined || neverPass(k))
34
57
  continue;
35
58
  env[k] = v;
@@ -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);
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "3.35.0";
1
+ export declare const VERSION = "3.35.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.35.0';
1
+ export const VERSION = '3.35.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.35.0",
3
+ "version": "3.35.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",