worktrust 0.10.20 → 0.10.21
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 +20 -0
- package/SECURITY.md +8 -0
- package/log-session.mjs +45 -3
- package/package.json +1 -1
- package/worktrust.mjs +3 -1
package/README.md
CHANGED
|
@@ -254,6 +254,12 @@ and counts, exactly as the session hook reads it.
|
|
|
254
254
|
|
|
255
255
|
## Rebuild the history
|
|
256
256
|
|
|
257
|
+
From **0.10.21 (release candidate)**, changed measured history waits for review before it
|
|
258
|
+
can replace measurements already received for that computer, client and historical day.
|
|
259
|
+
The earlier receipt is retained as local activity, not independent proof of human effort.
|
|
260
|
+
Other computers and periods remain on the record, including an unavailable old laptop.
|
|
261
|
+
A support withdrawal is not reversed by reconnecting or running a rebuild.
|
|
262
|
+
|
|
257
263
|
Since 0.10.5 there is one path: `npx worktrust@latest history` always re-measures and replaces this computer's earlier
|
|
258
264
|
lines day by day. If a send did not finish, or you merged two keys of one computer, run `npx worktrust@latest` again:
|
|
259
265
|
it finishes what did not arrive and never counts a day twice.
|
|
@@ -385,6 +391,20 @@ which would delete every password on the computer, and many people rightly keep
|
|
|
385
391
|
|
|
386
392
|
## What it reads, writes and sends
|
|
387
393
|
|
|
394
|
+
From **0.10.21 (release candidate)**, before each submission the hook keeps a local
|
|
395
|
+
metadata file in `~/.worktrust/measurements/`. The `worktrust-measurement/1` format retains
|
|
396
|
+
the available timeline, opaque stretch reference, dates, counts and collector identifiers.
|
|
397
|
+
It omits prompts, answers, titles, repository names, file paths, endpoint URLs and credentials.
|
|
398
|
+
Files request mode 0600 in a mode-0700 directory; Windows ACLs need their own validation.
|
|
399
|
+
Retries retain the same metadata once; changed measurements get a separate file. Disconnecting
|
|
400
|
+
does not erase this journal. You control its retention and backups; it is not a remote backup.
|
|
401
|
+
Keep the regular `preserve --archive` archive too if your AI app removes its session files.
|
|
402
|
+
Metadata cannot reconstruct deleted conversation text or observations it never recorded.
|
|
403
|
+
|
|
404
|
+
A successful HTTP response alone does not advance progress. The hook requires an explicit
|
|
405
|
+
receipt; JSON-RPC errors, tool errors, incomplete receipts and partially refused batches are
|
|
406
|
+
retried safely. A row kept pending on WorkTrust remains excluded from counted activity.
|
|
407
|
+
|
|
388
408
|
| | |
|
|
389
409
|
|---|---|
|
|
390
410
|
| **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. |
|
package/SECURITY.md
CHANGED
|
@@ -48,6 +48,14 @@ private transcripts or account data in a public issue.
|
|
|
48
48
|
|
|
49
49
|
## What measurement signatures establish
|
|
50
50
|
|
|
51
|
+
The metadata journal introduced in the 0.10.21 candidate preserves observations, not their
|
|
52
|
+
truth. A user who controls the computer can fabricate session files, timestamps, counters,
|
|
53
|
+
model labels and software-key signatures, or name an official code digest. Server-side
|
|
54
|
+
recalculation detects a conflicting arithmetic claim; it cannot authenticate a fabricated
|
|
55
|
+
timeline. Prior receipts provide a comparison baseline, not independent confirmation.
|
|
56
|
+
Changed historical replacements are held for review without overwriting that baseline.
|
|
57
|
+
The journal is not encrypted storage, hardware attestation or a server-signed archive.
|
|
58
|
+
|
|
51
59
|
Request proofs authenticate possession of the device key. Archive seals make later changes
|
|
52
60
|
detectable relative to their trusted key/root. Neither proves that the client is unmodified, that
|
|
53
61
|
local input files are authentic, or that work really happened. Local-only archive keys do not grant
|
package/log-session.mjs
CHANGED
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
* honoured here too, matched against the transcript's project directory, before a file is read.
|
|
61
61
|
*/
|
|
62
62
|
import { execFileSync, spawn, spawnSync } from "node:child_process";
|
|
63
|
-
import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
63
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync, lstatSync, openSync, closeSync, fsyncSync, linkSync, unlinkSync, constants } from "node:fs";
|
|
64
64
|
import { homedir } from "node:os";
|
|
65
65
|
import { dirname, join, resolve, sep } from "node:path";
|
|
66
66
|
import { fileURLToPath } from "node:url";
|
|
@@ -698,6 +698,43 @@ const noteReceipt = (answer) => {
|
|
|
698
698
|
for (const key of Object.keys(RECEIPTS)) RECEIPTS[key] += Number(receipt[key]) || 0;
|
|
699
699
|
} catch { /* a receipt unread leaves the counts short, never the send */ }
|
|
700
700
|
};
|
|
701
|
+
/** Only explicit durable receipts authorize a checkpoint. HTTP 200 alone says nothing. */
|
|
702
|
+
function confirmedReceipt(answer, expectedCount = null) {
|
|
703
|
+
try {
|
|
704
|
+
const candidates = answer.trim().startsWith("{") ? [answer] : answer.split(/\r?\n/).filter(line => line.startsWith("data:")).map(line => line.slice(5).trim()).filter(line => line && line !== "[DONE]");
|
|
705
|
+
const replies = candidates.map(text => JSON.parse(text)).filter(reply => reply?.id === 1);
|
|
706
|
+
if (replies.length !== 1) throw Error();
|
|
707
|
+
const reply = replies[0];
|
|
708
|
+
if (reply.jsonrpc !== "2.0" || reply.error || !reply.result || reply.result.isError === true) throw Error();
|
|
709
|
+
const content = reply.result.content;
|
|
710
|
+
if (!Array.isArray(content) || content.length !== 1 || content[0].type !== "text") throw Error();
|
|
711
|
+
const receipt = JSON.parse(content[0].text);
|
|
712
|
+
if (expectedCount === null) {
|
|
713
|
+
if (!(receipt.receipt === "received" && ["accepted", "flagged", "pending"].includes(receipt.status)) && !(receipt.receipt === "unchanged" && receipt.reason === "duplicate")) throw Error();
|
|
714
|
+
} else if (receipt.receipt !== "received" || receipt.received !== expectedCount || receipt.refused !== 0
|
|
715
|
+
|| !Number.isInteger(receipt.new) || receipt.new < 0 || !Number.isInteger(receipt.alreadyHeld) || receipt.alreadyHeld < 0
|
|
716
|
+
|| receipt.new + receipt.alreadyHeld !== expectedCount) throw Error();
|
|
717
|
+
return receipt;
|
|
718
|
+
} catch { throw Error("WorkTrust did not confirm every line; progress was not advanced. Retained metadata and safe retries remain available."); }
|
|
719
|
+
}
|
|
720
|
+
/** A private metadata journal survives retries, an edited transcript and a later CLI update. */
|
|
721
|
+
function retainMeasurement(payload, source) {
|
|
722
|
+
const fields = ["stretch_ref", "at", "started_at", "timeline", "seconds", "client_seconds", "model_seconds", "tool_seconds", "human_seconds", "idle_seconds", "tokens_in", "tokens_out", "tokens_cache_read", "tokens_cache_write", "exchanges", "interrupts", "steers", "agent_runs", "agent_seconds", "agent_peak", "duration_basis", "token_basis", "turn_basis", "cli_version", "cli_digest"];
|
|
723
|
+
const metadata = Object.fromEntries(fields.filter(key => Object.hasOwn(payload, key)).map(key => [key, payload[key]]));
|
|
724
|
+
const body = JSON.stringify({ format: "worktrust-measurement/1", source: source ?? "claude", metadata }) + "\n";
|
|
725
|
+
const parent = join(homedir(), ".worktrust"), dir = join(parent, "measurements");
|
|
726
|
+
for (const path of [parent, dir]) { mkdirSync(path, { recursive: true, mode: 0o700 }); const st = lstatSync(path); if (!st.isDirectory() || st.isSymbolicLink()) throw Error("WorkTrust metadata directory is not a private directory"); }
|
|
727
|
+
const file = join(dir, createHash("sha256").update(body).digest("hex") + ".json");
|
|
728
|
+
if (existsSync(file)) { const st = lstatSync(file); if (!st.isFile() || st.isSymbolicLink() || readFileSync(file, "utf8") !== body) throw Error("WorkTrust retained metadata did not match its digest"); return; }
|
|
729
|
+
const temporary = join(dir, ".pending-" + randomBytes(18).toString("hex"));
|
|
730
|
+
const fd = openSync(temporary, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | (constants.O_NOFOLLOW ?? 0), 0o600);
|
|
731
|
+
try {
|
|
732
|
+
writeFileSync(fd, body); fsyncSync(fd);
|
|
733
|
+
try { linkSync(temporary, file); } catch (error) {
|
|
734
|
+
if (error.code !== "EEXIST" || lstatSync(file).isSymbolicLink() || readFileSync(file, "utf8") !== body) throw error;
|
|
735
|
+
}
|
|
736
|
+
} finally { closeSync(fd); unlinkSync(temporary); }
|
|
737
|
+
}
|
|
701
738
|
async function sendHistory(door, entries, announce = false, rebuild = false, named = false, { byDay = false, withdrawUnknown = false } = {}) {
|
|
702
739
|
let accepted = 0;
|
|
703
740
|
// A Codex entry goes through Codex's own coupling where one exists (see codexDoor), the rest
|
|
@@ -714,11 +751,13 @@ async function sendHistory(door, entries, announce = false, rebuild = false, nam
|
|
|
714
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.
|
|
715
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.
|
|
716
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; }) } } });
|
|
754
|
+
for (const entry of batch) retainMeasurement(entry, source);
|
|
717
755
|
// `named` (0.10.10): a copied folder's lines name their client too, so the record says which app the copy came from.
|
|
718
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 });
|
|
719
757
|
const text = await response.text();
|
|
720
758
|
if (announce) console.log(`batch ${number}: ${response.status} ${text.slice(0, 200).replace(/\\n/g, " ")}`);
|
|
721
759
|
if (!response.ok) break;
|
|
760
|
+
try { confirmedReceipt(text, batch.length); } catch { break; }
|
|
722
761
|
accepted += batch.length;
|
|
723
762
|
noteReceipt(text);
|
|
724
763
|
}
|
|
@@ -756,10 +795,13 @@ const proofFor = (url, body) => {
|
|
|
756
795
|
const clientOf = (source, always = false) => (always || source === "antigravity" || DATABASE_CLIENTS.includes(source) || EXPORT_CLIENTS.includes(source) ? { "user-agent": `${source ?? "claude"}/hook (worktrust-hook)` } : {});
|
|
757
796
|
|
|
758
797
|
async function send(door, payload) {
|
|
798
|
+
retainMeasurement(payload, entrySource.get(payload));
|
|
759
799
|
const body = JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "log_work", arguments: payload } });
|
|
760
800
|
const response = await fetch(door.url, { method: "POST", headers: { "content-type": "application/json", accept: "application/json, text/event-stream", authorization: `Bearer ${door.token}`, ...clientOf(entrySource.get(payload)), ...proofFor(door.url, body) }, body });
|
|
761
801
|
if (!response.ok) throw new Error(`door said ${response.status}`);
|
|
762
|
-
|
|
802
|
+
const text = await response.text();
|
|
803
|
+
confirmedReceipt(text);
|
|
804
|
+
return text;
|
|
763
805
|
}
|
|
764
806
|
|
|
765
807
|
/**
|
|
@@ -1181,7 +1223,7 @@ if (flag("history") && flag("from-archive")) {
|
|
|
1181
1223
|
return entry;
|
|
1182
1224
|
});
|
|
1183
1225
|
const signedCount = all.filter(({ signed }) => signed).length;
|
|
1184
|
-
say(`${all.length} stretches in the archive · ${signedCount} signed by this computer's key (
|
|
1226
|
+
say(`${all.length} stretches in the archive · ${signedCount} signed by this computer's key (signature checked) · ${all.length - signedCount} unsigned or signed by another key (reconstructed) · ${entries.length} of them no longer in any AI app here`);
|
|
1185
1227
|
if (DRY || entries.length === 0) { if (entries[0]) say(`\nthe oldest of them, in full:\n${JSON.stringify(entries[0], null, 1)}`); say(entries.length === 0 ? "Nothing to send." : "\ndry run — nothing sent."); return await exitFlushed(0); }
|
|
1186
1228
|
if (!(await doorKnowsArchive(door))) { say("WorkTrust does not accept history from an archive yet (the door does not know the mark). Nothing was sent."); return await exitFlushed(1); }
|
|
1187
1229
|
return await exitFlushed((await sendHistory(door, entries, true)) === entries.length ? 0 : 1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "worktrust",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.21",
|
|
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
|
@@ -78,7 +78,7 @@ 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.
|
|
81
|
+
const CLI_VERSION = "0.10.21";
|
|
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");
|
|
@@ -683,6 +683,8 @@ async function offerHistory(paths, token, devicePem, url = MCP, rebuild = false)
|
|
|
683
683
|
if (rebuild) {
|
|
684
684
|
for (const row of found.clients ?? []) say(` ${row.client.padEnd(12)} ${String(row.days).padStart(4)} days ${row.first} … ${row.last}`);
|
|
685
685
|
say(" Re-measured with the current rules (what the seconds were, your own turns, tokens with the cache, every AI app above).");
|
|
686
|
+
say(" Changed measured history is held for review; earlier measurements remain in your record.");
|
|
687
|
+
say(" For older unmeasured history only:");
|
|
686
688
|
say(" WorkTrust REPLACES this computer's earlier lines for those days and apps: each earlier line is withdrawn and kept,");
|
|
687
689
|
say(" never deleted, so a day is counted once. Other computers, web sources and days not listed are not touched.");
|
|
688
690
|
}
|