@zhushanwen/pi-context-engineering
Progressive context compression for Pi — L0 zero-cost cleanup, L1 rule-based condensation, L2 emergency truncation, with recall mechanism.
Package details
Install @zhushanwen/pi-context-engineering from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:@zhushanwen/pi-context-engineering- Package
@zhushanwen/pi-context-engineering- Version
0.1.1- Published
- Jun 2, 2026
- Downloads
- not available
- Author
- zhushanwen321
- License
- MIT
- Types
- extension
- Size
- 91.4 KB
- Dependencies
- 0 dependencies · 1 peer
Pi manifest JSON
{
"extensions": [
"./src/index.ts"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
context-engineering
渐进式上下文压缩 — L0 零成本清理、L1 规则化浓缩、L2 紧急截断,附带 recall 召回机制。
功能
- L0(零成本清理):移除过期条目、截断冗长输出、清除 thinking block
- L1(规则化浓缩):基于规则的上下文压缩,保留关键信息
- L2(紧急截断):上下文窗口即将耗尽时的紧急保护
- Recall 召回:被压缩的内容可通过
recall_context工具按 ID 取回 - 统计命令:
/context-stats查看压缩统计
安装
# symlink 方式(开发推荐)
ln -s /path/to/xyz-pi-extensions-workspace/main/packages/context-engineering \
~/.pi/agent/extensions/context-engineering
# npm 方式(正式)
pi install npm:@zhushanwen/pi-context-engineering
使用
安装后自动生效,在 context 事件中执行压缩。
| 命令 | 说明 |
|---|---|
/context-engineering |
手动触发压缩 |
/context-stats |
查看压缩统计 |
LLM 可调用 recall_context 工具按 ID 取回被压缩的内容。
文件结构
context-engineering/
├── index.ts
└── src/
├── index.ts # 入口 — 事件注册、工具注册
├── compressor.ts # L0/L1/L2 压缩引擎
├── config.ts # 配置加载
├── frozen-fresh.ts # 冻结/新鲜状态管理
├── recall-store.ts # 召回存储
└── commands.ts # 命令处理