worktrust 0.10.30 → 0.10.32
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 +55 -6
- package/SECURITY.md +13 -0
- package/engine-release.json +1 -1
- package/log-session.mjs +428 -55
- package/package-release.json +1 -1
- package/package.json +1 -1
- package/stretch-evidence.mjs +1 -1
- package/transcript-readers.mjs +125 -5
- package/worktrust.mjs +73 -24
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":"34923747bec318637e6c93c543eb49b2a37cf2f67789b971ae3f7527975c860d","SECURITY.md":"b672649c7c7bf18538dd4560d7b533498721e0be765a000796d7d18390b5cbb6","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":"9466dc34e51c5c7443c68c9074cd21fb9be9d86e2633005d5033feb5d865c2cb","history-outbox.mjs":"b84e22542bb2d8195a469ee5f4116356ae9eac4a53ff2d40f0268b5b1de99dc5","log-session.mjs":"35d01fb00a472c022560a880c0863b57f24cb8311040bba21c3f0cf903b9074c","orchestration-contract.mjs":"ec08f303a166365b99e70b675de4cfe76c6156c2567e14b5569f6d992f0231b7","orchestration-evidence.mjs":"d0d06cecf0eb08e5c6e653c62a4f45b1eddf2119c2acb8341056b34f488d214a","orchestration-report.mjs":"d4e0a9ad8e4a01b462d22c6b1866aac291565c533ff476085d3367cb6d59bc1b","package-integrity.mjs":"a8210c9494a56bfb9a5ea3d10064c7a269f0b6330c0af7c0700e706c3c0224e3","package.json":"50adbece5072911c0a1421f92669fe7196013427a6fd08eb81456c7b56b5e5dc","preserve-lines.mjs":"2df64a69687aa51219bf7b86b88d175cc50990fa29574b31897e41a9ebeecf43","preserve-summary.mjs":"137f781ed7021596a3f0ea67afcf2ab8616ac293f833dbb8f176e838e0ed8321","preserve.mjs":"3e369083ba43bcda2fa0622fd526aa64fcf8ad66e7b6e8f23821752c4d47ad27","runtime-install.mjs":"aab47b52c79d726ef428a24f982c648fa3f1c2dc2b574f633611d02924864e5f","session-databases.mjs":"543fd3b82d28d96d789be0a1dc9186c5fafa783e98b87e5b3b17b211542e2b4d","setup-mcp.mjs":"0c29113179561af1c1e9ff8b7a786e7240edf48a2244993e12335e5ee362c812","stack-rules.mjs":"b23c56e72ec56ba02b17ed895f869172d988c468a697e8d6026b0e268f61e489","stretch-evidence.mjs":"5f5667b92adf11b1a5a6330a0f26dd6db73d56fe60823d9a5246dab71d27d380","transcript-readers.mjs":"ed6fef364aa28f39361d8f627abcda2162498cbaa13e90cc5860a768cb355fa2","worktrust-launch.mjs":"84801bd29d472d48188c126b9ebe3989a3132b54e13cc4fe534ff7c383a294ee","worktrust.mjs":"0e481fde109620dd23f750d7b9b0741c0ea831c45961a176164ef2a74f3dd7c0"},"format":"worktrust-package/1","kind":"npm","version":"0.10.32"},"signature":"r4b807x7NWQzjC04Eu7Rto-dydbPoaNq_pd2MczLVIJC2Z_5fuaf8PQtxPLbrQbCqw1q19b_X_mWBl_giwvtBw"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "worktrust",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.32",
|
|
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/stretch-evidence.mjs
CHANGED
|
@@ -207,7 +207,7 @@ function delegationOf(messages, { isHumanTurn, INTERRUPTED, textOf }) {
|
|
|
207
207
|
* next: the same input again (a blind retry) or a different one (a changed strategy). Inputs are compared by digest on
|
|
208
208
|
* this computer and never kept. Null when nothing failed.
|
|
209
209
|
*/
|
|
210
|
-
function recoveryOf(messages) {
|
|
210
|
+
export function recoveryOf(messages) {
|
|
211
211
|
const calls = [];
|
|
212
212
|
const byId = new Map();
|
|
213
213
|
for (const message of messages) {
|
package/transcript-readers.mjs
CHANGED
|
@@ -13,9 +13,12 @@
|
|
|
13
13
|
* counter's named rules and the hook's measure(), whose payloads are fixed allowlists of numbers,
|
|
14
14
|
* dates and enum values (log-session.mjs, "WHAT CANNOT LEAVE").
|
|
15
15
|
*/
|
|
16
|
-
import { closeSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
16
|
+
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
17
|
+
import { createHash } from "node:crypto";
|
|
18
|
+
import { spawnSync } from "node:child_process";
|
|
17
19
|
import { homedir } from "node:os";
|
|
18
20
|
import { join } from "node:path";
|
|
21
|
+
import { StringDecoder } from "node:string_decoder";
|
|
19
22
|
import { fileURLToPath } from "node:url";
|
|
20
23
|
|
|
21
24
|
// ── codex rollout reader ──
|
|
@@ -75,9 +78,12 @@ const ORIGIN_OF = { human: "human", scheduled: "scheduled", task_notification: "
|
|
|
75
78
|
const entrypointKind = (value) => (typeof value !== "string" ? null : /^sdk(-|$)/.test(value) ? "headless" : value === "cli" || /^claude-/.test(value) ? "interactive" : "unknown");
|
|
76
79
|
const SESSION_WORDS = new Set(["interactive", "headless", "scheduled", "unknown"]);
|
|
77
80
|
const onlyToolResults = (content) => Array.isArray(content) && content.length > 0 && content.every((part) => part?.type === "tool_result");
|
|
78
|
-
export function sessionKindReader() {
|
|
79
|
-
|
|
81
|
+
export function sessionKindReader(saved = null) {
|
|
82
|
+
// A READ POSITION RESUMES IT (0.10.32): `state()` is what it has read so far, as JSON, and `sessionKindReader(state)` goes on
|
|
83
|
+
// from there, so a transcript read from an offset decides the kind its whole file decides.
|
|
84
|
+
let entry = typeof saved?.entry === "string" ? saved.entry : null, human = saved?.human === true, first = saved && "first" in saved ? saved.first : undefined;
|
|
80
85
|
return {
|
|
86
|
+
state: () => ({ entry, human, ...(first === undefined ? {} : { first }) }),
|
|
81
87
|
note(line) {
|
|
82
88
|
if (!line || typeof line !== "object") return;
|
|
83
89
|
// What the client said on the line: a reader's word (Codex), else Claude Code's entrypoint. Interactive wins over headless,
|
|
@@ -100,6 +106,95 @@ export function sessionKindReader() {
|
|
|
100
106
|
}
|
|
101
107
|
/** One session's kind from its lines, in file order (the hook and the tests read it the same way). */
|
|
102
108
|
export const sessionKindOf = (lines) => { const reader = sessionKindReader(); for (const line of lines ?? []) reader.note(line); return reader.kind(); };
|
|
109
|
+
/**
|
|
110
|
+
* WHO WROTE THIS TURN (0.10.32): true when the app marked it the person's (`turnOrigin` / `origin.kind` human, or the line's own
|
|
111
|
+
* entrypoint interactive: a `claude --resume` by hand); false when it marked a program or a timer (an `sdk-*` entrypoint, a
|
|
112
|
+
* `scheduled` or program origin); null when it said neither. In a run no person started, only a true turn is a human input.
|
|
113
|
+
*/
|
|
114
|
+
export const turnByPerson = (line) => {
|
|
115
|
+
const origin = ORIGIN_OF[typeof line?.turnOrigin === "string" ? line.turnOrigin : typeof line?.origin?.kind === "string" ? line.origin.kind : ""] ?? null;
|
|
116
|
+
if (origin) return origin === "human";
|
|
117
|
+
const kind = entrypointKind(line?.entrypoint);
|
|
118
|
+
return kind === "interactive" ? true : kind === "headless" ? false : null;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* THE TIMER THAT RUNS THIS PROCESS (owner, 2026-10-28; docs/AGENTIC-OPERATIONS.md "2b"; 0.10.32): a run's schedule is read from the
|
|
123
|
+
* timer's own definition, never guessed from when runs happened.
|
|
124
|
+
* launchd the job's label (XPC_SERVICE_NAME, which launchd sets for the job and its children) names a plist in a LaunchAgents
|
|
125
|
+
* or LaunchDaemons folder; its StartInterval (a day, a week) or one StartCalendarInterval entry says the cadence;
|
|
126
|
+
* cron an ancestor process is cron; the command its child runs is exactly one line of the user's crontab; that line's
|
|
127
|
+
* fields say the cadence (`@daily`, `@weekly`, `@monthly`, or minute and hour fixed with one of day-of-month or
|
|
128
|
+
* day-of-week fixed).
|
|
129
|
+
* Anything else (an hourly or irregular timer, several entries, no definition found, two crontab lines alike): null. The ref is a
|
|
130
|
+
* hash of the timer's identity and its cadence (the label, or the cron fields), never of its command: updating what a timer runs
|
|
131
|
+
* keeps its schedule; a new cadence is a new schedule. Nothing of the definition leaves this computer.
|
|
132
|
+
*/
|
|
133
|
+
export const SCHEDULE_CADENCES = ["daily", "weekly", "monthly"];
|
|
134
|
+
const scheduleRef = (source, identity, cadence) => createHash("sha256").update(`worktrust-schedule|${source}|${identity}|${cadence}`).digest("base64url");
|
|
135
|
+
const whole = (value) => Number.isInteger(value) && value >= 0;
|
|
136
|
+
/** A launchd job definition (the plist as JSON) → its cadence, or null. */
|
|
137
|
+
export function launchdCadence(plist) {
|
|
138
|
+
if (!plist || typeof plist !== "object") return null;
|
|
139
|
+
if (plist.StartInterval === 86400) return "daily";
|
|
140
|
+
if (plist.StartInterval === 604800) return "weekly";
|
|
141
|
+
if (plist.StartInterval !== undefined) return null;
|
|
142
|
+
const entries = Array.isArray(plist.StartCalendarInterval) ? plist.StartCalendarInterval : plist.StartCalendarInterval ? [plist.StartCalendarInterval] : [];
|
|
143
|
+
if (entries.length !== 1 || typeof entries[0] !== "object") return null;
|
|
144
|
+
const { Minute, Hour, Day, Weekday, Month } = entries[0];
|
|
145
|
+
if (Month !== undefined || !whole(Minute) || !whole(Hour)) return null;
|
|
146
|
+
if (whole(Day) && Weekday === undefined) return "monthly";
|
|
147
|
+
if (whole(Weekday) && Day === undefined) return "weekly";
|
|
148
|
+
if (Day === undefined && Weekday === undefined) return "daily";
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
/** A crontab line's schedule fields (the five, or one @word) → its cadence, or null. */
|
|
152
|
+
export function cronCadence(fields) {
|
|
153
|
+
const word = { "@daily": "daily", "@midnight": "daily", "@weekly": "weekly", "@monthly": "monthly" };
|
|
154
|
+
if (fields.length === 1) return word[fields[0]] ?? null;
|
|
155
|
+
if (fields.length !== 5) return null;
|
|
156
|
+
const [minute, hour, dom, month, dow] = fields, one = (field) => /^[0-9]{1,2}$/.test(field);
|
|
157
|
+
if (!one(minute) || !one(hour) || month !== "*") return null;
|
|
158
|
+
if (dom === "*" && dow === "*") return "daily";
|
|
159
|
+
if (dom === "*" && one(dow)) return "weekly";
|
|
160
|
+
if (one(dom) && dow === "*") return "monthly";
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
/** The crontab's lines whose command is `command` → their schedule fields (an @word line has one). */
|
|
164
|
+
export const crontabFields = (crontab, command) => String(crontab ?? "").split("\n").map((line) => line.trim()).filter((line) => line && !line.startsWith("#") && !/^[A-Za-z_][A-Za-z0-9_]*=/.test(line))
|
|
165
|
+
.map((line) => (line.startsWith("@") ? [line.split(/\s+/, 1), line.replace(/^@\S+\s+/, "")] : [line.split(/\s+/).slice(0, 5), line.split(/\s+/).slice(5).join(" ")]))
|
|
166
|
+
.filter(([, cmd]) => cmd === command).map(([fields]) => fields);
|
|
167
|
+
export function timerSchedule({ env = process.env, home = homedir(), run = spawnSync, pid = process.pid } = {}) {
|
|
168
|
+
try {
|
|
169
|
+
const label = typeof env.XPC_SERVICE_NAME === "string" && /^[A-Za-z0-9._-]{1,200}$/.test(env.XPC_SERVICE_NAME) && !/^(0|application\.)/.test(env.XPC_SERVICE_NAME) ? env.XPC_SERVICE_NAME : null;
|
|
170
|
+
if (label) {
|
|
171
|
+
const file = [join(home, "Library/LaunchAgents"), "/Library/LaunchAgents", "/Library/LaunchDaemons"].map((dir) => join(dir, `${label}.plist`)).find((path) => existsSync(path));
|
|
172
|
+
if (!file) return null;
|
|
173
|
+
const read = run("plutil", ["-convert", "json", "-o", "-", file], { encoding: "utf8", timeout: 2000 });
|
|
174
|
+
const cadence = read.status === 0 ? launchdCadence(JSON.parse(read.stdout)) : null;
|
|
175
|
+
return cadence ? { cadence, ref: scheduleRef("launchd", label, cadence) } : null;
|
|
176
|
+
}
|
|
177
|
+
// cron: walk up the process tree (one `ps`), at most twelve steps, for cron and the command it started
|
|
178
|
+
const table = run("ps", ["-A", "-o", "pid=,ppid=,comm="], { encoding: "utf8", timeout: 2000 });
|
|
179
|
+
if (table.status !== 0) return null;
|
|
180
|
+
const parent = new Map(), name = new Map();
|
|
181
|
+
for (const row of table.stdout.split("\n")) { const m = /^\s*(\d+)\s+(\d+)\s+(.+?)\s*$/.exec(row); if (m) { parent.set(Number(m[1]), Number(m[2])); name.set(Number(m[1]), m[3]); } }
|
|
182
|
+
let child = pid, at = parent.get(pid);
|
|
183
|
+
for (let step = 0; step < 12 && at && at > 1; step += 1) {
|
|
184
|
+
if (/(^|\/)(cron|crond)$/.test(name.get(at) ?? "")) {
|
|
185
|
+
const args = run("ps", ["-o", "args=", "-p", String(child)], { encoding: "utf8", timeout: 2000 });
|
|
186
|
+
const command = args.status === 0 ? /^\S*sh -c (.+)$/.exec(args.stdout.trim())?.[1] ?? null : null;
|
|
187
|
+
if (!command) return null;
|
|
188
|
+
const tab = run("crontab", ["-l"], { encoding: "utf8", timeout: 2000 });
|
|
189
|
+
const lines = tab.status === 0 ? crontabFields(tab.stdout, command) : [];
|
|
190
|
+
const cadence = lines.length === 1 ? cronCadence(lines[0]) : null;
|
|
191
|
+
return cadence ? { cadence, ref: scheduleRef("cron", lines[0].join(" "), cadence) } : null;
|
|
192
|
+
}
|
|
193
|
+
child = at; at = parent.get(at);
|
|
194
|
+
}
|
|
195
|
+
return null;
|
|
196
|
+
} catch { return null; }
|
|
197
|
+
}
|
|
103
198
|
export function* codexLines(records) {
|
|
104
199
|
let cwd = null, model = null, mode = null, sessionKind = null;
|
|
105
200
|
const seenResponses = new Set();
|
|
@@ -156,12 +251,37 @@ export function* codexLines(records) {
|
|
|
156
251
|
* does not say who started them, and a guess is noise. Null when the day shows none of it.
|
|
157
252
|
*/
|
|
158
253
|
const EFFORT_LEVELS = new Set(["low", "medium", "high", "xhigh", "max"]);
|
|
254
|
+
/**
|
|
255
|
+
* A FILE'S LINES, 8 MB AT A TIME (0.10.32): a whole-file read throws past Node's longest string (about 512 MB), which is
|
|
256
|
+
* how the owner's Claude Code session went unmeasured from 2026-10-18; a rollout is read the same way as a transcript.
|
|
257
|
+
* Null when the file cannot be opened; a read that fails halfway ends the lines there.
|
|
258
|
+
*/
|
|
259
|
+
export function streamedLines(file) {
|
|
260
|
+
try { closeSync(openSync(file, "r")); } catch { return null; }
|
|
261
|
+
return { *[Symbol.iterator]() {
|
|
262
|
+
let fd; try { fd = openSync(file, "r"); } catch { return; }
|
|
263
|
+
try {
|
|
264
|
+
const decoder = new StringDecoder("utf8"), buffer = Buffer.allocUnsafe(8 << 20);
|
|
265
|
+
let rest = "";
|
|
266
|
+
for (;;) {
|
|
267
|
+
let n; try { n = readSync(fd, buffer, 0, buffer.length, null); } catch { return; }
|
|
268
|
+
if (n <= 0) break;
|
|
269
|
+
const parts = (rest + decoder.write(buffer.subarray(0, n))).split("\n");
|
|
270
|
+
rest = parts.pop();
|
|
271
|
+
yield* parts;
|
|
272
|
+
}
|
|
273
|
+
rest += decoder.end();
|
|
274
|
+
if (rest) yield rest;
|
|
275
|
+
} finally { closeSync(fd); }
|
|
276
|
+
} };
|
|
277
|
+
}
|
|
159
278
|
export function codexLive(file, day) {
|
|
160
279
|
if (!CODEX_ROLLOUT.test(String(file)) || !/^\d{4}-\d{2}-\d{2}$/.test(String(day))) return null;
|
|
161
|
-
|
|
280
|
+
const lines = streamedLines(file);
|
|
281
|
+
if (!lines) return null;
|
|
162
282
|
const out = {}, models = new Set();
|
|
163
283
|
const peak = (key, value) => { if (Number.isFinite(value)) { const v = Math.max(0, Math.min(100, Math.round(value))); if (v > 0 && (out[key] ?? 0) < v) out[key] = v; } };
|
|
164
|
-
for (const raw of
|
|
284
|
+
for (const raw of lines) {
|
|
165
285
|
if (!raw.includes(day)) continue;
|
|
166
286
|
let record; try { record = JSON.parse(raw); } catch { continue; }
|
|
167
287
|
if (String(record?.timestamp ?? "").slice(0, 10) !== day) continue;
|
package/worktrust.mjs
CHANGED
|
@@ -76,7 +76,21 @@ const command = args.includes("--help") ? "help" : args.includes("--version") ?
|
|
|
76
76
|
const flag = (name) => { const at = args.indexOf(`--${name}`); return at >= 0 ? args[at + 1] : undefined; };
|
|
77
77
|
const has = (name) => args.includes(`--${name}`);
|
|
78
78
|
/** 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). */
|
|
79
|
-
const CLI_VERSION = "0.10.
|
|
79
|
+
const CLI_VERSION = "0.10.32";
|
|
80
|
+
/**
|
|
81
|
+
* HOW THIS CLI MEASURES, AS A NUMBER OF ITS OWN (0.10.31; owner, 2026-10-28: 0.10.30 offered a re-measure it had no reason
|
|
82
|
+
* to offer). Raised ONLY when what is measured changes: the timeline, the seconds, the tokens, the steering, the session
|
|
83
|
+
* kinds, the readers. A release that changes consent, coupling or words keeps it. `update` offers the re-measure only when
|
|
84
|
+
* the earlier install measured by other rules, and names what changed from MEASURE_CHANGES; installed-release.json and
|
|
85
|
+
* history.json record it. 1 is the rules of 0.10.29, which 0.10.30 and 0.10.31 kept; 2 (0.10.32) adds the subagent runs, each
|
|
86
|
+
* agent call's outcome and who wrote each turn of a run no person started.
|
|
87
|
+
*/
|
|
88
|
+
const MEASURE_RULES = 2;
|
|
89
|
+
/** What each measure-rules version changed, in the words the re-measure offer says (one entry per raise, never rewritten). */
|
|
90
|
+
const MEASURE_CHANGES = {
|
|
91
|
+
1: ["each answer's tokens counted once", "nothing lost at midnight", "when each stretch began", "how you steered the agent", "what the seconds were", "more AI apps", "how each session was started"],
|
|
92
|
+
2: ["which subagents were active at once, and how their failed steps were recovered", "whether each agent call completed", "who wrote each turn of a run no person started"],
|
|
93
|
+
};
|
|
80
94
|
const ORIGIN = (flag("origin") ?? process.env.WORKTRUST_ORIGIN ?? "https://app.worktrust.io").replace(/\/$/, "");
|
|
81
95
|
const MCP = flag("url") ?? process.env.WORKTRUST_MCP_URL ?? `${ORIGIN}/api/mcp`;
|
|
82
96
|
const HOME_DIR = join(homedir(), ".worktrust");
|
|
@@ -140,7 +154,7 @@ function historyQueueScope(token) {
|
|
|
140
154
|
/** Run a script; its output is shown, or collected for the plan. The key travels in the environment only. */
|
|
141
155
|
function run(path, scriptArgs, token, collect = false, extraEnv = {}) {
|
|
142
156
|
return new Promise((resolve) => {
|
|
143
|
-
const child = spawn(moduleExecutable(HERE), [...moduleArgs(HERE, basename(path), scriptArgs)], { stdio: collect ? ["ignore", "pipe", "pipe"] : "inherit", env: { ...process.env, WORKTRUST_MCP_URL: MCP, WORKTRUST_MCP_TOKEN: token, WORKTRUST_NODE: NODE, WORKTRUST_NODE_ARGS: JSON.stringify(NODE_ARGS), WORKTRUST_CLI_VERSION: CLI_VERSION, WORKTRUST_HISTORY_SCOPE: historyQueueScope(token), ...extraEnv } });
|
|
157
|
+
const child = spawn(moduleExecutable(HERE), [...moduleArgs(HERE, basename(path), scriptArgs)], { stdio: collect ? ["ignore", "pipe", "pipe"] : "inherit", env: { ...process.env, WORKTRUST_MCP_URL: MCP, WORKTRUST_MCP_TOKEN: token, WORKTRUST_NODE: NODE, WORKTRUST_NODE_ARGS: JSON.stringify(NODE_ARGS), WORKTRUST_CLI_VERSION: CLI_VERSION, WORKTRUST_MEASURE_RULES: String(MEASURE_RULES), WORKTRUST_HISTORY_SCOPE: historyQueueScope(token), ...extraEnv } });
|
|
144
158
|
let out = "";
|
|
145
159
|
child.stdout?.on("data", (chunk) => { out += chunk; });
|
|
146
160
|
child.stderr?.on("data", (chunk) => { out += chunk; });
|
|
@@ -297,7 +311,7 @@ async function prepareBundledRuntime() {
|
|
|
297
311
|
}
|
|
298
312
|
function saveStableEntry() {
|
|
299
313
|
const target = join(HOME_DIR, "installed-release.json"), temporary = `${target}.${randomBytes(8).toString("hex")}.tmp`;
|
|
300
|
-
try { writeFileSync(temporary, JSON.stringify({ version: CLI_VERSION }), { flag: "wx", mode: 0o600 }); renameSync(temporary, target); }
|
|
314
|
+
try { writeFileSync(temporary, JSON.stringify({ version: CLI_VERSION, measureRules: MEASURE_RULES }), { flag: "wx", mode: 0o600 }); renameSync(temporary, target); }
|
|
301
315
|
finally { try { rmSync(temporary); } catch { /* already renamed */ } }
|
|
302
316
|
}
|
|
303
317
|
|
|
@@ -568,7 +582,7 @@ async function hook() {
|
|
|
568
582
|
if (has("hermes") || has("goose")) return sessionEnd();
|
|
569
583
|
const key = await freshKey();
|
|
570
584
|
if (!key) return;
|
|
571
|
-
const child = spawn(moduleExecutable(HERE), [...moduleArgs(HERE, "log-session.mjs", args.filter((arg) => arg !== "hook"))], { stdio: "inherit", env: { ...process.env, WORKTRUST_MCP_URL: key.url, WORKTRUST_MCP_TOKEN: key.token, WORKTRUST_CLI_VERSION: CLI_VERSION, WORKTRUST_HISTORY_SCOPE: historyQueueScope(key.token), ...(key.device ? { WORKTRUST_DEVICE_KEY: key.device } : {}) } }); // 0.10.20: the hook names the version that started it, beside each line
|
|
585
|
+
const child = spawn(moduleExecutable(HERE), [...moduleArgs(HERE, "log-session.mjs", args.filter((arg) => arg !== "hook"))], { stdio: "inherit", env: { ...process.env, WORKTRUST_MCP_URL: key.url, WORKTRUST_MCP_TOKEN: key.token, WORKTRUST_CLI_VERSION: CLI_VERSION, WORKTRUST_MEASURE_RULES: String(MEASURE_RULES), WORKTRUST_HISTORY_SCOPE: historyQueueScope(key.token), ...(key.device ? { WORKTRUST_DEVICE_KEY: key.device } : {}) } }); // 0.10.20: the hook names the version that started it, beside each line
|
|
572
586
|
process.exitCode = await new Promise((resolve, reject) => { child.on("error", reject); child.on("close", (code) => resolve(code ?? 1)); });
|
|
573
587
|
}
|
|
574
588
|
|
|
@@ -635,7 +649,7 @@ async function update() {
|
|
|
635
649
|
if (found.length === 0) say(" (no AI app found here)");
|
|
636
650
|
const hookFresh = !agreed.has("session-hook");
|
|
637
651
|
say(` The session hook and ${STABLE} are brought to ${CLI_VERSION}.`);
|
|
638
|
-
say(hookFresh ? ` + Session hook: ${join(homedir(), ".claude", "settings.json")} → SessionStart, SessionEnd and
|
|
652
|
+
say(hookFresh ? ` + Session hook: ${join(homedir(), ".claude", "settings.json")} → SessionStart, SessionEnd, PreCompact and (at most once an hour) Stop run it · new` : ` ✓ Session hook: refreshed (${agreed.said("session-hook")}; since 0.10.32 it also runs after an answer, at most once an hour, so a long session's finished days arrive the same day)`);
|
|
639
653
|
say(" The key stays as it is: no new pairing, the same computer in WorkTrust.");
|
|
640
654
|
say();
|
|
641
655
|
if (has("dry-run")) { say(" Dry run: nothing was written and nothing was sent."); return; }
|
|
@@ -645,7 +659,7 @@ async function update() {
|
|
|
645
659
|
else if (newOnes.length > 0) takeNew = await ask(`Couple the new ${newOnes.length === 1 ? "one" : "ones"} marked "new" (${newOnes.join(", ")})?`, false);
|
|
646
660
|
if (newOnes.length > 0 && !takeNew && !has("yes")) say(" The new ones stay as they are. npx worktrust update asks again.");
|
|
647
661
|
const skip = takeNew ? [] : fresh, hookOn = !hookFresh || takeNew;
|
|
648
|
-
const
|
|
662
|
+
const previous = stableInstall();
|
|
649
663
|
await prepareBundledRuntime();
|
|
650
664
|
ensureHome();
|
|
651
665
|
saveStableEntry();
|
|
@@ -663,7 +677,7 @@ async function update() {
|
|
|
663
677
|
await offerAntigravity();
|
|
664
678
|
const reported = await accepted(key.url, key.token, key.device);
|
|
665
679
|
say(reported === true ? ` ✓ WorkTrust received CLI version ${CLI_VERSION}.` : " ! Installed locally. WorkTrust could not confirm the version yet; it will be reported on the next connection.");
|
|
666
|
-
await offerRebuild(
|
|
680
|
+
await offerRebuild(previous, paths, key);
|
|
667
681
|
say();
|
|
668
682
|
say(" Done. Quit your AI apps completely and open them again to use the updated CLI.");
|
|
669
683
|
}
|
|
@@ -697,7 +711,7 @@ async function connect() {
|
|
|
697
711
|
if (!direct) say(` 3. The key is kept in ${KEY_PLACE}, works only on this computer (every call is signed) and is renewed every week.`);
|
|
698
712
|
say(` ${direct ? 3 : 4}. The session hook is installed:`);
|
|
699
713
|
say(" + The hook and counter from the checked release, retained outside the package-manager cache");
|
|
700
|
-
say(` + ${join(homedir(), ".claude", "settings.json")} → SessionStart, SessionEnd and
|
|
714
|
+
say(` + ${join(homedir(), ".claude", "settings.json")} → SessionStart, SessionEnd, PreCompact and (at most once an hour) Stop run it`);
|
|
701
715
|
say();
|
|
702
716
|
say(" Sent to WorkTrust afterwards: durations, token counts, model names, a layer keyword, counts,");
|
|
703
717
|
say(" and, to match the work to GitHub, the repository's owner/name and the commit hashes.");
|
|
@@ -793,13 +807,24 @@ async function offerHistory(paths, token, devicePem, url = MCP, rebuild = false,
|
|
|
793
807
|
: 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` : ""}.`
|
|
794
808
|
: 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.`
|
|
795
809
|
: `${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.`;
|
|
810
|
+
// ONLY THE DAYS THAT CHANGED (0.10.32): the hook asked WorkTrust which of this computer's days it holds as this CLI measures
|
|
811
|
+
// them and sent the others; every day it compared unchanged is nothing sent, said once. Not asked (an older WorkTrust) says nothing.
|
|
812
|
+
const compared = Number.isInteger(did?.days?.compared) ? did.days.compared : null, changed = Number.isInteger(did?.days?.changed) ? did.days.changed : null;
|
|
813
|
+
if (rebuild && sent.code === 0 && compared !== null && compared > 0 && changed === 0 && n(did.of) === 0) { say(` Nothing changed: WorkTrust holds all ${compared} days as this computer measures them. Nothing was sent.`); return; }
|
|
814
|
+
if (rebuild && compared !== null && changed !== null && compared > changed) say(` ${compared - changed} of ${compared} days unchanged on WorkTrust; sending the ${changed} that changed.`);
|
|
815
|
+
if (n(did?.unreadable) > 0) say(` ${n(did.unreadable)} transcript${n(did.unreadable) === 1 ? "" : "s"} could not be read; ${n(did.unreadable) === 1 ? "its" : "their"} days were not measured. WorkTrust was told the count, nothing else.`);
|
|
796
816
|
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.`);
|
|
797
817
|
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.`);
|
|
798
818
|
// 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.
|
|
799
819
|
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.");
|
|
800
820
|
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.`);
|
|
801
821
|
// 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.
|
|
802
|
-
if (rebuild && n(did?.staged) > 0 && !Number(did?.delivery?.review) && !Number(did?.delivery?.waiting))
|
|
822
|
+
if (rebuild && n(did?.staged) > 0 && !Number(did?.delivery?.review) && !Number(did?.delivery?.waiting)) {
|
|
823
|
+
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.`);
|
|
824
|
+
// WHERE IT WAITS (0.10.32): the receipt of the run's last batch names its place in WorkTrust's queue and a time; absent, nothing is guessed.
|
|
825
|
+
const queued = did?.queued;
|
|
826
|
+
if (queued && Number.isInteger(queued.position) && queued.position >= 1 && Number.isFinite(Number(queued.eta_minutes))) say(` queued, position ${queued.position}, about ${Math.max(1, Math.ceil(Number(queued.eta_minutes)))} min`);
|
|
827
|
+
}
|
|
803
828
|
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.");
|
|
804
829
|
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.");
|
|
805
830
|
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)` : ""}.`);
|
|
@@ -809,19 +834,39 @@ async function offerHistory(paths, token, devicePem, url = MCP, rebuild = false,
|
|
|
809
834
|
const stableVersion = () => { try { const installed = JSON.parse(readFileSync(join(HOME_DIR, "installed-release.json"), "utf8")); if (/^\d+\.\d+\.\d+$/.test(installed.version)) return installed.version; } catch { /* older registration */ } try { return /const CLI_VERSION = "([^"]+)";/.exec(readFileSync(STABLE_FILE, "utf8"))?.[1] ?? null; } catch { return null; } };
|
|
810
835
|
|
|
811
836
|
/**
|
|
812
|
-
*
|
|
813
|
-
*
|
|
814
|
-
*
|
|
815
|
-
|
|
837
|
+
* THE RULES AN EARLIER CLI MEASURED BY (0.10.31). Recorded since 0.10.31 (installed-release.json, history.json, or the
|
|
838
|
+
* stable copy's own MEASURE_RULES); before that, read from its version: 0.10.29 and 0.10.30 measured by rules 1, anything
|
|
839
|
+
* older by earlier rules (0). Null when the version is unknown too.
|
|
840
|
+
*/
|
|
841
|
+
const rulesOf = (record) => (Number.isInteger(record?.measureRules) && record.measureRules >= 0 ? record.measureRules
|
|
842
|
+
: typeof record?.version === "string" && /^\d+\.\d+\.\d+$/.test(record.version) ? (record.version.split(".").map(Number).reduce((order, part, at) => order || Math.sign(part - [0, 10, 29][at]), 0) < 0 ? 0 : 1) : null);
|
|
843
|
+
/** The stable copy's version and measure rules, what this computer ran before an update; both null without one. */
|
|
844
|
+
function stableInstall() {
|
|
845
|
+
const version = stableVersion();
|
|
846
|
+
if (!version) return { version: null, rules: null };
|
|
847
|
+
try { const installed = JSON.parse(readFileSync(join(HOME_DIR, "installed-release.json"), "utf8")); if (installed.version === version && rulesOf(installed) !== null) return { version, rules: rulesOf(installed) }; } catch { /* older registration */ }
|
|
848
|
+
try { const own = /const MEASURE_RULES = (\d+);/.exec(readFileSync(STABLE_FILE, "utf8"))?.[1]; if (own) return { version, rules: Number(own) }; } catch { /* no stable copy */ }
|
|
849
|
+
return { version, rules: rulesOf({ version }) };
|
|
850
|
+
}
|
|
851
|
+
/** What changed between two measure-rules versions, in MEASURE_CHANGES' words, oldest first. */
|
|
852
|
+
const measureChanges = (from, to) => Object.keys(MEASURE_CHANGES).map(Number).filter((rules) => rules > Math.min(from, to) && rules <= Math.max(from, to)).sort((x, y) => x - y).flatMap((rules) => MEASURE_CHANGES[rules]);
|
|
853
|
+
|
|
854
|
+
/**
|
|
855
|
+
* OFFERED ONCE, BY `update`, IN PLAIN WORDS (owner, 2026-10-07): when the computer's earlier lines were measured by OTHER
|
|
856
|
+
* RULES than this CLI's (0.10.31: the measure-rules version, not the CLI version; 0.10.30 offered on every version and
|
|
857
|
+
* invited a re-send of history measured exactly as before). The CLI cannot read the record, so it is an offer, not a
|
|
858
|
+
* finding: the plan is shown and the question asked by the same path as `history --rebuild`; Enter is No. The offer
|
|
859
|
+
* names what changed. The same rules updated again offer nothing.
|
|
816
860
|
*/
|
|
817
|
-
async function offerRebuild(
|
|
818
|
-
if (!
|
|
861
|
+
async function offerRebuild(previous, paths, key) {
|
|
862
|
+
if (!previous?.version || previous.rules === null || previous.rules === MEASURE_RULES) return;
|
|
863
|
+
const changes = measureChanges(previous.rules, MEASURE_RULES);
|
|
819
864
|
say();
|
|
820
|
-
say(` This computer's earlier lines in WorkTrust were measured by worktrust ${
|
|
821
|
-
say(
|
|
822
|
-
|
|
823
|
-
say(" sessions still on this computer and have WorkTrust replace this computer's earlier lines,
|
|
824
|
-
say(" a day twice. Later: npx worktrust");
|
|
865
|
+
say(` This computer's earlier lines in WorkTrust were measured by worktrust ${previous.version}. Version ${CLI_VERSION} measures`);
|
|
866
|
+
say(changes.length > 0 ? " differently:" : " differently.");
|
|
867
|
+
for (const change of changes) say(` · ${change}`);
|
|
868
|
+
say(" You can re-measure the sessions still on this computer and have WorkTrust replace this computer's earlier lines,");
|
|
869
|
+
say(" day by day, never counting a day twice. Later: npx worktrust");
|
|
825
870
|
// ONE QUESTION, AFTER THE PLAN (0.10.30): counting the plan reads this computer only and sends nothing, so it is shown
|
|
826
871
|
// first and the send is asked once, Enter is No; `--rebuild` agrees in advance, --yes alone never does.
|
|
827
872
|
await offerHistory(paths, key.token, key.device ?? null, key.url, true, has("rebuild"));
|
|
@@ -833,11 +878,12 @@ async function offerRebuild(previousVersion, paths, key) {
|
|
|
833
878
|
*/
|
|
834
879
|
const HISTORY_STATE = join(HOME_DIR, "history.json");
|
|
835
880
|
function historyDone(complete) {
|
|
836
|
-
try { ensureHome(); writeFileSync(HISTORY_STATE, JSON.stringify({ version: CLI_VERSION, at: new Date().toISOString(), complete }), { mode: 0o600 }); } catch { /* the next run asks again */ }
|
|
881
|
+
try { ensureHome(); writeFileSync(HISTORY_STATE, JSON.stringify({ version: CLI_VERSION, measureRules: MEASURE_RULES, at: new Date().toISOString(), complete }), { mode: 0o600 }); } catch { /* the next run asks again */ }
|
|
837
882
|
}
|
|
838
|
-
/** Complete AND measured by this
|
|
839
|
-
* measured by
|
|
840
|
-
|
|
883
|
+
/** Complete AND measured by this CLI's rules (0.10.9; the rules, not the version, since 0.10.31): a run stopped after the
|
|
884
|
+
* update, before the history, leaves the history measured by older rules, and the next run must offer it again rather
|
|
885
|
+
* than read "complete" as done. A version that measures as the one before finds its history done. */
|
|
886
|
+
const historyComplete = () => { try { const state = JSON.parse(readFileSync(HISTORY_STATE, "utf8")); return state.complete === true && rulesOf(state) === MEASURE_RULES; } catch { return false; } };
|
|
841
887
|
|
|
842
888
|
/**
|
|
843
889
|
* THE SAME COMMAND AGAIN DOES WHAT IS LEFT (0.10.5). On a computer already coupled, `npx worktrust@latest` brings it onto
|
|
@@ -1214,6 +1260,9 @@ async function status() {
|
|
|
1214
1260
|
say(key ? ` Key: in ${KEY_PLACE}, ${key.device ? "bound to this computer, " : ""}last renewed ${String(key.renewedAt ?? "").slice(0, 10) || "never"}` : " Key: not on this computer (or written into the apps' settings with --direct)");
|
|
1215
1261
|
if (key) say(key.account ? ` Account: ${key.account}${key.coupledAt ? `, coupled ${String(key.coupledAt).slice(0, 10)}` : ""}` : " Account: not recorded (coupled by an older version; `npx worktrust connect` records it)");
|
|
1216
1262
|
say(sessionHookHere() ? " Session hook: installed" : " Session hook: not installed");
|
|
1263
|
+
// A TRANSCRIPT THE HOOK COULD NOT READ (0.10.32): the count of its last run that had any, never which file; WorkTrust has the count too.
|
|
1264
|
+
{ let unread = null; try { unread = JSON.parse(readFileSync(join(HOME_DIR, "sessions.json"), "utf8")).__unreadable ?? null; } catch { /* no state yet */ }
|
|
1265
|
+
if (Number(unread?.count) > 0) say(` Transcripts: ${unread.count} could not be read on ${String(unread.at).slice(0, 10)}; their days are not measured until they can be (WorkTrust was told the count, nothing else)`); }
|
|
1217
1266
|
if (existsSync(join(homedir(), ".codex"))) { const notify = codexNotify().text ?? ""; say(isOurNotify(notify) ? " Codex: wakes the session hook" : " Codex: does not wake the session hook (npx worktrust update asks)"); }
|
|
1218
1267
|
if (existsSync(join(homedir(), ".hermes"))) { let text = ""; try { text = readFileSync(join(homedir(), ".hermes", "config.yaml"), "utf8"); } catch { /* none */ } say(/worktrust(?:-launch)?\.(?:mjs|py)\\?" hook --hermes/.test(text) ? " Hermes Agent: wakes the session hook" : " Hermes Agent: does not wake the session hook (npx worktrust update writes it)"); }
|
|
1219
1268
|
if (antigravityHere()) say(agyHooks()?.worktrust ? " Antigravity: wakes the session hook" : " Antigravity: does not wake the session hook (npx worktrust update asks)");
|