worktrust 0.10.23 → 0.10.24

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
@@ -1,5 +1,19 @@
1
1
  # worktrust
2
2
 
3
+ ## Candidate 0.10.24: delivery and account limits
4
+
5
+ Not published yet. After an approved update, WorkTrust receives the running version without
6
+ an activity upload. Pending metadata batches can be resumed with `worktrust history --resume`,
7
+ even after an AI app removed the original session files. Review-held revisions need review;
8
+ reconnecting does not approve them. Keep archives for work that was never queued.
9
+
10
+ The corresponding server candidate limits new personal registrations to five active device
11
+ identities. AI apps sharing one key share one slot; cloned keys share account upload capacity.
12
+ Retiring a device preserves earlier data. Existing accounts above the limit are preserved but
13
+ cannot add another identity. Version labels and device signatures are not independent evidence
14
+ of time or correctness. A CLI update does not automatically publish a passport.
15
+
16
+
3
17
  Couple a computer to [WorkTrust](https://worktrust.io) in one command. WorkTrust keeps a verified
4
18
  record of the work you do with AI without anyone reading that work: it receives metadata only.
5
19
 
@@ -1 +1 @@
1
- {"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"chat-exports.mjs":"04eafe333940ec03d5058d8d51062124aa12ab882bf04db03bcda5613ec69298","claude-mod.mjs":"02d86b0cdddf39879efc5194c0a5be6b41456faedec28963dc123a4e88dc3942","config-edits.mjs":"0eba2f176ef6f7afba071d6e00de0ff19ba2b283180a801dfd957aa38c1edd94","count-behaviour.mjs":"1beaec2a4d0aead76d166f89cc52441a9cf48f2e69da9888ca2091dd3a10a37b","log-session.mjs":"b99f082a58f0a92375026f52b62eb72173f06614b844e3def06b3ed40942b103","orchestration-contract.mjs":"ec08f303a166365b99e70b675de4cfe76c6156c2567e14b5569f6d992f0231b7","orchestration-evidence.mjs":"d0d06cecf0eb08e5c6e653c62a4f45b1eddf2119c2acb8341056b34f488d214a","orchestration-report.mjs":"d4e0a9ad8e4a01b462d22c6b1866aac291565c533ff476085d3367cb6d59bc1b","package-integrity.mjs":"b9d81dc88cf5c19ccfbf334a7af84a0c4e299a0e9e4d4091132253e22f855dc3","preserve-lines.mjs":"18081b745b8c47838448b0a49a129a363e29d3f2f5207bc591187d860157b456","preserve-summary.mjs":"137f781ed7021596a3f0ea67afcf2ab8616ac293f833dbb8f176e838e0ed8321","preserve.mjs":"38f83bd933853a986fef61f4e452c27d4a3adc6000f5c9201ef70f270b404eac","runtime-install.mjs":"b9d2e4febbf400a679eeb3a14b74eef6c2062c5b626d45872a193b7502d3201c","session-databases.mjs":"543fd3b82d28d96d789be0a1dc9186c5fafa783e98b87e5b3b17b211542e2b4d","setup-mcp.mjs":"70f63b61cf1e28fb2b7471e7768d596b0cf166ccdc9d1ce859ee58d29b2ecabc","stack-rules.mjs":"b23c56e72ec56ba02b17ed895f869172d988c468a697e8d6026b0e268f61e489","stretch-evidence.mjs":"5b31a6f29b785d277e92257532f3c7cee366a79759decc7a75cfbaec2686ee13","transcript-readers.mjs":"413948644a74dc0bf1b49548be193bf596bcf82ac7eae668f624345a18e189e7","worktrust-launch.mjs":"f28f699f986c72d99af8a7542d317f6dbb9e26d114f6ad083013567e08b8a650","worktrust.mjs":"b563a702634b41c064fdd0b6ad842c77ff851dfcf682b370c677114f8f75c061"},"format":"worktrust-package/1","kind":"engine","version":"0.10.23"},"signature":"g-Lbodi3WAsZnCC1kW05ecOXhxXCNgSITU67By6g3zJMQB5T7ksGWIO5FIP1d1Yf3IP5PlCyMTiJjm0C__8wCg"}
1
+ {"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"chat-exports.mjs":"04eafe333940ec03d5058d8d51062124aa12ab882bf04db03bcda5613ec69298","claude-mod.mjs":"02d86b0cdddf39879efc5194c0a5be6b41456faedec28963dc123a4e88dc3942","config-edits.mjs":"0eba2f176ef6f7afba071d6e00de0ff19ba2b283180a801dfd957aa38c1edd94","count-behaviour.mjs":"1beaec2a4d0aead76d166f89cc52441a9cf48f2e69da9888ca2091dd3a10a37b","history-outbox.mjs":"1bdca17b807c76e4a8e7bf42c6f07e12e8ae8e4466417cafdd26b1f58bf178a5","log-session.mjs":"6098eedb253b165819fdb4293adb6ddaa6c5843db0bbb007759701918955f664","orchestration-contract.mjs":"ec08f303a166365b99e70b675de4cfe76c6156c2567e14b5569f6d992f0231b7","orchestration-evidence.mjs":"d0d06cecf0eb08e5c6e653c62a4f45b1eddf2119c2acb8341056b34f488d214a","orchestration-report.mjs":"d4e0a9ad8e4a01b462d22c6b1866aac291565c533ff476085d3367cb6d59bc1b","package-integrity.mjs":"b9d81dc88cf5c19ccfbf334a7af84a0c4e299a0e9e4d4091132253e22f855dc3","preserve-lines.mjs":"18081b745b8c47838448b0a49a129a363e29d3f2f5207bc591187d860157b456","preserve-summary.mjs":"137f781ed7021596a3f0ea67afcf2ab8616ac293f833dbb8f176e838e0ed8321","preserve.mjs":"38f83bd933853a986fef61f4e452c27d4a3adc6000f5c9201ef70f270b404eac","runtime-install.mjs":"b9d2e4febbf400a679eeb3a14b74eef6c2062c5b626d45872a193b7502d3201c","session-databases.mjs":"543fd3b82d28d96d789be0a1dc9186c5fafa783e98b87e5b3b17b211542e2b4d","setup-mcp.mjs":"70f63b61cf1e28fb2b7471e7768d596b0cf166ccdc9d1ce859ee58d29b2ecabc","stack-rules.mjs":"b23c56e72ec56ba02b17ed895f869172d988c468a697e8d6026b0e268f61e489","stretch-evidence.mjs":"5b31a6f29b785d277e92257532f3c7cee366a79759decc7a75cfbaec2686ee13","transcript-readers.mjs":"413948644a74dc0bf1b49548be193bf596bcf82ac7eae668f624345a18e189e7","worktrust-launch.mjs":"f28f699f986c72d99af8a7542d317f6dbb9e26d114f6ad083013567e08b8a650","worktrust.mjs":"c1cce642ba2ef4099b0fc3d375a4f8e8cb669b6694b0c99f08164a38d5d943d9"},"format":"worktrust-package/1","kind":"engine","version":"0.10.24"},"signature":"P-IcgjGPwCdX-87Wlbc23kMzU2cCdBr15y84UdbYqJX7miLCLqdQX_gLaYrj7GdyqxwvBP2ryBtCQMm8LjTlDA"}
@@ -0,0 +1,93 @@
1
+ /** Local metadata queue. Never reads transcripts, credentials or the network; preserve does not load it. */
2
+ import {createHash,randomBytes} from 'node:crypto';
3
+ import {existsSync,lstatSync,mkdirSync,readdirSync,readFileSync,openSync,writeFileSync,fsyncSync,closeSync,renameSync,unlinkSync,constants} from 'node:fs';
4
+ import {join} from 'node:path';
5
+ import {homedir} from 'node:os';
6
+ const MAX_RETRY_SECONDS=24*60*60;
7
+ const digest=s=>createHash('sha256').update(s).digest('hex');
8
+ const scopeOf=target=>digest(target.url+'\0'+(target.token===process.env.WORKTRUST_MCP_TOKEN && /^[a-f0-9]{64}$/.test(process.env.WORKTRUST_HISTORY_SCOPE??'') ? 'device:'+process.env.WORKTRUST_HISTORY_SCOPE : 'token:'+target.token));
9
+ const regular=p=>{const s=lstatSync(p);if(s.isSymbolicLink()||!s.isFile())throw Error('HISTORY_QUEUE_UNSAFE');return s;};
10
+ function directory(p) {if(!existsSync(p))mkdirSync(p,{mode:0o700});const s=lstatSync(p);if(s.isSymbolicLink()||!s.isDirectory())throw Error('HISTORY_QUEUE_UNSAFE');}
11
+ function write(p,value) {
12
+ const temporary=p+'.'+randomBytes(8).toString('hex')+'.tmp';
13
+ const fd=openSync(temporary,constants.O_CREAT|constants.O_EXCL|constants.O_WRONLY|(constants.O_NOFOLLOW??0),0o600);
14
+ try {writeFileSync(fd,JSON.stringify(value));fsyncSync(fd);}finally{closeSync(fd);}
15
+ try {if(existsSync(p))regular(p);renameSync(temporary,p);}finally{if(existsSync(temporary))unlinkSync(temporary);}
16
+ }
17
+ /** Serialize local space reservations; never wait in a hook for another process. */
18
+ function reservation(root,run) {
19
+ const path=join(root,'.reservation');let fd;
20
+ try {fd=openSync(path,constants.O_CREAT|constants.O_EXCL|constants.O_WRONLY,0o600);}
21
+ catch(error) {
22
+ if(error.code!=='EEXIST')throw error;
23
+ const lock=read(path),before=regular(path);
24
+ if(!Number.isSafeInteger(lock?.pid)||lock.pid<=0)throw Error('HISTORY_QUEUE_BUSY');
25
+ try{process.kill(lock.pid,0);throw Error('HISTORY_QUEUE_BUSY');}
26
+ catch(error){if(error.code!=='ESRCH')throw Error('HISTORY_QUEUE_BUSY');}
27
+ if(regular(path).ino!==before.ino)throw Error('HISTORY_QUEUE_BUSY');
28
+ unlinkSync(path);return reservation(root,run);
29
+ }
30
+ try{writeFileSync(fd,JSON.stringify({pid:process.pid}));fsyncSync(fd);return run();}
31
+ finally{closeSync(fd);unlinkSync(path);}
32
+ }
33
+ function read(p) {if(!existsSync(p))return null;if(regular(p).size>4_500_000)throw Error('HISTORY_QUEUE_UNSAFE');return JSON.parse(readFileSync(p,'utf8'));}
34
+ export function queuedHistory(target,body,source) {
35
+ const home=join(homedir(),'.worktrust');directory(home);
36
+ const root=join(home,'history-outbox');directory(root);
37
+ // No bearer, endpoint, local path or user content is stored as an identifier.
38
+ const scope=scopeOf(target),id=digest(scope+'\0'+source+'\0'+body);
39
+ const request=join(root,id+'.request.json'),ack=join(root,id+'.ack.json'),state=join(root,id+'.state.json');
40
+ const acknowledged=read(ack);
41
+ if(acknowledged?.id===id)return {status:'acknowledged',confirm(){},defer(){}};
42
+ const current=read(state);
43
+ reservation(root,()=>{
44
+ if(!existsSync(request)) {
45
+ const files=readdirSync(root);let bytes=0,pending=0;
46
+ for(const file of files) {const stat=regular(join(root,file));bytes+=stat.size;if(file.endsWith('.request.json'))pending++;}
47
+ if(files.length>=12000||pending>=512||bytes+Buffer.byteLength(JSON.stringify({id,scope,source,body}))+1024>64*1024*1024)throw Error('HISTORY_QUEUE_FULL');
48
+ write(request,{id,scope,source,body});
49
+ } else if(read(request)?.body!==body)throw Error('HISTORY_QUEUE_CHANGED');
50
+ });
51
+ const status=current?.status==='review'?'review':Number(current?.retryAt)>Date.now()?'waiting':'pending';
52
+ return {status,retryAt:current?.retryAt??null,
53
+ confirm(){write(ack,{id,confirmedAt:new Date().toISOString()});if(existsSync(request)){regular(request);unlinkSync(request);}if(existsSync(state)){regular(state);unlinkSync(state);}},
54
+ defer(reason,seconds=0){if(existsSync(ack))return;write(state,{id,status:reason==='review'?'review':'retry',retryAt:Date.now()+Math.max(0,Math.min(MAX_RETRY_SECONDS,seconds))*1000});},
55
+ };
56
+ }
57
+ export function historyRefusal(text,response) {
58
+ let rpc;
59
+ try {rpc=JSON.parse(text.trim().startsWith('{')?text:text.split(/\r?\n/).find(s=>s.startsWith('data:'))?.slice(5));}catch{/* Unknown reply stays retryable, never acknowledged. */}
60
+ const review=rpc?.id===1 && (rpc?.error?.data?.outcome==='review' || String(rpc?.error?.message??'').startsWith('history replacement held for review:'));
61
+ const raw=Number(response.headers.get('retry-after'));
62
+ return {reason:review?'review':response.status===429?'capacity':'unconfirmed',seconds:Number.isFinite(raw)&&raw>0?Math.min(MAX_RETRY_SECONDS,raw):0};
63
+ }
64
+
65
+ /** Explicit recovery, even after the AI client removed its source files. A changed account/key
66
+ * cannot replay another coupling's pending data. Review is retried only on an explicit request. */
67
+ export async function resumeHistory(target, {send, confirmed, note, retryReview=false, dry=false}) {
68
+ const root=join(homedir(),'.worktrust','history-outbox'),scope=scopeOf(target);
69
+ const totals={received:0,review:0,waiting:0,batches:0};let paused=null;
70
+ if(!existsSync(root))return totals;
71
+ directory(root);
72
+ const files=readdirSync(root);if(files.length>12000)throw Error('HISTORY_QUEUE_FULL');
73
+ for(const file of files.sort()) {
74
+ if(!/^[a-f0-9]{64}\.request\.json$/.test(file))continue;
75
+ const item=read(join(root,file));if(item?.scope!==scope)continue;
76
+ if(typeof item.body!=='string'||typeof item.source!=='string'||item.id!==digest(scope+'\0'+item.source+'\0'+item.body)||file!==item.id+'.request.json')throw Error('HISTORY_QUEUE_CHANGED');
77
+ const rpc=JSON.parse(item.body),entries=rpc?.params?.arguments?.entries;
78
+ if(rpc.jsonrpc!=='2.0'||rpc.id!==1||rpc.method!=='tools/call'||rpc.params.name!=='import_history'||!Array.isArray(entries)||!entries.length||entries.length>200)throw Error('HISTORY_QUEUE_CHANGED');
79
+ const queued=queuedHistory(target,item.body,item.source);totals.batches++;
80
+ if(queued.status==='acknowledged')continue;
81
+ if(queued.status==='review'&&!retryReview){totals.review+=entries.length;continue;}
82
+ if(dry){totals.waiting+=entries.length;continue;}
83
+ if(queued.status==='waiting'&&!paused)paused={reason:'unconfirmed',seconds:Math.max(1,Math.ceil((queued.retryAt-Date.now())/1000))};
84
+ if(paused){if(queued.status==='review'){totals.review+=entries.length;continue;}queued.defer(paused.reason,paused.seconds);totals.waiting+=entries.length;continue;}
85
+ try {
86
+ const response=await send(item.body,item.source),text=await response.text();
87
+ try{if(!response.ok)throw Error();confirmed(text,entries.length);}
88
+ catch{const refusal=historyRefusal(text,response);if(refusal.reason!=='review')paused={reason:refusal.reason,seconds:refusal.seconds>0?refusal.seconds:5};queued.defer(refusal.reason,paused?.seconds??refusal.seconds);totals[refusal.reason==='review'?'review':'waiting']+=entries.length;continue;}
89
+ queued.confirm();totals.received+=entries.length;note(text);
90
+ }catch{paused={reason:'unconfirmed',seconds:5};queued.defer(paused.reason,paused.seconds);totals.waiting+=entries.length;}
91
+ }
92
+ return totals;
93
+ }
package/log-session.mjs CHANGED
@@ -90,12 +90,7 @@ const PINNED = join(homedir(), ".worktrust", "pinned");
90
90
  const ours = (command) => /log-session|worktrust\.mjs" hook|worktrust\.mjs hook/.test(String(command ?? ""));
91
91
  const COUNTER_EVERY_MS = 24 * 3600_000;
92
92
  /**
93
- * THE COUNTER KEEPS UP WITH THE DEPLOYMENT. The install fetched it once and never again, so a
94
- * machine set up in August counted with an August rubric in September while the door already
95
- * spoke a newer vocabulary. Now the version stamped in the local copy is compared with the one the
96
- * deployment serves — numerically, the way the door picks its newest rubric — and a newer copy
97
- * replaces the old one. A rubric bump is what makes the previous reading superseded on the
98
- * mirror; this is how the machine hears about it. Nothing else is read off the network here.
93
+ * Counter compatibility is pinned by the verified release.
99
94
  */
100
95
  const versionOf = (text) => /export const ANALYZER_VERSION = "counter@(\d+)\.(\d+)\.(\d+)"/.exec(text ?? "")?.slice(1, 4).map(Number) ?? null;
101
96
  const newer = (a, b) => { if (!a || !b) return false; for (let i = 0; i < 3; i += 1) { if (a[i] === b[i]) continue; return a[i] > b[i]; } return false; };
@@ -258,7 +253,7 @@ const { stackOfFiles = () => [], displayStackOfFiles = () => [] } = (await impor
258
253
  const EXPORT_PATHS = []; for (let i = 0; i < args.length; i += 1) if (args[i] === "--export" && args[i + 1]) EXPORT_PATHS.push(args[i + 1]);
259
254
  const DATABASE_CLIENTS = ["hermes", "goose", "opencode", "openclaw", "cursor", "copilot"]; // the registry's keys, the name each line carries
260
255
  const LIVE_SOURCE = new RegExp(`^(codex|antigravity|${DATABASE_CLIENTS.join("|")}):`); // a sweep entry's id → the client it names (every database client, 0.6.16)
261
- const READER_FILES = ["transcript-readers.mjs", "session-databases.mjs", "stretch-evidence.mjs", "chat-exports.mjs", "stack-rules.mjs", "claude-mod.mjs"]; // 0.7.4: the derived record travels with the hook; 0.10.10: the export reader; 0.10.11: the stack rules; 0.10.15: the mod
256
+ const READER_FILES = ["history-outbox.mjs", "transcript-readers.mjs", "session-databases.mjs", "stretch-evidence.mjs", "chat-exports.mjs", "stack-rules.mjs", "claude-mod.mjs"]; // 0.7.4: the derived record travels with the hook; 0.10.10: the export reader; 0.10.11: the stack rules; 0.10.15: the mod
262
257
  /** The readers go where the hook and the counter run: copied from beside this file, else (or for a newer counter) from the deployment. */
263
258
  async function installReaders(origin, fromNetwork = false) {
264
259
  let installed = true;
@@ -735,31 +730,44 @@ function retainMeasurement(payload, source) {
735
730
  }
736
731
  } finally { closeSync(fd); unlinkSync(temporary); }
737
732
  }
733
+ const HISTORY_DELIVERY = { review: 0, waiting: 0 };
738
734
  async function sendHistory(door, entries, announce = false, rebuild = false, named = false, { byDay = false, withdrawUnknown = false } = {}) {
739
735
  let accepted = 0;
740
- // A Codex entry goes through Codex's own coupling where one exists (see codexDoor), the rest
741
- // through the door given: the record files a line under the coupling that sent it. Antigravity's
742
- // go apart too, so their batch can name the client (clientOf).
743
- // An export's lines go as their own group too (0.10.10), so the record names the product (ChatGPT, Claude on the web).
744
- for (const [source, group] of [["claude", entries.filter((entry) => !entrySource.has(entry))], ["codex", entries.filter((entry) => entrySource.get(entry) === "codex")], ...["antigravity", ...DATABASE_CLIENTS, ...EXPORT_CLIENTS].map((client) => [client, entries.filter((entry) => entrySource.get(entry) === client)])]) {
736
+ const { queuedHistory, historyRefusal } = await import("./history-outbox.mjs");
737
+ // Keep each source and its approved coupling separate.
738
+ const groups = [["claude", entries.filter((entry) => !entrySource.has(entry))], ["codex", entries.filter((entry) => entrySource.get(entry) === "codex")], ...["antigravity", ...DATABASE_CLIENTS, ...EXPORT_CLIENTS].map((client) => [client, entries.filter((entry) => entrySource.get(entry) === client)])];
739
+ const encodeBatch = batch => JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "import_history", arguments: { ...(rebuild ? { rebuild: true } : {}), ...(withdrawUnknown ? { withdraw_unknown: true } : {}), entries: batch.map(({commits, ...rest}) => { void commits; return rest; }) } } });
740
+ // Persist the approved plan before sending, so later batches survive removed source files too.
741
+ try { for (const [source, group] of groups) { const target = source === "codex" ? codexDoor ?? door : door; if (target) for (const batch of batchesOf(group, byDay)) queuedHistory(target, encodeBatch(batch), source); } }
742
+ catch { console.error("History queue is full, busy or unavailable. Resume the saved batches before retrying this import; nothing was marked complete."); HISTORY_DELIVERY.waiting += entries.length; return 0; }
743
+ for (const [source, group] of groups) {
745
744
  const target = source === "codex" ? codexDoor ?? door : door;
746
745
  if (group.length === 0 || !target) continue;
747
746
  let number = 0;
748
747
  for (const batch of batchesOf(group, byDay)) {
749
748
  number += 1;
750
- // History carries no shas: an imported line forms no session, and the join is the live route's. REBUILD (owner, 2026-10-07): `rebuild: true`
751
- // tells the door to replace this computer's earlier lines on the days and for the client the batch carries, and every group names its client.
752
- // WITHDRAW UNKNOWN (owner, 2026-10-10): with an export, after the person's yes, `withdraw_unknown: true` also withdraws the AI-app lines on its days.
753
- const body = JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "import_history", arguments: { ...(rebuild ? { rebuild: true } : {}), ...(withdrawUnknown ? { withdraw_unknown: true } : {}), entries: batch.map((entry) => { const { commits, ...rest } = entry; void commits; return rest; }) } } });
749
+ // Imported entries carry no live commit/session join.
750
+ const body = encodeBatch(batch);
754
751
  for (const entry of batch) retainMeasurement(entry, source);
755
752
  // `named` (0.10.10): a copied folder's lines name their client too, so the record says which app the copy came from.
756
- const response = await fetch(target.url, { method: "POST", headers: { "content-type": "application/json", accept: "application/json, text/event-stream", authorization: `Bearer ${target.token}`, ...clientOf(source, rebuild || named), ...proofFor(target.url, body) }, body });
757
- const text = await response.text();
758
- if (announce) console.log(`batch ${number}: ${response.status} ${text.slice(0, 200).replace(/\\n/g, " ")}`);
759
- if (!response.ok) break;
760
- try { confirmedReceipt(text, batch.length); } catch { break; }
761
- accepted += batch.length;
762
- noteReceipt(text);
753
+ let queued;
754
+ try { queued = queuedHistory(target, body, source); }
755
+ catch { console.error("Pending history could not be stored safely. Nothing was marked complete; keep the local WorkTrust folder for recovery."); HISTORY_DELIVERY.waiting += batch.length; break; }
756
+ if (queued.status === "acknowledged" && !byDay) { accepted += batch.length; RECEIPTS.alreadyHeld += batch.length; continue; }
757
+ if (queued.status === "review" && !flag("retry-review")) { HISTORY_DELIVERY.review += batch.length; continue; }
758
+ if (queued.status === "waiting") { HISTORY_DELIVERY.waiting += batch.length; continue; }
759
+ try {
760
+ const response = await fetch(target.url, { method: "POST", headers: { "content-type": "application/json", accept: "application/json, text/event-stream", authorization: `Bearer ${target.token}`, ...clientOf(source, rebuild || named), ...proofFor(target.url, body) }, body, redirect: "error", signal: AbortSignal.timeout(65_000) });
761
+ const text = await response.text();
762
+ try { if (!response.ok) throw Error(); confirmedReceipt(text, batch.length); }
763
+ catch {
764
+ const refusal = historyRefusal(text, response); queued.defer(refusal.reason, refusal.seconds);
765
+ if (refusal.reason === "review") { HISTORY_DELIVERY.review += batch.length; continue; }
766
+ HISTORY_DELIVERY.waiting += batch.length; break;
767
+ }
768
+ queued.confirm(); accepted += batch.length; noteReceipt(text);
769
+ if (announce) console.log(`batch ${number}: received ${batch.length}`);
770
+ } catch { queued.defer("unconfirmed"); HISTORY_DELIVERY.waiting += batch.length; break; }
763
771
  }
