@caveman-ai/cli 1.2.1 → 1.2.3

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.
@@ -1,28 +1,72 @@
1
- import { readFileSync, statSync } from "node:fs";
2
- import { dirname, resolve } from "node:path";
1
+ import { existsSync, readFileSync, statSync } from "node:fs";
2
+ import { dirname, extname, isAbsolute, join, resolve } from "node:path";
3
3
  export function parseWindowsNodeShim(source) {
4
4
  for (const line of source.split(/\r?\n/)) {
5
5
  if (!/(?:\bnode(?:\.exe)?\b|_prog)/i.test(line) || !/%\*/.test(line))
6
6
  continue;
7
- const match = line.match(/"%(?:dp0%|~dp0)\\([^"\r\n]+\.(?:cjs|mjs|js))"\s+%\*/i);
7
+ // Shim-relative target (npm cmd-shim, pnpm/yarn-classic @zkochan forms), or
8
+ // a drive-absolute target (pnpm emits one when the global bin dir and the
9
+ // store sit on different drives — path.relative crosses drives as absolute).
10
+ const match = line.match(/"%(?:dp0%|~dp0)\\([^"\r\n]+\.(?:cjs|mjs|js))"\s+%\*/i)
11
+ ?? line.match(/"([A-Za-z]:[\\/][^"\r\n]+\.(?:cjs|mjs|js))"\s+%\*/i);
8
12
  if (match)
9
13
  return match[1];
10
14
  }
11
15
  return null;
12
16
  }
