worktrust 0.10.26 → 0.10.28
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 +19 -7
- package/SECURITY.md +1 -1
- package/engine-release.json +1 -1
- package/history-outbox.mjs +12 -6
- package/log-session.mjs +88 -23
- package/package-release.json +1 -1
- package/package.json +1 -1
- package/worktrust.mjs +29 -6
package/README.md
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
# worktrust
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 0.10.28: an honest receipt for a re-measure
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
A re-measure that lands as new lines over lines WorkTrust had withdrawn (support's withdrawal of client-computed
|
|
6
|
+
figures, a rebuild) is said as new lines, never as "Nothing changed"; entries WorkTrust refused for carrying no
|
|
7
|
+
timeline are named. This CLI sends every session's timeline and no figure of its own since 0.10.20; WorkTrust times
|
|
8
|
+
every second itself under its own idle cap, so a locally changed constant changes nothing it counts.
|
|
9
|
+
|
|
10
|
+
## 0.10.27: history kept on the server
|
|
11
|
+
|
|
12
|
+
A re-measure (`worktrust history`) sends its batches as one run; WorkTrust keeps each batch it
|
|
13
|
+
receives and rebuilds the days itself once the run is whole, so no `--resume` is needed. A line
|
|
14
|
+
under no product name is replaced only where the new lines overlap it.
|
|
15
|
+
|
|
16
|
+
## 0.10.26: OS credential storage
|
|
17
|
+
|
|
18
|
+
Explicit `worktrust protect-key` migration: an OS-vault wrapping key protects the locally
|
|
19
|
+
encrypted coupling credentials. It does not attest that local activity is truthful. See
|
|
8
20
|
[credential protection](#credential-protection) before enabling it.
|
|
9
21
|
|
|
10
22
|
After an approved update, WorkTrust receives the running version without
|
|
@@ -388,8 +400,8 @@ the proof of possession the pairing binds, for nothing your record would gain.
|
|
|
388
400
|
|
|
389
401
|
## Credential protection
|
|
390
402
|
|
|
391
|
-
Existing installations keep private file storage until the person opts in.
|
|
392
|
-
|
|
403
|
+
Existing installations keep private file storage until the person opts in. From 0.10.26,
|
|
404
|
+
run `worktrust update`, quit the AI apps, then run `worktrust protect-key` and restart
|
|
393
405
|
those apps. A new computer can run `worktrust protect-key` before connecting. `worktrust status`
|
|
394
406
|
shows the storage mode. This command is local and does not publish or change a Passport.
|
|
395
407
|
|
|
@@ -439,7 +451,7 @@ retried safely. A row kept pending on WorkTrust remains excluded from counted ac
|
|
|
439
451
|
| **Reads** | Which AI apps are installed (the settings folders of Claude Code, Codex, Cursor, Gemini CLI, Antigravity, VS Code, Windsurf, Hermes Agent, Goose, OpenCode, OpenClaw), and the chats Cursor and Copilot keep (clocks, models and token counts only). Afterwards, the session hook reads Claude Code's, Codex's and Antigravity's session files, the session databases of Hermes, Goose, OpenCode and OpenClaw, and the chats Cursor and Copilot keep, on this computer to measure durations and token counts. |
|
|
440
452
|
| **Writes** | The key file (above). In each AI app's MCP settings (`~/.claude.json` through `claude mcp`, `~/.cursor/mcp.json`, `~/.codex/config.toml`, `~/.gemini/settings.json`, `~/.gemini/config/mcp_config.json` (Antigravity), VS Code's `mcp.json`, Windsurf's `mcp_config.json`, Hermes's and Goose's `config.yaml`, OpenCode's `opencode.json`, OpenClaw through `openclaw mcp set`) a WorkTrust entry that runs the local bridge, with no key in it; three hooks in `~/.claude/settings.json`; the bridge, the hook and the counter in `~/.worktrust/`. |
|
|
441
453
|
| **Sends, to pair** | This computer's system (macOS, Windows, Linux) and host name. WorkTrust also records the network address the request arrives from, as a security record kept 90 days and seen only by WorkTrust staff (to answer a theft or fraud report). |
|
|
442
|
-
| **Sends, afterwards** | Per measured stretch of work, and nothing else: its timeline and basis (`timeline`, `duration_basis`: since 0.10.20 the CLI sends no duration and no hours in layers of its own; WorkTrust computes them from the timeline), token counts (`tokens_in`, `tokens_out`, `tokens_cache_read`, `tokens_cache_write`, `token_basis`), the model's name (`model`), the kind of work and one layer keyword such as frontend or backend (`title`, `kind`, `layer`, `layers`), closed technology keys (`stack`) and separate display-only tool keys (`tools_seen`), how the turns are counted (`turn_basis`; the counts themselves WorkTrust reads from the timeline; the subagents' seconds wait for a timeline per run), when it began and ended and your computer's offset from UTC (`started_at`, `at`, `utc_offset`), what the CLI derived from the stretch as kinds and counts (`evidence`: checks run and failed, delivery steps and whether a check passed first, recoveries, delegation, context, routing, steering, refusals, planning, files and test files changed, the complexity class; with the WorkTrust mod on, its `live` counts from inside Claude Code: permission answers, effort levels, context and plan-limit peaks, subagents and setup; never a word, a command or a path; since 0.8.3, `live` since 0.10.15), a hash of the session and the day (`stretch_ref`), `steered_from` when it ran over SSH, the stretch's clock as step kinds and whole seconds so WorkTrust computes the figures itself (`timeline`, since 0.10.20: never a word, a tool name or a path), the CLI's version and a digest of its own files as signals (`cli_version`, `cli_digest`), and, so the work can be matched to GitHub, the repository as its remote's owner/name (`repo`, only for a repository on GitHub, GitLab or Bitbucket, the hosts WorkTrust can couple; never one on your own or a client's server) and the hashes of the commits made in the stretch (`commits`, never their messages). |
|
|
454
|
+
| **Sends, afterwards** | Per measured stretch of work, and nothing else: its timeline and basis (`timeline`, `duration_basis`: since 0.10.20 the CLI sends no duration and no hours in layers of its own; WorkTrust computes them from the timeline), token counts (`tokens_in`, `tokens_out`, `tokens_cache_read`, `tokens_cache_write`, `token_basis`), the model's name (`model`), the kind of work and one layer keyword such as frontend or backend (`title`, `kind`, `layer`, `layers`), closed technology keys (`stack`) and separate display-only tool keys (`tools_seen`), how the turns are counted (`turn_basis`; the counts themselves WorkTrust reads from the timeline; the subagents' seconds wait for a timeline per run), when it began and ended and your computer's offset from UTC (`started_at`, `at`, `utc_offset`), what the CLI derived from the stretch as kinds and counts (`evidence`: checks run and failed, delivery steps and whether a check passed first, recoveries, delegation, context, routing, steering, refusals, planning, files and test files changed, the complexity class; with the WorkTrust mod on, its `live` counts from inside Claude Code: permission answers, effort levels, context and plan-limit peaks, subagents and setup; never a word, a command or a path; since 0.8.3, `live` since 0.10.15), a hash of the session and the day (`stretch_ref`), `steered_from` when it ran over SSH, the stretch's clock as step kinds and whole seconds so WorkTrust computes the figures itself (`timeline`, since 0.10.20: never a word, a tool name or a path), the CLI's version and a digest of its own files as signals (`cli_version`, `cli_digest`), and, so the work can be matched to GitHub, the repository as its remote's owner/name (`repo`, only for a repository on GitHub, GitLab or Bitbucket, the hosts WorkTrust can couple; never one on your own or a client's server), for any other git repository a code in its place (`repo_code`: 16 hex of an HMAC of its remote, or its root, keyed with this computer's own secret in `~/.worktrust/archive-salt`, which is never sent, so WorkTrust can group its lines but cannot tell which repository it is) and the hashes of the commits made in the stretch (`commits`, never their messages). |
|
|
443
455
|
| **Never sends** | Prompts, answers, code, file names or paths, commit messages, branch names, or the name of your local folder (a repository is named only as its remote's owner/name, above). The door has no field for them and refuses a submission that carries them. |
|
|
444
456
|
|
|
445
457
|
**The clock is WorkTrust's, not this computer's (0.10.20).** A measured stretch travels as its timeline: one step per
|
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":"11d005f6a87b821c66f006ff62d06d43fcb2cf381305fd5705908ab65ab7f5d0","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":"e79368c66a5eb2c99c07fdd2498efc0e0b7a5bea3e71ad21a0262da5bc42d446"},"format":"worktrust-package/1","kind":"engine","version":"0.10.28"},"signature":"pl6yOiAY_MOFDH6d8Fp8SzlIVziC6DFlWI2tmoz5QU3eys3APzf8pLZbOcIGwQTJsKQt25TXOHzhEQ3i5mbLCg"}
|
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
|
@@ -64,9 +64,9 @@ import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, wri
|
|
|
64
64
|
import { homedir } from "node:os";
|
|
65
65
|
import { dirname, join, resolve, sep } from "node:path";
|
|
66
66
|
import { fileURLToPath } from "node:url";
|
|
67
|
-
import { createHash, createPrivateKey, createPublicKey, randomBytes, sign as cryptoSign } from "node:crypto";
|
|
67
|
+
import { createHash, createHmac, createPrivateKey, createPublicKey, randomBytes, sign as cryptoSign } from "node:crypto";
|
|
68
68
|
|
|
69
|
-
import { moduleArgs, moduleExecutable } from "./package-integrity.mjs";
|
|
69
|
+
import { moduleArgs, moduleExecutable, readPrivateFile, createPrivateFile } from "./package-integrity.mjs";
|
|
70
70
|
|
|
71
71
|
async function main() {
|
|
72
72
|
const args = process.argv.slice(2), NODE_FLAGS = process.versions.node === "26.5.0" ? ["--no-concurrent-sparkplug"] : [];
|
|
@@ -320,6 +320,32 @@ const repoOf = (cwd) => {
|
|
|
320
320
|
const match = /[:/]([^/:]+)\/([^/]+?)(?:\.git)?$/.exec(remote);
|
|
321
321
|
return match ? `${match[1]}/${match[2]}` : null;
|
|
322
322
|
};
|
|
323
|
+
/**
|
|
324
|
+
* A REPOSITORY IT MAY NOT NAME, AS A CODE ONLY THIS COMPUTER CAN MAKE (owner, 2026-10-21). For a git repository whose remote is
|
|
325
|
+
* on no host WorkTrust can couple (or that has no remote), the name still never travels (0.8.6); what travels is 16 hex of an
|
|
326
|
+
* HMAC-SHA256, keyed with this computer's own secret (~/.worktrust/archive-salt, the archive's, made once with mode 600, never
|
|
327
|
+
* sent), over the normalised remote (host and path, no user, no secret, no .git) or, without one, the repository's root. The
|
|
328
|
+
* same repository gives the same code here, so its lines can be grouped and filed once; WorkTrust cannot turn a code back into
|
|
329
|
+
* a name, because it never holds the key. A folder that is no git repository gets no code.
|
|
330
|
+
*/
|
|
331
|
+
let repoSecret;
|
|
332
|
+
const repoCodeSecret = () => {
|
|
333
|
+
if (repoSecret !== undefined) return repoSecret;
|
|
334
|
+
const file = join(homedir(), ".worktrust", "archive-salt");
|
|
335
|
+
try { const kept = readPrivateFile(file)?.trim(); if (/^[0-9a-f]{64}$/.test(kept ?? "")) return (repoSecret = kept); } catch { /* first run */ }
|
|
336
|
+
try { const made = randomBytes(32).toString("hex"); createPrivateFile(file, `${made}\n`); return (repoSecret = made); } catch { try { const kept = readPrivateFile(file)?.trim(); return (repoSecret = /^[0-9a-f]{64}$/.test(kept ?? "") ? kept : null); } catch { return (repoSecret = null); } }
|
|
337
|
+
};
|
|
338
|
+
const repoCodeOf = (cwd) => {
|
|
339
|
+
const root = git(cwd, "rev-parse", "--show-toplevel");
|
|
340
|
+
if (!root) return null;
|
|
341
|
+
const remote = git(cwd, "remote", "get-url", "origin");
|
|
342
|
+
if (remote && CODE_HOSTS.test(remote)) return null;
|
|
343
|
+
const name = remote
|
|
344
|
+
? `remote:${remote.trim().toLowerCase().replace(/^[a-z][a-z0-9+.-]*:\/\//, "").replace(/^[^@/]+@/, "").replace(/:(?!\d)/, "/").replace(/\.git$/, "").replace(/\/+$/, "")}`
|
|
345
|
+
: `root:${root}`;
|
|
346
|
+
const secret = repoCodeSecret();
|
|
347
|
+
return secret ? createHmac("sha256", secret).update(`worktrust-repo-code|${name}`).digest("hex").slice(0, 16) : null;
|
|
348
|
+
};
|
|
323
349
|
/** The paths this stretch touched: what was committed inside it, else what is still uncommitted. */
|
|
324
350
|
const pathsTouched = (cwd, from, to) => {
|
|
325
351
|
const committed = git(cwd, "log", `--since=${from}`, `--until=${to}`, "--name-only", "--pretty=format:", "--no-merges");
|
|
@@ -573,6 +599,7 @@ const STEERED_HERE = process.env.SSH_CONNECTION || process.env.SSH_CLIENT || pro
|
|
|
573
599
|
function payloadFor(stretch) {
|
|
574
600
|
const cwd = stretch.cwd && existsSync(stretch.cwd) ? stretch.cwd : null;
|
|
575
601
|
const repo = cwd ? repoOf(cwd) : null;
|
|
602
|
+
const repoCode = cwd && !repo ? repoCodeOf(cwd) : null; // a code, never a name, for a repository it may not name
|
|
576
603
|
const touched = cwd ? pathsTouched(cwd, new Date(stretch.from).toISOString(), new Date(stretch.to).toISOString()) : { paths: [], committed: false, shas: [] };
|
|
577
604
|
const { layer, layers } = layersOf(touched.paths), stack = stackOfFiles(touched.paths), toolsSeen = displayStackOfFiles(touched.paths); // 0.10.11: the stack and the tools seen, from the same paths, keys only, two fields
|
|
578
605
|
// The seventh kind, used as it is defined: a stretch that changed no artefact is knowing
|
|
@@ -606,6 +633,7 @@ function payloadFor(stretch) {
|
|
|
606
633
|
...(stretch.shapeKnown && stretch.cacheWrite > 0 ? { tokens_cache_write: stretch.cacheWrite } : {}),
|
|
607
634
|
...(stretch.model ? { model: stretch.model } : {}),
|
|
608
635
|
...(repo ? { repo } : {}),
|
|
636
|
+
...(repoCode ? { repo_code: repoCode } : {}),
|
|
609
637
|
...(touched.shas.length > 0 ? { commits: touched.shas.slice(0, 50) } : {}),
|
|
610
638
|
...(stretch.ref ? { stretch_ref: stretch.ref } : {}), ...(stretch.steered ? { steered_from: stretch.steered } : {}),
|
|
611
639
|
// WHICH CODE SENT IT (0.10.20): a version and a digest of this hook's own files, signals never proof.
|
|
@@ -654,7 +682,7 @@ function batchesOf(group, byDay) {
|
|
|
654
682
|
return out;
|
|
655
683
|
}
|
|
656
684
|
/** 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
|
|
685
|
+
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, restored: 0, untimed: 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
686
|
const noteReceipt = (answer) => {
|
|
659
687
|
try {
|
|
660
688
|
const json = JSON.parse(answer.trim().startsWith("{") ? answer : answer.split("\n").find((row) => row.startsWith("data:"))?.slice(5) ?? "null");
|
|
@@ -675,6 +703,10 @@ function confirmedReceipt(answer, expectedCount = null) {
|
|
|
675
703
|
const receipt = JSON.parse(content[0].text);
|
|
676
704
|
if (expectedCount === null) {
|
|
677
705
|
if (!(receipt.receipt === "received" && ["accepted", "flagged", "pending"].includes(receipt.status)) && !(receipt.receipt === "unchanged" && receipt.reason === "duplicate")) throw Error();
|
|
706
|
+
} else if (receipt.staged === true) {
|
|
707
|
+
// KEPT ON THE SERVER (0.10.27): a batch of a run WorkTrust holds and rebuilds itself; every line counted as kept or refused.
|
|
708
|
+
if (receipt.receipt !== "received" || receipt.received !== expectedCount || !Number.isInteger(receipt.kept) || receipt.kept < 0
|
|
709
|
+
|| !Number.isInteger(receipt.refused) || receipt.refused < 0 || receipt.kept + receipt.refused > expectedCount) throw Error();
|
|
678
710
|
} else if (receipt.receipt !== "received" || receipt.received !== expectedCount || receipt.refused !== 0
|
|
679
711
|
|| !Number.isInteger(receipt.new) || receipt.new < 0 || !Number.isInteger(receipt.alreadyHeld) || receipt.alreadyHeld < 0
|
|
680
712
|
|| receipt.new + receipt.alreadyHeld !== expectedCount) throw Error();
|
|
@@ -699,29 +731,43 @@ function retainMeasurement(payload, source) {
|
|
|
699
731
|
}
|
|
700
732
|
} finally { closeSync(fd); unlinkSync(temporary); }
|
|
701
733
|
}
|
|
702
|
-
const HISTORY_DELIVERY = { review: 0, waiting: 0 };
|
|
734
|
+
const HISTORY_DELIVERY = { review: 0, waiting: 0, refused: 0 };
|
|
735
|
+
/**
|
|
736
|
+
* 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
|
|
737
|
+
* 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
|
|
738
|
+
* 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
|
|
739
|
+
* 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
|
|
740
|
+
* batch already received is neither uploaded nor kept twice. Never an export, a copied folder or the hook's late days.
|
|
741
|
+
*/
|
|
742
|
+
const historyRunId = (bodies) => {
|
|
743
|
+
const h = createHash("sha256").update(`worktrust-history-run|${new Date().toISOString().slice(0, 10)}|${bodies.join("\n")}`).digest("hex");
|
|
744
|
+
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)}`;
|
|
745
|
+
};
|
|
703
746
|
async function sendHistory(door, entries, announce = false, rebuild = false, named = false, { byDay = false, withdrawUnknown = false } = {}) {
|
|
704
747
|
let accepted = 0;
|
|
705
748
|
const { queuedHistory, historyRefusal } = await import("./history-outbox.mjs");
|
|
706
749
|
// Keep each source and its approved coupling separate.
|
|
707
750
|
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
|
-
|
|
751
|
+
// Imported entries carry no live commit/session join.
|
|
752
|
+
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 } : {}) } } });
|
|
753
|
+
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 })) : []; });
|
|
754
|
+
if (rebuild && !byDay) for (const token of new Set(plan.map((item) => item.target.token))) {
|
|
755
|
+
const run = plan.filter((item) => item.target.token === token), id = historyRunId(run.map((item) => encodeBatch(item.batch)));
|
|
756
|
+
run.forEach((item, index) => { item.run = { id, index, count: run.length }; });
|
|
757
|
+
}
|
|
758
|
+
for (const item of plan) item.body = encodeBatch(item.batch, item.run);
|
|
709
759
|
// Persist the approved plan before sending, so later batches survive removed source files too.
|
|
710
|
-
try { for (const
|
|
760
|
+
try { for (const item of plan) queuedHistory(item.target, item.body, item.source); }
|
|
711
761
|
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);
|
|
762
|
+
const numbers = new Map(), stopped = new Set();
|
|
763
|
+
for (const { source, target, batch, body } of plan) {
|
|
764
|
+
if (stopped.has(source)) continue;
|
|
765
|
+
const number = (numbers.get(source) ?? 0) + 1; numbers.set(source, number);
|
|
720
766
|
for (const entry of batch) retainMeasurement(entry, source);
|
|
721
767
|
// `named` (0.10.10): a copied folder's lines name their client too, so the record says which app the copy came from.
|
|
722
768
|
let queued;
|
|
723
769
|
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;
|
|
770
|
+
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
771
|
if (queued.status === "acknowledged" && !byDay) { accepted += batch.length; RECEIPTS.alreadyHeld += batch.length; continue; }
|
|
726
772
|
if (queued.status === "review" && !flag("retry-review")) { HISTORY_DELIVERY.review += batch.length; continue; }
|
|
727
773
|
if (queued.status === "waiting") { HISTORY_DELIVERY.waiting += batch.length; continue; }
|
|
@@ -730,18 +776,36 @@ async function sendHistory(door, entries, announce = false, rebuild = false, nam
|
|
|
730
776
|
const text = await response.text();
|
|
731
777
|
try { if (!response.ok) throw Error(); confirmedReceipt(text, batch.length); }
|
|
732
778
|
catch {
|
|
733
|
-
const refusal = historyRefusal(text, response);
|
|
779
|
+
const refusal = historyRefusal(text, response);
|
|
780
|
+
// A run WorkTrust closed (seven days without its last batch, another computer's key) is final: kept here it would wait forever.
|
|
781
|
+
if (refusal.reason === "closed") { queued.close(); HISTORY_DELIVERY.refused += batch.length; continue; }
|
|
782
|
+
queued.defer(refusal.reason, refusal.seconds);
|
|
734
783
|
if (refusal.reason === "review") { HISTORY_DELIVERY.review += batch.length; continue; }
|
|
735
|
-
HISTORY_DELIVERY.waiting += batch.length;
|
|
784
|
+
HISTORY_DELIVERY.waiting += batch.length; stopped.add(source); continue;
|
|
736
785
|
}
|
|
737
786
|
queued.confirm(); accepted += batch.length; noteReceipt(text);
|
|
738
787
|
if (announce) console.log(`batch ${number}: received ${batch.length}`);
|
|
739
|
-
} catch { queued.defer("unconfirmed"); HISTORY_DELIVERY.waiting += batch.length;
|
|
740
|
-
}
|
|
788
|
+
} catch { queued.defer("unconfirmed"); HISTORY_DELIVERY.waiting += batch.length; stopped.add(source); }
|
|
741
789
|
}
|
|
742
790
|
return accepted;
|
|
743
791
|
}
|
|
744
792
|
|
|
793
|
+
/** The outbox's batches for one coupling, sent as `--resume` and the hook send them: signed, named, bounded in time. */
|
|
794
|
+
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) });
|
|
795
|
+
/**
|
|
796
|
+
* PENDING HISTORY GOES BY ITSELF (0.10.27; owner, 2026-10-21). A batch the server did not receive (no network, a closed lid,
|
|
797
|
+
* the upload limit) stays in ~/.worktrust/history-outbox and is sent again by the next hook run, a few at a time, without a
|
|
798
|
+
* question: the person said yes when the run was planned, and once WorkTrust has the batch nothing waits here. A batch held
|
|
799
|
+
* for review is never resent this way (`--retry-review` is the person's own).
|
|
800
|
+
*/
|
|
801
|
+
async function resendPending(limit) {
|
|
802
|
+
try {
|
|
803
|
+
const { resumeHistory } = await import("./history-outbox.mjs");
|
|
804
|
+
for (const target of [door, ...(codexDoor && codexDoor.token !== door?.token ? [codexDoor] : [])].filter(Boolean))
|
|
805
|
+
await resumeHistory(target, { limit, confirmed: confirmedReceipt, note: noteReceipt, send: sendQueued(target, 20_000) });
|
|
806
|
+
} catch (error) { if (process.env.WORKTRUST_HOOK_DEBUG) console.error(`worktrust: ${error.message}`); }
|
|
807
|
+
}
|
|
808
|
+
|
|
745
809
|
/** Whether the door's import_history takes `from_archive` (0.8.0): asked with tools/list, never assumed. */
|
|
746
810
|
async function doorKnowsArchive(target) {
|
|
747
811
|
if (!target) return false;
|
|
@@ -1148,12 +1212,10 @@ if (!door && !codexDoor && !DRY) { return await exitFlushed(0); } // Not coupled
|
|
|
1148
1212
|
*/
|
|
1149
1213
|
if (flag("history") && flag("resume")) {
|
|
1150
1214
|
const { resumeHistory } = await import("./history-outbox.mjs");
|
|
1151
|
-
const totals = { received: 0, review: 0, waiting: 0, batches: 0 };
|
|
1215
|
+
const totals = { received: 0, review: 0, waiting: 0, batches: 0, refused: 0 };
|
|
1152
1216
|
try {
|
|
1153
1217
|
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
|
-
});
|
|
1218
|
+
const result = await resumeHistory(target, { dry: DRY, retryReview: flag("retry-review"), confirmed: confirmedReceipt, note: noteReceipt, send: sendQueued(target) });
|
|
1157
1219
|
for (const key of Object.keys(totals)) totals[key] += result[key];
|
|
1158
1220
|
}
|
|
1159
1221
|
console.log(JSON.stringify({ resumed: totals.received, ...totals, ...RECEIPTS }));
|
|
@@ -1291,6 +1353,9 @@ if (!DRY && late.length > 0) {
|
|
|
1291
1353
|
if (filed < late.length) for (const [id, mark] of heldBack) { if (mark) state[id] = mark; else delete state[id]; }
|
|
1292
1354
|
}
|
|
1293
1355
|
if (!DRY && (sent > 0 || filed > 0)) writeState(state);
|
|
1356
|
+
// 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
|
|
1357
|
+
// run that just sent late days itself (a batch it just tried waits for the next run, as it always did).
|
|
1358
|
+
if (!DRY && late.length === 0) await resendPending(4);
|
|
1294
1359
|
|
|
1295
1360
|
// The counter, at most once a day, detached: reading every transcript takes longer than a hook
|
|
1296
1361
|
// 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":"7216321b23aa02817322944fcfd76e26d9aa3620695e18e36fbf73b7fef78c7b","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":"0a08942197df86503fd8d171c22127046026d070af381201ae0a6c2f379e8107","history-outbox.mjs":"013885af8239da9fbd0f7fb339383f6dbcb462f439d8900c9290757f63fb597a","log-session.mjs":"11d005f6a87b821c66f006ff62d06d43fcb2cf381305fd5705908ab65ab7f5d0","orchestration-contract.mjs":"ec08f303a166365b99e70b675de4cfe76c6156c2567e14b5569f6d992f0231b7","orchestration-evidence.mjs":"d0d06cecf0eb08e5c6e653c62a4f45b1eddf2119c2acb8341056b34f488d214a","orchestration-report.mjs":"d4e0a9ad8e4a01b462d22c6b1866aac291565c533ff476085d3367cb6d59bc1b","package-integrity.mjs":"a8210c9494a56bfb9a5ea3d10064c7a269f0b6330c0af7c0700e706c3c0224e3","package.json":"09c69b353ef8fe916c9b5ccad9e7050146651f7f6cf028b75ab7e05358c39c70","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":"e79368c66a5eb2c99c07fdd2498efc0e0b7a5bea3e71ad21a0262da5bc42d446"},"format":"worktrust-package/1","kind":"npm","version":"0.10.28"},"signature":"W4F1Gr-yudsBRtwEEO3qym7ktxPZMrzicMU3vY20FfYOCjbNqnxsEYWYPzAskhq0btJ2FyM_HNKEkZpelI__CA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "worktrust",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.28",
|
|
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.28";
|
|
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");
|
|
@@ -707,13 +707,22 @@ async function offerHistory(paths, token, devicePem, url = MCP, rebuild = false)
|
|
|
707
707
|
// "replaced". The hook sums the receipts of every batch and prints one line; without it (an older hook) the sentence stays neutral.
|
|
708
708
|
const did = (() => { try { return JSON.parse(sent.out.trim().split("\n").reverse().find((line) => line.startsWith('{"history_sent"')) ?? "null"); } catch { return null; } })();
|
|
709
709
|
const n = (value) => Number(value) || 0;
|
|
710
|
+
// AN HONEST RECEIPT (owner, 2026-10-22; 0.10.28): a re-measure that landed as new lines over lines WorkTrust had withdrawn or
|
|
711
|
+
// cut off is said as new lines, never as "Nothing changed"; `restored` counts the ones WorkTrust landed over a support-withdrawn
|
|
712
|
+
// original with its own clock (the withdrawn line stays withdrawn). `untimed` names entries refused for carrying no timeline.
|
|
713
|
+
const landed = n(did.new) + n(did.restored);
|
|
710
714
|
const outcome = !did ? "The record shows what changed."
|
|
711
|
-
: n(did.replaced) > 0 ? `${n(did.replaced)} of this computer's earlier lines were replaced (withdrawn and kept, never deleted)${
|
|
712
|
-
:
|
|
713
|
-
: `${n(did.
|
|
715
|
+
: n(did.replaced) > 0 ? `${n(did.replaced)} of this computer's earlier lines were replaced (withdrawn and kept, never deleted)${landed > 0 ? `, ${landed} new` : ""}${n(did.filled) > 0 ? `, ${n(did.filled)} lines gained what was missing` : ""}.`
|
|
716
|
+
: landed === 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.`
|
|
717
|
+
: `${landed} new lines${n(did.restored) > 0 ? ` (${n(did.restored)} timed by WorkTrust in place of lines it had withdrawn)` : ""}${n(did.filled) > 0 ? `, ${n(did.filled)} lines gained what was missing` : ""}; ${n(did.alreadyHeld)} already held.`;
|
|
718
|
+
if (n(did?.untimed) > 0) say(` ${n(did.untimed)} lines were refused: they carried no timeline, so WorkTrust could not time them itself. This CLI sends every session's timeline; a line without one came from an older copy or an archive.`);
|
|
714
719
|
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 (
|
|
720
|
+
// 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.
|
|
721
|
+
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.");
|
|
722
|
+
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.`);
|
|
723
|
+
// 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.
|
|
724
|
+
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.`);
|
|
725
|
+
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
726
|
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
727
|
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
728
|
}
|
|
@@ -760,6 +769,7 @@ const historyComplete = () => { try { const state = JSON.parse(readFileSync(HIST
|
|
|
760
769
|
async function again() {
|
|
761
770
|
const before = stableVersion();
|
|
762
771
|
if (before && before !== CLI_VERSION) { await update(); return; }
|
|
772
|
+
{ const key = await freshKey(); if (key) await resendHistory(key); }
|
|
763
773
|
if (!historyComplete()) {
|
|
764
774
|
const key = await freshKey();
|
|
765
775
|
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 +782,19 @@ async function again() {
|
|
|
772
782
|
say(" This computer is coupled. `npx worktrust connect` couples it again; `npx worktrust disconnect` takes it out.");
|
|
773
783
|
}
|
|
774
784
|
|
|
785
|
+
/**
|
|
786
|
+
* PENDING HISTORY GOES BY ITSELF (0.10.27; owner, 2026-10-21): batches an earlier history run planned and the server never
|
|
787
|
+
* received (no network, a closed lid, the upload limit) are sent again here, without a question: the person said yes when the
|
|
788
|
+
* run was planned. Held-for-review batches stay held. Quiet when nothing was pending.
|
|
789
|
+
*/
|
|
790
|
+
async function resendHistory(key) {
|
|
791
|
+
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 } : {}) });
|
|
792
|
+
let did = null;
|
|
793
|
+
try { did = JSON.parse(sent.out.trim().split("\n").reverse().find((line) => line.startsWith('{"resumed"')) ?? "null"); } catch { /* nothing pending, or an older hook */ }
|
|
794
|
+
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.`); }
|
|
795
|
+
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.");
|
|
796
|
+
}
|
|
797
|
+
|
|
775
798
|
async function history() {
|
|
776
799
|
const key = await freshKey();
|
|
777
800
|
if (!key) fail("this computer is not coupled through the key file. Run npx worktrust first.");
|