@brandry/claude-jsonl-compressor 1.0.0 → 1.1.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/CHANGELOG.md +73 -56
- package/LICENSE +674 -674
- package/NOTICE +8 -8
- package/README.md +666 -611
- package/SKILL.md +230 -345
- package/agents/openai.yaml +7 -7
- package/bin/claude-jsonl-compressor.cjs +4 -4
- package/bin/claude-jsonl-repair-read-pages.cjs +4 -4
- package/bin/run-python.cjs +77 -77
- package/package.json +60 -60
- package/references/claude-jsonl-compression-format.md +635 -578
- package/scripts/claude_session_tools.py +304 -245
- package/scripts/compress_claude_jsonl.py +8608 -8275
- package/scripts/repair_claude_jsonl.py +627 -627
- package/templates/summary_template_en.md +78 -78
package/SKILL.md
CHANGED
|
@@ -1,345 +1,230 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: claude-jsonl-compressor
|
|
3
|
-
description: Compress one Claude Code JSONL
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Claude JSONL Compressor
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
--
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
- `
|
|
155
|
-
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
## Checkpoint Policy
|
|
232
|
-
|
|
233
|
-
Conversation rewind topology and file checkpoints are separate planes.
|
|
234
|
-
|
|
235
|
-
- `--checkpoint-policy active-correlated` is the default. It keeps only recent UUID-less `file-history-snapshot` records that structurally correlate to retained active records.
|
|
236
|
-
- `--checkpoint-policy none` keeps no UUID-less file-history snapshots.
|
|
237
|
-
- `--checkpoint-policy preserve-recent` is rejected in strict active-chain mode. It is meaningful only with explicit `--preserve-physical-tail`, whose report is labeled `physical-tail-compatibility` and which has no inactive-branch isolation guarantee.
|
|
238
|
-
- `--max-file-history-snapshots N` caps retained snapshots.
|
|
239
|
-
|
|
240
|
-
Never claim that compressed JSONL alone guarantees complete file-state rewind. The report states what snapshot side records were retained.
|
|
241
|
-
|
|
242
|
-
## Repeated Compression
|
|
243
|
-
|
|
244
|
-
Default behavior folds old compact summaries into one current compact summary. The output must contain one current compact pair.
|
|
245
|
-
|
|
246
|
-
Treat an older `preservedMessages` list as a historical snapshot. A later rewind may make its tail diverge from the current authoritative chain; report that warning, exclude the old tail, and continue only when the current chain itself is valid. Require every newly generated candidate to rebuild the snapshot so it exactly matches the candidate's current chain.
|
|
247
|
-
|
|
248
|
-
When the user explicitly asks to preserve existing summaries verbatim, repeat this flag in both model-pack and compression passes:
|
|
249
|
-
|
|
250
|
-
```powershell
|
|
251
|
-
--preserve-prior-summaries-verbatim
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
The script may expand the summary character budget to 1.5x. If exact preservation still does not fit, it uses the normal folded path and reports `fallback-folded`. It does not stack old compact pairs into the active chain.
|
|
255
|
-
|
|
256
|
-
For third and later rounds, apply chronology again. Prior summaries are historical evidence, not automatically current truth. Preserve old decisions and reasons while marking later supersessions.
|
|
257
|
-
|
|
258
|
-
## Read.pages Repair Commands
|
|
259
|
-
|
|
260
|
-
Scan without writing:
|
|
261
|
-
|
|
262
|
-
```powershell
|
|
263
|
-
python "$skill\scripts\repair_claude_jsonl.py" `
|
|
264
|
-
--input "C:\path\session.jsonl" `
|
|
265
|
-
--scan-only
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
Write a separate candidate and require the expected patch count:
|
|
269
|
-
|
|
270
|
-
```powershell
|
|
271
|
-
python "$skill\scripts\repair_claude_jsonl.py" `
|
|
272
|
-
--input "C:\path\session.jsonl" `
|
|
273
|
-
--output "C:\path\session.repaired.jsonl" `
|
|
274
|
-
--expect-matches 2
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
Replace one live session transactionally:
|
|
278
|
-
|
|
279
|
-
```powershell
|
|
280
|
-
python "$skill\scripts\repair_claude_jsonl.py" `
|
|
281
|
-
--input "$env:USERPROFILE\.claude\projects\PROJECT\SESSION.jsonl" `
|
|
282
|
-
--replace-original `
|
|
283
|
-
--confirm-session-closed `
|
|
284
|
-
--work-dir "C:\work\claude-repair\SESSION-TIMESTAMP" `
|
|
285
|
-
--expect-matches 2
|
|
286
|
-
```
|
|
287
|
-
|
|
288
|
-
Use `--scope all` only when the user explicitly wants inactive physical branches repaired too.
|
|
289
|
-
|
|
290
|
-
An automatic repair additionally requires exactly one later result with the same non-empty `sessionId` and a `sourceToolAssistantUUID` equal to the Read tool-use assistant UUID. Candidate publication must re-read and validate the actual published bytes and prove an idempotent second scan before success.
|
|
291
|
-
|
|
292
|
-
## Validation And Stop Condition
|
|
293
|
-
|
|
294
|
-
Before reporting success, require fresh evidence for the selected operation:
|
|
295
|
-
|
|
296
|
-
Compression:
|
|
297
|
-
|
|
298
|
-
- candidate validation `ok: true`
|
|
299
|
-
- no duplicate UUID, missing parent, cross-session parent or tool-pair error
|
|
300
|
-
- no empty/duplicate active tool ID; a partial ordered-subset result is accepted only as an explicit compatibility warning and count
|
|
301
|
-
- exactly one current Codex compact boundary/summary pair on the final pointer chain
|
|
302
|
-
- one projected final `last-prompt`
|
|
303
|
-
- dead-branch counts reported without branch text
|
|
304
|
-
- any observed attachment-order/session-lineage compatibility is explicitly reported, and output raw records remain one current-session chain
|
|
305
|
-
- explicit `--target-estimated-tokens` ceiling met under the complete-structure local estimate; an approximate ratio alone is not a hard success claim
|
|
306
|
-
- input unchanged in candidate mode
|
|
307
|
-
- backup bytes equal original bytes in live mode
|
|
308
|
-
- replacement validation `ok: true` in live mode
|
|
309
|
-
|
|
310
|
-
Repair:
|
|
311
|
-
|
|
312
|
-
- expected match count satisfied when supplied
|
|
313
|
-
- byte validation `ok: true`
|
|
314
|
-
- UUID/parent and tool-ID signatures unchanged
|
|
315
|
-
- second pass finds zero patchable matches
|
|
316
|
-
- shared full-transcript validation `ok: true`
|
|
317
|
-
- input unchanged in candidate mode
|
|
318
|
-
- numbered backup equals original in live mode
|
|
319
|
-
|
|
320
|
-
Structural validation alone is an observed-format check, not an Anthropic format guarantee. If the user permits Claude CLI testing, report `/resume`, `/context`, recent conversation rewind and recent file rewind as separate observations.
|
|
321
|
-
|
|
322
|
-
## Session Location
|
|
323
|
-
|
|
324
|
-
Prefer an exact path or filename. To locate one session without reading transcript bodies:
|
|
325
|
-
|
|
326
|
-
```powershell
|
|
327
|
-
python "$skill\scripts\claude_session_tools.py" `
|
|
328
|
-
--root "$env:USERPROFILE\.claude\projects" `
|
|
329
|
-
--query "SESSION.jsonl"
|
|
330
|
-
```
|
|
331
|
-
|
|
332
|
-
Use `--scan-titles` only when the user supplies a title and permits title scanning. Multiple matches are an error. Never broaden a single-target run into directory-wide compression.
|
|
333
|
-
|
|
334
|
-
## Failure Rules
|
|
335
|
-
|
|
336
|
-
- A strict topology failure produces no pack, candidate, sidecar or backup.
|
|
337
|
-
- For a special or ambiguous topology, report the strict failure and pause. Offer only the exact explicit control that matches the diagnosis, state the lost guarantee, and require a new user confirmation before running it. Manual/spliced files generally require `--preserve-physical-tail`, which forfeits inactive-branch and rewind isolation.
|
|
338
|
-
- A model-summary validation failure requires regenerating the pack/summary with identical settings; do not weaken validation.
|
|
339
|
-
- A tool-pair failure requires moving the cut earlier or diagnosing source inconsistency; do not invent tool results.
|
|
340
|
-
- A source hash change aborts live replacement.
|
|
341
|
-
- Live replacement requires the Claude process for that session to be closed. The transaction validates immutable candidate bytes, exclusively creates and verifies a numbered backup, captures the actual old target, verifies its full SHA-256, installs the candidate, and verifies the published bytes and structure. If another process recreates the target during capture, preserve the external target and recovery backups and fail without publishing. Parent-directory fsync is best effort and reported because platform support differs.
|
|
342
|
-
- A write/fsync/validation/replace failure returns nonzero. The transaction restores the captured original bytes when replacement began; if restoration itself fails, it raises a high-priority error and retains the numbered backup for recovery.
|
|
343
|
-
- Each unique live-transaction temporary path is checked against its recorded filesystem identity and frozen bytes before cleanup. A detected mismatch is retained and reported; a pre-commit failure also includes any cleanup residue in its error. Portable pathname cleanup cannot atomically bind that final delete to the earlier identity check across Windows, Linux, and macOS, so require a closed session and no other writer. Do not claim protection from hostile same-account directory manipulation.
|
|
344
|
-
- If a valid live replacement commits but final sidecar/report publication fails, return exit code 3 with `committed-report-failed` and the committed hashes/backup labels. Do not rerun blindly or describe that state as an uncommitted failure.
|
|
345
|
-
- Keep reports and temporary work outside `.claude`; do not leave ad hoc files in live session directories.
|
|
1
|
+
---
|
|
2
|
+
name: claude-jsonl-compressor
|
|
3
|
+
description: Compress one Claude Code JSONL using a source-anchored model summary, strict active-branch isolation and recent raw context, or explicitly repair historical Read.pages compatibility. Supports candidate output and transactional replacement of one closed live session.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Claude JSONL Compressor
|
|
7
|
+
|
|
8
|
+
Package **1.1.0**, engine **v10**, model-pack **v11**, report **1**.
|
|
9
|
+
|
|
10
|
+
Reduce Claude context/cache costs while preserving the user's required history.
|
|
11
|
+
Operate on exactly one authoritative JSONL. Never merge sessions or revive
|
|
12
|
+
rewound branches. Python uses only the standard library and calls no model or
|
|
13
|
+
network; Codex authors the semantic summary between two deterministic passes.
|
|
14
|
+
Do not install tokenizers, PyYAML or other packages. Do not run Claude CLI unless
|
|
15
|
+
the user explicitly requests it.
|
|
16
|
+
|
|
17
|
+
## Choose the operation and unique source
|
|
18
|
+
|
|
19
|
+
- Prefer exact path, filename or session ID. For an explicitly requested title
|
|
20
|
+
lookup, run `scripts/claude_session_tools.py --root ROOT --query TITLE --scan-titles`.
|
|
21
|
+
Without title scanning the helper reads no transcript bodies. Exact ID/path
|
|
22
|
+
matches take precedence; multiple matches stop. It uses the latest attributable
|
|
23
|
+
custom title, falling back to automatic title. Old names are not aliases.
|
|
24
|
+
- **Candidate:** distinct input/output paths; source stays unchanged. Output,
|
|
25
|
+
report and validation live outside the entire `.claude` tree.
|
|
26
|
+
- **Live replacement:** user requests in-place compression of one existing
|
|
27
|
+
`.claude/projects/PROJECT/SESSION.jsonl` (including identical input/output).
|
|
28
|
+
Use input only, `--replace-original --confirm-session-closed --work-dir WORK`.
|
|
29
|
+
WORK and all process files must be outside `.claude`. Closed-session
|
|
30
|
+
acknowledgement is a caller assertion, not lock detection. Use the original
|
|
31
|
+
filename stem as session ID unless another is explicitly requested.
|
|
32
|
+
- **Read.pages repair:** a separate, explicitly requested operation; never run
|
|
33
|
+
it implicitly as part of compression. See the repair section below.
|
|
34
|
+
|
|
35
|
+
Resolve the skill directory from the environment, for example:
|
|
36
|
+
|
|
37
|
+
```powershell
|
|
38
|
+
$skill = "$env:USERPROFILE\.codex\skills\claude-jsonl-compressor"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Preflight and choose affordable evidence
|
|
42
|
+
|
|
43
|
+
Run `--preflight` before reading the source for semantic importance, using the
|
|
44
|
+
same selection settings intended for both passes. `--analyze-resume-path` remains
|
|
45
|
+
available as the smaller topology-only diagnostic.
|
|
46
|
+
|
|
47
|
+
```powershell
|
|
48
|
+
python "$skill\scripts\compress_claude_jsonl.py" `
|
|
49
|
+
--input "C:\data\session.jsonl" --preflight `
|
|
50
|
+
--target-ratio 0.30 --min-recent-records 120 `
|
|
51
|
+
--summary-char-budget 60000 --target-estimated-tokens 150000 `
|
|
52
|
+
--tool-evidence full --citation-style scoped
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Choose settings deliberately:
|
|
56
|
+
|
|
57
|
+
- `--tool-evidence full` when document/research evidence lives in tool inputs or
|
|
58
|
+
results, or the user requires fine preservation of those contents. It includes
|
|
59
|
+
complete old active tool payloads, mixed text/tool records and auxiliary
|
|
60
|
+
results. Exact repeated long strings within one record use a visible alias;
|
|
61
|
+
different previews/results remain distinct. U+FFFD produces a warning, not
|
|
62
|
+
deletion of a complete record. Paths alone are not external file contents.
|
|
63
|
+
- CLI default `excerpt` is suitable when selected short tool evidence suffices;
|
|
64
|
+
it is not a full-payload fidelity guarantee. Do not silently downgrade a
|
|
65
|
+
research preservation requirement just to fit a budget.
|
|
66
|
+
- Use `--citation-style scoped` for new summaries, avoiding source labels like
|
|
67
|
+
L73/H1 being interpreted as citations. Legacy syntax remains a CLI option.
|
|
68
|
+
- To protect whole recent human-started turns, add `--min-recent-turns N`.
|
|
69
|
+
Only the final session after its latest compact is eligible. This may enlarge
|
|
70
|
+
raw context or leave nothing to summarize; never reduce a requested window
|
|
71
|
+
silently. Report actual human messages/snapshots, not promised rewind points.
|
|
72
|
+
- When the user requires existing summaries unchanged, use both
|
|
73
|
+
`--preserve-prior-summaries-verbatim --prior-summary-overflow error` in both
|
|
74
|
+
passes. This preserves exact old content including trailing whitespace and
|
|
75
|
+
appends a new layer inside one current compact summary. It stops on overflow.
|
|
76
|
+
The legacy default `fold` permits reported fallback-folded; do not use it for
|
|
77
|
+
an absolute no-rewrite request.
|
|
78
|
+
|
|
79
|
+
Preflight separates topology, selected-chain tool/compact validity, partition
|
|
80
|
+
and pack capacity. `nothing-to-summarize` needs no model work. A physical-tail
|
|
81
|
+
candidate and `end_turn` are diagnostics, not automatic authority. The latest
|
|
82
|
+
physical `last-prompt` remains authoritative even if malformed; reasonCode is
|
|
83
|
+
the machine-readable cause and status its coarse category. A selected chain
|
|
84
|
+
ending in tool_use may have a result later in the file; do not call the source
|
|
85
|
+
damaged solely because that selected window is incomplete.
|
|
86
|
+
|
|
87
|
+
The pack ceilings remain **500,000 characters / 150,000 local estimated tokens**.
|
|
88
|
+
The settings are `--model-pack-char-budget` and `--model-pack-estimated-token-budget`.
|
|
89
|
+
Full mandatory evidence that cannot fit stops before pack publication. Do not
|
|
90
|
+
automatically split into volumes, increase ceilings, invoke extra models or
|
|
91
|
+
repeatedly reread full history. Report the capacity boundary and available
|
|
92
|
+
choices. An explicit user request can authorize a larger budget or review
|
|
93
|
+
workflow within the model's capacity. `--target-estimated-tokens` gates candidate
|
|
94
|
+
Messages under a separate complete-structure local estimate; it does not predict
|
|
95
|
+
Claude `/context` total. `--target-ratio` is approximate byte planning only.
|
|
96
|
+
|
|
97
|
+
After successful preflight, freeze a numbered source backup before semantic
|
|
98
|
+
work and compare its SHA-256 with preflight. The locator's `--backup` creates
|
|
99
|
+
`.jsonl.backup`, `.backup1`, etc.; for an exact standalone file, its Python
|
|
100
|
+
`create_backup(Path(...))` helper has the same verified exclusive behavior.
|
|
101
|
+
An already supplied independent backup may serve for a candidate-only request
|
|
102
|
+
if its bytes/hash are verified. If the source changed, repeat preflight. Live
|
|
103
|
+
replacement still creates its own verified transaction backup before modifying
|
|
104
|
+
the live target; do not bypass it with a manual copy.
|
|
105
|
+
|
|
106
|
+
## Two-pass model workflow
|
|
107
|
+
|
|
108
|
+
Generate a pack outside `.claude`. Replace `--preflight` in the chosen command
|
|
109
|
+
with `--write-model-pack "C:\work\run\session.model-pack.md"`. Keep every
|
|
110
|
+
selection option identical in pass 2, including tool evidence, citation style,
|
|
111
|
+
turn count, prior-summary policy, candidate/pack budgets, checkpoint policy,
|
|
112
|
+
manual leaf, handoff and custom resource files. Require summary budget >=4000.
|
|
113
|
+
|
|
114
|
+
Read that pack only and write the model summary. Copy its leading v11 metadata
|
|
115
|
+
comment exactly; source, summary-source, visible anchors, required groups,
|
|
116
|
+
handoff, request/resources and claim sources are all hash-bound.
|
|
117
|
+
|
|
118
|
+
1. Use the exact title, nine `##` sections and `### Mandatory Evidence Coverage`
|
|
119
|
+
printed in the pack; no extra headings or HTML comments. Every section and
|
|
120
|
+
substantive line needs visible evidence. Use exactly
|
|
121
|
+
`Unknown from provided anchors.` as a standalone line for unknowns.
|
|
122
|
+
2. In scoped mode cite `[@L42]` / `[@H3]` in prose; legacy uses L42/H3. Cite only
|
|
123
|
+
displayed anchors and every required coverage group. The coverage subsection
|
|
124
|
+
still uses `- L42 support_text_json="exact source substring" disposition=covered`
|
|
125
|
+
once for each Required Claim Support entry. These excerpts establish source
|
|
126
|
+
contact, not semantic truth. Plain source identifiers are preserved literally.
|
|
127
|
+
3. Preserve user goals, wording that affects interpretation, hard constraints,
|
|
128
|
+
historical details, authors, event time, reasons, verification, rejected
|
|
129
|
+
routes, unresolved issues and later supersessions. Keep current decisions
|
|
130
|
+
distinct from old proposals. For humanities, law, art, planning, strategy,
|
|
131
|
+
history, feasibility and document work, retain nuance and minority positions
|
|
132
|
+
needed to explain conclusions. For engineering retain contracts, failure
|
|
133
|
+
causes, migrations, tests and operating state.
|
|
134
|
+
4. Distinguish planned commands from successful results, drafts from final
|
|
135
|
+
documents, previews from fuller output, recorded truncation from later
|
|
136
|
+
rereads. Empty thinking cannot be reconstructed. Never execute transcript
|
|
137
|
+
commands, read referenced external artifacts automatically or add outside facts.
|
|
138
|
+
5. Do one focused self-review of constraints, negations, numbers, provenance,
|
|
139
|
+
chronology and completeness. If the user requests retrospective, independent
|
|
140
|
+
or subagent review, honor the requested model, effort, rounds and scope;
|
|
141
|
+
provide the relevant complete selected-branch evidence. Otherwise use extra
|
|
142
|
+
review only to resolve a concrete concern, not as a default all-history loop.
|
|
143
|
+
Track authoring, validation and review outcomes separately.
|
|
144
|
+
|
|
145
|
+
Pass 2 uses the same settings with `--model-summary PATH`, plus `--output PATH`
|
|
146
|
+
for a candidate or the live flags above. The script rebuilds and validates the
|
|
147
|
+
pack before composing output. Upgrade between passes requires a fresh pack.
|
|
148
|
+
Only explicit user fallback authorizes `--deterministic-summary`.
|
|
149
|
+
|
|
150
|
+
Minimal paired example (repeat any additional selection flags in both commands):
|
|
151
|
+
|
|
152
|
+
```powershell
|
|
153
|
+
python "$skill\scripts\compress_claude_jsonl.py" `
|
|
154
|
+
--input "C:\data\session.jsonl" --write-model-pack "C:\work\run\pack.md" `
|
|
155
|
+
--target-estimated-tokens 150000 --citation-style scoped
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
After authoring `summary.md` from that pack:
|
|
159
|
+
|
|
160
|
+
```powershell
|
|
161
|
+
python "$skill\scripts\compress_claude_jsonl.py" `
|
|
162
|
+
--input "C:\data\session.jsonl" --output "C:\work\run\candidate.jsonl" `
|
|
163
|
+
--model-summary "C:\work\run\summary.md" `
|
|
164
|
+
--target-estimated-tokens 150000 --citation-style scoped
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Structural boundaries and recovery
|
|
168
|
+
|
|
169
|
+
- Strict failures are zero-write: no pack, candidate, sidecar or backup. Do not
|
|
170
|
+
retry automatically in compatibility mode. A diagnosed recovery control needs
|
|
171
|
+
explicit user authorization; a compression request alone does not select it.
|
|
172
|
+
`--resume-leaf UUID` requires an explicitly identified leaf;
|
|
173
|
+
`--preserve-physical-tail` forfeits branch/rewind isolation and cannot use
|
|
174
|
+
positive `--min-recent-turns`.
|
|
175
|
+
- `--max-post-last-prompt-extension N` permits only a direct, same-session,
|
|
176
|
+
physically later tool-result-only closure of all pending calls. Ordinary
|
|
177
|
+
conversation, control records, branches and partial closure are rejected.
|
|
178
|
+
- Same-session attachment-only physical inversions can be serialized in logical
|
|
179
|
+
order. One-way mixed-session lineage can summarize earlier sessions while
|
|
180
|
+
retaining only the final session raw; tool pairs cannot cross that boundary.
|
|
181
|
+
- No inactive/rewound text may enter any evidence, prior-summary block, appendix,
|
|
182
|
+
raw history, side record or API chain. Older preservedMessages is historical;
|
|
183
|
+
rewind divergence warns without reviving the old tail. New compact metadata
|
|
184
|
+
must match the candidate chain, with exactly one current compact pair/pointer.
|
|
185
|
+
- Preserve unknown raw fields; only the first retained parent edge and explicit
|
|
186
|
+
session-ID normalization may change. Final attributable title metadata is
|
|
187
|
+
projected separately, including later renames, with unknown fields retained.
|
|
188
|
+
- Default checkpoint policy is `active-correlated`; `none` disables snapshots.
|
|
189
|
+
`preserve-recent` is only physical-tail compatibility. File rewind depends on
|
|
190
|
+
native snapshots, not JSONL alone; Bash file changes are not checkpointed.
|
|
191
|
+
|
|
192
|
+
## Read.pages repair
|
|
193
|
+
|
|
194
|
+
```powershell
|
|
195
|
+
python "$skill\scripts\repair_claude_jsonl.py" --input "C:\data\session.jsonl" --scan-only
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
For a candidate add `--output PATH --expect-matches N`; live uses
|
|
199
|
+
`--replace-original --confirm-session-closed --work-dir WORK --expect-matches N`.
|
|
200
|
+
Default scope is strict active chain; `--scope all` needs explicit intent to
|
|
201
|
+
repair inactive records too. Exact Read tool_use pages deletion requires an
|
|
202
|
+
existing input.file_path member, one later same-session matching result and
|
|
203
|
+
matching sourceToolAssistantUUID. Pending calls stay unchanged. Bytes outside
|
|
204
|
+
planned member spans, UUID/parent/tool IDs, BOM/newlines/escaping remain identical.
|
|
205
|
+
|
|
206
|
+
## Completion and transaction evidence
|
|
207
|
+
|
|
208
|
+
Compression requires fresh candidate `ok: true`, valid UUID/parent/session/tool
|
|
209
|
+
pairing, one current compact pair and projected pointer, branch counts without
|
|
210
|
+
branch text, exact title projection and any requested token ceiling. Explicit
|
|
211
|
+
ordered-subset tool results are warnings/counts, not silently complete exchanges.
|
|
212
|
+
Candidate mode must leave input unchanged. Repair also requires expected match
|
|
213
|
+
count, exact byte validation, published-byte reread and idempotent second scan.
|
|
214
|
+
|
|
215
|
+
Live mode additionally requires backup bytes equal original, source hash
|
|
216
|
+
recheck, published bytes/structure validation and correct transaction state.
|
|
217
|
+
Target/explicit backup directories need hard links; capability probes run first.
|
|
218
|
+
Source races, write/fsync/install/validation failures stop; replacement failures
|
|
219
|
+
restore captured original or retain numbered recovery assets and report failure.
|
|
220
|
+
Never overwrite an external claimant. Parent-directory fsync and temporary
|
|
221
|
+
identity cleanup are best effort, not hostile-writer or power-loss guarantees.
|
|
222
|
+
Committed report failure returns **exit 3 / committed-report-failed**; do not
|
|
223
|
+
rerun blindly or call it an uncommitted failure. Keep all process files/reports
|
|
224
|
+
outside `.claude`; only requested JSONL/numbered backups remain in live storage.
|
|
225
|
+
|
|
226
|
+
For unusual topology, detailed status pairs, snapshot/transaction semantics or
|
|
227
|
+
repair constraints, read [the format reference](references/claude-jsonl-compression-format.md)
|
|
228
|
+
only as needed. Structural validation is an observed-format check, not an
|
|
229
|
+
Anthropic guarantee. If runtime testing is authorized, report `/resume`,
|
|
230
|
+
`/context` Messages, conversation rewind and file rewind as separate observations.
|