worktrust 0.10.18 → 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 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.
@@ -329,14 +335,17 @@ give `conversations.json`. Every 64 MB a line on stderr says how many megabytes
329
335
  one question; Enter is No; `--dry-run` shows the plan and stops. On a coupled computer the bare `npx worktrust` looks
330
336
  in your Downloads folder (its top level only) for such an export it has not sent, offers it the same way, once, and
331
337
  remembers your answer by the file's digest, never by a conversation.
332
- - **The export replaces.** On the days the export covers, its lines count and the earlier lines of that product a
333
- connector brought in (an AI signed in on the web, which selects what it reports) are withdrawn and kept, each with a
334
- correction row, so a day counts once; the command says how many. A connector line that arrives later for a day the
335
- export covers is held. Lines an AI app reported earlier under no product may describe the same conversations: the
336
- command says how many lie on those days and asks once, `Also withdraw N earlier lines an AI app reported for these
337
- days?`; Enter is No, `--yes` keeps No, `--dry-run` sends nothing, and only a typed yes or `--withdraw-unknown` said
338
- in advance withdraws exactly those lines on exactly those days, the same way, never deleting. Never touched: another
339
- product, your own measured sessions, a private line, a day the export does not cover.
338
+ - **The export replaces.** On the days the export covers, its lines count and the earlier lines of that product your
339
+ connector of the same vendor reported (an AI signed in on the web, which selects what it reports) are withdrawn and
340
+ kept, each with a correction row, so a day counts once; the command says how many. A connector line that arrives later
341
+ for a day the export covers is held. Lines that connector reported earlier under no product may describe the same
342
+ conversations: the command says how many lie on those days and asks once, `Also withdraw N earlier lines your Claude
343
+ connector reported for these days?`; Enter is No, `--yes` keeps No, `--dry-run` sends nothing, and only a typed yes or
344
+ `--withdraw-unknown` said in advance withdraws exactly those lines on exactly those days, the same way, never deleting.
345
+ The count in the question is the door's own, and it is the count the yes withdraws. Never touched, whatever you answer
346
+ (0.10.19, held on the server): any line a computer of yours wrote (measured sessions, a rebuilt or archived history, an
347
+ earlier export send), a measured line, a connector of another vendor, another product, a private line, a day the export
348
+ does not cover.
340
349
 
341
350
  ## A copied session folder, and the local archive key
342
351
 
@@ -382,14 +391,36 @@ which would delete every password on the computer, and many people rightly keep
382
391
 
383
392
  ## What it reads, writes and sends
384
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
+
385
408
  | | |
386
409
  |---|---|
387
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. |
388
411
  | **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/`. |
389
412
  | **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). |
390
- | **Sends, afterwards** | Per measured stretch of work, and nothing else: its durations (`seconds`, `duration_basis`, `model_seconds`, `tool_seconds`, `human_seconds`, `idle_seconds`), 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`), counts of how you work (`exchanges`, `turn_basis`, `agent_runs`, `agent_seconds`, `agent_peak`, `interrupts`, `steers`), 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, 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). |
413
+ | **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). |
391
414
  | **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. |
392
415
 
416
+ **The clock is WorkTrust's, not this computer's (0.10.20).** A measured stretch travels as its timeline: one step per
417
+ transcript line, as a kind (your turn, the model's answer, a tool call, a tool's result, a question that waited for you, an
418
+ interruption) and the whole seconds since the previous step. Nothing of a message is in it: no word, no tool name, no path.
419
+ This CLI computes no duration and no hours of its own and carries no rule for doing so; WorkTrust computes the seconds, the
420
+ hours in layers and the turns from the timeline when it arrives, and the figures the terminal shows after a send are
421
+ WorkTrust's receipt. The line also names the CLI's version and a digest of its own files, as signals of which code ran,
422
+ never as proof.
423
+
393
424
  ## Why you can check it
394
425
 
