worktrust 0.10.31 → 0.10.33
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 +54 -2
- package/SECURITY.md +13 -0
- package/engine-release.json +1 -1
- package/history-outbox.mjs +123 -0
- package/log-session.mjs +491 -57
- 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 +32 -10
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":"f11eb9e172a9acad48bc0e27f5859cbeaa7c37c1b2989b52dfc49e164cede038","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":"0e83cb929dac8a4c851ea47bbcbdd6d7f8ad1148d1084ef24619cb16e45bfd31","history-outbox.mjs":"b88072a28aa1dd94d9fab880f96b711b5fbed76ca62e5de24d612c08171e5b71","log-session.mjs":"d20e20c4fa5e4dd6a48a2c3b7caf4cefb090063503f38dc4716d8daee6d3bf22","orchestration-contract.mjs":"ec08f303a166365b99e70b675de4cfe76c6156c2567e14b5569f6d992f0231b7","orchestration-evidence.mjs":"d0d06cecf0eb08e5c6e653c62a4f45b1eddf2119c2acb8341056b34f488d214a","orchestration-report.mjs":"d4e0a9ad8e4a01b462d22c6b1866aac291565c533ff476085d3367cb6d59bc1b","package-integrity.mjs":"a8210c9494a56bfb9a5ea3d10064c7a269f0b6330c0af7c0700e706c3c0224e3","package.json":"1d9dbab38feaf5829be7df1feacf0a2b23b1374599d11c27d86c6661e26df80e","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":"804e7527618ff4ddea6b6457ff9878c1179581827580387b4468fd02af364266"},"format":"worktrust-package/1","kind":"npm","version":"0.10.33"},"signature":"zLrY_UyNlKq0iWFgAOn-mxP7K64ppxvECzEciY5qwu8E0N3fpmOmlN5v7AvX30KXY2XNwMmZeNMxlDsD4nttCQ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "worktrust",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.33",
|
|
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,18 +76,26 @@ 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.33";
|
|
80
80
|
/**
|
|
81
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
82
|
* to offer). Raised ONLY when what is measured changes: the timeline, the seconds, the tokens, the steering, the session
|
|
83
83
|
* kinds, the readers. A release that changes consent, coupling or words keeps it. `update` offers the re-measure only when
|
|
84
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.
|
|
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
|
+
* 0.10.33 KEEPS 2 (release 9, 2026-10-29): one line per autonomous process per day changes how finished headless and
|
|
88
|
+
* scheduled runs are PACKED into lines, not what is measured: the timeline, the seconds (the minute compaction keeps every
|
|
89
|
+
* counted second), the tokens, the steering, the session kinds and the readers are the same. On production (read-only) the
|
|
90
|
+
* existing data a re-measure would repack is 4 headless lines of one person on 2 days, none scheduled, none with a person's
|
|
91
|
+
* second and none under the 60 s floor, so a re-measure would move no figure the passport shows; raising would offer every
|
|
92
|
+
* person a re-measure for nothing. New runs arrive folded from 0.10.33 on.
|
|
86
93
|
*/
|
|
87
|
-
const MEASURE_RULES =
|
|
94
|
+
const MEASURE_RULES = 2;
|
|
88
95
|
/** What each measure-rules version changed, in the words the re-measure offer says (one entry per raise, never rewritten). */
|
|
89
96
|
const MEASURE_CHANGES = {
|
|
90
97
|
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"],
|
|
98
|
+
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"],
|
|
91
99
|
};
|
|
92
100
|
const ORIGIN = (flag("origin") ?? process.env.WORKTRUST_ORIGIN ?? "https://app.worktrust.io").replace(/\/$/, "");
|
|
93
101
|
const MCP = flag("url") ?? process.env.WORKTRUST_MCP_URL ?? `${ORIGIN}/api/mcp`;
|
|
@@ -152,7 +160,7 @@ function historyQueueScope(token) {
|
|
|
152
160
|
/** Run a script; its output is shown, or collected for the plan. The key travels in the environment only. */
|
|
153
161
|
function run(path, scriptArgs, token, collect = false, extraEnv = {}) {
|
|
154
162
|
return new Promise((resolve) => {
|
|
155
|
-
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 } });
|
|
163
|
+
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 } });
|
|
156
164
|
let out = "";
|
|
157
165
|
child.stdout?.on("data", (chunk) => { out += chunk; });
|
|
158
166
|
child.stderr?.on("data", (chunk) => { out += chunk; });
|
|
@@ -231,7 +239,7 @@ async function pairByBrowser(host, extra) {
|
|
|
231
239
|
server.close();
|
|
232
240
|
if (!code) fail("no approval arrived in time. Run `worktrust connect` again.");
|
|
233
241
|
const exchange = await post("/api/cli/token", { device_code: secret, code, code_verifier: verifier }).catch(() => null);
|
|
234
|
-
if (exchange?.json?.error === "device_limit") fail("
|
|
242
|
+
if (exchange?.json?.error === "device_limit") fail("The devices your plan allows are already connected. In WorkTrust Sources, disconnect a device (or upgrade to Premium for more), then connect again. Every connected device keeps working and earlier measurements are kept.");
|
|
235
243
|
if (!exchange || exchange.status !== 200 || !exchange.json.token) fail(`the approval could not be exchanged (${exchange?.json?.error ?? "no answer"}). Run \`worktrust connect\` again.`);
|
|
236
244
|
say(` ✓ Approved as "${exchange.json.label}"${exchange.json.account ? ` for the WorkTrust account ${exchange.json.account}` : ""}`);
|
|
237
245
|
if (exchange.json.account) say(" Not your account? Run `npx worktrust disconnect` now and revoke it in WorkTrust.");
|
|
@@ -266,7 +274,7 @@ async function pairByCode(host, extra) {
|
|
|
266
274
|
if (answer.json.account) say(" Not your account? Run `npx worktrust disconnect` now and revoke it in WorkTrust.");
|
|
267
275
|
return paired(answer.json);
|
|
268
276
|
}
|
|
269
|
-
if (answer.json.error === "device_limit") fail("
|
|
277
|
+
if (answer.json.error === "device_limit") fail("The devices your plan allows are already connected. In WorkTrust Sources, disconnect a device (or upgrade to Premium for more), then connect again. Every connected device keeps working and earlier measurements are kept.");
|
|
270
278
|
if (answer.json.error === "slow_down") wait += 2000;
|
|
271
279
|
else if (answer.json.error === "expired_token") fail("the code expired. Run `worktrust connect` again.");
|
|
272
280
|
else if (answer.json.error === "invalid_grant") fail("this pairing was already used. Run `worktrust connect` again.");
|
|
@@ -580,7 +588,7 @@ async function hook() {
|
|
|
580
588
|
if (has("hermes") || has("goose")) return sessionEnd();
|
|
581
589
|
const key = await freshKey();
|
|
582
590
|
if (!key) return;
|
|
583
|
-
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
|
|
591
|
+
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
|
|
584
592
|
process.exitCode = await new Promise((resolve, reject) => { child.on("error", reject); child.on("close", (code) => resolve(code ?? 1)); });
|
|
585
593
|
}
|
|
586
594
|
|
|
@@ -647,7 +655,7 @@ async function update() {
|
|
|
647
655
|
if (found.length === 0) say(" (no AI app found here)");
|
|
648
656
|
const hookFresh = !agreed.has("session-hook");
|
|
649
657
|
say(` The session hook and ${STABLE} are brought to ${CLI_VERSION}.`);
|
|
650
|
-
say(hookFresh ? ` + Session hook: ${join(homedir(), ".claude", "settings.json")} → SessionStart, SessionEnd and
|
|
658
|
+
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)`);
|
|
651
659
|
say(" The key stays as it is: no new pairing, the same computer in WorkTrust.");
|
|
652
660
|
say();
|
|
653
661
|
if (has("dry-run")) { say(" Dry run: nothing was written and nothing was sent."); return; }
|
|
@@ -709,7 +717,7 @@ async function connect() {
|
|
|
709
717
|
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.`);
|
|
710
718
|
say(` ${direct ? 3 : 4}. The session hook is installed:`);
|
|
711
719
|
say(" + The hook and counter from the checked release, retained outside the package-manager cache");
|
|
712
|
-
say(` + ${join(homedir(), ".claude", "settings.json")} → SessionStart, SessionEnd and
|
|
720
|
+
say(` + ${join(homedir(), ".claude", "settings.json")} → SessionStart, SessionEnd, PreCompact and (at most once an hour) Stop run it`);
|
|
713
721
|
say();
|
|
714
722
|
say(" Sent to WorkTrust afterwards: durations, token counts, model names, a layer keyword, counts,");
|
|
715
723
|
say(" and, to match the work to GitHub, the repository's owner/name and the commit hashes.");
|
|
@@ -805,13 +813,24 @@ async function offerHistory(paths, token, devicePem, url = MCP, rebuild = false,
|
|
|
805
813
|
: 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` : ""}.`
|
|
806
814
|
: 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.`
|
|
807
815
|
: `${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.`;
|
|
816
|
+
// ONLY THE DAYS THAT CHANGED (0.10.32): the hook asked WorkTrust which of this computer's days it holds as this CLI measures
|
|
817
|
+
// them and sent the others; every day it compared unchanged is nothing sent, said once. Not asked (an older WorkTrust) says nothing.
|
|
818
|
+
const compared = Number.isInteger(did?.days?.compared) ? did.days.compared : null, changed = Number.isInteger(did?.days?.changed) ? did.days.changed : null;
|
|
819
|
+
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; }
|
|
820
|
+
if (rebuild && compared !== null && changed !== null && compared > changed) say(` ${compared - changed} of ${compared} days unchanged on WorkTrust; sending the ${changed} that changed.`);
|
|
821
|
+
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.`);
|
|
808
822
|
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.`);
|
|
809
823
|
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.`);
|
|
810
824
|
// 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.
|
|
811
825
|
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.");
|
|
812
826
|
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.`);
|
|
813
827
|
// 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.
|
|
814
|
-
if (rebuild && n(did?.staged) > 0 && !Number(did?.delivery?.review) && !Number(did?.delivery?.waiting))
|
|
828
|
+
if (rebuild && n(did?.staged) > 0 && !Number(did?.delivery?.review) && !Number(did?.delivery?.waiting)) {
|
|
829
|
+
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.`);
|
|
830
|
+
// 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.
|
|
831
|
+
const queued = did?.queued;
|
|
832
|
+
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`);
|
|
833
|
+
}
|
|
815
834
|
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.");
|
|
816
835
|
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.");
|
|
817
836
|
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)` : ""}.`);
|
|
@@ -1247,6 +1266,9 @@ async function status() {
|
|
|
1247
1266
|
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)");
|
|
1248
1267
|
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)");
|
|
1249
1268
|
say(sessionHookHere() ? " Session hook: installed" : " Session hook: not installed");
|
|
1269
|
+
// 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.
|
|
1270
|
+
{ let unread = null; try { unread = JSON.parse(readFileSync(join(HOME_DIR, "sessions.json"), "utf8")).__unreadable ?? null; } catch { /* no state yet */ }
|
|
1271
|
+
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)`); }
|
|
1250
1272
|
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)"); }
|
|
1251
1273
|
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)"); }
|
|
1252
1274
|
if (antigravityHere()) say(agyHooks()?.worktrust ? " Antigravity: wakes the session hook" : " Antigravity: does not wake the session hook (npx worktrust update asks)");
|