pi-midcompact 0.3.0 → 0.5.0

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 CHANGED
@@ -1,14 +1,104 @@
1
1
  # pi-midcompact
2
2
 
3
- **Compress stale parts of a long Pi session without deleting the original history.**
3
+ [简体中文](./README.zh-CN.md)
4
4
 
5
- Long-running work accumulates exploration, command output, rejected approaches, and completed phases. `pi-midcompact` lets you and the Agent replace only the parts you have reviewed with concise summaries, leaving the current task and important decisions in full context.
5
+ **Attention-aware mid-context compression: compress the noise, keep the signal.**
6
+
7
+ “Attention-aware” borrows the core idea of neural attention: keep in working context what future work still needs to attend to, rather than deciding from message age alone. A long session does not become stale uniformly. Exploratory reads, failed attempts, routine tool output, and implementation work that is already complete can occupy most of the context window after their value has largely expired. A user requirement, hard-won decision, or unresolved failure from much earlier may still need to remain verbatim.
8
+
9
+ Pi's built-in `/compact` behaves like **prefix compaction**: it turns an older contiguous prefix into one summary and retains a recent tail. That is appropriate automatic maintenance, but the cut itself does not distinguish a dispensable old exploration from an older decision worth keeping raw.
10
+
11
+ The name `pi-midcompact` points to the other option: **mid-context compression**. It compresses selected spans inside the active context while leaving valuable raw context on either side in place, and preserves the original session history for recall.
6
12
 
7
13
  - Choose exactly which conversation ranges to compress.
8
14
  - Review the proposed boundaries and summaries before anything changes.
9
15
  - Keep the original Pi session entries available for later recall.
10
16
  - Keep compression local to the current session-tree branch.
11
17
 
18
+ ## What it does
19
+
20
+ At a natural checkpoint, `pi-midcompact` freezes the active session leaf as an anchor and opens a separate transaction. The Agent proposes ranges for completed low-value phases, preserves load-bearing messages verbatim, and prepares a draft for review. Nothing changes until you explicitly commit the plan.
21
+
22
+ ### User-directed depth, Agent-designed plan
23
+
24
+ The workflow is **Agent-driven but user-directed**. You describe the desired retention depth and what must remain visible; the Agent examines the frozen anchor, discusses trade-offs with you, and drafts selective ranges and summaries. You do not need to select atom IDs yourself.
25
+
26
+ > “I only want to reclaim roughly 30% of the stale context. Do not compress aggressively; keep the reasoning behind earlier decisions verbatim.”
27
+
28
+ That is planning guidance, not an enforced token target: semantic importance wins over an exact percentage. The Agent turns it into a reviewable proposal—selected ranges, explicit `KEEP` holes, and summaries—then you approve, revise, or reject it before committing.
29
+
30
+ ### A selective projection, prepared on a temporary branch
31
+
32
+ `/midcompact start` freezes the current session leaf as an **anchor**. Planning happens on a disposable child branch, so the discussion used to create and edit the draft never becomes part of the committed working context.
33
+
34
+ ```text
35
+ Frozen anchor: raw session history
36
+
37
+ [early exploration]──[decision to KEEP]──[routine tool output]──[latest work] ◀ anchor
38
+ ╰──── d1 ────╯ ╰──── d2 ────╯
39
+
40
+ Planning is isolated on a temporary branch:
41
+
42
+ ... [latest work] ──┬── [transaction] ── [draft v1] ── [draft v2] ◀ review / edit
43
+ │ (abandoned at commit)
44
+ └── [midcompact-state] ◀ committed leaf
45
+ (reviewed selection metadata, not a model message; written only by /midcompact commit)
46
+
47
+ Later model requests see a selective projection:
48
+
49
+ [summary d1]──[decision to KEEP]──[summary d2]──[latest work]
50
+
51
+ The raw session JSONL still contains:
52
+
53
+ [original d1]──[decision to KEEP]──[original d2]──[latest work]
54
+ ```
55
+
56
+ ### A reviewed draft can reclaim meaningful context
57
+
58
+ The earlier browser and TUI captures below illustrate a draft with **2 ranges** covering **42 of 73 atoms**, while the other 31 atoms remain verbatim. The current UI reports Pi-provided anchor usage separately from factual content chars and image counts; it does not derive projected token savings from local character estimates. Click either image to open it at full resolution.
59
+
60
+ <p align="center">
61
+ <a href="./figures/review-webui.png">
62
+ <img src="./figures/review-webui.png" alt="Browser review UI showing 42 of 73 atoms selected across two compression ranges" width="49%">
63
+ </a>
64
+ <a href="./figures/review-tui.png">
65
+ <img src="./figures/review-tui.png" alt="Native TUI review showing a selected compression range and its retained atoms" width="49%">
66
+ </a>
67
+ </p>
68
+
69
+ <p align="center"><sub>Editable browser review UI · Native Pi TUI review</sub></p>
70
+
71
+ ### Prefix compaction versus mid-context compression
72
+
73
+ Both mechanisms preserve the stored JSONL history, but they decide what later model requests see in different ways:
74
+
75
+ ```text
76
+ Pi built-in /compact — automatic threshold or one manual command
77
+
78
+ [older contiguous history────────────────────][recent tail]
79
+
80
+
81
+ [one compaction summary──────────────────────][recent tail]
82
+
83
+ pi-midcompact — mid-context compression, review, then human commit
84
+
85
+ [stale phase]──[load-bearing decision]──[routine output]──[recent work]
86
+ d1 KEEP d2
87
+ │ │
88
+ ▼ ▼
89
+ [summary d1]──[load-bearing decision]──[summary d2]──[recent work]
90
+ ```
91
+
92
+ | | Pi `/compact` | `pi-midcompact` |
93
+ | --- | --- | --- |
94
+ | Starts | Automatically near the context limit, or with `/compact` | At an explicit natural checkpoint with `/midcompact start` |
95
+ | Selects | One older contiguous prefix; keeps a recent token-budgeted tail | One or more reviewed ranges, including non-contiguous ranges and `KEEP` holes |
96
+ | Planning | Optional one-shot instruction to focus the generated summary | User states scope and retention depth; the Agent discusses trade-offs and drafts selective ranges and summaries |
97
+ | Decision gate | Generates a compaction checkpoint directly | Draft → TUI or browser review → explicit human `/midcompact commit` |
98
+ | Best fit | Automatic context maintenance and overflow recovery | Deliberate cleanup of completed phases while retaining specific decisions verbatim |
99
+
100
+ `pi-midcompact` does not disable or replace Pi's automatic compaction; it gives you a separate, human-reviewed way to make selective reductions. See [Pi's compaction documentation](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/docs/compaction.md) for the built-in mechanism.
101
+
12
102
  ## Install
