@mycompbox/compbox-cli 1.21.15 → 1.21.17

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.
Files changed (62) hide show
  1. package/.tsbuildinfo +1 -1
  2. package/commands/configure.d.ts.map +1 -1
  3. package/commands/configure.js +3 -3
  4. package/commands/configure.js.map +1 -1
  5. package/commands/doctor.d.ts +21 -3
  6. package/commands/doctor.d.ts.map +1 -1
  7. package/commands/doctor.js +93 -8
  8. package/commands/doctor.js.map +1 -1
  9. package/commands/run.d.ts.map +1 -1
  10. package/commands/run.js +4 -1
  11. package/commands/run.js.map +1 -1
  12. package/commands/service.d.ts +10 -19
  13. package/commands/service.d.ts.map +1 -1
  14. package/commands/service.js +107 -73
  15. package/commands/service.js.map +1 -1
  16. package/commands/workspace.d.ts +18 -1
  17. package/commands/workspace.d.ts.map +1 -1
  18. package/commands/workspace.js +126 -14
  19. package/commands/workspace.js.map +1 -1
  20. package/index.js +1443 -367
  21. package/package.json +1 -1
  22. package/utils/agent-invoker.d.ts +29 -2
  23. package/utils/agent-invoker.d.ts.map +1 -1
  24. package/utils/agent-invoker.js +97 -16
  25. package/utils/agent-invoker.js.map +1 -1
  26. package/utils/claude-runtime.d.ts +63 -7
  27. package/utils/claude-runtime.d.ts.map +1 -1
  28. package/utils/claude-runtime.js +203 -67
  29. package/utils/claude-runtime.js.map +1 -1
  30. package/utils/config-store.d.ts.map +1 -1
  31. package/utils/config-store.js +7 -4
  32. package/utils/config-store.js.map +1 -1
  33. package/utils/mcp-config-writer.d.ts +30 -4
  34. package/utils/mcp-config-writer.d.ts.map +1 -1
  35. package/utils/mcp-config-writer.js +33 -6
  36. package/utils/mcp-config-writer.js.map +1 -1
  37. package/utils/package-manager-shims.d.ts +20 -4
  38. package/utils/package-manager-shims.d.ts.map +1 -1
  39. package/utils/package-manager-shims.js +84 -13
  40. package/utils/package-manager-shims.js.map +1 -1
  41. package/utils/process-group.d.ts +9 -2
  42. package/utils/process-group.d.ts.map +1 -1
  43. package/utils/process-group.js +14 -4
  44. package/utils/process-group.js.map +1 -1
  45. package/utils/process-spawn.d.ts +68 -0
  46. package/utils/process-spawn.d.ts.map +1 -0
  47. package/utils/process-spawn.js +119 -0
  48. package/utils/process-spawn.js.map +1 -0
  49. package/utils/project-checks.d.ts +28 -0
  50. package/utils/project-checks.d.ts.map +1 -1
  51. package/utils/project-checks.js +58 -50
  52. package/utils/project-checks.js.map +1 -1
  53. package/utils/repo-setup.js +3 -3
  54. package/utils/repo-setup.js.map +1 -1
  55. package/utils/windows-runner.d.ts +136 -0
  56. package/utils/windows-runner.d.ts.map +1 -0
  57. package/utils/windows-runner.js +407 -0
  58. package/utils/windows-runner.js.map +1 -0
  59. package/utils/wrap-up.d.ts +81 -3
  60. package/utils/wrap-up.d.ts.map +1 -1
  61. package/utils/wrap-up.js +240 -8
  62. package/utils/wrap-up.js.map +1 -1
@@ -15,7 +15,7 @@
15
15
  * per-employee token and central base URL are supplied through its `env`.
16
16
  */
17
17
  import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
18
- import { basename, dirname, join } from 'path';
18
+ import { basename, dirname, join, win32 } from 'path';
19
19
  /** Default Claude Code project-level MCP config file name. */
20
20
  export const DEFAULT_MCP_CONFIG_FILENAME = '.mcp.json';
21
21
  /** Default server key used for the CompBox MCP entry. */
@@ -59,6 +59,28 @@ export function resolveInstalledMcpBundle(opts) {
59
59
  }
60
60
  return undefined;
61
61
  }
