worktrust 0.10.9 → 0.10.11

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
@@ -85,7 +85,12 @@ npx worktrust@latest history send this computer's earlier sessions later (
85
85
  npx worktrust@latest history --rebuild re-measure them with the current rules; WorkTrust replaces this computer's
86
86
  earlier lines day by day, never counting a day twice (shows the plan, asks first)
87
87
  npx worktrust@latest history --from-archive [dir] send what your local archive holds of sessions your AI apps
88
- already deleted, marked as from your archive (shows the plan, asks first)
88
+ already deleted, marked as from your archive: a day this computer's key signed as
89
+ measured, every other day as reconstructed (shows the plan, asks first)
90
+ npx worktrust@latest history --export <path> a ChatGPT or Claude data export (the zip, its folder or conversations.json)
91
+ as history: hours reconstructed from its clocks, never verified (shows the plan, asks first)
92
+ npx worktrust@latest history --from-folder <dir> your own copy of an AI app's session folder (a backed-up ~/.claude/projects,
93
+ ~/.codex/sessions): the days this computer's sessions lack, reconstructed (asks first)
89
94
  npx worktrust codex let Codex wake the session hook (asks first)
90
95
  npx worktrust antigravity let Antigravity wake the session hook (asks first)
91
96
  npx worktrust@latest status what is coupled here
@@ -226,11 +231,12 @@ sent stand as they were measured then, and sending the sessions again would coun
226
231
  does not name its stretch, so WorkTrust cannot tell it from the one that arrives.
227
232
 
