pi-smart-compact 7.20.0 → 7.22.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 +30 -0
- package/README.md +288 -188
- package/dist/app/run-context.d.ts +6 -0
- package/dist/app/run-context.d.ts.map +1 -1
- package/dist/app/run-smart-compact.d.ts +2 -0
- package/dist/app/run-smart-compact.d.ts.map +1 -1
- package/dist/app/steps/extract.d.ts.map +1 -1
- package/dist/app/steps/metrics.d.ts +1 -1
- package/dist/app/steps/metrics.d.ts.map +1 -1
- package/dist/app/steps/prepare.d.ts.map +1 -1
- package/dist/app/steps/state.d.ts.map +1 -1
- package/dist/app/steps/synthesize.d.ts.map +1 -1
- package/dist/app/steps/verify.d.ts +4 -13
- package/dist/app/steps/verify.d.ts.map +1 -1
- package/dist/app/steps/window.d.ts.map +1 -1
- package/dist/constants.d.ts +11 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/domain/scrub.d.ts +19 -0
- package/dist/domain/scrub.d.ts.map +1 -0
- package/dist/domain/summary-parse.d.ts +5 -5
- package/dist/domain/summary-parse.d.ts.map +1 -1
- package/dist/domain/summary-schema.d.ts +1 -1
- package/dist/domain/summary-schema.d.ts.map +1 -1
- package/dist/domain/tool-semantics.d.ts +15 -32
- package/dist/domain/tool-semantics.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5337 -4576
- package/dist/infra/fs.d.ts +2 -0
- package/dist/infra/fs.d.ts.map +1 -1
- package/dist/infra/llm-client.d.ts +12 -11
- package/dist/infra/llm-client.d.ts.map +1 -1
- package/dist/infra/llm-retry.d.ts.map +1 -1
- package/dist/infra/services.d.ts +23 -1
- package/dist/infra/services.d.ts.map +1 -1
- package/dist/phases/explore.d.ts.map +1 -1
- package/dist/phases/synthesize.d.ts +6 -3
- package/dist/phases/synthesize.d.ts.map +1 -1
- package/dist/phases/verify.d.ts +9 -22
- package/dist/phases/verify.d.ts.map +1 -1
- package/dist/types.d.ts +62 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/overlays.d.ts +5 -2
- package/dist/ui/overlays.d.ts.map +1 -1
- package/dist/utils/cache.d.ts +4 -2
- package/dist/utils/cache.d.ts.map +1 -1
- package/dist/utils/damage.d.ts +18 -1
- package/dist/utils/damage.d.ts.map +1 -1
- package/dist/utils/file-needles.d.ts +7 -5
- package/dist/utils/file-needles.d.ts.map +1 -1
- package/dist/utils/fingerprint.d.ts +1 -0
- package/dist/utils/fingerprint.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts +2 -1
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/utils/pruning.d.ts +0 -9
- package/dist/utils/pruning.d.ts.map +1 -1
- package/dist/utils/state.d.ts +4 -2
- package/dist/utils/state.d.ts.map +1 -1
- package/dist/utils/tokens.d.ts +12 -1
- package/dist/utils/tokens.d.ts.map +1 -1
- package/docs/RELEASE.md +1 -0
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [7.22.0] - 2026-07-15
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- Independent `summaryThinkingLevel` and `segmentationThinkingLevel` settings control per-phase reasoning, including `max`, while preserving provider defaults when unset.
|
|
7
|
+
|
|
8
|
+
## [7.21.0] - 2026-07-15
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- Canonical summary parsing now recognizes canonical H3 headings, merges duplicate sections, and preserves H3-only summaries during state injection.
|
|
12
|
+
- File verification uses collision-aware path needles; one monorepo basename can no longer satisfy multiple modified files.
|
|
13
|
+
- Every deterministic verification gap is repaired regardless of scalar score; typed gaps and repair provenance replace string-prefix policy.
|
|
14
|
+
- Recent-tail and batch planning count structured tool-call arguments with run-scoped provider/model calibration.
|
|
15
|
+
- Access pruning deduplicates only identical tool name + argument signatures; read/search/list evidence no longer collapses by path alone.
|
|
16
|
+
- MCP snake-case edit aliases are classified as mutations without treating ambiguous `path + text` payloads universally as writes.
|
|
17
|
+
- Incremental extraction reconciles cached unresolved errors against successful retries in the new suffix.
|
|
18
|
+
- LLM call counts now come from the run-scoped metrics sink, including probes, retries, failures and patches.
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
- High-confidence secret scrubbing at provider, extraction-cache, backup, state and pending-summary boundaries; optional PII scrubbing.
|
|
22
|
+
- Optional fail-closed manual Apply/Cancel approval gate with verification provenance.
|
|
23
|
+
- Exact max-call and max-latency budgets with deterministic degradation, plus `--focus` budget weighting.
|
|
24
|
+
- Online `session_compact` → `message_end` damage monitoring and opt-in adaptive preservation policy.
|
|
25
|
+
- `/smart-compact loops` manager for resolve/reopen, priority and pin/unpin overrides with stable summary identity across runs.
|
|
26
|
+
- Deterministic adversarial EESV release gate (`bun run gate`) covering parser, verification, tools, cache, budgets, scrubbing and damage.
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
- Public README redesigned for npm, GitHub and Pi package surfaces with install-first quick start, progressive EESV documentation, complete configuration, safety/privacy guidance and current recovery/observability flows.
|
|
30
|
+
- Extraction and exploration share one deduplicated fact context; runtime call accounting now comes from the metrics sink instead of inferred round counts.
|
|
31
|
+
- CI and the release checklist now run the adversarial EESV gate.
|
|
32
|
+
|
|
3
33
|
## [7.20.0] - 2026-07-14
|
|
4
34
|
|
|
5
35
|
### Fixed
|
package/README.md
CHANGED
|
@@ -1,37 +1,20 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
-
<
|
|
3
|
+
<a href="https://github.com/alpertarhan/pi-smart-compact">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/alpertarhan/pi-smart-compact/main/docs/assets/banner.svg" alt="pi-smart-compact" width="860" />
|
|
5
|
+
</a>
|
|
4
6
|
|
|
5
7
|
[](https://github.com/alpertarhan/pi-smart-compact/actions/workflows/ci.yml)
|
|
6
8
|
[](https://www.npmjs.com/package/pi-smart-compact)
|
|
7
|
-
[](
|
|
8
|
-
[](https://github.com/alpertarhan/pi-smart-compact/blob/main/LICENSE)
|
|
10
|
+
[](https://github.com/earendil-works/pi)
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
### Verification-oriented context compaction for the Pi Coding Agent
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Default compaction trims your conversation blind. `pi-smart-compact` keeps what
|
|
15
|
-
the agent actually needs to continue — the **goal, changed files, unresolved
|
|
16
|
-
errors, decisions, constraints, and open loops** — through a verified
|
|
17
|
-
**Extract → Explore → Synthesize → Verify** pipeline.
|
|
18
|
-
|
|
19
|
-
> Facts first, synthesis second, verification last.
|
|
20
|
-
|
|
21
|
-
---
|
|
22
|
-
|
|
23
|
-
## Why
|
|
14
|
+
Preserve the agent's **working state**—goals, files, decisions, errors,
|
|
15
|
+
constraints, and open loops—not just a vague recap of the conversation.
|
|
24
16
|
|
|
25
|
-
|
|
26
|
-
context that matters most during coding. The result is the classic
|
|
27
|
-
*"didn't we already fix this?"* loop.
|
|
28
|
-
|
|
29
|
-
| Default compaction | `pi-smart-compact` |
|
|
30
|
-
| --- | --- |
|
|
31
|
-
| Trims by token count | Extracts facts deterministically (zero LLM) |
|
|
32
|
-
| Generic prose recap | Structured working-state summary |
|
|
33
|
-
| Loses files / errors / decisions | Preserves them, then **verifies** they survived |
|
|
34
|
-
| No regression signal | Damage detection + metrics dashboard |
|
|
17
|
+
</div>
|
|
35
18
|
|
|
36
19
|
## Install
|
|
37
20
|
|
|
@@ -39,7 +22,7 @@ context that matters most during coding. The result is the classic
|
|
|
39
22
|
pi install npm:pi-smart-compact
|
|
40
23
|
```
|
|
41
24
|
|
|
42
|
-
|
|
25
|
+
Or install directly from GitHub:
|
|
43
26
|
|
|
44
27
|
```bash
|
|
45
28
|
pi install git:github.com/alpertarhan/pi-smart-compact
|
|
@@ -48,237 +31,354 @@ pi install git:github.com/alpertarhan/pi-smart-compact
|
|
|
48
31
|
## Quick start
|
|
49
32
|
|
|
50
33
|
```bash
|
|
51
|
-
/smart-compact
|
|
52
|
-
/smart-compact
|
|
53
|
-
/smart-compact
|
|
54
|
-
/smart-compact
|
|
55
|
-
/smart-compact
|
|
56
|
-
/smart-compact
|
|
34
|
+
/smart-compact # interactive model + profile picker
|
|
35
|
+
/smart-compact balanced # direct profile
|
|
36
|
+
/smart-compact anthropic/claude-sonnet-4 balanced # direct model + profile
|
|
37
|
+
/smart-compact balanced --focus=auth # preserve extra auth detail
|
|
38
|
+
/smart-compact metrics # text metrics report
|
|
39
|
+
/smart-compact dashboard # interactive metrics dashboard
|
|
40
|
+
/smart-compact restore # browse and restore backups
|
|
41
|
+
/smart-compact loops # manage persisted open loops
|
|
57
42
|
```
|
|
58
43
|
|
|
59
|
-
|
|
44
|
+
The extension also participates in Pi's native compaction flow automatically
|
|
45
|
+
when actual context usage crosses the configured threshold (60% by default),
|
|
46
|
+
and exposes a `smart_compact` tool for long-running agents.
|
|
60
47
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
48
|
+
> The tool path stages a safe pending summary. It never compacts the active
|
|
49
|
+
> conversation in the middle of an agent turn.
|
|
50
|
+
|
|
51
|
+
## Why smart compaction?
|
|
52
|
+
|
|
53
|
+
| Native-style recap | `pi-smart-compact` |
|
|
54
|
+
| --- | --- |
|
|
55
|
+
| Summarizes prose | Preserves operational coding state |
|
|
56
|
+
| Trusts one LLM response | Extracts deterministic ground truth first |
|
|
57
|
+
| File/error omissions can be silent | Verifies coverage and repairs known gaps |
|
|
58
|
+
| One strategy for every session | Chooses single-pass or hierarchical synthesis |
|
|
59
|
+
| No quality feedback | Tracks provenance, damage signals, and metrics |
|
|
60
|
+
|
|
61
|
+
The design principle is simple:
|
|
62
|
+
|
|
63
|
+
> **Facts first. Synthesis second. Verification before apply.**
|
|
64
|
+
|
|
65
|
+
## EESV pipeline
|
|
66
|
+
|
|
67
|
+
```text
|
|
68
|
+
Pi conversation
|
|
69
|
+
│
|
|
70
|
+
▼
|
|
71
|
+
┌───────────┐ ┌───────────┐ ┌────────────┐ ┌───────────┐
|
|
72
|
+
│ Extract │ → │ Explore │ → │ Synthesize │ → │ Verify │
|
|
73
|
+
│ 0 LLM │ │ adaptive │ │ 1-pass or │ │ + repair │
|
|
74
|
+
│ calls │ │ │ │ hierarchical│ │ │
|
|
75
|
+
└───────────┘ └───────────┘ └────────────┘ └───────────┘
|
|
76
|
+
│
|
|
77
|
+
▼
|
|
78
|
+
staged/applied by Pi
|
|
66
79
|
```
|
|
67
80
|
|
|
68
|
-
|
|
69
|
-
|
|
81
|
+
| Stage | Responsibility |
|
|
82
|
+
| --- | --- |
|
|
83
|
+
| **Extract** | Deterministically catalogs files, errors, decisions, constraints, topics, media metadata, and open loops. This is the verification ground truth. |
|
|
84
|
+
| **Explore** | Uses a cheaper segmentation model when a complex session needs deeper topic boundaries or error-chain inspection. Simple sessions skip it. |
|
|
85
|
+
| **Synthesize** | Uses one pass for short sessions and bounded chunk/assembly fallbacks for long sessions. Focus and call/latency budgets are enforced here. |
|
|
86
|
+
| **Verify** | Checks canonical sections and extracted facts, applies every safe deterministic repair, and escalates only unresolved low-scoring gaps to an LLM patch. |
|
|
70
87
|
|
|
71
|
-
|
|
88
|
+
### What survives compaction
|
|
72
89
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
90
|
+
- The current goal and user constraints
|
|
91
|
+
- Modified, read, and deleted files
|
|
92
|
+
- Unresolved **and** resolved error history
|
|
93
|
+
- Explicit and implicit decisions
|
|
94
|
+
- Open follow-ups, blockers, priorities, and pinned loops
|
|
95
|
+
- Next actions and critical continuation context
|
|
96
|
+
- Changes since the previous compaction
|
|
97
|
+
|
|
98
|
+
Summaries use a canonical H1/H2/H3-aware structure, collision-safe file
|
|
99
|
+
matching, typed verification gaps, and persisted repair provenance.
|
|
80
100
|
|
|
81
|
-
|
|
101
|
+
## Usage surfaces
|
|
102
|
+
|
|
103
|
+
| Surface | Behavior |
|
|
82
104
|
| --- | --- |
|
|
83
|
-
|
|
|
84
|
-
|
|
|
85
|
-
|
|
|
86
|
-
|
|
|
105
|
+
| `/smart-compact` | Explicit manual run. Supports picker UI, direct args, dry-run, focus, and budgets. |
|
|
106
|
+
| `session_before_compact` | Auto path. Runs before Pi's native compaction and returns a verification-scored result when context pressure is high. |
|
|
107
|
+
| `smart_compact` tool | Agent path. Produces a pending summary for Pi's next natural compact; does not compact mid-turn. |
|
|
108
|
+
| `/smart-compact loops` | Project-level open-loop manager: resolve/reopen, priority, pin/unpin. |
|
|
87
109
|
|
|
88
|
-
|
|
89
|
-
deleted files · unresolved & resolved errors · key decisions · open follow-up
|
|
90
|
-
work · critical next-turn context · the delta since the previous compaction.
|
|
110
|
+
### Focus and budgets
|
|
91
111
|
|
|
92
|
-
|
|
112
|
+
```bash
|
|
113
|
+
/smart-compact balanced --focus=authentication
|
|
114
|
+
/smart-compact aggressive --max-calls=6 --max-latency=30000
|
|
115
|
+
/smart-compact balanced --focus=src/auth.ts --max-calls=8
|
|
116
|
+
```
|
|
93
117
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
118
|
+
- `--focus` assigns more synthesis/exploration budget to a topic or path. It
|
|
119
|
+
does **not** attempt unsupported non-contiguous compaction.
|
|
120
|
+
- `--max-calls` accepts `1–100`.
|
|
121
|
+
- `--max-latency` accepts `5000–600000` milliseconds.
|
|
122
|
+
- Call-budget exhaustion degrades to deterministic summaries. The latency
|
|
123
|
+
budget is a hard cancellation deadline.
|
|
99
124
|
|
|
100
|
-
|
|
101
|
-
|
|
125
|
+
The tool exposes equivalent `focus`, `max_calls`, and `max_latency_ms`
|
|
126
|
+
parameters.
|
|
102
127
|
|
|
103
|
-
##
|
|
128
|
+
## Profiles
|
|
104
129
|
|
|
105
|
-
|
|
130
|
+
| Profile | Summary budget | Recent context kept | Best for |
|
|
131
|
+
| --- | ---: | ---: | --- |
|
|
132
|
+
| `light` | 10,000 tokens | 30,000 tokens | Maximum continuity and detail |
|
|
133
|
+
| `balanced` | 6,000 tokens | 20,000 tokens | General use; default |
|
|
134
|
+
| `aggressive` | 3,000 tokens | 10,000 tokens | Tight context budgets |
|
|
106
135
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
Add retry/backoff to the LLM client so transient 429/5xx don't abort compaction.
|
|
136
|
+
Profiles are a starting policy. Provider/model calibration, conversation shape,
|
|
137
|
+
focus hints, damage feedback, and explicit budgets refine the actual run.
|
|
110
138
|
|
|
111
|
-
##
|
|
112
|
-
- [requirement] never compact mid-turn from the tool path
|
|
139
|
+
## Safety and privacy
|
|
113
140
|
|
|
114
|
-
|
|
115
|
-
### Done
|
|
116
|
-
- [x] Added `withRetry` wrapper in src/infra/llm-retry.ts
|
|
117
|
-
### In Progress
|
|
118
|
-
- [ ] Wire retry client into the services container
|
|
119
|
-
### Blocked
|
|
120
|
-
- None
|
|
141
|
+
### Deterministic safeguards
|
|
121
142
|
|
|
122
|
-
|
|
123
|
-
-
|
|
143
|
+
- Tool-call-aware recent-tail budgeting
|
|
144
|
+
- Exact access-call pruning—different reads, searches, offsets, and patterns do not collapse
|
|
145
|
+
- Tool-call/tool-result pair integrity at the compaction boundary
|
|
146
|
+
- Collision-safe modified-file verification for monorepos
|
|
147
|
+
- Mandatory deterministic repair for patchable verification gaps
|
|
148
|
+
- Cross-session guard and five-minute TTL for pending summaries
|
|
149
|
+
- Session-log recovery for older, truncated tool results
|
|
150
|
+
- Retention-pruned backups before compaction
|
|
124
151
|
|
|
125
|
-
|
|
126
|
-
- src/infra/llm-retry.ts
|
|
127
|
-
- src/infra/llm-client.ts
|
|
152
|
+
### Secrets and PII
|
|
128
153
|
|
|
129
|
-
|
|
130
|
-
|
|
154
|
+
High-confidence secret scrubbing is enabled by default at every relevant trust
|
|
155
|
+
boundary:
|
|
131
156
|
|
|
132
|
-
|
|
133
|
-
|
|
157
|
+
```text
|
|
158
|
+
provider request · extraction cache · backup · state · pending summary
|
|
159
|
+
```
|
|
134
160
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
161
|
+
It covers common API keys, cloud/GitHub/Slack tokens, JWTs, bearer tokens,
|
|
162
|
+
private keys, and credential assignments. Optional email/phone/payment-card
|
|
163
|
+
scrubbing is available through `scrubPii`.
|
|
138
164
|
|
|
139
|
-
|
|
140
|
-
|
|
165
|
+
Secret scrubbing is defense in depth, **not a replacement for proper secret
|
|
166
|
+
handling or a dedicated DLP system**. See the
|
|
167
|
+
[security policy](https://github.com/alpertarhan/pi-smart-compact/blob/main/SECURITY.md).
|
|
141
168
|
|
|
142
|
-
|
|
143
|
-
|
|
169
|
+
### Approval and feedback
|
|
170
|
+
|
|
171
|
+
- `requireApproval: true` adds a fail-closed manual **Apply / Cancel** decision
|
|
172
|
+
after the provenance review screen. Auto and tool paths retain their native
|
|
173
|
+
staged lifecycle.
|
|
174
|
+
- Online damage monitoring observes the first post-compaction messages and
|
|
175
|
+
records re-read files or repeated context. Remediation hints feed those files
|
|
176
|
+
into the next compaction.
|
|
177
|
+
- `adaptiveDamageFeedback` can opt a project into larger preservation budgets
|
|
178
|
+
after repeated high-damage reports.
|
|
144
179
|
|
|
145
|
-
##
|
|
146
|
-
|
|
180
|
+
## Open-loop control
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
/smart-compact loops
|
|
147
184
|
```
|
|
148
185
|
|
|
149
|
-
|
|
150
|
-
|
|
186
|
+
The manager operates on the project's persisted `CompactionState`:
|
|
187
|
+
|
|
188
|
+
- resolve or reopen a loop
|
|
189
|
+
- change priority
|
|
190
|
+
- pin or unpin it across later compactions
|
|
191
|
+
|
|
192
|
+
Overrides use normalized summary identity instead of positional IDs, so a loop
|
|
193
|
+
cannot accidentally inherit another loop's state on a later run.
|
|
151
194
|
|
|
152
195
|
## Configuration
|
|
153
196
|
|
|
154
|
-
Add to `~/.pi/agent/settings.json`:
|
|
197
|
+
Add `smartCompact` to `~/.pi/agent/settings.json`:
|
|
155
198
|
|
|
156
199
|
```json
|
|
157
200
|
{
|
|
158
201
|
"smartCompact": {
|
|
159
202
|
"profile": "balanced",
|
|
160
|
-
"summaryModel":
|
|
203
|
+
"summaryModel": null,
|
|
204
|
+
"segmentationModel": null,
|
|
205
|
+
"summaryThinkingLevel": null,
|
|
206
|
+
"segmentationThinkingLevel": null,
|
|
161
207
|
"autoTrigger": true,
|
|
162
208
|
"minContextPercent": 60,
|
|
163
|
-
"backupEnabled": true
|
|
209
|
+
"backupEnabled": true,
|
|
210
|
+
"scrubSecrets": true,
|
|
211
|
+
"scrubPii": false,
|
|
212
|
+
"requireApproval": false,
|
|
213
|
+
"maxLlmCalls": 0,
|
|
214
|
+
"maxLatencyMs": 0,
|
|
215
|
+
"focusWeighting": true,
|
|
216
|
+
"onlineDamageMonitor": true,
|
|
217
|
+
"adaptiveDamageFeedback": false,
|
|
218
|
+
"pinPaths": []
|
|
164
219
|
}
|
|
165
220
|
}
|
|
166
221
|
```
|
|
167
222
|
|
|
168
|
-
|
|
169
|
-
| --- | --- | --- |
|
|
170
|
-
| `profile` | `light \| balanced \| aggressive` | `balanced` |
|
|
171
|
-
| `summaryModel` | `string \| null` | `null` (uses session model) |
|
|
172
|
-
| `segmentationModel` | `string \| null` | `null` |
|
|
173
|
-
| `autoTrigger` | `boolean` | `true` |
|
|
174
|
-
| `autoTriggerTimeoutMs` | `number` | `120000` |
|
|
175
|
-
| `minContextPercent` | `number` | `60` |
|
|
176
|
-
| `backupEnabled` | `boolean` | `true` |
|
|
177
|
-
| `backupDir` | `string` | `~/.pi/agent/compact-backups` |
|
|
178
|
-
| `profiles` | per-profile overrides | built-ins |
|
|
179
|
-
| `pinPaths` | `string[]` | `[]` (paths always preserved) |
|
|
180
|
-
|
|
181
|
-
### Profiles
|
|
182
|
-
|
|
183
|
-
| Profile | Summary budget | Keep recent | Use when |
|
|
184
|
-
| --- | ---: | ---: | --- |
|
|
185
|
-
| `light` | 10000 | 30000 | preserve more detail |
|
|
186
|
-
| `balanced` | 6000 | 20000 | default, general use |
|
|
187
|
-
| `aggressive` | 3000 | 10000 | tighter summaries |
|
|
223
|
+
### Per-phase reasoning
|
|
188
224
|
|
|
189
|
-
|
|
225
|
+
Exploration can use a cheaper reasoning level while final synthesis and repair
|
|
226
|
+
use a stronger one:
|
|
190
227
|
|
|
191
|
-
|
|
228
|
+
```json
|
|
229
|
+
{
|
|
230
|
+
"smartCompact": {
|
|
231
|
+
"segmentationThinkingLevel": "low",
|
|
232
|
+
"summaryThinkingLevel": "high"
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
```
|
|
192
236
|
|
|
193
|
-
|
|
237
|
+
`segmentationThinkingLevel` applies to exploration; `summaryThinkingLevel`
|
|
238
|
+
applies to synthesis, assembly, and repair. Supported values are `minimal`,
|
|
239
|
+
`low`, `medium`, `high`, `xhigh`, and `max`. Leave either value as `null` to
|
|
240
|
+
preserve the provider's existing behavior. An explicit call-level reasoning
|
|
241
|
+
option takes precedence over these defaults.
|
|
242
|
+
|
|
243
|
+
<details>
|
|
244
|
+
<summary><strong>All configuration keys</strong></summary>
|
|
245
|
+
|
|
246
|
+
| Key | Type | Default | Notes |
|
|
247
|
+
| --- | --- | --- | --- |
|
|
248
|
+
| `profile` | `light \| balanced \| aggressive` | `balanced` | Default policy profile |
|
|
249
|
+
| `summaryModel` | `string \| null` | `null` | Uses the active session model when null |
|
|
250
|
+
| `segmentationModel` | `string \| null` | `null` | Optional cheaper model for Explore |
|
|
251
|
+
| `summaryThinkingLevel` | `minimal \| low \| medium \| high \| xhigh \| max \| null` | `null` | Reasoning level for synthesis and repair; provider default when null |
|
|
252
|
+
| `segmentationThinkingLevel` | `minimal \| low \| medium \| high \| xhigh \| max \| null` | `null` | Reasoning level for exploration; provider default when null |
|
|
253
|
+
| `autoTrigger` | `boolean` | `true` | Participate in Pi's native compact hook |
|
|
254
|
+
| `autoTriggerTimeoutMs` | `number` | `120000` | Hard timeout for automatic runs |
|
|
255
|
+
| `minContextPercent` | `number` | `60` | Actual context usage gate |
|
|
256
|
+
| `backupEnabled` | `boolean` | `true` | Write a pre-compaction backup |
|
|
257
|
+
| `backupDir` | `string` | `~/.pi/agent/compact-backups` | Empty config value uses this path |
|
|
258
|
+
| `profiles` | object | built-ins | Per-profile numeric overrides |
|
|
259
|
+
| `pinPaths` | `string[]` | `[]` | Always preserve matching paths |
|
|
260
|
+
| `requireApproval` | `boolean` | `false` | Manual UI only; cancel/error fails closed |
|
|
261
|
+
| `scrubSecrets` | `boolean` | `true` | High-confidence credential redaction |
|
|
262
|
+
| `scrubPii` | `boolean` | `false` | Email/phone/card-shaped redaction |
|
|
263
|
+
| `maxLlmCalls` | integer `0–100` | `0` | `0` means unlimited |
|
|
264
|
+
| `maxLatencyMs` | `0` or `5000–600000` | `0` | `0` means unlimited |
|
|
265
|
+
| `focusWeighting` | `boolean` | `true` | Weight focused topics/paths higher |
|
|
266
|
+
| `onlineDamageMonitor` | `boolean` | `true` | Observe post-compaction regression signals |
|
|
267
|
+
| `adaptiveDamageFeedback` | `boolean` | `false` | Increase preservation after repeated damage |
|
|
268
|
+
|
|
269
|
+
The legacy `semanticCompact` root key is still accepted for compatibility.
|
|
270
|
+
|
|
271
|
+
</details>
|
|
272
|
+
|
|
273
|
+
## Example summary
|
|
274
|
+
|
|
275
|
+
<details>
|
|
276
|
+
<summary><strong>Show canonical output</strong></summary>
|
|
194
277
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
- Open-loop injection + cross-compaction delta tracking
|
|
199
|
-
- Pinned-path preservation (`pinPaths`) — a deterministic, LLM-free guarantee
|
|
200
|
-
- Damage auto-remediation — re-read files feed forward and get re-preserved next compaction
|
|
278
|
+
```markdown
|
|
279
|
+
## Goal
|
|
280
|
+
Add retry/backoff to the LLM client without breaking cancellation.
|
|
201
281
|
|
|
202
|
-
|
|
282
|
+
## Constraints & Preferences
|
|
283
|
+
- [requirement] Never compact mid-turn from the tool path.
|
|
203
284
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
-
|
|
207
|
-
|
|
285
|
+
## Progress
|
|
286
|
+
### Done
|
|
287
|
+
- [x] Added `withRetry` in `src/infra/llm-retry.ts`.
|
|
288
|
+
### In Progress
|
|
289
|
+
- [ ] Wire the retry client into run-scoped services.
|
|
290
|
+
### Blocked
|
|
291
|
+
- None.
|
|
208
292
|
|
|
209
|
-
|
|
293
|
+
## Key Decisions
|
|
294
|
+
- **Honor Retry-After verbatim**: provider limits are authoritative.
|
|
210
295
|
|
|
211
|
-
|
|
212
|
-
-
|
|
213
|
-
-
|
|
296
|
+
## Files Modified
|
|
297
|
+
- src/infra/llm-retry.ts
|
|
298
|
+
- src/infra/llm-client.ts
|
|
214
299
|
|
|
215
|
-
##
|
|
300
|
+
## Open Loops
|
|
301
|
+
- [high] Preserve AbortSignal behavior across providers.
|
|
216
302
|
|
|
217
|
-
|
|
218
|
-
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
303
|
+
## Changes Since Last Compaction
|
|
304
|
+
- New files touched: src/infra/llm-retry.ts
|
|
305
|
+
|
|
306
|
+
## Next Steps
|
|
307
|
+
1. Add an outer timeout as a second line of defense.
|
|
308
|
+
|
|
309
|
+
## Critical Context
|
|
310
|
+
- Retry 408/425/429/5xx; fail fast on other 4xx responses.
|
|
311
|
+
```
|
|
223
312
|
|
|
224
|
-
|
|
313
|
+
</details>
|
|
225
314
|
|
|
226
|
-
|
|
227
|
-
published bundle. This keeps the extension independent from Pi's release cadence:
|
|
228
|
-
the lockfile provides a reproducible development baseline, while daily CI runs
|
|
229
|
-
the full suite against the latest Pi packages without changing the manifest.
|
|
315
|
+
## Observability and recovery
|
|
230
316
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
outputs from the session log.
|
|
317
|
+
```bash
|
|
318
|
+
/smart-compact metrics # text report
|
|
319
|
+
/smart-compact dashboard # interactive TUI; can write a local HTML report
|
|
320
|
+
/smart-compact restore # browse, inspect, and restore backups
|
|
321
|
+
```
|
|
237
322
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
context-rewriting extension, prefer a single `session_before_compact` owner
|
|
242
|
-
unless hook order is explicitly coordinated.
|
|
323
|
+
Metrics include method, profile, provider, phase timing, token/call estimates,
|
|
324
|
+
verification quality, cache behavior, redactions, adaptation, fallbacks, and
|
|
325
|
+
cancelled runs.
|
|
243
326
|
|
|
244
|
-
|
|
327
|
+
<details>
|
|
328
|
+
<summary><strong>Runtime artifacts</strong></summary>
|
|
245
329
|
|
|
246
|
-
|
|
330
|
+
All files live under `~/.pi/agent/`.
|
|
247
331
|
|
|
248
332
|
| Path | Purpose |
|
|
249
333
|
| --- | --- |
|
|
250
|
-
| `settings.json` |
|
|
251
|
-
| `compact-backups/` | conversation backups
|
|
252
|
-
| `.cache/compact-extraction-<session>.json` |
|
|
253
|
-
| `.cache/compact-metrics.jsonl` | metrics log
|
|
254
|
-
| `.cache/smart-compact-report.html` | HTML dashboard |
|
|
255
|
-
| `.cache/smart-compact/projects/<projectId>.json` |
|
|
256
|
-
| `.cache/smart-compact/states/<projectId>.json` |
|
|
257
|
-
| `.cache/smart-compact/damage-reports.jsonl` |
|
|
258
|
-
| `.cache/smart-compact/remediation-<projectId>.json` |
|
|
334
|
+
| `settings.json` | Configuration (read only) |
|
|
335
|
+
| `compact-backups/` | Retention-pruned conversation backups |
|
|
336
|
+
| `.cache/compact-extraction-<session>.json` | Incremental extraction cache |
|
|
337
|
+
| `.cache/compact-metrics.jsonl` | Tail-retained metrics log; 5 MiB cap |
|
|
338
|
+
| `.cache/smart-compact-report.html` | Local HTML dashboard |
|
|
339
|
+
| `.cache/smart-compact/projects/<projectId>.json` | Project fingerprint |
|
|
340
|
+
| `.cache/smart-compact/states/<projectId>.json` | Compaction state and loop overrides |
|
|
341
|
+
| `.cache/smart-compact/damage-reports.jsonl` | Damage reports; 5 MiB cap |
|
|
342
|
+
| `.cache/smart-compact/remediation-<projectId>.json` | Files to preserve after damage |
|
|
343
|
+
|
|
344
|
+
</details>
|
|
345
|
+
|
|
346
|
+
## Compatibility
|
|
347
|
+
|
|
348
|
+
Pi core packages are host-provided wildcard peers and are excluded from the
|
|
349
|
+
published bundle. The lockfile gives contributors a reproducible baseline,
|
|
350
|
+
while CI validates the latest Pi release daily without changing the manifest.
|
|
351
|
+
An exact version can be checked with `bun run compat:pi <version>`.
|
|
352
|
+
|
|
353
|
+
`pi-smart-compact` is designed to coexist with
|
|
354
|
+
[`pi-toolkit`](https://github.com/ersintarhan/pi-toolkit): toolkit handles daily
|
|
355
|
+
context hygiene; smart-compact handles high-pressure verified compaction. If
|
|
356
|
+
another extension also owns `session_before_compact` or rewrites branch history,
|
|
357
|
+
coordinate hook order or prefer a single automatic compaction owner.
|
|
259
358
|
|
|
260
359
|
## Development
|
|
261
360
|
|
|
262
361
|
```bash
|
|
263
362
|
bun install
|
|
264
|
-
bun run typecheck
|
|
265
|
-
bun test
|
|
266
|
-
bun run
|
|
267
|
-
bun run
|
|
268
|
-
bun run
|
|
269
|
-
bun run
|
|
363
|
+
bun run typecheck
|
|
364
|
+
bun test
|
|
365
|
+
bun run gate # deterministic adversarial EESV release gate
|
|
366
|
+
bun run bench
|
|
367
|
+
bun run build
|
|
368
|
+
bun run compat:pi # isolated latest-Pi compatibility check
|
|
270
369
|
```
|
|
271
370
|
|
|
272
|
-
Pull requests run the
|
|
371
|
+
Pull requests run typecheck, the complete test suite, the adversarial gate, and
|
|
372
|
+
the build in GitHub Actions.
|
|
273
373
|
|
|
274
|
-
##
|
|
374
|
+
## Project documentation
|
|
275
375
|
|
|
276
|
-
- [
|
|
277
|
-
- [
|
|
278
|
-
- [
|
|
279
|
-
- [
|
|
280
|
-
- [
|
|
281
|
-
- [
|
|
376
|
+
- [Architecture](https://github.com/alpertarhan/pi-smart-compact/blob/main/ARCHITECTURE.md)
|
|
377
|
+
- [Changelog](https://github.com/alpertarhan/pi-smart-compact/blob/main/CHANGELOG.md)
|
|
378
|
+
- [Contributing](https://github.com/alpertarhan/pi-smart-compact/blob/main/CONTRIBUTING.md)
|
|
379
|
+
- [Security](https://github.com/alpertarhan/pi-smart-compact/blob/main/SECURITY.md)
|
|
380
|
+
- [Support](https://github.com/alpertarhan/pi-smart-compact/blob/main/SUPPORT.md)
|
|
381
|
+
- [Release checklist](https://github.com/alpertarhan/pi-smart-compact/blob/main/docs/RELEASE.md)
|
|
282
382
|
|
|
283
383
|
## License
|
|
284
384
|
|
|
@@ -38,6 +38,7 @@ import type { CompressionProfile, LlmMessage, StructuredExtraction, ExplorationR
|
|
|
38
38
|
import type { PendingSlot } from "./pending-slot.ts";
|
|
39
39
|
import type { PruningResult } from "../utils/pruning.ts";
|
|
40
40
|
import type { CompactionTier } from "../utils/helpers.ts";
|
|
41
|
+
import type { TokenEstimator } from "../utils/tokens.ts";
|
|
41
42
|
import type { SmartCompactServices } from "../infra/services.ts";
|
|
42
43
|
export type Notifier = (msg: string, type?: "info" | "success" | "warning" | "error") => void;
|
|
43
44
|
export interface CancellationToken {
|
|
@@ -76,6 +77,8 @@ export interface RcBase {
|
|
|
76
77
|
isRunning: Cell<boolean>;
|
|
77
78
|
flags: RunFlags;
|
|
78
79
|
userNote?: string;
|
|
80
|
+
focus?: string;
|
|
81
|
+
maxLlmCalls?: number;
|
|
79
82
|
timeoutMs: number;
|
|
80
83
|
phaseTimings: PipelinePhaseTiming[];
|
|
81
84
|
pipelineStart: number;
|
|
@@ -91,6 +94,8 @@ export interface PreparedExt {
|
|
|
91
94
|
config: CompactConfig;
|
|
92
95
|
profileCfg: ProfileConfig;
|
|
93
96
|
providerCaps: ProviderCapabilities;
|
|
97
|
+
estimator: TokenEstimator;
|
|
98
|
+
adapted: boolean;
|
|
94
99
|
summaryAuth: ResolvedAuth;
|
|
95
100
|
segAuth: ResolvedAuth;
|
|
96
101
|
}
|
|
@@ -157,6 +162,7 @@ export interface VerifiedExt extends SynthesizedExt {
|
|
|
157
162
|
readonly _verified: true;
|
|
158
163
|
verificationScore: number;
|
|
159
164
|
verificationGaps: string[];
|
|
165
|
+
verificationProvenance: import("../types.ts").VerificationProvenance;
|
|
160
166
|
verified: boolean;
|
|
161
167
|
}
|
|
162
168
|
export type VerifiedRc = RcBase & VerifiedExt;
|