62
+ /**
63
+ * True when `command` launches Node directly: bare `node`, or an absolute
64
+ * Node binary (`/usr/local/bin/node`, `C:\\Program Files\\nodejs\\node.exe`).
65
+ * Uses win32 basename so both `/` and `\\` separators are handled.
66
+ */
67
+ export function isNodeCommand(command) {
68
+ return /^node(\.exe)?$/i.test(win32.basename(command));
69
+ }
70
+ /**
71
+ * True when the entry launches the published package through npx — bare
72
+ * `npx …` or the Windows-safe `cmd /c npx …` wrapper.
73
+ */
74
+ export function isNpxLaunch(command, args) {
75
+ const base = win32.basename(command).toLowerCase();
76
+ if (base === 'npx' || base === 'npx.cmd')
77
+ return true;
78
+ if (base === 'cmd' || base === 'cmd.exe') {
79
+ const a = (args ?? []).map((x) => x.toLowerCase());
80
+ return a[0] === '/c' && (a[1] === 'npx' || a[1] === 'npx.cmd');
81
+ }
82
+ return false;
83
+ }
62
84
  /** Default absolute path to the project MCP config in the given directory. */
63
85
  export function defaultMcpConfigPath(projectRoot = process.cwd()) {
64
86
  return join(projectRoot, DEFAULT_MCP_CONFIG_FILENAME);
@@ -67,10 +89,12 @@ export function defaultMcpConfigPath(projectRoot = process.cwd()) {
67
89
  * Build the CompBox MCP server entry from a spec. Exposed for testing and reuse.
68
90
  *
69
91
  * Launch-target selection (when neither `command` nor `args` is explicitly
70
- * overridden): prefer `node <installed bundle>` when the brew-installed
71
- * compbox-mcp.cjs resolves, else fall back to `npx -y ${MCP_SERVER_PACKAGE}`
72
- * (fetched from the public npm registry on first use). An explicit `command`
73
- * or `args` override always wins and disables detection.
92
+ * overridden): prefer `<process.execPath> <installed bundle>` when the
93
+ * installed compbox-mcp.cjs resolves (all platforms), else fall back to
94
+ * `npx -y ${MCP_SERVER_PACKAGE}` (fetched from the public npm registry on
95
+ * first use) — wrapped as `cmd /c npx -y …` on win32, where the bare `npx`
96
+ * shim cannot be spawned without a shell. An explicit `command` or `args`
97
+ * override always wins and disables detection.
74
98
  */
75
99
  export function buildCompboxServerEntry(spec) {
76
100
  const env = {
@@ -81,7 +105,10 @@ export function buildCompboxServerEntry(spec) {
81
105
  if (!explicitLaunch) {
82
106
  const bundlePath = (spec.resolveInstalledBundle ?? resolveInstalledMcpBundle)();
83
107
  if (bundlePath !== undefined) {
84
- return { command: 'node', args: [bundlePath], env };
108
+ return { command: spec.execPath ?? process.execPath, args: [bundlePath], env };
109
+ }
110
+ if ((spec.platform ?? process.platform) === 'win32') {
111
+ return { command: 'cmd', args: ['/c', 'npx', '-y', MCP_SERVER_PACKAGE], env };
85
112
  }
86
113
  }
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CAAC;IAChC,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACpC,aAAa,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAE/E,OAAO;QACL,WAAW,EAAE,CAAC,OAAO;QACrB,YAAY;QACZ,gBAAgB;QAChB,UAAU;QACV,KAAK;KACN,CAAC;AACJ,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { type EnvLike } from './claude-runtime.js';
1
2
  /**
2
3
  * Package managers a project's lockfile may ask for that don't come with Node,
3
4
  * and the npx package that stands in for each. pnpm 10 reads both v9 and
@@ -8,22 +9,36 @@ declare const STAND_INS: {
8
9
  readonly yarn: "yarn@1";
9
10
  };
10
11
  export type ShimmedTool = keyof typeof STAND_INS;
11
- /** Whether `command` is an executable file in one of the PATH's folders. */
12
- export declare function isOnPath(command: string, path: string): boolean;
12
+ /** PATH with `exclude` removed, so CompBox's own shims never count as an install. */
13
+ export declare function pathWithout(path: string, exclude: string, platform?: NodeJS.Platform): string;
14
+ /**
15
+ * Whether `command` is an executable file in one of the PATH's folders. On
16
+ * Windows each PATHEXT extension is tried too (`pnpm` finds `pnpm.cmd`), and
17
+ * PATH is split on `;`.
18
+ */
19
+ export declare function isOnPath(command: string, path: string, platform?: NodeJS.Platform, env?: EnvLike): boolean;
13
20
  /**
14
21
  * The shell script that runs a missing package manager through npx. Node's
15
22
  * folder goes first on PATH because npx and the package manager are Node
16
23
  * scripts, and the runner's PATH may not include Node.
17
24
  */
18
25
  export declare function shimScript(tool: ShimmedTool, nodeBinDir: string, npx: string): string;
26
+ /**
27
+ * The Windows batch file that runs a missing package manager through npx.
28
+ * Arguments are forwarded with %* and npx's exit code is passed back with
29
+ * `exit /b`, so a failing install or test still fails the build.
30
+ */
31
+ export declare function shimCmdScript(tool: ShimmedTool, nodeBinDir: string, npx: string): string;
19
32
  /**
20
33
  * A build's first step installs the project's dependencies with the tool its
21
34
  * lockfile names, and the agents then run that tool for tests and builds. A
22
35
  * repo with a pnpm-lock.yaml on a computer without pnpm stopped every build
23
36
  * with "spawn pnpm ENOENT" (Veena, 2026-10-22). For each such tool that isn't
24
37
  * on the runner's PATH, write a stand-in to ~/.compbox/shims that runs it with
25
- * npx, and return that folder so the caller puts it on PATH. Returns null when
26
- * nothing is missing (or on Windows, where npx shims would need .cmd files).
38
+ * npx, and return that folder so the caller puts it on PATH. On Windows the
39
+ * stand-ins are `<tool>.cmd` batch files. The shim folder itself is left out
40
+ * when checking what's installed and when finding npx, so a shim never stands
41
+ * in for, or calls, itself. Returns null when nothing is missing.
27
42
  */
28
43
  export declare function ensurePackageManagerShims(opts?: {
29
44
  path?: string | undefined;
@@ -32,6 +47,7 @@ export declare function ensurePackageManagerShims(opts?: {
32
47
  nodeBinDir?: string;
33
48
  /** Widens PATH with the usual install folders; tests pass PATH through as is. */
34
49
  searchPath?: (path: string | undefined) => string;
50
+ env?: EnvLike;
35
51
  }): {
36
52
  dir: string;
37
53
  tools: ShimmedTool[];
@@ -1 +1 @@
1
- {"version":3,"file":"package-manager-shims.d.ts","sourceRoot":"","sources":["../../src/utils/package-manager-shims.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,QAAA,MAAM,SAAS;;;CAA+C,CAAC;AAE/D,MAAM,MAAM,WAAW,GAAG,MAAM,OAAO,SAAS,CAAC;AAEjD,4EAA4E;AAC5E,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAW/D;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAUrF;AAED;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,GAAE;IAC9C,IAAI,CAAC,EAAE,MAAM,GAAG,SAA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AAM,GAAG,SAAS,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iFAAiF;IACjF,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,KAAK,MAAM,CAAC;IAClD,GAAG,CAAC,EAAE,OAAO,CAAC;CACV,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,WAAW,EAAE,CAAA;CAAE,GAAG,IAAI,CAkCpD"}
@@ -1,18 +1,45 @@
1
1
  import { accessSync, chmodSync, constants, existsSync, mkdirSync, writeFileSync } from 'node:fs';
2
2
  import { homedir } from 'node:os';
3
- import { delimiter, dirname, join } from 'node:path';
4
- import { claudeChildEnvPath } from './claude-runtime.js';
3
+ import { dirname, join, posix as posixPath, win32 as win32Path } from 'node:path';
4
+ import { claudeChildEnvPath, isExecutableFile } from './claude-runtime.js';
5
5
  /**
6
6
  * Package managers a project's lockfile may ask for that don't come with Node,
7
7
  * and the npx package that stands in for each. pnpm 10 reads both v9 and
8
8
  * older lockfiles; yarn 1 reads classic yarn.lock files.
9
9
  */
10
10
  const STAND_INS = { pnpm: 'pnpm@10', yarn: 'yarn@1' };
11
- /** Whether `command` is an executable file in one of the PATH's folders. */
12
- export function isOnPath(command, path) {
13
- for (const dir of path.split(delimiter)) {
11
+ function delimiterFor(platform) {
12
+ return platform === 'win32' ? win32Path.delimiter : posixPath.delimiter;
13
+ }
14
+ /** Compares folders the way the platform does: case-insensitively on Windows. */
15
+ function sameDir(a, b, platform) {
16
+ if (platform !== 'win32')
17
+ return posixPath.resolve(a) === posixPath.resolve(b);
18
+ const norm = (d) => d.replace(/[\\/]+$/, '').replace(/\//g, '\\').toLowerCase();
19
+ return norm(a) === norm(b);
20
+ }
21
+ /** PATH with `exclude` removed, so CompBox's own shims never count as an install. */
22
+ export function pathWithout(path, exclude, platform = process.platform) {
23
+ const delim = delimiterFor(platform);
24
+ return path
25
+ .split(delim)
26
+ .filter((d) => d && !sameDir(d, exclude, platform))
27
+ .join(delim);
28
+ }
29
+ /**
30
+ * Whether `command` is an executable file in one of the PATH's folders. On
31
+ * Windows each PATHEXT extension is tried too (`pnpm` finds `pnpm.cmd`), and
32
+ * PATH is split on `;`.
33
+ */
34
+ export function isOnPath(command, path, platform = process.platform, env = process.env) {
35
+ for (const dir of path.split(delimiterFor(platform))) {
14
36
  if (!dir)
15
37
  continue;
38
+ if (platform === 'win32') {
39
+ if (findWin32Executable(command, dir, env))
40
+ return true;
41
+ continue;
42
+ }
16
43
  try {
17
44
  accessSync(join(dir, command), constants.X_OK);
18
45
  return true;
@@ -23,6 +50,20 @@ export function isOnPath(command, path) {
23
50
  }
24
51
  return false;
25
52
  }
53
+ function win32Extensions(env) {
54
+ const raw = env.PATHEXT ?? '.COM;.EXE;.BAT;.CMD';
55
+ return raw.split(';').map((e) => e.trim().toLowerCase()).filter((e) => e.length > 1 && e.startsWith('.'));
56
+ }
57
+ /** `dir/command` or `dir/command<ext>` for an executable PATHEXT extension, else null. */
58
+ function findWin32Executable(command, dir, env) {
59
+ const names = win32Path.extname(command) ? [command] : win32Extensions(env).map((ext) => command + ext);
60
+ for (const name of names) {
61
+ const candidate = join(dir, name);
62
+ if (isExecutableFile(candidate, 'win32', env))
63
+ return candidate;
64
+ }
65
+ return null;
66
+ }
26
67
  /**
27
68
  * The shell script that runs a missing package manager through npx. Node's
28
69
  * folder goes first on PATH because npx and the package manager are Node
@@ -39,28 +80,58 @@ export function shimScript(tool, nodeBinDir, npx) {
39
80
  '',
40
81
  ].join('\n');
41
82
  }
83
+ /**
84
+ * The Windows batch file that runs a missing package manager through npx.
85
+ * Arguments are forwarded with %* and npx's exit code is passed back with
86
+ * `exit /b`, so a failing install or test still fails the build.
87
+ */
88
+ export function shimCmdScript(tool, nodeBinDir, npx) {
89
+ return [
90
+ '@echo off',
91
+ `rem Written by CompBox: ${tool} isn't installed on this computer, so it runs`,
92
+ "rem through Node's npx. Installing it yourself makes CompBox use that instead.",
93
+ `set "PATH=${nodeBinDir};%PATH%"`,
94
+ `"${npx}" --yes ${STAND_INS[tool]} %*`,
95
+ 'exit /b %ERRORLEVEL%',
96
+ '',
97
+ ].join('\r\n');
98
+ }
42
99
  /**
43
100
  * A build's first step installs the project's dependencies with the tool its
44
101
  * lockfile names, and the agents then run that tool for tests and builds. A
45
102
  * repo with a pnpm-lock.yaml on a computer without pnpm stopped every build
46
103
  * with "spawn pnpm ENOENT" (Veena, 2026-10-22). For each such tool that isn't
47
104
  * on the runner's PATH, write a stand-in to ~/.compbox/shims that runs it with
48
- * npx, and return that folder so the caller puts it on PATH. Returns null when
49
- * nothing is missing (or on Windows, where npx shims would need .cmd files).
105
+ * npx, and return that folder so the caller puts it on PATH. On Windows the
106
+ * stand-ins are `<tool>.cmd` batch files. The shim folder itself is left out
107
+ * when checking what's installed and when finding npx, so a shim never stands
108
+ * in for, or calls, itself. Returns null when nothing is missing.
50
109
  */
51
110
  export function ensurePackageManagerShims(opts = {}) {
52
- if ((opts.platform ?? process.platform) === 'win32')
53
- return null;
54
- const path = (opts.searchPath ?? claudeChildEnvPath)(opts.path ?? process.env.PATH);
55
- const missing = Object.keys(STAND_INS).filter((tool) => !isOnPath(tool, path));
111
+ const platform = opts.platform ?? process.platform;
112
+ const env = opts.env ?? process.env;
113
+ const dir = join(opts.home ?? homedir(), '.compbox', 'shims');
114
+ const searchPath = opts.searchPath ?? ((p) => claudeChildEnvPath(p, { platform, env }));
115
+ const path = pathWithout(searchPath(opts.path ?? process.env.PATH), dir, platform);
116
+ const missing = Object.keys(STAND_INS).filter((tool) => !isOnPath(tool, path, platform, env));
56
117
  if (missing.length === 0)
57
118
  return null;
58
119
  const nodeBinDir = opts.nodeBinDir ?? dirname(process.execPath);
59
- const npx = existsSync(join(nodeBinDir, 'npx')) ? join(nodeBinDir, 'npx') : 'npx';
60
- const dir = join(opts.home ?? homedir(), '.compbox', 'shims');
120
+ const win32 = platform === 'win32';
121
+ let npx;
122
+ if (win32) {
123
+ npx = findWin32Executable('npx', nodeBinDir, env) ?? 'npx';
124
+ }
125
+ else {
126
+ npx = existsSync(join(nodeBinDir, 'npx')) ? join(nodeBinDir, 'npx') : 'npx';
127
+ }
61
128
  try {
62
129
  mkdirSync(dir, { recursive: true });
63
130
  for (const tool of missing) {
131
+ if (win32) {
132
+ writeFileSync(join(dir, `${tool}.cmd`), shimCmdScript(tool, nodeBinDir, npx));
133
+ continue;
134
+ }
64
135
  const file = join(dir, tool);
65
136
  writeFileSync(file, shimScript(tool, nodeBinDir, npx));
66
137
  chmodSync(file, 0o755);
@@ -1 +1 @@
1
- {"version":3,"file":"package-manager-shims.js","sourceRoot":"","sources":["../../src/utils/package-manager-shims.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACjG,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD;;;;GAIG;AACH,MAAM,SAAS,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAW,CAAC;AAI/D,4EAA4E;AAC5E,MAAM,UAAU,QAAQ,CAAC,OAAe,EAAE,IAAY;IACpD,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;QACxC,IAAI,CAAC,GAAG;YAAE,SAAS;QACnB,IAAI,CAAC;YACH,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;YAC/C,OAAO,IAAI,CAAC;QACd,CAAC;QA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C;QACP,qEAAqE;QACrE,4CAA4C;QAC5C,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AACjC,CAAC"}
@@ -7,19 +7,26 @@
7
7
  * group — and cancellation signals the whole group: SIGTERM first, then SIGKILL
8
8
  * after a grace period. On Windows, `taskkill /T /F` kills the process tree.
9
9
  */
10
- import { type ChildProcess, type SpawnOptions } from 'node:child_process';
10
+ import { spawn as nodeSpawn, type ChildProcess, type SpawnOptions } from 'node:child_process';
11
11
  /** How long the agent gets to exit on SIGTERM before the group is SIGKILLed. */
12
12
  export declare const CANCEL_GRACE_MS = 10000;
13
13
  export interface ProcessGroupDeps {
14
14
  platform?: NodeJS.Platform;
15
15
  /** Defaults to `process.kill`; called with a negative pid to signal the group. */
16
16
  kill?: (pid: number, signal: NodeJS.Signals) => void;
17
- /** Windows only: kills the process tree rooted at `pid` (defaults to `taskkill /PID pid /T /F`). */
17
+ /** Windows only: kills the process tree rooted at `pid` (defaults to `taskkill /pid pid /T /F`). */
18
18
  killTree?: (pid: number) => void;
19
+ /** Spawner used for `taskkill` by the default `killTree` (tests inject a fake). */
20
+ spawn?: typeof nodeSpawn;
19
21
  graceMs?: number;
20
22
  }
21
23
  /** Spawn options that make the child lead its own process group (POSIX only). */
22
24
  export declare function groupSpawnOptions(platform?: NodeJS.Platform): Pick<SpawnOptions, 'detached'>;
25
+ /**
26
+ * Windows tree kill: `taskkill /pid <pid> /T /F`. Shared by cancellation here
27
+ * and `killProcessTree` (process-spawn.ts) so both paths kill the same way.
28
+ */
29
+ export declare function taskkillTree(pid: number, spawn?: typeof nodeSpawn): void;
23
30
  /**
24
31
  * Terminates the child and everything it started. POSIX: SIGTERM to the group,
25
32
  * SIGKILL after the grace period unless the child has exited. Windows: taskkill
@@ -1 +1 @@
1
- {"version":3,"file":"process-group.d.ts","sourceRoot":"","sources":["../../src/utils/process-group.ts"],"names":[],"mappings":"AAAA;;;;;;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EAAE,MAAM,GAAG;IAChD,MAAM,EAAE,QAAQ,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC,CAKA"}
@@ -14,9 +14,13 @@ export const CANCEL_GRACE_MS = 10_000;
14
14
  export function groupSpawnOptions(platform = process.platform) {
15
15
  return platform === 'win32' ? {} : { detached: true };
16
16
  }
17
- function defaultKillTree(pid) {
17
+ /**
18
+ * Windows tree kill: `taskkill /pid <pid> /T /F`. Shared by cancellation here
19
+ * and `killProcessTree` (process-spawn.ts) so both paths kill the same way.
20
+ */
21
+ export function taskkillTree(pid, spawn = nodeSpawn) {
18
22
  try {
19
- const killer = nodeSpawn('taskkill', ['/PID', String(pid), '/T', '/F'], {
23
+ const killer = spawn('taskkill', ['/pid', String(pid), '/T', '/F'], {
20
24
  stdio: 'ignore',
21
25
  windowsHide: true,
22
26
  });
@@ -28,6 +32,12 @@ function defaultKillTree(pid) {
28
32
  // Best-effort.
29
33
  }
30
34
  }
35
+ function windowsKillTree(pid, deps) {
36
+ if (deps.killTree)
37
+ deps.killTree(pid);
38
+ else
39
+ taskkillTree(pid, deps.spawn);
40
+ }
31
41
  /** Sends `signal` to the child's whole group; a group that's already gone (ESRCH) is fine. */
32
42
  function signalGroup(child, signal, deps) {
33
43
  const pid = child.pid;
@@ -66,7 +76,7 @@ export function terminateProcessGroup(child, deps = {}) {
66
76
  const platform = deps.platform ?? process.platform;
67
77
  if (platform === 'win32') {
68
78
  if (child.pid !== undefined)
69
- (deps.killTree ?? defaultKillTree)(child.pid);
79
+ windowsKillTree(child.pid, deps);
70
80
  else
71
81
  child.kill('SIGKILL');
72
82
  return () => undefined;
@@ -86,7 +96,7 @@ export function killProcessGroupNow(child, deps = {}) {
86
96
  const platform = deps.platform ?? process.platform;
87
97
  if (platform === 'win32') {
88
98
  if (child.pid !== undefined)
89
- (deps.killTree ?? defaultKillTree)(child.pid);
99
+ windowsKillTree(child.pid, deps);
90
100
  else
91
101
  child.kill('SIGKILL');
92
102
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"process-group.js","sourceRoot":"","sources":["../../src/utils/process-group.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,KAAK,IAAI,SAAS,EAAwC,MAAM,oBAAoB,CAAC;AAE9F,gFAAgF;AAChF,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC;AAWtC,iFAAiF;AACjF,MAAM,UAAU,iBAAiB,CAAC,WAA4B,OAAO,CAAC,QAAQ;IAC5E,OAAO,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;AACxD,CAAC;AAED,SAAS,eAAe,CAAC,GAAW;IAClC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,SAAS,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE;YACtE,KAAK,EAAE,QAAQ;YACf,WAAW,EAAE,IAAI;SAClB,CAAC,CAAC;QACH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;YACtB,6CAA6C;QAC/C,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,eAAe;IACjB,CAAC;AACH,CAAC;AAED,8FAA8F;AAC9F,SAAS,WAAW,CAAC,KAAmB,EAAE,MAAsB,EAAE,IAAsB;IACtF,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;IACtB,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,+EAA+E;QAC/E,IAAI,CAAC;YACH,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACrB,CAAC;QAAC,MAAM,CAAC;YACP,eAAe;QACjB,CAAC;QACD,OAAO;IACT,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,CAAS,EA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,OAAO,CAAC,CAAC;IAC/C,CAAC,CAAC;AACJ,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAI7C,OAAO;QACL,MAAM,EAAE,QAAQ;QAChB,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,mCAAmC,IAAI,eAAe,EAAE;KAC7F,CAAC;AACJ,CAAC"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Cross-platform child spawning (ENG-404).
3
+ *
4
+ * On Windows, package-manager shims (`npm.cmd`, `pnpm.cmd`, `claude.cmd`, ...)
5
+ * are batch files. Since the CVE-2024-27980 fix, Node refuses to spawn `.cmd` /
6
+ * `.bat` files directly without `shell: true`, and `shell: true` hands an
7
+ * unescaped string to cmd.exe, which is an injection risk. Instead we run
8
+ * them through `cmd.exe /d /s /c "<command line>"` ourselves, with
9
+ * `windowsVerbatimArguments` so Node leaves our quoting alone, and escape every
10
+ * argument for both the MSVCRT argv parser and cmd.exe's metacharacters.
11
+ * `shell: true` is never used.
12
+ *
13
+ * Everywhere else (POSIX, or a real `.exe` on Windows) the command and argv go
14
+ * to `child_process.spawn` unchanged.
15
+ */
16
+ import { spawn as nodeSpawn, type ChildProcess, type SpawnOptions } from 'node:child_process';
17
+ import { type ProcessGroupDeps } from './process-group.js';
18
+ /** True when `command` is a batch file that has to run through cmd.exe. */
19
+ export declare function isBatchFile(command: string): boolean;
20
+ /**
21
+ * Builds the command line handed to `cmd.exe /d /s /c` (without the outer
22
+ * quotes that `/s` strips). Pure, so it can be table-tested on any platform.
23
+ */
24
+ export declare function buildWindowsCmdLine(command: string, args: readonly string[]): string;
25
+ export interface SpawnPlan {
26
+ command: string;
27
+ args: string[];
28
+ options: SpawnOptions;
29
+ }
30
+ /** Injectable environment for planning a spawn (tests run the win32 path anywhere). */
31
+ export interface SpawnPlanEnv {
32
+ platform?: NodeJS.Platform;
33
+ /** Used when `options.env` is not set; defaults to `process.env`. */
34
+ env?: NodeJS.ProcessEnv;
35
+ /** Defaults to `fs.existsSync`; used to resolve bare names on Windows. */
36
+ exists?: (path: string) => boolean;
37
+ }
38
+ /**
39
+ * Windows only: resolves a bare command name (`npm`, `pnpm`, `claude`) the way
40
+ * cmd.exe would — PATH × PATHEXT — so a `.cmd` shim is found and run through
41
+ * cmd.exe. Names with a directory or an extension are returned unchanged, as is
42
+ * a name that can't be found (spawn then reports ENOENT as before).
43
+ */
44
+ export declare function resolveWindowsCommand(command: string, env: NodeJS.ProcessEnv, exists?: (path: string) => boolean): string;
45
+ /**
46
+ * Decides how to spawn `command args`. Exposed for tests; use
47
+ * `spawnCrossPlatform` to actually start the process. Off Windows the plan is
48
+ * the input unchanged (minus `shell`).
49
+ */
50
+ export declare function planCrossPlatformSpawn(command: string, args: readonly string[], options?: SpawnOptions, planEnv?: SpawnPlanEnv): SpawnPlan;
51
+ export interface SpawnCrossPlatformDeps extends SpawnPlanEnv {
52
+ /** Defaults to node's `spawn`; agent-invoker passes its injectable `spawnImpl`. */
53
+ spawn?: typeof nodeSpawn;
54
+ }
55
+ /**
56
+ * `child_process.spawn` that also works for `.cmd` / `.bat` targets (and bare
57
+ * names resolving to them) on Windows, via cmd.exe with safe escaping. POSIX
58
+ * behaviour is unchanged: same command, argv and options.
59
+ */
60
+ export declare function spawnCrossPlatform(command: string, args?: readonly string[], options?: SpawnOptions, deps?: SpawnCrossPlatformDeps): ChildProcess;
61
+ /**
62
+ * Immediately kills the child and everything it started. Windows:
63
+ * `taskkill /pid <pid> /T /F`, which includes cmd.exe and its grandchildren
64
+ * (tests inject `spawn` or `killTree`). POSIX: SIGKILL to the child's process
65
+ * group, the same as before; spawn with `groupSpawnOptions()` so it leads one.
66
+ */
67
+ export declare function killProcessTree(child: ChildProcess, deps?: ProcessGroupDeps): void;
68
+ //# sourceMappingURL=process-spawn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-spawn.d.ts","sourceRoot":"","sources":["../../src/utils/process-spawn.ts"],"names":[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CAChC,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,SAAS,MAAM,EAAO,EAC5B,OAAO,GAAE,YAAiB,EAC1B,IAAI,GAAE,sBAA2B,GAChC,YAAY,CAGd;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,GAAE,gBAAqB,GAAG,IAAI,CAEtF"}
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Cross-platform child spawning (ENG-404).
3
+ *
4
+ * On Windows, package-manager shims (`npm.cmd`, `pnpm.cmd`, `claude.cmd`, ...)
5
+ * are batch files. Since the CVE-2024-27980 fix, Node refuses to spawn `.cmd` /
6
+ * `.bat` files directly without `shell: true`, and `shell: true` hands an
7
+ * unescaped string to cmd.exe, which is an injection risk. Instead we run
8
+ * them through `cmd.exe /d /s /c "<command line>"` ourselves, with
9
+ * `windowsVerbatimArguments` so Node leaves our quoting alone, and escape every
10
+ * argument for both the MSVCRT argv parser and cmd.exe's metacharacters.
11
+ * `shell: true` is never used.
12
+ *
13
+ * Everywhere else (POSIX, or a real `.exe` on Windows) the command and argv go
14
+ * to `child_process.spawn` unchanged.
15
+ */
16
+ import { spawn as nodeSpawn } from 'node:child_process';
17
+ import { existsSync } from 'node:fs';
18
+ import { win32 as win32Path } from 'node:path';
19
+ import { killProcessGroupNow } from './process-group.js';
20
+ /** Characters cmd.exe treats specially; each is escaped with `^`. */
21
+ const CMD_META_CHARS = /([()\][%!^"`<>&|;, *?])/g;
22
+ /** True when `command` is a batch file that has to run through cmd.exe. */
23
+ export function isBatchFile(command) {
24
+ return /\.(cmd|bat)$/i.test(command.trim());
25
+ }
26
+ function escapeCmdMeta(value) {
27
+ return value.replace(CMD_META_CHARS, '^$1');
28
+ }
29
+ /**
30
+ * Quotes one argument for the MSVCRT parser (backslashes before a quote and at
31
+ * the end are doubled, quotes become `\"`), wraps it in quotes, then escapes
32
+ * cmd.exe metacharacters. Batch files re-parse their arguments (`%*`, `%1`),
33
+ * so for them the metacharacters are escaped a second time.
34
+ */
35
+ function escapeArgument(arg, doubleEscape) {
36
+ let quoted = arg.replace(/(\\*)"/g, '$1$1\\"');
37
+ quoted = quoted.replace(/(\\*)$/, '$1$1');
38
+ quoted = escapeCmdMeta(`"${quoted}"`);
39
+ return doubleEscape ? escapeCmdMeta(quoted) : quoted;
40
+ }
41
+ /**
42
+ * Builds the command line handed to `cmd.exe /d /s /c` (without the outer
43
+ * quotes that `/s` strips). Pure, so it can be table-tested on any platform.
44
+ */
45
+ export function buildWindowsCmdLine(command, args) {
46
+ const doubleEscape = isBatchFile(command);
47
+ // The command is caret-escaped for cmd.exe (spaces in paths become `^ `),
48
+ // not MSVCRT-quoted: cmd.exe resolves it, not the target's argv parser.
49
+ const escapedCommand = escapeCmdMeta(command.replace(/"/g, ''));
50
+ return [escapedCommand, ...args.map((arg) => escapeArgument(arg, doubleEscape))].join(' ');
51
+ }
52
+ /** Windows env var names are case-insensitive (`Path`, `PATHEXT`, `ComSpec`). */
53
+ function envValue(env, name) {
54
+ const upper = name.toUpperCase();
55
+ const key = Object.keys(env).find((k) => k.toUpperCase() === upper);
56
+ return key === undefined ? undefined : env[key];
57
+ }
58
+ /**
59
+ * Windows only: resolves a bare command name (`npm`, `pnpm`, `claude`) the way
60
+ * cmd.exe would — PATH × PATHEXT — so a `.cmd` shim is found and run through
61
+ * cmd.exe. Names with a directory or an extension are returned unchanged, as is
62
+ * a name that can't be found (spawn then reports ENOENT as before).
63
+ */
64
+ export function resolveWindowsCommand(command, env, exists = existsSync) {
65
+ if (/[\\/:]/.test(command) || win32Path.extname(command) !== '')
66
+ return command;
67
+ const exts = (envValue(env, 'PATHEXT') ?? '.COM;.EXE;.BAT;.CMD')
68
+ .split(';')
69
+ .filter((ext) => ext !== '');
70
+ const dirs = (envValue(env, 'PATH') ?? '').split(';').filter((dir) => dir !== '');
71
+ for (const dir of dirs) {
72
+ for (const ext of exts) {
73
+ const candidate = win32Path.join(dir.replace(/"/g, ''), command + ext.toLowerCase());
74
+ if (exists(candidate))
75
+ return candidate;
76
+ }
77
+ }
78
+ return command;
79
+ }
80
+ /**
81
+ * Decides how to spawn `command args`. Exposed for tests; use
82
+ * `spawnCrossPlatform` to actually start the process. Off Windows the plan is
83
+ * the input unchanged (minus `shell`).
84
+ */
85
+ export function planCrossPlatformSpawn(command, args, options = {}, planEnv = {}) {
86
+ const platform = planEnv.platform ?? process.platform;
87
+ // `shell` is never honoured: it's exactly the unescaped path we're avoiding.
88
+ const { shell: _shell, ...rest } = options;
89
+ if (platform !== 'win32')
90
+ return { command, args: [...args], options: rest };
91
+ const env = options.env ?? planEnv.env ?? process.env;
92
+ const resolved = resolveWindowsCommand(command, env, planEnv.exists);
93
+ if (!isBatchFile(resolved))
94
+ return { command, args: [...args], options: rest };
95
+ return {
96
+ command: envValue(env, 'ComSpec') ?? 'cmd.exe',
97
+ args: ['/d', '/s', '/c', `"${buildWindowsCmdLine(resolved, args)}"`],
98
+ options: { ...rest, windowsVerbatimArguments: true, windowsHide: true },
99
+ };
100
+ }
101
+ /**
102
+ * `child_process.spawn` that also works for `.cmd` / `.bat` targets (and bare
103
+ * names resolving to them) on Windows, via cmd.exe with safe escaping. POSIX
104
+ * behaviour is unchanged: same command, argv and options.
105
+ */
106
+ export function spawnCrossPlatform(command, args = [], options = {}, deps = {}) {
107
+ const plan = planCrossPlatformSpawn(command, args, options, deps);
108
+ return (deps.spawn ?? nodeSpawn)(plan.command, plan.args, plan.options);
109
+ }
110
+ /**
111
+ * Immediately kills the child and everything it started. Windows:
112
+ * `taskkill /pid <pid> /T /F`, which includes cmd.exe and its grandchildren
113
+ * (tests inject `spawn` or `killTree`). POSIX: SIGKILL to the child's process
114
+ * group, the same as before; spawn with `groupSpawnOptions()` so it leads one.
115
+ */
116
+ export function killProcessTree(child, deps = {}) {
117
+ killProcessGroupNow(child, deps);
118
+ }
119
+ //# sourceMappingURL=process-spawn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-spawn.js","sourceRoot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