pi-context-steward 0.0.0-stage → 1.0.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 ADDED
@@ -0,0 +1,19 @@
1
+ # Changelog
2
+
3
+ ## [1.0.1] - 2026-12-04
4
+
5
+ - README: comparison with related Pi packages ("How it compares").
6
+
7
+ ## [1.0.0] - 2026-12-04
8
+
9
+ First public release.
10
+
11
+ - Persistent context meter on every tool result (handle, size, context vs. budget), cache-stable by design.
12
+ - Batched consolidation through Pi `context_edit` entries: stale results, large tool-call inputs, old listings, outputs and reads are replaced by stubs; originals are saved to disk.
13
+ - Pin-preserving compaction: pinned facts are appended verbatim; stub notes are kept by the summarizer.
14
+ - Modes `off`, `meter`, `net`, `full`, and an automatic default (`net` from a 32k budget, `meter` below).
15
+ - Budget follows Pi's compaction threshold when `reserveTokens` is configured.
16
+ - Cost model that accounts for Anthropic's ~20-block cache lookback.
17
+ - JSON configuration with global, project and per-model layers; a default file is created on first start.
18
+ - Model-switch handling: warning when the context exceeds the new budget, larger previous model writes the summary.
19
+ - JSONL metrics and `scripts/analyze.mjs` for A/B comparisons.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Deemkeen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,286 @@
1
- # Temporary Holding Version
1
+ # pi-context-steward
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm](https://img.shields.io/npm/v/pi-context-steward)](https://www.npmjs.com/package/pi-context-steward)
4
+ [![CI](https://github.com/deemkeen/pi-context-steward/actions/workflows/ci.yml/badge.svg)](https://github.com/deemkeen/pi-context-steward/actions/workflows/ci.yml)
5
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
6
+
7
+ **Context awareness and cache-aware context management for the [Pi coding agent](https://pi.dev).**
8
+
9
+ The extension shows the model how full its context is. When the context approaches the budget, it removes stale and bulky tool output in a few large batches. That way the work goes on without compaction, and the prompt cache survives between those batches.
10
+
11
+ ![Results at a 128k budget](https://raw.githubusercontent.com/deemkeen/pi-context-steward/main/docs/results.png)
12
+
13
+ In 11 runs of the same task with Claude Opus 5.5 at a 128k budget, the recommended setting was the cheapest and fastest variant. It needed **no compaction**, while plain Pi needed three:
14
+
15
+ | Variant | Runs | Cost per run | Model time | Compactions | File reads |
16
+ |---|---|---|---|---|---|
17
+ | **`net`, soft 0.85 → target 0.35 (default)** | 1 | **$3.84** | **10.5 min** | **0** | **16** |
18
+ | `meter` | 2 | $4.08 | 11.3 min | 1 | 26.5 |
19
+ | `full`, soft 0.6 → 0.4 | 4 | $4.82 | 13.7 min | 0 | 16.8 |
20
+ | `net`, soft 0.6 → 0.4 | 2 | $5.08 | 12.6 min | 0 | 20 |
21
+ | `off` (Pi default) | 2 | $6.24 | 16.2 min | 3 | 33.5 |
22
+
23
+ Compared with plain Pi, the default setting cost **38% less**, finished **35% faster** and read **half as many files**. Every run reached the task goal. Run counts are small. The full study, including what it does *not* show, is in [docs/RESULTS.md](https://github.com/deemkeen/pi-context-steward/blob/main/docs/RESULTS.md).
24
+
25
+ ## How it compares
26
+
27
+ Several Pi packages manage context. What sets this one apart:
28
+
29
+ - **The model sees the meter, not just you.** Display packages show *you* how full the context is. This extension shows the *model*, in every tool result. With Opus 5.5 that alone changed behavior: it started writing findings to disk before a compaction could lose them. None of the packages below gives the model this signal.
30
+ - **Consolidation without a model call.** Summarizing pruners send finished tool batches to a summarizer model, which costs extra requests and latency. Here, rule-based stubs replace stale and bulky results, and the originals go to disk. A consolidation took 0.02–0.4 s in the measured runs.
31
+ - **Priced against the prompt cache.** Anthropic looks for cached prefixes only about 20 content blocks back, so any edit to older history makes the next request re-write the whole conversation. The planner estimates that cost, consolidates late and deep (85% → 35% of the budget, thresholds taken from measured runs) and skips a consolidation that would free too little to pay for it.
32
+ - **More than tool output.** It also shortens large inputs of finished tool calls (file contents passed to `write`/`edit`, long scripts), keeps pinned facts verbatim through compaction, picks its mode per model, and handles model switches.
33
+
34
+ | Package | Approach | Model call to prune | When history is rewritten | Model sees context vs. budget |
35
+ |---|---|---|---|---|
36
+ | **pi-context-steward** | Rule-based stubs and input shortening; originals on disk | **No** | **Rarely:** near the budget, only when it pays off | **Yes** |
37
+ | [pi-context-prune](https://pi.dev/packages/pi-context-prune) | LLM summaries of finished tool batches; `context_tree_query` recovers originals | Yes (configurable summarizer) | Per batch; by default the model decides when | No |
38
+ | [pi-condense](https://pi.dev/packages/pi-condense) | Builds on pi-context-prune; adds zero-LLM shortcuts (dedup, spill to file, chain compression) | Mostly | Once per finished unit of work | No |
39
+ | [pi-context-pruning](https://pi.dev/packages/pi-context-pruning) | OpenCode-style: old tool outputs become markers | No | After every turn | No |
40
+ | [pi-context-usage](https://pi.dev/packages/pi-context-usage), [pi-context-view](https://pi.dev/packages/pi-context-view) | Visualize context usage for you | – | Never | No |
41
+ | [pi-cache-optimizer](https://pi.dev/packages/pi-cache-optimizer) | Raises the cache hit rate (stable prompt, cache keys) | – | Never | No |
42
+
43
+ Packages that change compaction itself solve a different problem: they make compaction better or cheaper, while this extension aims to make it rare. Examples are [pi-vcc](https://pi.dev/packages/pi-vcc) (algorithmic, no LLM call), [pi-jev-compaction](https://pi.dev/packages/pi-jev-compaction) (keep/drop/truncate decisions), [pi-observational-memory](https://pi.dev/packages/pi-observational-memory) (memory prepared in the background) and [pi-early-compact](https://pi.dev/packages/pi-early-compact) (compacts early on 1M-window models).
44
+
45
+ **When another package may suit you better:** pi-context-prune is more mature and widely used, and its LLM summaries usually keep more of a result than a rule-based stub. It also has a dedicated recovery tool; here the stub names a file that the model reads back with `read`.
46
+
47
+ ---
48
+
49
+ ## Contents
50
+
51
+ - [Install](#install)
52
+ - [Quick start: Opus via GitHub Copilot](#quick-start-opus-via-github-copilot)
53
+ - [How it works](#how-it-works)
54
+ - [Modes](#modes)
55
+ - [Configuration](#configuration)
56
+ - [Switching models](#switching-models)
57
+ - [Measuring your own runs](#measuring-your-own-runs)
58
+ - [Limitations](#limitations)
59
+ - [Development](#development)
60
+
61
+ ## Install
62
+
63
+ ```bash
64
+ # from npm (recommended)
65
+ pi install npm:pi-context-steward
66
+
67
+ # or straight from GitHub
68
+ pi install git:github.com/deemkeen/pi-context-steward
69
+
70
+ # or try it for one session without installing
71
+ pi -e npm:pi-context-steward
72
+ ```
73
+
74
+ Developed and tested with `@earendil-works/pi-coding-agent` 1.8.0. The extension needs no runtime dependencies besides what Pi supplies.
75
+
76
+ On first start it creates `~/.pi/agent/context-steward.json` with the recommended defaults. Run `/steward` to see what it decided for the current model.
77
+
78
+ ## Quick start: Opus via GitHub Copilot
79
+
80
+ 1. In Pi, run `/login` and choose **GitHub Copilot**.
81
+ 2. Make Opus the default model and set the compaction threshold, here 300k, in `~/.pi/agent/settings.json`:
82
+
83
+ ```json
84
+ {
85
+ "defaultProvider": "github-copilot",
86
+ "defaultModel": "claude-opus-5.5",
87
+ "compaction": {
88
+ "modelOverrides": {
89
+ "github-copilot/claude-opus-5.5": { "reserveTokens": 700000, "keepRecentTokens": 40000 }
90
+ }
91
+ }
92
+ }
93
+ ```
94
+
95
+ `reserveTokens` = context window − threshold = 1,000,000 − 300,000.
96
+ 3. Start Pi. The extension's budget follows that threshold, and the mode is chosen automatically (`net`). `/steward` should show:
97
+
98
+ ```
99
+ mode net · auto (budget 300k: harness consolidation, no compactions in measured runs)
100
+ context 4k / budget 300k · consolidation at 255k · Pi compaction at 300k
101
+ ```
102
+
103
+ No extension configuration is needed. Everything else is optional.
104
+
105
+ ## How it works
106
+
107
+ The extension has three layers.
108
+
109
+ ### 1. Meter
110
+
111
+ Every tool result gets a short meter, written into the stored result itself:
112
+
113
+ ```
114
+ ⟦r12 · 3.1k · ctx 46k/128k 36%⟧
115
+ ```
116
+
117
+ That is the result's handle (`r12`), its size, and the context against the budget. A short section in the system prompt explains it.
118
+
119
+ The meter is part of the result **when the result is created**, not added on each request. Pi places the cache breakpoint on the last block of a request. A meter that changed from one request to the next would make every cached prefix unreachable. A meter stored with the result is byte-identical in every later request.
120
+
121
+ The meter alone already changes behavior. With Opus 5.5 the model plans around it, for example:
122
+
123
+ > *"Compaction will likely happen, so I'll write my findings progressively into ARCHITECTURE.md"*
124
+
125
+ The model writes notes to disk early instead of losing them to a summary later.
126
+
127
+ ### 2. Consolidation (the safety net)
128
+
129
+ When the context reaches `softRatio` × budget (default 85%), the harness replaces tool results with stubs until the context is down to `targetRatio` × budget (default 35%). It works in this order:
130
+
131
+ 1. Results the model asked to prune (`full` mode only).
132
+ 2. Stale results: a file read and later edited, written or read again; a command that ran again.
133
+ 3. Large inputs of successful tool calls, such as file contents passed to `write`/`edit` or long heredoc scripts. They are cut to their first and last lines. Files on disk are unaffected. Thinking blocks and their signatures are never touched.
134
+ 4. Old listings and searches (`ls`, `find`, `grep`, `rg`, `git status`, …).
135
+ 5. Old command output. The stub keeps the last lines, which usually hold the verdict.
136
+ 6. Old file reads.
137
+
138
+ A stub looks like this:
139
+
140
+ ```
141
+ ⟦r31 pruned · bash `mvn … test` · was 4.8k⟧
142
+ Old output. Ended with: [INFO] Tests run: 1360, Failures: 0 | [INFO] BUILD SUCCESS
143
+ Original: ~/.pi/agent/sessions/…/context-steward/<session>/r31.txt
144
+ ```
145
+
146
+ The original is written to disk and can be read back. The session file keeps it as well, because Pi `context_edit` entries change the model's view, not the history.
147
+
148
+ **Never touched:** the newest 6 results, the newest 15% of the budget, your messages, the model's text and thinking, and error output unless it is stale.
149
+
150
+ **Why so late, and why so deep:** Anthropic looks for cached prefixes only about 20 content blocks back from the cache breakpoint. Editing anything older therefore makes the next request **re-write the entire conversation** to the cache. Every consolidation costs a full rewrite, however little it frees. So it should happen rarely and free a lot. Measured at 128k: consolidating late and deep (85% → 35%) cost **$3.84** per run with 2 consolidations, while consolidating early (60% → 40%) cost **$5.08** with 6. A consolidation that would free less than 12% of the budget is skipped.
151
+
152
+ A consolidation needs no model call. It took 0.02–0.4 s in the measured runs; a Pi compaction took 18–55 s.
153
+
154
+ ### 3. Pin-preserving compaction
155
+
156
+ If compaction still happens, the extension writes the summary with Pi's own summarizer and adds three things:
157
+ - an instruction to keep the notes from stubs,
158
+ - your pinned facts, appended **verbatim**,
159
+ - the lists of read and modified files.
160
+
161
+ If anything fails, Pi's default compaction runs instead.
162
+
163
+ ## Modes
164
+
165
+ | Mode | Meter | Consolidation + pin-preserving compaction | `context_prune` / `context_pin` tools |
166
+ |---|---|---|---|
167
+ | `off` | – | – | – |
168
+ | `meter` | ✓ | – | – |
169
+ | `net` | ✓ | ✓ | – |
170
+ | `full` | ✓ | ✓ | ✓ |
171
+
172
+ **Default: automatic.** Without an explicit `mode`, the extension chooses per model from the effective budget:
173
+ - **`net` from 32k up.** It was the best variant measured at 128k. At 300k a cost model calibrated on the runs estimates it as cheap as `meter`, about 10% faster, and without compactions.
174
+ - **`meter` below 32k.** The protected newest results then fill most of the room, and a consolidation rarely frees enough to pay for a cache rewrite.
175
+
176
+ `full` additionally gives the model two tools:
177
+ - `context_prune({ items: [{ id: "r12", note: "…" }], now? })`: the model removes results itself, and its note replaces the content.
178
+ - `context_pin({ add?, remove? })`: facts that survive every compaction word for word.
179
+
180
+ The model uses these sensibly, for example pruning once at a phase boundary. At 128k, though, the extra calls and cache rewrites cost more than they saved. That is why `full` is opt-in.
181
+
182
+ ## Configuration
183
+
184
+ Everyday settings live in JSON. Later layers win:
185
+
186
+ | Layer | Location |
187
+ |---|---|
188
+ | defaults | built in |
189
+ | global | `~/.pi/agent/context-steward.json`, created on first start (`PI_STEWARD_CONFIG` points elsewhere) |
190
+ | project | `<project>/.pi/context-steward.json`, read only in trusted projects (`/steward init` creates it) |
191
+ | per model | `"models": { "provider/id": { … } }` inside either file |
192
+ | environment | `PI_STEWARD_*` |
193
+ | flags | `--steward-mode`, `--steward-budget`, `--steward-label`, `--steward-summary-model` |
194
+
195
+ Example:
196
+
197
+ ```json
198
+ {
199
+ "softRatio": 0.85,
200
+ "targetRatio": 0.35,
201
+ "models": {
202
+ "github-copilot/claude-opus-5.5": { "budget": 300000 },
203
+ "github-copilot/claude-sonnet-5.5": { "mode": "meter" }
204
+ }
205
+ }
206
+ ```
207
+
208
+ | Key | Default | Meaning |
209
+ |---|---|---|
210
+ | `mode` | automatic | `auto`, `off`, `meter`, `net`, `full`. Leave it out for the automatic choice. |
211
+ | `budget` | follows Pi | Working budget in tokens. Without it, the budget follows Pi's compaction threshold when `reserveTokens` is set, else min(window, 128k). Capped at the model window. |
212
+ | `softRatio` | `0.85` | Consolidation starts at this share of the budget. |
213
+ | `targetRatio` | `0.35` | Consolidation goes down to this share. |
214
+ | `minFreeRatio` | `0.12` | A consolidation that frees less is skipped. |
215
+ | `elideInputs` | `true` | Shorten large inputs of successful tool calls. |
216
+ | `protectRecentResults` | `6` | Newest results the harness never prunes. |
217
+ | `protectTailRatio` | `0.15` | Newest share of the budget the harness never prunes. |
218
+ | `summaryModel` | current model | `provider/id` that writes compaction summaries. |
219
+ | `label` | – | Tags all metrics (top level only). |
220
+ | `metricsPath` | `~/.pi/agent/context-steward/metrics.jsonl` | Metrics file (top level only). |
221
+
222
+ Invalid values and unknown keys are reported at startup and in `/steward`. Valid keys still apply. The generated file references `context-steward.schema.json` for editor autocompletion. Run `/reload` after editing.
223
+
224
+ Environment variables: `PI_STEWARD_MODE`, `PI_STEWARD_BUDGET`, `PI_STEWARD_LABEL`, `PI_STEWARD_SUMMARY_MODEL`, `PI_STEWARD_SOFT`, `PI_STEWARD_TARGET`, `PI_STEWARD_MIN_FREE`, `PI_STEWARD_PROTECT_RESULTS`, `PI_STEWARD_PROTECT_TAIL`, `PI_STEWARD_ELIDE_INPUTS`, `PI_STEWARD_METRICS`, `PI_STEWARD_CONFIG`.
225
+
226
+ **Commands:**
227
+ - `/steward`: mode and why, context, budget, thresholds, counters, config files in use, and errors.
228
+ - `/steward init`: creates a project config.
229
+
230
+ ## Switching models
231
+
232
+ On a model switch the extension reloads the configuration for the new model, recomputes budget, thresholds and the automatic mode, and turns the tools on or off to match.
233
+
234
+ If the context is larger than the new model's budget, it warns: Pi will compact before the next request. In `net`/`full` it also picks a summarizer the history fits into, in this order:
235
+ 1. `summaryModel`, if set,
236
+ 2. the new model, if the history fits into 80% of its window,
237
+ 3. otherwise the previous, larger model.
238
+
239
+ To decide yourself what the summary keeps, run `/compact` before switching.
240
+
241
+ ## Measuring your own runs
242
+
243
+ Every mode, `off` included, writes one JSON line per event to `~/.pi/agent/context-steward/metrics.jsonl`: requests with token usage and cost, consolidations, compactions, prunes and pins. To compare variants:
244
+
245
+ ```bash
246
+ for mode in off meter net; do
247
+ pi --steward-mode $mode --steward-label "$mode-r1" -p "$(cat task.md)"
248
+ done
249
+ node scripts/analyze.mjs --by group --group '^(\w+)-' --outcomes outcomes.csv
250
+ ```
251
+
252
+ `outcomes.csv` holds `label,success` lines. The analysis prints cost, cache hit rate, cache writes, mean and peak prompt, consolidations, compactions and success rate per variant.
253
+
254
+ Use tasks that outgrow the budget; short tasks look the same in every mode. Expect large run-to-run variance from things like build environments: in our runs it was larger than some of the effects.
255
+
256
+ ## Limitations
257
+
258
+ - **Small number of runs.** The measurements cover 12 runs on one task with one model (Opus 5.5 via Copilot), mostly at a 128k budget. The 300k figures are estimates from a model calibrated on those runs. See [docs/RESULTS.md](https://github.com/deemkeen/pi-context-steward/blob/main/docs/RESULTS.md).
259
+ - **The task type favors compaction.** Everything lost could simply be re-read. Tasks whose state cannot be re-read, like long debugging sessions, should benefit more from avoiding compaction, but this is not measured.
260
+ - **Token positions are estimates** (chars/4, scaled to Pi's own count). Stale detection relies on the standard tool names (`read`, `edit`, `write`, `bash`, `ls`, `find`, `grep`) and a `path` argument.
261
+ - **Input elision is verified against the Anthropic API** (Opus 5.5 via Copilot). For Gemini, whose tool calls carry their own signatures, it is untested; set `"elideInputs": false` there.
262
+ - **Offloaded originals are not cleaned up** automatically. They live next to the session files.
263
+
264
+ ## Development
265
+
266
+ ```bash
267
+ npm install
268
+ npm run typecheck
269
+ npm test # unit tests + end-to-end tests on the real Pi runtime with a scripted model
270
+ ```
271
+
272
+ The end-to-end tests check the cache invariants directly: across a whole run, the message list sent to the model changes only at consolidations, and only from the first edited message on.
273
+
274
+ | File | Purpose |
275
+ |---|---|
276
+ | `src/index.ts` | wiring (events, tools, command) |
277
+ | `src/config.ts` | JSON layers, automatic mode |
278
+ | `src/planner.ts` | consolidation policy (pure) |
279
+ | `src/context-index.ts` | view of the projected context |
280
+ | `src/meter.ts`, `src/stubs.ts`, `src/elide.ts` | meter, stubs, input elision |
281
+ | `src/compaction.ts` | pin-preserving compaction |
282
+ | `src/metrics.ts`, `scripts/analyze.mjs` | measurements |
283
+
284
+ ## License
285
+
286
+ [MIT](LICENSE)
@@ -0,0 +1,123 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "urn:pi-context-steward:config",
4
+ "title": "context-steward configuration",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "properties": {
8
+ "$schema": {
9
+ "type": "string",
10
+ "description": "Path or URL of this schema (editor autocompletion)."
11
+ },
12
+ "mode": {
13
+ "$ref": "#/$defs/tunables/properties/mode"
14
+ },
15
+ "budget": {
16
+ "$ref": "#/$defs/tunables/properties/budget"
17
+ },
18
+ "softRatio": {
19
+ "$ref": "#/$defs/tunables/properties/softRatio"
20
+ },
21
+ "targetRatio": {
22
+ "$ref": "#/$defs/tunables/properties/targetRatio"
23
+ },
24
+ "minFreeRatio": {
25
+ "$ref": "#/$defs/tunables/properties/minFreeRatio"
26
+ },
27
+ "protectRecentResults": {
28
+ "$ref": "#/$defs/tunables/properties/protectRecentResults"
29
+ },
30
+ "protectTailRatio": {
31
+ "$ref": "#/$defs/tunables/properties/protectTailRatio"
32
+ },
33
+ "summaryModel": {
34
+ "$ref": "#/$defs/tunables/properties/summaryModel"
35
+ },
36
+ "elideInputs": {
37
+ "$ref": "#/$defs/tunables/properties/elideInputs"
38
+ },
39
+ "label": {
40
+ "type": "string",
41
+ "description": "Tags all metrics. Usually set per run with --steward-label instead."
42
+ },
43
+ "metricsPath": {
44
+ "type": "string",
45
+ "description": "Metrics file (JSONL). ~ is expanded."
46
+ },
47
+ "models": {
48
+ "type": "object",
49
+ "description": "Per-model overrides keyed by \"provider/id\".",
50
+ "additionalProperties": {
51
+ "$ref": "#/$defs/tunables"
52
+ }
53
+ }
54
+ },
55
+ "$defs": {
56
+ "tunables": {
57
+ "type": "object",
58
+ "additionalProperties": false,
59
+ "properties": {
60
+ "mode": {
61
+ "enum": [
62
+ "auto",
63
+ "off",
64
+ "meter",
65
+ "net",
66
+ "full"
67
+ ],
68
+ "default": "auto",
69
+ "description": "auto (default): net, or meter below a 32k budget; off: metrics only; meter: meter only; net: meter + harness consolidation + pin-preserving compaction; full: net + context_prune/context_pin tools"
70
+ },
71
+ "budget": {
72
+ "type": "integer",
73
+ "minimum": 0,
74
+ "description": "Working budget in tokens. 0 or absent: follow Pi's compaction threshold if configured, else min(window, 128000)."
75
+ },
76
+ "softRatio": {
77
+ "type": "number",
78
+ "minimum": 0,
79
+ "exclusiveMaximum": 1,
80
+ "default": 0.85,
81
+ "description": "Consolidation starts at this share of the budget."
82
+ },
83
+ "targetRatio": {
84
+ "type": "number",
85
+ "minimum": 0,
86
+ "exclusiveMaximum": 1,
87
+ "default": 0.35,
88
+ "description": "Consolidation tries to get down to this share of the budget."
89
+ },
90
+ "minFreeRatio": {
91
+ "type": "number",
92
+ "minimum": 0,
93
+ "exclusiveMaximum": 1,
94
+ "default": 0.12,
95
+ "description": "A soft-limit consolidation that frees less than this share of the budget is skipped."
96
+ },
97
+ "protectRecentResults": {
98
+ "type": "integer",
99
+ "minimum": 0,
100
+ "default": 6,
101
+ "description": "The newest N tool results are never pruned by the harness."
102
+ },
103
+ "protectTailRatio": {
104
+ "type": "number",
105
+ "minimum": 0,
106
+ "exclusiveMaximum": 1,
107
+ "default": 0.15,
108
+ "description": "Nothing in the newest share of the budget is pruned by the harness."
109
+ },
110
+ "summaryModel": {
111
+ "type": "string",
112
+ "pattern": "^[^/]+/.+$",
113
+ "description": "provider/id of the model that writes compaction summaries (default: current model)."
114
+ },
115
+ "elideInputs": {
116
+ "type": "boolean",
117
+ "default": true,
118
+ "description": "During consolidation, shorten large inputs (file contents passed to write/edit, long scripts) of successful tool calls to head + marker + tail. Files on disk are unaffected."
119
+ }
120
+ }
121
+ }
122
+ }
123
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "softRatio": 0.85,
3
+ "targetRatio": 0.35,
4
+ "models": {
5
+ "github-copilot/claude-opus-5.5": {
6
+ "budget": 300000
7
+ }
8
+ }
9
+ }
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "pi-context-steward",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.1",
4
+ "description": "Context awareness and cache-aware context management for the Pi coding agent: a persistent context meter, batched consolidation instead of most compactions, and pin-preserving summaries.",
5
+ "keywords": [
6
+ "pi-package",
7
+ "pi",
8
+ "pi-extension",
9
+ "pi-coding-agent",
10
+ "context-window",
11
+ "context-management",
12
+ "prompt-caching",
13
+ "compaction",
14
+ "llm",
15
+ "agent"
16
+ ],
17
+ "license": "MIT",
18
+ "author": "Deemkeen",
19
+ "homepage": "https://github.com/deemkeen/pi-context-steward#readme",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/deemkeen/pi-context-steward.git"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/deemkeen/pi-context-steward/issues"
26
+ },
27
+ "type": "module",
28
+ "files": [
29
+ "src",
30
+ "scripts",
31
+ "examples",
32
+ "context-steward.schema.json",
33
+ "README.md",
34
+ "CHANGELOG.md",
35
+ "LICENSE"
36
+ ],
37
+ "pi": {
38
+ "extensions": [
39
+ "./src/index.ts"
40
+ ],
41
+ "image": "https://raw.githubusercontent.com/deemkeen/pi-context-steward/main/docs/results.png"
42
+ },
43
+ "scripts": {
44
+ "typecheck": "tsc --noEmit",
45
+ "test": "node --experimental-strip-types --test test/*.test.ts",
46
+ "analyze": "node scripts/analyze.mjs"
47
+ },
48
+ "engines": {
49
+ "node": ">=22.6"
50
+ },
51
+ "peerDependencies": {
52
+ "@earendil-works/pi-coding-agent": "*",
53
+ "@earendil-works/pi-ai": "*",
54
+ "typebox": "*"
55
+ },
56
+ "devDependencies": {
57
+ "@earendil-works/pi-coding-agent": "1.8.0",
58
+ "@types/node": "^22.0.0",
59
+ "typescript": "^5.9.0"
60
+ }
61
+ }