228
233
  `npx worktrust@latest history --from-archive` (0.8.0) is for the sessions an AI app has already deleted (Claude
229
- Code's default is 30 days). It sends what your local archive (`preserve --archive`) holds of them, and only that: days
230
- this computer signed with its own key, of sessions no longer on the computer, each line marked as coming from your
231
- archive. It refuses, and sends nothing, when the computer has no device key, when the archive does not verify, or when
232
- WorkTrust does not yet accept the mark. It shows the plan first and asks once; Enter is No. Such lines are history,
233
- like any import: never verified hours.
234
+ Code's default is 30 days). It sends what your local archive (`preserve --archive`) holds of them, and only that:
235
+ days of sessions no longer on the computer, each line marked as coming from your archive. One rule (2026-10-10):
236
+ a day signed by this computer's device key goes as it was measured; every other day (unsigned, signed by the local
237
+ archive key, or by another computer's key) goes as **reconstructed**, and the plan says how many of each. It refuses,
238
+ and sends nothing, when the archive does not verify or when WorkTrust does not yet accept the mark. It shows the plan
239
+ first and asks once; Enter is No. Such lines are history, like any import: never verified hours.
234
240
 
235
241
  `npx worktrust@latest history --rebuild` re-measures every session still on this computer with the current rules and
236
242
  sends them with one difference: WorkTrust **replaces** this computer's earlier lines, day by day.
@@ -254,6 +260,59 @@ sends them with one difference: WorkTrust **replaces** this computer's earlier l
254
260
  and the same version updated again offers nothing. The command cannot read your record, so it is an offer, not a
255
261
  finding.
256
262
 
263
+ ## A web chat's data export
264
+
265
+ `npx worktrust@latest history --export <path>` (0.10.10) brings a ChatGPT data export (Settings → Data controls →
266
+ Export data) or a Claude data export (Settings → Privacy → Export data) onto your record as history, so years of
267
+ browser chats appear with their months, days and rhythm. The path is the zip the vendor sent you, the folder it was
268
+ unpacked into, or `conversations.json` itself; the vendor is told by the file's shape. Of the zip only
269
+ `conversations.json` is opened: the profile, memories and files beside it are never inflated.
270
+
271
+ - **What goes.** Per conversation and day: a neutral line (`A conversation in ChatGPT`, `A conversation in Claude on
272
+ the web`), the seconds between the messages' clocks counted the way a measured day is (a pause over five minutes is
273
+ not work; a day is cut at eight hours), your own turns as a count, the model's name where the export carries one, when
274
+ it began and ended, and a stable name made of the conversation's id and the day, so the same export sent twice, or
275
+ from two computers, is each line once. Never a title, never a message, never tokens (the export carries none and none
276
+ are estimated).
277
+ - **What it counts as.** Hours **reconstructed**, shown on your record with their origin and never in your verified
278
+ hours: an export file can be edited before it is read, and no device key witnessed those hours. WorkTrust holds this
279
+ at the door and in the database, whatever the sender claims.
280
+ - **How it asks.** The plan first (the product, conversations, days, reconstructed hours, first and last month), then
281
+ one question; Enter is No; `--dry-run` shows the plan and stops. On a coupled computer the bare `npx worktrust` looks
282
+ in your Downloads folder (its top level only) for such an export it has not sent, offers it the same way, once, and
283
+ remembers your answer by the file's digest, never by a conversation.
284
+ - **The export replaces.** On the days the export covers, its lines count and the earlier lines of that product a
285
+ connector brought in (an AI signed in on the web, which selects what it reports) are withdrawn and kept, each with a
286
+ correction row, so a day counts once; the command says how many. A connector line that arrives later for a day the
287
+ export covers is held. Lines an AI app reported earlier under no product may describe the same conversations: the
288
+ command says how many lie on those days and asks once, `Also withdraw N earlier lines an AI app reported for these
289
+ days?`; Enter is No, `--yes` keeps No, `--dry-run` sends nothing, and only a typed yes or `--withdraw-unknown` said
290
+ in advance withdraws exactly those lines on exactly those days, the same way, never deleting. Never touched: another
291
+ product, your own measured sessions, a private line, a day the export does not cover.
292
+
293
+ ## A copied session folder, and the local archive key
294
+
295
+ **One rule (2026-10-10).** Verified hours are what this computer's coupled key witnessed: the live session hook, the
296
+ AI apps' own folders read at history time, and an archive day signed by this computer's device key. Everything else
297
+ that carries clocks is **reconstructed**: shown on your record with its origin, never in your verified hours.
298
+
299
+ `npx worktrust@latest history --from-folder <dir>` brings in your own copy of an AI app's session folder: a backed-up
300
+ `~/.claude/projects`, `~/.codex/sessions`, or an Antigravity brain folder. It is read with the same readers and the
301
+ same clock as the live folders, never the live folders themselves (a path that is, or holds, one of them is refused).
302
+ Each day is named exactly as the live folder would name it, so a stretch this computer's own sessions already hold is
303
+ skipped (they win), and the same copy sent twice is each line once. What travels: the copy's own counts (tokens, your
304
+ turns, the model, the evidence kinds), as reconstructed hours, titled as from a copied session folder; not the hours in
305
+ layers, which say what a measured day's seconds were. The plan first, one question, Enter is No; `--dry-run` sends
306
+ nothing.
307
+
308
+ `preserve --archive` on a computer that is not coupled now signs each day's root with a **local archive key**
309
+ (`~/.worktrust/archive-key.json`, only you can read it), made once and said in one line. It needs no account and no
310
+ network and never leaves this computer. It is continuity, not proof of time: a day it signed can be told from an edit,
311
+ and the chain stays one computer's when you couple later (the device key then signs new days, and either key may seal
312
+ a day it sealed before), but such a day reaches WorkTrust as reconstructed. It is never offered as the device key at
313
+ pairing: `connect` always mints a fresh pair, because a private key that lived on disk before the pairing would weaken
314
+ the proof of possession the pairing binds, for nothing your record would gain.
315
+
257
316
  ## Where the key lives, and why it only works here
258
317
 
