worktrust 0.10.37 → 0.11.0
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/LICENSE +43 -18
- package/README.md +59 -2
- package/SECURITY.md +25 -0
- package/chat-exports.mjs +20 -20
- package/engine-release.json +1 -1
- package/export-facts.mjs +71 -0
- package/log-session.mjs +15 -15
- package/package-release.json +1 -1
- package/package.json +36 -2
- package/remote-adapter-claude-code.mjs +111 -0
- package/remote-adapter-codex.mjs +119 -0
- package/remote-approval-bridge.mjs +122 -0
- package/remote-approvals.mjs +124 -0
- package/remote-attachments.mjs +129 -0
- package/remote-changes.mjs +94 -0
- package/remote-claude-events.mjs +212 -0
- package/remote-claude-progress.mjs +328 -0
- package/remote-cli.mjs +325 -0
- package/remote-coalesce.mjs +40 -0
- package/remote-codex-events.mjs +153 -0
- package/remote-daemon.mjs +205 -0
- package/remote-inventory.mjs +132 -0
- package/remote-journal.mjs +155 -0
- package/remote-pairing.mjs +104 -0
- package/remote-pipeline-config.mjs +177 -0
- package/remote-pipeline-parsers.mjs +121 -0
- package/remote-pipeline.mjs +234 -0
- package/remote-policy.mjs +199 -0
- package/remote-preview.mjs +146 -0
- package/remote-projects.mjs +87 -0
- package/remote-protocol.mjs +3881 -0
- package/remote-qr.mjs +175 -0
- package/remote-release-plans.mjs +88 -0
- package/remote-releases.mjs +297 -0
- package/remote-run.mjs +174 -0
- package/remote-service.mjs +101 -0
- package/remote-session-list.mjs +25 -0
- package/remote-sessions.mjs +348 -0
- package/remote-steered.mjs +114 -0
- package/remote-steering.mjs +97 -0
- package/remote-store.mjs +123 -0
- package/remote-transport.mjs +88 -0
- package/worktrust.mjs +13 -6
package/LICENSE
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
WorkTrust CLI Licence
|
|
2
2
|
|
|
3
|
-
Version 1.
|
|
4
|
-
Status: draft, subject to legal review.
|
|
3
|
+
Version 1.1, in force from WorkTrust CLI version 0.10.39 (7 November 2026).
|
|
5
4
|
|
|
6
|
-
Copyright (c) 2026
|
|
5
|
+
Copyright (c) 2026 Oravita B.V. (WorkTrust), registered with the Dutch Chamber of
|
|
7
6
|
Commerce (KvK) under number 98076051. All rights reserved.
|
|
8
7
|
|
|
9
8
|
1. What this licence covers
|
|
10
9
|
|
|
11
10
|
"The Software" means the WorkTrust command-line tool in every form in which
|
|
12
|
-
|
|
11
|
+
Oravita B.V. distributes it: the "worktrust" package on npm, the "worktrust"
|
|
13
12
|
package on PyPI, the scripts served from worktrust.io, the WorkTrust preservation
|
|
14
13
|
kit, and the files these install on a computer (including the WorkTrust mod for
|
|
15
|
-
Claude Code), together with their documentation
|
|
16
|
-
|
|
14
|
+
Claude Code), together with their documentation and their source code wherever
|
|
15
|
+
it is published, including the public repository github.com/fhomey/worktrust-cli
|
|
16
|
+
and any copy or fork of it. "You" means the person or organisation that obtains,
|
|
17
|
+
reads, installs or runs the Software.
|
|
18
|
+
|
|
19
|
+
By downloading, installing, running or reading the source code of the Software,
|
|
20
|
+
you accept this licence. If you do not accept it, do none of these things.
|
|
17
21
|
|
|
18
22
|
2. What you may do
|
|
19
23
|
|
|
20
|
-
|
|
24
|
+
Oravita B.V. grants the licences below free of charge. Each is non-exclusive,
|
|
21
25
|
non-transferable, non-sublicensable and revocable, and covers installing and
|
|
22
26
|
running the unmodified Software on computers you own or control.
|
|
23
27
|
|
|
@@ -40,10 +44,12 @@ running the unmodified Software on computers you own or control.
|
|
|
40
44
|
Software and run it to evaluate it.
|
|
41
45
|
|
|
42
46
|
You may make the copies needed to install and run the Software and a reasonable
|
|
43
|
-
number of backup copies. You may read the source code
|
|
44
|
-
what the Software does on your computer
|
|
45
|
-
to report a security problem as described in SECURITY.md. Being
|
|
46
|
-
source code gives you no other right
|
|
47
|
+
number of backup copies. You may read the source code for one purpose only: to
|
|
48
|
+
understand and check what the Software does on your computer. You may test it on
|
|
49
|
+
your own computer to report a security problem as described in SECURITY.md. Being
|
|
50
|
+
able to read the source code gives you no other right, and a copy or fork made on
|
|
51
|
+
a code-hosting platform (such as the fork that GitHub's terms allow on a public
|
|
52
|
+
repository) gives no right to use the code at all.
|
|
47
53
|
|
|
48
54
|
3. What you may not do
|
|
49
55
|
|
|
@@ -61,7 +67,23 @@ Except as section 2 allows or mandatory law permits, you may not:
|
|
|
61
67
|
f. remove or change any copyright notice, this licence or any other notice in
|
|
62
68
|
the Software; or
|
|
63
69
|
g. present a modified or rebuilt copy as the Software or as an official
|
|
64
|
-
WorkTrust release
|
|
70
|
+
WorkTrust release;
|
|
71
|
+
h. use the Software, its source code, its documentation, or anything you
|
|
72
|
+
learned from reading them, as a model, reference, template or starting point
|
|
73
|
+
for any software, product or service other than the WorkTrust service. This
|
|
74
|
+
includes reimplementing, porting, translating or rewriting it in another
|
|
75
|
+
programming language; reproducing its structure, sequence and organisation,
|
|
76
|
+
its protocols, message formats or interfaces; and giving it to another
|
|
77
|
+
person or to an AI system to do any of these things;
|
|
78
|
+
i. use any of the above to design, build, operate or improve a platform,
|
|
79
|
+
product or service of your own or of anyone else, whether or not it
|
|
80
|
+
competes with WorkTrust; or
|
|
81
|
+
j. allow or help anyone else to do anything this section forbids.
|
|
82
|
+
|
|
83
|
+
The Software may only be used for the WorkTrust service, in the ways section 2
|
|
84
|
+
describes. The restrictions in this section are contractual obligations: they
|
|
85
|
+
apply also where copyright alone would not prevent the act, and they bind anyone
|
|
86
|
+
who obtains the source code, from any source.
|
|
65
87
|
|
|
66
88
|
Nothing in this licence restricts what mandatory law allows a lawful user of a
|
|
67
89
|
computer program to do, including the acts permitted by Articles 5 and 6 of
|
|
@@ -69,20 +91,22 @@ Directive 2009/24/EC as implemented in the Dutch Copyright Act (Auteurswet).
|
|
|
69
91
|
|
|
70
92
|
4. Ownership and all rights reserved
|
|
71
93
|
|
|
72
|
-
The Software is licensed, not sold.
|
|
94
|
+
The Software is licensed, not sold. Oravita B.V. (WorkTrust) retains all right,
|
|
73
95
|
title and interest in the Software and keeps all rights that this licence does
|
|
74
96
|
not expressly grant. This licence grants no right to the name WorkTrust, its
|
|
75
97
|
logos or other marks.
|
|
76
98
|
|
|
77
99
|
The archives, reports and other files the Software produces from your own data
|
|
78
|
-
belong to you. This licence gives
|
|
100
|
+
belong to you. This licence gives Oravita B.V. no right to them; what you send to
|
|
79
101
|
the WorkTrust service is governed by the service's terms and privacy statement.
|
|
80
102
|
|
|
81
103
|
5. Earlier versions
|
|
82
104
|
|
|
83
105
|
Versions of the Software up to and including 0.10.17 were published under the MIT
|
|
84
106
|
licence. Those versions remain available under that licence for those versions
|
|
85
|
-
only.
|
|
107
|
+
only. Versions 0.10.18 up to and including 0.10.38 were published under version
|
|
108
|
+
1.0 of this licence. This version 1.1 applies to version 0.10.39 and every later
|
|
109
|
+
version.
|
|
86
110
|
|
|
87
111
|
6. Third-party components
|
|
88
112
|
|
|
@@ -103,10 +127,11 @@ https://worktrust.io/privacy. This licence grants no right to the service.
|
|
|
103
127
|
|
|
104
128
|
8. Termination
|
|
105
129
|
|
|
106
|
-
This licence ends automatically if you breach it.
|
|
130
|
+
This licence ends automatically if you breach it. Oravita B.V. may also end it by
|
|
107
131
|
notice, for example when it ends the WorkTrust service. When it ends, you must
|
|
108
132
|
stop using the Software and delete every copy you hold. Sections 3, 4, 9, 10 and
|
|
109
|
-
11 survive termination.
|
|
133
|
+
11 survive termination. A breach of section 3 entitles Oravtia B.V. to every remedy the
|
|
134
|
+
law provides, including an injunction and compensation for its damage.
|
|
110
135
|
|
|
111
136
|
9. No warranty
|
|
112
137
|
|
|
@@ -117,7 +142,7 @@ without interruption.
|
|
|
117
142
|
|
|
118
143
|
10. Limitation of liability
|
|
119
144
|
|
|
120
|
-
To the fullest extent the law allows,
|
|
145
|
+
To the fullest extent the law allows, Oravita B.V. is not liable for any damage
|
|
121
146
|
arising from or in connection with the Software or its use, whether in contract,
|
|
122
147
|
tort or otherwise, including loss of data, profit or business. This does not
|
|
123
148
|
limit liability for intent or deliberate recklessness, or any liability that
|
package/README.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# worktrust
|
|
2
2
|
|
|
3
|
+
## 0.11.0: steer your own agents from your phone
|
|
4
|
+
|
|
5
|
+
`npx worktrust remote` pairs this computer with the WorkTrust app and lets the phone steer the coding agents that run
|
|
6
|
+
here (Claude Code and Codex): start a chat in a project, choose the agent and its model from the ones this computer
|
|
7
|
+
reports, send photos and files into the project's inbox (at most 25 MB a file), approve what the agent asks, and follow
|
|
8
|
+
its work. Everything between the phone and this computer is sealed end to end; the relay passes it without reading it.
|
|
9
|
+
The local agent plans its own work with three tools on its session (a release, its tasks, their state and estimate), so
|
|
10
|
+
the phone's Status shows one table of what runs, what waits ("after release 22") and what ended. A session reports its
|
|
11
|
+
active time, the background jobs an agent left running, and, inside a git worktree, the repository it belongs to. A
|
|
12
|
+
local preview renders a dev server you allowed, as desktop, tablet or phone, with this computer's own browser. A phone
|
|
13
|
+
app from before this version cannot read what 0.11.0 sends: update both. What is measured for the passport is unchanged:
|
|
14
|
+
remote-steered sessions never count as your hours, and the measure rules stay 3.
|
|
15
|
+
|
|
16
|
+
## 0.10.38: an export says what it can about its own clock
|
|
17
|
+
|
|
18
|
+
`npx worktrust history --export` now sends, beside each run's timeline, the facts WorkTrust checks to tell an edited
|
|
19
|
+
ChatGPT or Claude-on-the-web export from one as the vendor made it: every model slug of the run (`models`), how many kept
|
|
20
|
+
steps are dated more than ten minutes before the step they follow (`tree_inversions`), and, for a ChatGPT conversation
|
|
21
|
+
whose id carries a clock, how far its creation time sits from that clock (`id_skew`). Once per export batch it sends the
|
|
22
|
+
export's envelope: its kind (a zip, several zips, a folder or a bare file), the moment the vendor's zip name gives, the
|
|
23
|
+
first and last write time of its conversations entries, its last message, and whether its shape is the vendor's (no extra
|
|
24
|
+
field but zip64's, no data descriptor, no Finder litter, parts in order). Never a conversation's id, title or text, never
|
|
25
|
+
the archive's file name. A line whose clock does not hold up goes to Review with its reason named, never refused or
|
|
26
|
+
deleted; a re-zipped export alone is only a label. Lines that arrived from 0.10.37 or older are not judged again. One new
|
|
27
|
+
module, `export-facts.mjs`. What is measured is unchanged: the measure rules stay 3.
|
|
28
|
+
|
|
3
29
|
## 0.10.37: an export arrives whole; progress, Ctrl+C and the reason in WorkTrust's words; CLI active and updating itself
|
|
4
30
|
|
|
5
31
|
An export send no longer stops at WorkTrust's upload budget per minute: the person's own send waits it out (at most 90
|
|
@@ -684,6 +710,34 @@ does not offer its earlier work. Other retained files and your local evidence ar
|
|
|
684
710
|
automatic server or archive erasure.
|
|
685
711
|
Then revoke the key in WorkTrust: Sources → Devices → this computer → Revoke.
|
|
686
712
|
|
|
713
|
+
## Remote agents: steer this computer's agents from your phone (`npx worktrust remote`, not yet released)
|
|
714
|
+
|
|
715
|
+
Off until you run `npx worktrust remote enable` at this keyboard; an AI agent's shell is refused every `remote` command
|
|
716
|
+
except `status`.
|
|
717
|
+
|
|
718
|
+
- `enable` makes a REMOTE key pair for this computer (Ed25519 and X25519, files of mode 0600 in `~/.worktrust/remote/`),
|
|
719
|
+
never the measurement key, and has it approved in WorkTrust with your second factor; then it starts a service while you
|
|
720
|
+
are logged in (launchd on macOS, a systemd user unit on Linux, linger off; on Windows `npx worktrust remote run` in a
|
|
721
|
+
terminal) and draws a QR code for the WorkTrust app. `pair` draws a new one: five minutes, one phone, once. A phone
|
|
722
|
+
that scanned it is confirmed; one that typed the code instead waits for `npx worktrust remote phones confirm`.
|
|
723
|
+
- `projects add <folder>` grants a folder (its real path; never your home folder, the disk's root or a folder holding
|
|
724
|
+
keys, keychains, browser profiles or wallets). A phone starts agents only in granted folders, several at once (four by
|
|
725
|
+
default).
|
|
726
|
+
- From a phone you may approve: a file edit inside the project, a test, build or lint command from a short reviewed list,
|
|
727
|
+
and a message an agent sends through a connector, shown whole (channel, every recipient, subject, text, attachment
|
|
728
|
+
names). Everything else is decided at this keyboard or not at all: installs from the network, `git push`, deploys,
|
|
729
|
+
deleting outside the project, reading secret files, any "always allow". It is denied on this computer, and the phone is
|
|
730
|
+
told why.
|
|
731
|
+
- One outbound connection to the WorkTrust gateway, end-to-end encrypted: the gateway relays sealed messages and reads no
|
|
732
|
+
prompt, file, path, output or model name. No port is opened on this computer.
|
|
733
|
+
- A session steered from a phone is never your AI Hours: the service records it in `~/.worktrust/remote/steered.jsonl`
|
|
734
|
+
before the agent starts, and the session hook sends it as an agent run (`session_kind` headless, `steered_from`
|
|
735
|
+
remote).
|
|
736
|
+
- `status`, `pause`, `resume`, `disable` (the hard off; `--forget` also deletes the remote keys), `phones`, `projects`.
|
|
737
|
+
|
|
738
|
+
Remote needs Node 22.4 or later (the Python package bundles one). The production gateway is not live yet; nothing
|
|
739
|
+
connects until one is set.
|
|
740
|
+
|
|
687
741
|
## Requirements
|
|
688
742
|
|
|
689
743
|
Node 18 or later for the base CLI. SQLite session readers require Node 22.5 or later with `node:sqlite`;
|
|
@@ -696,11 +750,14 @@ Security reports: see [SECURITY.md](SECURITY.md).
|
|
|
696
750
|
|
|
697
751
|
## Licence
|
|
698
752
|
|
|
699
|
-
Use is allowed under the WorkTrust CLI Licence; copying, modifying or redistributing the
|
|
753
|
+
Use is allowed under the WorkTrust CLI Licence, for the WorkTrust service only; copying, modifying or redistributing the
|
|
754
|
+
code is not, and neither is using it, or what you learned from reading it, as a model for any other product or
|
|
755
|
+
platform (rewriting, porting or translating it included). See LICENSE.
|
|
700
756
|
The licence is free of charge. `preserve` (with `--apply`, `--archive`, `--verify` and `--summary`) is for everyone,
|
|
701
757
|
with or without an account; every other feature is for WorkTrust account holders, and without an account the rest may
|
|
702
758
|
only be installed and evaluated. The archives and files the CLI makes from your own data are yours.
|
|
703
|
-
|
|
759
|
+
Version 1.1 of the licence applies from 0.10.39; 0.10.18 to 0.10.38 were published under version 1.0; versions up to and
|
|
760
|
+
including 0.10.17 were published under the MIT licence and stay under it.
|
|
704
761
|
|
|
705
762
|
## Release signatures and the limits of verification
|
|
706
763
|
|
package/SECURITY.md
CHANGED
|
@@ -209,6 +209,31 @@ the platform keeps only the listed keys, from a CLI key alone, and shows them to
|
|
|
209
209
|
`worktrust mod remove` and `worktrust disconnect` take it out of the settings and delete the plugin
|
|
210
210
|
and its counts.
|
|
211
211
|
|
|
212
|
+
## Remote agents (`npx worktrust remote`, not yet released)
|
|
213
|
+
|
|
214
|
+
What it is: standing remote execution of AI agents on this computer, steered from a confirmed phone. Its limits:
|
|
215
|
+
|
|
216
|
+
- Separate key, separate audience. The remote keys (`~/.worktrust/remote/remote-keys.json`, 0600) are not the measurement
|
|
217
|
+
key and no remote module reads the measurement credentials (`scripts/check-remote-cli.mjs` refuses one that names them).
|
|
218
|
+
Bindings are verified against issuer keys pinned in the release; a test-only issuer key is honoured only for a gateway on
|
|
219
|
+
this computer's loopback.
|
|
220
|
+
- Controllers are confirmed here. A phone becomes a controller by scanning the QR this terminal draws (its secret proves
|
|
221
|
+
it saw this screen and is mixed into the first handshake) or by a typed code confirmed at this keyboard. The issuer alone
|
|
222
|
+
cannot add a controller. `remote phones remove` drops one at once.
|
|
223
|
+
- The gateway reads no content: commands and events are sealed between the phone and this computer (XChaCha20-Poly1305
|
|
224
|
+
under keys from an authenticated X25519 handshake). The gateway sees ids, message types, times and size classes.
|
|
225
|
+
- At most once. Every command is written to `~/.worktrust/remote/journal.jsonl` and flushed to disk before an agent runs; a
|
|
226
|
+
repeat is answered from the journal, and a command an interrupted daemon left mid-way is closed as failed, never run again.
|
|
227
|
+
- Approvals are classified on this computer. Only project edits, the reviewed test, build and lint commands, and outward
|
|
228
|
+
messages shown whole can be approved from a phone, each by a signed decision bound to the exact action, single use,
|
|
229
|
+
five minutes at most; offline or no answer is a denial. Claude Code also gets deny rules for pushes, installs, deploys
|
|
230
|
+
and secret reads, and loads only your user settings, so a repository's own rules or hooks do not apply remotely.
|
|
231
|
+
- What it does not stop: an approved test command runs the project's own test code, which can do what that code does;
|
|
232
|
+
grant only folders whose code you trust. The phone's keys are on the phone: until you revoke it, whoever unlocks it can
|
|
233
|
+
steer agents within these rules. macOS asks for folder access per program, so the access you grant the service's `node`
|
|
234
|
+
covers every script that `node` runs.
|
|
235
|
+
- Hours. A remote-steered session is never your AI Hours (see README).
|
|
236
|
+
|
|
212
237
|
## Python distribution and explicit agent observations
|
|
213
238
|
|
|
214
239
|
The official [PyPI package](https://pypi.org/project/worktrust/) runs the same measurement
|
package/chat-exports.mjs
CHANGED
|
@@ -32,7 +32,7 @@ import { once } from "node:events";
|
|
|
32
32
|
import { existsSync, openSync, readSync, closeSync, fstatSync, readdirSync, statSync, constants } from "node:fs";
|
|
33
33
|
import { homedir } from "node:os";
|
|
34
34
|
import { basename, dirname, join } from "node:path";
|
|
35
|
-
import { createInflateRaw } from "node:zlib";
|
|
35
|
+
import { createInflateRaw } from "node:zlib"; const { newShape = () => null, noteShape = () => {}, mergeShapes = () => null, inversionsOf = () => null, idSkewOf = () => null, envelopeOf = () => null } = (await import("./export-facts.mjs").catch(() => null)) ?? {}; // 0.10.38: what the export says of its own clock (counts, booleans, instants); a copy without the module sends none of it, as an older CLI
|
|
36
36
|
|
|
37
37
|
/** The two vendors, by the client name the door reads as their product (chatgpt → chatgpt_web, claude-web → claude_web). */
|
|
38
38
|
export const EXPORT_CLIENTS = ["chatgpt", "claude-web"];
|
|
@@ -112,8 +112,8 @@ function zipEntries(path, accept) {
|
|
|
112
112
|
for (let at = tail.length - 22; at >= 0; at -= 1) if (tail.readUInt32LE(at) === 0x06054b50 && at + 22 + tail.readUInt16LE(at + 20) === tail.length) { eocd = at; break; }
|
|
113
113
|
if (eocd < 0) {
|
|
114
114
|
if (size < 30 || readAt(0, 4).readUInt32LE(0) !== LOCAL) throw Error(`not a zip archive: ${path}`);
|
|
115
|
-
const { selected, cut } = walkLocal(path, size, readAt, accept);
|
|
116
|
-
return { parts: entryParts(path, selected, size, readAt, chunksOf, true), close, cut };
|
|
115
|
+
const { selected, cut, shape } = walkLocal(path, size, readAt, accept);
|
|
116
|
+
return { parts: entryParts(path, selected, size, readAt, chunksOf, true), close, cut, shape };
|
|
117
117
|
}
|
|
118
118
|
const endAt = size - tailLength + eocd;
|
|
119
119
|
let entries = tail.readUInt16LE(eocd + 10), directorySize = tail.readUInt32LE(eocd + 12), directoryAt = tail.readUInt32LE(eocd + 16), directoryEnd = endAt;
|
|
@@ -136,7 +136,7 @@ function zipEntries(path, accept) {
|
|
|
136
136
|
damaged(directoryAt + directorySize === directoryEnd);
|
|
137
137
|
const directory = readAt(directoryAt, directorySize);
|
|
138
138
|
let at = 0;
|
|
139
|
-
const selected = new Map();
|
|
139
|
+
const selected = new Map(), shape = newShape();
|
|
140
140
|
for (let index = 0; index < entries; index += 1) {
|
|
141
141
|
damaged(at + 46 <= directory.length && directory.readUInt32LE(at) === 0x02014b50);
|
|
142
142
|
const method = directory.readUInt16LE(at + 10);
|
|
@@ -144,7 +144,7 @@ function zipEntries(path, accept) {
|
|
|
144
144
|
const nameLength = directory.readUInt16LE(at + 28), extraLength = directory.readUInt16LE(at + 30), commentLength = directory.readUInt16LE(at + 32);
|
|
145
145
|
const flags = directory.readUInt16LE(at + 8), disk = directory.readUInt16LE(at + 34);
|
|
146
146
|
damaged(at + 46 + nameLength + extraLength + commentLength <= directory.length);
|
|
147
|
-
const name = directory.toString("utf8", at + 46, at + 46 + nameLength), extra = directory.subarray(at + 46 + nameLength, at + 46 + nameLength + extraLength);
|
|
147
|
+
const name = directory.toString("utf8", at + 46, at + 46 + nameLength), extra = directory.subarray(at + 46 + nameLength, at + 46 + nameLength + extraLength); noteShape(shape, name, flags, extra, directory.readUInt16LE(at + 14), directory.readUInt16LE(at + 12), accept(basename(name)) && !name.endsWith("/") ? partOf(basename(name)) : null);
|
|
148
148
|
at += 46 + nameLength + extraLength + commentLength;
|
|
149
149
|
if (!accept(basename(name)) || name.endsWith("/")) continue;
|
|
150
150
|
if (compressed === U32 || uncompressed === U32 || localAt === U32) [uncompressed, compressed, localAt] = zip64Extra(extra, [uncompressed, compressed, localAt]);
|
|
@@ -153,7 +153,7 @@ function zipEntries(path, accept) {
|
|
|
153
153
|
selected.set(basename(name), { name, method, flags, compressed, uncompressed, localAt });
|
|
154
154
|
}
|
|
155
155
|
damaged(at === directory.length);
|
|
156
|
-
return { parts: entryParts(path, selected, directoryAt, readAt, chunksOf, false), close, cut: null };
|
|
156
|
+
return { parts: entryParts(path, selected, directoryAt, readAt, chunksOf, false), close, cut: null, shape };
|
|
157
157
|
} catch (error) { close(); throw error; }
|
|
158
158
|
}
|
|
159
159
|
const LOCAL = 0x04034b50, U32 = 0xffffffff;
|
|
@@ -200,7 +200,7 @@ function entryParts(path, selected, end, readAt, chunksOf, walked) {
|
|
|
200
200
|
* refuses the export by that entry's name; otherwise what was read is handed over WITH the cut (`cut`), never as the whole.
|
|
201
201
|
*/
|
|
202
202
|
function walkLocal(path, size, readAt, accept) {
|
|
203
|
-
const selected = new Map();
|
|
203
|
+
const selected = new Map(), shape = newShape();
|
|
204
204
|
let at = 0, walked = 0, where = null;
|
|
205
205
|
for (;;) {
|
|
206
206
|
if (at === size) { where = "at the end of an entry"; break; }
|
|
@@ -215,7 +215,7 @@ function walkLocal(path, size, readAt, accept) {
|
|
|
215
215
|
let compressed = local.readUInt32LE(18), uncompressed = local.readUInt32LE(22);
|
|
216
216
|
const wide = compressed === U32 || uncompressed === U32;
|
|
217
217
|
if (wide) [uncompressed, compressed] = zip64Extra(extra, [U32, U32]);
|
|
218
|
-
const wanted = accept(basename(name)) && !name.endsWith("/"), dataAt = at + 30 + nameLength + extraLength;
|
|
218
|
+
const wanted = accept(basename(name)) && !name.endsWith("/"), dataAt = at + 30 + nameLength + extraLength; noteShape(shape, name, flags, extra, local.readUInt16LE(12), local.readUInt16LE(10), wanted ? partOf(basename(name)) : null);
|
|
219
219
|
if ((flags & 8) && compressed === 0 && uncompressed === 0) {
|
|
220
220
|
if (wanted) throw Error(`${basename(name)} in ${path} carries no length in its header and the archive has no directory: it cannot be read without one`);
|
|
221
221
|
where = "at an entry whose header carries no length"; break;
|
|
@@ -238,7 +238,7 @@ function walkLocal(path, size, readAt, accept) {
|
|
|
238
238
|
}
|
|
239
239
|
if (selected.size === 0) throw Error(`${path} is cut off (no directory at its end) and holds no whole conversations part before the cut: download the export again`);
|
|
240
240
|
const names = [...selected.keys()].sort(byPart);
|
|
241
|
-
return { selected, cut: { size, at, where, entries: walked, parts: names.length, first: names[0], last: names.at(-1) } };
|
|
241
|
+
return { selected, shape, cut: { size, at, where, entries: walked, parts: names.length, first: names[0], last: names.at(-1) } };
|
|
242
242
|
}
|
|
243
243
|
/** Numbered parts run without a gap: a part missing from the middle of the run is a partial export, never read as the whole. */
|
|
244
244
|
function contiguous(names, where, fromZero = false) {
|
|
@@ -266,9 +266,9 @@ const refuseOther = (path) => { const other = OTHER_PART.exec(basename(path)); i
|
|
|
266
266
|
/** One conversations zip: its conversations entries, or a refusal that names the zip. */
|
|
267
267
|
function zipParts(path, given) {
|
|
268
268
|
refuseOther(path);
|
|
269
|
-
const { parts, close, cut } = zipEntries(path, (name) => CONVERSATIONS_ENTRY.test(name));
|
|
269
|
+
const { parts, close, cut, shape } = zipEntries(path, (name) => CONVERSATIONS_ENTRY.test(name));
|
|
270
270
|
if (parts.length === 0) { close(); throw Error(`no ${FILE} in ${given}`); }
|
|
271
|
-
return { parts, close, cuts: cut ? [cut] : [] };
|
|
271
|
+
return { parts, close, cuts: cut ? [cut] : [], envelope: { kind: "zip", name: basename(path), shape } };
|
|
272
272
|
}
|
|
273
273
|
/** A folder's conversations zips (conversations-000.zip, -001.zip …), in part order; nothing else of the folder is read. */
|
|
274
274
|
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)); };
|
|
@@ -300,7 +300,7 @@ function zipsParts(zips, given) {
|
|
|
300
300
|
for (const zip of zips) opened.push(zipParts(zip, given));
|
|
301
301
|
const parts = opened.flatMap((one) => one.parts);
|
|
302
302
|
limit(parts.length <= EXPORT_LIMITS.parts && parts.reduce((sum, part) => sum + part.bytes, 0) <= EXPORT_LIMITS.fileBytes, "conversations parts");
|
|
303
|
-
return { parts, close: () => { for (const one of opened) one.close(); }, cuts: opened.flatMap((one) => one.cuts) };
|
|
303
|
+
return { parts, close: () => { for (const one of opened) one.close(); }, cuts: opened.flatMap((one) => one.cuts), envelope: { kind: "zips", name: null, shape: mergeShapes(opened.map((one) => one.envelope.shape)) } };
|
|
304
304
|
} catch (error) { for (const one of opened) one.close(); throw error; }
|
|
305
305
|
}
|
|
306
306
|
/**
|
|
@@ -320,7 +320,7 @@ function looseParts(dir, given) {
|
|
|
320
320
|
try {
|
|
321
321
|
for (const name of names) { const path = join(dir, name); opened.push({ path, file: openExport(path, EXPORT_LIMITS.fileBytes) }); }
|
|
322
322
|
limit(opened.reduce((sum, one) => sum + one.file.size, 0) <= EXPORT_LIMITS.fileBytes, "conversations parts");
|
|
323
|
-
return { parts: opened.map(({ path, file }) => ({ path, bytes: file.size, chunks: () => file.chunksOf(0, file.size, file.size) })), close: () => { for (const one of opened) one.file.close(); }, cuts: [] };
|
|
323
|
+
return { parts: opened.map(({ path, file }) => ({ path, bytes: file.size, chunks: () => file.chunksOf(0, file.size, file.size) })), close: () => { for (const one of opened) one.file.close(); }, cuts: [], envelope: { kind: "folder" } };
|
|
324
324
|
} catch (error) { for (const one of opened) one.file.close(); throw error; }
|
|
325
325
|
}
|
|
326
326
|
|
|
@@ -343,7 +343,7 @@ function exportParts(given) {
|
|
|
343
343
|
let manifest;
|
|
344
344
|
try {
|
|
345
345
|
// A json holding an object, not an array of conversations, may be the vendor's manifest: read for its conversations parts alone.
|
|
346
|
-
if (basename(path) === FILE || file.size > EXPORT_LIMITS.manifestBytes || !/^\s*\{/.test(file.readAt(0, Math.min(64, file.size)).toString("utf8"))) return { parts: [{ path, bytes: file.size, chunks: () => file.chunksOf(0, file.size, file.size) }], close: file.close };
|
|
346
|
+
if (basename(path) === FILE || file.size > EXPORT_LIMITS.manifestBytes || !/^\s*\{/.test(file.readAt(0, Math.min(64, file.size)).toString("utf8"))) return { parts: [{ path, bytes: file.size, chunks: () => file.chunksOf(0, file.size, file.size) }], close: file.close, envelope: { kind: stat.isDirectory() ? "folder" : "json" } };
|
|
347
347
|
try { manifest = JSON.parse(file.readAt(0, file.size).toString("utf8")); } catch { throw Error(`export unreadable: ${path}`); }
|
|
348
348
|
} catch (error) { file.close(); throw error; }
|
|
349
349
|
file.close();
|
|
@@ -618,7 +618,7 @@ const transcriptLine = ({ type, timestamp, model, text }) => ({ type, timestamp,
|
|
|
618
618
|
async function* exportRecords(given, { expect = null, excluded = () => false, skipped = null, text = false, report = null, metadata = false } = {}) {
|
|
619
619
|
if (metadata && text) throw Error("an export's metadata is counted without the text, never with it");
|
|
620
620
|
const totals = {};
|
|
621
|
-
const { parts, close, cuts = [] } = exportParts(given);
|
|
621
|
+
const { parts, close, cuts = [], envelope = null } = exportParts(given);
|
|
622
622
|
const path = parts[0].path, digest = createHash("sha256");
|
|
623
623
|
let vendor = null, count = 0, oversized = 0, empty = 0, bytes = 0, next = PROGRESS_BYTES, offset = 0, tick = 0, at = 0; const size = parts.reduce((n, one) => n + (Number(one.bytes) || 0), 0);
|
|
624
624
|
if (report) { report.path = path; report.vendor = expect; report.digest = null; report.conversations = 0; report.oversized = 0; report.empty = 0; report.parts = parts.length; report.cut = cuts.length > 0 ? cuts : null; }
|
|
@@ -636,7 +636,7 @@ async function* exportRecords(given, { expect = null, excluded = () => false, sk
|
|
|
636
636
|
if (report) report.vendor = vendor;
|
|
637
637
|
const title = String((vendor === "chatgpt" ? kept.title : kept.name) ?? "");
|
|
638
638
|
if (excluded(title)) { skipped?.push(title.slice(0, 40)); return { vendor, excluded: true, lines: [] }; }
|
|
639
|
-
const record = { vendor, id: String((vendor === "chatgpt" ? kept.conversation_id ?? kept.id : kept.uuid) ?? `#${index}`), lines: vendor === "chatgpt" ? chatgptLines(kept, text) : claudeLines(kept, text) };
|
|
639
|
+
const record = { vendor, id: String((vendor === "chatgpt" ? kept.conversation_id ?? kept.id : kept.uuid) ?? `#${index}`), lines: vendor === "chatgpt" ? chatgptLines(kept, text) : claudeLines(kept, text) }; record.clock = { inversions: inversionsOf(record.lines), ...(vendor === "chatgpt" ? { idSkew: idSkewOf(String(kept.conversation_id ?? kept.id ?? ""), kept.create_time) } : {}) }; // 0.10.38: counts and a skew, never the id
|
|
640
640
|
if (metadata) { record.metadata = vendor === "chatgpt" ? chatgptMetadata(kept) : null; for (const counts of Object.values(record.metadata ?? {})) addCounts(totals, counts); } // a Claude export carries no such fields: null, never zeros
|
|
641
641
|
return record;
|
|
642
642
|
};
|
|
@@ -662,7 +662,7 @@ async function* exportRecords(given, { expect = null, excluded = () => false, sk
|
|
|
662
662
|
}
|
|
663
663
|
} finally { close(); }
|
|
664
664
|
if (vendor === null && empty > 0) throw Error(`${path} is neither a ChatGPT nor a Claude export (or mixes the two)`);
|
|
665
|
-
report?.onProgress?.({ part: at, parts: parts.length, bytes, size, conversations: count }); if (report) { report.vendor = vendor ?? expect; report.digest = digest.digest("hex"); report.conversations = count; report.oversized = oversized; report.empty = empty; if (metadata) report.metadata = vendor === "chatgpt" ? totals : null; }
|
|
665
|
+
report?.onProgress?.({ part: at, parts: parts.length, bytes, size, conversations: count }); if (report) { report.vendor = vendor ?? expect; report.digest = digest.digest("hex"); report.envelope = envelopeOf(envelope, vendor ?? expect); report.conversations = count; report.oversized = oversized; report.empty = empty; if (metadata) report.metadata = vendor === "chatgpt" ? totals : null; }
|
|
666
666
|
}
|
|
667
667
|
|
|
668
668
|
/** One export, read whole but compact: its vendor by shape, one record per conversation (its kept lines; none for an excluded or oversized one), and the digest of its bytes (what `sent` is remembered by). */
|
|
@@ -674,7 +674,7 @@ export async function readExport(given, expect = null, { excluded = () => false,
|
|
|
674
674
|
limit(kept <= EXPORT_LIMITS.keptBytes, "kept bytes");
|
|
675
675
|
conversations.push(record);
|
|
676
676
|
}
|
|
677
|
-
return { vendor: report.vendor, conversations, digest: report.digest, path: report.path, parts: report.parts, oversized: report.oversized, empty: report.empty, cut: report.cut, ...(metadata ? { metadata: report.metadata } : {}) };
|
|
677
|
+
return { vendor: report.vendor, conversations, digest: report.digest, path: report.path, parts: report.parts, oversized: report.oversized, empty: report.empty, cut: report.cut, envelope: report.envelope ?? null, ...(metadata ? { metadata: report.metadata } : {}) };
|
|
678
678
|
}
|
|
679
679
|
|
|
680
680
|
/**
|
|
@@ -686,9 +686,9 @@ export async function readExport(given, expect = null, { excluded = () => false,
|
|
|
686
686
|
*/
|
|
687
687
|
export async function* exportSessions(given, { expect = null, excluded = () => false, skipped = null, text = false, report = null, metadata = false } = {}) {
|
|
688
688
|
const records = typeof given === "string" ? exportRecords(given, { expect, excluded, skipped, text, report, metadata }) : given.conversations;
|
|
689
|
-
for await (const { vendor, id, lines, metadata: counts = null } of records) {
|
|
689
|
+
for await (const { vendor, id, lines, clock = null, metadata: counts = null } of records) {
|
|
690
690
|
if (lines.length === 0) continue; // excluded, left out as too large, or without a message
|
|
691
|
-
yield { key: `${vendor === "chatgpt" ? "chatgpt" : "claude.ai"}:${id}`, projectDir: vendor === "chatgpt" ? "chatgpt" : "claude-ai", basename: vendor === "chatgpt" ? "chatgpt" : "claude.ai", vendor, id, lines: lines.map(transcriptLine), ...(metadata ? { metadata: counts } : {}) };
|
|
691
|
+
yield { key: `${vendor === "chatgpt" ? "chatgpt" : "claude.ai"}:${id}`, projectDir: vendor === "chatgpt" ? "chatgpt" : "claude-ai", basename: vendor === "chatgpt" ? "chatgpt" : "claude.ai", vendor, id, lines: lines.map(transcriptLine), clock, ...(metadata ? { metadata: counts } : {}) };
|
|
692
692
|
}
|
|
693
693
|
}
|
|
694
694
|
|
package/engine-release.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"chat-exports.mjs":"
|
|
1
|
+
{"keyId":"608168ccdef72562fc91f9c0f9f2c2d6876bece7f7362cb545b818f7947da6b5","payload":{"files":{"chat-exports.mjs":"f026c5a063f62c22ba6f25474a9d9fdbb6074beebbfe1faff2a876c437a1a000","claude-mod.mjs":"02d86b0cdddf39879efc5194c0a5be6b41456faedec28963dc123a4e88dc3942","commit-rules.mjs":"e94cc32a5415f6d9e978145ab9505ac4ae0bac9431e6e9104b9b37155260b51f","config-edits.mjs":"527a7674f9d52b284bfda3b8089eb4b930a709bf14aedbec7f6eef1e59ef52ee","count-behaviour.mjs":"179baf829eda488bab3f17ae6917473ec01d0d6346f47de7bc144351274f19c8","credential-store.mjs":"a4b3540a61f4ce19e535c7f1d260c0d817686cd066d559a76db2ab108144abba","credential-vault-scripts.mjs":"7e42fe1db3885c2dec6f1de87bebfbefe2292d29179a68f3da87d19eb6c7704b","credential-vault.mjs":"279baabb217e2a3f170e8d7f2b271a88484531f9031c441360ea91561a70da99","export-facts.mjs":"3bbb46c80e8678b5cea7e15dcbfc456a2b48595053241c2b3cea508092f9b917","git-commits.mjs":"f9c084c54937a86df8fe30a0db2a58e04eeef0dbae69c54b8e368efc9964d6d8","history-outbox.mjs":"85c70389effc5b4ec9d9b33af9192314e67f47af2752515b42a7959344ce2354","history-progress.mjs":"dcc25ee94b727f2605a763349a4d8764640335d6cf0043fb6108cebeed16dcb9","log-session.mjs":"eb3bc0972bc30788521a492e136ed792d8265e0c5b8aede81fec4f3e071a25d0","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":"cd111cae0f53a25a2d878a158479abfb1ace353361454843f91a16d241101d46","remote-adapter-claude-code.mjs":"fe11c7fd37b570404e90fe53c11b471c2b5f114e8616bcdc281792cb000ecaf4","remote-adapter-codex.mjs":"44c41bc92a12ea6aa2232d67ba4a02f335aaea1429816e9a9e3eb3911a97cb3a","remote-approval-bridge.mjs":"9661bb2d698aed1c788246506e842dfaa4507d5357e454bf67b5b4b65da1621d","remote-approvals.mjs":"c033f36d261b3a5be552c9b02f92f30bd7217c8a1a55116fb514acb61e198c6f","remote-attachments.mjs":"2e9c1277329a45cf26c0c62abda632cf0ab9fad78d0504416ecee9805220e16c","remote-changes.mjs":"2141fece4961a5bc1bb1b046f78222812617457b1ba6452275eac6a897e62e19","remote-claude-events.mjs":"58822471203c6a1b66cf81c115c4d713657c3dea5c7b98df959f894ee5b2e704","remote-claude-progress.mjs":"2ca626d3dbc16d8d570abe1df6477b7e44ffb43c1d9145228ec5ea1928e415ca","remote-cli.mjs":"85a6b26e332f6b89584edfa58bff6d753918cc391ca62bb02b9f344b0508db37","remote-coalesce.mjs":"cb0967d9cfe81e3892bcade8349d6814db98be8c2adbdb54df0b8d1b142f65d1","remote-codex-events.mjs":"58657d6070a50c837737cb85f5a1eaf9c2cbc4e1adfe3e970748ab3b2af94631","remote-daemon.mjs":"c22eec13da604d262c116a7a389555dae8a3b68fd9de7df44dad178f3ea0ec63","remote-inventory.mjs":"d5a1c0180bab5c0522e73c913876050b9b36eb9ed06a8fa0e8e258ce54b67282","remote-journal.mjs":"907ebd48c53162b22dc743ef95b53c1a6be6886a7495605b5cfa820b8de9d330","remote-pairing.mjs":"ae03427b6510e52da08aaf9387d5e08516ee25380c7efa420432f4e1e936a7c5","remote-pipeline-config.mjs":"00cde6a61ce21144c51ac56fce42fee159aa9dba6586218a7ea790ce4a6bd40b","remote-pipeline-parsers.mjs":"43ca0d332d7bc883c4759a754a555815ae5dfe133446b91ba9f2e48a350fa20f","remote-pipeline.mjs":"b856ead989b29ddb618ef69bbacd104bae2b02c9d1c5214291d08ce469a8b24e","remote-policy.mjs":"aacf7578537021ab3849095bb1f58f0ed12c453c6ca2ab1352a1716fb13b0ca4","remote-preview.mjs":"fe504ad6f83dcb4a4ebdcc018686a9a5a900c47cdf8c45b75e7d02e2f3056155","remote-projects.mjs":"d07997167d1f51139ff010c8753639e48c5cd33688568459e184eabb12bfff84","remote-protocol.mjs":"f0beb91750397d1c6f0042fe716413cf8027684a84d4ed17bccee996cc5e2544","remote-qr.mjs":"b80e2b4a5bc020cf6ed92e91d06b327cb5197de1c35b3445a0fc2c7a3bf1ab3f","remote-release-plans.mjs":"11884a62b7d6dcccb5e154a26603bdf650f7b40f946329fb174d8c13729bec74","remote-releases.mjs":"fb08b72593ea00013c8b679e0c0d7dee95b0fd7cc5fd31b80ac575d0e340927d","remote-run.mjs":"914af621d768abd126adda479f5ee7d52f3ed93c17897ab184c7116980b299e2","remote-service.mjs":"1b9d4ecf99b667f2ab7c78fe1dfd5cf507cbb36c5bcad15bfa2a88c313ae758e","remote-session-list.mjs":"0fc1e9df7997e28c8c9a63d3ae63347120fa91238b82ee05c1041b1e9d297ebd","remote-sessions.mjs":"24e24d0e574c40049edd7ae11d4cc98965f2a962bbd59c642a0ea7d6b74f5171","remote-steered.mjs":"fbbd3685a8cd497ae03235d258e2116e2129aac19046759fb2468fe79911f0b3","remote-steering.mjs":"7ba22e6110cea3ac75a4f084f8f92a5bd90c31a19d3ce58a88a0843bdadea834","remote-store.mjs":"c68fd7b55d857cd4c06d0e53a5989c4f20e7f8e7add5e18443b3c16d864cabd1","remote-transport.mjs":"68650fd77ea09b5762377f87cabdc1c73a34d77324aa5bf0cd9742094a50c32b","runtime-install.mjs":"aab47b52c79d726ef428a24f982c648fa3f1c2dc2b574f633611d02924864e5f","self-update.mjs":"378e3620d48c72cf0bf812be408883b995cdb2223de34a20f762dd73eeffb258","session-databases.mjs":"b9fe20d7445205bdbf4cf2eaaf9cc770dad01e23d41e644b04930ca34e10426d","setup-mcp.mjs":"b732e3dd9b3e522b7cc8acf167ce28ba8f1a8dee797ee15bd7c3b02919b13e6f","stack-rules.mjs":"b23c56e72ec56ba02b17ed895f869172d988c468a697e8d6026b0e268f61e489","stretch-evidence.mjs":"5f5667b92adf11b1a5a6330a0f26dd6db73d56fe60823d9a5246dab71d27d380","transcript-readers.mjs":"e9f20415c2b5d62a09f35a63075002ebd1da56edb32f242d52822d58ecbd8ac3","worktrust-launch.mjs":"84801bd29d472d48188c126b9ebe3989a3132b54e13cc4fe534ff7c383a294ee","worktrust.mjs":"5321c67b7bb0699780a155d87473a4975ef81e47deada06f7d5b5bde9a973f98"},"format":"worktrust-package/1","kind":"engine","version":"0.11.0"},"signature":"XUqwPAZcSahQg_tFdNCH6CNIf6IB_pas98SfH_-aNjmJQLNIcRk07tpLiUc31LhKXbUsyuEzQ8sO7eHrKUYQBQ"}
|
package/export-facts.mjs
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WHAT AN EXPORT SAYS ABOUT ITS OWN CLOCK (CLI 0.10.38; owner 2026-11-06, export plausibility). chat-exports.mjs reads a ChatGPT
|
|
3
|
+
* or Claude-on-the-web export; these pure helpers turn what it passes on the way into counts, booleans and instants that
|
|
4
|
+
* WorkTrust checks on arrival (packages/core/src/export-plausibility.ts). Never a conversation's id, title or text, never the
|
|
5
|
+
* archive's file name or the name's other parts: only the facts below leave this computer.
|
|
6
|
+
*
|
|
7
|
+
* newShape() / noteShape(…) the archive's shape as its entries are walked: an extra field other than zip64's, a data
|
|
8
|
+
* descriptor, Finder's litter (__MACOSX, .DS_Store), conversations parts out of order, and the
|
|
9
|
+
* conversations entries' first and last DOS write time (a DOS time has no zone: read as UTC)
|
|
10
|
+
* mergeShapes(shapes) one shape for an export split over several zips
|
|
11
|
+
* inversionsOf(lines) kept steps dated more than ten minutes before the step they follow (none in 5,003 real ones)
|
|
12
|
+
* idSkewOf(id, created) ChatGPT: a v8 conversation id's first 32 bits are the second it was minted (since 2024-09); the
|
|
13
|
+
* conversation's create_time minus that second, whole seconds; a v4 id has no clock (null)
|
|
14
|
+
* envelopeOf(envelope, vendor) the batch's envelope: the archive's kind, the moment a vendor's file name gives, the write
|
|
15
|
+
* times and the shape's booleans; a folder or a bare JSON says its kind alone
|
|
16
|
+
*/
|
|
17
|
+
const dosTime = (date, time) => {
|
|
18
|
+
const month = (date >> 5) & 15, day = date & 31, hour = time >> 11, minute = (time >> 5) & 63, second = (time & 31) * 2;
|
|
19
|
+
return month < 1 || month > 12 || day < 1 || hour > 23 || minute > 59 || second > 59 ? null : Date.UTC(1980 + (date >> 9), month - 1, day, hour, minute, second);
|
|
20
|
+
};
|
|
21
|
+
const SIGNS = ["extraFields", "dataDescriptor", "macLitter", "outOfOrder"];
|
|
22
|
+
export const newShape = () => ({ extraFields: false, dataDescriptor: false, macLitter: false, outOfOrder: false, writtenFrom: null, writtenTo: null, lastPart: -1 });
|
|
23
|
+
/** One entry of the walk: its name, general-purpose flags, extra field, DOS date and time, and its part number when it is a conversations entry (else null). */
|
|
24
|
+
export function noteShape(shape, name, flags, extra, date, time, part) {
|
|
25
|
+
for (let at = 0; at + 4 <= extra.length; at += 4 + extra.readUInt16LE(at + 2)) if (extra.readUInt16LE(at) !== 1) shape.extraFields = true;
|
|
26
|
+
if (flags & 8) shape.dataDescriptor = true;
|
|
27
|
+
if (/(^|\/)__MACOSX\//.test(name) || /(^|\/)\.DS_Store$/.test(name)) shape.macLitter = true;
|
|
28
|
+
if (part === null) return;
|
|
29
|
+
const written = dosTime(date, time);
|
|
30
|
+
if (written !== null) { shape.writtenFrom = Math.min(shape.writtenFrom ?? written, written); shape.writtenTo = Math.max(shape.writtenTo ?? written, written); }
|
|
31
|
+
if (part < shape.lastPart) shape.outOfOrder = true;
|
|
32
|
+
shape.lastPart = Math.max(shape.lastPart, part);
|
|
33
|
+
}
|
|
34
|
+
export function mergeShapes(shapes) {
|
|
35
|
+
const times = (key) => shapes.map((one) => one[key]).filter((at) => at !== null);
|
|
36
|
+
return { ...newShape(), ...Object.fromEntries(SIGNS.map((key) => [key, shapes.some((one) => one[key])])),
|
|
37
|
+
writtenFrom: times("writtenFrom").length ? Math.min(...times("writtenFrom")) : null, writtenTo: times("writtenTo").length ? Math.max(...times("writtenTo")) : null };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const INVERSION_MS = 600_000;
|
|
41
|
+
export function inversionsOf(lines) {
|
|
42
|
+
let n = 0, before = null;
|
|
43
|
+
for (const line of lines) {
|
|
44
|
+
const at = line.timestamp ? Date.parse(line.timestamp) : NaN;
|
|
45
|
+
if (!Number.isFinite(at)) continue;
|
|
46
|
+
if (before !== null && at < before - INVERSION_MS) n += 1;
|
|
47
|
+
before = at;
|
|
48
|
+
}
|
|
49
|
+
return n;
|
|
50
|
+
}
|
|
51
|
+
const V8 = /^[0-9a-f]{8}-[0-9a-f]{4}-8[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
52
|
+
export function idSkewOf(id, created) {
|
|
53
|
+
if (typeof id !== "string" || !V8.test(id)) return null;
|
|
54
|
+
const minted = parseInt(id.slice(0, 8), 16), at = Number(created);
|
|
55
|
+
return Number.isFinite(at) && at > 0 && minted > 1_600_000_000 && Math.abs(at - minted) <= 1e9 ? Math.round(at - minted) : null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** A vendor names its export zip after the moment it was made; Claude's pattern is not verified on a real export (no match: no moment). */
|
|
59
|
+
const NAMED = {
|
|
60
|
+
chatgpt: /^[0-9a-f]{64}-(\d{4})-(\d{2})-(\d{2})-(\d{2})-(\d{2})-(\d{2})-[0-9a-f]{32}(?: ?\(\d{1,3}\))?\.zip$/i,
|
|
61
|
+
"claude-web": /^data-(?:[0-9a-f-]{36}-)?(\d{4})-(\d{2})-(\d{2})-(\d{2})-(\d{2})-(\d{2})(?:-batch-\d{4})?(?: ?\(\d{1,3}\))?\.zip$/i,
|
|
62
|
+
};
|
|
63
|
+
const iso = (at) => (at === null || at === undefined ? null : new Date(at).toISOString());
|
|
64
|
+
export function envelopeOf(envelope, vendor) {
|
|
65
|
+
if (!envelope) return null;
|
|
66
|
+
if (envelope.kind !== "zip" && envelope.kind !== "zips") return { kind: envelope.kind };
|
|
67
|
+
const named = envelope.kind === "zip" && typeof envelope.name === "string" ? NAMED[vendor]?.exec(envelope.name) : null;
|
|
68
|
+
const at = named ? Date.UTC(+named[1], +named[2] - 1, +named[3], +named[4], +named[5], +named[6]) : NaN, { shape } = envelope;
|
|
69
|
+
return { kind: envelope.kind, named_at: Number.isFinite(at) ? iso(at) : null, written_from: iso(shape.writtenFrom), written_to: iso(shape.writtenTo),
|
|
70
|
+
shape: { vendor_name: Boolean(named), extra_fields: shape.extraFields, data_descriptor: shape.dataDescriptor, mac_litter: shape.macLitter, out_of_order: shape.outOfOrder } };
|
|
71
|
+
}
|