13
- export function portableInvocation(command, args, platform = process.platform) {
14
- if (platform !== "win32" || !/\.(?:cmd|bat)$/i.test(command)) {
15
- return { command, args: [...args] };
17
+ function envValue(env, name) {
18
+ const key = Object.keys(env).find((candidate) => candidate.toLowerCase() === name.toLowerCase());
19
+ return key === undefined ? undefined : env[key];
20
+ }
21
+ // Resolve a bare command through PATH/PATHEXT the way Windows does. This used
22
+ // to be the caller's job, and the contract was invisible: hand this function a
23
+ // bare "npx" on win32 and the .cmd test below missed, so it handed the bare
24
+ // name straight to spawn(), which fails with EINVAL rather than launching
25
+ // anything. Every other copy of this helper in the repo resolves internally;
26
+ // so does this one now. Extensionless names resolve only through PATHEXT —
27
+ // npm/pnpm .bin dirs park a non-executable Unix shim under the bare name next
28
+ // to the real .CMD, and probing the bare name first picks the wrong one (#834).
29
+ export function resolveWindowsCommand(command, env) {
30
+ const pathExt = envValue(env, "PATHEXT") ?? ".COM;.EXE;.BAT;.CMD";
31
+ const names = extname(command)
32
+ ? [command]
33
+ : pathExt.split(";").map((extension) => `${command}${extension.startsWith(".") ? extension : `.${extension}`}`);
34
+ // A path skips PATH lookup but NOT PATHEXT: handing an extensionless file
35
+ // straight to execFile is the exact EFTYPE this function exists to prevent.
36
+ if (isAbsolute(command) || /[\\/]/.test(command)) {
37
+ for (const name of names)
38
+ if (existsSync(name))
39
+ return name;
40
+ return existsSync(command) ? command : undefined;
41
+ }
42
+ for (const directory of (envValue(env, "PATH") ?? "").split(";")) {
43
+ if (!directory)
44
+ continue;
45
+ for (const name of names) {
46
+ const candidate = join(directory, name);
47
+ if (existsSync(candidate))
48
+ return candidate;
49
+ }
16
50
  }
17
- const stat = statSync(command);
51
+ return undefined;
52
+ }
53
+ export function portableInvocation(command, args, platform = process.platform, env = process.env) {
54
+ if (platform !== "win32")
55
+ return { command, args: [...args] };
56
+ const executable = resolveWindowsCommand(command, env) ?? command;
57
+ if (!/\.(?:cmd|bat)$/i.test(executable))
58
+ return { command: executable, args: [...args] };
59
+ const stat = statSync(executable);
18
60
  if (!stat.isFile() || stat.size > 256 * 1024) {
19
- throw new Error(`cannot safely launch Windows command shim: ${command}`);
61
+ throw new Error(`cannot safely launch Windows command shim: ${executable}`);
20
62
  }
21
- const relativeScript = parseWindowsNodeShim(readFileSync(command, "utf8"));
22
- if (!relativeScript) {
23
- throw new Error(`cannot safely launch non-Node Windows command shim: ${command}; install a native .exe`);
63
+ const shimScript = parseWindowsNodeShim(readFileSync(executable, "utf8"));
64
+ if (!shimScript) {
65
+ throw new Error(`cannot safely launch non-Node Windows command shim: ${executable}; install a native .exe`);
24
66
  }
25
- const script = resolve(dirname(command), ...relativeScript.split(/[\\/]+/));
67
+ const script = /^[A-Za-z]:[\\/]/.test(shimScript)
68
+ ? shimScript
69
+ : resolve(dirname(executable), ...shimScript.split(/[\\/]+/));
26
70
  if (!statSync(script).isFile()) {
27
71
  throw new Error(`Windows command shim target is missing: ${script}`);
28
72
  }
@@ -26,20 +26,30 @@ function resolveWindowsCommand(command, env) {
26
26
  return null;
27
27
  }
28
28
 
29
+ export function parseWindowsNodeShim(source) {
30
+ for (const line of source.split(/\r?\n/)) {
31
+ if (!/(?:\bnode(?:\.exe)?\b|_prog)/i.test(line) || !/%\*/.test(line)) continue;
32
+ // Shim-relative target (npm cmd-shim, pnpm/yarn-classic @zkochan forms), or
33
+ // a drive-absolute target (pnpm emits one when the global bin dir and the
34
+ // store sit on different drives — path.relative crosses drives as absolute).
35
+ const match = line.match(/"%(?:dp0%|~dp0)\\([^"\r\n]+\.(?:cjs|mjs|js))"\s+%\*/i)
36
+ || line.match(/"([A-Za-z]:[\\/][^"\r\n]+\.(?:cjs|mjs|js))"\s+%\*/i);
37
+ if (match) return match[1];
38
+ }
39
+ return null;
40
+ }
41
+
29
42
  export function portableInvocation(command, args, platform = process.platform, env = process.env) {
30
43
  if (platform !== "win32") return { command, args: [...args] };
31
44
  const executable = resolveWindowsCommand(command, env) ?? command;
32
45
  if (!/\.(?:cmd|bat)$/i.test(executable)) return { command: executable, args: [...args] };
33
46
  const stat = statSync(executable);
34
47
  if (!stat.isFile() || stat.size > 256 * 1024) throw new Error(`unsafe Windows command shim: ${executable}`);
35
- let relativeScript = null;
36
- for (const line of readFileSync(executable, "utf8").split(/\r?\n/)) {
37
- if (!/(?:\bnode(?:\.exe)?\b|_prog)/i.test(line) || !/%\*/.test(line)) continue;
38
- const match = line.match(/"%(?:dp0%|~dp0)\\([^"\r\n]+\.(?:cjs|mjs|js))"\s+%\*/i);
39
- if (match) { relativeScript = match[1]; break; }
40
- }
48
+ const relativeScript = parseWindowsNodeShim(readFileSync(executable, "utf8"));
41
49
  if (!relativeScript) throw new Error(`non-Node Windows command shim: ${executable}`);
42
- const script = resolve(dirname(executable), ...relativeScript.split(/[\\/]+/));
50
+ const script = /^[A-Za-z]:[\\/]/.test(relativeScript)
51
+ ? relativeScript
52
+ : resolve(dirname(executable), ...relativeScript.split(/[\\/]+/));
43
53
  if (!statSync(script).isFile()) throw new Error(`Windows command shim target missing: ${script}`);
44
54
  return { command: process.execPath, args: [script, ...args] };
45
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caveman-ai/cli",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "Caveman CLI — wrap coding agents with recoverable local context compression and truthful metering (`caveman claude`), then drive Caveman Cloud from terminal. Compression and metering run in companion Go binaries: run `caveman setup` to see install state. Local savings stay inferred until verified.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -26,12 +26,12 @@
26
26
  "LICENSE"
27
27
  ],
28
28
  "scripts": {
29
- "build": "node scripts/gen-binaries.mjs && node scripts/gen-wedge-installer.mjs && node scripts/compile-registries.mjs && tsc && node scripts/bundle-delegate.mjs && node scripts/bundle-tui.mjs && node scripts/shebang.mjs",
29
+ "build": "node scripts/gen-binaries.mjs && node scripts/gen-wedge-installer.mjs && node scripts/compile-registries.mjs && tsc && node scripts/bundle-delegate.mjs && node scripts/bundle-tui.mjs && node scripts/bundle-pi-extension.mjs && node scripts/shebang.mjs",
30
30
  "prepack": "npm run build",
31
31
  "lint": "tsc --noEmit",
32
- "test": "node scripts/gen-binaries.mjs && node scripts/gen-wedge-installer.mjs && node scripts/compile-registries.mjs && tsc && node scripts/bundle-delegate.mjs && node scripts/bundle-tui.mjs && node scripts/shebang.mjs && node --test --test-concurrency=4 tests/*.runtime.mjs",
32
+ "test": "node scripts/gen-binaries.mjs && node scripts/gen-wedge-installer.mjs && node scripts/compile-registries.mjs && tsc && node scripts/bundle-delegate.mjs && node scripts/bundle-tui.mjs && node scripts/bundle-pi-extension.mjs && node scripts/shebang.mjs && node --test --test-force-exit --test-concurrency=4 tests/*.runtime.mjs",
33
33
  "bench:native": "node scripts/benchmark-native-hooks.mjs",
34
- "test:fast": "node scripts/gen-binaries.mjs && node scripts/gen-wedge-installer.mjs && node scripts/compile-registries.mjs && tsc && node scripts/bundle-delegate.mjs && node scripts/bundle-tui.mjs && node --test --test-concurrency=4 --test-reporter=dot tests/agent-native.runtime.mjs tests/billing.runtime.mjs tests/capability-config.runtime.mjs tests/login.runtime.mjs tests/mcp-surface.runtime.mjs tests/porcelain.runtime.mjs tests/practice-registry.runtime.mjs tests/skills.runtime.mjs tests/status.runtime.mjs tests/subscription-recovery.runtime.mjs tests/wrap-gate.runtime.mjs"
34
+ "test:fast": "node scripts/gen-binaries.mjs && node scripts/gen-wedge-installer.mjs && node scripts/compile-registries.mjs && tsc && node scripts/bundle-delegate.mjs && node scripts/bundle-tui.mjs && node scripts/bundle-pi-extension.mjs && node --test --test-force-exit --test-concurrency=4 --test-reporter=dot tests/agent-native.runtime.mjs tests/billing.runtime.mjs tests/capability-config.runtime.mjs tests/login.runtime.mjs tests/mcp-surface.runtime.mjs tests/porcelain.runtime.mjs tests/practice-registry.runtime.mjs tests/skills.runtime.mjs tests/status.runtime.mjs tests/subscription-recovery.runtime.mjs tests/wrap-gate.runtime.mjs"
35
35
  },
36
36
  "dependencies": {},
37
37
  "devDependencies": {