worktrust 0.10.26 → 0.10.27
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 +11 -6
- package/SECURITY.md +1 -1
- package/engine-release.json +1 -1
- package/history-outbox.mjs +12 -6
- package/log-session.mjs +58 -21
- package/package-release.json +1 -1
- package/package.json +1 -1
- package/worktrust.mjs +21 -3
package/README.md
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
# worktrust
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 0.10.27: history kept on the server
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
A re-measure (`worktrust history`) sends its batches as one run; WorkTrust keeps each batch it
|
|
6
|
+
receives and rebuilds the days itself once the run is whole, so no `--resume` is needed. A line
|
|
7
|
+
under no product name is replaced only where the new lines overlap it.
|
|
8
|
+
|
|
9
|
+
## 0.10.26: OS credential storage
|
|
10
|
+
|
|
11
|
+
Explicit `worktrust protect-key` migration: an OS-vault wrapping key protects the locally
|
|
12
|
+
encrypted coupling credentials. It does not attest that local activity is truthful. See
|
|
8
13
|
[credential protection](#credential-protection) before enabling it.
|
|
9
14
|
|
|
10
15
|
After an approved update, WorkTrust receives the running version without
|
|
@@ -388,8 +393,8 @@ the proof of possession the pairing binds, for nothing your record would gain.
|
|
|
388
393
|
|
|
389
394
|
## Credential protection
|
|
390
395
|
|
|
391
|
-
Existing installations keep private file storage until the person opts in.
|
|
392
|
-
|
|
396
|
+
Existing installations keep private file storage until the person opts in. From 0.10.26,
|
|
397
|
+
run `worktrust update`, quit the AI apps, then run `worktrust protect-key` and restart
|
|
393
398
|
those apps. A new computer can run `worktrust protect-key` before connecting. `worktrust status`
|
|
394
399
|
shows the storage mode. This command is local and does not publish or change a Passport.
|
|
395
400
|
|
package/SECURITY.md
CHANGED
|
@@ -29,7 +29,7 @@ private transcripts or account data in a public issue.
|
|
|
29
29
|
## Where the key is, and how long it lives
|
|
30
30
|
|
|
31
31
|
- Existing installations use a private local file until explicit `worktrust protect-key` migration
|
|
32
|
-
(0.10.26
|
|
32
|
+
(0.10.26 and later). Base64 in that legacy file is not encryption.
|
|
33
33
|
- Protected mode uses AES-256-GCM for all coupling secrets and OS storage for a separate random
|
|
34
34
|
wrapping key: macOS Keychain, Windows Credential Manager with local-machine persistence, or
|
|
35
35
|
Linux Secret Service. Only a random identifier, provider, nonce, ciphertext and authentication
|
package/engine-release.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"chat-exports.mjs":"04eafe333940ec03d5058d8d51062124aa12ab882bf04db03bcda5613ec69298","claude-mod.mjs":"02d86b0cdddf39879efc5194c0a5be6b41456faedec28963dc123a4e88dc3942","config-edits.mjs":"0eba2f176ef6f7afba071d6e00de0ff19ba2b283180a801dfd957aa38c1edd94","count-behaviour.mjs":"1beaec2a4d0aead76d166f89cc52441a9cf48f2e69da9888ca2091dd3a10a37b","credential-store.mjs":"a4b3540a61f4ce19e535c7f1d260c0d817686cd066d559a76db2ab108144abba","credential-vault-scripts.mjs":"7e42fe1db3885c2dec6f1de87bebfbefe2292d29179a68f3da87d19eb6c7704b","credential-vault.mjs":"279baabb217e2a3f170e8d7f2b271a88484531f9031c441360ea91561a70da99","history-outbox.mjs":"
|
|
1
|
+
{"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"chat-exports.mjs":"04eafe333940ec03d5058d8d51062124aa12ab882bf04db03bcda5613ec69298","claude-mod.mjs":"02d86b0cdddf39879efc5194c0a5be6b41456faedec28963dc123a4e88dc3942","config-edits.mjs":"0eba2f176ef6f7afba071d6e00de0ff19ba2b283180a801dfd957aa38c1edd94","count-behaviour.mjs":"1beaec2a4d0aead76d166f89cc52441a9cf48f2e69da9888ca2091dd3a10a37b","credential-store.mjs":"a4b3540a61f4ce19e535c7f1d260c0d817686cd066d559a76db2ab108144abba","credential-vault-scripts.mjs":"7e42fe1db3885c2dec6f1de87bebfbefe2292d29179a68f3da87d19eb6c7704b","credential-vault.mjs":"279baabb217e2a3f170e8d7f2b271a88484531f9031c441360ea91561a70da99","history-outbox.mjs":"013885af8239da9fbd0f7fb339383f6dbcb462f439d8900c9290757f63fb597a","log-session.mjs":"87066a26e9d2d3947540b24e34139f63b25a1e4f8e13f389fa5e2d398893c368","orchestration-contract.mjs":"ec08f303a166365b99e70b675de4cfe76c6156c2567e14b5569f6d992f0231b7","orchestration-evidence.mjs":"d0d06cecf0eb08e5c6e653c62a4f45b1eddf2119c2acb8341056b34f488d214a","orchestration-report.mjs":"d4e0a9ad8e4a01b462d22c6b1866aac291565c533ff476085d3367cb6d59bc1b","package-integrity.mjs":"a8210c9494a56bfb9a5ea3d10064c7a269f0b6330c0af7c0700e706c3c0224e3","preserve-lines.mjs":"2df64a69687aa51219bf7b86b88d175cc50990fa29574b31897e41a9ebeecf43","preserve-summary.mjs":"137f781ed7021596a3f0ea67afcf2ab8616ac293f833dbb8f176e838e0ed8321","preserve.mjs":"3e369083ba43bcda2fa0622fd526aa64fcf8ad66e7b6e8f23821752c4d47ad27","runtime-install.mjs":"aab47b52c79d726ef428a24f982c648fa3f1c2dc2b574f633611d02924864e5f","session-databases.mjs":"543fd3b82d28d96d789be0a1dc9186c5fafa783e98b87e5b3b17b211542e2b4d","setup-mcp.mjs":"6ecfbf44f001dd433512b26736031ebc855b154e2bb0a401e2512b43623cd9cd","stack-rules.mjs":"b23c56e72ec56ba02b17ed895f869172d988c468a697e8d6026b0e268f61e489","stretch-evidence.mjs":"5b31a6f29b785d277e92257532f3c7cee366a79759decc7a75cfbaec2686ee13","transcript-readers.mjs":"413948644a74dc0bf1b49548be193bf596bcf82ac7eae668f624345a18e189e7","worktrust-launch.mjs":"84801bd29d472d48188c126b9ebe3989a3132b54e13cc4fe534ff7c383a294ee","worktrust.mjs":"4fc0b26c65394591ef13a354c53792926c43a4c829357c6dac12570181ac0e47"},"format":"worktrust-package/1","kind":"engine","version":"0.10.27"},"signature":"5m483yf79RTRQEzPghieWXgMJv77iUwp7wmRJMf8Vxu6zvOw5nPCS1V4TPRvAjCwjwedSJ9yI1q7IpG0gZbcCA"}
|
package/history-outbox.mjs
CHANGED
|
@@ -38,7 +38,7 @@ export function queuedHistory(target,body,source) {
|
|
|
38
38
|
const scope=scopeOf(target),id=digest(scope+'\0'+source+'\0'+body);
|
|
39
39
|
const request=join(root,id+'.request.json'),ack=join(root,id+'.ack.json'),state=join(root,id+'.state.json');
|
|
40
40
|
const acknowledged=read(ack);
|
|
41
|
-
if(acknowledged?.id===id)return {status:'acknowledged',confirm(){},defer(){}};
|
|
41
|
+
if(acknowledged?.id===id)return {status:'acknowledged',confirm(){},close(){},defer(){}};
|
|
42
42
|
const current=read(state);
|
|
43
43
|
reservation(root,()=>{
|
|
44
44
|
if(!existsSync(request)) {
|
|
@@ -50,6 +50,8 @@ export function queuedHistory(target,body,source) {
|
|
|
50
50
|
});
|
|
51
51
|
const status=current?.status==='review'?'review':Number(current?.retryAt)>Date.now()?'waiting':'pending';
|
|
52
52
|
return {status,retryAt:current?.retryAt??null,
|
|
53
|
+
// close (0.10.27): WorkTrust refused the batch for good (its run closed): kept here it would wait forever, so it is let go.
|
|
54
|
+
close(){write(ack,{id,closedAt:new Date().toISOString()});if(existsSync(request)){regular(request);unlinkSync(request);}if(existsSync(state)){regular(state);unlinkSync(state);}},
|
|
53
55
|
confirm(){write(ack,{id,confirmedAt:new Date().toISOString()});if(existsSync(request)){regular(request);unlinkSync(request);}if(existsSync(state)){regular(state);unlinkSync(state);}},
|
|
54
56
|
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
57
|
};
|
|
@@ -59,14 +61,16 @@ export function historyRefusal(text,response) {
|
|
|
59
61
|
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
62
|
const review=rpc?.id===1 && (rpc?.error?.data?.outcome==='review' || String(rpc?.error?.message??'').startsWith('history replacement held for review:'));
|
|
61
63
|
const raw=Number(response.headers.get('retry-after'));
|
|
62
|
-
|
|
64
|
+
// A staged run WorkTrust closed or refused (0.10.27: another computer's key, seven days without its last batch) is final.
|
|
65
|
+
const closed=rpc?.id===1 && String(rpc?.error?.message??'').startsWith('history run refused:');
|
|
66
|
+
return {reason:review?'review':closed?'closed':response.status===429?'capacity':'unconfirmed',seconds:Number.isFinite(raw)&&raw>0?Math.min(MAX_RETRY_SECONDS,raw):0};
|
|
63
67
|
}
|
|
64
68
|
|
|
65
69
|
/** Explicit recovery, even after the AI client removed its source files. A changed account/key
|
|
66
70
|
* 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}) {
|
|
71
|
+
export async function resumeHistory(target, {send, confirmed, note, retryReview=false, dry=false, limit=Infinity}) {
|
|
68
72
|
const root=join(homedir(),'.worktrust','history-outbox'),scope=scopeOf(target);
|
|
69
|
-
const totals={received:0,review:0,waiting:0,batches:0};let paused=null;
|
|
73
|
+
const totals={received:0,review:0,waiting:0,batches:0,refused:0};let paused=null,sent=0;
|
|
70
74
|
if(!existsSync(root))return totals;
|
|
71
75
|
directory(root);
|
|
72
76
|
const files=readdirSync(root);if(files.length>12000)throw Error('HISTORY_QUEUE_FULL');
|
|
@@ -78,14 +82,16 @@ export async function resumeHistory(target, {send, confirmed, note, retryReview=
|
|
|
78
82
|
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
83
|
const queued=queuedHistory(target,item.body,item.source);totals.batches++;
|
|
80
84
|
if(queued.status==='acknowledged')continue;
|
|
85
|
+
// `limit` (0.10.27): the hook sends a few a run by itself; the rest wait, untouched, for the next run.
|
|
86
|
+
if(sent>=limit){totals.waiting+=entries.length;continue;}
|
|
81
87
|
if(queued.status==='review'&&!retryReview){totals.review+=entries.length;continue;}
|
|
82
88
|
if(dry){totals.waiting+=entries.length;continue;}
|
|
83
89
|
if(queued.status==='waiting'&&!paused)paused={reason:'unconfirmed',seconds:Math.max(1,Math.ceil((queued.retryAt-Date.now())/1000))};
|
|
84
90
|
if(paused){if(queued.status==='review'){totals.review+=entries.length;continue;}queued.defer(paused.reason,paused.seconds);totals.waiting+=entries.length;continue;}
|
|
85
91
|
try {
|
|
86
|
-
const response=await send(item.body,item.source),text=await response.text();
|
|
92
|
+
sent++;const response=await send(item.body,item.source),text=await response.text();
|
|
87
93
|
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;}
|
|
94
|
+
catch{const refusal=historyRefusal(text,response);if(refusal.reason==='closed'){queued.close();totals.refused+=entries.length;continue;}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
95
|
queued.confirm();totals.received+=entries.length;note(text);
|
|
90
96
|
}catch{paused={reason:'unconfirmed',seconds:5};queued.defer(paused.reason,paused.seconds);totals.waiting+=entries.length;}
|
|
91
97
|
}
|
package/log-session.mjs
CHANGED
|
@@ -654,7 +654,7 @@ function batchesOf(group, byDay) {
|
|
|
654
654
|
return out;
|
|
655
655
|
}
|
|
656
656
|
/** THE RECEIPTS' COUNTS (2026-10-10): what an export send replaced, how many AI-app lines lie on its days, how many were withdrawn; summed over the batches, read for the counts alone. */
|
|
657
|
-
const RECEIPTS = { new: 0, alreadyHeld: 0, filled: 0, replaced: 0, superseded: 0, recut: 0, unknownOnDays: 0, unknownWithdrawn: 0, corrected: 0, measuredSeconds: 0 }; // 0.10.20: measuredSeconds is WorkTrust's own figure for what the batch stored, the one the terminal shows // 0.10.17: recut, the one-envelope export lines its runs replaced // 2026-10-10: and what a re-measure did (new, held, filled, replaced), so the command can say it
|
|
657
|
+
const RECEIPTS = { new: 0, alreadyHeld: 0, filled: 0, replaced: 0, superseded: 0, recut: 0, unknownOnDays: 0, unknownWithdrawn: 0, corrected: 0, measuredSeconds: 0, staged: 0, kept: 0 }; // 0.10.27: staged, the batches WorkTrust keeps on its server, and kept, their lines // 0.10.20: measuredSeconds is WorkTrust's own figure for what the batch stored, the one the terminal shows // 0.10.17: recut, the one-envelope export lines its runs replaced // 2026-10-10: and what a re-measure did (new, held, filled, replaced), so the command can say it
|
|
658
658
|
const noteReceipt = (answer) => {
|
|
659
659
|
try {
|
|
660
660
|
const json = JSON.parse(answer.trim().startsWith("{") ? answer : answer.split("\n").find((row) => row.startsWith("data:"))?.slice(5) ?? "null");
|
|
@@ -675,6 +675,10 @@ function confirmedReceipt(answer, expectedCount = null) {
|
|
|
675
675
|
const receipt = JSON.parse(content[0].text);
|
|
676
676
|
if (expectedCount === null) {
|
|
677
677
|
if (!(receipt.receipt === "received" && ["accepted", "flagged", "pending"].includes(receipt.status)) && !(receipt.receipt === "unchanged" && receipt.reason === "duplicate")) throw Error();
|
|
678
|
+
} else if (receipt.staged === true) {
|
|
679
|
+
// KEPT ON THE SERVER (0.10.27): a batch of a run WorkTrust holds and rebuilds itself; every line counted as kept or refused.
|
|
680
|
+
if (receipt.receipt !== "received" || receipt.received !== expectedCount || !Number.isInteger(receipt.kept) || receipt.kept < 0
|
|
681
|
+
|| !Number.isInteger(receipt.refused) || receipt.refused < 0 || receipt.kept + receipt.refused > expectedCount) throw Error();
|
|
678
682
|
} else if (receipt.receipt !== "received" || receipt.received !== expectedCount || receipt.refused !== 0
|
|
679
683
|
|| !Number.isInteger(receipt.new) || receipt.new < 0 || !Number.isInteger(receipt.alreadyHeld) || receipt.alreadyHeld < 0
|
|
680
684
|
|| receipt.new + receipt.alreadyHeld !== expectedCount) throw Error();
|
|
@@ -699,29 +703,43 @@ function retainMeasurement(payload, source) {
|
|
|
699
703
|
}
|
|
700
704
|
} finally { closeSync(fd); unlinkSync(temporary); }
|
|
701
705
|
}
|
|
702
|
-
const HISTORY_DELIVERY = { review: 0, waiting: 0 };
|
|
706
|
+
const HISTORY_DELIVERY = { review: 0, waiting: 0, refused: 0 };
|
|
707
|
+
/**
|
|
708
|
+
* ONE RUN PER COUPLING (0.10.27; owner, 2026-10-21: re-measured history is kept on the server). The batches of a re-measure
|
|
709
|
+
* to one key are one run: an id, each batch's number and the run's count ride in every batch, and WorkTrust keeps each batch
|
|
710
|
+
* it receives and rebuilds the run's days itself, every AI app of the run together, once all of them have arrived. The id is
|
|
711
|
+
* a digest of the UTC day and the run's batches, never of a key: the same plan sent again the same day is the same run, so a
|
|
712
|
+
* batch already received is neither uploaded nor kept twice. Never an export, a copied folder or the hook's late days.
|
|
713
|
+
*/
|
|
714
|
+
const historyRunId = (bodies) => {
|
|
715
|
+
const h = createHash("sha256").update(`worktrust-history-run|${new Date().toISOString().slice(0, 10)}|${bodies.join("\n")}`).digest("hex");
|
|
716
|
+
return `${h.slice(0, 8)}-${h.slice(8, 12)}-4${h.slice(13, 16)}-${(8 | (parseInt(h[16], 16) & 3)).toString(16)}${h.slice(17, 20)}-${h.slice(20, 32)}`;
|
|
717
|
+
};
|
|
703
718
|
async function sendHistory(door, entries, announce = false, rebuild = false, named = false, { byDay = false, withdrawUnknown = false } = {}) {
|
|
704
719
|
let accepted = 0;
|
|
705
720
|
const { queuedHistory, historyRefusal } = await import("./history-outbox.mjs");
|
|
706
721
|
// Keep each source and its approved coupling separate.
|
|
707
722
|
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)])];
|
|
708
|
-
|
|
723
|
+
// Imported entries carry no live commit/session join.
|
|
724
|
+
const encodeBatch = (batch, run = null) => 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; }), ...(run ? { run } : {}) } } });
|
|
725
|
+
const plan = groups.flatMap(([source, group]) => { const target = source === "codex" ? codexDoor ?? door : door; return group.length > 0 && target ? batchesOf(group, byDay).map((batch) => ({ source, target, batch, run: null })) : []; });
|
|
726
|
+
if (rebuild && !byDay) for (const token of new Set(plan.map((item) => item.target.token))) {
|
|
727
|
+
const run = plan.filter((item) => item.target.token === token), id = historyRunId(run.map((item) => encodeBatch(item.batch)));
|
|
728
|
+
run.forEach((item, index) => { item.run = { id, index, count: run.length }; });
|
|
729
|
+
}
|
|
730
|
+
for (const item of plan) item.body = encodeBatch(item.batch, item.run);
|
|
709
731
|
// Persist the approved plan before sending, so later batches survive removed source files too.
|
|
710
|
-
try { for (const
|
|
732
|
+
try { for (const item of plan) queuedHistory(item.target, item.body, item.source); }
|
|
711
733
|
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; }
|
|
712
|
-
|
|
713
|
-
const
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
for (const batch of batchesOf(group, byDay)) {
|
|
717
|
-
number += 1;
|
|
718
|
-
// Imported entries carry no live commit/session join.
|
|
719
|
-
const body = encodeBatch(batch);
|
|
734
|
+
const numbers = new Map(), stopped = new Set();
|
|
735
|
+
for (const { source, target, batch, body } of plan) {
|
|
736
|
+
if (stopped.has(source)) continue;
|
|
737
|
+
const number = (numbers.get(source) ?? 0) + 1; numbers.set(source, number);
|
|
720
738
|
for (const entry of batch) retainMeasurement(entry, source);
|
|
721
739
|
// `named` (0.10.10): a copied folder's lines name their client too, so the record says which app the copy came from.
|
|
722
740
|
let queued;
|
|
723
741
|
try { queued = queuedHistory(target, body, source); }
|
|
724
|
-
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;
|
|
742
|
+
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; stopped.add(source); continue; }
|
|
725
743
|
if (queued.status === "acknowledged" && !byDay) { accepted += batch.length; RECEIPTS.alreadyHeld += batch.length; continue; }
|
|
726
744
|
if (queued.status === "review" && !flag("retry-review")) { HISTORY_DELIVERY.review += batch.length; continue; }
|
|
727
745
|
if (queued.status === "waiting") { HISTORY_DELIVERY.waiting += batch.length; continue; }
|
|
@@ -730,18 +748,36 @@ async function sendHistory(door, entries, announce = false, rebuild = false, nam
|
|
|
730
748
|
const text = await response.text();
|
|
731
749
|
try { if (!response.ok) throw Error(); confirmedReceipt(text, batch.length); }
|
|
732
750
|
catch {
|
|
733
|
-
const refusal = historyRefusal(text, response);
|
|
751
|
+
const refusal = historyRefusal(text, response);
|
|
752
|
+
// A run WorkTrust closed (seven days without its last batch, another computer's key) is final: kept here it would wait forever.
|
|
753
|
+
if (refusal.reason === "closed") { queued.close(); HISTORY_DELIVERY.refused += batch.length; continue; }
|
|
754
|
+
queued.defer(refusal.reason, refusal.seconds);
|
|
734
755
|
if (refusal.reason === "review") { HISTORY_DELIVERY.review += batch.length; continue; }
|
|
735
|
-
HISTORY_DELIVERY.waiting += batch.length;
|
|
756
|
+
HISTORY_DELIVERY.waiting += batch.length; stopped.add(source); continue;
|
|
736
757
|
}
|
|
737
758
|
queued.confirm(); accepted += batch.length; noteReceipt(text);
|
|
738
759
|
if (announce) console.log(`batch ${number}: received ${batch.length}`);
|
|
739
|
-
} catch { queued.defer("unconfirmed"); HISTORY_DELIVERY.waiting += batch.length;
|
|
740
|
-
}
|
|
760
|
+
} catch { queued.defer("unconfirmed"); HISTORY_DELIVERY.waiting += batch.length; stopped.add(source); }
|
|
741
761
|
}
|
|
742
762
|
return accepted;
|
|
743
763
|
}
|
|
744
764
|
|
|
765
|
+
/** The outbox's batches for one coupling, sent as `--resume` and the hook send them: signed, named, bounded in time. */
|
|
766
|
+
const sendQueued = (target, ms = 65_000) => (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(ms) });
|
|
767
|
+
/**
|
|
768
|
+
* PENDING HISTORY GOES BY ITSELF (0.10.27; owner, 2026-10-21). A batch the server did not receive (no network, a closed lid,
|
|
769
|
+
* the upload limit) stays in ~/.worktrust/history-outbox and is sent again by the next hook run, a few at a time, without a
|
|
770
|
+
* question: the person said yes when the run was planned, and once WorkTrust has the batch nothing waits here. A batch held
|
|
771
|
+
* for review is never resent this way (`--retry-review` is the person's own).
|
|
772
|
+
*/
|
|
773
|
+
async function resendPending(limit) {
|
|
774
|
+
try {
|
|
775
|
+
const { resumeHistory } = await import("./history-outbox.mjs");
|
|
776
|
+
for (const target of [door, ...(codexDoor && codexDoor.token !== door?.token ? [codexDoor] : [])].filter(Boolean))
|
|
777
|
+
await resumeHistory(target, { limit, confirmed: confirmedReceipt, note: noteReceipt, send: sendQueued(target, 20_000) });
|
|
778
|
+
} catch (error) { if (process.env.WORKTRUST_HOOK_DEBUG) console.error(`worktrust: ${error.message}`); }
|
|
779
|
+
}
|
|
780
|
+
|
|
745
781
|
/** Whether the door's import_history takes `from_archive` (0.8.0): asked with tools/list, never assumed. */
|
|
746
782
|
async function doorKnowsArchive(target) {
|
|
747
783
|
if (!target) return false;
|
|
@@ -1148,12 +1184,10 @@ if (!door && !codexDoor && !DRY) { return await exitFlushed(0); } // Not coupled
|
|
|
1148
1184
|
*/
|
|
1149
1185
|
if (flag("history") && flag("resume")) {
|
|
1150
1186
|
const { resumeHistory } = await import("./history-outbox.mjs");
|
|
1151
|
-
const totals = { received: 0, review: 0, waiting: 0, batches: 0 };
|
|
1187
|
+
const totals = { received: 0, review: 0, waiting: 0, batches: 0, refused: 0 };
|
|
1152
1188
|
try {
|
|
1153
1189
|
for (const target of [door, ...(codexDoor && codexDoor.token !== door?.token ? [codexDoor] : [])].filter(Boolean)) {
|
|
1154
|
-
const result = await resumeHistory(target, { dry: DRY, retryReview: flag("retry-review"), confirmed: confirmedReceipt, note: noteReceipt,
|
|
1155
|
-
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) }),
|
|
1156
|
-
});
|
|
1190
|
+
const result = await resumeHistory(target, { dry: DRY, retryReview: flag("retry-review"), confirmed: confirmedReceipt, note: noteReceipt, send: sendQueued(target) });
|
|
1157
1191
|
for (const key of Object.keys(totals)) totals[key] += result[key];
|
|
1158
1192
|
}
|
|
1159
1193
|
console.log(JSON.stringify({ resumed: totals.received, ...totals, ...RECEIPTS }));
|
|
@@ -1291,6 +1325,9 @@ if (!DRY && late.length > 0) {
|
|
|
1291
1325
|
if (filed < late.length) for (const [id, mark] of heldBack) { if (mark) state[id] = mark; else delete state[id]; }
|
|
1292
1326
|
}
|
|
1293
1327
|
if (!DRY && (sent > 0 || filed > 0)) writeState(state);
|
|
1328
|
+
// What an earlier history run left on this computer because the server never received it: a few batches a run, by itself; not in a
|
|
1329
|
+
// run that just sent late days itself (a batch it just tried waits for the next run, as it always did).
|
|
1330
|
+
if (!DRY && late.length === 0) await resendPending(4);
|
|
1294
1331
|
|
|
1295
1332
|
// The counter, at most once a day, detached: reading every transcript takes longer than a hook
|
|
1296
1333
|
// may hold a session's exit, and its result waits for a click either way. `--stage` and never
|
package/package-release.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"AGENTS.md":"c6f5280c5bf81a14db4bdc282218fb005706e92dd9a9170c0e727716ee91685a","CLAUDE.md":"5933504f93e5a40369a4790e96dd5dad791d849d3178b1833eb64088e456aaeb","LICENSE":"3096ed1693974a90e1f4f59bf01c9559d94a7941d933e36fb81d3995a97f25c1","README.md":"
|
|
1
|
+
{"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"AGENTS.md":"c6f5280c5bf81a14db4bdc282218fb005706e92dd9a9170c0e727716ee91685a","CLAUDE.md":"5933504f93e5a40369a4790e96dd5dad791d849d3178b1833eb64088e456aaeb","LICENSE":"3096ed1693974a90e1f4f59bf01c9559d94a7941d933e36fb81d3995a97f25c1","README.md":"cc8a27fbabea83b0fb1beabf5ecb88b22bd3b119f277962dbf5a2d8ceb0bdbcd","SECURITY.md":"b0cf3c839c918f3a403ae33e857c947fe62cbbad96bee6cac748bb42924839fc","chat-exports.mjs":"04eafe333940ec03d5058d8d51062124aa12ab882bf04db03bcda5613ec69298","claude-mod.mjs":"02d86b0cdddf39879efc5194c0a5be6b41456faedec28963dc123a4e88dc3942","config-edits.mjs":"0eba2f176ef6f7afba071d6e00de0ff19ba2b283180a801dfd957aa38c1edd94","count-behaviour.mjs":"1beaec2a4d0aead76d166f89cc52441a9cf48f2e69da9888ca2091dd3a10a37b","credential-store.mjs":"a4b3540a61f4ce19e535c7f1d260c0d817686cd066d559a76db2ab108144abba","credential-vault-scripts.mjs":"7e42fe1db3885c2dec6f1de87bebfbefe2292d29179a68f3da87d19eb6c7704b","credential-vault.mjs":"279baabb217e2a3f170e8d7f2b271a88484531f9031c441360ea91561a70da99","engine-release.json":"ba2a3976481100d2dd8e35c95e7ecbc8aa61c58d50a3bd1b1262971e0b42b459","history-outbox.mjs":"013885af8239da9fbd0f7fb339383f6dbcb462f439d8900c9290757f63fb597a","log-session.mjs":"87066a26e9d2d3947540b24e34139f63b25a1e4f8e13f389fa5e2d398893c368","orchestration-contract.mjs":"ec08f303a166365b99e70b675de4cfe76c6156c2567e14b5569f6d992f0231b7","orchestration-evidence.mjs":"d0d06cecf0eb08e5c6e653c62a4f45b1eddf2119c2acb8341056b34f488d214a","orchestration-report.mjs":"d4e0a9ad8e4a01b462d22c6b1866aac291565c533ff476085d3367cb6d59bc1b","package-integrity.mjs":"a8210c9494a56bfb9a5ea3d10064c7a269f0b6330c0af7c0700e706c3c0224e3","package.json":"38a2d376319d548668011efd51db7a43255923b33a742f6963262f3361832f00","preserve-lines.mjs":"2df64a69687aa51219bf7b86b88d175cc50990fa29574b31897e41a9ebeecf43","preserve-summary.mjs":"137f781ed7021596a3f0ea67afcf2ab8616ac293f833dbb8f176e838e0ed8321","preserve.mjs":"3e369083ba43bcda2fa0622fd526aa64fcf8ad66e7b6e8f23821752c4d47ad27","runtime-install.mjs":"aab47b52c79d726ef428a24f982c648fa3f1c2dc2b574f633611d02924864e5f","session-databases.mjs":"543fd3b82d28d96d789be0a1dc9186c5fafa783e98b87e5b3b17b211542e2b4d","setup-mcp.mjs":"6ecfbf44f001dd433512b26736031ebc855b154e2bb0a401e2512b43623cd9cd","stack-rules.mjs":"b23c56e72ec56ba02b17ed895f869172d988c468a697e8d6026b0e268f61e489","stretch-evidence.mjs":"5b31a6f29b785d277e92257532f3c7cee366a79759decc7a75cfbaec2686ee13","transcript-readers.mjs":"413948644a74dc0bf1b49548be193bf596bcf82ac7eae668f624345a18e189e7","worktrust-launch.mjs":"84801bd29d472d48188c126b9ebe3989a3132b54e13cc4fe534ff7c383a294ee","worktrust.mjs":"4fc0b26c65394591ef13a354c53792926c43a4c829357c6dac12570181ac0e47"},"format":"worktrust-package/1","kind":"npm","version":"0.10.27"},"signature":"P02S_9sBSMsXrW4AmS7ioWEj0ujkHw5HVxQUBAe-lT13zLTfxhp3xVcbjl1G98VextHoGPILd2cUNzDkm3E4CQ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "worktrust",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.27",
|
|
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
|
@@ -75,7 +75,7 @@ const command = args.includes("--help") ? "help" : args.includes("--version") ?
|
|
|
75
75
|
const flag = (name) => { const at = args.indexOf(`--${name}`); return at >= 0 ? args[at + 1] : undefined; };
|
|
76
76
|
const has = (name) => args.includes(`--${name}`);
|
|
77
77
|
/** 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). */
|
|
78
|
-
const CLI_VERSION = "0.10.
|
|
78
|
+
const CLI_VERSION = "0.10.27";
|
|
79
79
|
const ORIGIN = (flag("origin") ?? process.env.WORKTRUST_ORIGIN ?? "https://app.worktrust.io").replace(/\/$/, "");
|
|
80
80
|
const MCP = flag("url") ?? process.env.WORKTRUST_MCP_URL ?? `${ORIGIN}/api/mcp`;
|
|
81
81
|
const HOME_DIR = join(homedir(), ".worktrust");
|
|
@@ -712,8 +712,12 @@ async function offerHistory(paths, token, devicePem, url = MCP, rebuild = false)
|
|
|
712
712
|
: 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.`
|
|
713
713
|
: `${n(did.new)} new lines${n(did.filled) > 0 ? `, ${n(did.filled)} lines gained what was missing` : ""}; ${n(did.alreadyHeld)} already held.`;
|
|
714
714
|
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.`);
|
|
715
|
-
|
|
716
|
-
if (
|
|
715
|
+
// KEPT ON THE SERVER (0.10.27; owner, 2026-10-21): what did not arrive stays here and goes again by itself; nothing to resume by hand.
|
|
716
|
+
if (Number(did?.delivery?.waiting) > 0) say(" Some batches did not reach WorkTrust yet. They stay on this computer and are sent again by themselves the next time npx worktrust or your AI app's hook runs.");
|
|
717
|
+
if (Number(did?.delivery?.refused) > 0) say(` WorkTrust closed an earlier run of ${did.delivery.refused} lines (it missed a batch for seven days): run npx worktrust@latest history again to send them as a new run.`);
|
|
718
|
+
// A STAGED RUN (0.10.27): WorkTrust holds every batch and rebuilds the days itself once the run is whole; the receipts say what it kept.
|
|
719
|
+
if (rebuild && n(did?.staged) > 0 && !Number(did?.delivery?.review) && !Number(did?.delivery?.waiting)) say(` ✓ Re-measured. WorkTrust holds all ${n(did.staged)} batches (${n(did.kept)} lines) and rebuilds these days itself, every AI app together, a day counted once. Sources › Logs shows it while it works.`);
|
|
720
|
+
else 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.");
|
|
717
721
|
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.");
|
|
718
722
|
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)` : ""}.`);
|
|
719
723
|
}
|
|
@@ -760,6 +764,7 @@ const historyComplete = () => { try { const state = JSON.parse(readFileSync(HIST
|
|
|
760
764
|
async function again() {
|
|
761
765
|
const before = stableVersion();
|
|
762
766
|
if (before && before !== CLI_VERSION) { await update(); return; }
|
|
767
|
+
{ const key = await freshKey(); if (key) await resendHistory(key); }
|
|
763
768
|
if (!historyComplete()) {
|
|
764
769
|
const key = await freshKey();
|
|
765
770
|
if (key) { say(); say(` Your earlier sessions are not yet measured by worktrust ${CLI_VERSION} in WorkTrust, or did not all arrive. This finishes them.`); await offerHistory(await scripts(), key.token, key.device ?? null, key.url, true); }
|
|
@@ -772,6 +777,19 @@ async function again() {
|
|
|
772
777
|
say(" This computer is coupled. `npx worktrust connect` couples it again; `npx worktrust disconnect` takes it out.");
|
|
773
778
|
}
|
|
774
779
|
|
|
780
|
+
/**
|
|
781
|
+
* PENDING HISTORY GOES BY ITSELF (0.10.27; owner, 2026-10-21): batches an earlier history run planned and the server never
|
|
782
|
+
* received (no network, a closed lid, the upload limit) are sent again here, without a question: the person said yes when the
|
|
783
|
+
* run was planned. Held-for-review batches stay held. Quiet when nothing was pending.
|
|
784
|
+
*/
|
|
785
|
+
async function resendHistory(key) {
|
|
786
|
+
const paths = await scripts(), sent = await run(paths["log-session.mjs"], ["--history", "--resume"], key.token, true, { WORKTRUST_MCP_URL: key.url, ...(key.device ? { WORKTRUST_DEVICE_KEY: key.device } : {}) });
|
|
787
|
+
let did = null;
|
|
788
|
+
try { did = JSON.parse(sent.out.trim().split("\n").reverse().find((line) => line.startsWith('{"resumed"')) ?? "null"); } catch { /* nothing pending, or an older hook */ }
|
|
789
|
+
if (Number(did?.resumed) > 0) { say(); say(` ✓ ${did.resumed} lines of earlier history that had not reached WorkTrust were sent; WorkTrust keeps them and rebuilds the days itself.`); }
|
|
790
|
+
if (Number(did?.waiting) > 0) say(" Some earlier history is still on this computer; it is sent again by itself the next time npx worktrust or your AI app's hook runs.");
|
|
791
|
+
}
|
|
792
|
+
|
|
775
793
|
async function history() {
|
|
776
794
|
const key = await freshKey();
|
|
777
795
|
if (!key) fail("this computer is not coupled through the key file. Run npx worktrust first.");
|