worktrust 0.10.4 → 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.4",
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/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.4";
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");
@@ -623,7 +623,7 @@ async function connect() {
623
623
  await offerCodex();
624
624
  await offerAntigravity();
625
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."); }
626
- 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);
627
627
  say();
628
628
  // ONE LINE, NO CHANGE (2026-10-06): Claude Code deletes what the hook measures from; `preserve --apply` keeps it, on a yes.
629
629
  const keeps = claudeKeepsDays();
@@ -644,7 +644,7 @@ async function offerHistory(paths, token, devicePem, url = MCP, rebuild = false)
644
644
  let found = null;
645
645
  try { found = JSON.parse(counted.out.trim().split("\n").pop()); } catch { /* no line: nothing to offer */ }
646
646
  say();
647
- 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; }
648
648
  say(` This computer holds ${found.sessions} earlier sessions of your AI apps · ${found.hours} measured hours · ${found.first} … ${found.last}.`);
649
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.
650
650
  if (rebuild) {
@@ -654,9 +654,10 @@ async function offerHistory(paths, token, devicePem, url = MCP, rebuild = false)
654
654
  say(" never deleted, so a day is counted once. Other computers, web sources and days not listed are not touched.");
655
655
  }
656
656
  if (has("dry-run")) { say(" Dry run: nothing was sent."); return; }
657
- 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; }
658
658
  const sent = await run(paths["log-session.mjs"], ["--history", ...(rebuild ? ["--rebuild"] : [])], token, true, env);
659
- 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
+ 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.");
660
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.");
661
662
  }
662
663
 
@@ -676,16 +677,47 @@ async function offerRebuild(previousVersion, paths, key) {
676
677
  say(" differently (each answer's tokens counted once, nothing lost at midnight, when each stretch began, how you steered");
677
678
  say(" the agent, what the seconds were, more AI apps). You can re-measure the");
678
679
  say(" sessions still on this computer and have WorkTrust replace this computer's earlier lines, day by day, never counting");
679
- say(" a day twice. Later: npx worktrust@latest history --rebuild");
680
+ say(" a day twice. Later: npx worktrust@latest");
680
681
  if (!(await ask("Show the plan and rebuild now?", false))) { say(" Not now."); return; }
681
682
  await offerHistory(paths, key.token, key.device ?? null, key.url, true);
682
683
  }
683
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
+
684
714
  async function history() {
685
715
  const key = await freshKey();
686
716
  if (!key) fail("this computer is not coupled through the key file. Run npx worktrust first.");
687
717
  if (has("from-archive")) return offerArchive(await scripts(), key);
688
- 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);
689
721
  }
690
722
 
691
723
  /**
@@ -954,7 +986,7 @@ if (agentShell && PERSON_ONLY.has(command)) {
954
986
  process.exit(3);
955
987
  }
956
988
 
957
- 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(); }
958
990
  else if (command === "mcp") await bridge();
959
991
  else if (command === "hook") await hook();
960
992
  else if (command === "connect") await connect();