259
318
  The key is kept in **one file only you can read**: `~/.worktrust/key.json` (mode 600, in a folder of
@@ -280,7 +339,7 @@ which would delete every password on the computer, and many people rightly keep
280
339
  | **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. |
281
340
  | **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/`. |
282
341
  | **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). |
283
- | **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`), 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; never a word, a command or a path; since 0.8.3), 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). |
342
+ | **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`), the technologies the touched files name as keys from WorkTrust's closed list (`stack`, `tools_seen`: a `.tsx` file names TypeScript and React, a `Dockerfile` names Docker; read off the paths with the same rules the record uses, since 0.10.11; never a path), 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; never a word, a command or a path; since 0.8.3), 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). |
284
343
  | **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. |
285
344
 
286
345
  ## Why you can check it
@@ -0,0 +1,182 @@
1
+ /**
2
+ * A WEB CHAT'S DATA EXPORT, READ ONCE FOR TWO READERS (CLI 0.10.10, owner 2026-10-10). ChatGPT (Settings → Data
3
+ * controls → Export data) and Claude on the web (Settings → Privacy → Export data) each hand a person a zip with a
4
+ * `conversations.json` in it. The counter reads it for signals; the session hook reads it as HISTORY, so a person's
5
+ * years of browser chats appear on their record. One reader here, imported by both, so the two cannot drift.
6
+ *
7
+ * WHAT IT NEVER DOES. It opens nothing of the zip but `conversations.json` (a vendor's export carries the account's
8
+ * profile, memories and files beside it: those are never inflated). It hands the text to the counter's rubric on this
9
+ * computer, as it always did, and to the hook it hands clocks, roles and a model name only: the conversation's title
10
+ * and every message stay here. Hours from an export are RECONSTRUCTED, never measured: the file can be edited before
11
+ * it is read and no device key witnessed it, so the record shows them with their origin and never in verified hours.
12
+ *
13
+ * readExport(path) { vendor, conversations, digest } a folder holding conversations.json, the file, or the zip
14
+ * exportSessions(path, …) one session per conversation, in the transcript's own shape (type, timestamp, message)
15
+ * exportRef(vendor, id, day) the stretch's stable name: the same on any computer, so a second send is the same line
16
+ * findExports(dir) the exports lying in one folder (its top level only), by path and vendor
17
+ */
18
+ import { createHash } from "node:crypto";
19
+ import { existsSync, openSync, readSync, closeSync, readFileSync, readdirSync, statSync } from "node:fs";
20
+ import { homedir } from "node:os";
21
+ import { basename, join } from "node:path";
22
+ import { inflateRawSync } from "node:zlib";
23
+
24
+ /** The two vendors, by the client name the door reads as their product (chatgpt → chatgpt_web, claude-web → claude_web). */
25
+ export const EXPORT_CLIENTS = ["chatgpt", "claude-web"];
26
+ /** The neutral line each vendor's conversation is filed under: never the conversation's own title. */
27
+ export const EXPORT_TITLES = { chatgpt: "A conversation in ChatGPT", "claude-web": "A conversation in Claude on the web" };
28
+ const PRODUCT_NAMES = { chatgpt: "ChatGPT", "claude-web": "Claude on the web" };
29
+ export const exportProductName = (vendor) => PRODUCT_NAMES[vendor] ?? vendor;
30
+ const FILE = "conversations.json";
31
+ const expand = (path) => String(path).replace(/^~(?=\/|$)/, homedir());
32
+
33
+ /**
34
+ * A ZIP, READ FOR ONE ENTRY. No dependency: the end-of-central-directory record is found from the back, the central
35
+ * directory walked for the one name, and only that entry's bytes inflated (stored or deflated; anything else, and a
36
+ * zip64 archive, is refused by name). Nothing else in the archive is touched.
37
+ */
38
+ function zipEntry(path, wanted) {
39
+ const size = statSync(path).size;
40
+ const fd = openSync(path, "r");
41
+ const readAt = (at, length) => { const buffer = Buffer.alloc(length); const got = readSync(fd, buffer, 0, length, at); return buffer.subarray(0, got); };
42
+ try {
43
+ const tailLength = Math.min(size, 65_557);
44
+ const tail = readAt(size - tailLength, tailLength);
45
+ let eocd = -1;
46
+ for (let at = tail.length - 22; at >= 0; at -= 1) if (tail.readUInt32LE(at) === 0x06054b50) { eocd = at; break; }
47
+ if (eocd < 0) throw Error(`not a zip archive: ${path}`);
48
+ const entries = tail.readUInt16LE(eocd + 10), directorySize = tail.readUInt32LE(eocd + 12), directoryAt = tail.readUInt32LE(eocd + 16);
49
+ if (entries === 0xffff || directorySize === 0xffffffff || directoryAt === 0xffffffff) throw Error(`a zip64 archive is not read: ${path}`);
50
+ const directory = readAt(directoryAt, directorySize);
51
+ let at = 0;
52
+ for (let index = 0; index < entries && at + 46 <= directory.length; index += 1) {
53
+ if (directory.readUInt32LE(at) !== 0x02014b50) throw Error(`a damaged zip archive: ${path}`);
54
+ const method = directory.readUInt16LE(at + 10), compressed = directory.readUInt32LE(at + 20), uncompressed = directory.readUInt32LE(at + 24);
55
+ const nameLength = directory.readUInt16LE(at + 28), extraLength = directory.readUInt16LE(at + 30), commentLength = directory.readUInt16LE(at + 32), localAt = directory.readUInt32LE(at + 42);
56
+ const name = directory.toString("utf8", at + 46, at + 46 + nameLength);
57
+ at += 46 + nameLength + extraLength + commentLength;
58
+ if (basename(name) !== wanted || name.endsWith("/")) continue;
59
+ if (compressed === 0xffffffff || uncompressed === 0xffffffff || localAt === 0xffffffff) throw Error(`a zip64 entry is not read: ${path}`);
60
+ const local = readAt(localAt, 30);
61
+ if (local.readUInt32LE(0) !== 0x04034b50) throw Error(`a damaged zip archive: ${path}`);
62
+ const dataAt = localAt + 30 + local.readUInt16LE(26) + local.readUInt16LE(28);
63
+ const bytes = readAt(dataAt, compressed);
64
+ if (method === 0) return bytes;
65
+ if (method === 8) return inflateRawSync(bytes);
66
+ throw Error(`${wanted} in ${path} is compressed in a way this reader does not open (method ${method})`);
67
+ }
68
+ return null;
69
+ } finally { closeSync(fd); }
70
+ }
71
+
72
+ /** The bytes of `conversations.json`, wherever the given path keeps them: a folder, the file itself, or the vendor's zip. */
73
+ function exportBytes(given) {
74
+ const path = expand(given);
75
+ let stat; try { stat = statSync(path); } catch { throw Error(`export not found: ${given}`); }
76
+ if (stat.isDirectory()) { const file = join(path, FILE); if (!existsSync(file)) throw Error(`no ${FILE} in ${given}`); return { bytes: readFileSync(file), path: file }; }
77
+ if (/\.zip$/i.test(path)) { const bytes = zipEntry(path, FILE); if (!bytes) throw Error(`no ${FILE} in ${given}`); return { bytes, path }; }
78
+ return { bytes: readFileSync(path), path };
79
+ }
80
+
81
+ /** Which vendor wrote these conversations, by their shape alone; mixed or unknown shapes are refused, never guessed. */
82
+ export function vendorOf(conversations) {
83
+ if (!Array.isArray(conversations) || conversations.length === 0) return null;
84
+ const shapes = new Set(conversations.map((c) => (c && typeof c === "object" && c.mapping && typeof c.mapping === "object" ? "chatgpt" : c && typeof c === "object" && Array.isArray(c.chat_messages) ? "claude-web" : "unknown")));
85
+ return shapes.size === 1 ? [...shapes][0] : null;
86
+ }
87
+
88
+ /** One export, read: its vendor by shape, its conversations, and the digest of its bytes (what `sent` is remembered by). */
89
+ export function readExport(given, expect = null) {
90
+ const { bytes, path } = exportBytes(given);
91
+ let conversations; try { conversations = JSON.parse(bytes.toString("utf8")); } catch { throw Error(`export unreadable: ${path}`); }
92
+ if (!Array.isArray(conversations)) throw Error(`${path} must contain an array of conversations`);
93
+ const vendor = vendorOf(conversations);
94
+ if (conversations.length > 0 && !vendor) throw Error(`${path} is neither a ChatGPT nor a Claude export (or mixes the two)`);
95
+ if (expect && vendor && vendor !== expect) throw Error(`${path} is a ${exportProductName(vendor)} export, not ${exportProductName(expect)}`);
96
+ return { vendor: vendor ?? expect, conversations, digest: createHash("sha256").update(bytes).digest("hex"), path };
97
+ }
98
+
99
+ /** The kept branch of one ChatGPT conversation, oldest first: from `current_node` up through the parents. */
100
+ function chatgptBranch(conversation) {
101
+ const mapping = conversation?.mapping && typeof conversation.mapping === "object" ? conversation.mapping : {};
102
+ const branch = [];
103
+ const seen = new Set();
104
+ for (let id = conversation?.current_node; id && mapping[id] && !seen.has(id); id = mapping[id].parent) { seen.add(id); branch.push(mapping[id]); }
105
+ return branch.reverse();
106
+ }
107
+ /** A ChatGPT conversation's lines: the person and the model only; system prompts, tools and what the app hides are neither. */
108
+ function chatgptLines(conversation) {
109
+ const lines = [];
110
+ for (const node of chatgptBranch(conversation)) {
111
+ const m = node?.message;
112
+ const role = m?.author?.role;
113
+ if ((role !== "user" && role !== "assistant") || m?.metadata?.is_visually_hidden_from_conversation) continue;
114
+ const parts = Array.isArray(m?.content?.parts) ? m.content.parts.filter((part) => typeof part === "string") : [];
115
+ const text = parts.join("\n");
116
+ if (text.length === 0) continue;
117
+ const seconds = Number(m?.create_time ?? conversation?.create_time);
118
+ const at = Number.isFinite(seconds) && seconds > 0 ? new Date(seconds * 1000).toISOString() : null;
119
+ const model = typeof m?.metadata?.model_slug === "string" ? m.metadata.model_slug : undefined;
120
+ lines.push({ type: role === "user" ? "user" : "assistant", timestamp: at, message: { ...(role === "assistant" && model ? { model } : {}), content: [{ type: "text", text }] } });
121
+ }
122
+ return lines;
123
+ }
124
+ /** A claude.ai conversation's messages in the transcript's own shape; the export names no model. */
125
+ function claudeLines(conversation) {
126
+ const messages = Array.isArray(conversation?.chat_messages) ? conversation.chat_messages : [];
127
+ return messages.map((m) => {
128
+ const text = typeof m?.text === "string" && m.text.length > 0 ? m.text : (Array.isArray(m?.content) ? m.content.filter((c) => c?.type === "text" && typeof c.text === "string").map((c) => c.text).join("\n") : "");
129
+ const at = m?.created_at ?? conversation?.created_at ?? null;
130
+ return { type: m?.sender === "human" ? "user" : "assistant", timestamp: at, message: { content: [{ type: "text", text }] } };
131
+ });
132
+ }
133
+ const titleOf = (vendor, conversation) => String((vendor === "chatgpt" ? conversation?.title : conversation?.name) ?? "");
134
+ const idOf = (vendor, conversation, index) => String((vendor === "chatgpt" ? conversation?.conversation_id ?? conversation?.id : conversation?.uuid) ?? `#${index}`);
135
+
136
+ /**
137
+ * Every conversation of an export as one session: `key` names the vendor and the conversation's id, `lines` carry
138
+ * the transcript shape both readers measure. `excluded(title)` skips a conversation by its title before anything of
139
+ * it is read (the same `--exclude` as a project directory); the title itself goes no further than that call.
140
+ * `given` is a path, or an export `readExport` already returned (so a zip is inflated once).
141
+ */
142
+ export function* exportSessions(given, { expect = null, excluded = () => false, skipped = null } = {}) {
143
+ const { vendor, conversations } = typeof given === "string" ? readExport(given, expect) : given;
144
+ for (let index = 0; index < conversations.length; index += 1) {
145
+ const conversation = conversations[index];
146
+ const title = titleOf(vendor, conversation);
147
+ if (excluded(title)) { skipped?.push(title.slice(0, 40)); continue; }
148
+ const lines = vendor === "chatgpt" ? chatgptLines(conversation) : claudeLines(conversation);
149
+ if (lines.length === 0) continue;
150
+ const id = idOf(vendor, conversation, index);
151
+ yield { key: `${vendor === "chatgpt" ? "chatgpt" : "claude.ai"}:${id}`, projectDir: vendor === "chatgpt" ? "chatgpt" : "claude-ai", basename: vendor === "chatgpt" ? "chatgpt" : "claude.ai", vendor, id, lines };
152
+ }
153
+ }
154
+
155
+ /**
156
+ * THE STRETCH'S NAME (the hook's `stretch_ref`, 43 characters): a hash of the vendor, the conversation's id and the
157
+ * UTC day, the same on any computer and on any copy of the export, so the same export sent twice, or from two
158
+ * computers, is each line once. The conversation's id is a vendor's opaque id; the hash carries nothing readable.
159
+ */
160
+ export const exportRef = (vendor, id, day) => createHash("sha256").update(`worktrust-export|${vendor}|${id}|${day}`).digest("base64url");
161
+
162
+ /**
163
+ * THE EXPORTS IN ONE FOLDER, its top level only (the Downloads folder, where a vendor's export lands): a zip holding
164
+ * `conversations.json`, a folder holding one, or the file itself. Each is read to tell its vendor and digest; a file
165
+ * that is none of these, or not an export, is passed over without a word.
166
+ */
167
+ export function findExports(dir = join(homedir(), "Downloads")) {
168
+ const root = expand(dir);
169
+ let names = []; try { names = readdirSync(root); } catch { return []; }
170
+ const found = [];
171
+ for (const name of names.sort()) {
172
+ const path = join(root, name);
173
+ let stat; try { stat = statSync(path); } catch { continue; }
174
+ const candidate = stat.isDirectory() ? existsSync(join(path, FILE)) : /\.zip$/i.test(name) || name === FILE;
175
+ if (!candidate) continue;
176
+ try {
177
+ const { vendor, conversations, digest } = readExport(path);
178
+ if (vendor && conversations.length > 0) found.push({ path, vendor, digest, conversations: conversations.length });
179
+ } catch { /* not an export, or not one this reader opens */ }
180
+ }
181
+ return found;
182
+ }
@@ -616,66 +616,22 @@ const skippedDirs = [];
616
616
  const countedDirs = [];