13
103
 
14
104
  From npm:
@@ -37,7 +127,7 @@ Run:
37
127
  /midcompact start
38
128
  ```
39
129
 
40
- Pi asks for confirmation, then creates a temporary transaction after the anchor and tells the Agent how to plan the compression. No conversation is changed yet. You can include the initial scope in the same command:
130
+ Pi opens a three-way chooser before creating transaction state: **Drop**, **Agent direct**, or **User manual**. Agent direct starts the existing inventory-first Agent workflow. User manual sends the same transaction guidance with a final “acknowledge only” instruction; after the Agent replies briefly, the Selection workbench opens. It does not start planning or mutate the DraftPlan until the user hands off later. Save the initial DraftPlan, close the UI, then tell the Agent to continue when you are ready. You can include an initial focus in the same command:
41
131
 
42
132
  ```text
43
133
  /midcompact start Compress the early repository exploration, but keep user requirements verbatim.
@@ -50,7 +140,7 @@ Describe the goal in normal language. For example:
50
140
  ```text
51
141
  Compress the early repository exploration and routine command output.
52
142
  Keep the user's requirements, the rejected database decision, and the final validation errors verbatim.
53
- Aim for a moderate reduction, not the smallest possible context.
143
+ Reclaim roughly 30% of the stale context, but preserve semantic distinctions rather than chasing an exact token number.
54
144
  ```
55
145
 
56
146
  The Agent locates relevant parts of the frozen conversation, proposes one or more ranges, and writes a summary for each range. You can ask it to preserve a specific message, split a range, or revise a summary.
@@ -63,9 +153,22 @@ Run:
63
153
  /midcompact review
