pi-precompact 0.0.0-stage → 0.2.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 +28 -0
- package/CONTRIBUTING.md +152 -0
- package/LICENSE +21 -0
- package/README.md +219 -2
- package/package.json +71 -4
- package/src/card.ts +194 -0
- package/src/controller.ts +446 -0
- package/src/files.ts +24 -0
- package/src/footer.ts +471 -0
- package/src/format.ts +20 -0
- package/src/index.ts +107 -0
- package/src/native.ts +47 -0
- package/src/validation.ts +82 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Versions follow SemVer. Future entries come from Markdown changesets.
|
|
4
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for the release workflow.
|
|
5
|
+
|
|
6
|
+
## 0.2.0 - 2026-10-26
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- Show the precompact state in the footer from session start, including idle, paused, off, and unavailable.
|
|
11
|
+
- Open a status card for /precompact status and announce adopted background summaries.
|
|
12
|
+
- Draw a context bar in Pi's built-in footer with the background start, Pi's threshold, the state, and the expected context after adoption; Pi's own context text stays unchanged.
|
|
13
|
+
- Show nothing in the footer before the first measured response, like Pi, then fade the context bar in once. PI_PRECOMPACT_MOTION=off shows it without animation.
|
|
14
|
+
- Publish the package on npm. Install it with `pi install npm:pi-precompact`.
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- Name the package pi-precompact, with the command /precompact and the motion variable PI_PRECOMPACT_MOTION.
|
|
19
|
+
- Show the footer short form as pre and Pi's status text as precompact: <state>.
|
|
20
|
+
|
|
21
|
+
## 0.1.0 - 2026-10-25
|
|
22
|
+
|
|
23
|
+
Local development baseline, not an npm publication.
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
|
|
27
|
+
- Prepare native Pi 1.4.0 compaction summaries in the background without interrupting the agent.
|
|
28
|
+
- Apply valid summaries only at native threshold compaction, with cancellation, context validation, and foreground fallback.
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
## Setup and checks
|
|
4
|
+
|
|
5
|
+
Use Node.js 22.19+ and Python 3.11+. Git, npm, Make, and tar must be on `PATH`.
|
|
6
|
+
The lockfile pins development dependencies. Pi supplies the runtime SDK.
|
|
7
|
+
Run all commands from the repository root.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm ci --ignore-scripts
|
|
11
|
+
make hooks-install
|
|
12
|
+
make verify
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
`make verify` and CI run the same checks:
|
|
16
|
+
|
|
17
|
+
- Biome formatting, import order, and recommended lint rules.
|
|
18
|
+
- Strict TypeScript checks.
|
|
19
|
+
- Unit tests and Pi SDK integration tests with a local scripted provider.
|
|
20
|
+
- A real npm tarball check, including loading the extracted extension without packaged development dependencies.
|
|
21
|
+
- Changeset parser, Git hook, and release tests in disposable repositories.
|
|
22
|
+
- Pending changeset and manifest/lockfile validation.
|
|
23
|
+
|
|
24
|
+
The CI definition covers Linux and macOS with Node.js 22 and 24.
|
|
25
|
+
It needs no provider credentials and has read-only GitHub permissions.
|
|
26
|
+
There is no automatic npm publication, OIDC, or release-token workflow.
|
|
27
|
+
|
|
28
|
+
To apply formatting:
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
npm run format
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Do not relax tests to accept an unsupported Pi version. Review the private native adapter before changing the exact SDK pin.
|
|
35
|
+
Runtime changes need applicable regression and integration tests. Pure tooling changes do not need live-provider calls or GUI tests.
|
|
36
|
+
|
|
37
|
+
## Changesets
|
|
38
|
+
|
|
39
|
+
This repository uses a small Python changeset flow, not `@changesets/cli`.
|
|
40
|
+
Every non-merge, non-release commit adds one new Markdown changeset.
|
|
41
|
+
Write notes for changelog readers, not as copies of commit messages.
|
|
42
|
+
|
|
43
|
+
For documentation, tests, formatting, or internal tooling without a release note, add an explicit empty changeset.
|
|
44
|
+
Editing a note from an earlier commit does not count as a new changeset.
|
|
45
|
+
Do not bypass the hook.
|
|
46
|
+
|
|
47
|
+
Interactive entry:
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
make changeset
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Non-interactive entry:
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
python3 scripts/changeset.py add --type fixed --bump patch "Preserve newer messages after compaction."
|
|
57
|
+
python3 scripts/changeset.py add --empty
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Stage the generated file with the change it describes. Example note:
|
|
61
|
+
|
|
62
|
+
```markdown
|
|
63
|
+
---
|
|
64
|
+
type: fixed
|
|
65
|
+
bump: patch
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
Preserve newer messages after compaction.
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
| Field | Values |
|
|
72
|
+
| --- | --- |
|
|
73
|
+
| `type` | `added`, `changed`, `fixed`, `removed` |
|
|
74
|
+
| `bump` | `patch`, `minor`, `major` |
|
|
75
|
+
|
|
76
|
+
The highest pending bump wins. Bumps do not add together.
|
|
77
|
+
Only stable `X.Y.Z` versions are supported. There is no special 0.x rule.
|
|
78
|
+
|
|
79
|
+
An empty changeset contains two `---` lines. It generates no note or version bump.
|
|
80
|
+
The next release with real notes consumes pending empty changesets too.
|
|
81
|
+
|
|
82
|
+
Keep related unpublished notes consistent. Do not rewrite published changelog history.
|
|
83
|
+
A changeset is neither release authorization nor evidence of acceptance.
|
|
84
|
+
|
|
85
|
+
### Hook behavior
|
|
86
|
+
|
|
87
|
+
Install the hook once per clone with `make hooks-install`.
|
|
88
|
+
The installer preserves existing hooks and `core.hooksPath`. Integrate `check-staged` into an existing hook manager instead.
|
|
89
|
+
|
|
90
|
+
The hook locates Python 3.11+ on `PATH`. It does not install Python or activate Nix.
|
|
91
|
+
|
|
92
|
+
The hook checks staged content, not unstaged edits:
|
|
93
|
+
|
|
94
|
+
- Merge commits use notes from the merged branches. Staged notes still need valid syntax.
|
|
95
|
+
- Amend checks use the commit's parent, so the original note counts.
|
|
96
|
+
- Release commits must exactly match the generated manifest, lockfile, changelog, and consumed notes.
|
|
97
|
+
|
|
98
|
+
The hook rejects hand-edited version bumps, mismatched lockfile versions, and unrelated changes in release commits.
|
|
99
|
+
CI validates pending notes and tests hook behavior. It does not enforce changesets across all historical commits.
|
|
100
|
+
|
|
101
|
+
## Prepare a release
|
|
102
|
+
|
|
103
|
+
Prepare a version only after an explicit release request, from clean `main` with verified, committed changesets.
|
|
104
|
+
Use the changeset tool, not `npm version` or a manual version edit.
|
|
105
|
+
|
|
106
|
+
```sh
|
|
107
|
+
make changeset-status
|
|
108
|
+
make version
|
|
109
|
+
make verify
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
`make version` plans all outputs before writing. It:
|
|
113
|
+
|
|
114
|
+
1. Selects the highest pending SemVer bump.
|
|
115
|
+
2. Updates the version in the package manifest.
|
|
116
|
+
3. Updates the lockfile version and its root package version, without resolving dependencies.
|
|
117
|
+
4. Prepends a dated changelog section and removes all consumed changesets.
|
|
118
|
+
|
|
119
|
+
It does not run npm, commit, tag, push, install, or publish.
|
|
120
|
+
Review the diff. Commit only the generated release files, with a message such as `version bump to v0.1.1`.
|
|
121
|
+
Feature branches keep their notes until merge. They do not prepare releases.
|
|
122
|
+
|
|
123
|
+
### Publish a release
|
|
124
|
+
|
|
125
|
+
A maintainer publishes each release by hand from a local machine, with npm two-factor authentication.
|
|
126
|
+
|
|
127
|
+
1. Prepare the version with `make version` and commit only the generated release files.
|
|
128
|
+
2. Push `main` and wait for green CI on that exact release commit.
|
|
129
|
+
3. Run the read-only publication gate:
|
|
130
|
+
|
|
131
|
+
```sh
|
|
132
|
+
npm run release:check
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
It requires clean `main`, synchronized versions, no pending notes, and an exact changeset-generated release at `HEAD`.
|
|
136
|
+
It also checks the publication metadata and runs the normal checks. `prepublishOnly` runs the same gate.
|
|
137
|
+
4. Run `npm publish --provenance=false`. A local release has no npm provenance.
|
|
138
|
+
5. Check the exact version on the registry, and install it with `pi install npm:pi-precompact@<version>` in a clean Pi home.
|
|
139
|
+
6. Tag the release commit as `v<version>`, push the tag, and create the GitHub release from the changelog section.
|
|
140
|
+
|
|
141
|
+
Do not republish a version that the registry already accepted. Repair only the missing tag or release.
|
|
142
|
+
|
|
143
|
+
## Reference choices
|
|
144
|
+
|
|
145
|
+
The small Pi plugins supplied the package shape: source exports, explicit Pi resources, host peer dependencies, narrow tarball contents, and CI checks.
|
|
146
|
+
Pi Dynamic Workflows supplied the Biome and pre-publication verification pattern.
|
|
147
|
+
This repository does not copy automatic publishing workflows from existing plugins.
|
|
148
|
+
|
|
149
|
+
The changeset tool adapts the author's changeset scripts from the TWS, Zugriff-Menu, and Teams-GPUI projects.
|
|
150
|
+
`scripts/LICENSE.tws` keeps the TWS MIT notice.
|
|
151
|
+
This adaptation replaces Cargo version handling with single-package npm version handling.
|
|
152
|
+
It does not copy Teams-GPUI's backlog exemption, Nix fallback, or application installation steps.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Patrick Wozniak
|
|
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,220 @@
|
|
|
1
|
-
#
|
|
1
|
+
# pi-precompact
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An experimental Pi extension that prepares compaction summaries while the agent continues its work.
|
|
4
|
+
Pi still decides when to compact. The extension supplies a valid prepared summary at that boundary, or leaves the request to Pi.
|
|
5
|
+
|
|
6
|
+
Inspired by [OpenCode background compaction](https://github.com/anomalyco/opencode/pull/57444).
|
|
7
|
+
This is an independent implementation, not an OpenCode port.
|
|
8
|
+
|
|
9
|
+
Not related to the npm package `pi-background-compaction`.
|
|
10
|
+
|
|
11
|
+
## Status
|
|
12
|
+
|
|
13
|
+
- Targets `@earendil-works/pi-coding-agent` **1.4.0** only.
|
|
14
|
+
- Uses Pi's native context projection, preparation, and summary generator.
|
|
15
|
+
- Does not abort the agent or inject a `continue` message.
|
|
16
|
+
- Does not install itself, change settings, or run a background process.
|
|
17
|
+
- Has deterministic unit tests and SDK integration tests with Pi's local Faux provider.
|
|
18
|
+
- Has no live-provider endurance or latency benchmark yet.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
pi install npm:pi-precompact
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
New sessions load the extension. Run `/reload` in a session that is already open.
|
|
27
|
+
To try it for one invocation without changing settings:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
pi -e npm:pi-precompact
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Do not combine it with another extension that replaces compaction.
|
|
34
|
+
|
|
35
|
+
Commands:
|
|
36
|
+
|
|
37
|
+
```text
|
|
38
|
+
/precompact status
|
|
39
|
+
/precompact off
|
|
40
|
+
/precompact on
|
|
41
|
+
/precompact reset
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
These commands affect only the current session. `reset` cancels the prepared job and clears the failure counter.
|
|
45
|
+
|
|
46
|
+
`/precompact` and `/precompact status` open a status card in the TUI, in place of the editor.
|
|
47
|
+
The card appears only on this explicit request. It shows the state and last event, a context bar with the plugin's start and Pi's threshold,
|
|
48
|
+
the expected result of a held summary, the request usage, and the failure count. It updates every second.
|
|
49
|
+
Press `r` to reset, `o` to switch off or on, and Escape or Enter to close. RPC, JSON, and print modes keep the one-line answer.
|
|
50
|
+
|
|
51
|
+
When Pi adopts a background summary, the TUI and RPC clients receive one notice, for example:
|
|
52
|
+
|
|
53
|
+
```text
|
|
54
|
+
✓ Background summary applied · no wait · 249k → ~38k tokens · prepared in 48s
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`waited 12s` replaces `no wait` when Pi had to wait for a running request. The token value after `→` is Pi's estimate.
|
|
58
|
+
Native fallback compactions produce no notice.
|
|
59
|
+
|
|
60
|
+
The plugin sets one footer status from session start, `precompact: <state>`:
|
|
61
|
+
|
|
62
|
+
| State | Meaning |
|
|
63
|
+
| --- | --- |
|
|
64
|
+
| `idle` | Enabled; no summary is in progress. |
|
|
65
|
+
| `running` | Preparing a summary while the agent continues. |
|
|
66
|
+
| `ready` | Holding a summary until Pi requests threshold compaction. |
|
|
67
|
+
| `paused` | Two background requests failed; native compaction remains available. |
|
|
68
|
+
| `off` | Disabled for this session, or native auto-compaction is disabled. |
|
|
69
|
+
| `unavailable` | Unsupported Pi installation, virtual model, or no model selected. |
|
|
70
|
+
|
|
71
|
+
In Pi's built-in TUI footer, the plugin moves this status from the status row into the statistics line.
|
|
72
|
+
Pi's own context segment stays exactly as Pi renders it. From 100 columns, a context bar comes before it:
|
|
73
|
+
|
|
74
|
+
```text
|
|
75
|
+
━━━━━━━━━━━━━━━━━━━│━━━─│─ 91.6%/272k (auto) → ~14%
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
- The accent mark is where background preparation starts. The error mark is where Pi compacts.
|
|
79
|
+
- The fill uses the state colour: `running` accent, `ready` success, `paused` warning, the others muted or dim.
|
|
80
|
+
- `→ ~14%` follows while a summary is ready: the estimated context after Pi adopts it.
|
|
81
|
+
- `✓ pre` follows directly after an adopted summary, until the next change.
|
|
82
|
+
- `pre running`, `pre ready` (without an estimate), `pre paused`, `pre off`, and `pre unavailable` name the other states.
|
|
83
|
+
|
|
84
|
+
Below 100 columns the line shows `91.6%/272k (auto) pre: ready` instead. When even that does not fit,
|
|
85
|
+
or the footer has an unknown layout, Pi's status row keeps `precompact: <state>`.
|
|
86
|
+
|
|
87
|
+
Before the first response with token usage, Pi shows only its context value and no usage numbers.
|
|
88
|
+
The plugin then shows nothing either: no bar, no `pre` text, and no status row entry.
|
|
89
|
+
With the first measured response, the bar fades in once:
|
|
90
|
+
|
|
91
|
+
- Pi's numbers appear at once; the bar reserves its columns in the same frame.
|
|
92
|
+
- Each glyph fades from the terminal background to its colour in 120 ms, 5 ms after its left neighbour.
|
|
93
|
+
- The fill grows from 80 to 240 ms. A frame follows every 40 ms; the easing is `cubic-bezier(0.23, 1, 0.32, 1)`.
|
|
94
|
+
- A new width, value, or state during the animation shows the final bar at once.
|
|
95
|
+
- Sessions with earlier responses, for example after `/resume` or `/reload`, show the bar without animation.
|
|
96
|
+
|
|
97
|
+
The plugin asks the terminal for its background colour once, as Pi's theme does.
|
|
98
|
+
Without an answer or without truecolor, each glyph appears directly in its colour as the wave reaches it.
|
|
99
|
+
Set `PI_PRECOMPACT_MOTION=off` before starting Pi to show the bar without animation.
|
|
100
|
+
The design is on pages 04 and 05 of `design/figcraft/footer-status.figcraft`.
|
|
101
|
+
|
|
102
|
+
Use `/precompact status` for the last event and failure count.
|
|
103
|
+
Pi's `(auto)` context indicator refers to native automatic compaction, not this plugin.
|
|
104
|
+
|
|
105
|
+
Pi has no public API to place text inside its footer. A zero-row widget below the editor finds the one mounted
|
|
106
|
+
built-in `FooterComponent` and wraps the render method of that instance; the prototype stays untouched.
|
|
107
|
+
The plugin reads the instance's status provider read-only and never modifies shared statuses.
|
|
108
|
+
Other footer decorators can wrap the same instance before or after it; each keeps the other's lines.
|
|
109
|
+
Custom footers are left alone. Shutdown and reload restore Pi's method and clear this plugin's status only.
|
|
110
|
+
JSON, print, and RPC modes receive no terminal status or footer decoration.
|
|
111
|
+
|
|
112
|
+
To remove it, run `pi remove npm:pi-precompact`.
|
|
113
|
+
|
|
114
|
+
## Scheduling
|
|
115
|
+
|
|
116
|
+
1. After a completed turn, resolve Pi's effective compaction settings for the current model.
|
|
117
|
+
2. Start one summary when context reaches 85% of the native compaction ceiling.
|
|
118
|
+
3. Require at least 64,000 measured input and cache tokens from the latest valid assistant response.
|
|
119
|
+
4. Keep the result in memory while the agent continues.
|
|
120
|
+
5. At native threshold compaction, validate the snapshot and await its result if necessary.
|
|
121
|
+
6. Return the prepared summary to Pi, or let Pi perform normal compaction.
|
|
122
|
+
|
|
123
|
+
The ceiling is `contextWindow - reserveTokens`. For a 200,000-token model with a 30,000-token reserve, background work starts at 144,500 tokens.
|
|
124
|
+
Pi's model overrides and adaptive reserves remain authoritative.
|
|
125
|
+
The extension does not start speculative work after the ceiling is already reached.
|
|
126
|
+
|
|
127
|
+
A job has a two-minute deadline from its start. Foreground waiting uses the remaining time, not a new two-minute timeout.
|
|
128
|
+
Two background failures pause speculative work until compaction or an explicit reset.
|
|
129
|
+
Manual compaction, custom instructions, and overflow recovery always use Pi's foreground path.
|
|
130
|
+
|
|
131
|
+
## Context safety
|
|
132
|
+
|
|
133
|
+
The summary uses the canonical `prepareCompaction()` and `compact()` functions from the running Pi installation.
|
|
134
|
+
There is no copied cut-point or projection algorithm.
|
|
135
|
+
|
|
136
|
+
The extension hashes the original branch and checks it again before applying a result.
|
|
137
|
+
It rejects changed models, settings, branch prefixes, context edits, and intervening compactions.
|
|
138
|
+
It also checks after a foreground wait, because session changes can race the request.
|
|
139
|
+
Session replacement, tree navigation, reload, model selection, and cancellation discard pending work.
|
|
140
|
+
|
|
141
|
+
Pi keeps the retained history as native messages. The extension does not convert recent tool output or attachments into truncated text.
|
|
142
|
+
New messages after the snapshot remain in that retained history. No catch-up summary call is necessary.
|
|
143
|
+
Pi can still make two native summary calls for a split turn.
|
|
144
|
+
|
|
145
|
+
Before acceptance, an in-memory `SessionManager` previews the real compaction entry, including replayed system state.
|
|
146
|
+
The estimated result must reduce context and fit below the native ceiling with a 15% estimate margin.
|
|
147
|
+
New history after the snapshot must also fit within `min(max(2 × keepRecentTokens, 30,000), ceiling / 4)`.
|
|
148
|
+
These checks use Pi's token estimates, not an exact provider tokenizer. Native overflow recovery remains the final safeguard.
|
|
149
|
+
|
|
150
|
+
Pi 1.4.0 skips inherited file metadata from all extension-generated compactions.
|
|
151
|
+
A narrow adapter preserves this extension's marked file lists in both background preparation and foreground fallback.
|
|
152
|
+
It leaves other extensions' details alone.
|
|
153
|
+
|
|
154
|
+
## Compatibility and limits
|
|
155
|
+
|
|
156
|
+
`prepareCompaction()` is not a public root export in Pi 1.4.0.
|
|
157
|
+
The adapter loads the installed distribution module after checking the runtime and package versions.
|
|
158
|
+
Unknown versions, mismatched installations, and binary installations without distribution modules leave the extension inactive.
|
|
159
|
+
Pi's normal compaction remains available.
|
|
160
|
+
|
|
161
|
+
Virtual routing models use native compaction only. This avoids speculative work against unresolved model limits.
|
|
162
|
+
Physical models use `ctx.modelRegistry.streamSimple()`, with the configured provider and request-time authentication.
|
|
163
|
+
The extension does not read credential files or resolve secrets itself.
|
|
164
|
+
Background requests do not use custom SDK `agent.streamFunction` overrides or request-transform hooks.
|
|
165
|
+
|
|
166
|
+
Background summaries consume provider quota, even when discarded. Requests can overlap with ordinary agent requests.
|
|
167
|
+
Accepted summaries carry their native usage into the compaction entry.
|
|
168
|
+
The extension records known discarded-result usage as a non-context `precompact.discarded` custom entry.
|
|
169
|
+
Pi does not include those custom entries in its built-in cost totals.
|
|
170
|
+
|
|
171
|
+
Partial failures and cancelled or late requests can incur costs without returning usage.
|
|
172
|
+
A provider that ignores abort can continue remote work after the local wait ends.
|
|
173
|
+
|
|
174
|
+
This extension follows Pi's summary prompt and cache policy. It does not implement OpenCode's prompt-cache optimization.
|
|
175
|
+
It reads persisted context, not temporary `context` or `context_with_system` hook transformations.
|
|
176
|
+
Persistent omissions and replacements must use Pi's `context_edit` entries.
|
|
177
|
+
|
|
178
|
+
## Development
|
|
179
|
+
|
|
180
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for setup, Changesets, the commit hook, and the separate release procedure.
|
|
181
|
+
See [CHANGELOG.md](CHANGELOG.md) for release notes.
|
|
182
|
+
|
|
183
|
+
Prerequisites: Node.js 22.19+, Python 3.11+, Git, npm, Make, and tar.
|
|
184
|
+
|
|
185
|
+
From the repository root, install the locked development dependencies:
|
|
186
|
+
|
|
187
|
+
```sh
|
|
188
|
+
npm ci --ignore-scripts
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Install the changeset hook once per clone:
|
|
192
|
+
|
|
193
|
+
```sh
|
|
194
|
+
make hooks-install
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Run the same checks as CI:
|
|
198
|
+
|
|
199
|
+
```sh
|
|
200
|
+
npm run check
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
This checks formatting, lint, types, runtime tests, the actual npm tarball, and the Changesets flow.
|
|
204
|
+
CI runs these checks on Linux and macOS with Node.js 22 and 24.
|
|
205
|
+
|
|
206
|
+
Tests use temporary directories, in-memory credentials, in-memory sessions, and a local scripted provider.
|
|
207
|
+
They do not load personal extensions, read real credential files, or call a remote model.
|
|
208
|
+
The integration tests inject deterministic token usage through Pi's finalized-message hook.
|
|
209
|
+
They exercise real extension loading, provider streaming, tool-driven turns, threshold compaction, fallback, and shutdown.
|
|
210
|
+
|
|
211
|
+
Source:
|
|
212
|
+
|
|
213
|
+
- `src/index.ts`: lifecycle hooks and commands.
|
|
214
|
+
- `src/controller.ts`: job scheduling and cancellation.
|
|
215
|
+
- `src/native.ts`: version-guarded native adapter.
|
|
216
|
+
- `src/validation.ts`: branch validation and context preview.
|
|
217
|
+
- `src/files.ts`: file-metadata inheritance for Pi 1.4.0.
|
|
218
|
+
- `src/card.ts`: the status card for `/precompact status`.
|
|
219
|
+
- `src/footer.ts`: the context bar in Pi's built-in footer.
|
|
220
|
+
- `src/format.ts`: token, duration, and share formatting.
|
package/package.json
CHANGED
|
@@ -1,6 +1,73 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-precompact",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Precompute Pi compaction summaries without interrupting the agent.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./src/index.ts"
|
|
8
|
+
},
|
|
9
|
+
"author": "Patrick Wozniak",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/patlux/pi-precompact.git"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/patlux/pi-precompact#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/patlux/pi-precompact/issues"
|
|
18
|
+
},
|
|
19
|
+
"private": false,
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=22.19.0"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public",
|
|
25
|
+
"registry": "https://registry.npmjs.org/"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"pi-package",
|
|
29
|
+
"pi-extension",
|
|
30
|
+
"pi",
|
|
31
|
+
"compaction"
|
|
32
|
+
],
|
|
33
|
+
"pi": {
|
|
34
|
+
"extensions": [
|
|
35
|
+
"./src/index.ts"
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"src",
|
|
40
|
+
"README.md",
|
|
41
|
+
"CHANGELOG.md",
|
|
42
|
+
"CONTRIBUTING.md",
|
|
43
|
+
"LICENSE"
|
|
44
|
+
],
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"@earendil-works/pi-coding-agent": "1.4.0",
|
|
47
|
+
"@earendil-works/pi-tui": "1.4.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@biomejs/biome": "2.4.16",
|
|
51
|
+
"@earendil-works/pi-ai": "1.4.0",
|
|
52
|
+
"@earendil-works/pi-coding-agent": "1.4.0",
|
|
53
|
+
"@earendil-works/pi-tui": "1.4.0",
|
|
54
|
+
"@types/node": "^22.19.0",
|
|
55
|
+
"tsx": "4.23.15",
|
|
56
|
+
"typescript": "^5.9.3"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"test": "node --import tsx --test test/*.test.ts",
|
|
60
|
+
"typecheck": "tsc --noEmit",
|
|
61
|
+
"lint": "biome check --error-on-warnings .",
|
|
62
|
+
"format": "biome check --write .",
|
|
63
|
+
"changeset": "python3 scripts/changeset.py add",
|
|
64
|
+
"changeset:status": "python3 scripts/changeset.py status",
|
|
65
|
+
"changeset:test": "python3 -B scripts/test_changeset.py -v",
|
|
66
|
+
"hooks:install": "python3 scripts/changeset.py install-hook",
|
|
67
|
+
"version:prepare": "python3 scripts/changeset.py version",
|
|
68
|
+
"release:check": "python3 scripts/changeset.py release-ready && npm run check",
|
|
69
|
+
"prepublishOnly": "npm run release:check",
|
|
70
|
+
"pack:dry": "npm pack --dry-run --ignore-scripts",
|
|
71
|
+
"check": "npm run lint && npm run typecheck && npm test && npm run changeset:test && npm run changeset:status"
|
|
72
|
+
}
|
|
73
|
+
}
|