617
617
  let exportConversations = 0;
618
618
  const skippedConversations = [];
619
- function* claudeExportSessions() {
620
- for (const given of EXPORTS) {
621
- let path = given.replace(/^~(?=\/|$)/, homedir());
622
- try { if (statSync(path).isDirectory()) path = join(path, "conversations.json"); } catch { throw Error(`claude export not found: ${given}`); }
623
- let conversations; try { conversations = JSON.parse(readFileSync(path, "utf8")); } catch { throw Error(`claude export unreadable: ${path}`); }
624
- if (!Array.isArray(conversations)) throw Error("claude export must contain an array of conversations");
625
- for (const conversation of conversations) {
626
- const title = String(conversation?.name ?? "");
627
- if (excluded(title)) { skippedConversations.push(title.slice(0, 40)); continue; }
628
- const messages = Array.isArray(conversation?.chat_messages) ? conversation.chat_messages : [];
629
- if (messages.length === 0) continue;
630
- exportConversations += 1;
631
- // The export's messages in the transcript's own shape, so one rubric reads both.
632
- const lines = messages.map((m) => {
633
- const text = typeof m?.text === "string" && m.text.length > 0 ? m.text : (Array.isArray(m?.content) ? m.content.filter((c) => c?.type === "text" && typeof c.text === "string").map((c) => c.text).join("\n") : "");
634
- const at = m?.created_at ?? conversation?.created_at ?? null;
635
- return { type: m?.sender === "human" ? "user" : "assistant", timestamp: at, message: { content: [{ type: "text", text }] } };
636
- });
637
- yield { key: `claude.ai:${conversation?.uuid ?? title}`, projectDir: "claude-ai", basename: "claude.ai", lines };
638
- }
619
+ /**
620
+ * THE EXPORT READERS LIVE IN chat-exports.mjs beside this file (0.10.10): the session hook reads the same exports as
621
+ * history, so one reader serves both. The export's messages arrive in the transcript's own shape, so one rubric reads
622
+ * both; a vendor's zip is opened for its conversations.json alone. Without the module an export flag is refused by name.
623
+ */
624
+ const { exportSessions = null } = (await import("./chat-exports.mjs").catch(() => null)) ?? {};
625
+ function* vendorExportSessions(paths, expect) {
626
+ if (paths.length > 0 && !exportSessions) throw Error("chat-exports.mjs is not beside this file: a data export cannot be read");
627
+ for (const given of paths) for (const session of exportSessions(given, { expect, excluded, skipped: skippedConversations })) {
628
+ if (expect === "chatgpt") chatgptConversations += 1; else exportConversations += 1;
629
+ yield session;
639
630
  }
640
631
  }
632
+ function* claudeExportSessions() { yield* vendorExportSessions(EXPORTS, "claude-web"); }
641
633
  let chatgptConversations = 0;
642
- /** The kept branch of one ChatGPT conversation, oldest first: from `current_node` up through the parents. */
643
- function chatgptBranch(conversation) {
644
- const mapping = conversation?.mapping && typeof conversation.mapping === "object" ? conversation.mapping : {};
645
- const branch = [];
646
- const seen = new Set();
647
- for (let id = conversation?.current_node; id && mapping[id] && !seen.has(id); id = mapping[id].parent) { seen.add(id); branch.push(mapping[id]); }
648
- return branch.reverse();
649
- }
650
- function* chatgptExportSessions() {
651
- for (const given of CHATGPT_EXPORTS) {
652
- let path = given.replace(/^~(?=\/|$)/, homedir());
653
- try { if (statSync(path).isDirectory()) path = join(path, "conversations.json"); } catch { throw Error(`chatgpt export not found: ${given}`); }
654
- let conversations; try { conversations = JSON.parse(readFileSync(path, "utf8")); } catch { throw Error(`chatgpt export unreadable: ${path}`); }
655
- if (!Array.isArray(conversations)) throw Error("chatgpt export must contain an array of conversations");
656
- for (const conversation of conversations) {
657
- const title = String(conversation?.title ?? "");
658
- if (excluded(title)) { skippedConversations.push(title.slice(0, 40)); continue; }
659
- const lines = [];
660
- for (const node of chatgptBranch(conversation)) {
661
- const m = node?.message;
662
- const role = m?.author?.role;
663
- // The person and the model only: system prompts, tools and what the app hides are neither.
664
- if ((role !== "user" && role !== "assistant") || m?.metadata?.is_visually_hidden_from_conversation) continue;
665
- const parts = Array.isArray(m?.content?.parts) ? m.content.parts.filter((part) => typeof part === "string") : [];
666
- const text = parts.join("\n");
667
- if (text.length === 0) continue;
668
- const seconds = Number(m?.create_time ?? conversation?.create_time);
669
- const at = Number.isFinite(seconds) && seconds > 0 ? new Date(seconds * 1000).toISOString() : null;
670
- const model = typeof m?.metadata?.model_slug === "string" ? m.metadata.model_slug : undefined;
671
- lines.push({ type: role === "user" ? "user" : "assistant", timestamp: at, message: { ...(role === "assistant" && model ? { model } : {}), content: [{ type: "text", text }] } });
672
- }
673
- if (lines.length === 0) continue;
674
- chatgptConversations += 1;
675
- yield { key: `chatgpt:${conversation?.conversation_id ?? conversation?.id ?? title}`, projectDir: "chatgpt", basename: "chatgpt", lines };
676
- }
677
- }
678
- }
634
+ function* chatgptExportSessions() { yield* vendorExportSessions(CHATGPT_EXPORTS, "chatgpt"); }
679
635
  /**
680
636
  * THE READERS FOR CODEX AND ANTIGRAVITY live in transcript-readers.mjs beside this file (2026-10-04;
681
637
  * the session hook imports the same file). Run alone, without it, the counter reads Claude Code,