764
772
  }
765
773
  return accepted;
@@ -792,7 +800,7 @@ const proofFor = (url, body) => {
792
800
  * on this computer, and the door names a coupling's clients by the user-agent it hears (mcp_identify's
793
801
  * agents_seen). An Antigravity line names Antigravity: the product name, nothing of the work.
794
802
  */
795
- const clientOf = (source, always = false) => (always || source === "antigravity" || DATABASE_CLIENTS.includes(source) || EXPORT_CLIENTS.includes(source) ? { "user-agent": `${source ?? "claude"}/hook (worktrust-hook)` } : {});
803
+ const clientOf = (source, always = false) => (CLI_VERSION_SENT || always || source === "antigravity" || DATABASE_CLIENTS.includes(source) || EXPORT_CLIENTS.includes(source) ? { "user-agent": `${source ?? "claude"}/hook (worktrust-hook)${CLI_VERSION_SENT ? ` worktrust-cli/${CLI_VERSION_SENT}` : ""}` } : {});
796
804
 
797
805
  async function send(door, payload) {
798
806
  retainMeasurement(payload, entrySource.get(payload));
@@ -1201,6 +1209,21 @@ if (!door && !codexDoor && !DRY) { return await exitFlushed(0); } // Not coupled
1201
1209
  * device key (only lines this computer signed travel), an archive that verifies, a stretch whose session is gone from
1202
1210
  * this computer (one still here goes through the ordinary history), a door that knows the mark, and the person asking.
1203
1211
  */
1212
+ if (flag("history") && flag("resume")) {
1213
+ const { resumeHistory } = await import("./history-outbox.mjs");
1214
+ const totals = { received: 0, review: 0, waiting: 0, batches: 0 };
1215
+ try {
1216
+ for (const target of [door, ...(codexDoor && codexDoor.token !== door?.token ? [codexDoor] : [])].filter(Boolean)) {
1217
+ const result = await resumeHistory(target, { dry: DRY, retryReview: flag("retry-review"), confirmed: confirmedReceipt, note: noteReceipt,
1218
+ send: (body, source) => fetch(target.url, { method: "POST", headers: { "content-type": "application/json", accept: "application/json, text/event-stream", authorization: `Bearer ${target.token}`, ...clientOf(source, true), ...proofFor(target.url, body) }, body, redirect: "error", signal: AbortSignal.timeout(65_000) }),
1219
+ });
1220
+ for (const key of Object.keys(totals)) totals[key] += result[key];
1221
+ }
1222
+ console.log(JSON.stringify({ resumed: totals.received, ...totals, ...RECEIPTS }));
1223
+ return await exitFlushed(DRY || (!totals.waiting && !totals.review) ? 0 : 1);
1224
+ } catch { console.log("Pending history could not be read safely. Nothing was marked complete; keep the local WorkTrust folder for recovery."); return await exitFlushed(1); }
1225
+ }
1226
+
1204
1227
  if (flag("history") && flag("from-archive")) {
1205
1228
  const named = value("from-archive"), dir = named && !named.startsWith("--") ? named.replace(/^~(?=\/|$)/, homedir()) : join(homedir(), "AI-Evidence");
1206
1229
  const say = (text) => console.log(text);
@@ -1262,7 +1285,7 @@ if (flag("history")) {
1262
1285
  // An export that arrived whole is remembered by its digest (never by a conversation), so the bare command offers it no more.
1263
1286
  if (fromExports && accepted === entries.length) for (const report of fromExports.reports) rememberExport(report.digest, { vendor: report.vendor, sent: true, at: new Date().toISOString(), conversations: report.conversations });
1264
1287
  // ONE LINE FOR THE COMMAND TO ASK WITH (2026-10-10): what the door replaced, how many AI-app lines lie on the export's days, how many it withdrew.
1265
- if (fromExports) console.log(JSON.stringify({ export_sent: accepted, of: entries.length, ...RECEIPTS })); else console.log(JSON.stringify({ history_sent: accepted, of: entries.length, ...RECEIPTS })); // the same line for a history send: what the door did with it, and WorkTrust's measuredSeconds for what it stored
1288
+ if (fromExports) console.log(JSON.stringify({ export_sent: accepted, of: entries.length, ...RECEIPTS })); else console.log(JSON.stringify({ history_sent: accepted, of: entries.length, ...RECEIPTS, delivery: HISTORY_DELIVERY })); // the same line for a history send: what the door did with it, and WorkTrust's measuredSeconds for what it stored
1266
1289
  return await exitFlushed(accepted === entries.length ? 0 : 1);
1267
1290
  }
1268
1291
 
@@ -1 +1 @@
1
- {"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"AGENTS.md":"d1db152d88338df23b5900beed6a69bedc2900b6f53fef3f036b46dd7a07b841","CLAUDE.md":"5933504f93e5a40369a4790e96dd5dad791d849d3178b1833eb64088e456aaeb","LICENSE":"3096ed1693974a90e1f4f59bf01c9559d94a7941d933e36fb81d3995a97f25c1","README.md":"560104ad89115bb9392a39ba31431546296605e23ba7134aebb65e398b54741d","SECURITY.md":"e3ed1927cbceef97b38ca630aadd0a91a0df02368f822f4fd66e3ed0b6a07e8d","chat-exports.mjs":"04eafe333940ec03d5058d8d51062124aa12ab882bf04db03bcda5613ec69298","claude-mod.mjs":"02d86b0cdddf39879efc5194c0a5be6b41456faedec28963dc123a4e88dc3942","config-edits.mjs":"0eba2f176ef6f7afba071d6e00de0ff19ba2b283180a801dfd957aa38c1edd94","count-behaviour.mjs":"1beaec2a4d0aead76d166f89cc52441a9cf48f2e69da9888ca2091dd3a10a37b","engine-release.json":"1b8113feffe4a6c8c513f885c2a507eac002c661a79526734ac054453a6466a2","log-session.mjs":"b99f082a58f0a92375026f52b62eb72173f06614b844e3def06b3ed40942b103","orchestration-contract.mjs":"ec08f303a166365b99e70b675de4cfe76c6156c2567e14b5569f6d992f0231b7","orchestration-evidence.mjs":"d0d06cecf0eb08e5c6e653c62a4f45b1eddf2119c2acb8341056b34f488d214a","orchestration-report.mjs":"d4e0a9ad8e4a01b462d22c6b1866aac291565c533ff476085d3367cb6d59bc1b","package-integrity.mjs":"b9d81dc88cf5c19ccfbf334a7af84a0c4e299a0e9e4d4091132253e22f855dc3","package.json":"29ed1c5bfa3075d6970b94a7b922d85dfdcce7a4e3afc6808d340ae421a3aa0d","preserve-lines.mjs":"18081b745b8c47838448b0a49a129a363e29d3f2f5207bc591187d860157b456","preserve-summary.mjs":"137f781ed7021596a3f0ea67afcf2ab8616ac293f833dbb8f176e838e0ed8321","preserve.mjs":"38f83bd933853a986fef61f4e452c27d4a3adc6000f5c9201ef70f270b404eac","runtime-install.mjs":"b9d2e4febbf400a679eeb3a14b74eef6c2062c5b626d45872a193b7502d3201c","session-databases.mjs":"543fd3b82d28d96d789be0a1dc9186c5fafa783e98b87e5b3b17b211542e2b4d","setup-mcp.mjs":"70f63b61cf1e28fb2b7471e7768d596b0cf166ccdc9d1ce859ee58d29b2ecabc","stack-rules.mjs":"b23c56e72ec56ba02b17ed895f869172d988c468a697e8d6026b0e268f61e489","stretch-evidence.mjs":"5b31a6f29b785d277e92257532f3c7cee366a79759decc7a75cfbaec2686ee13","transcript-readers.mjs":"413948644a74dc0bf1b49548be193bf596bcf82ac7eae668f624345a18e189e7","worktrust-launch.mjs":"f28f699f986c72d99af8a7542d317f6dbb9e26d114f6ad083013567e08b8a650","worktrust.mjs":"b563a702634b41c064fdd0b6ad842c77ff851dfcf682b370c677114f8f75c061"},"format":"worktrust-package/1","kind":"npm","version":"0.10.23"},"signature":"WESSe1_j0LegjJCE5a8xKYLoeKmDic5pLIK8bUpCSV2yqnU7P4UIfOosoux_buhU6-khECj2I_rNUTz4YQsbCw"}
1
+ {"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"AGENTS.md":"d1db152d88338df23b5900beed6a69bedc2900b6f53fef3f036b46dd7a07b841","CLAUDE.md":"5933504f93e5a40369a4790e96dd5dad791d849d3178b1833eb64088e456aaeb","LICENSE":"3096ed1693974a90e1f4f59bf01c9559d94a7941d933e36fb81d3995a97f25c1","README.md":"d6db7aff9f8c6ff8da1c67e9f16aa8ebf4a55efc21265e16c81b6408237ab056","SECURITY.md":"e3ed1927cbceef97b38ca630aadd0a91a0df02368f822f4fd66e3ed0b6a07e8d","chat-exports.mjs":"04eafe333940ec03d5058d8d51062124aa12ab882bf04db03bcda5613ec69298","claude-mod.mjs":"02d86b0cdddf39879efc5194c0a5be6b41456faedec28963dc123a4e88dc3942","config-edits.mjs":"0eba2f176ef6f7afba071d6e00de0ff19ba2b283180a801dfd957aa38c1edd94","count-behaviour.mjs":"1beaec2a4d0aead76d166f89cc52441a9cf48f2e69da9888ca2091dd3a10a37b","engine-release.json":"c31900cf37fb8ff571190ef1235fab4bed57007fc8c111e701da26dc5ad6dc90","history-outbox.mjs":"1bdca17b807c76e4a8e7bf42c6f07e12e8ae8e4466417cafdd26b1f58bf178a5","log-session.mjs":"6098eedb253b165819fdb4293adb6ddaa6c5843db0bbb007759701918955f664","orchestration-contract.mjs":"ec08f303a166365b99e70b675de4cfe76c6156c2567e14b5569f6d992f0231b7","orchestration-evidence.mjs":"d0d06cecf0eb08e5c6e653c62a4f45b1eddf2119c2acb8341056b34f488d214a","orchestration-report.mjs":"d4e0a9ad8e4a01b462d22c6b1866aac291565c533ff476085d3367cb6d59bc1b","package-integrity.mjs":"b9d81dc88cf5c19ccfbf334a7af84a0c4e299a0e9e4d4091132253e22f855dc3","package.json":"e2994c95ae40d276855b29263b3f284baccd1536f84db44a29259757dcf46b99","preserve-lines.mjs":"18081b745b8c47838448b0a49a129a363e29d3f2f5207bc591187d860157b456","preserve-summary.mjs":"137f781ed7021596a3f0ea67afcf2ab8616ac293f833dbb8f176e838e0ed8321","preserve.mjs":"38f83bd933853a986fef61f4e452c27d4a3adc6000f5c9201ef70f270b404eac","runtime-install.mjs":"b9d2e4febbf400a679eeb3a14b74eef6c2062c5b626d45872a193b7502d3201c","session-databases.mjs":"543fd3b82d28d96d789be0a1dc9186c5fafa783e98b87e5b3b17b211542e2b4d","setup-mcp.mjs":"70f63b61cf1e28fb2b7471e7768d596b0cf166ccdc9d1ce859ee58d29b2ecabc","stack-rules.mjs":"b23c56e72ec56ba02b17ed895f869172d988c468a697e8d6026b0e268f61e489","stretch-evidence.mjs":"5b31a6f29b785d277e92257532f3c7cee366a79759decc7a75cfbaec2686ee13","transcript-readers.mjs":"413948644a74dc0bf1b49548be193bf596bcf82ac7eae668f624345a18e189e7","worktrust-launch.mjs":"f28f699f986c72d99af8a7542d317f6dbb9e26d114f6ad083013567e08b8a650","worktrust.mjs":"c1cce642ba2ef4099b0fc3d375a4f8e8cb669b6694b0c99f08164a38d5d943d9"},"format":"worktrust-package/1","kind":"npm","version":"0.10.24"},"signature":"L6nxsuFrIoXcxsVvNrPkxkMV_woNpE5IGJLWjsvwGKdxtUkq2P6Foe7r2HmWavXleroNIcWcPf4CljteUCO9CQ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "worktrust",
3
- "version": "0.10.23",
3
+ "version": "0.10.24",
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": {
@@ -33,7 +33,8 @@
33
33
  "package-integrity.mjs",
34
34
  "worktrust-launch.mjs",
35
35
  "engine-release.json",
36
- "package-release.json"
36
+ "package-release.json",
37
+ "history-outbox.mjs"
37
38
  ],
38
39
  "engines": {
39
40
  "node": ">=18"
package/worktrust.mjs CHANGED
@@ -63,7 +63,7 @@
63
63
  * No dependencies: Node 18 or later.
64
64
  */
65
65
  import { execFileSync, spawn } from "node:child_process";
66
- import { createHash, generateKeyPairSync, randomBytes, sign } from "node:crypto";
66
+ import { createHash, createPublicKey, generateKeyPairSync, randomBytes, sign } from "node:crypto";
67
67
  import { createServer } from "node:http";
68
68
  import { chmodSync, closeSync, copyFileSync, existsSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync, writeSync } from "node:fs";
69
69
  import { homedir, hostname, platform } from "node:os";
@@ -78,12 +78,12 @@ const command = args.includes("--help") ? "help" : args.includes("--version") ?
78
78
  const flag = (name) => { const at = args.indexOf(`--${name}`); return at >= 0 ? args[at + 1] : undefined; };
79
79
  const has = (name) => args.includes(`--${name}`);
80
80
  /** 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). */
81
- const CLI_VERSION = "0.10.23";
81
+ const CLI_VERSION = "0.10.24";
82
82
  const ORIGIN = (flag("origin") ?? process.env.WORKTRUST_ORIGIN ?? "https://app.worktrust.io").replace(/\/$/, "");
83
83
  const MCP = flag("url") ?? process.env.WORKTRUST_MCP_URL ?? `${ORIGIN}/api/mcp`;
84
84
  const HOME_DIR = join(homedir(), ".worktrust");
85
85
  const HERE = dirname(fileURLToPath(import.meta.url));
86
- const SCRIPTS = ["setup-mcp.mjs", "log-session.mjs", "count-behaviour.mjs", "transcript-readers.mjs", "session-databases.mjs", "config-edits.mjs", "stretch-evidence.mjs", "chat-exports.mjs", "stack-rules.mjs", "runtime-install.mjs", "orchestration-contract.mjs", "orchestration-evidence.mjs", "orchestration-report.mjs", "claude-mod.mjs", "package-integrity.mjs", "worktrust-launch.mjs"];
86
+ const SCRIPTS = ["history-outbox.mjs", "setup-mcp.mjs", "log-session.mjs", "count-behaviour.mjs", "transcript-readers.mjs", "session-databases.mjs", "config-edits.mjs", "stretch-evidence.mjs", "chat-exports.mjs", "stack-rules.mjs", "runtime-install.mjs", "orchestration-contract.mjs", "orchestration-evidence.mjs", "orchestration-report.mjs", "claude-mod.mjs", "package-integrity.mjs", "worktrust-launch.mjs"];
87
87
  /** The modules the scripts import by name from beside them; a download keeps that name. */
88
88
  const IMPORTED = new Set(["transcript-readers.mjs", "session-databases.mjs", "config-edits.mjs", "stretch-evidence.mjs", "chat-exports.mjs", "stack-rules.mjs", "runtime-install.mjs", "orchestration-contract.mjs", "orchestration-evidence.mjs", "orchestration-report.mjs"]);
89
89
  const downloaded = (name) => (IMPORTED.has(name) ? name : `${name}.download.mjs`);
@@ -131,10 +131,18 @@ async function scripts() {
131
131
  fail("Use the complete official npm/Python package or preservation kit. Individual scripts are not downloaded or executed without release verification.");
132
132
  }
133
133
 
134
+ /** Stable across bearer renewal, distinct across account/device replacement. Never sent to the server. */
135
+ function historyQueueScope(token) {
136
+ const key = keyStore.load();
137
+ if (!key || key.token !== token || !key.accountRef || !key.device) return "";
138
+ try { return createHash("sha256").update(`${key.accountRef}\0${createPublicKey(key.device).export({ format: "jwk" }).x}`).digest("hex"); }
139
+ catch { return ""; }
140
+ }
141
+
134
142
  /** Run a script; its output is shown, or collected for the plan. The key travels in the environment only. */
135
143
  function run(path, scriptArgs, token, collect = false, extraEnv = {}) {
136
144
  return new Promise((resolve) => {
137
- const child = spawn(process.execPath, [...NODE_FLAGS, path, ...scriptArgs], { stdio: collect ? ["ignore", "pipe", "pipe"] : "inherit", env: { ...process.env, WORKTRUST_MCP_URL: MCP, WORKTRUST_MCP_TOKEN: token, WORKTRUST_NODE: NODE, WORKTRUST_CLI_VERSION: CLI_VERSION, ...extraEnv } });
145
+ const child = spawn(process.execPath, [...NODE_FLAGS, path, ...scriptArgs], { stdio: collect ? ["ignore", "pipe", "pipe"] : "inherit", env: { ...process.env, WORKTRUST_MCP_URL: MCP, WORKTRUST_MCP_TOKEN: token, WORKTRUST_NODE: NODE, WORKTRUST_CLI_VERSION: CLI_VERSION, WORKTRUST_HISTORY_SCOPE: historyQueueScope(token), ...extraEnv } });
138
146
  let out = "";
139
147
  child.stdout?.on("data", (chunk) => { out += chunk; });
140
148
  child.stderr?.on("data", (chunk) => { out += chunk; });
@@ -213,6 +221,7 @@ async function pairByBrowser(host, extra) {
213
221
  server.close();
214
222
  if (!code) fail("no approval arrived in time. Run `worktrust connect` again.");
215
223
  const exchange = await post("/api/cli/token", { device_code: secret, code, code_verifier: verifier }).catch(() => null);
224
+ if (exchange?.json?.error === "device_limit") fail("Five devices are already connected. In WorkTrust Sources, disconnect a device, then connect again. Earlier measurements are kept.");
216
225
  if (!exchange || exchange.status !== 200 || !exchange.json.token) fail(`the approval could not be exchanged (${exchange?.json?.error ?? "no answer"}). Run \`worktrust connect\` again.`);
217
226
  say(` ✓ Approved as "${exchange.json.label}"${exchange.json.account ? ` for the WorkTrust account ${exchange.json.account}` : ""}`);
218
227
  if (exchange.json.account) say(" Not your account? Run `npx worktrust disconnect` now and revoke it in WorkTrust.");
@@ -247,6 +256,7 @@ async function pairByCode(host, extra) {
247
256
  if (answer.json.account) say(" Not your account? Run `npx worktrust disconnect` now and revoke it in WorkTrust.");
248
257
  return paired(answer.json);
249
258
  }
259
+ if (answer.json.error === "device_limit") fail("Five devices are already connected. In WorkTrust Sources, disconnect a device, then connect again. Earlier measurements are kept.");
250
260
  if (answer.json.error === "slow_down") wait += 2000;
251
261
  else if (answer.json.error === "expired_token") fail("the code expired. Run `worktrust connect` again.");
252
262
  else if (answer.json.error === "invalid_grant") fail("this pairing was already used. Run `worktrust connect` again.");
@@ -356,7 +366,7 @@ function proof(device, url, body) {
356
366
  async function accepted(url, token, device) {
357
367
  try {
358
368
  const body = JSON.stringify({ jsonrpc: "2.0", id: 0, method: "tools/list" });
359
- const response = await fetch(url, { method: "POST", headers: { "content-type": "application/json", accept: "application/json", authorization: `Bearer ${token}`, "user-agent": "worktrust-bridge", ...proof(device, url, body) }, body, redirect: "error", signal: AbortSignal.timeout(5000) });
369
+ const response = await fetch(url, { method: "POST", headers: { "content-type": "application/json", accept: "application/json", authorization: `Bearer ${token}`, "user-agent": `worktrust-bridge worktrust-cli/${CLI_VERSION}`, ...proof(device, url, body) }, body, redirect: "error", signal: AbortSignal.timeout(5000) });
360
370
  if (response.status === 401 || response.status === 403) return false;
361
371
  if (response.status !== 200) return null;
362
372
  const answer = await response.json();
@@ -500,7 +510,7 @@ async function hook() {
500
510
  if (has("hermes") || has("goose")) return sessionEnd();
501
511
  const key = await freshKey();
502
512
  if (!key) return;
503
- const child = spawn(process.execPath, [...NODE_FLAGS, join(BUNDLED ? HERE : HOME_DIR, "log-session.mjs"), ...args.filter((arg) => arg !== "hook")], { stdio: "inherit", env: { ...process.env, WORKTRUST_MCP_URL: key.url, WORKTRUST_MCP_TOKEN: key.token, WORKTRUST_CLI_VERSION: CLI_VERSION, ...(key.device ? { WORKTRUST_DEVICE_KEY: key.device } : {}) } }); // 0.10.20: the hook names the version that started it, beside each line
513
+ const child = spawn(process.execPath, [...NODE_FLAGS, join(BUNDLED ? HERE : HOME_DIR, "log-session.mjs"), ...args.filter((arg) => arg !== "hook")], { stdio: "inherit", env: { ...process.env, WORKTRUST_MCP_URL: key.url, WORKTRUST_MCP_TOKEN: key.token, WORKTRUST_CLI_VERSION: CLI_VERSION, WORKTRUST_HISTORY_SCOPE: historyQueueScope(key.token), ...(key.device ? { WORKTRUST_DEVICE_KEY: key.device } : {}) } }); // 0.10.20: the hook names the version that started it, beside each line
504
514
  process.exitCode = await new Promise((resolve, reject) => { child.on("error", reject); child.on("close", (code) => resolve(code ?? 1)); });
505
515
  }
506
516
 
@@ -578,10 +588,11 @@ async function update() {
578
588
  // Codex installed since, or a No said at connect: the one question, asked again (or "already set").
579
589
  await offerCodex();
580
590
  await offerAntigravity();
591
+ const reported = await accepted(key.url, key.token, key.device);
592
+ say(reported === true ? ` ✓ WorkTrust received CLI version ${CLI_VERSION}.` : " ! Installed locally. WorkTrust could not confirm the version yet; it will be reported on the next connection.");
581
593
  await offerRebuild(previousVersion, paths, key);
582
594
  say();
583
- say(" Done. Quit your AI apps completely and open them again; the CLI version shows in WorkTrust");
584
- say(" under Sources → CLI once one of them has spoken. A key an app held by hand still works until you end it there.");
595
+ say(" Done. Quit your AI apps completely and open them again to use the updated CLI.");
585
596
  }
586
597
 
587
598
  async function connect() {
@@ -691,7 +702,7 @@ async function offerHistory(paths, token, devicePem, url = MCP, rebuild = false)
691
702
  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"); return; }
692
703
  // Marked unfinished before the first batch leaves (0.10.9): a send stopped halfway (Ctrl+C, a closed lid) is finished by the next run.
693
704
  historyDone(false);
694
- const sent = await run(paths["log-session.mjs"], ["--history", ...(rebuild ? ["--rebuild"] : [])], token, true, env);
705
+ const sent = await run(paths["log-session.mjs"], ["--history", ...(rebuild ? ["--rebuild"] : []), ...(has("retry-review") ? ["--retry-review"] : [])], token, true, env);
695
706
  historyDone(sent.code === 0);
696
707
  // WHAT ACTUALLY HAPPENED, FROM THE DOOR'S RECEIPTS (owner, 2026-10-10): a re-measure in which nothing changed must not say
697
708
  // "replaced". The hook sums the receipts of every batch and prints one line; without it (an older hook) the sentence stays neutral.
@@ -701,8 +712,10 @@ async function offerHistory(paths, token, devicePem, url = MCP, rebuild = false)
701
712
  : n(did.replaced) > 0 ? `${n(did.replaced)} of this computer's earlier lines were replaced (withdrawn and kept, never deleted)${n(did.new) > 0 ? `, ${n(did.new)} new` : ""}${n(did.filled) > 0 ? `, ${n(did.filled)} lines gained what was missing` : ""}.`
702
713
  : n(did.new) === 0 ? `Nothing changed: the same measurement${n(did.filled) > 0 ? `; ${n(did.filled)} lines gained what was missing (the stack, the tools seen, a layer)` : ""}; ${n(did.alreadyHeld)} lines already held.`
703
714
  : `${n(did.new)} new lines${n(did.filled) > 0 ? `, ${n(did.filled)} lines gained what was missing` : ""}; ${n(did.alreadyHeld)} already held.`;
704
- if (rebuild) say(sent.code === 0 ? ` ✓ Re-measured. ${outcome}` : " Not all of it arrived. Run npx worktrust again: it finishes what did not arrive, a day already rebuilt is counted once.");
705
- 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 history again: a line already received is kept once.");
715
+ if (Number(did?.delivery?.review) > 0) say(` ${did.delivery.review} lines are waiting for review. Earlier measurements remain unchanged. Reconnecting or repeating the import does not approve them.`);
716
+ if (Number(did?.delivery?.waiting) > 0) say(" Pending batches remain on this computer. Run npx worktrust history --resume after the upload limit or connection recovers.");
717
+ if (rebuild && !Number(did?.delivery?.review) && !Number(did?.delivery?.waiting)) say(sent.code === 0 ? ` ✓ Re-measured. ${outcome}` : " Not all of it arrived. Run npx worktrust again: it finishes what did not arrive, a day already rebuilt is counted once.");
718
+ else if (!rebuild) say(sent.code === 0 ? " ✓ Sent as history. Activity is recorded with its origin; independent verification and passport publication are separate. A day WorkTrust already holds is kept once." : " Not all of it arrived. Run npx worktrust history again: a line already received is kept once.");
706
719
  if (did && Number(did.measuredSeconds) > 0) say(` Measured by WorkTrust: ${(Number(did.measuredSeconds) / 3600).toFixed(1)} h for what this send stored${n(did.corrected) > 0 ? ` (${n(did.corrected)} lines corrected: a figure sent beside the timeline differed)` : ""}.`);
707
720
  }
708
721
 
@@ -763,6 +776,11 @@ async function again() {
763
776
  async function history() {
764
777
  const key = await freshKey();
765
778
  if (!key) fail("this computer is not coupled through the key file. Run npx worktrust first.");
779
+ if (has("resume")) {
780
+ if (!has("dry-run") && !has("history") && !(await ask("Resume previously approved metadata uploads? Lines held for review stay held.", false))) return;
781
+ const paths = await scripts(), sent = await run(paths["log-session.mjs"], ["--history", "--resume", ...(has("dry-run") ? ["--dry-run"] : []), ...(has("retry-review") ? ["--retry-review"] : [])], key.token, true, { WORKTRUST_MCP_URL: key.url, ...(key.device ? { WORKTRUST_DEVICE_KEY: key.device } : {}) });
782
+ say(sent.out.trim()); process.exitCode = sent.code; return;
783
+ }
766
784
  if (has("from-archive")) return offerArchive(await scripts(), key);
767
785
  if (has("export")) { if (!flag("export") || flag("export").startsWith("--")) fail("--export needs the export's path: the zip, its folder, conversations.json, a conversations-000.zip part, or the manifest"); await offerExport(await scripts(), key, flag("export")); return; }
768
786
  if (has("from-folder")) { if (!flag("from-folder") || flag("from-folder").startsWith("--")) fail("--from-folder needs the copied folder's path"); await offerFolder(await scripts(), key, flag("from-folder")); return; }
@@ -1150,6 +1168,8 @@ function help() {
1150
1168
  say(" --replace yes in advance to coupling a computer that is already coupled");
1151
1169
  say(" worktrust update this computer onto the newest CLI: same key, no new pairing");
1152
1170
  say(" worktrust history send this computer's earlier sessions as history (asks first)");
1171
+ say(" --resume retry saved metadata batches, even if source files are gone (asks first)");
1172
+ say(" --retry-review explicitly retry held batches after support resolves their review");
1153
1173
  say(" --rebuild re-measure them with the current rules; WorkTrust replaces this computer's earlier lines,");
1154
1174
  say(" day by day, never counting a day twice (shows the plan per AI app, asks first; --dry-run: the plan only)");
1155
1175
  say(" --from-archive [dir] send what your archive (preserve --archive) holds of sessions your AI apps already deleted,");