@caveman-ai/cli 1.0.0 → 1.1.0

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 (2) hide show
  1. package/dist/index.js +98 -13
  2. package/package.json +6 -2
package/dist/index.js CHANGED
@@ -380,13 +380,16 @@ function invokedCommand(legacyVerb, groupedTail = "") {
380
380
  }
381
381
  let currentInvocation;
382
382
  currentInvocation = resolveInvocation(process.argv.slice(2));
383
- // Version 3 restores explicit opt-in. Every persisted older decision remains
384
- // authoritative; an undecided install stays off and writes nothing.
383
+ // Version 3 = default-on (opt-out): telemetry is on unless the user
384
+ // turns it off. A persisted decision from any version — including a "no" to the
385
+ // old v1 [y/N] prompt — is honored forever; the default only fills the
386
+ // undecided gap, and the first default-on run prints the disclosure line.
385
387
  const TELEMETRY_PROMPT_VERSION = 3;
386
388
  const TELEMETRY_URL = "https://api.caveman.so/telemetry/cli";
387
389
  // The production control-API origin — derived from TELEMETRY_URL (the CLI's
388
390
  // other hardcoded prod-host literal) so the two can never drift apart.
389
391
  const PROD_API_URL = new URL(TELEMETRY_URL).origin;
392
+ const TELEMETRY_DISCLOSURE_LINE = "anonymous usage stats on — command counts only, never prompts, code, or file paths · caveman telemetry off";
390
393
  const SYNC_DISCLOSURE = "sync uploads span metadata to your org's dashboard — tokens, cost, latency, model, status. Imported standalone observations never affect managed budgets, verified savings, or billing. Subscription/OAuth sessions carry token counts only — no dollar figure. Never prompt or response bytes.";
