worktrust 0.10.3 → 0.10.5

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 CHANGED
@@ -215,6 +215,10 @@ and counts, exactly as the session hook reads it.
215
215
 
216
216
  ## Rebuild the history
217
217
 
218
+ Since 0.10.5 there is one path: `npx worktrust@latest history` always re-measures and replaces this computer's earlier
219
+ lines day by day. If a send did not finish, or you merged two keys of one computer, run `npx worktrust@latest` again:
220
+ it finishes what did not arrive and never counts a day twice.
221
+
218
222
  A newer version of this command measures a session differently from an older one: what the seconds were (the model
219
223
  answering, tools running, your own turns, pauses), your own turns rather than every message, tokens with the cache,
220
224
  and more AI apps (Cursor, Copilot, Hermes, Goose, OpenCode, OpenClaw, Codex, Antigravity). Lines an earlier version
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "worktrust",
3
- "version": "0.10.3",
3
+ "version": "0.10.5",
4
4
  "description": "Couple this computer to WorkTrust: approve a code in your browser, and every AI app here reports what you built. Metadata only, no dependencies.",
5
5
  "type": "module",
6
6
  "bin": {
package/setup-mcp.mjs CHANGED
@@ -68,7 +68,16 @@ const masked = BRIDGE ? "kept in ~/.worktrust/key.json, not in these files" : `$
68
68
  const stdio = { command: NODE, args: [BRIDGE ?? "", "mcp"] };
69
69
  const home = homedir();
70
70
  /** Whether Claude Code's own command is on this machine: asked of the shell, never guessed from a file. */
71
- const onPath = (command) => spawnSync(platform() === "win32" ? "where" : "which", [command], { encoding: "utf8", shell: platform() === "win32" }).status === 0;
71
+ /**
72
+ * A COMMAND, RUN THE SAME WAY ON EVERY SYSTEM (0.10.4). On Windows `claude`, `openclaw` and `where` are .cmd shims that
73
+ * need a shell, and Node 24 warns (DEP0190) when arguments ride beside `shell: true` unescaped. So on Windows the line is
74
+ * built here, each argument quoted for cmd.exe, and handed over whole; elsewhere no shell is used at all.
75
+ */
76
+ const quoteForCmd = (arg) => (/^[\w@%+=:,./\\-]+$/.test(arg) ? arg : `"${String(arg).replace(/"/g, '\\"')}"`);
77
+ const runCommand = (command, args, options = {}) => (platform() === "win32"
78
+ ? spawnSync([command, ...args].map(quoteForCmd).join(" "), { encoding: "utf8", ...options, shell: true })
79
+ : spawnSync(command, args, { encoding: "utf8", ...options }));
80
+ const onPath = (command) => runCommand(platform() === "win32" ? "where" : "which", [command]).status === 0;
72
81
  const claudeOnPath = () => onPath("claude");
73
82
  const VIBE_DIR = process.env.VIBE_HOME?.trim() || join(home, ".vibe");
74
83
  const GROK_DIR = process.env.GROK_HOME?.trim() || join(home, ".grok");