395
426
  - **No dependencies and no install scripts.** Plain files, readable
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
@@ -1,24 +1,20 @@
1
1
  /**
2
2
  * THE LOCAL COUNTER — rubric v0.1 (`counter@0.1.0`).
3
- *
4
3
  * Reads this machine's own Claude Code transcripts, its Codex rollouts (2026-09-27), its Antigravity conversations (2026-10-04), its VS Code
5
4
  * Copilot chat sessions (2026-09-08) and, when given, a claude.ai export (~/.claude/projects/**​/*.jsonl — transcripts
6
5
  * ONLY, never project files), classifies each of the person's OWN messages with the
7
6
  * deterministic rules below, and reports COUNTS per month through the WorkTrust MCP door's
8
7
  * `log_signals`. The same logs under the same rubric give the same numbers: every count is
9
8
  * re-derivable, and a better rubric is a new version that writes beside this one.
10
- *
11
9
  * WHAT CANNOT LEAVE: the door's schema takes vocabulary keys and integers; it has no text
12
10
  * field and refuses unknown keys by name. This script builds exactly that payload and nothing
13
11
  * else — a password or a .env line has no channel to travel through. Run with --dry-run to see
14
12
  * every number before anything is sent.
15
- *
16
13
  * node count-behaviour.mjs --dry-run
17
14
  * node count-behaviour.mjs --url https://app.worktrust.io/api/mcp --token wt_...
18
15
  * node count-behaviour.mjs --dry-run --exclude client-x --exclude secret
19
16
  * node count-behaviour.mjs --dry-run --claude-export ~/Downloads/claude-export (a claude.ai data export beside the transcripts)
20
17
  * node count-behaviour.mjs --dry-run --chatgpt-export ~/Downloads/chatgpt-export (a ChatGPT data export, the same way)
21
- *
22
18
  * CONFIDENTIAL PROJECTS stay out BEFORE anything is counted: `--exclude <text>` (repeatable)
23
19
  * skips every project directory whose name contains that text, and `.worktrust-counter.json`
24
20
  * in your home directory does the same permanently: { "exclude": ["client-x"] }. An excluded
@@ -55,7 +51,6 @@ export const encode = value => JSON.stringify(value, (_, v) => v instanceof Map
55
51
  export const decode = value => JSON.parse(value, (_, v) => v?.$map ? new Map(v.$map) : v?.$set ? new Set(v.$set) : v);
56
52
  export function checkpointStore(path, signature, manifest) {
57
53
  mkdirSync(dirname(path), {recursive:true,mode:0o700});
58
- // A process lock prevents two local runs from replacing each other's checkpoint.
59
54
  const lock=path+'.lock';
60
55
  try { const fd=openSync(lock,'wx',0o600);writeFileSync(fd,String(process.pid));closeSync(fd); }
61
56
  catch(error) {
@@ -409,7 +404,25 @@ function gitCommitsOf(cwd, sinceIso) {
409
404
  return commits;
410
405
  }
411
406
 
407
+ export const isoWeek = (day) => {
408
+ const date = new Date(`${day}T00:00:00Z`);
409
+ const thursday = new Date(date); thursday.setUTCDate(date.getUTCDate() + 3 - ((date.getUTCDay() + 6) % 7));
410
+ const firstThursday = new Date(Date.UTC(thursday.getUTCFullYear(), 0, 4));
411
+ const week = 1 + Math.round(((thursday - firstThursday) / 86400000 - 3 + ((firstThursday.getUTCDay() + 6) % 7)) / 7);
412
+ return `${thursday.getUTCFullYear()}-W${String(week).padStart(2, "0")}`;
413
+ };
414
+ export function overlappingSessions(spans) {
415
+ const ordered=spans.map((span,index)=>({...span,index})).filter(s=>s.end>s.start).sort((a,b)=>a.start-b.start);
416
+ const found=new Set();let maximumEnd=-Infinity;
417
+ for(let i=0;i<ordered.length;i++){
418
+ const a=ordered[i];
419
+ if(maximumEnd>a.start || (ordered[i+1] && ordered[i+1].start<a.end))found.add(a.index);
420
+ maximumEnd=Math.max(maximumEnd,a.end);
421
+ }
422
+ return found;
423
+ }
412
424
 
425
+ async function main() {
413
426
  const args = process.argv.slice(2);
414
427
  const flag = (name) => args.includes(`--${name}`);
415
428
  const value = (name) => { const i = args.indexOf(`--${name}`); return i >= 0 ? args[i + 1] : undefined; };
@@ -473,7 +486,7 @@ if (flag("classify")) {
473
486
  const form = classifyOpening(row.text);
474
487
  console.log(JSON.stringify({ form, kind: openingActKind(row.text, form), second: row.second === undefined ? null : classifySecondTurn(row.second), pasted: Math.round(pastedShare(row.text ?? "") * 100) / 100, restated: row.skill === undefined ? null : restatedSentences(row.text, row.skill), gitSide: row.commits === undefined ? null : gitSideCounts(row.commits), testRun: row.command === undefined ? null : { test: isTestCommand(row.command), outcome: row.result === undefined ? null : testOutcomeOf(row.result, row.isError) } }));
475
488
  }
476
- process.exit(0);
489
+ return (process.exitCode = 0);
477
490
  }
478
491
  {
479
492
  const i = args.indexOf("--agreement");
@@ -485,7 +498,7 @@ if (flag("classify")) {
485
498
  const perLanguage = Object.fromEntries([...byLang.entries()].map(([lang, pairs]) => [lang, { n: pairs.length, kappa: cohenKappa(pairs) }]));
486
499
  const passes = rows.length >= 100 && unclassified !== null && unclassified <= UNCLASSIFIED_CEILING && Object.values(perLanguage).every((entry) => entry.kappa !== null && entry.kappa >= KAPPA_FLOOR);
487
500
  console.log(JSON.stringify({ n: rows.length, unclassified, perLanguage, floors: { kappa: KAPPA_FLOOR, unclassified: UNCLASSIFIED_CEILING, items: 100 }, counterGrade: passes }));
488
- process.exit(passes ? 0 : 1);
501
+ return (process.exitCode = passes ? 0 : 1);
489
502
  }
490
503
  }
491
504
  /**
@@ -788,13 +801,6 @@ const byMonthContext = new Map(); // month → Map("signal|context" → count)
788
801
  * week never straddles two stored months: "2026-09|2026-W36". A count without a day (a
789
802
  * month-level aggregate) lands in the month's "U" bucket.
790
803
  */