64
154
  ```
65
155
 
66
- The native TUI displays the frozen conversation as a linear timeline. Each item is marked either `KEEP` or as belonging to a proposed range. Review the range boundaries and the summary that will replace each range.
156
+ In interactive mode, the native TUI displays the frozen conversation as a linear timeline. Each item is marked either `KEEP` or as belonging to a proposed range. Review the range boundaries and the summary that will replace each range.
157
+
158
+ For RPC, print, or other no-TUI modes, use the editable local browser interface instead:
159
+
160
+ ```text
161
+ /midcompact review-webui
162
+ ```
163
+
164
+ Use Selection to create or change ranges and KEEP holes:
165
+
166
+ ```text
167
+ /midcompact select
168
+ /midcompact select-webui
169
+ ```
67
170
 
68
- You can edit a selected summary or topic in the TUI. To change range boundaries or leave an important hole uncompressed, tell the Agent what to keep and ask it to revise the plan, then review it again.
171
+ Use the TUI or local browser Review surface to edit summaries/topics and reject ranges. Review deliberately does not create or resize ranges; reopen Selection for boundary changes. To continue with Agent after a user-created plan, send a normal message asking it to continue the current midcompact draft; the Agent is prompted to read the existing plan first.
69
172
 
70
173
  ### 4. Commit the reviewed compression
71
174
 
@@ -79,8 +182,6 @@ This is deliberately a human command. The Agent cannot commit compression itself
79
182
 
80
183
  Pi returns to the anchor, discards the temporary planning branch, stores the reviewed compression state, and resumes work from the committed branch. Future model requests receive the selected old ranges as summaries instead of raw messages.
81
184
 
82
- ![A compression transaction keeps planning separate from the working branch.](./figures/transaction-lifecycle.svg)
83
-
84
185
  ### 5. Continue working or abort
85
186
 
86
187
  Keep working normally after committing. If you decide not to compress, run:
@@ -91,37 +192,7 @@ Keep working normally after committing. If you decide not to compress, run:
91
192
 
92
193
  This returns to the anchor and discards the transaction without changing the active context.
93
194
 
94
- ## What the Agent Does
95
-
96
- During an active transaction, the Agent uses the `midcompact` tool against the frozen anchor snapshot:
97
-
98
- ![How the Agent turns semantic judgment into a reviewed compression plan.](./figures/agent-planning.svg)
99
-
100
- | Action | Purpose |
101
- | --- | --- |
102
- | `locate` | Finds likely conversation landmarks and shows readable previews. |
103
- | `plan` | Adds, revises, removes, or displays proposed compression ranges and summaries. |
104
- | `recall` | Searches committed summaries or temporarily retrieves original content from a compressed block. |
105
-
106
- The Agent makes semantic decisions: which exploration is stale, which user requirements and decisions must stay visible, and what a useful summary needs to retain. The extension enforces the mechanical rules: ranges cannot overlap, incomplete tool exchanges cannot be compressed, and the Agent cannot bypass the human commit gate.
107
-
108
- Temporary references such as `a0007` exist only during planning. They are not inserted into normal prompts or retained as permanent message identifiers.
109
-
110
- ## What Happens Behind the Scenes
111
-
112
- A committed compression does not rewrite or delete the Pi session.
113
-
114
- ![Compression replaces a reviewed range only in later model requests.](./figures/context-projection.svg)
115
-
116
- 1. `/midcompact start [instructions]` freezes the current session-tree leaf as the anchor and starts a temporary maintenance branch.
117
- 2. The Agent and you discuss a draft on that branch. This planning chatter is abandoned at commit.
118
- 3. `/midcompact commit` returns to the anchor and saves a branch-local `midcompact-state` entry containing the reviewed ranges and summaries.
119
- 4. Before later model requests, the extension finds the exact selected raw message sequences and projects them into summary messages.
120
- 5. The underlying session entries remain unchanged. If an exact match cannot be found, the extension keeps the raw messages rather than removing uncertain content.
121
-
122
- This is why the process is both selective and reversible at the information-access level: a summary saves context, while the source history remains available through recall or the Pi session tree.
123
-
124
- ## Review Controls
195
+ ## Native TUI Controls
125
196
 
126
197
  Inside `/midcompact review`:
127
198
 
@@ -140,8 +211,11 @@ Enter/Esc/q close
140
211
 
141
212
  | Command | Result |
142
213
  | --- | --- |
143
- | `/midcompact start [instructions]` | Confirms and starts a transaction at the current session-tree leaf, optionally with an initial compression focus. |
144
- | `/midcompact review` | Opens the draft review timeline. |
214
+ | `/midcompact start [instructions]` | Opens Drop / Agent direct / User manual, then starts a transaction at the current session-tree leaf. |
215
+ | `/midcompact select` | Opens the native TUI Selection workbench for range and KEEP editing. |
216
+ | `/midcompact select-webui` | Opens the local browser Selection workbench. |
217
+ | `/midcompact review` | Opens summary/topic review in the native TUI. |
218
+ | `/midcompact review-webui` | Opens summary/topic review in a local browser. |
145
219
  | `/midcompact commit` | Commits the reviewed draft. Human only. |
146
220
  | `/midcompact abort` | Abandons the transaction and returns to the anchor. |
147
221
  | `/midcompact status` | Displays the current draft, or the committed compression state on this branch. |
@@ -151,6 +225,7 @@ The extension shows planning status in Pi's footer only while a transaction is a
151
225
  ## Guarantees and Limits
152
226
 
153
227
  - **Original history is retained.** Compression changes what later model requests see, not the stored Pi messages.
228
+ - **Fail-open projection.** If an exact reviewed sequence no longer resolves, the extension sends the raw history unchanged rather than removing uncertain content.
154
229
  - **State is branch-local.** Navigating with `/tree` to a point before a committed state restores raw history; returning to its descendant restores the projection.
155
230
  - **Human review is required.** The Agent can propose a plan but cannot execute `/midcompact commit`.
156
231
  - **Tool protocol is protected.** Unknown, incomplete, or orphaned tool exchanges are not compressible.
@@ -158,4 +233,4 @@ The extension shows planning status in Pi's footer only while a transaction is a
158
233
  - **Native Pi `/compact` interaction needs more real-session validation.** Avoid relying on mixed automatic/native compaction behavior for critical work until it has been exercised in your environment.
159
234
  - **Provider and extension interoperability needs more real-session validation.** Unusual message shapes, third-party context-transform ordering, and long-lived exact message fingerprints have not been broadly exercised.
160
235
  - **Very long sessions are not stress-tested.** Large review snapshots and repeated block accumulation may eventually require consolidation.
161
- - **Review is TUI-only.** There is no browser review interface in this version.
236
+ - **Browser workbenches are local.** `select-webui` and `review-webui` bind to loopback and mutate the same branch-local DraftPlan as the native TUI surfaces.
@@ -0,0 +1,236 @@
1
+ # pi-midcompact
2
+
3
+ [English](./README.md)
4
+
5
+ **Attention-aware 的上下文中段压缩:压缩噪声,保留关键信息。**
6
+
7
+ 这里的 Attention-aware 借用注意力机制的核心想法:保留与压缩的判断,要看后续工作仍需关注什么,不能只按消息新旧划分。长会话里的内容不会同时失去价值。早期探索、失败尝试、常规工具输出,以及已经完成的实现过程,在对应工作结束后往往只有很少的后续价值,却可能占据大部分上下文。相比之下,较早的用户需求、关键决策或尚未解决的错误,仍可能需要保留原文。
8
+
9
+ Pi 内置的 `/compact` 可理解为**前缀压缩**(prefix compaction):它把一段较早的连续历史汇总为一份摘要,并保留近期上下文。这适合自动维护会话;不过,切分边界本身不会区分可舍弃的早期探索和应保留原文的较早决策。
10
+
11
+ `pi-midcompact` 名称中的 mid 指向另一种做法:**上下文中段压缩**(mid-context compression)。它在活跃上下文内部选择区段压缩,让两侧仍有价值的内容保留原文,并保留原始会话历史,供需要时召回。
12
+
13
+ - 可选择多个对话区段进行压缩。
14
+ - 区段边界和摘要均须审查后才会生效。
15
+ - 原始 Pi 会话条目可在需要时由 Agent 召回。
16
+ - 压缩状态只在当前会话树分支生效。
17
+
18
+ ## 它解决什么问题
19
+
20
+ 在合适的工作节点,`pi-midcompact` 会把当前会话叶节点冻结为锚点,并开启独立事务。Agent 负责为已经完成、后续价值较低的阶段拟定压缩区段,关键消息保留原文;草案必须经过审查,只有显式提交后才会生效。
21
+
22
+ ### 用户确定方向,Agent 设计方案
23
+
24
+ 这套流程由 Agent 推动,方向由用户确定。用户只需说明希望保留什么、准备压缩到什么程度;Agent 会查看冻结后的锚点,与用户讨论取舍,拟定待压缩区段和摘要。用户不必自己定位对话原子编号。
25
+
26
+ > “我只想回收大约 30% 的陈旧上下文,不要压得太狠;早期决策背后的推理请保留原文。”
27
+
28
+ 这里的比例只作规划参考,语义上的重要性高于精确比例。Agent 会把要求转成一份可审查的方案:列出拟压缩区段、明确 `KEEP` 保留区,并为每个区段撰写摘要。用户可以批准、修改或否决,再决定是否提交。
29
+
30
+ ### 在临时分支中规划,提交后选择性投影
31
+
32
+ `/midcompact start` 会把当前会话叶节点冻结为**锚点**。规划工作发生在临时子分支上,因此用于制定和修改草案的对话不会进入提交后的工作上下文。
33
+
34
+ ```text
35
+ 冻结锚点:原始会话历史
36
+
37
+ [早期探索]────[保留的决策]────[常规工具输出]────[最近工作] ◀ 锚点
38
+ ╰── d1 ──╯ ╰── d2 ──╯
39
+
40
+ 规划工作在临时分支上进行:
41
+
42
+ ... [最近工作] ──┬── [事务] ── [草案 v1] ── [草案 v2] ◀ 审查 / 修改
43
+ │ (提交时舍弃)
44
+ └── [midcompact-state] ◀ 提交后的叶节点
45
+ (记录已审查的选择;不是模型消息;仅由 /midcompact commit 写入)
46
+
47
+ 后续模型请求看到的是选择性投影后的上下文:
48
+
49
+ [d1 摘要]────[保留的决策]────[d2 摘要]────[最近工作]
50
+
51
+ 原始会话 JSONL 仍保留:
52
+
53
+ [d1 原文]────[保留的决策]────[d2 原文]────[最近工作]
54
+ ```
55
+
56
+ ### 实际压缩效果
57
+
58
+ 下面的早期浏览器和 TUI 截图展示了一份包含 **2 个区段**、覆盖 **73 个 atom 中 42 个**的草案,其余 31 个 atom 保留原文。当前 UI 会把 Pi 提供的锚点 usage 与扩展统计的 content chars、图片数量分开显示,不再根据本地字符估算推导预计 token 节省量。点击图片可查看原图。
59
+
60
+ <p align="center">
61
+ <a href="./figures/review-webui.png">
62
+ <img src="./figures/review-webui.png" alt="浏览器审查界面:73 个对话原子中有 42 个分布在两个压缩区段内" width="49%">
63
+ </a>
64
+ <a href="./figures/review-tui.png">
65
+ <img src="./figures/review-tui.png" alt="原生 TUI 审查界面:展示选中的压缩区段及其中的对话原子" width="49%">
66
+ </a>
67
+ </p>
68
+
69
+ <p align="center"><sub>可编辑的浏览器审查界面 · Pi 原生 TUI 审查界面</sub></p>
70
+
71
+ ### 前缀压缩与上下文中段压缩
72
+
73
+ 两种机制都保留 JSONL 中存储的原始历史,但它们决定后续模型请求内容的方式不同:
74
+
75
+ ```text
76
+ Pi 内置 /compact —— 达到阈值时自动执行,或手动执行一次命令
77
+
78
+ [较早的一段连续历史────────────────────][保留的近期上下文]
79
+
80
+
81
+ [一份压缩摘要──────────────────────────][保留的近期上下文]
82
+
83
+ pi-midcompact —— 上下文中段压缩,审查后由用户提交
84
+
85
+ [陈旧阶段]────[关键决策]────[常规输出]────[近期工作]
86
+ d1 KEEP d2
87
+ │ │
88
+ ▼ ▼
89
+ [d1 摘要]────[关键决策]────[d2 摘要]────[近期工作]
90
+ ```
91
+
92
+ | 项目 | Pi `/compact` | `pi-midcompact` |
93
+ | --- | --- | --- |
94
+ | 开始条件 | 接近上下文上限时自动触发,或运行 `/compact` | 在合适的工作节点运行 `/midcompact start` |
95
+ | 选择范围 | 一段较早的连续前缀,并按 token 预算保留近期内容 | 一个或多个经过审查的区段;支持不连续区段和 `KEEP` 保留区 |
96
+ | 规划方式 | 支持一次性指令,用于限定生成摘要的重点 | 用户说明范围和保留深度;Agent 讨论取舍并拟定区段与摘要 |
97
+ | 提交约束 | 直接生成压缩检查点 | 先形成草案,再用 TUI 或浏览器审查,最后由用户运行 `/midcompact commit` |
98
+ | 适用场景 | 自动维护上下文、从上下文溢出中恢复 | 清理已经完成的工作阶段,同时保留特定决策原文 |
99
+
100
+ `pi-midcompact` 不会关闭或替代 Pi 的自动压缩;它提供另一条经过人工审查的选择性压缩路径。Pi 内置机制可参阅 [Pi 的 compaction 文档](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/docs/compaction.md)。
101
+
102
+ ## 安装
103
+
104
+ 从 npm 安装:
105
+
106
+ ```bash
107
+ pi install npm:pi-midcompact
108
+ ```
109
+
110
+ 从 GitHub 安装:
111
+
112
+ ```bash
113
+ pi install git:github.com/frostime/pi-midcompact
114
+ ```
115
+
116
+ 安装后重启 Pi,或运行 `/reload`。此扩展适用于 Pi `0.84.x`。
117
+
118
+ ## 使用方法
119
+
120
+ 应在合适的工作节点启动事务:当前阶段已完成到足以概括的程度,且 Pi 处于空闲状态。当前节点会成为冻结的**锚点**。Agent 只针对这个快照拟定方案,之后的规划对话不会意外进入被压缩的工作上下文。
121
+
122
+ ### 1. 设置压缩检查点
123
+
124
+ 运行:
125
+
126
+ ```text
127
+ /midcompact start
128
+ ```
129
+
130
+ Pi 会在创建事务状态前提供三个选项:**Drop**、**Agent direct** 和 **User manual**。Agent direct 进入现有的 inventory-first Agent 流程;User manual 会发送同样的事务说明,但末尾要求 Agent 只确认知悉。Agent 简短回复后,才打开 Selection 工作台;在用户交接前不会开始规划或修改 DraftPlan。用户保存初始 DraftPlan 并关闭界面后,可在准备好时再让 Agent 继续。也可以在命令中直接写明初始重点:
131
+
132
+ ```text
133
+ /midcompact start 压缩前期仓库探索过程,但保留用户需求原文。
134
+ ```
135
+
136
+ ### 2. 与 Agent 讨论压缩方案
137
+
138
+ 直接用自然语言说明目标,例如:
139
+
140
+ ```text
141
+ 压缩前期仓库探索和常规命令输出。
142
+ 保留用户需求、被否决的数据库方案,以及最终验证错误的原文。
143
+ 希望回收约 30% 的陈旧上下文,但不要为了凑精确数字而丢失语义差别。
144
+ ```
145
+
146
+ Agent 会在冻结的会话快照中定位相关内容,提出一个或多个区段,并为每个区段撰写摘要。可以要求它保留某条消息、拆分区段,或重写摘要。
147
+
148
+ ### 3. 审查草案
149
+
150
+ 运行:
151
+
152
+ ```text
153
+ /midcompact review
154
+ ```
155
+
156
+ 在交互模式下,原生 TUI 会把冻结的对话显示为线性时间线。每个条目都会标为 `KEEP`,或标明其所属的拟压缩区段。请检查区段边界,以及将用来替换原文的摘要。
157
+
158
+ 在 RPC、print 或其他没有 TUI 的模式下,请改用可编辑的本地浏览器界面:
159
+
160
+ ```text
161
+ /midcompact review-webui
162
+ ```
163
+
164
+ 需要创建或调整区段与 `KEEP` 保留洞时,使用 Selection:
165
+
166
+ ```text
167
+ /midcompact select
168
+ /midcompact select-webui
169
+ ```
170
+
171
+ TUI 与本地浏览器 Review 界面用于编辑摘要/主题和否决区段。Review 不创建或调整区段边界;边界变化应重新打开 Selection。用户先创建计划后,只需发送普通消息要求 Agent 继续当前 midcompact draft,Agent 会先读取已有计划。
172
+
173
+ ### 4. 提交已审查的压缩
174
+
175
+ 方案确认后,运行:
176
+
177
+ ```text
178
+ /midcompact commit
179
+ ```
180
+
181
+ 这个命令只能由用户执行,Agent 无法自行提交压缩。
182
+
183
+ Pi 会回到锚点,放弃临时规划分支,保存已审查的压缩状态,然后从提交后的分支继续工作。后续模型请求会收到所选旧区段的摘要,而不是原始消息。
184
+
185
+ ### 5. 继续工作或放弃事务
186
+
187
+ 提交后可以继续正常工作。若决定不压缩,运行:
188
+
189
+ ```text
190
+ /midcompact abort
191
+ ```
192
+
193
+ 该命令会回到锚点,丢弃事务,不改变当前生效的上下文。
194
+
195
+ ## 原生 TUI 快捷键
196
+
197
+ 在 `/midcompact review` 中:
198
+
199
+ ```text
200
+ n/p 或 Left/Right 选择拟压缩区段
201
+ Up/Down、j/k 滚动
202
+ PgUp/PgDn 翻页
203
+ x 展开所选区段中的对话原子
204
+ e 编辑所选摘要
205
+ t 编辑所选主题
206
+ d 移除所选区段
207
+ Enter/Esc/q 关闭
208
+ ```
209
+
210
+ ## 命令
211
+
212
+ | 命令 | 作用 |
213
+ | --- | --- |
214
+ | `/midcompact start [instructions]` | 显示 Drop / Agent direct / User manual,并在当前会话树叶节点启动事务。 |
215
+ | `/midcompact select` | 在原生 TUI 中打开 Selection 工作台,编辑区段和 `KEEP`。 |
216
+ | `/midcompact select-webui` | 在本地浏览器中打开 Selection 工作台。 |
217
+ | `/midcompact review` | 在原生 TUI 中审查摘要和主题。 |
218
+ | `/midcompact review-webui` | 在本地浏览器中审查摘要和主题。 |
219
+ | `/midcompact commit` | 提交已审查的草案;只能由用户执行。 |
220
+ | `/midcompact abort` | 放弃事务并回到锚点。 |
221
+ | `/midcompact status` | 显示当前草案,或本分支已提交的压缩状态。 |
222
+
223
+ 扩展只在事务进行期间在 Pi 页脚显示规划状态;提交或放弃后会自动清除。
224
+
225
+ ## 保证与限制
226
+
227
+ - **保留原始历史。** 压缩只改变后续模型请求看到的内容,不改写存储的 Pi 消息。
228
+ - **匹配失败时保留原文。** 若无法精确定位已审查的消息序列,扩展会原样发送历史,而不会删除不确定的内容。
229
+ - **状态只在分支内生效。** 用 `/tree` 回到压缩状态之前的节点会恢复原始历史;回到其后代节点则恢复投影。
230
+ - **必须人工审查。** Agent 可以提出方案,不能执行 `/midcompact commit`。
231
+ - **保护工具调用协议。** 未知、不完整或孤立的工具调用交互不能压缩。
232
+ - **支持重复事务。** 后续事务可以继续压缩新积累的原始上下文;已有摘要保持受保护状态。
233
+ - **与 Pi 原生 `/compact` 的组合仍需更多真实会话验证。** 在完成充分验证前,不应在关键工作中依赖两者混用。
234
+ - **Provider 与扩展互操作性仍需更多真实会话验证。** 非常规消息形态、第三方上下文转换顺序,以及长时间运行的精确消息指纹尚未得到广泛验证。
235
+ - **超长会话尚未完成压力测试。** 审查快照很大、压缩块反复累积时,最终可能需要进一步整合。
236
+ - **浏览器工作台仅在本机开放。** `select-webui` 与 `review-webui` 绑定到 loopback,并与原生 TUI 操作同一份分支内 DraftPlan。
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-midcompact",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Branch-aware mid-context compression for the Pi coding agent",
5
5
  "author": "frostime",
6
6
  "repository": {
@@ -27,11 +27,12 @@
27
27
  "src",
28
28
  "skills",
29
29
  "README.md",
30
+ "README.zh-CN.md",
30
31
  "figures"
31
32
  ],
32
33
  "scripts": {
33
34
  "typecheck": "tsc -p tsconfig.json --noEmit",
34
- "test": "rm -rf .test-dist && tsc -p tsconfig.test.json && node test/install-mocks.mjs && node --test test/core.test.mjs test/runtime.test.mjs",
35
+ "test": "rm -rf .test-dist && tsc -p tsconfig.test.json && node test/install-mocks.mjs && node --test test/core.test.mjs test/runtime-start.test.mjs test/runtime-agent.test.mjs test/runtime-user.test.mjs test/runtime-transaction.test.mjs test/runtime-lock.test.mjs",
35
36
  "typecheck:contract": "tsc -p tsconfig.test.json --noEmit",
36
37
  "pack:check": "npm pack --dry-run"
37
38
  },