@astrosheep/pi-context

中文文档
0.38.0发布于 2026/10/10MITTypeScriptES Module零依赖近 30 天下载 2096

Codex-style context windows for Pi: durable reset windows, session history tools, and persistent notes.

此软件包已被标记为弃用

Renamed to notesoup. Install notesoup instead.

原始使用文档
文档目录7 节
  1. Why not just compaction?
  2. Install
  3. What you get
  4. Configuration
  5. Documentation
  6. Development
  7. License

pi-context

Your agent's memory gets wiped when the context fills. pi-context makes that survivable: the agent writes itself a checkpoint before the wipe, wakes up in a fresh window, and digs up whatever it still needs from the old conversation. For you it's mostly invisible — an occasional notification, /clear-memory to force a fresh window, /pi-context to toggle.

The architecture — durable context windows, model-authored notes, searchable history — is the one OpenAI prototyped in Codex's context_management experiment and switched off ten days later, because it was welded to their backend. pi-context is the same architecture running entirely on your machine, built only on Pi's public extension APIs. No backend, no subscription gate, no server that can 404 at the worst possible moment. It can't be switched off from far away, because there is no far away.

Why not just compaction?

  • Reset ≠ summary. Compaction is lossy compression you sit and wait for — and the next one summarizes the summary of the summary. A pi-context reset summarizes nothing: the window closes in O(1), because whatever mattered was already written to notes beforehand. Fast because there's nothing to compute; safe because the raw history never leaves disk.
  • Notes are files you can open. Plain Markdown in ~/.agents/notes, in named homes (@project, @human, @self, @model, plus per-session). Readable, editable, greppable, git-able. Not an encrypted blob — and not a secret the model is instructed to keep from you. (Yes, that was a real instruction. No, we didn't port it.)
  • History never forgets. Every closed window — messages, tool calls, tool output — stays fully searchable through the history_* tools. Notes are the agent's lossy index; history is the lossless record underneath. This is the half the original experiment never shipped.

Install

pi install npm:@astrosheep/pi-context

Or load it for a single invocation without installing:

pi -e npm:@astrosheep/pi-context

What you get

  • Durable context windows. /clear-memory (alias /cm) clears and stops; /cm Continue reviewing the implementation clears and continues. The model can also request a window itself with clear_memory, and a budget close-out fires automatically before the window runs out. Abort and ordinary errors never count as completion; the raw conversation stays in the session, just out of the next context.
  • A boot block at every window head. Static once-per-window content (cache-stable) with the window identity, the recent-notes index, and a short protocol teaching the model how to recover: notes for its own bookkeeping, history tools for everything before the reset.
  • get_context_remaining — the live countdown to the close-out line, so the agent can see the cliff before it drives off it.
  • Nine history/notes tools, flattened from the original Codex actions:
Codex actionPi tool
history.list_windowshistory_windows
history.list_itemshistory_list
history.read_itemhistory_read
history.search_contentshistory_search
notes.writenotes_write
notes.updatenotes_update
notes.renamenotes_update (rename_to)
notes.readnotes_read
notes.listnotes_list
notes.searchnotes_search
  • Runtime toggle — /pi-context off stops new automatic resets; /pi-context on re-enables them; bare /pi-context reports the state.

Configuration

The reminder threshold is Pi's compaction reserve plus a margin, configured under the top-level pi-context key in ~/.pi/agent/settings.json or <cwd>/.pi/settings.json (project values win per key):

{
  "compaction": { "reserveTokens": 16384 },
  "pi-context": { "reminderMarginTokens": 24576 }
}

The dreamer model is configured under the same key; --dreamer <model pattern> on the dream CLI wins, then a non-empty pi-context.dreamer string, then the automatic model:

{
  "pi-context": { "reminderMarginTokens": 24576, "dreamer": "anthropic/claude-sonnet-4-5" }
}

Documentation

Development

npm test            # build from a clean dist, then run the suite
npm run typecheck
git diff --check
node scripts/check-notes-package.mjs  # optional built /notes CRUD smoke; no install

The harness runs against the real installed Pi SessionManager/SettingsManager in temporary directories with fake credentials — no model or network calls, and the real ~/.pi is never touched. See CONTRIBUTING.md for ownership and verification rules.

License

MIT

版本与发布记录

@astrosheep/pi-context 共发布 60 个版本,首次发布于 2026/09/14;过去 12 个月发布了 60 个版本。

版本发布日期距今
0.38.0latest2026/10/1028 天前
0.37.12026/10/0929 天前
0.37.02026/10/0929 天前
0.35.62026/10/0830 天前
0.35.52026/10/0830 天前
0.35.42026/10/0830 天前

关于 @astrosheep/pi-context 的常见问题

@astrosheep/pi-context 是什么?

Codex-style context windows for Pi: durable reset windows, session history tools, and persistent notes.注意:该包已被作者标记为弃用——Renamed to notesoup. Install notesoup instead.

如何安装 @astrosheep/pi-context?

在项目目录运行 npm install @astrosheep/pi-context,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 dream,可以用 npx dream 直接运行。

@astrosheep/pi-context 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@astrosheep/pi-context 支持 ESM 还是 CommonJS?

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

@astrosheep/pi-context 可以商用吗?

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

@astrosheep/pi-context 的下载量有多少?

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

@astrosheep/pi-context 还在维护吗?

最新版本 0.38.0 发布于 2026/10/10(28 天前);至今共发布 60 个版本,其中过去 12 个月发布了 60 个;首次发布于 2026/09/14。作者已将其标记为弃用,新项目建议寻找替代方案。