391
394
  const TELEMETRY_COMMAND_ALLOWLIST = [
392
395
  "agent", "audit", "billing", "browse", "compress", "convert", "costs", "deploy", "dev", "doctor", "evals", "experiments",
@@ -404,6 +407,7 @@ const TELEMETRY_START_MS = Date.now();
404
407
  let telemetryCommandSent = false;
405
408
  let telemetryEphemeralId = "";
406
409
  async function main() {
410
+ await ensureTelemetryDefault();
407
411
  try {
408
412
  await dispatch();
409
413
  emitCommandRunOnce("ok");
@@ -432,9 +436,12 @@ function telemetryState() {
432
436
  const cfg = telemetryConfigFromDisk();
433
437
  if (cfg?.decidedAt)
434
438
  return { state: cfg.enabled ? "on" : "off", source: "config", config: cfg };
435
- // No decision on disk: default OFF. Do not persist an identifier until the
436
- // user explicitly runs `caveman telemetry on` (or opts in via environment).
437
- return { state: "off", source: "default", config: undefined };
439
+ // No decision on disk: default ON (opt-out); only reachable interactively —
440
+ // the CI/non-TTY branch above already returned off. NOTHING may send while
441
+ // source is still "default": telemetrySendable gates every emitter, so the
442
+ // first real send always follows ensureTelemetryDefault's persist (stable
443
+ // anonymous id) + printed disclosure.
444
+ return { state: "on", source: "default", config: undefined };
438
445
  }
439
446
  // telemetrySendable is the single choke point every emitter must pass: on, and
440
447
  // never the un-persisted default (no silent sends, no ephemeral-id retention
@@ -476,6 +483,44 @@ function parseTelemetryConfig(value) {
476
483
  out.anonymousId = raw.anonymousId;
477
484
  return out;
478
485
  }
486
+ // ensureTelemetryDefault persists the default-on decision (with a stable
487
+ // anonymous id — retention counting is useless on ephemeral ids) the first time
488
+ // a real command runs interactively, and prints the one-line disclosure so the
489
+ // default is never silent. Env kills (DO_NOT_TRACK / CAVEMAN_TELEMETRY=0) and
490
+ // any persisted decision — including a "no" to the old v1 prompt — win.
491
+ async function ensureTelemetryDefault() {
492
+ const state = telemetryState();
493
+ if (isHelpLikeInvocation())
494
+ return;
495
+ // `caveman telemetry …` manages the decision explicitly — don't pre-mint an
496
+ // "on" for someone whose first-ever command is `telemetry off`.
497
+ if (currentInvocation.verb === "telemetry")
498
+ return;
499
+ if (state.source !== "default")
500
+ return;
501
+ const telemetry = {
502
+ enabled: true,
503
+ anonymousId: randomUUID(),
504
+ decidedAt: new Date().toISOString(),
505
+ promptVersion: TELEMETRY_PROMPT_VERSION,
506
+ };
507
+ // A failed persist must never block the command (read-only home, root-owned
508
+ // config). Nothing sends this run either way: source stays "default" until a
509
+ // persist succeeds, and telemetrySendable refuses un-persisted defaults.
510
+ try {
511
+ await saveTelemetryConfig(telemetry);
512
+ }
513
+ catch {
514
+ return;
515
+ }
516
+ process.stderr.write(`${dim(TELEMETRY_DISCLOSURE_LINE)}\n`);
517
+ }
518
+ function isHelpLikeInvocation() {
519
+ return currentInvocation.verb === "help"
520
+ || currentInvocation.verb === "version"
521
+ || currentInvocation.argv[0] === "--help"
522
+ || currentInvocation.argv[0] === "-h";
523
+ }
479
524
  // promptYesNo is the one line-buffered [y/N] reader. Ctrl-D / closed stdin
480
525
  // resolves as the default No, never hangs the CLI.
481
526
  function promptYesNo(question) {
@@ -2029,8 +2074,8 @@ function printInstallResult(installed, platform, binDir, json, continuing = fals
2029
2074
  async function setupInstall(json, options = {}) {
2030
2075
  const platform = setupPlatform();
2031
2076
  const timeoutSeconds = setupTimeoutSeconds();
2032
- const binDir = join(cavemanHome(), "bin");
2033
- mkdirSync(binDir, { recursive: true });
2077
+ const binDir = join(ensureCavemanHome(), "bin");
2078
+ mkdirSync(binDir, { recursive: true, mode: 0o700 });
2034
2079
  const local = verifiedLocalInstall(binDir);
2035
2080
  if (local) {
2036
2081
  printInstallResult(local, platform, binDir, json, options.continuing);
@@ -4597,13 +4642,39 @@ async function spawnWrapped(bin, cmdArgs, agent, opts, gw, codexSubscription = f
4597
4642
  for (const [signal, handler] of signalHandlers)
4598
4643
  process.removeListener(signal, handler);
4599
4644
  };
4600
- for (const signal of ["SIGHUP", "SIGINT", "SIGQUIT", "SIGTERM"]) {
4645
+ const wrapSignals = ["SIGHUP", "SIGINT", "SIGQUIT", "SIGTERM"];
4646
+ for (const signal of wrapSignals) {
4601
4647
  const handler = () => {
4602
- cleanupWrapTempDirs();
4603
- removeProxySessionMarker(sessionMarker);
4604
- child.kill(signal);
4648
+ // Forward the signal but defer cleanup and self-termination until the
4649
+ // child exits: deleting the wrap temp pack before the agent shuts down
4650
+ // races its SessionEnd hooks, which still read the plugin directory.
4605
4651
  removeSignalHandlers();
4606
- process.kill(process.pid, signal);
4652
+ const finish = () => {
4653
+ cleanupWrapTempDirs();
4654
+ removeProxySessionMarker(sessionMarker);
4655
+ process.kill(process.pid, signal);
4656
+ };
4657
+ // Escape hatch: a second signal, or a child that traps the first one,
4658
+ // must still clean up — the temp pack can hold copied agent
4659
+ // credentials (e.g. the Codex ephemeral home's auth.json), so dying
4660
+ // at default disposition without cleanup would strand them on disk.
4661
+ const escape = () => {
4662
+ removeSignalHandlers();
4663
+ child.kill("SIGKILL");
4664
+ finish();
4665
+ };
4666
+ for (const s of wrapSignals) {
4667
+ signalHandlers.set(s, escape);
4668
+ process.once(s, escape);
4669
+ }
4670
+ child.kill(signal);
4671
+ const grace = setTimeout(escape, 10_000);
4672
+ grace.unref();
4673
+ child.once("exit", () => {
4674
+ clearTimeout(grace);
4675
+ removeSignalHandlers();
4676
+ finish();
4677
+ });
4607
4678
  };
4608
4679
  signalHandlers.set(signal, handler);
4609
4680
  process.once(signal, handler);
@@ -8615,6 +8686,20 @@ export function wrapExternalWritesDisabled(env = process.env) {
8615
8686
  function cavemanHome() {
8616
8687
  return process.env.CAVEMAN_HOME ?? join(homedir(), ".caveman");
8617
8688
  }
8689
+ // ensureCavemanHome creates ~/.caveman itself with owner-only perms and repairs
8690
+ // an existing permissive mode. The proxy refuses CCR (sqlite parent check) when
8691
+ // this directory is group/world writable, and recursive mkdir with a mode only
8692
+ // applies it to directories it creates — an earlier no-mode caller (login, mcp
8693
+ // install) would otherwise have already created it 0775 under umask 002.
8694
+ function ensureCavemanHome() {
8695
+ const home = cavemanHome();
8696
+ mkdirSync(home, { recursive: true, mode: 0o700 });
8697
+ try {
8698
+ chmodSync(home, 0o700);
8699
+ }
8700
+ catch { /* not ours / Windows */ }
8701
+ return home;
8702
+ }
8618
8703
  // cavemanBin resolves one of caveman's own Go binaries (proxy/engine/mcp/browse):
8619
8704
  // explicit env override first, then PATH, then ~/.caveman/bin — the directory the
8620
8705
  // install script and the missing-binary panels tell users to build into, so
@@ -14293,7 +14378,7 @@ function credentialsPath() {
14293
14378
  return join(caveHome(), "credentials");
14294
14379
  }
14295
14380
  function fileTokenSet(token) {
14296
- mkdirSync(caveHome(), { recursive: true });
14381
+ ensureCavemanHome();
14297
14382
  try {
14298
14383
  chmodSync(credentialsPath(), 0o600);
14299
14384
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caveman-ai/cli",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
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",
@@ -20,7 +20,11 @@
20
20
  "caveman": "dist/index.js",
21
21
  "cave": "dist/index.js"
22
22
  },
23
- "files": ["dist", "README.md", "LICENSE"],
23
+ "files": [
24
+ "dist",
25
+ "README.md",
26
+ "LICENSE"
27
+ ],
24
28
  "scripts": {
25
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",
26
30
  "prepack": "npm run build",