791
- export const isoWeek = (day) => {
792
- const date = new Date(`${day}T00:00:00Z`);
793
- const thursday = new Date(date); thursday.setUTCDate(date.getUTCDate() + 3 - ((date.getUTCDay() + 6) % 7));
794
- const firstThursday = new Date(Date.UTC(thursday.getUTCFullYear(), 0, 4));
795
- const week = 1 + Math.round(((thursday - firstThursday) / 86400000 - 3 + ((firstThursday.getUTCDay() + 6) % 7)) / 7);
796
- return `${thursday.getUTCFullYear()}-W${String(week).padStart(2, "0")}`;
797
- };
798
804
  const byWeek = new Map(); // "month|week" → Map(signal → count)
799
805
  /**
800
806
  * THE WORK STRETCH (0.7.0, the owner's capability framework v4 §13: "work_stretch_id, the stable unit joining AI
@@ -1175,7 +1181,7 @@ for await (const session of sessions()) {
1175
1181
  checkpoint?.write(sessionIndex,{maps:checkpointMaps,sets:checkpointSets,sessionSpans,messages,files,currentContext,duplicateLines},checkpointDependencies);
1176
1182
  if(++processed>=maxSessions && sessionIndex<manifest.length){
1177
1183
  console.log(`Counter paused at ${sessionIndex}/${manifest.length} sessions; rerun the same command. Nothing sent.`);
1178
- checkpoint?.close();process.exit(0);
1184
+ checkpoint?.close();return (process.exitCode = 0);
1179
1185
  }
1180
1186
  }
1181
1187
  currentUnit = null; currentDay = null; currentStretchBase = null; // month-level aggregates carry no unit, no day and no stretch
@@ -1198,16 +1204,6 @@ for (const [context, cwd] of contextCwds) {
1198
1204
  }
1199
1205
  currentUnit = null; currentDay = null; currentContext = null;
1200
1206
  // The same strict overlap test in O(n log n), rather than comparing every pair.
1201
- export function overlappingSessions(spans) {
1202
- const ordered=spans.map((span,index)=>({...span,index})).filter(s=>s.end>s.start).sort((a,b)=>a.start-b.start);
1203
- const found=new Set();let maximumEnd=-Infinity;
1204
- for(let i=0;i<ordered.length;i++){
1205
- const a=ordered[i];
1206
- if(maximumEnd>a.start || (ordered[i+1] && ordered[i+1].start<a.end))found.add(a.index);
1207
- maximumEnd=Math.max(maximumEnd,a.end);
1208
- }
1209
- return found;
1210
- }
1211
1207
  const overlapping=overlappingSessions(sessionSpans);
1212
1208
  // Parallelism: a session that overlaps any other counted session, once per session.
1213
1209
  for (let i = 0; i < sessionSpans.length; i += 1) {
@@ -1221,7 +1217,7 @@ for (let i = 0; i < sessionSpans.length; i += 1) {
1221
1217
  if (flag("stretch-signals")) {
1222
1218
  const rows = [...byStretch.entries()].sort(([, a], [, b]) => a.day.localeCompare(b.day)).map(([stretch_ref, entry]) => JSON.stringify({ stretch_ref, day: entry.day, analyzer_version: ANALYZER_VERSION, signals: Object.fromEntries(Object.entries(entry.signals).sort().map(([signal, count]) => [signal, Math.min(COUNT_CEILING, count)])) }));
1223
1219
  await new Promise((resolve) => process.stdout.write(`${[...rows, JSON.stringify({ stretch_signals_end: rows.length })].join("\n")}\n`, resolve));
1224
- process.exit(0);
1220
+ return (process.exitCode = 0);
1225
1221
  }
1226
1222
 
1227
1223
  const months = [...byMonth.keys()].sort();
@@ -1281,10 +1277,10 @@ console.log("");
1281
1277
  if (LABEL_OUT) { writeFileSync(LABEL_OUT, labelRows.map((row) => JSON.stringify(row)).join("\n") + "\n"); console.log(` openings written for labelling: ${labelRows.length} → ${LABEL_OUT} (local file; add "label" per line, then --agreement ${LABEL_OUT})`); }
1282
1278
  if (DRY) {
1283
1279
  console.log(`dry run — nothing sent. Next: run again with --stage — the reading then WAITS in the app (${appOrigin}/behaviour) until the person clicks Import; nothing is counted before that click. (Alternative without the app visit: approval code ${APPROVAL} at ${appOrigin}/behaviour?approve=${APPROVAL}, then --send.)${URL_ && TOKEN ? ` Coupling found (${new URL(URL_).host}).` : " Pass --url and --token (or couple this client) first."}`);
1284
- process.exit(0);
1280
+ return (process.exitCode = 0);
1285
1281
  }
1286
1282
  if (STAGE) {
1287
- if (!URL_ || !TOKEN) { console.error("no coupling found: pass --url and --token, or set WORKTRUST_MCP_URL / WORKTRUST_MCP_TOKEN"); process.exit(1); }
1283
+ if (!URL_ || !TOKEN) { console.error("no coupling found: pass --url and --token, or set WORKTRUST_MCP_URL / WORKTRUST_MCP_TOKEN"); return (process.exitCode = 1); }
1288
1284
  const readings = months.map((month) => ({ period: month, stretches: sessionsByMonth.get(month) ?? 0, signals: [...byMonth.get(month).entries()].map(([signal, count]) => ({ signal, count: clampCount(signal, count, month) })), contexts: cellsOf(month), context_names: contextNamesOf(), units: [...(unitsByMonth.get(month)?.values() ?? [])].map(({ unit, signal, induced, day, context }) => ({ unit, signal, induced, ...(day ? { day } : {}), ...(context ? { context } : {}) })) }));
1289
1285
  if (!flag("legacy-stage")) {
1290
1286
  // WHAT THIS MACHINE ALREADY DELIVERED, per month and ISO week, for this coupling and rubric
@@ -1326,7 +1322,7 @@ if (STAGE) {
1326
1322
  const unchanged=new Set(readings.map(r=>r.period)).size-plan.length;
1327
1323
  console.log(` ${plan.length} month(s) with new or changed weeks${unchanged>0?` · ${unchanged} unchanged, not sent`:""}`);
1328
1324
  for(const {reading,changes} of plan)console.log(` ${reading.period}: ${changes.length?changes.map(c=>`${c.week} ${c.previous===null?"new":c.observations===0?"removed":`${c.previous}→${c.observations}`}`).join(" · "):"per-project cells changed"}`);
1329
- if(plan.length===0){console.log("Nothing new since the last delivery from this machine. Nothing sent.");process.exit(0);}
1325
+ if(plan.length===0){console.log("Nothing new since the last delivery from this machine. Nothing sent.");return (process.exitCode = 0);}
1330
1326
  // Persist the outbound revision BEFORE sending. A failed HTTP response replays safely.
1331
1327
  let delivery=null;try{delivery=JSON.parse(readFileSync(deliveryPath,"utf8"));}catch{}
1332
1328
  if(delivery?.scope!==scope)delivery=null;
@@ -1356,7 +1352,7 @@ if (STAGE) {
1356
1352
  }
1357
1353
  }
1358
1354
  console.log("Complete months await the owner's Import in /behaviour. Imports replace this coupling's month, including corrections and removals.");
1359
- process.exit(0);
1355
+ return (process.exitCode = 0);
1360
1356
  }
1361
1357
  // UNDER THE HOST'S CEILING. A serverless request takes about 4.5 MB; a year of unit references
1362
1358
  // does not fit in one. Months are staged in chunks that stay under the ceiling, each with its own
@@ -1378,9 +1374,9 @@ if (STAGE) {
1378
1374
  console.log(` staged ${chunk[0].period}${chunk.length > 1 ? `–${chunk[chunk.length - 1].period}` : ""} → ${text}`);
1379
1375
  }
1380
1376
  console.log(` the person imports ${chunks.length === 1 ? "it" : `each of the ${chunks.length} readings`} at ${appOrigin}/behaviour — one click each; nothing is on the mirror before it.`);
1381
- process.exit(0);
1377
+ return (process.exitCode = 0);
1382
1378
  }
1383
- if (!URL_ || !TOKEN) { console.error("no coupling found: pass --url and --token, or set WORKTRUST_MCP_URL / WORKTRUST_MCP_TOKEN"); process.exit(1); }
1379
+ if (!URL_ || !TOKEN) { console.error("no coupling found: pass --url and --token, or set WORKTRUST_MCP_URL / WORKTRUST_MCP_TOKEN"); return (process.exitCode = 1); }
1384
1380
  console.log(`sending to ${new URL(URL_).host} …`);
1385
1381
  for (const month of months) {
1386
1382
  const bucket = byMonth.get(month);
@@ -1392,3 +1388,6 @@ for (const month of months) {
1392
1388
  const text = answer?.result?.content?.[0]?.text ?? answer?.error?.message ?? `http ${response.status}`;
1393
1389
  console.log(` sent ${month} → ${text}`);
1394
1390
  }
1391
+
1392
+ }
1393
+ await main();