@foliox/transparent-compact-pi 0.9.3 → 0.11.1
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 +75 -0
- package/README.md +80 -174
- package/docs/DESIGN.md +247 -16
- package/extensions/index.ts +561 -119
- package/extensions/lib/checkpoint-cap.ts +38 -33
- package/extensions/lib/tool-stubs/display.mjs +21 -0
- package/extensions/lib/tool-stubs/inputs.mjs +12 -0
- package/extensions/lib/tool-stubs/locations.mjs +42 -0
- package/extensions/lib/tool-stubs/parse.mjs +39 -0
- package/extensions/lib/tool-stubs/parser/LICENSE.Go +27 -0
- package/extensions/lib/tool-stubs/parser/LICENSE.mvdan-sh +27 -0
- package/extensions/lib/tool-stubs/parser/NOTICE.md +13 -0
- package/extensions/lib/tool-stubs/parser/PATENTS.Go +22 -0
- package/extensions/lib/tool-stubs/parser/build.json +12 -0
- package/extensions/lib/tool-stubs/parser/go.mod +5 -0
- package/extensions/lib/tool-stubs/parser/go.sum +2 -0
- package/extensions/lib/tool-stubs/parser/main.go +36 -0
- package/extensions/lib/tool-stubs/parser/shell.wasm +0 -0
- package/extensions/lib/tool-stubs/parser/wasm_exec.js +575 -0
- package/extensions/lib/tool-stubs/renderer.mjs +53 -0
- package/extensions/lib/tool-stubs/shell.mjs +251 -0
- package/extensions/lib/turn-context.ts +209 -0
- package/extensions/lib/turn-filter.ts +346 -0
- package/package.json +7 -2
- package/skills/context-retrieval/SKILL.md +0 -5
package/docs/DESIGN.md
CHANGED
|
@@ -21,24 +21,72 @@ extension builds a checkpoint without changing that boundary or calling a model:
|
|
|
21
21
|
New tool lines use `[Tools]:` with compact display signatures:
|
|
22
22
|
|
|
23
23
|
```text
|
|
24
|
-
read
|
|
25
|
-
write
|
|
26
|
-
edit
|
|
24
|
+
read @1:12-41
|
|
25
|
+
write @2 (2144 chars)
|
|
26
|
+
edit @1 ×2
|
|
27
27
|
bash "uv run pytest -q 2>&1 | tail -25" → output: "3 failed, 16 passed in 0.21s"
|
|
28
|
+
bash{cd @3 && cargo test >@4 | tail}
|
|
28
29
|
```
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
31
|
+
Known tools use positive input selection: bash retains `command`; read retains
|
|
32
|
+
`path`, `offset` and `limit`; write/edit retain their path and payload-derived
|
|
33
|
+
sizes/counts. Other call arguments are omitted regardless of extension, including
|
|
34
|
+
non-null execution controls. Unknown tools keep bounded agnostic argument previews.
|
|
35
|
+
Read ranges describe requests, not returned coverage or symbol positions.
|
|
36
|
+
|
|
37
|
+
Quoted bash commands of at most 160 encoded characters stay literal, with cwd
|
|
38
|
+
shortening and escaped newlines. Longer commands use a full mvdan/sh AST to retain
|
|
39
|
+
commands, common subcommands, path operands, pipes, sequencing, redirects and
|
|
40
|
+
grouping. Flags and non-location arguments are generally omitted. Inline program
|
|
41
|
+
bodies become explicit `[inline]`/`[body]` markers with bounded lexical path mentions;
|
|
42
|
+
these are not effect analysis. Unsupported, oversized or malformed shell input
|
|
43
|
+
falls back to a head-only literal preview, still without execution metadata.
|
|
44
|
+
|
|
45
|
+
A shared `<locations>` dictionary near the checkpoint end resolves `@N` IDs.
|
|
46
|
+
File lists use the same IDs while retaining their operation/evidence annotations.
|
|
47
|
+
IDs are append-only and branch-local, persisted in compaction details so resume,
|
|
48
|
+
fork, filtering/restoration and repeated compaction do not renumber old references.
|
|
49
|
+
Definitions are rendered only for surviving structured tool references and visible
|
|
50
|
+
file lists, never discovered by regex-scanning prose. Canonical metadata keeps the
|
|
51
|
+
complete registry so restoring a turn or disabling the cap restores its definitions.
|
|
52
|
+
Raw command/program payloads are not copied into display records.
|
|
53
|
+
|
|
54
|
+
The cap counts dictionary characters, including their removal when a call is
|
|
55
|
+
trimmed. Definitions needed by file lists are fixed overhead; unused definitions
|
|
56
|
+
are omitted after pruning, native-turn replacement and capping. Skeletons are not
|
|
57
|
+
shortened into partial syntax. Literal previews can tighten to 120 then 80 encoded
|
|
58
|
+
characters before adjacent tool-only prefixes are grouped and destructive trimming
|
|
59
|
+
starts. Calls remain independently removable and ordered.
|
|
60
|
+
|
|
61
|
+
All signatures are display notation, not replayable commands or tool arguments.
|
|
62
|
+
No command diffs or read folding are performed.
|
|
63
|
+
|
|
64
|
+
**Parser dependency and rebuilds.** `extensions/lib/tool-stubs/parser/go.mod`
|
|
65
|
+
pins the official `mvdan.cc/sh/v3` module at `v3.14.1`. Our small Go bridge calls
|
|
66
|
+
`syntax.NewParser` and upstream's `syntax/typedjson.Encode` directly; the renderer
|
|
67
|
+
consumes that upstream JSON format without an intermediate AST schema. It does
|
|
68
|
+
not import an interpreter. The JavaScript loader initializes the bundled WASM
|
|
69
|
+
lazily, once, with Go's globals isolated from Pi. There are no npm parser
|
|
70
|
+
runtime dependencies, external executables, downloads, or target-file reads.
|
|
71
|
+
|
|
72
|
+
Checked-in WASM keeps npm and Git installs self-contained. Rebuild with Go
|
|
73
|
+
1.27.3 available on PATH:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
npm run build:shell-parser
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The build uses pinned module checksums, `-trimpath`, no VCS stamping and no build
|
|
80
|
+
ID. It copies the matching Go support script unmodified. `parser/build.json`
|
|
81
|
+
records source/asset hashes and toolchain/upstream versions; tests detect stale
|
|
82
|
+
sources or assets. The bundled Go and mvdan/sh licenses are in that directory.
|
|
83
|
+
Go is a build-only requirement; users do not need it.
|
|
84
|
+
|
|
85
|
+
**Development experiment — dictionary placement:** keep the shared dictionary at
|
|
86
|
+
the end for now, preserving the checkpoint's start for session-start information.
|
|
87
|
+
Compare dictionary-first versus dictionary-last in independent behavioural tests;
|
|
88
|
+
prompt-order research is suggestive, not a direct evaluation of this format. Do
|
|
89
|
+
not duplicate the dictionary without evidence that the extra context cost helps.
|
|
42
90
|
|
|
43
91
|
`[tool error]` means a safely matched result was flagged as an error; `[unknown]`
|
|
44
92
|
means no safely matched result/status. Plain successes have no status label; this
|
|
@@ -76,6 +124,188 @@ extension, display setting, or content format. Long type names are abbreviated
|
|
|
76
124
|
like tool-call arguments. This applies even with the cap disabled. Previously
|
|
77
125
|
saved canonical spans are not rewritten; older custom-message bodies may remain in them.
|
|
78
126
|
|
|
127
|
+
### User-controlled turn filtering
|
|
128
|
+
|
|
129
|
+
`/compact-filtered` sequences ordinary verbatim manual compaction and the shared
|
|
130
|
+
`/filter-turns` editor. It waits for Pi's completion callback, so the new checkpoint
|
|
131
|
+
is already saved and the host is idle before the picker opens. There is no special
|
|
132
|
+
custom-instruction sentinel or interactive filtering path in `session_before_compact`.
|
|
133
|
+
The first phase inherits all existing choices like ordinary `/compact`; the second
|
|
134
|
+
phase proposes a separate reversible revision. Escape in the picker leaves the
|
|
135
|
+
completed compaction intact. A failed or cancelled first phase never opens it.
|
|
136
|
+
Pi's current no-op outcomes (`Already compacted` and `Nothing to compact (session too
|
|
137
|
+
small)`) open an existing checkpoint only if the session/branch is unchanged. A
|
|
138
|
+
session/branch change or unexpected checkpoint result cancels the workflow; the
|
|
139
|
+
shared editor rechecks idle/UI/method state before opening.
|
|
140
|
+
|
|
141
|
+
Only turns wholly before the saved boundary can be excluded; pre-flagged turns
|
|
142
|
+
still overlapping the retained tail remain pending and their flags can be cancelled
|
|
143
|
+
in the picker. Other recent turns stay locked. Agent/tool subentries are inspection
|
|
144
|
+
views of their owning user turn. Previously pruned turns start checked; unchecking
|
|
145
|
+
restores their compacted representation. Confirmation distinguishes pruning,
|
|
146
|
+
restoration, fidelity and pending-flag changes. Escape goes back from confirmation,
|
|
147
|
+
or cancels only the proposed revision. No filtering UI runs in ordinary manual,
|
|
148
|
+
threshold or overflow compaction itself.
|
|
149
|
+
|
|
150
|
+
`/filter-turns` uses the same selection/confirmation UI against the existing
|
|
151
|
+
checkpoint only. It does not invoke Pi's compaction preparation, append a compaction,
|
|
152
|
+
add a span, move `firstKeptEntryId`, or start an agent turn. It therefore also works
|
|
153
|
+
immediately after compaction when Pi has nothing more to compact. An existing
|
|
154
|
+
verbatim checkpoint and an idle interactive session are required; recent messages
|
|
155
|
+
remain untouched, though pending aside flags can be cancelled.
|
|
156
|
+
|
|
157
|
+
Canonical span lines carry parallel `turnIds`, anchored to raw user entry IDs
|
|
158
|
+
through Pi's source-preserving projection (including explicit context replacements).
|
|
159
|
+
A group includes all activity until the next raw user message, even across multiple
|
|
160
|
+
compaction spans. Confirmed exclusions are stored as the current `filteredTurnIds`
|
|
161
|
+
snapshot on the compaction entry or its standalone revision, not an append-only
|
|
162
|
+
union. Later verbatim checkpoints apply that branch-local selection to the original canonical spans before size
|
|
163
|
+
trimming, reindexing tool display records without changing stored history. File
|
|
164
|
+
operation lists and startup-read snapshots in compaction details remain canonical
|
|
165
|
+
and unfiltered; only the rendered checkpoint masks them. Restoring a turn therefore
|
|
166
|
+
also restores its retained-read copies and file-list membership without re-reading
|
|
167
|
+
files or reselecting startup evidence. There is no migration or reconstruction of
|
|
168
|
+
saved spans without turn ownership; opaque content is not individually selectable.
|
|
169
|
+
|
|
170
|
+
One `[Turn manually filtered]` marker replaces each excluded group at its original
|
|
171
|
+
position, even across spans. Markers survive the size cap. Startup-read copies owned
|
|
172
|
+
by the group are excluded; file-list paths used only by excluded turns are removed.
|
|
173
|
+
Filtering does not undo filesystem mutations. The checkpoint introduction and
|
|
174
|
+
persistent reorientation conditionally explain that the user excluded low-value
|
|
175
|
+
context, which remains retrievable from the full raw history. Recovery tools are
|
|
176
|
+
unchanged. Cancelling or failing a turn edit saves no revision. Mechanical compaction
|
|
177
|
+
with existing pruning or fidelity choices cancels on build failure rather than
|
|
178
|
+
falling through to a model summary that would lose those choices.
|
|
179
|
+
|
|
180
|
+
Standalone updates append a non-context `transparent-compact:filter-revision`
|
|
181
|
+
entry containing the source compaction ID, rendered checkpoint, exclusions and
|
|
182
|
+
keep overrides. The latest revision for the active compaction wins. At request
|
|
183
|
+
time, `context_with_system` replaces Pi's projected `compactionSummary` with the
|
|
184
|
+
revised text and any selected native turn segments, and refreshes the managed
|
|
185
|
+
reminder for that revision. Original compaction entries and
|
|
186
|
+
the raw recent tail are never edited. Host views/estimates based solely on Pi's
|
|
187
|
+
saved projection can still reflect the original summary; actual provider requests
|
|
188
|
+
receive the revision. The checkpoint size guard applies before a revision is saved.
|
|
189
|
+
|
|
190
|
+
Reload/resume and tree navigation select revisions from the raw active branch.
|
|
191
|
+
The next real verbatim compaction inherits their choices and supersedes the old
|
|
192
|
+
revision; model-summary compaction is also given the revised previous summary and
|
|
193
|
+
file lists rather than stale saved checkpoint content. Cancelling the picker or
|
|
194
|
+
size-cap decision saves no filtering revision. No-op confirmation writes nothing.
|
|
195
|
+
|
|
196
|
+
`/filter-later <message>` (alias `/fl`) submits an ordinary user message through Pi's user-message API.
|
|
197
|
+
A short-lived bridge from that submission's input event writes a non-context
|
|
198
|
+
`transparent-compact:aside-turn` entry just before its user message is persisted.
|
|
199
|
+
The next raw user entry consumes the flag, guarded by that message's timestamp.
|
|
200
|
+
A failed/handled input is cleared by the next input, and session changes clear the
|
|
201
|
+
bridge; no content heuristic is used to flag historical messages. Asides remain
|
|
202
|
+
visible until eligible and are pre-checked by manual filtering.
|
|
203
|
+
|
|
204
|
+
`/filter-auto on|off` persists a branch-local
|
|
205
|
+
`transparent-compact:auto-filter` policy (default off). When enabled, threshold
|
|
206
|
+
and overflow compaction apply eligible user pre-flags without opening a picker.
|
|
207
|
+
Ordinary `/compact` does not apply new pre-flags; summary mode is unchanged.
|
|
208
|
+
The compaction's `keptAsideTurnIds` snapshot records explicit manual keep/restore
|
|
209
|
+
overrides, so future auto compactions do not re-exclude those asides. Turning off
|
|
210
|
+
auto filtering affects new applications, not existing exclusions. No automatic
|
|
211
|
+
relevance judgment, model call or filesystem mutation is introduced.
|
|
212
|
+
|
|
213
|
+
### Selective full-fidelity turns
|
|
214
|
+
|
|
215
|
+
The same picker has four modes: `[X] PRUNED`, `[ ] PROSE`, `[○] PROSE+TOOLS`, and
|
|
216
|
+
`[■] FULL`. `[-] LOCKED` is an independent availability state and remains unchanged.
|
|
217
|
+
Space switches any kept mode to PRUNED, or PRUNED to PROSE. `f` cycles all four modes;
|
|
218
|
+
for pending recent-tail pre-flags it only toggles PRUNED/PROSE. Both controls always
|
|
219
|
+
act on the whole owning user turn. Expansion and confirmation preview show the
|
|
220
|
+
chosen representation; preview also estimates token growth.
|
|
221
|
+
|
|
222
|
+
The compaction/revision stores a `fidelity` map of raw user IDs to `tools`/`full`
|
|
223
|
+
and generated `slots`, never another copy of raw payloads. PRUNED continues to use
|
|
224
|
+
`filteredTurnIds`; absent fidelity means PROSE. Before capping, every compacted copy
|
|
225
|
+
of a selected native turn is replaced by a single generated slot, even across
|
|
226
|
+
multiple canonical spans. Slots are structurally protected from trimming. Generated
|
|
227
|
+
random markers are resolved to checked UTF-16 offsets in the final checkpoint;
|
|
228
|
+
request projection never interprets historical text as a managed placeholder.
|
|
229
|
+
|
|
230
|
+
At request time, the checkpoint is split at those offsets into chronological
|
|
231
|
+
compacted segments interleaved with original user/assistant/tool messages. The raw
|
|
232
|
+
projection disables compaction while preserving branch topology and Pi's explicit
|
|
233
|
+
context edits and custom-message conversion. Historical system configuration and
|
|
234
|
+
obsolete managed reorientation messages are not replayed. Tool-call/result groups
|
|
235
|
+
must be complete and unambiguous. PROSE+TOOLS replaces each thinking block with a
|
|
236
|
+
text marker in place; FULL retains stored blocks/signatures/images. Request-local
|
|
237
|
+
copies prevent later transforms from mutating canonical session records. Provider
|
|
238
|
+
compatibility transformations still apply, including cross-model reasoning and
|
|
239
|
+
non-vision image handling; no unavailable reasoning or nested outputs are invented.
|
|
240
|
+
|
|
241
|
+
Native turns replace their compacted prose and startup-read duplicates, not the
|
|
242
|
+
canonical source data. File paths remain listed and successful read outputs in
|
|
243
|
+
native turns get a conservative historical-evidence annotation. PROSE restoration
|
|
244
|
+
can recover its canonical retained reads again. Mode choices inherit through
|
|
245
|
+
reload/resume, tree navigation and later verbatim compactions; explicit fidelity
|
|
246
|
+
choices also override aside pre-flags. An empty revision clears old fidelity rather
|
|
247
|
+
than falling back to the source checkpoint's map. Explicit summary compaction gets
|
|
248
|
+
expanded historical text as its previous summary and may summarize it normally.
|
|
249
|
+
|
|
250
|
+
Native message token estimates count as fixed overhead in the character cap; only
|
|
251
|
+
PROSE is trimmable. Independent context-window checks run before saving and after
|
|
252
|
+
system restoration on each actual request, with output/framing headroom. They use
|
|
253
|
+
Pi's token estimates, not a provider tokenizer. Oversized updates save no revision;
|
|
254
|
+
subsequent budget/projection failures explicitly abort the active operation (a hook
|
|
255
|
+
exception alone is not a cancellation gate). Existing full-fidelity content is never
|
|
256
|
+
silently dropped or downgraded to make room. The user can remove/downgrade a pin,
|
|
257
|
+
even if later context edits made its original tool group unreplayable. Host views
|
|
258
|
+
and compaction-boundary selection still use Pi's saved checkpoint; provider requests
|
|
259
|
+
include native expansions and are checked separately.
|
|
260
|
+
|
|
261
|
+
### Live context size preview
|
|
262
|
+
|
|
263
|
+
Selection and review share a live whole-context estimate: input tokens/context
|
|
264
|
+
window, percentage, net delta from saved input, and headroom after the same output
|
|
265
|
+
and framing reserve used by the context guard. The total explicitly includes the
|
|
266
|
+
measured tail size, not the configured retention target. Short terminals show the
|
|
267
|
+
total only.
|
|
268
|
+
The editor supplies a read-only estimator to the picker. It renders proposed
|
|
269
|
+
selections through the same checkpoint builder as saving, with passive cap
|
|
270
|
+
resolution and no notifications/dialogs/persistence. Warn assumes applying the
|
|
271
|
+
current budget on changes; unchanged selections use the actual saved checkpoint,
|
|
272
|
+
not a hypothetical rebuild under a newly changed cap policy. A presentation result
|
|
273
|
+
from the real cap renderer records actual trimming/tightening; only then does the UI
|
|
274
|
+
mention the size limit, in plain language, including whether saving asks first.
|
|
275
|
+
Raw `cap warn` policy/debug labels are not shown.
|
|
276
|
+
|
|
277
|
+
Notice accounting separately measures generated pruning guidance, checkpoint
|
|
278
|
+
revision notices and full-fidelity guidance using counterfactual messages through
|
|
279
|
+
the real estimator. Only the generated introduction before `SECTION_HEADER` and
|
|
280
|
+
the generated reminder are edited in these counterfactuals; quoted historical text
|
|
281
|
+
is untouched. Costs therefore follow the actual text/estimator, with no fixed token
|
|
282
|
+
allowance. Activation/removal changes are summed into one inline `+~N scaffolding`
|
|
283
|
+
(or `−~N scaffolding`) indicator after the tail on the estimated-context row,
|
|
284
|
+
already included in the total and net delta.
|
|
285
|
+
No notice breakdown or extra notice row is shown; unchanged context has no added
|
|
286
|
+
scaffolding indicator. Existing notice rounding is not presented as fresh overhead
|
|
287
|
+
on every checkbox.
|
|
288
|
+
The first prune and first checkpoint update can therefore add noticeable one-time
|
|
289
|
+
cost even when little prose is removed. The delta still includes marker replacements
|
|
290
|
+
and size-limit effects; it is not a raw selected-text token count.
|
|
291
|
+
|
|
292
|
+
The estimator expands generated native slots, removes retained-read duplicates,
|
|
293
|
+
and respects explicit context edits. It counts the untouched live tail (excluding
|
|
294
|
+
old system configuration, obsolete managed checklists and context-excluded bash
|
|
295
|
+
output), plus the current prompt/active tool schemas and one current reminder.
|
|
296
|
+
These are Pi estimates before provider-specific transformations; future input and
|
|
297
|
+
other extensions' future request transformations cannot be predicted. A failed
|
|
298
|
+
baseline leaves delta unknown, while repaired proposed context can still get an
|
|
299
|
+
honest total. Failed estimates are shown as unavailable, never zero.
|
|
300
|
+
|
|
301
|
+
Estimation is asynchronous and coalesced per mode change; navigation, resize and
|
|
302
|
+
theme changes reuse the last result. Pending recalculations retain the completed
|
|
303
|
+
readout, its styling and row count, replacing values only when a new estimate is
|
|
304
|
+
ready. Loading text appears only before any successful estimate (or when retrying
|
|
305
|
+
a failed estimate), not on every toggle. Generation checks reject stale results, and
|
|
306
|
+
closing/disposing the dialog invalidates pending work. No estimated sizes are
|
|
307
|
+
persisted in checkpoint metadata, and no model calls are introduced.
|
|
308
|
+
|
|
79
309
|
### File-list evidence annotations
|
|
80
310
|
|
|
81
311
|
The lists record reads and modifications in compacted history, not an exhaustive
|
|
@@ -352,7 +582,8 @@ There is no blanket edit-target reread. Before replacing an existing file with
|
|
|
352
582
|
view, and forbids reconstructing unchanged sections from memory. Small exact-match
|
|
353
583
|
edits and newly created files do not acquire a blanket reread requirement.
|
|
354
584
|
It is a saved
|
|
355
|
-
custom message tagged with the current compaction entry ID,
|
|
585
|
+
custom message tagged with the current compaction entry ID and, after standalone
|
|
586
|
+
filtering, its revision ID, not a temporary nudge:
|
|
356
587
|
subsequent responses and user turns retain it in history before the work that
|
|
357
588
|
followed it. `before_agent_start` adds it on normal starts/resume when missing;
|
|
358
589
|
`session_compact` steers it into automatic mid-run and overflow continuations.
|