Repository navigation
feat(pi): TokenPilot adapter for pi - #98
Merged
Merged
Conversation
Adds an in-process extension for the pi coding agent (`@earendil-works/pi-coding-agent`, verified on 0.87.1) in `components/adapters/pi`, built on the shared host glue from the OpenCode adapter (`components/adapters/shared/canonical`). Refs zjunlp#97. - Stabilizer: `before_agent_start` system-prompt sections, so pi appends a section delta instead of replacing the prompt. - Reduction: request-time in the `context` hook, through the shared `@lightrsi/reduction` pipeline over a canonical envelope. - Recovery: a native `memory_fault_recover` tool with the shared MCP tool's name, description and schema (pi has no MCP). - Eviction (opt-in, needs taskStateEstimator settings): the shared canonical-surface cycle, applied as native `context_edit` entries at `turn_end`, before pi's own threshold compaction. - Repeat-read rule: the shared disclosed-read memo, as in zjunlp#92 and the OpenCode adapter, saved per session so `pi -p` / `--continue` restarts keep it. - Reversible install with backups; never writes credentials; every hook fails open and logs to `<stateDir>/tokenpilot/adapter.log`. Tests: 86 in the package (runtime, codec, install/doctor, registration). The shared glue is already covered by the OpenCode package's suites. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S6it2Si8k8XNGMF8RdyMQz
`lightrsi pi status|report|doctor|visual|mode|stabilizer|reduction|eviction` through the existing in-process host bridge, so pi gets the same command surface as OpenCode. TOKENPILOT_PI_CONFIG selects a non-default config file. Tests: tests/in-process-hosts.test.ts now runs every case for both pi and OpenCode. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S6it2Si8k8XNGMF8RdyMQz
- components/adapters/pi/README.md is in the adapter commit; this adds the design note (docs/adapters/pi-design.md), the HOSTS.md and adapters README rows, the website host page and compatibility matrix, and the sidebar link. - CI runs the pi adapter suite. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S6it2Si8k8XNGMF8RdyMQz
Collaborator
|
Thanks @boxabirds — merged! Great to see pi land as our first in-process, proxy-free adapter, and the measured result (37,371 → 4,985 prompt tokens, 834 s → 69 s) is a strong signal. Also nice that the adapter reuses the shared code from #96 rather than adding new shared logic. Thanks again for the contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #97. Adds TokenPilot support for pi (
@earendil-works/pi-coding-agent), verified on 0.87.1.It builds on the shared code merged in #96. 38 files and about 2,900 lines, mostly the adapter and its tests.
Measured benefit
The test used llama-server with Qwen3-1.7B and a 32k context window, running the same 4-turn coding session with the adapter off and on, each from a fresh model load. The session runs a build, reads and counts a JSON file, writes a file, then recalls the build's last line.
With the adapter on, the model recovered the trimmed build output with
memory_fault_recoverin the last turn.lightrsi pi doctorreported healthy after the run.How it plugs in
pi has an in-process extension API, so no proxy is needed and no pi-owned config file is changed.
before_agent_startsystem-prompt sections, so pi appends a section change instead of replacing the promptcontexthookmemory_fault_recovertool with the shared MCP tool's name, description and schema, since pi has no MCPcontext_editentries atturn_end, which apply before pi's own compactionInstall is reversible. It writes one extension loader file, with a backup of anything already there, and a
tokenpilot.jsonthat never contains credentials. Uninstall removes only what install added. The adapter is also registered in the shared CLI aslightrsi pi status|report|doctor|visual|mode|….What's in the 3 commits
components/adapters/pi)The adapter reuses the shared code from #96 for config, reduction, eviction and the repeat-read rule from #92, so it adds no new shared code.
Known limits
mode aggressiveisn't exposed, as on Claude Code and OpenCode.Tests
pnpm build,pnpm typecheckandcheck:boundariespass, and every suite CI runs passes.Prepared with help from Claude Code; the commits are marked
Co-Authored-By: Claude.