worktrust 0.10.34 → 0.10.36

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.
@@ -39,7 +39,9 @@ export function queuedHistory(target,body,source) {
39
39
  const request=join(root,id+'.request.json'),ack=join(root,id+'.ack.json'),state=join(root,id+'.state.json');
40
40
  const acknowledged=read(ack);
41
41
  // REPLACED (0.10.29): a batch cut into smaller ones is acknowledged by its pieces; the caller follows them.
42
- if(acknowledged?.id===id)return {id,status:Array.isArray(acknowledged.replacedBy)?'replaced':'acknowledged',replacedBy:Array.isArray(acknowledged.replacedBy)?acknowledged.replacedBy.filter(child=>/^[a-f0-9]{64}$/.test(child)):[],lines:Number.isInteger(acknowledged.lines)?acknowledged.lines:null,confirm(){},close(){},defer(){},oversize(){},replace(){return [];}};
42
+ // CLOSED (2026-10-31): a batch WorkTrust refused for good is let go here, never "acknowledged": WorkTrust holds nothing of it,
43
+ // so a send that finds it says it was refused, never "already held" (CLI 0.10.35 counted it held and reported a run whole).
44
+ if(acknowledged?.id===id)return {id,status:Array.isArray(acknowledged.replacedBy)?'replaced':acknowledged.closedAt?'closed':'acknowledged',replacedBy:Array.isArray(acknowledged.replacedBy)?acknowledged.replacedBy.filter(child=>/^[a-f0-9]{64}$/.test(child)):[],lines:Number.isInteger(acknowledged.lines)?acknowledged.lines:null,confirm(){},close(){},defer(){},oversize(){},replace(){return [];}};
43
45
  const current=read(state);
44
46
  reservation(root,()=>{
45
47
  if(!existsSync(request)) {
@@ -73,7 +75,11 @@ export function historyRefusal(text,response) {
73
75
  // A staged run WorkTrust closed or refused (0.10.27: another computer's key, seven days without its last batch) is final.
74
76
  const closed=rpc?.id===1 && String(rpc?.error?.message??'').startsWith('history run refused:');
75
77
  // A 413 (0.10.29) is the batch, not the queue: it is cut smaller, never sent again as it was, and nothing else waits for it.
76
- return {reason:review?'review':closed?'closed':response.status===413?'oversize':response.status===429?'capacity':'unconfirmed',seconds:Number.isFinite(raw)&&raw>0?Math.min(MAX_RETRY_SECONDS,raw):0};
78
+ // THE SERVER'S OWN SENTENCE (0.10.35; every final refusal since 2026-10-31): why WorkTrust refused the batch, printed instead of
79
+ // a guess (0.10.35 said "it missed a batch for seven days" of a batch refused for its lines). One line, control characters
80
+ // taken out, at most 400 characters.
81
+ const said=closed?String(rpc.error.message).replace(/[\u0000-\u001f\u007f-\u009f]/g,' ').slice(0,400):null;
82
+ return {reason:review?'review':closed?'closed':response.status===413?'oversize':response.status===429?'capacity':'unconfirmed',seconds:Number.isFinite(raw)&&raw>0?Math.min(MAX_RETRY_SECONDS,raw):0,...(said?{said}:{})};
77
83
  }
78
84
 
79
85
  /** Explicit recovery, even after the AI client removed its source files. A changed account/key
@@ -87,7 +93,7 @@ export function historyRefusal(text,response) {
87
93
  * (`refused`: WorkTrust keeps the earlier lines counting, and `npx worktrust@latest history` measures again). A single line too
88
94
  * large for a call is let go the same way. `only` limits a pass to those batches (and their pieces): the send that just queued them.
89
95
  */
90
- export async function resumeHistory(target, {send, confirmed, note, retryReview=false, dry=false, limit=Infinity, cutter=null, only=null}) {
96
+ export async function resumeHistory(target, {send, confirmed, note, closed=null, retryReview=false, dry=false, limit=Infinity, cutter=null, only=null}) {
91
97
  const root=join(homedir(),'.worktrust','history-outbox'),scope=scopeOf(target);
92
98
  const totals={received:0,review:0,waiting:0,batches:0,refused:0,held:0,split:0};let paused=null,sent=0;
93
99
  if(!existsSync(root))return totals;
@@ -110,7 +116,8 @@ export async function resumeHistory(target, {send, confirmed, note, retryReview=
110
116
  const marked=(id)=>read(join(root,id+'.state.json'))?.status==='oversize';
111
117
  const whole=(batches)=>batches.length>0&&batches.length===batches[0].run.count&&batches.every((item,index)=>item.run.index===index&&item.run.count===batches[0].run.count);
112
118
  const queue=only?[...only]:[...ids],seen=new Set();
113
- const letGo=(batches)=>{for(const batch of batches){queuedHistory(target,batch.body,batch.source).close('oversize');items.set(batch.id,null);seen.add(batch.id);totals.refused+=batch.entries.length;}return null;};
119
+ // `closed` (2026-10-31): told which run lost a batch for good, so the send never reports that run whole.
120
+ const letGo=(batches)=>{for(const batch of batches){queuedHistory(target,batch.body,batch.source).close('oversize');items.set(batch.id,null);seen.add(batch.id);totals.refused+=batch.entries.length;closed?.(batch.run,batch.entries.length);}return null;};
114
121
  // Cut smaller: answers the pieces' ids, or null when the batch (or its run) can never fit and was let go.
115
122
  const resplit=(item,queued,tighter)=>{
116
123
  if(item.run){
@@ -131,7 +138,7 @@ export async function resumeHistory(target, {send, confirmed, note, retryReview=
131
138
  if(ack?.id===id){if(Array.isArray(ack.replacedBy))queue.unshift(...ack.replacedBy.filter(child=>/^[a-f0-9]{64}$/.test(child)));else if(only&&Number.isInteger(ack.lines))totals.held+=ack.lines;continue;}
132
139
  const item=load(id);if(!item)continue;
133
140
  const queued=queuedHistory(target,item.body,item.source);totals.batches++;
134
- if(queued.status==='acknowledged')continue;
141
+ if(queued.status==='acknowledged'||queued.status==='closed')continue;
135
142
  if(queued.status==='replaced'){queue.unshift(...queued.replacedBy);continue;}
136
143
  // `limit` (0.10.27): the hook sends a few a run by itself; the rest wait, untouched, for the next run.
137
144
  if(sent>=limit){totals.waiting+=item.entries.length;continue;}
@@ -151,16 +158,38 @@ export async function resumeHistory(target, {send, confirmed, note, retryReview=
151
158
  try{if(!response.ok)throw Error();confirmed(text,item.entries.length);}
152
159
  catch{
153
160
  const refusal=historyRefusal(text,response);
154
- if(refusal.reason==='closed'){queued.close();totals.refused+=item.entries.length;continue;}
161
+ if(refusal.reason==='closed'){queued.close();totals.refused+=item.entries.length;if(refusal.said)totals.said=refusal.said;closed?.(item.run,item.entries.length);continue;}
155
162
  // Too large (0.10.29): marked and taken again at once, by the cut, never resent as it was. Without a cutter it waits.
156
163
  if(refusal.reason==='oversize'){queued.oversize();if(cutter){seen.delete(id);queue.unshift(id);}else totals.waiting+=item.entries.length;continue;}
157
164
  if(refusal.reason!=='review')paused={reason:refusal.reason,seconds:refusal.seconds>0?refusal.seconds:5};queued.defer(refusal.reason,paused?.seconds??refusal.seconds);totals[refusal.reason==='review'?'review':'waiting']+=item.entries.length;continue;
158
165
  }
159
- queued.confirm(item.entries.length);totals.received+=item.entries.length;note(text);
166
+ queued.confirm(item.entries.length);totals.received+=item.entries.length;note(text,item.run);
160
167
  }catch{paused={reason:'unconfirmed',seconds:5};queued.defer(paused.reason,paused.seconds);totals.waiting+=item.entries.length;}
161
168
  }
162
169
  return totals;
163
170
  }
171
+ /**
172
+ * A RUN IS DONE WHEN WORKTRUST HOLDS ALL OF IT (2026-10-31). On 2026-10-30 a re-measure of four batches lost one to a final
173
+ * refusal and the command said "✓ Re-measured. WorkTrust holds all 3 batches": the receipts it had were read as the run. Per run
174
+ * a send touches: its declared count, the batches WorkTrust confirmed (a receipt now, or an acknowledgement an earlier send kept
175
+ * here), the most the door said had arrived, whether a receipt said the run is complete, and the batches refused for good.
176
+ * `state()` is what the command reads: whole only when every run is; null when the send touched none.
177
+ */
178
+ export function runLedger() {
179
+ const runs=new Map();
180
+ const of=(run)=>{if(!run||typeof run.id!=='string'||!Number.isInteger(run.count)||!Number.isInteger(run.index))return null;const known=runs.get(run.id)??{count:run.count,confirmed:new Set(),arrived:0,complete:false,refused:new Set()};runs.set(run.id,known);return known;};
181
+ const kept=(run)=>Math.min(run.count,Math.max(run.arrived,run.confirmed.size));
182
+ return {
183
+ heard(run,receipt){const known=of(run);if(!known)return;known.confirmed.add(run.index);if(Number.isInteger(receipt?.arrived))known.arrived=Math.max(known.arrived,receipt.arrived);if(receipt?.complete===true||(Number.isInteger(receipt?.of)&&receipt.arrived===receipt.of))known.complete=true;},
184
+ held(run){of(run)?.confirmed.add(run.index);},
185
+ refused(run){of(run)?.refused.add(run.index);},
186
+ state(){
187
+ const all=[...runs.values()];if(!all.length)return null;
188
+ return {batches:all.reduce((n,run)=>n+run.count,0),arrived:all.reduce((n,run)=>n+kept(run),0),refused:all.reduce((n,run)=>n+run.refused.size,0),
189
+ whole:all.every(run=>run.refused.size===0&&(run.complete||kept(run)===run.count))};
190
+ },
191
+ };
192
+ }
164
193
  /** A queued batch's id, as queuedHistory names it, so a send can hand its own batches to resumeHistory (`only`). */
165
194
  export const historyIdOf=(target,body,source)=>digest(scopeOf(target)+'\0'+source+'\0'+body);
166
195
 
package/log-session.mjs CHANGED
@@ -242,7 +242,7 @@ const { modCounts = () => null } = (await import("./claude-mod.mjs").catch(() =>
242
242
  const liveOf = (file, day) => modCounts(String(file).split(/[\\/]/).pop().replace(/\.jsonl$/, ""), day) ?? codexLive(file, day); // 0.10.16: a Codex rollout's own
243
243
  const { stackOfFiles = () => [], displayStackOfFiles = () => [] } = (await import("./stack-rules.mjs").catch(() => null)) ?? {}; // 0.10.11: core's stack rules and the display-only keys (tools_seen), generated (build-stack-rules --check); absent → nothing named, never a guess
244
244
  const EXPORT_PATHS = []; for (let i = 0; i < args.length; i += 1) if (args[i] === "--export" && args[i + 1]) EXPORT_PATHS.push(args[i + 1]);
245
- const DATABASE_CLIENTS = ["hermes", "goose", "opencode", "openclaw", "cursor", "copilot"]; // the registry's keys, the name each line carries
245
+ const DATABASE_CLIENTS = ["hermes", "goose", "opencode", "openclaw", "cursor", "copilot", "gemini-cli"]; // the registry's keys, the name each line carries (0.10.35: Gemini CLI)
246
246
  const LIVE_SOURCE = new RegExp(`^(codex|antigravity|${DATABASE_CLIENTS.join("|")}):`); // a sweep entry's id → the client it names (every database client, 0.6.16)
247
247
  const READER_FILES = ["history-outbox.mjs", "transcript-readers.mjs", "session-databases.mjs", "stretch-evidence.mjs", "chat-exports.mjs", "stack-rules.mjs", "claude-mod.mjs"]; // 0.7.4: the derived record travels with the hook; 0.10.10: the export reader; 0.10.11: the stack rules; 0.10.15: the mod
248
248
  /** The roots this machine's transcripts live under; a test names its own. */
@@ -802,7 +802,7 @@ function callOutcomesOf(messages) {
802
802
  /** A digest of this hook and the readers beside it, as installed: the door records it beside each line as a signal of which code ran, never as proof. */
803
803
  const selfDigest = (() => { try { const here = dirname(fileURLToPath(import.meta.url)); const hash = createHash("sha256"); for (const name of ["log-session.mjs", ...READER_FILES].sort()) { try { hash.update(`${name}\0`).update(readFileSync(join(here, name))).update("\0"); } catch { hash.update(`${name}\0missing\0`); } } return hash.digest("hex"); } catch { return null; } })();
804
804
  const CLI_VERSION_SENT = /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,4}$/.test(process.env.WORKTRUST_CLI_VERSION ?? "") ? process.env.WORKTRUST_CLI_VERSION : null; // `worktrust.mjs` hands its own version to the hook it starts
805
-
805
+ const DOOR_MODE_SENT = CLI_VERSION_SENT && /^(hours_only|work_lines)(\.[0-9]{9,11})?$/.test(process.env.WORKTRUST_DOOR_MODE ?? "") ? process.env.WORKTRUST_DOOR_MODE : null; // 0.10.37: `mcp off|on`, a closed word and its moment beside the version
806
806
  /**
807
807
  * THE TOKENS, AND THE CACHE HALVES APART (roadmap 16). Claude Code's usage block carries input_tokens, output_tokens,
808
808
  * cache_creation_input_tokens and cache_read_input_tokens. `tokensIn` stays what it was — new input plus what was written
@@ -919,13 +919,11 @@ function payloadFor(stretch) {
919
919
  * adding a twin. Returns how many entries were accepted, so a caller can advance a watermark over
920
920
  * exactly what landed. `announce` because one caller is a person watching a terminal and the other
921
921
  * is a hook holding a session's exit open.
922
- */
923
- /**
922
+ *
924
923
  * THE BATCHES: at most two hundred lines each. `byDay` (an export, 2026-10-10) never splits a UTC day across two batches unless
925
924
  * one day alone exceeds the cap: the door's receipt counts per day what it replaced and how many AI-app lines lie there, and a
926
925
  * day in two batches would be counted twice.
927
- */
928
- /**
926
+ *
929
927
  * A batch stays under the door's ceilings for one history call (2026-10-23, docs/INTAKE-HARDENING.md): 2 MB a call and 1.5 MB of
930
928
  * timelines a call, each with room for the envelope. A timeline (0.10.20) is up to 200 KB a line, so a batch is cut by bytes
931
929
  * and by timeline bytes as well as by count. Until 0.10.28 the cut was 3.5 MB, under the door's 4.5 MB outer bound only.
@@ -957,11 +955,11 @@ function batchesOf(group, byDay, limit = BATCH_LIMIT) {
957
955
  }
958
956
  /** THE RECEIPTS' COUNTS (2026-10-10): what an export send replaced, how many AI-app lines lie on its days, how many were withdrawn; summed over the batches, read for the counts alone. */
959
957
  const RECEIPTS = { new: 0, alreadyHeld: 0, filled: 0, replaced: 0, superseded: 0, recut: 0, unknownOnDays: 0, unknownWithdrawn: 0, corrected: 0, measuredSeconds: 0, staged: 0, kept: 0, restored: 0, untimed: 0 }; // 0.10.27: staged, the batches WorkTrust keeps on its server, and kept, their lines // 0.10.20: measuredSeconds is WorkTrust's own figure for what the batch stored, the one the terminal shows // 0.10.17: recut, the one-envelope export lines its runs replaced // 2026-10-10: and what a re-measure did (new, held, filled, replaced), so the command can say it
960
- const noteReceipt = (answer) => {
958
+ const noteReceipt = (answer, run = null) => {
961
959
  try {
962
960
  const json = JSON.parse(answer.trim().startsWith("{") ? answer : answer.split("\n").find((row) => row.startsWith("data:"))?.slice(5) ?? "null");
963
961
  const receipt = JSON.parse(json?.result?.content?.[0]?.text ?? "{}");
964
- for (const key of Object.keys(RECEIPTS)) RECEIPTS[key] += Number(receipt[key]) || 0;
962
+ for (const key of Object.keys(RECEIPTS)) RECEIPTS[key] += Number(receipt[key]) || 0; if (receipt.staged === true) RUNS.heard(run, receipt);
965
963
  // THE QUEUE (0.10.32): the receipt of the batch that completes a run says where the run waits; the last one seen is kept.
966
964
  const queued = receipt.queued;
967
965
  if (queued && Number.isInteger(queued.position) && queued.position >= 1 && Number.isFinite(Number(queued.eta_minutes)) && Number(queued.eta_minutes) >= 0) QUEUED.at = { position: queued.position, eta_minutes: Math.max(1, Math.ceil(Number(queued.eta_minutes))) };
@@ -969,6 +967,7 @@ const noteReceipt = (answer) => {
969
967
  };
970
968
  /** Where the last completed run waits in WorkTrust's queue (0.10.32): null when no receipt said so (an older server, or not complete yet). */
971
969
  const QUEUED = { at: null };
970
+ const RUNS = (await import("./history-outbox.mjs").then((m) => m.runLedger?.(), () => null)) ?? { heard() {}, held() {}, refused() {}, state: () => null }; // A RUN IS DONE WHEN WORKTRUST HOLDS ALL OF IT (2026-10-31): each run's declared batches against the receipts; a copy without the outbox (preserve) sends no run
972
971
  /** Only explicit durable receipts authorize a checkpoint. HTTP 200 alone says nothing. */
973
972
  function confirmedReceipt(answer, expectedCount = null) {
974
973
  try {
@@ -1158,7 +1157,7 @@ async function sendHistory(door, entries, announce = false, rebuild = false, nam
1158
1157
  const handLater = (item) => { const row = later.get(item.target.token) ?? { target: item.target, ids: [] }; row.ids.push(historyIdOf(item.target, item.body, item.source)); later.set(item.target.token, row); };
1159
1158
  for (const item of plan) {
1160
1159
  const { source, target, batch, body } = item;
1161
- if (stopped.has(source)) continue;
1160
+ if (stopped.has(source)) { HISTORY_DELIVERY.waiting += batch.length; continue; } // 2026-10-31: held back behind its AI app's failed batch, waiting in the outbox, and said
1162
1161
  if (item.run && stoppedRuns.has(item.run.id)) { handLater(item); continue; }
1163
1162
  const number = (numbers.get(source) ?? 0) + 1; numbers.set(source, number);
1164
1163
  for (const entry of batch) retainMeasurement(entry, source);
@@ -1166,7 +1165,8 @@ async function sendHistory(door, entries, announce = false, rebuild = false, nam
1166
1165
  let queued;
1167
1166
  try { queued = queuedHistory(target, body, source); }
1168
1167
  catch { console.error("Pending history could not be stored safely. Nothing was marked complete; keep the local WorkTrust folder for recovery."); HISTORY_DELIVERY.waiting += batch.length; stopped.add(source); continue; }
1169
- if (queued.status === "acknowledged" && !byDay) { accepted += batch.length; RECEIPTS.alreadyHeld += batch.length; continue; }
1168
+ if (queued.status === "closed") { HISTORY_DELIVERY.refused += batch.length; RUNS.refused(item.run); continue; } // 2026-10-31: let go on an earlier send is refused, never "already held"
1169
+ if (queued.status === "acknowledged" && !byDay) { accepted += batch.length; RECEIPTS.alreadyHeld += batch.length; RUNS.held(item.run); continue; }
1170
1170
  if (queued.status === "replaced" || queued.status === "oversize") { handLater(item); if (item.run) stoppedRuns.add(item.run.id); continue; }
1171
1171
  if (queued.status === "review" && !flag("retry-review")) { HISTORY_DELIVERY.review += batch.length; continue; }
1172
1172
  if (queued.status === "waiting") { HISTORY_DELIVERY.waiting += batch.length; continue; }
@@ -1177,21 +1177,21 @@ async function sendHistory(door, entries, announce = false, rebuild = false, nam
1177
1177
  catch {
1178
1178
  const refusal = historyRefusal(text, response);
1179
1179
  // A run WorkTrust closed (seven days without its last batch, another computer's key) is final: kept here it would wait forever.
1180
- if (refusal.reason === "closed") { queued.close(); HISTORY_DELIVERY.refused += batch.length; continue; }
1180
+ if (refusal.reason === "closed") { queued.close(); HISTORY_DELIVERY.refused += batch.length; if (refusal.said) HISTORY_DELIVERY.said = refusal.said; RUNS.refused(item.run); continue; }
1181
1181
  if (refusal.reason === "oversize") { queued.oversize(); handLater(item); if (item.run) stoppedRuns.add(item.run.id); continue; }
1182
1182
  queued.defer(refusal.reason, refusal.seconds);
1183
1183
  if (refusal.reason === "review") { HISTORY_DELIVERY.review += batch.length; continue; }
1184
1184
  HISTORY_DELIVERY.waiting += batch.length; stopped.add(source); continue;
1185
1185
  }
1186
- queued.confirm(batch.length); accepted += batch.length; noteReceipt(text);
1186
+ queued.confirm(batch.length); accepted += batch.length; noteReceipt(text, item.run);
1187
1187
  if (announce) console.log(`batch ${number}: received ${batch.length}`);
1188
1188
  } catch { queued.defer("unconfirmed"); HISTORY_DELIVERY.waiting += batch.length; stopped.add(source); }
1189
1189
  }
1190
1190
  for (const { target, ids } of later.values()) {
1191
1191
  try {
1192
- const totals = await resumeHistory(target, { only: ids, cutter: outboxCut, retryReview: flag("retry-review"), confirmed: confirmedReceipt, note: noteReceipt, send: sendQueued(target) });
1192
+ const totals = await resumeHistory(target, { only: ids, cutter: outboxCut, retryReview: flag("retry-review"), confirmed: confirmedReceipt, note: noteReceipt, closed: RUNS.refused, send: sendQueued(target) });
1193
1193
  accepted += totals.received + totals.held; RECEIPTS.alreadyHeld += totals.held;
1194
- HISTORY_DELIVERY.waiting += totals.waiting; HISTORY_DELIVERY.review += totals.review; HISTORY_DELIVERY.refused += totals.refused;
1194
+ HISTORY_DELIVERY.waiting += totals.waiting; HISTORY_DELIVERY.review += totals.review; HISTORY_DELIVERY.refused += totals.refused; if (totals.said) HISTORY_DELIVERY.said = totals.said;
1195
1195
  if (announce && totals.split) console.log(`${totals.split} batch${totals.split === 1 ? "" : "es"} too large for one call: cut smaller and sent again in pieces`);
1196
1196
  if (announce && totals.refused) console.log(`${totals.refused} line${totals.refused === 1 ? "" : "s"} could not be sent in a call WorkTrust takes; the earlier lines keep counting. Run npx worktrust@latest history again to measure them anew.`);
1197
1197
  } catch { console.error("Pending history could not be read safely. Nothing was marked complete; keep the local WorkTrust folder for recovery."); }
@@ -1215,7 +1215,7 @@ async function resendPending(limit) {
1215
1215
  } catch (error) { if (process.env.WORKTRUST_HOOK_DEBUG) console.error(`worktrust: ${error.message}`); }
1216
1216
  }
1217
1217
 
1218
- /** Whether the door's import_history takes `from_archive` (0.8.0): asked with tools/list, never assumed. */
1218
+ /** Whether the door's import_history takes `from_archive` (0.8.0), asked with tools/list; a door that no longer LISTS import_history to a computer's key (2026-10-31) is one that takes it. */
1219
1219
  async function doorKnowsArchive(target) {
1220
1220
  if (!target) return false;
1221
1221
  try {
@@ -1224,7 +1224,7 @@ async function doorKnowsArchive(target) {
1224
1224
  const text = await response.text();
1225
1225
  const json = JSON.parse(text.trim().startsWith("{") ? text : text.split("\n").find((row) => row.startsWith("data:"))?.slice(5) ?? "null");
1226
1226
  const tool = json?.result?.tools?.find((one) => one.name === "import_history");
1227
- return Boolean(tool?.inputSchema?.properties?.entries?.items?.properties?.from_archive);
1227
+ return tool ? Boolean(tool.inputSchema?.properties?.entries?.items?.properties?.from_archive) : Array.isArray(json?.result?.tools) && json.result.tools.some((one) => one.name === "log_work");
1228
1228
  } catch { return false; }
1229
1229
  }
1230
1230
 
@@ -1242,7 +1242,7 @@ const proofFor = (url, body) => {
1242
1242
  * on this computer, and the door names a coupling's clients by the user-agent it hears (mcp_identify's
1243
1243
  * agents_seen). An Antigravity line names Antigravity: the product name, nothing of the work.
1244
1244
  */
1245
- const clientOf = (source, always = false) => (CLI_VERSION_SENT || always || source === "antigravity" || DATABASE_CLIENTS.includes(source) || EXPORT_CLIENTS.includes(source) ? { "user-agent": `${source ?? "claude"}/hook (worktrust-hook)${CLI_VERSION_SENT ? ` worktrust-cli/${CLI_VERSION_SENT}` : ""}` } : {});
1245
+ const clientOf = (source, always = false) => (CLI_VERSION_SENT || always || source === "antigravity" || DATABASE_CLIENTS.includes(source) || EXPORT_CLIENTS.includes(source) ? { "user-agent": `${source ?? "claude"}/hook (worktrust-hook)${CLI_VERSION_SENT ? ` worktrust-cli/${CLI_VERSION_SENT}` : ""}${DOOR_MODE_SENT ? ` worktrust-mode/${DOOR_MODE_SENT}` : ""}` } : {});
1246
1246
 
1247
1247
  async function send(door, payload) {
1248
1248
  retainMeasurement(payload, entrySource.get(payload));
@@ -1421,7 +1421,10 @@ async function exportEntries() {
1421
1421
  }
1422
1422
  }
1423
1423
  const days = [...report.days].sort();
1424
- reports.push({ path: read.path, vendor: read.vendor, digest: read.digest, conversations: read.conversations, days: days.length, first: days[0] ?? null, last: days.at(-1) ?? null, oversized: read.oversized }); // no hours (0.10.20): WorkTrust computes them on arrival and the receipt says
1424
+ // A DOWNLOAD CUT OFF (2026-10-31): the reader read the conversations parts the archive held whole before the cut, and says
1425
+ // where it stopped; the person is told every time, so a partial export is never shown as the whole (counts and part names only).
1426
+ for (const cut of read.cut ?? []) process.stderr.write(`export: the archive is cut off (${cut.where}) after ${cut.last}: ${cut.parts} conversations part${cut.parts === 1 ? "" : "s"} read whole, ${read.conversations} conversations; nothing past the cut is read, so this is not the whole export\n`);
1427
+ reports.push({ path: read.path, vendor: read.vendor, digest: read.digest, conversations: read.conversations, days: days.length, first: days[0] ?? null, last: days.at(-1) ?? null, oversized: read.oversized, ...(read.empty ? { empty: read.empty } : {}), ...(read.cut ? { parts: read.parts, cut: read.cut } : {}) }); // no hours (0.10.20): WorkTrust computes them on arrival and the receipt says
1425
1428
  }
1426
1429
  const seen = new Set();
1427
1430
  return { entries: entries.filter((entry) => !seen.has(entry.stretch_ref) && seen.add(entry.stretch_ref)).sort((a, b) => a.at.localeCompare(b.at)), reports };
@@ -1749,9 +1752,9 @@ if (flag("history")) {
1749
1752
  return await exitFlushed(0);
1750
1753
  }
1751
1754
  // ONLY THE DAYS THAT CHANGED (0.10.32): a re-measure of this computer's own sessions asks the door first; an export, a copied
1752
- // folder and a plain history never do. Not known is every day.
1755
+ // folder and a plain history never do. Not known is every day. `--force-days` (0.10.35) asks nothing and sends every day of every AI app again.
1753
1756
  const staged = flag("rebuild") && !fromExports && !fromFolder;
1754
- const sending = staged ? await changedOnly(entries) : entries;
1757
+ const sending = staged && !flag("force-days") ? await changedOnly(entries) : entries; // FORCED (0.10.35; owner, 2026-10-30): the lines WorkTrust holds without their app, named; every app at once, so a day loses no app's line
1755
1758
  if (staged && COMPARED.asked && COMPARED.days > COMPARED.changed) console.log(sending.length === 0 ? `nothing changed: WorkTrust holds all ${COMPARED.days} days as this computer measures them` : `${COMPARED.days - COMPARED.changed} of ${COMPARED.days} days unchanged on WorkTrust; sending the ${COMPARED.changed} that changed`);
1756
1759
  // A batch the door refused is a failure the caller must see, not a quiet zero.
1757
1760
  const accepted = sending.length === 0 ? 0 : await sendHistory(door, sending, true, flag("rebuild"), Boolean(fromFolder), fromExports ? { byDay: true, withdrawUnknown: flag("withdraw-unknown") } : {});
@@ -1759,8 +1762,8 @@ if (flag("history")) {
1759
1762
  if (fromExports && accepted === entries.length) for (const report of fromExports.reports) rememberExport(report.digest, { vendor: report.vendor, sent: true, at: new Date().toISOString(), conversations: report.conversations });
1760
1763
  // ONE LINE FOR THE COMMAND TO ASK WITH (2026-10-10): what the door replaced, how many AI-app lines lie on the export's days, how many it withdrew.
1761
1764
  if (!fromExports && !fromFolder) await settleReadFailures(door ?? codexDoor); // 0.10.32: a transcript that could not be read is counted and told
1762
- if (fromExports) console.log(JSON.stringify({ export_sent: accepted, of: entries.length, ...RECEIPTS })); else console.log(JSON.stringify({ history_sent: accepted, of: sending.length, unreadable: READ_FAILURES.n, ...RECEIPTS, delivery: HISTORY_DELIVERY, ...(staged ? { days: { compared: COMPARED.asked ? COMPARED.days : null, changed: COMPARED.asked ? COMPARED.changed : null }, queued: QUEUED.at } : {}) })); // the same line for a history send: what the door did with it, and WorkTrust's measuredSeconds for what it stored
1763
- return await exitFlushed(accepted === sending.length ? 0 : 1);
1765
+ if (fromExports) console.log(JSON.stringify({ export_sent: accepted, of: entries.length, ...RECEIPTS })); else console.log(JSON.stringify({ history_sent: accepted, of: sending.length, unreadable: READ_FAILURES.n, ...RECEIPTS, delivery: HISTORY_DELIVERY, ...(staged ? { days: { compared: COMPARED.asked ? COMPARED.days : null, changed: COMPARED.asked ? COMPARED.changed : null }, queued: QUEUED.at, run: RUNS.state() } : {}) })); // the same line for a history send: what the door did with it, and WorkTrust's measuredSeconds for what it stored
1766
+ return await exitFlushed(accepted === sending.length && RUNS.state()?.whole !== false ? 0 : 1); // 2026-10-31: a run WorkTrust does not hold whole fails too
1764
1767
  }
1765
1768
 
1766
1769
  const input = hookInput();
@@ -1 +1 @@
1
- {"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"AGENTS.md":"c6f5280c5bf81a14db4bdc282218fb005706e92dd9a9170c0e727716ee91685a","CLAUDE.md":"5933504f93e5a40369a4790e96dd5dad791d849d3178b1833eb64088e456aaeb","LICENSE":"3096ed1693974a90e1f4f59bf01c9559d94a7941d933e36fb81d3995a97f25c1","README.md":"4f2ea9b41f90fbdc478fa1f461e4f34d8c67c847ec5bec983f809bd49897fdc7","SECURITY.md":"b672649c7c7bf18538dd4560d7b533498721e0be765a000796d7d18390b5cbb6","chat-exports.mjs":"04eafe333940ec03d5058d8d51062124aa12ab882bf04db03bcda5613ec69298","claude-mod.mjs":"02d86b0cdddf39879efc5194c0a5be6b41456faedec28963dc123a4e88dc3942","commit-rules.mjs":"e94cc32a5415f6d9e978145ab9505ac4ae0bac9431e6e9104b9b37155260b51f","config-edits.mjs":"0eba2f176ef6f7afba071d6e00de0ff19ba2b283180a801dfd957aa38c1edd94","count-behaviour.mjs":"1beaec2a4d0aead76d166f89cc52441a9cf48f2e69da9888ca2091dd3a10a37b","credential-store.mjs":"a4b3540a61f4ce19e535c7f1d260c0d817686cd066d559a76db2ab108144abba","credential-vault-scripts.mjs":"7e42fe1db3885c2dec6f1de87bebfbefe2292d29179a68f3da87d19eb6c7704b","credential-vault.mjs":"279baabb217e2a3f170e8d7f2b271a88484531f9031c441360ea91561a70da99","engine-release.json":"613734a8d130c4dbd512faf6ee53e29f9892a2cbc92173598411ec28c8bc6ebe","git-commits.mjs":"f9c084c54937a86df8fe30a0db2a58e04eeef0dbae69c54b8e368efc9964d6d8","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":"427be6e3e70086bc3484bcde258447d393d11bf4088298db786a024a4ae7469b","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":"dd947a3de77a3db3f17c7027f16a2e5a2da1001ed954808614e20eb871691e6b"},"format":"worktrust-package/1","kind":"npm","version":"0.10.34"},"signature":"NBifKfprOGRr5AeZSTgwwIhcyGtTuQCYYWQGAOZFZ8y3Uk700xdJlJ4x_lffCNmh-ANZZo2qliuUQrw8iO50AQ"}
1
+ {"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"AGENTS.md":"c6f5280c5bf81a14db4bdc282218fb005706e92dd9a9170c0e727716ee91685a","CLAUDE.md":"5933504f93e5a40369a4790e96dd5dad791d849d3178b1833eb64088e456aaeb","LICENSE":"3096ed1693974a90e1f4f59bf01c9559d94a7941d933e36fb81d3995a97f25c1","README.md":"65f5597520d3add8f021ee68f39cbc29bae59744da46e89d641cf7fb4474f541","SECURITY.md":"b672649c7c7bf18538dd4560d7b533498721e0be765a000796d7d18390b5cbb6","chat-exports.mjs":"bda43095a62bab608fc9309f9e7a2232dc10b29c514fb34e1aae357daa132737","claude-mod.mjs":"02d86b0cdddf39879efc5194c0a5be6b41456faedec28963dc123a4e88dc3942","commit-rules.mjs":"e94cc32a5415f6d9e978145ab9505ac4ae0bac9431e6e9104b9b37155260b51f","config-edits.mjs":"0eba2f176ef6f7afba071d6e00de0ff19ba2b283180a801dfd957aa38c1edd94","count-behaviour.mjs":"179baf829eda488bab3f17ae6917473ec01d0d6346f47de7bc144351274f19c8","credential-store.mjs":"a4b3540a61f4ce19e535c7f1d260c0d817686cd066d559a76db2ab108144abba","credential-vault-scripts.mjs":"7e42fe1db3885c2dec6f1de87bebfbefe2292d29179a68f3da87d19eb6c7704b","credential-vault.mjs":"279baabb217e2a3f170e8d7f2b271a88484531f9031c441360ea91561a70da99","engine-release.json":"5d0bc51d24750c8ea15423f5625a8e27cfe352c88fe17c623ef0fc5f59bca2da","git-commits.mjs":"f9c084c54937a86df8fe30a0db2a58e04eeef0dbae69c54b8e368efc9964d6d8","history-outbox.mjs":"31609392f4e13dd37678ab3154bd2896cce1a8cca4903b78dd2d96da82b1f406","log-session.mjs":"9c78cadbc469f273367a438721fcc47ce101dc230b6c9a18fe0923960f471bc9","orchestration-contract.mjs":"ec08f303a166365b99e70b675de4cfe76c6156c2567e14b5569f6d992f0231b7","orchestration-evidence.mjs":"d0d06cecf0eb08e5c6e653c62a4f45b1eddf2119c2acb8341056b34f488d214a","orchestration-report.mjs":"d4e0a9ad8e4a01b462d22c6b1866aac291565c533ff476085d3367cb6d59bc1b","package-integrity.mjs":"a8210c9494a56bfb9a5ea3d10064c7a269f0b6330c0af7c0700e706c3c0224e3","package.json":"bb2bac211ec7f12913d860beb8a7b7733f926a361d575733951b0140f0409dec","preserve-lines.mjs":"2df64a69687aa51219bf7b86b88d175cc50990fa29574b31897e41a9ebeecf43","preserve-summary.mjs":"137f781ed7021596a3f0ea67afcf2ab8616ac293f833dbb8f176e838e0ed8321","preserve.mjs":"3e369083ba43bcda2fa0622fd526aa64fcf8ad66e7b6e8f23821752c4d47ad27","runtime-install.mjs":"aab47b52c79d726ef428a24f982c648fa3f1c2dc2b574f633611d02924864e5f","session-databases.mjs":"b9fe20d7445205bdbf4cf2eaaf9cc770dad01e23d41e644b04930ca34e10426d","setup-mcp.mjs":"dcaa912b0e15a74ab3365aa62f345ba436510b958e9f5cdceddd57ffb99ef4b7","stack-rules.mjs":"b23c56e72ec56ba02b17ed895f869172d988c468a697e8d6026b0e268f61e489","stretch-evidence.mjs":"5f5667b92adf11b1a5a6330a0f26dd6db73d56fe60823d9a5246dab71d27d380","transcript-readers.mjs":"e9f20415c2b5d62a09f35a63075002ebd1da56edb32f242d52822d58ecbd8ac3","worktrust-launch.mjs":"84801bd29d472d48188c126b9ebe3989a3132b54e13cc4fe534ff7c383a294ee","worktrust.mjs":"ff83a783504950cba6f62cb14786e504db701be6c324a44c3fefac26628f516d"},"format":"worktrust-package/1","kind":"npm","version":"0.10.36"},"signature":"t6KO1vCVVWp2XvOnCv6p7PTsCXQIrf3TeOComgkM9ePryMwd0NoNjNfrLY0PrF0-8zG7DxnUdGsqpeIW4mxKAg"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "worktrust",
3
- "version": "0.10.34",
3
+ "version": "0.10.36",
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": {
@@ -12,7 +12,7 @@ import { readFileSync, readdirSync, statSync } from "node:fs";
12
12
  import * as zlib from "node:zlib"; // zstd since Node 22.15; older Node reads OpenClaw's uncompressed rows only
13
13
  import { homedir, platform } from "node:os";
14
14
  import { join } from "node:path";
15
- import { cleanModel, cursorCall, copilotCall } from "./transcript-readers.mjs";
15
+ import { cleanModel, cursorCall, copilotCall, geminiCall } from "./transcript-readers.mjs";
16
16
 
17
17
  // ── hermes session reader ──
18
18
  /**
@@ -450,6 +450,94 @@ export function copilotLines(pseudo) {
450
450
  }
451
451
  // ── end copilot session reader ──
452
452
 
453
+ // ── gemini-cli session reader ──
454
+ /**
455
+ * GEMINI CLI (0.10.35; owner, 2026-10-30). Gemini CLI records every chat itself (ChatRecordingService,
456
+ * google-gemini/gemini-cli packages/core/src/services/chatRecordingService.ts and config/storage.ts, read 2026-10-30): one
457
+ * file per session under `<global temp dir>/<project id>/chats/`, the global temp dir `~/.gemini/tmp`; the file is
458
+ * `session-<YYYY-MM-DDTHH-MM>-<8 characters of the session id>.jsonl`, a record per line, or a whole `.json`
459
+ * ConversationRecord from before the JSONL form. A subagent's session is a folder under its parent's
460
+ * (`chats/<parent id>/<id>.jsonl`): its time lies inside its parent's and it is not read. The records are replayed as
461
+ * Gemini CLI's own loader does: the first line the session's metadata; a message (`id`, `timestamp`, `type` user | gemini |
462
+ * info | error | warning) re-appended whole when its tokens or tool calls arrive, the last one per id kept; `$rewindTo`
463
+ * drops that message and everything after it; `$patch` may remove or reorder messages; `$set` merges metadata (an old
464
+ * `messages` in it replaces them all). Read for clocks and counts only: a `user` message is the person's turn; a `gemini`
465
+ * message the model's, with its `model` and its tokens (`input` the prompt, of which `cached` came from the cache, `output`,
466
+ * `thoughts`, `tool`); each tool call its name, status and clock (a shell command's line for the CLI to name a kind of,
467
+ * never kept). The `content`, the thoughts, `displayContent`, the tool calls' other arguments and results, `summary` and
468
+ * `directories` are parsed with the line and never kept. The project folder is not read (its directory under tmp is Gemini
469
+ * CLI's own short id, and a path never leaves): these lines name no repository.
470
+ * NOT VERIFIED on a real install here: the paths and records are read from Gemini CLI's source; the tests run on fixtures
471
+ * of that shape.
472
+ */
473
+ export function geminiHomes(given) { return given ? [given.replace(/^~(?=\/|$)/, homedir())] : [join(homedir(), ".gemini")]; }
474
+ export function* geminiSessions(homes) {
475
+ for (const home of homes) {
476
+ let projects = []; try { projects = readdirSync(join(home, "tmp")); } catch { continue; }
477
+ for (const project of projects.sort()) {
478
+ const dir = join(home, "tmp", project, "chats");
479
+ let names = []; try { names = readdirSync(dir); } catch { continue; }
480
+ for (const name of names.sort()) {
481
+ if (!/^session-.*\.jsonl?$/.test(name)) continue;
482
+ // A session migrated to .jsonl may leave its .json beside it: the .jsonl is the session.
483
+ if (name.endsWith(".json") && names.includes(`${name}l`)) continue;
484
+ const id = name.replace(/\.jsonl?$/, "");
485
+ if (!/^[A-Za-z0-9_.:-]{1,120}$/.test(id)) continue;
486
+ let writtenAt = 0; try { const st = statSync(join(dir, name)); if (!st.isFile()) continue; writtenAt = st.mtimeMs; } catch { continue; }
487
+ yield { sessionId: id, file: `gemini-cli:${join(dir, name)}#${id}`, cwd: null, writtenAt };
488
+ }
489
+ }
490
+ }
491
+ }
492
+ /** A session file back into its messages, in order: the JSONL records replayed (the loader's rules), or the old whole file. */
493
+ function geminiMessages(text, jsonl) {
494
+ if (!jsonl) { const whole = JSON.parse(text); return Array.isArray(whole?.messages) ? whole.messages : []; }
495
+ let messages = new Map();
496
+ for (const raw of text.split("\n")) {
497
+ if (!raw.trim()) continue;
498
+ let record; try { record = JSON.parse(raw); } catch { continue; }
499
+ if (!record || typeof record !== "object") continue;
500
+ if (typeof record.$rewindTo === "string") {
501
+ const ids = [...messages.keys()], at = ids.indexOf(record.$rewindTo);
502
+ messages = new Map(at < 0 ? [] : ids.slice(0, at).map((id) => [id, messages.get(id)]));
503
+ continue;
504
+ }
505
+ if (record.$patch && typeof record.$patch === "object") {
506
+ for (const id of Array.isArray(record.$patch.removeIds) ? record.$patch.removeIds : []) messages.delete(id);
507
+ if (Array.isArray(record.$patch.orderIds)) { const order = record.$patch.orderIds.filter((id) => messages.has(id)); messages = new Map([...order, ...[...messages.keys()].filter((id) => !order.includes(id))].map((id) => [id, messages.get(id)])); }
508
+ continue;
509
+ }
510
+ if (record.$set && typeof record.$set === "object") { if (Array.isArray(record.$set.messages)) messages = new Map(record.$set.messages.filter((m) => typeof m?.id === "string").map((m) => [m.id, m])); continue; }
511
+ if (typeof record.id === "string" && typeof record.type === "string") messages.set(record.id, record);
512
+ }
513
+ return [...messages.values()];
514
+ }
515
+ export function geminiLines(pseudo) {
516
+ const { file } = splitSession(pseudo);
517
+ let messages; try { messages = geminiMessages(readFileSync(file, "utf8"), file.endsWith(".jsonl")); } catch { return null; }
518
+ const lines = [];
519
+ const count = (value) => (Number.isFinite(Number(value)) && Number(value) > 0 ? Math.round(Number(value)) : 0);
520
+ for (const message of messages) {
521
+ const timestamp = isoOf(message?.timestamp); if (!timestamp) continue;
522
+ if (message.type === "user") { lines.push({ type: "user", timestamp, message: { content: [{ type: "text" }] } }); continue; }
523
+ if (message.type !== "gemini") continue;
524
+ // The prompt's count holds what the cache served: new input is the rest (and the tool-use prompt), the cache read apart;
525
+ // a thought is output, as every other reader counts reasoning.
526
+ const t = message.tokens && typeof message.tokens === "object" ? message.tokens : null;
527
+ const usage = t ? { usage: { input_tokens: Math.max(0, count(t.input) - count(t.cached)) + count(t.tool), output_tokens: count(t.output) + count(t.thoughts), cache_read_input_tokens: count(t.cached), cache_creation_input_tokens: 0 } } : {};
528
+ for (const raw of Array.isArray(message.toolCalls) ? message.toolCalls : []) {
529
+ const call = geminiCall(raw), at = isoOf(raw?.timestamp) ?? timestamp;
530
+ if (!call) continue;
531
+ lines.push({ type: "assistant", timestamp: at, message: { content: [call.use] } });
532
+ lines.push({ type: "user", timestamp: at, message: { content: [call.result] } });
533
+ }
534
+ lines.push({ type: "assistant", timestamp, message: { model: cleanModel(message.model), ...usage, content: [] } });
535
+ }
536
+ // Each line at its own clock: a tool call's moment may fall before or after the message that carries it.
537
+ return lines.map((line, at) => ({ line, at })).sort((a, b) => Date.parse(a.line.timestamp) - Date.parse(b.line.timestamp) || a.at - b.at).map(({ line }) => line);
538
+ }
539
+ // ── end gemini-cli session reader ──
540
+
453
541
  // ── database clients ──
454
542
  /** The clients whose sessions live in a database, one registry: the hook and the counter ask it, not each client. */
455
543
  const DATABASE_CLIENTS = {
@@ -459,6 +547,7 @@ const DATABASE_CLIENTS = {
459
547
  openclaw: { homes: openclawHomes, sessions: openclawSessions, lines: openclawLines },
460
548
  cursor: { homes: cursorHomes, sessions: cursorSessions, lines: cursorLines },
461
549
  copilot: { homes: copilotHomes, sessions: copilotSessions, lines: copilotLines },
550
+ "gemini-cli": { homes: geminiHomes, sessions: geminiSessions, lines: geminiLines },
462
551
  };
463
552
  export const DATABASE_SESSION = new RegExp(`^(${Object.keys(DATABASE_CLIENTS).join("|")}):.+#[A-Za-z0-9_.:-]{1,120}$`);
464
553
  /** Every attended session of every database client; `given` names a client's own home (a test), `onlyGiven` reads no other. */
package/setup-mcp.mjs CHANGED
@@ -260,7 +260,9 @@ for (const client of CLIENTS) {
260
260
  }
261
261
  const text = existsSync(client.file) ? readFileSync(client.file, "utf8") : "";
262
262
  // With the bridge, coupled means the bridge is in AND no entry with a key in it is left beside it.
263
- const already = client.shape === "yaml" && !REMOVE ? (BRIDGE !== undefined ? text.includes(JSON.stringify(BRIDGE)) && (!client.plugin || goosePluginStands()) : text.includes(URL_)) && yamlConfig(client, text, false) === text : REMOVE ? text.includes(URL_) || /worktrust(?:-launch)?\.(?:mjs|py)/.test(text) : BRIDGE !== undefined ? text.includes(JSON.stringify(BRIDGE).slice(1, -1)) && !text.includes(URL_) : text.includes(URL_);
263
+ // A TOML'S SERVER TABLES ONLY (2026-10-31): Codex's `notify` names the same launcher, and read as "already there" it left Codex doorless.
264
+ const doorText = client.shape === "toml" ? (text.match(/\n?\[mcp_servers\.[^\n]*\][\s\S]*?(?=\n\[|$)/g) ?? []).join("\n") : text;
265
+ const already = client.shape === "yaml" && !REMOVE ? (BRIDGE !== undefined ? text.includes(JSON.stringify(BRIDGE)) && (!client.plugin || goosePluginStands()) : text.includes(URL_)) && yamlConfig(client, text, false) === text : REMOVE ? doorText.includes(URL_) || /worktrust(?:-launch)?\.(?:mjs|py)/.test(doorText) : BRIDGE !== undefined ? doorText.includes(JSON.stringify(BRIDGE).slice(1, -1)) && !doorText.includes(URL_) : doorText.includes(URL_);
264
266
  // THE WAY OUT, ON THE MACHINE. Uncoupling in the app ends the TOKEN; the config that names the
265
267
  // door stays behind on every client here, so the next person to read this file believes the
266
268
  // machine is coupled. `--remove` takes the entry out; the account side is a separate act and
@@ -453,6 +453,20 @@ export function cursorCall(bubble) {
453
453
  * a kind of, never kept) with the exit code VS Code recorded; a missing exit code is unknown. Its to-do list is TodoWrite
454
454
  * (statuses only), its subagents are Agent. What a confirmation type means is not documented, so no refusal is read.
455
455
  */
456
+ /**
457
+ * A GEMINI CLI TOOL CALL AS THE STRETCH READS IT (0.10.35): its name mapped to the common one (a shell command is Bash, its
458
+ * to-do list TodoWrite), the command for the CLI to name a KIND of (never kept), the to-do statuses (never their text), and
459
+ * the status Gemini CLI recorded (`success`; `error` or `cancelled` a failure); any other status is unknown, never a pass.
460
+ */
461
+ const GEMINI_NAMES = { run_shell_command: "Bash", write_todos: "TodoWrite", replace: "Edit", write_file: "Write", read_file: "Read", read_many_files: "Read", search_file_content: "Grep", grep_search: "Grep", glob: "Glob", list_directory: "LS" };
462
+ export function geminiCall(call) {
463
+ const id = typeof call?.id === "string" && call.id ? call.id : null;
464
+ if (!id) return null;
465
+ const raw = String(call.name ?? "tool"), name = GEMINI_NAMES[raw] ?? raw, args = call.args && typeof call.args === "object" ? call.args : {};
466
+ const input = name === "Bash" ? { command: typeof args.command === "string" ? args.command : "" } : name === "TodoWrite" && Array.isArray(args.todos) ? { todos: args.todos.map((todo) => ({ status: todo?.status === "completed" ? "completed" : "pending" })) } : {};
467
+ const failed = call.status === "error" || call.status === "cancelled", known = failed || call.status === "success";
468
+ return { use: { type: "tool_use", id, name, input }, result: { type: "tool_result", tool_use_id: id, is_error: failed, ...(known ? {} : { outcome: "unknown" }), content: "" } };
469
+ }
456
470
  const COPILOT_NAMES = { run_in_terminal: "Bash", manage_todo_list: "TodoWrite", execution_subagent: "Agent", runSubagent: "Agent", copilot_replaceString: "Edit", copilot_createFile: "Write", copilot_readFile: "Read", copilot_findTextInFiles: "Grep", copilot_findFiles: "Glob" };
457
471
  export function copilotCall(part) {
458
472
  const id = typeof part.toolCallId === "string" && part.toolCallId ? part.toolCallId : null;