billion-context-pi 0.0.1 → 0.0.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/LICENSE +21 -0
- package/README.md +155 -19
- package/README.zh-CN.md +173 -0
- package/dist/commands.d.ts +8 -0
- package/dist/compress-tool.d.ts +15 -0
- package/dist/config.d.ts +25 -0
- package/dist/decompress-tool.d.ts +11 -0
- package/dist/delegate-tool.d.ts +27 -0
- package/dist/fleet-widget.d.ts +14 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +8953 -0
- package/dist/index.js.map +1 -0
- package/dist/log.d.ts +8 -0
- package/dist/messages.d.ts +6 -0
- package/dist/rename-notice.d.ts +14 -0
- package/dist/runtime.d.ts +29 -0
- package/dist/search-index.d.ts +20 -0
- package/dist/search-tool.d.ts +9 -0
- package/dist/setup-subagent-tools.d.ts +8 -0
- package/dist/state.d.ts +8 -0
- package/dist/status-tool.d.ts +12 -0
- package/dist/system-prompt.d.ts +2 -0
- package/dist/tokens.d.ts +16 -0
- package/dist/update.d.ts +1 -0
- package/dist/user-config.d.ts +16 -0
- package/package.json +64 -13
- package/index.js +0 -14
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ranxianglei
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,38 +1,174 @@
|
|
|
1
|
-
#
|
|
1
|
+
# pai-acp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[English](./README.md) | [中文](./README.zh-CN.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
<p align="center">
|
|
6
|
+
<strong>Active Context Pruning</strong> for <a href="https://pi.dev">Pi</a>
|
|
7
|
+
<br />
|
|
8
|
+
The model decides <em>when</em> and <em>what</em> to compress — not a hard limit.
|
|
9
|
+
</p>
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
---
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="https://www.npmjs.com/package/pai-acp"><img src="https://img.shields.io/npm/v/pai-acp.svg?style=flat-square" alt="npm"></a>
|
|
15
|
+
<a href="https://github.com/ranxianglei/pai-acp/blob/master/LICENSE"><img src="https://img.shields.io/npm/l/pai-acp.svg?style=flat-square" alt="license"></a>
|
|
16
|
+
<a href="https://github.com/ranxianglei/pai-acp"><img src="https://img.shields.io/badge/GitHub-ranxianglei%2Fpai--acp-181717?style=flat-square&logo=github" alt="GitHub"></a>
|
|
17
|
+
</p>
|
|
10
18
|
|
|
11
|
-
|
|
19
|
+
<p align="center">
|
|
20
|
+
<code>pi install npm:pai-acp</code>
|
|
21
|
+
</p>
|
|
12
22
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
- **
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Why?
|
|
26
|
+
|
|
27
|
+
When conversations get long, the model runs out of context. Most tools hard-truncate — silently dropping earlier messages. **ACP** gives the model a `compress` tool: the LLM decides **when** and **what** to compress into high-fidelity summaries, preserving critical details (file paths, decisions, error strings) while reclaiming context space.
|
|
28
|
+
|
|
29
|
+
Unlike Pi's built-in auto-compaction (which replaces everything with a single summary), ACP:
|
|
30
|
+
- **Preserves structure** — compressed ranges become labeled blocks you can decompress later
|
|
31
|
+
- **Multi-tier** — summaries can be further distilled (T1 → T2 → T3) as sessions grow
|
|
32
|
+
- **Searchable** — `search_context` finds information inside compressed blocks without decompressing
|
|
33
|
+
- **Selective** — protected tools, user messages, and the recent working set are never compressed
|
|
34
|
+
|
|
35
|
+
This means:
|
|
36
|
+
|
|
37
|
+
1. **A single session handles enormous workloads.** Per simulation tests of the three-tier architecture (see [opencode-acp](https://github.com/ranxianglei/opencode-acp)), one session can process on the order of 10–60 billion cumulative tokens — while retaining long-term memory of distant key information (paths, decisions, signatures). You can work in the **same session for months** without outgrowing the context.
|
|
38
|
+
2. **Context stays lean over the long run.** In practice context typically holds under ~150K tokens (opencode-acp keeps it under ~200K), so compared to traditional compaction that lets context balloon toward 1M, **a single session costs roughly 5× less in tokens**.
|
|
18
39
|
|
|
19
40
|
## Install
|
|
20
41
|
|
|
21
42
|
```bash
|
|
22
|
-
pi install pai-acp
|
|
43
|
+
pi install npm:pai-acp
|
|
23
44
|
```
|
|
24
45
|
|
|
25
|
-
|
|
46
|
+
That's it. The extension auto-loads on next Pi startup. No configuration needed — it reads your model's context window automatically.
|
|
47
|
+
|
|
48
|
+
> **Uninstall `pi-subagents` first (optional, recommended).** pai-acp ships its own `acp_delegate` sub-agent tool (see below) that replaces pi-subagents at a fraction of the context cost (~600 tok vs ~7K tok/turn). If you have pi-subagents installed, remove it to avoid duplicate delegation tools:
|
|
49
|
+
> ```bash
|
|
50
|
+
> pi remove npm:pi-subagents
|
|
51
|
+
> ```
|
|
52
|
+
|
|
53
|
+
## How it works
|
|
54
|
+
|
|
55
|
+
ACP intercepts Pi's `context` event (fired before each LLM call) and runs an 8-stage pipeline:
|
|
26
56
|
|
|
27
|
-
```bash
|
|
28
|
-
pi install billion-context-pi
|
|
29
57
|
```
|
|
58
|
+
assign refs → sync blocks → prune → filter → hide calls → recommend → nudge → emergency truncate
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Each message gets an invisible `<acp>` ref tag (`m00001`, `m00002`, ...) visible to the model but not the user. The model uses these refs to specify compression ranges.
|
|
62
|
+
|
|
63
|
+
Pi's built-in auto-compaction is cancelled — ACP is the sole context manager.
|
|
64
|
+
|
|
65
|
+
## Model-facing tools
|
|
66
|
+
|
|
67
|
+
| Tool | What it does |
|
|
68
|
+
|------|-------------|
|
|
69
|
+
| `compress` | Replace a contiguous message range with a detailed summary |
|
|
70
|
+
| `decompress` | Restore a previously compressed block's content |
|
|
71
|
+
| `search_context` | Search compressed block summaries (and visible messages) by keyword |
|
|
72
|
+
| `acp_status` | Show context usage, compressed blocks, compressible ranges |
|
|
73
|
+
| `acp_delegate` | Spawn a clean-context sub-agent for a task (review / research / implement / plan / advise) |
|
|
74
|
+
| `acp_delegate_wait` | Block until a delegate run finishes (returns its result; times out otherwise) |
|
|
75
|
+
| `acp_delegate_cancel` | Cancel a running delegate by runId |
|
|
76
|
+
|
|
77
|
+
### acp_delegate — clean-context delegation
|
|
78
|
+
|
|
79
|
+
Hand a self-contained task to a fresh pi process running in a clean context. Five built-in roles, each with a tailored tool whitelist and system prompt:
|
|
80
|
+
|
|
81
|
+
| Role | Tools | Best for |
|
|
82
|
+
|------|-------|----------|
|
|
83
|
+
| `reviewer` | read, bash | Read-only code review (bugs, risks, file:line) |
|
|
84
|
+
| `researcher` | read, bash | Read-only codebase investigation |
|
|
85
|
+
| `worker` | read, edit, write, bash | Make code changes |
|
|
86
|
+
| `planner` | read, bash | Analyze + propose a step-by-step plan |
|
|
87
|
+
| `oracle` | read, bash | Answer questions / advise |
|
|
88
|
+
|
|
89
|
+
The full delegate result is saved to a file (`/tmp/acp-delegate/<runId>.out`); the tool result and injected notification carry only the **task title + file path** (no preview) — use `read` for the details. This keeps the parent context lean.
|
|
90
|
+
|
|
91
|
+
- **Interactive (TUI) & RPC modes**: `async:true` (default) runs the child in the background; a short completion notification is injected into the chat when it finishes.
|
|
92
|
+
- **Print / JSON modes** (`pi -p`, SDK): `async:true` auto-downgrades to **synchronous** — the result returns as the tool result in the same turn (the parent exits after one turn, so background injection would be lost).
|
|
93
|
+
|
|
94
|
+
In the **interactive TUI**, async runs also show a live status widget below the editor (agent, elapsed seconds, task preview), so you always know what's running and for how long. Disabled automatically in RPC/print/JSON.
|
|
95
|
+
|
|
96
|
+
## `/acp` command
|
|
97
|
+
|
|
98
|
+
Rich status display for the user:
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
╭─────────────────────────────────────────────╮
|
|
102
|
+
│ ACP Context Analysis │
|
|
103
|
+
╰─────────────────────────────────────────────╯
|
|
104
|
+
pai-acp@0.1.14
|
|
105
|
+
|
|
106
|
+
Context: 12% (120K / 1.0M)
|
|
107
|
+
Growth: +15K since last nudge
|
|
108
|
+
|
|
109
|
+
Token Breakdown:
|
|
110
|
+
System ░░░░░░░░░░░░░░░░░░░░ 2% 2.1K
|
|
111
|
+
Tool ████████████░░░░░░░░ 58% 69.6K
|
|
112
|
+
Summaries ████░░░░░░░░░░░░░░░░ 20% 24.0K
|
|
113
|
+
Code ██░░░░░░░░░░░░░░░░░░ 10% 12.0K
|
|
114
|
+
Text █░░░░░░░░░░░░░░░░░░░ 5% 6.0K
|
|
115
|
+
|
|
116
|
+
Blocks: 3 active (3.7K summary, 15.2K original compressed)
|
|
117
|
+
b1 (T1) 3.7K→599 age=5m "API exploration"
|
|
118
|
+
b2 (T1) 8.2K→2.1K age=2m "Debug session"
|
|
119
|
+
b3 (T2) 3.3K→1.0K age=1m "Architecture review"
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Configuration
|
|
123
|
+
|
|
124
|
+
pai-acp works out of the box with no configuration. Three optional keys can be set in a JSON config file.
|
|
125
|
+
|
|
126
|
+
### Config file
|
|
127
|
+
|
|
128
|
+
Create `~/.pi/acp.json` (global) and/or `<project>/.pi/acp.json` (project-local, overrides global):
|
|
129
|
+
|
|
130
|
+
```json
|
|
131
|
+
{
|
|
132
|
+
"debug": false,
|
|
133
|
+
"autoUpdate": true,
|
|
134
|
+
"modelContextLimit": 200000,
|
|
135
|
+
"delegate": true
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
| Key | Default | Description |
|
|
140
|
+
|-----|---------|-------------|
|
|
141
|
+
| `debug` | `false` | Write diagnostic events to `~/.pi/acp-debug.log`. Also enabled by env `ACP_DEBUG=1`. |
|
|
142
|
+
| `autoUpdate` | `true` | On Pi startup, check npm for a newer version and auto-install it (throttled to one check per 3 minutes). Disable to avoid all startup network calls. |
|
|
143
|
+
| `modelContextLimit` | *(auto)* | Override the context limit (in tokens). Defaults to the model's `contextWindow`. |
|
|
144
|
+
| `delegate` | `true` | Enable the `acp_delegate` tools (delegate/wait/cancel) and their system-prompt section. Set `false` to skip registering them (e.g. you use a different sub-agent extension, or run headless where async injection adds no value). |
|
|
145
|
+
|
|
146
|
+
> **Only these four keys are read from `acp.json`.** Other tuning knobs (`preserveRecentMessages`, `protectedTools`, nudge thresholds) are code-level and not user-overridable.
|
|
147
|
+
|
|
148
|
+
### Environment variables
|
|
149
|
+
|
|
150
|
+
| Variable | Effect |
|
|
151
|
+
|----------|--------|
|
|
152
|
+
| `ACP_AUTO_UPDATE` | Set to `0` / `false` / `no` / `off` (case-insensitive) to disable auto-update, overriding the config. |
|
|
153
|
+
| `ACP_MODEL_CONTEXT_LIMIT` | Override the context limit. Takes precedence over the config value. |
|
|
154
|
+
| `ACP_DEBUG` | Set to `1` or `true` to enable debug logging. |
|
|
155
|
+
|
|
156
|
+
### Compression philosophy
|
|
157
|
+
|
|
158
|
+
The model receives detailed guidance (in its system prompt) on **when** to compress, **what** to keep verbatim (paths, signatures, errors, decisions, user intent), and **what** to drop (verbose logs, duplicates, consumed exploration). This guidance is injected on every turn so it stays in the model's attention.
|
|
159
|
+
|
|
160
|
+
### What gets protected
|
|
161
|
+
|
|
162
|
+
ACP protects three categories of content from compression:
|
|
163
|
+
|
|
164
|
+
1. **Always-protected tools** — `compress` calls are hard-protected (they're load-bearing metadata; compressing them breaks decompress and the "summary is historical" contract).
|
|
165
|
+
2. **Soft recent-zone** — the last N messages (default 5) and last ~5K tokens are soft-protected so the model keeps its working set. Tool results from `decompress`, `search_context`, `read`, and `bash` are **excluded** from this zone: they're large and meant to be compressible once consumed, so they don't eat the protected budget.
|
|
166
|
+
3. **Last user message** — always protected (user intent must survive).
|
|
30
167
|
|
|
31
|
-
##
|
|
168
|
+
## Built on acp-kernel
|
|
32
169
|
|
|
33
|
-
|
|
34
|
-
- [`billion-context-opencode`](https://www.npmjs.com/package/billion-context-opencode) — opencode adapter (reserved).
|
|
170
|
+
The compression engine is [`acp-kernel`](https://github.com/ranxianglei/acp-kernel) — a platform-agnostic, MIT-licensed library with 208 tests. It's bundled inline into `dist/index.js`, so there are zero runtime dependencies.
|
|
35
171
|
|
|
36
172
|
## License
|
|
37
173
|
|
|
38
|
-
MIT
|
|
174
|
+
MIT.
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
[English](./README.md) | [中文](./README.zh-CN.md)
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<strong>主动上下文剪枝</strong> — <a href="https://pi.dev">Pi</a> 的 ACP 插件
|
|
5
|
+
<br />
|
|
6
|
+
由模型决定<em>何时</em>压缩、压缩<em>什么</em> — 而非硬性截断。
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://www.npmjs.com/package/pai-acp"><img src="https://img.shields.io/npm/v/pai-acp.svg?style=flat-square" alt="npm"></a>
|
|
13
|
+
<a href="https://github.com/ranxianglei/pai-acp/blob/master/LICENSE"><img src="https://img.shields.io/npm/l/pai-acp.svg?style=flat-square" alt="license"></a>
|
|
14
|
+
<a href="https://github.com/ranxianglei/pai-acp"><img src="https://img.shields.io/badge/GitHub-ranxianglei%2Fpai--acp-181717?style=flat-square&logo=github" alt="GitHub"></a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
<p align="center">
|
|
18
|
+
<code>pi install npm:pai-acp</code>
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 为什么选择 ACP
|
|
24
|
+
|
|
25
|
+
当对话变长,模型的上下文会耗尽。多数工具采用硬截断 —— 静默丢弃早期消息。**ACP** 把 `compress` 工具交给模型:由 LLM 决定**何时**压缩、压缩**什么**,将内容压缩成高保真摘要,在回收上下文空间的同时保留关键细节(文件路径、决策、错误字符串)。
|
|
26
|
+
|
|
27
|
+
与 Pi 内置的自动压缩(把所有内容替换成单个摘要)不同,ACP:
|
|
28
|
+
|
|
29
|
+
- **保留结构** — 压缩的范围变成带标签的块,可后续解压
|
|
30
|
+
- **多级压缩** — 摘要可被进一步蒸馏(T1 → T2 → T3),随会话增长保持有界
|
|
31
|
+
- **可搜索** — `search_context` 无需解压即可搜索已压缩块内的信息
|
|
32
|
+
- **有选择性** — 受保护的工具、用户消息、近期工作集永不被压缩
|
|
33
|
+
|
|
34
|
+
这使得:
|
|
35
|
+
|
|
36
|
+
1. **一个会话即可支撑海量工作。** 根据三级压缩架构的模拟测试(见 [opencode-acp](https://github.com/ranxianglei/opencode-acp)),单会话累计可处理约 100 亿至 600 亿 token —— 同时对遥远的关键信息(路径、决策、签名)保持长久记忆。用户可以在**同一个会话里连续工作几个月**,而无需因为上下文膨胀而开新会话丢上下文。
|
|
37
|
+
2. **上下文长期保持精简。** 实际运行中上下文通常稳定在 15 万 token 以下(opencode-acp 实测维持在 20 万以下),相比传统压缩方案动辄撑到 100 万上下文,**单会话累计可节省近 5 倍的 token 费用**。
|
|
38
|
+
|
|
39
|
+
## 安装
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pi install npm:pai-acp
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
完成。扩展在下次 Pi 启动时自动加载。无需配置 —— 它会自动读取模型的上下文窗口。
|
|
46
|
+
|
|
47
|
+
> **建议先卸载 `pi-subagents`(可选,推荐)。** pai-acp 自带 `acp_delegate` 子代理工具(见下文),以极低的上下文成本(~600 tok vs ~7K tok/轮)替代 pi-subagents。如果你已安装 pi-subagents,卸载它以避免重复的委派工具:
|
|
48
|
+
> ```bash
|
|
49
|
+
> pi remove npm:pi-subagents
|
|
50
|
+
> ```
|
|
51
|
+
|
|
52
|
+
## 工作原理
|
|
53
|
+
|
|
54
|
+
ACP 拦截 Pi 的 `context` 事件(每次 LLM 调用前触发),运行一个 8 阶段管线:
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
assign refs → sync blocks → prune → filter → hide calls → recommend → nudge → emergency truncate
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
每条消息获得一个不可见的 `<acp>` 引用标签(`m00001`、`m00002`、...),对模型可见但用户不可见。模型用这些引用来指定压缩范围。
|
|
61
|
+
|
|
62
|
+
Pi 内置的自动压缩会被取消 —— ACP 是唯一的上下文管理者。
|
|
63
|
+
|
|
64
|
+
## 模型工具
|
|
65
|
+
|
|
66
|
+
| 工具 | 作用 |
|
|
67
|
+
|------|------|
|
|
68
|
+
| `compress` | 用详细摘要替换连续的消息范围 |
|
|
69
|
+
| `decompress` | 恢复之前压缩的块内容 |
|
|
70
|
+
| `search_context` | 按关键词搜索已压缩块摘要(及可见消息) |
|
|
71
|
+
| `acp_status` | 显示上下文用量、已压缩块、可压缩范围 |
|
|
72
|
+
| `acp_delegate` | 为某个任务派生一个干净上下文的子代理(审查 / 调研 / 实现 / 规划 / 建议) |
|
|
73
|
+
| `acp_delegate_wait` | 阻塞等待委派任务完成(返回结果,否则超时) |
|
|
74
|
+
| `acp_delegate_cancel` | 按 runId 取消正在运行的委派任务 |
|
|
75
|
+
|
|
76
|
+
### acp_delegate — 干净上下文委派
|
|
77
|
+
|
|
78
|
+
把一个自包含的任务交给一个运行在干净上下文中的新 pi 进程。五个内置角色,各自有定制的工具白名单和系统提示:
|
|
79
|
+
|
|
80
|
+
| 角色 | 工具 | 适用场景 |
|
|
81
|
+
|------|------|----------|
|
|
82
|
+
| `reviewer` | read, bash | 只读代码审查(bug、风险、file:line) |
|
|
83
|
+
| `researcher` | read, bash | 只读代码库调研 |
|
|
84
|
+
| `worker` | read, edit, write, bash | 修改代码 |
|
|
85
|
+
| `planner` | read, bash | 分析 + 提出分步计划 |
|
|
86
|
+
| `oracle` | read, bash | 回答问题 / 建议 |
|
|
87
|
+
|
|
88
|
+
委派的完整结果保存到文件(`/tmp/acp-delegate/<runId>.out`);工具结果和注入通知只携带**任务标题 + 文件路径**(无预览)— 需要细节时用 `read` 读取。这让父上下文保持精简。
|
|
89
|
+
|
|
90
|
+
- **交互(TUI)与 RPC 模式**:`async:true`(默认)在后台运行子进程;完成时一条简短通知注入到聊天框。
|
|
91
|
+
- **Print / JSON 模式**(`pi -p`、SDK):`async:true` 自动降级为**同步** — 结果在同一轮作为工具结果返回(父进程一轮后即退出,后台注入会丢失)。
|
|
92
|
+
|
|
93
|
+
在**交互 TUI** 中,异步运行还会在编辑器下方显示一个实时状态 widget(角色、已运行秒数、任务预览),让你随时知道什么在跑、跑了多久。RPC/print/JSON 模式自动禁用。
|
|
94
|
+
|
|
95
|
+
## `/acp` 命令
|
|
96
|
+
|
|
97
|
+
为用户提供丰富的状态显示:
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
╭─────────────────────────────────────────────╮
|
|
101
|
+
│ ACP Context Analysis │
|
|
102
|
+
╰─────────────────────────────────────────────╯
|
|
103
|
+
pai-acp@0.1.14
|
|
104
|
+
|
|
105
|
+
Context: 12% (120K / 1.0M)
|
|
106
|
+
Growth: +15K since last nudge
|
|
107
|
+
|
|
108
|
+
Token Breakdown:
|
|
109
|
+
System ░░░░░░░░░░░░░░░░░░░░ 2% 2.1K
|
|
110
|
+
Tool ████████████░░░░░░░░ 58% 69.6K
|
|
111
|
+
Summaries ████░░░░░░░░░░░░░░░░ 20% 24.0K
|
|
112
|
+
Code ██░░░░░░░░░░░░░░░░░░ 10% 12.0K
|
|
113
|
+
Text █░░░░░░░░░░░░░░░░░░░ 5% 6.0K
|
|
114
|
+
|
|
115
|
+
Blocks: 3 active (3.7K summary, 15.2K original compressed)
|
|
116
|
+
b1 (T1) 3.7K→599 age=5m "API exploration"
|
|
117
|
+
b2 (T1) 8.2K→2.1K age=2m "Debug session"
|
|
118
|
+
b3 (T2) 3.3K→1.0K age=1m "Architecture review"
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## 配置
|
|
122
|
+
|
|
123
|
+
pai-acp 开箱即用,无需任何配置。可以在 JSON 配置文件中设置三个可选 key。
|
|
124
|
+
|
|
125
|
+
### 配置文件
|
|
126
|
+
|
|
127
|
+
创建 `~/.pi/acp.json`(全局)和/或 `<项目>/.pi/acp.json`(项目级,覆盖全局):
|
|
128
|
+
|
|
129
|
+
```json
|
|
130
|
+
{
|
|
131
|
+
"debug": false,
|
|
132
|
+
"autoUpdate": true,
|
|
133
|
+
"modelContextLimit": 200000,
|
|
134
|
+
"delegate": true
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
| Key | 默认值 | 说明 |
|
|
139
|
+
|-----|--------|------|
|
|
140
|
+
| `debug` | `false` | 将诊断事件写入 `~/.pi/acp-debug.log`。也可用环境变量 `ACP_DEBUG=1` 启用。 |
|
|
141
|
+
| `autoUpdate` | `true` | Pi 启动时检查 npm 是否有更新版本并自动安装(限频:每 3 分钟最多一次检查)。禁用以避免所有启动时的网络请求。 |
|
|
142
|
+
| `modelContextLimit` | *(自动)* | 覆盖上下文上限(token 数)。默认为模型的 `contextWindow`。 |
|
|
143
|
+
| `delegate` | `true` | 启用 `acp_delegate` 工具(delegate/wait/cancel)及其系统提示词段落。设为 `false` 则不注册这些工具(例如你用了别的子代理扩展,或跑 headless 场景异步注入没有意义)。 |
|
|
144
|
+
|
|
145
|
+
> **只有这四个 key 会被 `acp.json` 读取。** 其他调优参数(`preserveRecentMessages`、`protectedTools`、nudge 阈值)是代码级的,不向用户开放。
|
|
146
|
+
|
|
147
|
+
### 环境变量
|
|
148
|
+
|
|
149
|
+
| 变量 | 作用 |
|
|
150
|
+
|------|------|
|
|
151
|
+
| `ACP_AUTO_UPDATE` | 设为 `0` / `false` / `no` / `off`(不区分大小写)以禁用自动更新,覆盖配置值。 |
|
|
152
|
+
| `ACP_MODEL_CONTEXT_LIMIT` | 覆盖上下文上限。优先级高于配置值。 |
|
|
153
|
+
| `ACP_DEBUG` | 设为 `1` 或 `true` 启用 debug 日志。 |
|
|
154
|
+
|
|
155
|
+
### 压缩策略
|
|
156
|
+
|
|
157
|
+
模型接收(在其系统提示中)关于**何时**压缩、**逐字保留什么**(路径、签名、错误、决策、用户意图)、**丢弃什么**(冗长日志、重复内容、已消费的探索)的详细指导。这段指导每轮都注入,确保它始终在模型的注意力范围内。
|
|
158
|
+
|
|
159
|
+
### 哪些内容会被保护
|
|
160
|
+
|
|
161
|
+
ACP 保护三类内容不被压缩:
|
|
162
|
+
|
|
163
|
+
1. **永久保护的工具** — `compress` 调用被硬保护(它们是承载关键元数据的;压缩它们会破坏 decompress 和"摘要是历史"的契约)。
|
|
164
|
+
2. **软近期区** — 最后 N 条消息(默认 5)和最后约 5K token 被软保护,让模型保留工作集。来自 `decompress`、`search_context`、`read`、`bash` 的工具结果被**排除**出此区:它们体量大、消费后就该能压缩,所以不该占用保护预算。
|
|
165
|
+
3. **最后一条用户消息** — 始终保护(用户意图必须存活)。
|
|
166
|
+
|
|
167
|
+
## 基于 acp-kernel
|
|
168
|
+
|
|
169
|
+
压缩引擎是 [`acp-kernel`](https://github.com/ranxianglei/acp-kernel) — 平台无关、MIT 许可的库,有 208 个测试。它被内联打包进 `dist/index.js`,因此零运行时依赖。
|
|
170
|
+
|
|
171
|
+
## 许可证
|
|
172
|
+
|
|
173
|
+
MIT.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RegisteredCommand } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { AcpRuntime } from "./runtime.js";
|
|
3
|
+
type CommandOptions = Omit<RegisteredCommand, "name" | "sourceInfo">;
|
|
4
|
+
export declare function makeCommands(runtime: AcpRuntime): Array<{
|
|
5
|
+
name: string;
|
|
6
|
+
options: CommandOptions;
|
|
7
|
+
}>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import type { ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import type { AcpRuntime } from "./runtime.js";
|
|
4
|
+
declare const CompressParams: Type.TObject<{
|
|
5
|
+
topic: Type.TOptional<Type.TString>;
|
|
6
|
+
content: Type.TArray<Type.TObject<{
|
|
7
|
+
startId: Type.TString;
|
|
8
|
+
endId: Type.TString;
|
|
9
|
+
summary: Type.TString;
|
|
10
|
+
topic: Type.TOptional<Type.TString>;
|
|
11
|
+
}>>;
|
|
12
|
+
summaryMaxChars: Type.TOptional<Type.TNumber>;
|
|
13
|
+
}>;
|
|
14
|
+
export declare function makeCompressTool(runtime: AcpRuntime): ToolDefinition<typeof CompressParams>;
|
|
15
|
+
export {};
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Config } from "acp-kernel";
|
|
2
|
+
/**
|
|
3
|
+
* Adapter configuration. Maps onto acp-kernel's `Config` plus Pi-specific knobs
|
|
4
|
+
* (live model context window, protected tools, state persistence).
|
|
5
|
+
*/
|
|
6
|
+
export interface AdapterConfig {
|
|
7
|
+
/** When omitted, the adapter reads `ctx.model.contextWindow` live each turn.
|
|
8
|
+
* Set explicitly for tests/headless runs. */
|
|
9
|
+
modelContextLimit?: number;
|
|
10
|
+
protectedTools?: string[];
|
|
11
|
+
preserveRecentMessages?: number;
|
|
12
|
+
/** Check npm for a newer pai-acp on startup and auto-install it. Default: true.
|
|
13
|
+
* Disable via `autoUpdate: false` or env `ACP_AUTO_UPDATE=0` to avoid all
|
|
14
|
+
* network calls on startup. */
|
|
15
|
+
autoUpdate?: boolean;
|
|
16
|
+
/** Write ACP debug events to the debug log file (default ~/.pi/acp-debug.log).
|
|
17
|
+
* Default: false (or env ACP_DEBUG=1/true). */
|
|
18
|
+
debug?: boolean;
|
|
19
|
+
/** Enable acp_delegate tools (delegate/wait/cancel) and their system-prompt
|
|
20
|
+
* section. Default: true. Set `delegate: false` (adapter config or
|
|
21
|
+
* ~/.pi/acp.json) to skip registering them. */
|
|
22
|
+
delegate?: boolean;
|
|
23
|
+
coreOverrides?: Partial<Config>;
|
|
24
|
+
}
|
|
25
|
+
export declare function resolveConfig(adapter: AdapterConfig, liveContextLimit: number): Config;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import type { ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import type { AcpRuntime } from "./runtime.js";
|
|
4
|
+
declare const DecompressParams: Type.TObject<{
|
|
5
|
+
blockId: Type.TString;
|
|
6
|
+
full: Type.TOptional<Type.TBoolean>;
|
|
7
|
+
toFile: Type.TOptional<Type.TString>;
|
|
8
|
+
inline: Type.TOptional<Type.TBoolean>;
|
|
9
|
+
}>;
|
|
10
|
+
export declare function makeDecompressTool(runtime: AcpRuntime): ToolDefinition<typeof DecompressParams>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import type { ExtensionAPI, ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
/** Snapshot of currently-running delegate runs, for the TUI status widget. */
|
|
4
|
+
export declare function runningRunsSnapshot(): {
|
|
5
|
+
runId: string;
|
|
6
|
+
agent: string;
|
|
7
|
+
task: string;
|
|
8
|
+
startedAt: number;
|
|
9
|
+
}[];
|
|
10
|
+
declare const DelegateParams: Type.TObject<{
|
|
11
|
+
agent: Type.TString;
|
|
12
|
+
task: Type.TString;
|
|
13
|
+
cwd: Type.TOptional<Type.TString>;
|
|
14
|
+
model: Type.TOptional<Type.TString>;
|
|
15
|
+
async: Type.TOptional<Type.TBoolean>;
|
|
16
|
+
}>;
|
|
17
|
+
declare const CancelParams: Type.TObject<{
|
|
18
|
+
runId: Type.TString;
|
|
19
|
+
}>;
|
|
20
|
+
declare const WaitParams: Type.TObject<{
|
|
21
|
+
runId: Type.TString;
|
|
22
|
+
timeout: Type.TOptional<Type.TInteger>;
|
|
23
|
+
}>;
|
|
24
|
+
export declare function makeDelegateTool(pi: ExtensionAPI): ToolDefinition<typeof DelegateParams>;
|
|
25
|
+
export declare function makeDelegateWaitTool(_pi: ExtensionAPI): ToolDefinition<typeof WaitParams>;
|
|
26
|
+
export declare function makeDelegateCancelTool(_pi: ExtensionAPI): ToolDefinition<typeof CancelParams>;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
interface WidgetRun {
|
|
3
|
+
runId: string;
|
|
4
|
+
agent: string;
|
|
5
|
+
task: string;
|
|
6
|
+
startedAt: number;
|
|
7
|
+
}
|
|
8
|
+
type RunsSnapshot = () => WidgetRun[];
|
|
9
|
+
export declare const delegateStatusWidget: {
|
|
10
|
+
setContext(ctx: ExtensionContext, snapshot: RunsSnapshot): void;
|
|
11
|
+
dispose(): void;
|
|
12
|
+
poke(): void;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ExtensionFactory } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { AdapterConfig } from "./config.js";
|
|
3
|
+
export declare function createAcpExtension(adapter?: AdapterConfig): ExtensionFactory;
|
|
4
|
+
declare const _default: ExtensionFactory;
|
|
5
|
+
export default _default;
|