@@ -214,7 +223,7 @@ for (const client of CLIENTS) {
214
223
  if (REMOVE ? !named : named && text.includes(JSON.stringify(BRIDGE ?? URL_).slice(1, -1)) && (BRIDGE === undefined || !text.includes(URL_))) { console.log(REMOVE ? ` – ${client.label}: does not name the door` : ` ✓ ${client.label}: already names the door (${client.file})`); if (!REMOVE) standing += 1; continue; }
215
224
  if (!WRITE) { console.log(` ${REMOVE ? "−" : "+"} ${client.label}: would run ${shown}`); continue; }
216
225
  if (!onPath("openclaw")) { console.log(` ! ${client.label}: the \`openclaw\` command is not on this machine's PATH; run ${shown}`); continue; }
217
- const run = spawnSync("openclaw", verb, { encoding: "utf8", shell: platform() === "win32" });
226
+ const run = runCommand("openclaw", verb);
218
227
  if (run.status === 0) { console.log(` ${REMOVE ? "−" : "+"} ${client.label}: ${REMOVE ? "removed" : "coupled"} through \`openclaw mcp ${REMOVE ? "unset" : "set"}\``); touched += 1; }
219
228
  else console.log(` ! ${client.label}: \`openclaw mcp\` refused (${(run.stderr || run.stdout || "").trim().split("\n")[0] || "no output"}); run it yourself: ${shown}`);
220
229
  continue;
@@ -232,11 +241,11 @@ for (const client of CLIENTS) {
232
241
  if (BRIDGE || REMOVE) for (const entry of direct.entries.filter((one) => !(REMOVE && one.name === NAME && one.scope === "user"))) {
233
242
  const verb = `claude mcp remove -s ${entry.scope} ${entry.name}`;
234
243
  if (!WRITE) { console.log(` ↻ ${client.label}: the direct entry "${entry.name}" (${entry.scope}) is replaced`); continue; }
235
- const out = claudeOnPath() ? spawnSync("claude", ["mcp", "remove", "-s", entry.scope, entry.name], { encoding: "utf8", shell: platform() === "win32", ...(entry.dir ? { cwd: entry.dir } : {}) }) : null;
244
+ const out = claudeOnPath() ? runCommand("claude", ["mcp", "remove", "-s", entry.scope, entry.name], entry.dir ? { cwd: entry.dir } : {}) : null;
236
245
  console.log(out?.status === 0 ? ` – ${client.label}: removed the direct entry "${entry.name}" (${entry.scope})` : ` ! ${client.label}: could not remove "${entry.name}"; run it yourself${entry.dir ? ` in ${entry.dir}` : ""}: ${verb}`);
237
246
  }
238
247
  if (WRITE && claudeOnPath()) {
239
- const run = spawnSync("claude", claudeArgs, { encoding: "utf8", shell: platform() === "win32" });
248
+ const run = runCommand("claude", claudeArgs);
240
249
  if (run.status === 0) { console.log(` + ${client.label}: ${REMOVE ? "removed" : "coupled"} through \`claude mcp ${REMOVE ? "remove" : "add"}\` (user scope)`); touched += 1; continue; }
241
250
  console.log(` ! ${client.label}: \`claude mcp\` refused (${(run.stderr || run.stdout || "").trim().split("\n")[0] || "no output"}); run it yourself: ${shown}`);
242
251
  continue;
package/worktrust.mjs CHANGED
@@ -10,7 +10,7 @@
10
10
  * npx worktrust@latest connect couple again, also on a computer already coupled
11
11
  * npx worktrust@latest update this computer onto the newest CLI, same key, no new pairing
12
12
  * npx worktrust@latest history send this computer's earlier sessions as history (asks first)
13
- * npx worktrust@latest history --rebuild re-measure them with the current rules; WorkTrust replaces this computer's
13
+ * npx worktrust@latest history --rebuild the same as history (0.10.5: history always re-measures); WorkTrust replaces this computer's
14
14
  * earlier lines day by day, never counting a day twice (shows the plan, asks first)
15
15
  * npx worktrust@latest history --from-archive [dir] send what your local archive holds of sessions your AI apps have
16
16
  * already deleted, marked as from your archive (shows the plan, asks first)
@@ -73,7 +73,7 @@ const command = args.find((arg, at) => !arg.startsWith("--") && !(at > 0 && VALU
73
73
  const flag = (name) => { const at = args.indexOf(`--${name}`); return at >= 0 ? args[at + 1] : undefined; };
74
74
  const has = (name) => args.includes(`--${name}`);
75
75
  /** This CLI's version, said to the door so the app can tell which computer runs an old one (check-cli-package holds it equal to package.json). */
76
- const CLI_VERSION = "0.10.3";
76
+ const CLI_VERSION = "0.10.5";
77
77
  const ORIGIN = (flag("origin") ?? process.env.WORKTRUST_ORIGIN ?? "https://app.worktrust.io").replace(/\/$/, "");
78
78
  const MCP = flag("url") ?? process.env.WORKTRUST_MCP_URL ?? `${ORIGIN}/api/mcp`;
79
79
  const HOME_DIR = join(homedir(), ".worktrust");
@@ -593,7 +593,8 @@ async function connect() {
593
593
 
594
594
  // The device key: made here, its private half kept with the key, its public half bound at WorkTrust.
595
595
  const device = direct ? null : generateKeyPairSync("ed25519");
596
- const apps = foundApps.map((line) => /^\s*[↻+✓] ([^:]+):/.exec(line)?.[1]).filter(Boolean).slice(0, 12);
596
+ // Claude Code is coupled through its own command, so its plan line reads "! … couple with": it is coupled all the same (0.10.4).
597
+ const apps = foundApps.map((line) => /^\s*(?:[↻+✓] ([^:]+):|! ([^:]+): couple with)/.exec(line)).map((match) => match?.[1] ?? match?.[2]).filter(Boolean).slice(0, 12);
597
598
  const extra = { apps, ...computerIds(), ...(device ? { device_key: device.publicKey.export({ format: "jwk" }).x } : {}) };
598
599
  const pairing = useDevice() ? await pairByCode(host, extra) : await pairByBrowser(host, extra);
599
600
  const { token } = pairing;
@@ -622,7 +623,7 @@ async function connect() {
622
623
  await offerCodex();
623
624
  await offerAntigravity();
624
625
  if (switched) { say(); say(" Earlier work on this computer is not offered: it was coupled to another account before. Only work from now on goes to this account."); }
625
- else await offerHistory(paths, token, device ? device.privateKey.export({ format: "pem", type: "pkcs8" }) : null);
626
+ else await offerHistory(paths, token, device ? device.privateKey.export({ format: "pem", type: "pkcs8" }) : null, MCP, true);
626
627
  say();
627
628
  // ONE LINE, NO CHANGE (2026-10-06): Claude Code deletes what the hook measures from; `preserve --apply` keeps it, on a yes.
628
629
  const keeps = claudeKeepsDays();
@@ -643,7 +644,7 @@ async function offerHistory(paths, token, devicePem, url = MCP, rebuild = false)
643
644
  let found = null;
644
645
  try { found = JSON.parse(counted.out.trim().split("\n").pop()); } catch { /* no line: nothing to offer */ }
645
646
  say();
646
- if (!found?.sessions) { say(rebuild ? " Your AI apps hold no earlier sessions on this computer to re-measure." : " Your AI apps hold no earlier sessions on this computer to send."); return; }
647
+ if (!found?.sessions) { historyDone(true); say(rebuild ? " Your AI apps hold no earlier sessions on this computer to re-measure." : " Your AI apps hold no earlier sessions on this computer to send."); return; }
647
648
  say(` This computer holds ${found.sessions} earlier sessions of your AI apps · ${found.hours} measured hours · ${found.first} … ${found.last}.`);
648
649
  // REBUILD (owner, 2026-10-07): the plan per AI app, in days and hours, and what it replaces, before the one question. Enter is No.
649
650
  if (rebuild) {
@@ -653,10 +654,11 @@ async function offerHistory(paths, token, devicePem, url = MCP, rebuild = false)
653
654
  say(" never deleted, so a day is counted once. Other computers, web sources and days not listed are not touched.");
654
655
  }
655
656
  if (has("dry-run")) { say(" Dry run: nothing was sent."); return; }
656
- if (!has("history") && !(rebuild ? await ask("Rebuild the history (replaces this computer's earlier lines for these days)?", false) : await ask("Send these as history (hours and tokens per day; never text)?", false))) { say(rebuild ? " Not sent. Rebuild later with: npx worktrust@latest history --rebuild" : " Not sent. Send them later with: npx worktrust@latest history"); return; }
657
+ if (!has("history") && !(rebuild ? await ask("Send them (re-measured; this computer's earlier lines for these days are replaced, a day is counted once)?", false) : await ask("Send these as history (hours and tokens per day; never text)?", false))) { historyDone(false); say(" Not sent. Send them later with: npx worktrust@latest"); return; }
657
658
  const sent = await run(paths["log-session.mjs"], ["--history", ...(rebuild ? ["--rebuild"] : [])], token, true, env);
658
- if (rebuild) say(sent.code === 0 ? " ✓ Rebuilt. This computer's earlier lines for those days were replaced; the record shows each replacement." : " Not all of it arrived. Run npx worktrust@latest history --rebuild again: a day already rebuilt is counted once.");
659
- else say(sent.code === 0 ? " ✓ Sent as history. It shows in WorkTrust as earlier work, never as verified hours." : " Not all of it arrived. Run npx worktrust@latest history again: a line already received is kept once.");
659
+ historyDone(sent.code === 0);
660
+ if (rebuild) say(sent.code === 0 ? " ✓ Rebuilt. This computer's earlier lines for those days were replaced; the record shows each replacement." : " Not all of it arrived. Run npx worktrust@latest again: it finishes what did not arrive, a day already rebuilt is counted once.");
661
+ else say(sent.code === 0 ? " ✓ Sent as history. Measured sessions count toward your verified hours; a day WorkTrust already holds is kept once." : " Not all of it arrived. Run npx worktrust@latest history again: a line already received is kept once.");
660
662
  }
661
663
 
662
664
  /** The version stamped in the stable copy in ~/.worktrust, the CLI this computer ran before an update; null without one. */
@@ -675,16 +677,47 @@ async function offerRebuild(previousVersion, paths, key) {
675
677
  say(" differently (each answer's tokens counted once, nothing lost at midnight, when each stretch began, how you steered");
676
678
  say(" the agent, what the seconds were, more AI apps). You can re-measure the");
677
679
  say(" sessions still on this computer and have WorkTrust replace this computer's earlier lines, day by day, never counting");
678
- say(" a day twice. Later: npx worktrust@latest history --rebuild");
680
+ say(" a day twice. Later: npx worktrust@latest");
679
681
  if (!(await ask("Show the plan and rebuild now?", false))) { say(" Not now."); return; }
680
682
  await offerHistory(paths, key.token, key.device ?? null, key.url, true);
681
683
  }
682
684
 
685
+ /**
686
+ * WHETHER THE HISTORY ARRIVED (0.10.5, owner: "someone with little experience never knows to rebuild"). Written after each
687
+ * send: complete when every batch arrived or there was nothing to send. Only the outcome and the version, never a session.
688
+ */
689
+ const HISTORY_STATE = join(HOME_DIR, "history.json");
690
+ function historyDone(complete) {
691
+ try { ensureHome(); writeFileSync(HISTORY_STATE, JSON.stringify({ version: CLI_VERSION, at: new Date().toISOString(), complete }), { mode: 0o600 }); } catch { /* the next run asks again */ }
692
+ }
693
+ const historyComplete = () => { try { return JSON.parse(readFileSync(HISTORY_STATE, "utf8")).complete === true; } catch { return false; } };
694
+
695
+ /**
696
+ * THE SAME COMMAND AGAIN DOES WHAT IS LEFT (0.10.5). On a computer already coupled, `npx worktrust@latest` brings it onto
697
+ * this CLI when an earlier one is installed (the update, which also offers the re-measure), else finishes the history
698
+ * when it never arrived whole (a failed send, a question answered No, a computer coupled before this marker existed);
699
+ * then says what is coupled. Each step still shows its plan and asks; Enter is No.
700
+ */
701
+ async function again() {
702
+ const before = stableVersion();
703
+ if (before && before !== CLI_VERSION) { await update(); return; }
704
+ if (!historyComplete()) {
705
+ const key = await freshKey();
706
+ if (key) { say(); say(" Your earlier sessions have not all reached WorkTrust from this computer yet. This finishes them."); await offerHistory(await scripts(), key.token, key.device ?? null, key.url, true); }
707
+ }
708
+ say();
709
+ await status();
710
+ say();
711
+ say(" This computer is coupled. `npx worktrust@latest connect` couples it again; `npx worktrust@latest disconnect` takes it out.");
712
+ }
713
+
683
714
  async function history() {
684
715
  const key = await freshKey();
685
716
  if (!key) fail("this computer is not coupled through the key file. Run npx worktrust first.");
686
717
  if (has("from-archive")) return offerArchive(await scripts(), key);
687
- await offerHistory(await scripts(), key.token, key.device ?? null, key.url, has("rebuild"));
718
+ // ONE PATH (0.10.5): sending is re-measuring. On a computer WorkTrust has never heard from nothing is replaced, so it is a
719
+ // plain send; after a failure, a merge or an older CLI, the same command replaces day by day. `--rebuild` still reads.
720
+ await offerHistory(await scripts(), key.token, key.device ?? null, key.url, true);
688
721
  }
689
722
 
690
723
  /**
@@ -953,7 +986,7 @@ if (agentShell && PERSON_ONLY.has(command)) {
953
986
  process.exit(3);
954
987
  }
955
988
 
956
- if (command === "default") { if (keyStore.load()) { status(); say(); say(" This computer is coupled. `npx worktrust@latest connect` couples it again; `npx worktrust@latest disconnect` takes it out."); } else await connect(); }
989
+ if (command === "default") { if (keyStore.load()) await again(); else await connect(); }
957
990
  else if (command === "mcp") await bridge();
958
991
  else if (command === "hook") await hook();
959
992
  else if (command === "connect") await connect();