@adeildo/pi-compact

中文文档
6.0.0发布于 2026/11/02MITES Module构建来源已验证近 30 天下载 2371

Keeps a long pi session's context small: hides old tool output, keeping each call so the agent can run it again, and writes pi's compaction summary from the session's board.

原始使用文档

@adeildo/pi-compact

npm pi SDK

In a long session, every request sends the whole context again, and most of it is old tool output that the agent no longer needs. This package hides that old output and keeps what matters: your words, the agent's words and the decisions. On a week of real sessions, it cut the cost by about a third.

pi install npm:@adeildo/pi-compact

What it does

When a run ends with more than 150k tokens of context, each tool output older than the last 10 turns becomes one line that names its call:

Output hidden to save context, about 4.2k tokens. It came from: read src/view.ts. Run it again if you need it.
  • Your messages, the agent's words, errors and the last 10 turns stay whole.
  • After a prune, the agent gets its board back, so it keeps track of its work.
  • When pi compacts anyway, the board and your last words go on top of the summary unchanged.

Each prune leaves a line in the chat with what it saved, and Ctrl+O lists the calls it hid.

After a tool call, the prune's line: 181 old tool outputs hidden, 705k to 250k tokens, and below it what the next request pays to rewrite the cache and in how many requests that pays back. Then pi's cache miss notice for that rewrite.
A prune's line, and the one cache rewrite it costs on the next request.

Commands and settings

/prune hides old output when the run ends, whatever the size of the context.

These are on the Compact tab of Alt+S, and stored under compact in ~/.pi/agent/extensions/pi-harness/settings.json.

SettingDefaultWhat it does
Hide old tool outputonTurns the prune on
On Anthropic's sideoffOn Anthropic models, Anthropic clears old output instead of the prune, and the agent keeps its thinking
Above150000How many tokens of context a run must end with to prune
Write it from the boardonPuts the board on top of pi's summary, written on the model below. When off, pi uses the session's model
ModelautoThe model that writes the summary. auto picks the cheapest one of the session's provider

The tab also shows what this session's prunes freed, and how many hidden outputs the agent had to run again. A high share means the prune hides output that the agent still needs.

How it works explains when a prune runs, why it works this way, Anthropic's own clearing, and how it was measured.

adeildo.dev
pi-harness is made by adeildo.dev

版本与发布记录

@adeildo/pi-compact 共发布 21 个版本,首次发布于 2026/10/13;过去 12 个月发布了 21 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
6.0.0latest2026/11/025 天前
5.15.02026/10/2414 天前
5.14.02026/10/2414 天前
5.13.02026/10/2315 天前
5.12.22026/10/2316 天前
5.12.12026/10/2216 天前

关于 @adeildo/pi-compact 的常见问题

@adeildo/pi-compact 是什么?

Keeps a long pi session's context small: hides old tool output, keeping each call so the agent can run it again, and writes pi's compaction summary from the session's board.

如何安装 @adeildo/pi-compact?

在项目目录运行 npm install @adeildo/pi-compact,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@earendil-works/pi-ai(*)、@earendil-works/pi-tui(*)、@earendil-works/pi-coding-agent(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@adeildo/pi-compact 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/adeildo__pi-compact 是否存在。

@adeildo/pi-compact 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@adeildo/pi-compact 可以商用吗?

@adeildo/pi-compact 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@adeildo/pi-compact 的下载量有多少?

根据 npm 官方下载统计,@adeildo/pi-compact 在 2026/10/05 – 2026/11/03 这 30 天内被下载 2,371 次,日均约 79 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adeildo/pi-compact 还在维护吗?

最新版本 6.0.0 发布于 2026/11/02(5 天前);至今共发布 21 个版本,其中过去 12 个月发布了 21 个;首次发布于 2026/10/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。