worktrust 0.10.34 → 0.10.35
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 +18 -0
- package/engine-release.json +1 -1
- package/history-outbox.mjs +5 -2
- package/log-session.mjs +5 -5
- package/package-release.json +1 -1
- package/package.json +1 -1
- package/session-databases.mjs +90 -1
- package/transcript-readers.mjs +14 -0
- package/worktrust.mjs +14 -4
package/README.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# worktrust
|
|
2
2
|
|
|
3
|
+
## 0.10.35: Gemini CLI read; every earlier line can name its AI app
|
|
4
|
+
|
|
5
|
+
Gemini CLI's sessions are read in place, as Copilot's are: the files Gemini CLI records itself under
|
|
6
|
+
`~/.gemini/tmp/<project>/chats/session-*.jsonl` (or an older `.json`), each message's role and clock, the model and
|
|
7
|
+
the token counts, and each tool call's name and status; the messages, the thoughts and the tool calls' arguments and
|
|
8
|
+
results are parsed with the file and never kept or sent. A subagent's session lies inside its parent's and is not
|
|
9
|
+
counted. The project folder is not read, so these lines name no repository. Their lines go as `gemini-cli`.
|
|
10
|
+
|
|
11
|
+
WorkTrust now records which AI app each line came from (Copilot in VS Code, Gemini CLI, Antigravity …), so its AI apps
|
|
12
|
+
table can give them their own rows. Lines measured before carry only their product ("Other apps"). The measure rules
|
|
13
|
+
go to 3: `update` offers the re-measure once, and it sends every day again; WorkTrust replaces only the lines of
|
|
14
|
+
"Other apps" and "App not recorded" that name no app, with the same counted seconds, and keeps every other line as it is.
|
|
15
|
+
`npx worktrust history --rebuild --force-days` does the same at any time: every day of every AI app, even the days
|
|
16
|
+
WorkTrust already holds unchanged (every app at once, so no day loses another app's line).
|
|
17
|
+
|
|
3
18
|
## 0.10.34: your own commits, measured on this computer (`npx worktrust git`)
|
|
4
19
|
|
|
5
20
|
GitHub shows an App that reads commits as "Read access to code", and has no narrower permission. `npx worktrust git`
|
|
@@ -254,6 +269,9 @@ yourself run a command that sends. See [Keep your history](#keep-your-history).
|
|
|
254
269
|
(asked, answered), its model and its token counts; the messages and responses are parsed with the file and never
|
|
255
270
|
kept or sent. Neither app runs a hook WorkTrust can give it, so the WorkTrust door, which both start when they
|
|
256
271
|
open, starts the session hook in the background, at most once an hour.
|
|
272
|
+
10. **Gemini CLI, read in place (0.10.35).** Its sessions are the files Gemini CLI records under
|
|
273
|
+
`~/.gemini/tmp/<project>/chats/`: each message's role and clock, the model, the token counts and each tool
|
|
274
|
+
call's name and status, never a message, a thought or a tool's output. Subagent sessions are not counted.
|
|
257
275
|
|
|
258
276
|
```
|
|
259
277
|
npx worktrust@latest history send this computer's earlier sessions later (asks first)
|
package/engine-release.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"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","git-commits.mjs":"f9c084c54937a86df8fe30a0db2a58e04eeef0dbae69c54b8e368efc9964d6d8","history-outbox.mjs":"
|
|
1
|
+
{"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"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","git-commits.mjs":"f9c084c54937a86df8fe30a0db2a58e04eeef0dbae69c54b8e368efc9964d6d8","history-outbox.mjs":"10cdcdcc595fbc3222e39b3d845a2ff16c0e7ae20eb43a2d2794e8c4d3a7353e","log-session.mjs":"378a2fd38f4eafd8820a85e4bc4490929ceed59c2711e5cfef6e01e2e195ad3d","orchestration-contract.mjs":"ec08f303a166365b99e70b675de4cfe76c6156c2567e14b5569f6d992f0231b7","orchestration-evidence.mjs":"d0d06cecf0eb08e5c6e653c62a4f45b1eddf2119c2acb8341056b34f488d214a","orchestration-report.mjs":"d4e0a9ad8e4a01b462d22c6b1866aac291565c533ff476085d3367cb6d59bc1b","package-integrity.mjs":"a8210c9494a56bfb9a5ea3d10064c7a269f0b6330c0af7c0700e706c3c0224e3","preserve-lines.mjs":"2df64a69687aa51219bf7b86b88d175cc50990fa29574b31897e41a9ebeecf43","preserve-summary.mjs":"137f781ed7021596a3f0ea67afcf2ab8616ac293f833dbb8f176e838e0ed8321","preserve.mjs":"3e369083ba43bcda2fa0622fd526aa64fcf8ad66e7b6e8f23821752c4d47ad27","runtime-install.mjs":"aab47b52c79d726ef428a24f982c648fa3f1c2dc2b574f633611d02924864e5f","session-databases.mjs":"b9fe20d7445205bdbf4cf2eaaf9cc770dad01e23d41e644b04930ca34e10426d","setup-mcp.mjs":"0c29113179561af1c1e9ff8b7a786e7240edf48a2244993e12335e5ee362c812","stack-rules.mjs":"b23c56e72ec56ba02b17ed895f869172d988c468a697e8d6026b0e268f61e489","stretch-evidence.mjs":"5f5667b92adf11b1a5a6330a0f26dd6db73d56fe60823d9a5246dab71d27d380","transcript-readers.mjs":"e9f20415c2b5d62a09f35a63075002ebd1da56edb32f242d52822d58ecbd8ac3","worktrust-launch.mjs":"84801bd29d472d48188c126b9ebe3989a3132b54e13cc4fe534ff7c383a294ee","worktrust.mjs":"2a3ea97efabb582ebdc78bcb772e78a5aae06c243a5092563c88904df93003b9"},"format":"worktrust-package/1","kind":"engine","version":"0.10.35"},"signature":"tLkEDhYff_g15GrDNcNOzZDW3Y4b0pKv4HAkh8GM59E5IitPsz0eCU-244_mTKubaLILtdTcp85ZU1k_VAeUAQ"}
|
package/history-outbox.mjs
CHANGED
|
@@ -73,7 +73,10 @@ export function historyRefusal(text,response) {
|
|
|
73
73
|
// A staged run WorkTrust closed or refused (0.10.27: another computer's key, seven days without its last batch) is final.
|
|
74
74
|
const closed=rpc?.id===1 && String(rpc?.error?.message??'').startsWith('history run refused:');
|
|
75
75
|
// 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
|
-
|
|
76
|
+
// THE SERVER'S OWN SENTENCE (0.10.35): a re-measure refused for older measure rules says why and the one command that helps;
|
|
77
|
+
// the CLI prints it instead of guessing (one line, control characters taken out, at most 400 characters).
|
|
78
|
+
const said=closed&&rpc?.error?.data?.reason==='measure_rules'?String(rpc.error.message).replace(/[\u0000-\u001f\u007f-\u009f]/g,' ').slice(0,400):null;
|
|
79
|
+
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
80
|
}
|
|
78
81
|
|
|
79
82
|
/** Explicit recovery, even after the AI client removed its source files. A changed account/key
|
|
@@ -151,7 +154,7 @@ export async function resumeHistory(target, {send, confirmed, note, retryReview=
|
|
|
151
154
|
try{if(!response.ok)throw Error();confirmed(text,item.entries.length);}
|
|
152
155
|
catch{
|
|
153
156
|
const refusal=historyRefusal(text,response);
|
|
154
|
-
if(refusal.reason==='closed'){queued.close();totals.refused+=item.entries.length;continue;}
|
|
157
|
+
if(refusal.reason==='closed'){queued.close();totals.refused+=item.entries.length;if(refusal.said)totals.said=refusal.said;continue;}
|
|
155
158
|
// 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
159
|
if(refusal.reason==='oversize'){queued.oversize();if(cutter){seen.delete(id);queue.unshift(id);}else totals.waiting+=item.entries.length;continue;}
|
|
157
160
|
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;
|
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. */
|
|
@@ -1177,7 +1177,7 @@ 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; 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; }
|
|
@@ -1191,7 +1191,7 @@ async function sendHistory(door, entries, announce = false, rebuild = false, nam
|
|
|
1191
1191
|
try {
|
|
1192
1192
|
const totals = await resumeHistory(target, { only: ids, cutter: outboxCut, retryReview: flag("retry-review"), confirmed: confirmedReceipt, note: noteReceipt, 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."); }
|
|
@@ -1749,9 +1749,9 @@ if (flag("history")) {
|
|
|
1749
1749
|
return await exitFlushed(0);
|
|
1750
1750
|
}
|
|
1751
1751
|
// 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.
|
|
1752
|
+
// 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
1753
|
const staged = flag("rebuild") && !fromExports && !fromFolder;
|
|
1754
|
-
const sending = staged ? await changedOnly(entries) : entries;
|
|
1754
|
+
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
1755
|
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
1756
|
// A batch the door refused is a failure the caller must see, not a quiet zero.
|
|
1757
1757
|
const accepted = sending.length === 0 ? 0 : await sendHistory(door, sending, true, flag("rebuild"), Boolean(fromFolder), fromExports ? { byDay: true, withdrawUnknown: flag("withdraw-unknown") } : {});
|
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":"9774f45499ba5fd3db19135ddd3c9606f0744db11556acf7a41100bd2c0bd9d4","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":"982e696f36761c655ab7696cf920bafac1ebe0c59d040b7219d510523fc346eb","git-commits.mjs":"f9c084c54937a86df8fe30a0db2a58e04eeef0dbae69c54b8e368efc9964d6d8","history-outbox.mjs":"10cdcdcc595fbc3222e39b3d845a2ff16c0e7ae20eb43a2d2794e8c4d3a7353e","log-session.mjs":"378a2fd38f4eafd8820a85e4bc4490929ceed59c2711e5cfef6e01e2e195ad3d","orchestration-contract.mjs":"ec08f303a166365b99e70b675de4cfe76c6156c2567e14b5569f6d992f0231b7","orchestration-evidence.mjs":"d0d06cecf0eb08e5c6e653c62a4f45b1eddf2119c2acb8341056b34f488d214a","orchestration-report.mjs":"d4e0a9ad8e4a01b462d22c6b1866aac291565c533ff476085d3367cb6d59bc1b","package-integrity.mjs":"a8210c9494a56bfb9a5ea3d10064c7a269f0b6330c0af7c0700e706c3c0224e3","package.json":"f357f15ad0a9bf85b82371dabccc20a15a38c040cc7cd1aad60e58fd7edfdca6","preserve-lines.mjs":"2df64a69687aa51219bf7b86b88d175cc50990fa29574b31897e41a9ebeecf43","preserve-summary.mjs":"137f781ed7021596a3f0ea67afcf2ab8616ac293f833dbb8f176e838e0ed8321","preserve.mjs":"3e369083ba43bcda2fa0622fd526aa64fcf8ad66e7b6e8f23821752c4d47ad27","runtime-install.mjs":"aab47b52c79d726ef428a24f982c648fa3f1c2dc2b574f633611d02924864e5f","session-databases.mjs":"b9fe20d7445205bdbf4cf2eaaf9cc770dad01e23d41e644b04930ca34e10426d","setup-mcp.mjs":"0c29113179561af1c1e9ff8b7a786e7240edf48a2244993e12335e5ee362c812","stack-rules.mjs":"b23c56e72ec56ba02b17ed895f869172d988c468a697e8d6026b0e268f61e489","stretch-evidence.mjs":"5f5667b92adf11b1a5a6330a0f26dd6db73d56fe60823d9a5246dab71d27d380","transcript-readers.mjs":"e9f20415c2b5d62a09f35a63075002ebd1da56edb32f242d52822d58ecbd8ac3","worktrust-launch.mjs":"84801bd29d472d48188c126b9ebe3989a3132b54e13cc4fe534ff7c383a294ee","worktrust.mjs":"2a3ea97efabb582ebdc78bcb772e78a5aae06c243a5092563c88904df93003b9"},"format":"worktrust-package/1","kind":"npm","version":"0.10.35"},"signature":"zBGC2wIWsTuBDq7bcmDRreaEYyxq59m78Cd8yfiLHx_s4gMOqj2ZMeXON5ePQgB_OhsB1Esf2JWLpR_xrGJyCQ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "worktrust",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.35",
|
|
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/session-databases.mjs
CHANGED
|
@@ -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/transcript-readers.mjs
CHANGED
|
@@ -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;
|
package/worktrust.mjs
CHANGED
|
@@ -76,7 +76,7 @@ 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.35";
|
|
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
|
|
@@ -90,12 +90,19 @@ const CLI_VERSION = "0.10.34";
|
|
|
90
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
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
92
|
* person a re-measure for nothing. New runs arrive folded from 0.10.33 on.
|
|
93
|
+
* 0.10.35 RAISES IT TO 3 (owner, 2026-10-30): a new READER, Gemini CLI's own session files, so a computer with Gemini CLI has
|
|
94
|
+
* days no earlier rules measured; and every line now names its AI app at the door (source_app, 20261031100000), which lines
|
|
95
|
+
* measured before carry only when re-measured. Raising is what earlier readers would have done had the number existed (it
|
|
96
|
+
* came with 0.10.31): `update` offers the re-measure once, its day digests change with the rules, so the re-measure sends
|
|
97
|
+
* every day again; WorkTrust replaces only the lines of the two buckets (other apps, app not recorded) that name no app
|
|
98
|
+
* (20261031100200) and carries every other line as it is: no figure moves, the Other apps hours move to their app's row.
|
|
93
99
|
*/
|
|
94
|
-
const MEASURE_RULES =
|
|
100
|
+
const MEASURE_RULES = 3;
|
|
95
101
|
/** What each measure-rules version changed, in the words the re-measure offer says (one entry per raise, never rewritten). */
|
|
96
102
|
const MEASURE_CHANGES = {
|
|
97
103
|
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
104
|
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"],
|
|
105
|
+
3: ["Gemini CLI's sessions", "which AI app each earlier line came from (Copilot in VS Code, Gemini CLI and the other apps get their own rows)"],
|
|
99
106
|
};
|
|
100
107
|
const ORIGIN = (flag("origin") ?? process.env.WORKTRUST_ORIGIN ?? "https://app.worktrust.io").replace(/\/$/, "");
|
|
101
108
|
const MCP = flag("url") ?? process.env.WORKTRUST_MCP_URL ?? `${ORIGIN}/api/mcp`;
|
|
@@ -799,7 +806,7 @@ async function offerHistory(paths, token, devicePem, url = MCP, rebuild = false,
|
|
|
799
806
|
if (!has("history") && !agreedInAdvance && !(rebuild ? await ask("Send them (re-measured; this computer's earlier lines for these days are replaced, a day is counted once)?", false) : await ask("Send these as history (hours and tokens per day; never text)?", false))) { historyDone(false); say(" Not sent. Send them later with: npx worktrust"); return; }
|
|
800
807
|
// Marked unfinished before the first batch leaves (0.10.9): a send stopped halfway (Ctrl+C, a closed lid) is finished by the next run.
|
|
801
808
|
historyDone(false);
|
|
802
|
-
const sent = await run(paths["log-session.mjs"], ["--history", ...(rebuild ? ["--rebuild"] : []), ...(has("retry-review") ? ["--retry-review"] : [])], token, true, env);
|
|
809
|
+
const sent = await run(paths["log-session.mjs"], ["--history", ...(rebuild ? ["--rebuild"] : []), ...(rebuild && has("force-days") ? ["--force-days"] : []), ...(has("retry-review") ? ["--retry-review"] : [])], token, true, env);
|
|
803
810
|
historyDone(sent.code === 0);
|
|
804
811
|
// WHAT ACTUALLY HAPPENED, FROM THE DOOR'S RECEIPTS (owner, 2026-10-10): a re-measure in which nothing changed must not say
|
|
805
812
|
// "replaced". The hook sums the receipts of every batch and prints one line; without it (an older hook) the sentence stays neutral.
|
|
@@ -823,7 +830,8 @@ async function offerHistory(paths, token, devicePem, url = MCP, rebuild = false,
|
|
|
823
830
|
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.`);
|
|
824
831
|
// 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.
|
|
825
832
|
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.");
|
|
826
|
-
|
|
833
|
+
// 0.10.35: a re-measure refused for older measure rules is told in WorkTrust's own words (the hook passes them on, cleaned).
|
|
834
|
+
if (Number(did?.delivery?.refused) > 0) say(typeof did.delivery.said === "string" ? ` ${did.delivery.said.replace(/[\u0000-\u001f\u007f-\u009f]/g, " ").slice(0, 400)}` : ` 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.`);
|
|
827
835
|
// 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.
|
|
828
836
|
if (rebuild && n(did?.staged) > 0 && !Number(did?.delivery?.review) && !Number(did?.delivery?.waiting)) {
|
|
829
837
|
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.`);
|
|
@@ -1376,6 +1384,8 @@ function help() {
|
|
|
1376
1384
|
say(" --retry-review explicitly retry held batches after support resolves their review");
|
|
1377
1385
|
say(" --rebuild re-measure them with the current rules; WorkTrust replaces this computer's earlier lines,");
|
|
1378
1386
|
say(" day by day, never counting a day twice (shows the plan per AI app, asks first; --dry-run: the plan only)");
|
|
1387
|
+
say(" --force-days with --rebuild: send every day again, also the days WorkTrust holds unchanged, so lines");
|
|
1388
|
+
say(" measured before an app was named per line get their app (every AI app at once)");
|
|
1379
1389
|
say(" --from-archive [dir] send what your archive (preserve --archive) holds of sessions your AI apps already deleted,");
|
|
1380
1390
|
say(" marked as from your archive: a day this computer's key signed as measured, every other day");
|
|
1381
1391
|
say(" as reconstructed, never verified hours (shows the plan, asks first)");
|