@caveman-ai/cli 2.1.0 → 4.0.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/README.md +3 -1
- package/dist/agents.generated.js +20 -20
- package/dist/binaries.generated.js +1 -1
- package/dist/caveman-pi-extension.mjs +66 -21
- package/dist/device-auth.generated.js +176 -0
- package/dist/home-acl.js +45 -0
- package/dist/index.js +2895 -622
- package/dist/learn-autopilot.js +2 -1
- package/dist/modules/apply.js +622 -0
- package/dist/modules/cloud.js +150 -0
- package/dist/modules/config-home.js +73 -0
- package/dist/modules/doctor.js +86 -0
- package/dist/modules/index-file.js +157 -0
- package/dist/modules/onboard.js +860 -0
- package/dist/modules/provider-logins.js +292 -0
- package/dist/modules/registry.js +96 -0
- package/dist/modules/status.js +71 -0
- package/dist/modules/stop.js +99 -0
- package/dist/native-hook-fast.js +15 -7
- package/dist/native-pipe.js +17 -0
- package/dist/portable-command.js +27 -4
- package/dist/portable-process.mjs +61 -11
- package/dist/reserved-verbs.generated.js +3 -0
- package/dist/stats-cli.js +2 -0
- package/package.json +4 -4
package/dist/portable-command.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// packages/pi-extension bundles this file as its own: keep it to node: builtins.
|
|
1
2
|
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
2
3
|
import { dirname, extname, isAbsolute, join, resolve } from "node:path";
|
|
3
4
|
export function parseWindowsNodeShim(source) {
|
|
@@ -13,6 +14,26 @@ export function parseWindowsNodeShim(source) {
|
|
|
13
14
|
if (match)
|
|
14
15
|
return match[1];
|
|
15
16
|
}
|
|
17
|
+
// Node's own npm.cmd / npx.cmd (first on PATH on every Windows Node install)
|
|
18
|
+
// do not inline the script. They set
|
|
19
|
+
// SET "NPM_CLI_JS=%~dp0\node_modules\npm\bin\npm-cli.js"
|
|
20
|
+
// and launch `"%NODE_EXE%" "%NPM_CLI_JS%" %*`. Only that pair is accepted;
|
|
21
|
+
// arbitrary variable expansion stays rejected. Same as installer/lib/portable-process.js.
|
|
22
|
+
// ponytail: the stock shim prefers a globally upgraded npm (NPM_PREFIX_*);
|
|
23
|
+
// this takes the npm bundled with Node. Mirror npm-prefix.js if that bites.
|
|
24
|
+
const npm = source.match(/SET\s+"(NP[MX])_CLI_JS=%~dp0\\([^"\r\n]+\.js)"[\s\S]*"%NODE_EXE%"\s+"%\1_CLI_JS%"\s+%\*/i);
|
|
25
|
+
return npm ? npm[2] : null;
|
|
26
|
+
}
|
|
27
|
+
// A shim that forwards to a native executable beside it: what npm writes for a
|
|
28
|
+
// package whose bin is an .exe (Claude Code ships one), and pnpm's
|
|
29
|
+
// `@"<target>" %*` form, drive-absolute when the store is on another drive.
|
|
30
|
+
// The executable is run directly, so no batch syntax is evaluated here either.
|
|
31
|
+
export function parseWindowsExeShim(source) {
|
|
32
|
+
for (const line of source.split(/\r?\n/)) {
|
|
33
|
+
const match = line.match(/^[ \t]*@?"(?:%(?:dp0%|~dp0)\\?([^"\r\n]+\.exe)|([A-Za-z]:[\\/][^"\r\n]+\.exe))"[ \t]+%\*[ \t]*$/i);
|
|
34
|
+
if (match)
|
|
35
|
+
return match[1] ?? match[2];
|
|
36
|
+
}
|
|
16
37
|
return null;
|
|
17
38
|
}
|
|
18
39
|
// Accept only a single shim-relative forwarding command, optionally preceded by
|
|
@@ -37,7 +58,8 @@ function resolveWindowsNodeShim(executable, depth = 0, seen = new Set()) {
|
|
|
37
58
|
const nested = parseWindowsNestedShim(source);
|
|
38
59
|
const forwardsToBatch = /"[^"\r\n]+\.(?:cmd|bat)"[ \t]+%\*/i.test(source);
|
|
39
60
|
const jsTarget = forwardsToBatch ? null : parseWindowsNodeShim(source);
|
|
40
|
-
const
|
|
61
|
+
const exeTarget = forwardsToBatch || jsTarget ? null : parseWindowsExeShim(source);
|
|
62
|
+
const child = jsTarget ?? nested ?? exeTarget;
|
|
41
63
|
if (!child) {
|
|
42
64
|
throw new Error(`cannot safely launch non-Node Windows command shim: ${normalized}; install a native .exe`);
|
|
43
65
|
}
|
|
@@ -46,7 +68,7 @@ function resolveWindowsNodeShim(executable, depth = 0, seen = new Set()) {
|
|
|
46
68
|
: resolve(dirname(normalized), ...child.split(/[\\/]+/));
|
|
47
69
|
if (!existsSync(target) || !statSync(target).isFile())
|
|
48
70
|
throw new Error(`Windows command shim target is missing: ${target}`);
|
|
49
|
-
return jsTarget ? target : resolveWindowsNodeShim(target, depth + 1, seen);
|
|
71
|
+
return jsTarget || (!nested && exeTarget) ? target : resolveWindowsNodeShim(target, depth + 1, seen);
|
|
50
72
|
}
|
|
51
73
|
function envValue(env, name) {
|
|
52
74
|
const key = Object.keys(env).find((candidate) => candidate.toLowerCase() === name.toLowerCase());
|
|
@@ -90,6 +112,7 @@ export function portableInvocation(command, args, platform = process.platform, e
|
|
|
90
112
|
const executable = resolveWindowsCommand(command, env) ?? command;
|
|
91
113
|
if (!/\.(?:cmd|bat)$/i.test(executable))
|
|
92
114
|
return { command: executable, args: [...args] };
|
|
93
|
-
const
|
|
94
|
-
|
|
115
|
+
const target = resolveWindowsNodeShim(executable);
|
|
116
|
+
// A shim's target is a Node script to run under this Node, or a native executable.
|
|
117
|
+
return /\.exe$/i.test(target) ? { command: target, args: [...args] } : { command: process.execPath, args: [target, ...args] };
|
|
95
118
|
}
|
|
@@ -2,13 +2,17 @@ import { spawnSync } from "node:child_process";
|
|
|
2
2
|
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
3
3
|
import { dirname, extname, isAbsolute, join, resolve } from "node:path";
|
|
4
4
|
|
|
5
|
+
// A JS port of packages/cli/src/portable-command.ts: this file is copied
|
|
6
|
+
// verbatim into the CLI's dist/ beside the delegate, so it cannot import the
|
|
7
|
+
// TypeScript. packages/cli/tests/portable-command.runtime.mjs fails if the two
|
|
8
|
+
// launch any shim differently.
|
|
9
|
+
|
|
5
10
|
function envValue(env, name) {
|
|
6
11
|
const key = Object.keys(env).find((candidate) => candidate.toLowerCase() === name.toLowerCase());
|
|
7
12
|
return key === undefined ? undefined : env[key];
|
|
8
13
|
}
|
|
9
14
|
|
|
10
15
|
function resolveWindowsCommand(command, env) {
|
|
11
|
-
if (isAbsolute(command) || /[\\/]/.test(command)) return existsSync(command) ? command : null;
|
|
12
16
|
const pathExt = envValue(env, "PATHEXT") ?? ".COM;.EXE;.BAT;.CMD";
|
|
13
17
|
// Extensionless commands resolve only through PATHEXT, matching Windows
|
|
14
18
|
// semantics; the bare name next to a .CMD shim is a non-executable Unix shim.
|
|
@@ -16,6 +20,11 @@ function resolveWindowsCommand(command, env) {
|
|
|
16
20
|
? [command]
|
|
17
21
|
: pathExt.split(";").map((extension) =>
|
|
18
22
|
`${command}${extension.startsWith(".") ? extension : `.${extension}`}`);
|
|
23
|
+
// A path skips PATH lookup but not PATHEXT.
|
|
24
|
+
if (isAbsolute(command) || /[\\/]/.test(command)) {
|
|
25
|
+
for (const name of names) if (existsSync(name)) return name;
|
|
26
|
+
return existsSync(command) ? command : null;
|
|
27
|
+
}
|
|
19
28
|
for (const directory of (envValue(env, "PATH") ?? "").split(";")) {
|
|
20
29
|
if (!directory) continue;
|
|
21
30
|
for (const name of names) {
|
|
@@ -32,26 +41,67 @@ export function parseWindowsNodeShim(source) {
|
|
|
32
41
|
// Shim-relative target (npm cmd-shim, pnpm/yarn-classic @zkochan forms), or
|
|
33
42
|
// a drive-absolute target (pnpm emits one when the global bin dir and the
|
|
34
43
|
// store sit on different drives — path.relative crosses drives as absolute).
|
|
35
|
-
|
|
44
|
+
// %~dp0 already ends with a separator; managed Pi adds none before its target.
|
|
45
|
+
const match = line.match(/"%(?:dp0%|~dp0)\\?([^"\r\n]+\.(?:cjs|mjs|js))"\s+%\*/i)
|
|
36
46
|
|| line.match(/"([A-Za-z]:[\\/][^"\r\n]+\.(?:cjs|mjs|js))"\s+%\*/i);
|
|
37
47
|
if (match) return match[1];
|
|
38
48
|
}
|
|
49
|
+
// Node's own npm.cmd / npx.cmd set
|
|
50
|
+
// SET "NPX_CLI_JS=%~dp0\node_modules\npm\bin\npx-cli.js"
|
|
51
|
+
// and launch `"%NODE_EXE%" "%NPX_CLI_JS%" %*`. Only that pair is accepted.
|
|
52
|
+
// ponytail: takes the npm bundled with Node, not a globally upgraded one.
|
|
53
|
+
const npm = source.match(/SET\s+"(NP[MX])_CLI_JS=%~dp0\\([^"\r\n]+\.js)"[\s\S]*"%NODE_EXE%"\s+"%\1_CLI_JS%"\s+%\*/i);
|
|
54
|
+
return npm ? npm[2] : null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// A shim that forwards to a native executable: npm's shim for an .exe bin and
|
|
58
|
+
// pnpm's `@"<target>" %*` form. The executable is run directly.
|
|
59
|
+
export function parseWindowsExeShim(source) {
|
|
60
|
+
for (const line of source.split(/\r?\n/)) {
|
|
61
|
+
const match = line.match(/^[ \t]*@?"(?:%(?:dp0%|~dp0)\\?([^"\r\n]+\.exe)|([A-Za-z]:[\\/][^"\r\n]+\.exe))"[ \t]+%\*[ \t]*$/i);
|
|
62
|
+
if (match) return match[1] ?? match[2];
|
|
63
|
+
}
|
|
39
64
|
return null;
|
|
40
65
|
}
|
|
41
66
|
|
|
67
|
+
// Accept only a single shim-relative forwarding command, optionally preceded by
|
|
68
|
+
// @echo off. Never evaluate batch syntax or interpolate caller-controlled argv.
|
|
69
|
+
function parseWindowsNestedShim(source) {
|
|
70
|
+
const match = source.match(/^(?:@echo[ \t]+off[ \t]*\r?\n)?[ \t]*"%~dp0\\?([\w .@+\-\\/]+\.(?:cmd|bat))"[ \t]+%\*[ \t]*(?:\r?\n)?$/i);
|
|
71
|
+
return match?.[1] ?? null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function resolveWindowsNodeShim(executable, depth = 0, seen = new Set()) {
|
|
75
|
+
if (depth > 4) throw new Error("Windows command shim nesting too deep");
|
|
76
|
+
const normalized = resolve(executable);
|
|
77
|
+
if (seen.has(normalized.toLowerCase())) throw new Error("Windows command shim cycle");
|
|
78
|
+
seen.add(normalized.toLowerCase());
|
|
79
|
+
const stat = statSync(normalized);
|
|
80
|
+
if (!stat.isFile() || stat.size > 256 * 1024) {
|
|
81
|
+
throw new Error(`cannot safely launch Windows command shim: ${normalized}`);
|
|
82
|
+
}
|
|
83
|
+
const source = readFileSync(normalized, "utf8");
|
|
84
|
+
// Batch forwarding must match the whole wrapper, not a later Node command.
|
|
85
|
+
const nested = parseWindowsNestedShim(source);
|
|
86
|
+
const forwardsToBatch = /"[^"\r\n]+\.(?:cmd|bat)"[ \t]+%\*/i.test(source);
|
|
87
|
+
const jsTarget = forwardsToBatch ? null : parseWindowsNodeShim(source);
|
|
88
|
+
const exeTarget = forwardsToBatch || jsTarget ? null : parseWindowsExeShim(source);
|
|
89
|
+
const child = jsTarget ?? nested ?? exeTarget;
|
|
90
|
+
if (!child) throw new Error(`cannot safely launch non-Node Windows command shim: ${normalized}`);
|
|
91
|
+
const target = /^[A-Za-z]:[\\/]/.test(child)
|
|
92
|
+
? child
|
|
93
|
+
: resolve(dirname(normalized), ...child.split(/[\\/]+/));
|
|
94
|
+
if (!existsSync(target) || !statSync(target).isFile()) throw new Error(`Windows command shim target is missing: ${target}`);
|
|
95
|
+
return jsTarget || (!nested && exeTarget) ? target : resolveWindowsNodeShim(target, depth + 1, seen);
|
|
96
|
+
}
|
|
97
|
+
|
|
42
98
|
export function portableInvocation(command, args, platform = process.platform, env = process.env) {
|
|
43
99
|
if (platform !== "win32") return { command, args: [...args] };
|
|
44
100
|
const executable = resolveWindowsCommand(command, env) ?? command;
|
|
45
101
|
if (!/\.(?:cmd|bat)$/i.test(executable)) return { command: executable, args: [...args] };
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (!relativeScript) throw new Error(`non-Node Windows command shim: ${executable}`);
|
|
50
|
-
const script = /^[A-Za-z]:[\\/]/.test(relativeScript)
|
|
51
|
-
? relativeScript
|
|
52
|
-
: resolve(dirname(executable), ...relativeScript.split(/[\\/]+/));
|
|
53
|
-
if (!statSync(script).isFile()) throw new Error(`Windows command shim target missing: ${script}`);
|
|
54
|
-
return { command: process.execPath, args: [script, ...args] };
|
|
102
|
+
const target = resolveWindowsNodeShim(executable);
|
|
103
|
+
// A shim's target is a Node script to run under this Node, or a native executable.
|
|
104
|
+
return /\.exe$/i.test(target) ? { command: target, args: [...args] } : { command: process.execPath, args: [target, ...args] };
|
|
55
105
|
}
|
|
56
106
|
|
|
57
107
|
export function delegateSpawnOptions(platform = process.platform) {
|
|
@@ -28,6 +28,8 @@ export const RESERVED_VERBS = new Set([
|
|
|
28
28
|
"logout",
|
|
29
29
|
"mcp",
|
|
30
30
|
"mem",
|
|
31
|
+
"off",
|
|
32
|
+
"on",
|
|
31
33
|
"opportunities",
|
|
32
34
|
"plan",
|
|
33
35
|
"practices",
|
|
@@ -46,6 +48,7 @@ export const RESERVED_VERBS = new Set([
|
|
|
46
48
|
"start",
|
|
47
49
|
"stats",
|
|
48
50
|
"status",
|
|
51
|
+
"stop",
|
|
49
52
|
"sync",
|
|
50
53
|
"telemetry",
|
|
51
54
|
"tools",
|
package/dist/stats-cli.js
CHANGED
|
@@ -88,6 +88,8 @@ export function renderStatsSummary(report) {
|
|
|
88
88
|
lines.push(`Overhead regressions ${count(m.expanded_requests)} requests (included in net delta)`);
|
|
89
89
|
if (m.legacy_requests > 0)
|
|
90
90
|
lines.push(`Legacy segment reductions ${count(m.legacy_saved_tokens)} tokens / ${count(m.legacy_requests)} requests (separate)`);
|
|
91
|
+
if ((m.cache_warm_requests ?? 0) > 0)
|
|
92
|
+
lines.push(`Cache warms ${count(m.cache_warm_requests ?? 0)} sent by Caveman (tokens and spend included above)`);
|
|
91
93
|
if (m.unknown_auth_requests > 0)
|
|
92
94
|
lines.push(`Unknown billing ${count(m.unknown_auth_requests)} requests (excluded from money totals)`);
|
|
93
95
|
if (report.providers?.length) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caveman-ai/cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
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": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"typescript": "5.9.3"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
|
-
"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",
|
|
37
|
+
"build": "node scripts/gen-binaries.mjs && node scripts/gen-wedge-installer.mjs && node scripts/gen-device-auth.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",
|
|
38
38
|
"lint": "tsc --noEmit",
|
|
39
|
-
"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 --import ./tests/fixtures/sanitize-host-env.mjs --test --test-force-exit --test-concurrency=4 tests/*.runtime.mjs",
|
|
39
|
+
"test": "node scripts/gen-binaries.mjs && node scripts/gen-wedge-installer.mjs && node scripts/gen-device-auth.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 --import ./tests/fixtures/sanitize-host-env.mjs --test --test-force-exit --test-concurrency=4 tests/*.runtime.mjs",
|
|
40
40
|
"bench:native": "node scripts/benchmark-native-hooks.mjs",
|
|
41
|
-
"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 --import ./tests/fixtures/sanitize-host-env.mjs --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"
|
|
41
|
+
"test:fast": "node scripts/gen-binaries.mjs && node scripts/gen-wedge-installer.mjs && node scripts/gen-device-auth.mjs && node scripts/compile-registries.mjs && tsc && node scripts/bundle-delegate.mjs && node scripts/bundle-tui.mjs && node scripts/bundle-pi-extension.mjs && node --import ./tests/fixtures/sanitize-host-env.mjs --test --test-force-exit --test-concurrency=4 --test-reporter=dot tests/agent-native.runtime.mjs tests/agent-traffic.runtime.mjs tests/billing.runtime.mjs tests/capability-config.runtime.mjs tests/config-home.runtime.mjs tests/login-device-flow.runtime.mjs tests/login.runtime.mjs tests/mcp-surface.runtime.mjs tests/modules-apply.runtime.mjs tests/modules-index.runtime.mjs tests/modules-status.runtime.mjs tests/onboard-agent-door.runtime.mjs tests/onboard-interactive.runtime.mjs tests/onboard-setup.runtime.mjs tests/porcelain.runtime.mjs tests/practice-registry.runtime.mjs tests/routing.runtime.mjs tests/skills.runtime.mjs tests/status.runtime.mjs tests/subscription-recovery.runtime.mjs tests/wrap-gate.runtime.mjs"
|
|
42
42
|
}
|
|
43
43
|
}
|