worktrust 0.10.16 → 0.10.17
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 +12 -4
- package/chat-exports.mjs +125 -39
- package/log-session.mjs +47 -16
- package/package.json +1 -1
- package/worktrust.mjs +6 -4
package/README.md
CHANGED
|
@@ -120,7 +120,7 @@ npx worktrust@latest history --rebuild re-measure them with the current rules;
|
|
|
120
120
|
npx worktrust@latest history --from-archive [dir] send what your local archive holds of sessions your AI apps
|
|
121
121
|
already deleted, marked as from your archive: a day this computer's key signed as
|
|
122
122
|
measured, every other day as reconstructed (shows the plan, asks first)
|
|
123
|
-
npx worktrust@latest history --export <path> a ChatGPT or Claude data export (the zip, its folder
|
|
123
|
+
npx worktrust@latest history --export <path> a ChatGPT or Claude data export (the zip, its folder, conversations.json, a conversations part or the manifest)
|
|
124
124
|
as history: hours reconstructed from its clocks, never verified (shows the plan, asks first)
|
|
125
125
|
npx worktrust@latest history --from-folder <dir> your own copy of an AI app's session folder (a backed-up ~/.claude/projects,
|
|
126
126
|
~/.codex/sessions): the days this computer's sessions lack, reconstructed (asks first)
|
|
@@ -300,9 +300,17 @@ sends them with one difference: WorkTrust **replaces** this computer's earlier l
|
|
|
300
300
|
Export data) or a Claude data export (Settings → Privacy → Export data) onto your record as history, so years of
|
|
301
301
|
browser chats appear with their months, days and rhythm. The path is the zip the vendor sent you, the folder it was
|
|
302
302
|
unpacked into, or `conversations.json` itself; the vendor is told by the file's shape. Of the zip only
|
|
303
|
-
`conversations.json` is opened: the profile, memories and files beside it are never inflated.
|
|
304
|
-
|
|
305
|
-
|
|
303
|
+
`conversations.json` is opened: the profile, memories and files beside it are never inflated. Claude on the web now
|
|
304
|
+
sends a manifest and one zip per category (0.10.17): give a `conversations-000.zip` part, the folder holding the
|
|
305
|
+
`conversations-*.zip` parts (read in part order), or the manifest json, which is read only for the file names of its
|
|
306
|
+
conversations parts lying beside it; its download links are never followed. The other parts (memories, projects,
|
|
307
|
+
artifacts, frames, design chats, the light metadata) are refused by name and never opened.
|
|
308
|
+
|
|
309
|
+
- **What goes.** Per run of activity in a conversation (0.10.17; before, one line per conversation and day): a run
|
|
310
|
+
ends where two messages lie more than thirty minutes apart, the gap after which the hook calls a stretch finished, so a
|
|
311
|
+
conversation left open for hours is two windows, not one. Cutting changes the windows and never the total: the five
|
|
312
|
+
minutes the clock counts after a message stay with the run before the gap. A day of one run keeps the name it had; a
|
|
313
|
+
cut day replaces the one line an earlier send made of it. Each run: a neutral line (`A conversation in ChatGPT`, `A conversation in Claude on
|
|
306
314
|
the web`), the seconds between the messages' clocks counted the way a measured day is (a pause over five minutes is
|
|
307
315
|
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
|
|
308
316
|
it began and ended, and a stable name made of the conversation's id and the day, so the same export sent twice, or
|
package/chat-exports.mjs
CHANGED
|
@@ -5,20 +5,24 @@
|
|
|
5
5
|
* years of browser chats appear on their record. One reader here, imported by both, so the two cannot drift.
|
|
6
6
|
*
|
|
7
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).
|
|
8
|
+
* profile, memories and files beside it: those are never inflated). Claude's split export (2026-10-17: a manifest and one
|
|
9
|
+
* zip per category) is read through its `conversations-NNN.zip` parts alone, in part order; the manifest only names them,
|
|
10
|
+
* its links are never fetched, and every other category's zip is refused by name. It hands the text to the counter's rubric on this
|
|
9
11
|
* computer, as it always did, and to the hook it hands clocks, roles and a model name only: the conversation's title
|
|
10
12
|
* and every message stay here. Hours from an export are RECONSTRUCTED, never measured: the file can be edited before
|
|
11
13
|
* it is read and no device key witnessed it, so the record shows them with their origin and never in verified hours.
|
|
12
14
|
*
|
|
13
|
-
* readExport(path) { vendor, conversations, digest } a folder holding conversations.json
|
|
15
|
+
* readExport(path) { vendor, conversations, digest } a folder holding conversations.json or conversations
|
|
16
|
+
* parts, the file, the zip, one conversations-NNN.zip part, or Claude's manifest json
|
|
14
17
|
* exportSessions(path, …) one session per conversation, in the transcript's own shape (type, timestamp, message)
|
|
15
18
|
* exportRef(vendor, id, day) the stretch's stable name: the same on any computer, so a second send is the same line
|
|
19
|
+
* exportRunRef(vendor, id, day, index) one run's name, when the hook cuts a conversation-day into runs (0.10.17)
|
|
16
20
|
* findExports(dir) the exports lying in one folder (its top level only), by path and vendor
|
|
17
21
|
*/
|
|
18
22
|
import { createHash } from "node:crypto";
|
|
19
23
|
import { existsSync, openSync, readSync, closeSync, fstatSync, readdirSync, statSync, constants } from "node:fs";
|
|
20
24
|
import { homedir } from "node:os";
|
|
21
|
-
import { basename, join } from "node:path";
|
|
25
|
+
import { basename, dirname, join } from "node:path";
|
|
22
26
|
import { inflateRawSync } from "node:zlib";
|
|
23
27
|
|
|
24
28
|
/** The two vendors, by the client name the door reads as their product (chatgpt → chatgpt_web, claude-web → claude_web). */
|
|
@@ -33,7 +37,8 @@ const expand = (path) => String(path).replace(/^~(?=\/|$)/, homedir());
|
|
|
33
37
|
// Bound allocations and parsing work before touching untrusted sizes. Large attachment-bearing ZIPs
|
|
34
38
|
// need not fit in memory; only the directory and conversations entry are ever read. No limit override.
|
|
35
39
|
export const EXPORT_LIMITS = Object.freeze({ fileBytes: 2 * 1024 ** 3, directoryBytes: 8 * 1024 ** 2,
|
|
36
|
-
jsonBytes: 64 * 1024 ** 2, compressedBytes: 64 * 1024 ** 2, depth: 64, structure: 1_000_000, conversations: 50_000
|
|
40
|
+
jsonBytes: 64 * 1024 ** 2, compressedBytes: 64 * 1024 ** 2, depth: 64, structure: 1_000_000, conversations: 50_000,
|
|
41
|
+
parts: 64, manifestBytes: 1024 ** 2 });
|
|
37
42
|
const limit = (condition, label) => { if (!condition) throw Error(`export limit exceeded: ${label}`); };
|
|
38
43
|
const damaged = (condition) => { if (!condition) throw Error("a damaged zip archive"); };
|
|
39
44
|
/** One descriptor, bounded reads: reject special files/short reads and bound concurrent file growth. */
|
|
@@ -55,11 +60,12 @@ function openExport(path, maximum) {
|
|
|
55
60
|
}
|
|
56
61
|
|
|
57
62
|
/**
|
|
58
|
-
* A ZIP, READ FOR
|
|
59
|
-
* directory walked for the
|
|
60
|
-
* zip64 archive, is refused by name). Nothing else in the archive is touched.
|
|
63
|
+
* A ZIP, READ FOR ITS CONVERSATIONS ENTRIES. No dependency: the end-of-central-directory record is found from the back, the
|
|
64
|
+
* central directory walked for the names `accept` takes, and only those entries' bytes inflated (stored or deflated;
|
|
65
|
+
* anything else, and a zip64 archive, is refused by name), in part order. Nothing else in the archive is touched. Two
|
|
66
|
+
* entries of one name are ambiguous and refused.
|
|
61
67
|
*/
|
|
62
|
-
function
|
|
68
|
+
function zipEntries(path, accept) {
|
|
63
69
|
const { fd, size, readAt } = openExport(path, EXPORT_LIMITS.fileBytes);
|
|
64
70
|
try {
|
|
65
71
|
const tailLength = Math.min(size, 65_557);
|
|
@@ -74,7 +80,8 @@ function zipEntry(path, wanted) {
|
|
|
74
80
|
limit(directorySize <= EXPORT_LIMITS.directoryBytes, "zip directory bytes");
|
|
75
81
|
damaged(directoryAt + directorySize === size - tailLength + eocd);
|
|
76
82
|
const directory = readAt(directoryAt, directorySize);
|
|
77
|
-
let at = 0
|
|
83
|
+
let at = 0;
|
|
84
|
+
const selected = new Map();
|
|
78
85
|
for (let index = 0; index < entries; index += 1) {
|
|
79
86
|
damaged(at + 46 <= directory.length && directory.readUInt32LE(at) === 0x02014b50);
|
|
80
87
|
const method = directory.readUInt16LE(at + 10), compressed = directory.readUInt32LE(at + 20), uncompressed = directory.readUInt32LE(at + 24);
|
|
@@ -83,41 +90,107 @@ function zipEntry(path, wanted) {
|
|
|
83
90
|
damaged(at + 46 + nameLength + extraLength + commentLength <= directory.length);
|
|
84
91
|
const name = directory.toString("utf8", at + 46, at + 46 + nameLength);
|
|
85
92
|
at += 46 + nameLength + extraLength + commentLength;
|
|
86
|
-
if (basename(name)
|
|
93
|
+
if (!accept(basename(name)) || name.endsWith("/")) continue;
|
|
87
94
|
if (compressed === 0xffffffff || uncompressed === 0xffffffff || localAt === 0xffffffff) throw Error(`a zip64 entry is not read: ${path}`);
|
|
88
95
|
limit(compressed <= EXPORT_LIMITS.compressedBytes, "compressed entry bytes");
|
|
89
96
|
limit(uncompressed <= EXPORT_LIMITS.jsonBytes, "expanded entry bytes");
|
|
90
97
|
if ((flags & (1 | 64)) !== 0 || disk !== 0) throw Error("unsupported zip: encrypted or multi-disk entry");
|
|
91
|
-
damaged(selected
|
|
92
|
-
selected
|
|
98
|
+
damaged(!selected.has(basename(name)));
|
|
99
|
+
selected.set(basename(name), { name, method, flags, compressed, uncompressed, localAt });
|
|
93
100
|
}
|
|
94
101
|
damaged(at === directory.length);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
102
|
+
limit(selected.size <= EXPORT_LIMITS.parts, "conversations parts");
|
|
103
|
+
let total = 0;
|
|
104
|
+
return [...selected.keys()].sort(byPart).map((key) => {
|
|
105
|
+
const { name, method, flags, compressed, uncompressed, localAt } = selected.get(key);
|
|
106
|
+
total += uncompressed;
|
|
107
|
+
limit(total <= EXPORT_LIMITS.jsonBytes, "expanded entry bytes");
|
|
108
|
+
const local = readAt(localAt, 30, directoryAt);
|
|
109
|
+
damaged(local.readUInt32LE(0) === 0x04034b50 && local.readUInt16LE(8) === method && local.readUInt16LE(6) === flags);
|
|
110
|
+
const nameLength = local.readUInt16LE(26), dataAt = localAt + 30 + nameLength + local.readUInt16LE(28);
|
|
111
|
+
damaged(readAt(localAt + 30, nameLength, directoryAt).toString("utf8") === name);
|
|
112
|
+
if (!(flags & 8)) damaged(local.readUInt32LE(18) === compressed && local.readUInt32LE(22) === uncompressed);
|
|
113
|
+
const bytes = readAt(dataAt, compressed, directoryAt);
|
|
114
|
+
if (method === 0) { damaged(compressed === uncompressed); return bytes; }
|
|
115
|
+
if (method !== 8) throw Error(`${basename(name)} in ${path} is compressed in a way this reader does not open (method ${method})`);
|
|
116
|
+
let inflated;
|
|
117
|
+
try { inflated = inflateRawSync(bytes, { maxOutputLength: Math.max(1, uncompressed) }); }
|
|
118
|
+
catch { throw Error("a damaged zip archive or export limit exceeded: expanded entry bytes"); }
|
|
119
|
+
damaged(inflated.length === uncompressed);
|
|
120
|
+
return inflated;
|
|
121
|
+
});
|
|
110
122
|
} finally { closeSync(fd); }
|
|
111
123
|
}
|
|
112
124
|
|
|
113
|
-
/**
|
|
114
|
-
|
|
125
|
+
/**
|
|
126
|
+
* THE CONVERSATIONS, AND ONLY THEM (owner, 2026-10-17). Inside a zip: `conversations.json`, or a part-numbered
|
|
127
|
+
* `conversations-000.json`. Claude on the web now hands a person a manifest and one zip per category; of those only the
|
|
128
|
+
* `conversations-NNN.zip` parts are read. The other categories (memories, projects, artifacts, frames, design chats, the
|
|
129
|
+
* light metadata) are refused by their name, never opened.
|
|
130
|
+
*/
|
|
131
|
+
const CONVERSATIONS_ENTRY = /^conversations(?:[-_]\d{1,6})?\.json$/i;
|
|
132
|
+
const CONVERSATIONS_PART = /^conversations[-_](\d{1,6})\.zip$/i;
|
|
133
|
+
const OTHER_PART = /^(light_metadata|projects|memories|design_chats|frames|artifact_data|users?|attachments?)[-_]\d{1,6}\.zip$/i;
|
|
134
|
+
const partOf = (name) => Number(/(\d{1,6})\.(?:json|zip)$/i.exec(name)?.[1] ?? -1);
|
|
135
|
+
const byPart = (a, b) => partOf(a) - partOf(b) || a.localeCompare(b);
|
|
136
|
+
const refuseOther = (path) => { const other = OTHER_PART.exec(basename(path)); if (other) throw Error(`${basename(path)} is the export's ${other[1].toLowerCase()} part: only its conversations parts are read`); };
|
|
137
|
+
/** One conversations zip: its conversations entries, or a refusal that names the zip. */
|
|
138
|
+
function zipParts(path, given) {
|
|
139
|
+
refuseOther(path);
|
|
140
|
+
const parts = zipEntries(path, (name) => CONVERSATIONS_ENTRY.test(name));
|
|
141
|
+
if (parts.length === 0) throw Error(`no ${FILE} in ${given}`);
|
|
142
|
+
return parts.map((bytes) => ({ bytes, path }));
|
|
143
|
+
}
|
|
144
|
+
/** A folder's conversations zips (conversations-000.zip, -001.zip …), in part order; nothing else of the folder is read. */
|
|
145
|
+
const folderParts = (dir) => { let names = []; try { names = readdirSync(dir); } catch { return []; } return names.filter((name) => CONVERSATIONS_PART.test(name)).sort(byPart).map((name) => join(dir, name)); };
|
|
146
|
+
/**
|
|
147
|
+
* THE MANIFEST (Claude on the web, version "1.0"): a list of `data_files` with a category, a part, a file name and a link.
|
|
148
|
+
* It is read for the file names of its conversations parts alone, which must lie beside it; a link in it is NEVER fetched
|
|
149
|
+
* (this reader opens no network), and a name that is not a plain conversations zip in the same folder is refused.
|
|
150
|
+
*/
|
|
151
|
+
function manifestParts(manifest, path) {
|
|
152
|
+
const files = Array.isArray(manifest?.data_files) ? manifest.data_files : null;
|
|
153
|
+
if (!files) throw Error(`${path} is neither an export nor its manifest`);
|
|
154
|
+
limit(files.length <= 10_000, "manifest entries");
|
|
155
|
+
const wanted = files.filter((file) => file && typeof file === "object" && file.category === "conversations").map((file) => String(file.filename ?? ""));
|
|
156
|
+
if (wanted.length === 0) throw Error(`${path} names no conversations part`);
|
|
157
|
+
const missing = [], found = [];
|
|
158
|
+
for (const name of wanted.sort(byPart)) {
|
|
159
|
+
if (!/^[\w.-]{1,200}$/.test(name) || !CONVERSATIONS_PART.test(name)) throw Error(`${path} names a conversations part that is not a plain conversations zip beside it`);
|
|
160
|
+
const at = join(dirname(path), name);
|
|
161
|
+
if (existsSync(at)) found.push(at); else missing.push(name);
|
|
162
|
+
}
|
|
163
|
+
if (missing.length > 0) throw Error(`the manifest names conversations parts that are not beside it: ${missing.join(", ")} (download them into the same folder; the links in the manifest are never followed)`);
|
|
164
|
+
return found;
|
|
165
|
+
}
|
|
166
|
+
/** Several parts together stay inside one export's budget. */
|
|
167
|
+
const withinBudget = (parts) => { limit(parts.length <= EXPORT_LIMITS.parts && parts.reduce((sum, part) => sum + part.bytes.length, 0) <= EXPORT_LIMITS.jsonBytes * 4, "conversations parts"); return parts; };
|
|
168
|
+
|
|
169
|
+
/** The bytes of every conversations part, wherever the given path keeps them: a folder, the file itself, a zip, a part, or the manifest. */
|
|
170
|
+
function exportParts(given) {
|
|
115
171
|
let path = expand(given);
|
|
116
172
|
let stat; try { stat = statSync(path); } catch { throw Error(`export not found: ${given}`); }
|
|
117
|
-
if (stat.isDirectory()) {
|
|
118
|
-
|
|
173
|
+
if (stat.isDirectory()) {
|
|
174
|
+
if (existsSync(join(path, FILE))) path = join(path, FILE);
|
|
175
|
+
else {
|
|
176
|
+
const zips = folderParts(path);
|
|
177
|
+
if (zips.length === 0) throw Error(`no ${FILE} in ${given}`);
|
|
178
|
+
limit(zips.length <= EXPORT_LIMITS.parts, "conversations parts");
|
|
179
|
+
return withinBudget(zips.flatMap((zip) => zipParts(zip, given)));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (/\.zip$/i.test(path)) return zipParts(path, given);
|
|
119
183
|
const { fd, size, readAt } = openExport(path, EXPORT_LIMITS.jsonBytes);
|
|
120
|
-
|
|
184
|
+
let bytes; try { bytes = readAt(0, size); } finally { closeSync(fd); }
|
|
185
|
+
// A json holding an object, not an array of conversations, may be the vendor's manifest: read for its conversations parts alone.
|
|
186
|
+
if (basename(path) !== FILE && size <= EXPORT_LIMITS.manifestBytes && /^\s*\{/.test(bytes.subarray(0, 64).toString("utf8"))) {
|
|
187
|
+
boundJson(bytes);
|
|
188
|
+
let manifest; try { manifest = JSON.parse(bytes.toString("utf8")); } catch { throw Error(`export unreadable: ${path}`); }
|
|
189
|
+
const zips = manifestParts(manifest, path);
|
|
190
|
+
limit(zips.length <= EXPORT_LIMITS.parts, "conversations parts");
|
|
191
|
+
return withinBudget(zips.flatMap((zip) => zipParts(zip, given)));
|
|
192
|
+
}
|
|
193
|
+
return [{ bytes, path }];
|
|
121
194
|
}
|
|
122
195
|
|
|
123
196
|
/** Scan bytes before JSON.parse allocates an object graph; escaped quotes/brackets inside strings
|
|
@@ -143,15 +216,21 @@ export function vendorOf(conversations) {
|
|
|
143
216
|
|
|
144
217
|
/** One export, read: its vendor by shape, its conversations, and the digest of its bytes (what `sent` is remembered by). */
|
|
145
218
|
export function readExport(given, expect = null) {
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
219
|
+
const parts = exportParts(given), digest = createHash("sha256");
|
|
220
|
+
const path = parts[0].path;
|
|
221
|
+
const conversations = [];
|
|
222
|
+
for (const { bytes, path: from } of parts) {
|
|
223
|
+
boundJson(bytes);
|
|
224
|
+
let some; try { some = JSON.parse(bytes.toString("utf8")); } catch { throw Error(`export unreadable: ${from}`); }
|
|
225
|
+
if (!Array.isArray(some)) throw Error(`${from} must contain an array of conversations`);
|
|
226
|
+
limit(conversations.length + some.length <= EXPORT_LIMITS.conversations, "conversation count");
|
|
227
|
+
for (const conversation of some) conversations.push(conversation);
|
|
228
|
+
digest.update(bytes); // one part: the digest of its bytes, as before; several: of their bytes in part order
|
|
229
|
+
}
|
|
151
230
|
const vendor = vendorOf(conversations);
|
|
152
231
|
if (conversations.length > 0 && !vendor) throw Error(`${path} is neither a ChatGPT nor a Claude export (or mixes the two)`);
|
|
153
232
|
if (expect && vendor && vendor !== expect) throw Error(`${path} is a ${exportProductName(vendor)} export, not ${exportProductName(expect)}`);
|
|
154
|
-
return { vendor: vendor ?? expect, conversations, digest:
|
|
233
|
+
return { vendor: vendor ?? expect, conversations, digest: digest.digest("hex"), path, parts: parts.length };
|
|
155
234
|
}
|
|
156
235
|
|
|
157
236
|
/** The kept branch of one ChatGPT conversation, oldest first: from `current_node` up through the parents. */
|
|
@@ -216,6 +295,13 @@ export function* exportSessions(given, { expect = null, excluded = () => false,
|
|
|
216
295
|
* computers, is each line once. The conversation's id is a vendor's opaque id; the hash carries nothing readable.
|
|
217
296
|
*/
|
|
218
297
|
export const exportRef = (vendor, id, day) => createHash("sha256").update(`worktrust-export|${vendor}|${id}|${day}`).digest("base64url");
|
|
298
|
+
/**
|
|
299
|
+
* ONE RUN'S NAME (CLI 0.10.17, owner 2026-10-17): a conversation-day the hook cuts into runs of activity names each run by
|
|
300
|
+
* the same three and the run's index, in order from the day's first message. A day of one run keeps `exportRef`, the name
|
|
301
|
+
* it always had, so a day sent before the cut is the same line; a day of several runs names that old line as the one its
|
|
302
|
+
* runs replace (the hook's `supersedes_ref`).
|
|
303
|
+
*/
|
|
304
|
+
export const exportRunRef = (vendor, id, day, index) => createHash("sha256").update(`worktrust-export|${vendor}|${id}|${day}|run|${index}`).digest("base64url");
|
|
219
305
|
|
|
220
306
|
/**
|
|
221
307
|
* THE EXPORTS IN ONE FOLDER, its top level only (the Downloads folder, where a vendor's export lands): a zip holding
|
|
@@ -229,7 +315,7 @@ export function findExports(dir = join(homedir(), "Downloads")) {
|
|
|
229
315
|
for (const name of names.sort()) {
|
|
230
316
|
const path = join(root, name);
|
|
231
317
|
let stat; try { stat = statSync(path); } catch { continue; }
|
|
232
|
-
const candidate = stat.isDirectory() ? existsSync(join(path, FILE)) : /\.zip$/i.test(name) || name === FILE;
|
|
318
|
+
const candidate = stat.isDirectory() ? existsSync(join(path, FILE)) || folderParts(path).length > 0 : (/\.zip$/i.test(name) && !OTHER_PART.test(name)) || name === FILE;
|
|
233
319
|
if (!candidate) continue;
|
|
234
320
|
try {
|
|
235
321
|
const { vendor, conversations, digest } = readExport(path);
|
package/log-session.mjs
CHANGED
|
@@ -270,7 +270,7 @@ const { callOf = (block) => ({ id: block.id, kinds: [], family: String(block.nam
|
|
|
270
270
|
const { DATABASE_SESSION = /(?!)/, databaseLines = () => null, databaseSessions = function* () {} } = (await import("./session-databases.mjs").catch(() => null)) ?? {};
|
|
271
271
|
// A WEB CHAT'S DATA EXPORT AS HISTORY (0.10.10, owner 2026-10-10): chat-exports.mjs reads a ChatGPT or Claude export (the counter
|
|
272
272
|
// imports the same reader); `--history --export <path>` sends its conversations as RECONSTRUCTED days, never measured, never tokens.
|
|
273
|
-
const { EXPORT_CLIENTS = [], EXPORT_TITLES = {}, exportSessions = null, exportRef = null, readExport = null, findExports = null } = (await import("./chat-exports.mjs").catch(() => null)) ?? {};
|
|
273
|
+
const { EXPORT_CLIENTS = [], EXPORT_TITLES = {}, exportSessions = null, exportRef = null, exportRunRef = null, readExport = null, findExports = null } = (await import("./chat-exports.mjs").catch(() => null)) ?? {};
|
|
274
274
|
const { modCounts = () => null } = (await import("./claude-mod.mjs").catch(() => null)) ?? {}; // 0.10.15: the WorkTrust mod's live counts per Claude Code session and day; absent → no `live` group, never zeros
|
|
275
275
|
const liveOf = (file, day) => modCounts(String(file).split(/[\\/]/).pop().replace(/\.jsonl$/, ""), day) ?? codexLive(file, day); // 0.10.16: a Codex rollout's own
|
|
276
276
|
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
|
|
@@ -736,7 +736,7 @@ function batchesOf(group, byDay) {
|
|
|
736
736
|
return out;
|
|
737
737
|
}
|
|
738
738
|
/** 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. */
|
|
739
|
-
const RECEIPTS = { new: 0, alreadyHeld: 0, filled: 0, replaced: 0, superseded: 0, unknownOnDays: 0, unknownWithdrawn: 0 }; // 2026-10-10: and what a re-measure did (new, held, filled, replaced), so the command can say it
|
|
739
|
+
const RECEIPTS = { new: 0, alreadyHeld: 0, filled: 0, replaced: 0, superseded: 0, recut: 0, unknownOnDays: 0, unknownWithdrawn: 0 }; // 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
|
|
740
740
|
const noteReceipt = (answer) => {
|
|
741
741
|
try {
|
|
742
742
|
const json = JSON.parse(answer.trim().startsWith("{") ? answer : answer.split("\n").find((row) => row.startsWith("data:"))?.slice(5) ?? "null");
|
|
@@ -862,7 +862,8 @@ function historyEntries(floor = null, all = false) {
|
|
|
862
862
|
|
|
863
863
|
/**
|
|
864
864
|
* A DATA EXPORT'S CONVERSATIONS AS HISTORY (0.10.10, owner 2026-10-10: "hours from an export count as reconstructed, shown,
|
|
865
|
-
* never in verified hours").
|
|
865
|
+
* never in verified hours"). Since 0.10.17 one line per RUN of activity in a conversation-day (runsOf, below), no longer one
|
|
866
|
+
* envelope per conversation and day. The same clock cuts them (a day, gaps capped at IDLE_CAP) and the same measure counts the
|
|
866
867
|
* person's own turns and the model, but the line says `reconstructed`: the file can be edited before it is read and no
|
|
867
868
|
* device key witnessed it. No tokens (the export carries none and none are estimated), no layers, no evidence; the
|
|
868
869
|
* title names the product and never the conversation; the stretch's name is the vendor, the conversation's id and the
|
|
@@ -870,11 +871,31 @@ function historyEntries(floor = null, all = false) {
|
|
|
870
871
|
* (20261009170000), so the line is cut there before it leaves.
|
|
871
872
|
*/
|
|
872
873
|
const RECONSTRUCTED_MAX = 28800;
|
|
874
|
+
/**
|
|
875
|
+
* WHERE A CONVERSATION-DAY IS CUT (CLI 0.10.17, owner 2026-10-17): the hook's own stretch-finished gap, IDLE_BEFORE_SWEEP
|
|
876
|
+
* (half an hour of quiet says a stretch is finished), never a new constant. Counting is unchanged: every gap between two
|
|
877
|
+
* messages, the person's or the model's, counts up to IDLE_CAP, and a gap the cut falls in is counted, as it always was,
|
|
878
|
+
* with the run BEFORE it (the five minutes the clock credits after a message). So the runs' seconds sum to exactly what
|
|
879
|
+
* the one envelope carried, and only the windows sharpen: a long-idle conversation no longer spans its own gap.
|
|
880
|
+
*/
|
|
881
|
+
const RUN_GAP = IDLE_BEFORE_SWEEP;
|
|
882
|
+
function runsOf(messages) {
|
|
883
|
+
const runs = [];
|
|
884
|
+
let current = null;
|
|
885
|
+
for (let i = 0; i < messages.length; i += 1) {
|
|
886
|
+
const gap = i === 0 ? null : messages[i].at - messages[i - 1].at;
|
|
887
|
+
if (current && gap > RUN_GAP) { current.seconds += Math.min(IDLE_CAP, Math.round(gap / 1000)); current = null; }
|
|
888
|
+
if (!current) { current = { messages: [], seconds: 0 }; runs.push(current); }
|
|
889
|
+
else current.seconds += Math.min(IDLE_CAP, Math.round(gap / 1000));
|
|
890
|
+
current.messages.push(messages[i]);
|
|
891
|
+
}
|
|
892
|
+
return runs;
|
|
893
|
+
}
|
|
873
894
|
const EXPORTS_STATE = join(homedir(), ".worktrust", "exports.json"); // per export digest: sent, or offered and declined; nothing of a conversation
|
|
874
895
|
const readExportsState = () => { try { return JSON.parse(readFileSync(EXPORTS_STATE, "utf8")); } catch { return {}; } };
|
|
875
896
|
const rememberExport = (digest, note) => { const state = readExportsState(); state[digest] = { ...(state[digest] ?? {}), ...note }; mkdirSync(dirname(EXPORTS_STATE), { recursive: true }); writeFileSync(EXPORTS_STATE, JSON.stringify(state, null, 1)); };
|
|
876
897
|
function exportEntries() {
|
|
877
|
-
if (!exportSessions) throw Error("chat-exports.mjs is not beside this file: a data export cannot be read");
|
|
898
|
+
if (!exportSessions || !exportRunRef) throw Error("chat-exports.mjs is not beside this file, or is older than this hook: a data export cannot be read");
|
|
878
899
|
const entries = [], reports = [];
|
|
879
900
|
for (const given of EXPORT_PATHS) {
|
|
880
901
|
const read = readExport(given);
|
|
@@ -885,18 +906,28 @@ function exportEntries() {
|
|
|
885
906
|
messages.sort((a, b) => a.at - b.at);
|
|
886
907
|
for (const [day, ofDay] of byDayOf(messages)) {
|
|
887
908
|
if (ofDay.length === 0) continue;
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
909
|
+
// ONE STRETCH PER RUN OF ACTIVITY (0.10.17): the day's messages cut where the hook calls a stretch finished; one run
|
|
910
|
+
// is the day as before, under the name it always had; several name the one-envelope line they replace.
|
|
911
|
+
const runs = runsOf(ofDay), whole = measure(null, ofDay), old = exportRef(read.vendor, id, day);
|
|
912
|
+
runs.forEach(({ messages: run, seconds }, index) => {
|
|
913
|
+
const stretch = measure(null, run), ref = runs.length === 1 ? old : exportRunRef(read.vendor, id, day, index);
|
|
914
|
+
// The day as a whole decides whether there is a duration (under a minute is none, as before); a run then carries
|
|
915
|
+
// its own share of the day's count, and a run with nothing to count carries none.
|
|
916
|
+
const own = runs.length === 1 ? whole.seconds : whole.seconds !== null && seconds > 0 ? seconds : null;
|
|
917
|
+
const entry = {
|
|
918
|
+
title: EXPORT_TITLES[read.vendor], kind: "researched",
|
|
919
|
+
...(own !== null ? { seconds: Math.min(RECONSTRUCTED_MAX, own), duration_basis: "reconstructed" } : {}),
|
|
920
|
+
...(stretch.exchanges > 0 ? { exchanges: stretch.exchanges, turn_basis: "humanOnly" } : {}),
|
|
921
|
+
...(stretch.model ? { model: stretch.model } : {}),
|
|
922
|
+
stretch_ref: ref, source_event_id: `exp_${ref}`,
|
|
923
|
+
...(runs.length > 1 ? { supersedes_ref: old } : {}),
|
|
924
|
+
started_at: new Date(stretch.from).toISOString(), utc_offset: stretch.offset, at: new Date(stretch.to).toISOString(),
|
|
925
|
+
};
|
|
926
|
+
entrySource.set(entry, read.vendor);
|
|
927
|
+
entryFile.set(entry, { file: `${read.vendor}:${id}`, from: stretch.from, folder: null });
|
|
928
|
+
report.seconds += entry.seconds ?? 0; entries.push(entry);
|
|
929
|
+
});
|
|
930
|
+
report.days.add(day);
|
|
900
931
|
}
|
|
901
932
|
}
|
|
902
933
|
const days = [...report.days].sort();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "worktrust",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.17",
|
|
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/worktrust.mjs
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* npx worktrust history --from-folder <dir> your own copy of an AI app's session folder (a backed-up ~/.claude/projects,
|
|
21
21
|
* ~/.codex/sessions): the days this computer's own sessions lack, reconstructed,
|
|
22
22
|
* never verified hours (shows the plan, asks first; 0.10.10)
|
|
23
|
-
* npx worktrust history --export <path> a ChatGPT or Claude data export (the zip, its folder
|
|
23
|
+
* npx worktrust history --export <path> a ChatGPT or Claude data export (the zip, its folder, conversations.json, a conversations part or the manifest)
|
|
24
24
|
* as history: hours RECONSTRUCTED from its clocks, shown with their origin,
|
|
25
25
|
* never verified hours (shows the plan, asks first; 0.10.10). The bare
|
|
26
26
|
* command on a coupled computer offers an export lying in ~/Downloads once.
|
|
@@ -83,7 +83,7 @@ const command = args.includes("--help") ? "help" : args.includes("--version") ?
|
|
|
83
83
|
const flag = (name) => { const at = args.indexOf(`--${name}`); return at >= 0 ? args[at + 1] : undefined; };
|
|
84
84
|
const has = (name) => args.includes(`--${name}`);
|
|
85
85
|
/** 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). */
|
|
86
|
-
const CLI_VERSION = "0.10.
|
|
86
|
+
const CLI_VERSION = "0.10.17";
|
|
87
87
|
const ORIGIN = (flag("origin") ?? process.env.WORKTRUST_ORIGIN ?? "https://app.worktrust.io").replace(/\/$/, "");
|
|
88
88
|
const MCP = flag("url") ?? process.env.WORKTRUST_MCP_URL ?? `${ORIGIN}/api/mcp`;
|
|
89
89
|
const HOME_DIR = join(homedir(), ".worktrust");
|
|
@@ -767,7 +767,7 @@ async function history() {
|
|
|
767
767
|
const key = await freshKey();
|
|
768
768
|
if (!key) fail("this computer is not coupled through the key file. Run npx worktrust first.");
|
|
769
769
|
if (has("from-archive")) return offerArchive(await scripts(), key);
|
|
770
|
-
if (has("export")) { if (!flag("export") || flag("export").startsWith("--")) fail("--export needs the export's path: the zip, its folder,
|
|
770
|
+
if (has("export")) { if (!flag("export") || flag("export").startsWith("--")) fail("--export needs the export's path: the zip, its folder, conversations.json, a conversations-000.zip part, or the manifest"); await offerExport(await scripts(), key, flag("export")); return; }
|
|
771
771
|
if (has("from-folder")) { if (!flag("from-folder") || flag("from-folder").startsWith("--")) fail("--from-folder needs the copied folder's path"); await offerFolder(await scripts(), key, flag("from-folder")); return; }
|
|
772
772
|
// ONE PATH (0.10.5): sending is re-measuring. On a computer WorkTrust has never heard from nothing is replaced, so it is a
|
|
773
773
|
// plain send; after a failure, a merge or an older CLI, the same command replaces day by day. `--rebuild` still reads.
|
|
@@ -821,6 +821,8 @@ async function offerExport(paths, key, path) {
|
|
|
821
821
|
// says so; the lines an AI app reported under no product on those days may describe the same conversations, and go only on a yes.
|
|
822
822
|
const counts = lastCounts(sent.out);
|
|
823
823
|
if (counts.superseded > 0) say(` ${counts.superseded} earlier line${counts.superseded === 1 ? "" : "s"} of ${product} on those days, brought in by a connector, ${counts.superseded === 1 ? "is" : "are"} withdrawn and kept (each with a correction row): the export's lines count, a day counts once.`);
|
|
824
|
+
// ONE STRETCH PER RUN (0.10.17): a conversation-day sent before as one envelope is now its runs; the door withdrew the envelope.
|
|
825
|
+
if (counts.recut > 0) say(` ${counts.recut} earlier line${counts.recut === 1 ? "" : "s"} of this export, one per conversation and day, ${counts.recut === 1 ? "is" : "are"} replaced by one line per run of activity (withdrawn and kept, the same total).`);
|
|
824
826
|
if (counts.unknownOnDays > 0) {
|
|
825
827
|
const n = counts.unknownOnDays;
|
|
826
828
|
say(` ${n} earlier line${n === 1 ? "" : "s"} an AI app reported for these days, under no product, may describe the same conversations.`);
|
|
@@ -1150,7 +1152,7 @@ function help() {
|
|
|
1150
1152
|
say(" --from-archive [dir] send what your archive (preserve --archive) holds of sessions your AI apps already deleted,");
|
|
1151
1153
|
say(" marked as from your archive: a day this computer's key signed as measured, every other day");
|
|
1152
1154
|
say(" as reconstructed, never verified hours (shows the plan, asks first)");
|
|
1153
|
-
say(" --export <path> a ChatGPT or Claude data export (the zip, its folder
|
|
1155
|
+
say(" --export <path> a ChatGPT or Claude data export (the zip, its folder, conversations.json, a conversations part or the manifest) as history:");
|
|
1154
1156
|
say(" hours reconstructed from its clocks, shown with their origin, never verified hours (asks first);");
|
|
1155
1157
|
say(" on its days the export replaces the product's earlier connector lines (withdrawn, kept)");
|
|
1156
1158
|
say(" --withdraw-unknown with --export: yes in advance to withdrawing the earlier lines an AI app reported for those days");
|