@zhushanwen/pi-context-engineering 0.1.0 → 0.1.2
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/README.md +47 -0
- package/package.json +10 -3
- package/src/index.ts +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# context-engineering
|
|
2
|
+
|
|
3
|
+
渐进式上下文压缩 — L0 零成本清理、L1 规则化浓缩、L2 紧急截断,附带 recall 召回机制。
|
|
4
|
+
|
|
5
|
+
## 功能
|
|
6
|
+
|
|
7
|
+
- **L0(零成本清理)**:移除过期条目、截断冗长输出、清除 thinking block
|
|
8
|
+
- **L1(规则化浓缩)**:基于规则的上下文压缩,保留关键信息
|
|
9
|
+
- **L2(紧急截断)**:上下文窗口即将耗尽时的紧急保护
|
|
10
|
+
- **Recall 召回**:被压缩的内容可通过 `recall_context` 工具按 ID 取回
|
|
11
|
+
- **统计命令**:`/context-stats` 查看压缩统计
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# symlink 方式(开发推荐)
|
|
17
|
+
ln -s /path/to/xyz-pi-extensions-workspace/main/packages/context-engineering \
|
|
18
|
+
~/.pi/agent/extensions/context-engineering
|
|
19
|
+
|
|
20
|
+
# npm 方式(正式)
|
|
21
|
+
pi install npm:@zhushanwen/pi-context-engineering
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## 使用
|
|
25
|
+
|
|
26
|
+
安装后自动生效,在 `context` 事件中执行压缩。
|
|
27
|
+
|
|
28
|
+
| 命令 | 说明 |
|
|
29
|
+
|------|------|
|
|
30
|
+
| `/context-engineering` | 手动触发压缩 |
|
|
31
|
+
| `/context-stats` | 查看压缩统计 |
|
|
32
|
+
|
|
33
|
+
LLM 可调用 `recall_context` 工具按 ID 取回被压缩的内容。
|
|
34
|
+
|
|
35
|
+
## 文件结构
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
context-engineering/
|
|
39
|
+
├── index.ts
|
|
40
|
+
└── src/
|
|
41
|
+
├── index.ts # 入口 — 事件注册、工具注册
|
|
42
|
+
├── compressor.ts # L0/L1/L2 压缩引擎
|
|
43
|
+
├── config.ts # 配置加载
|
|
44
|
+
├── frozen-fresh.ts # 冻结/新鲜状态管理
|
|
45
|
+
├── recall-store.ts # 召回存储
|
|
46
|
+
└── commands.ts # 命令处理
|
|
47
|
+
```
|
package/package.json
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhushanwen/pi-context-engineering",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Progressive context compression for Pi — L0 zero-cost cleanup, L1 rule-based condensation, L2 emergency truncation, with recall mechanism.",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "src/index.ts",
|
|
7
|
+
"pi": {
|
|
8
|
+
"extensions": [
|
|
9
|
+
"./src/index.ts"
|
|
10
|
+
]
|
|
11
|
+
},
|
|
6
12
|
"keywords": [
|
|
7
|
-
"pi",
|
|
13
|
+
"pi-package",
|
|
8
14
|
"extension",
|
|
9
15
|
"context",
|
|
10
16
|
"compression"
|
|
@@ -15,7 +21,8 @@
|
|
|
15
21
|
"index.ts"
|
|
16
22
|
],
|
|
17
23
|
"peerDependencies": {
|
|
18
|
-
"@mariozechner/pi-coding-agent": "*"
|
|
24
|
+
"@mariozechner/pi-coding-agent": "*",
|
|
25
|
+
"@sinclair/typebox": "*"
|
|
19
26
|
},
|
|
20
27
|
"scripts": {
|
|
21
28
|
"typecheck": "npx tsc --noEmit"
|
package/src/index.ts
CHANGED
|
@@ -62,7 +62,7 @@ export default function contextEngineeringExtension(pi: ExtensionAPI): void {
|
|
|
62
62
|
frozenFreshState = createFrozenFreshState();
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
-
pi.on("context", (event, ctx) => {
|
|
65
|
+
pi.on("context", (event: any, ctx: any) => {
|
|
66
66
|
try {
|
|
67
67
|
// Pi Extension API types differ from our internal message types.
|
|
68
68
|
// Both sides define the same shape but TypeScript can't verify across packages.
|
|
@@ -86,7 +86,7 @@ export default function contextEngineeringExtension(pi: ExtensionAPI): void {
|
|
|
86
86
|
description: "Recall original content compressed by context engineering. Use when you need the full content of an expired, truncated, or condensed tool result.",
|
|
87
87
|
promptSnippet: "recall_context(id) — retrieve original content compressed by context engineering",
|
|
88
88
|
parameters: RecallParams,
|
|
89
|
-
execute: async (_tcId, params, _sig, _upd, _ctx) => recallResult(params.id, store),
|
|
89
|
+
execute: async (_tcId: string, params: any, _sig: any, _upd: any, _ctx: any) => recallResult(params.id, store),
|
|
90
90
|
});
|
|
91
91
|
|
|
92
92
|
pi.registerCommand("context-engineering", {
|