@lune_99/pi-compaction 0.0.0-stage → 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,30 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
5
+
6
+ ## [Unreleased]
7
+
8
+ ### Added
9
+
10
+ - **Follow session model**: Add a default summary-model choice that inherits the current session model and effort at the start of each compaction. Selecting a separate model retains independent thinking-level configuration.
11
+ - **Dedicated summary model**: Run manual, threshold and overflow compaction with a separately selected Pi model and thinking level, without changing the session model. Pi's native `compact()` still owns prompts, split turns, previous-summary updates, file operations and checkpoint writing.
12
+ - **Tool history review**: Optionally ask a Pi-registered classifier whether each fragment of an eligible tool result is safe to drop before summarizing. A call and its result are removed only when every fragment meets the drop confidence (default `0.7`); fragments exceeding the classifier window keep their arguments and are replaced with placeholders or preserved, while any other classification failure cancels the compaction.
13
+ - **Explicit cancellation**: Any summary or classification failure returns a cancel result instead of falling back to native compaction. `abortCompaction()`, session switches and leaf changes stop pending requests, and late results can never commit a checkpoint.
14
+ - **Lune settings section**: Configure the summary model, thinking level, classifier, drop confidence and deletable tools in the unified Lune panel with global and project scopes. Interception is on by default; Pi owns provider authentication and model capabilities.
15
+ - **Review notice and checkpoint metadata**: Show one dim single-line notification with the classifier, checked calls, disjoint edit counts and summary-input size. Each checkpoint records the summary model, effective thinking level and review statistics under `details.luneCompaction`.
16
+ - **Embedding API**: `installCompaction` and `createCompactionExtension` accept resolved options from the host instead of reading settings; returning `null` leaves native Pi compaction untouched. `CompactionController.getRun()` returns an isolated snapshot of the current run.
17
+ - **Visual README.** Introduce the extension with feature highlights, npm installation steps and previews rendered from its real TUI components. Regenerate the SVG and PNG assets with `npm run docs:images`.
18
+
19
+ ### Changed
20
+
21
+ - **Published Core dependency.** Require `@lune_99/pi-lune-core@^0.1.0` from npm instead of a sibling checkout. Core remains a mandatory runtime dependency for shared infrastructure and settings.
22
+
23
+ - **Native Settings and Panel composition**: The configured installer binds Core
24
+ Settings and independently registers its Panel through native Pi lifecycle callbacks.
25
+ ResourceScope owns reverse cleanup; compaction cancellation stays plugin-owned.
26
+ Models resolve directly through Pi, while selectors use Core's `/panel` helper.
27
+ Existing settings IDs, policy controls and embedded-options contracts are unchanged.
28
+
29
+ - **Summary enabled by default**: Lune compaction now runs without an explicitly selected summary model and follows the session model and effort. Existing global and project overrides still apply, so select a model to keep summaries separate and turn Lune compaction off to keep Pi's native summary.
30
+ - **Concise review notice**: Collapse the tool-history review notification into a single line with the classifier, checked calls, disjoint edit counts and summary-input size. Drops inside fully removed calls no longer inflate the fragment count, so each entry describes a separate change.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nouvelle-Lune
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,3 +1,69 @@
1
- # Temporary Holding Version
1
+ # Lune Compaction
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm version](https://img.shields.io/npm/v/@lune_99/pi-compaction.svg)](https://www.npmjs.com/package/@lune_99/pi-compaction) [![npm downloads](https://img.shields.io/npm/dw/@lune_99/pi-compaction.svg)](https://www.npmjs.com/package/@lune_99/pi-compaction) [![license](https://img.shields.io/npm/l/@lune_99/pi-compaction.svg)](LICENSE)
4
+
5
+ ![Lune Compaction preview](docs/compaction-settings.png)
6
+
7
+ **A model of your choice for [Pi](https://pi.dev) compaction, with optional tool-history review.**
8
+
9
+ Lune Compaction lets summaries follow your session model or use a separate one. Turn on tool-history review to remove disposable output before summarizing, while Pi keeps its normal compaction workflow and session checkpoints.
10
+
11
+ ## Quick start
12
+
13
+ Install from npm:
14
+
15
+ ```bash
16
+ pi install npm:@lune_99/pi-compaction
17
+ ```
18
+
19
+ Then start Pi normally:
20
+
21
+ ```bash
22
+ pi
23
+ ```
24
+
25
+ Lune compaction is on by default. Run `/compact` as usual, or let Pi compact automatically.
26
+
27
+ ## What it does
28
+
29
+ - **Gives summaries their own model.** Follow the session model and effort, or select a separate summary model with an independent thinking level.
30
+ - **Works with native compaction.** Manual, threshold and overflow compaction keep Pi's handling of previous summaries, split turns and file operations.
31
+ - **Reviews tool output before summarizing.** An optional classifier judges which result fragments are no longer useful. You choose the confidence threshold and which tools may lose their whole call.
32
+ - **Shows what was removed.** A review notice reports the classifier, calls checked, edits and the change in summary-input size.
33
+ - **Keeps configuration close.** Pick models and review options in the Compaction settings panel, with global defaults and project overrides.
34
+ - **Reports failures explicitly.** A failed summary or classification cancels the operation; cancelled or stale work cannot write a checkpoint.
35
+
36
+ ## Compaction settings
37
+
38
+ Open:
39
+
40
+ ```text
41
+ /lune-core-settings compaction
42
+ ```
43
+
44
+ Choose **Follow session model** to use the current model and effort. Selecting a separate **Compaction model** makes **Compaction thinking level** independent.
45
+
46
+ **Jev preprocessing** is off by default. Enable it to review tool history, then choose a Pi classifier, set **Drop confidence** and select **Deletable tools**. A whole call is removed only when its tool is permitted and every result fragment meets the threshold. Summary models and classifiers come from Pi's configured providers.
47
+
48
+ `Ctrl+G` switches global/project scope; `Ctrl+R` removes the selected override. Changes apply to the next compaction.
49
+
50
+ ## Tool-history review
51
+
52
+ An example review notice:
53
+
54
+ ![Lune Compaction review notice](docs/compaction-review.png)
55
+
56
+ The notice reports the size of the messages entering the summary in characters. Review changes that input; the on-disk tool transcript stays intact.
57
+
58
+ ## Development
59
+
60
+ ```bash
61
+ npm install
62
+ npm test
63
+ npm run typecheck
64
+ npm run docs:images # regenerate docs/*.svg + docs/*.png (needs rsvg-convert)
65
+ ```
66
+
67
+ ## License
68
+
69
+ MIT
Binary file
@@ -0,0 +1,9 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="946.4399999999999" height="108.8" viewBox="0 0 946.4399999999999 108.8" font-family="Menlo, FiraCode Nerd Font Mono, monospace" font-size="14" xml:space="preserve" role="img" aria-label="pi — an illustrative tool-review notice">
2
+ <title>pi — an illustrative tool-review notice</title>
3
+ <rect width="946.4399999999999" height="108.8" rx="10" fill="#181a1b"/>
4
+ <rect width="946.4399999999999" height="34" rx="10" fill="#768186" opacity="0.25"/>
5
+ <circle cx="24" cy="17" r="5" fill="#ff5f57"/><circle cx="42" cy="17" r="5" fill="#febc2e"/><circle cx="60" cy="17" r="5" fill="#28c840"/>
6
+ <text x="80" y="22" fill="#9da5a9" font-size="13">pi — an illustrative tool-review notice</text>
7
+ <text x="18.00" y="65.97" fill="#dee0e1" textLength="8.43" lengthAdjust="spacingAndGlyphs"> </text><text x="26.43" y="65.97" fill="#7e888e" textLength="902.01" lengthAdjust="spacingAndGlyphs">◇ Tool review · example/classifier · 12 calls checked: 3 calls deleted · 1 result fragment deleted · </text>
8
+ <text x="18.00" y="85.37" fill="#dee0e1" textLength="8.43" lengthAdjust="spacingAndGlyphs"> </text><text x="26.43" y="85.37" fill="#7e888e" textLength="118.02" lengthAdjust="spacingAndGlyphs">48k→31k (-35%)</text><text x="144.45" y="85.37" fill="#dee0e1" textLength="783.99" lengthAdjust="spacingAndGlyphs"> </text>
9
+ </svg>
Binary file
@@ -0,0 +1,24 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="929.5799999999999" height="399.79999999999995" viewBox="0 0 929.5799999999999 399.79999999999995" font-family="Menlo, FiraCode Nerd Font Mono, monospace" font-size="14" xml:space="preserve" role="img" aria-label="pi — choose how your next compaction runs">
2
+ <title>pi — choose how your next compaction runs</title>
3
+ <rect width="929.5799999999999" height="399.79999999999995" rx="10" fill="#181a1b"/>
4
+ <rect width="929.5799999999999" height="34" rx="10" fill="#768186" opacity="0.25"/>
5
+ <circle cx="24" cy="17" r="5" fill="#ff5f57"/><circle cx="42" cy="17" r="5" fill="#febc2e"/><circle cx="60" cy="17" r="5" fill="#28c840"/>
6
+ <text x="80" y="22" fill="#9da5a9" font-size="13">pi — choose how your next compaction runs</text>
7
+ <text x="18.00" y="65.97" fill="#7e888e" textLength="893.58" lengthAdjust="spacingAndGlyphs">──────────────────────────────────────────────────────────────────────────────────────────────────────────</text>
8
+ <text x="18.00" y="85.37" fill="#a798d7" textLength="185.46" lengthAdjust="spacingAndGlyphs">Lune settings · global</text>
9
+ <text x="18.00" y="104.77" fill="#a798d7" textLength="84.30" lengthAdjust="spacingAndGlyphs">Compaction</text>
10
+ <text x="18.00" y="124.17" fill="#7e888e" textLength="893.58" lengthAdjust="spacingAndGlyphs">──────────────────────────────────────────────────────────────────────────────────────────────────────────</text>
11
+ <text x="18.00" y="143.57" fill="#a798d7" textLength="303.48" lengthAdjust="spacingAndGlyphs">→ Lune compaction on</text>
12
+ <text x="18.00" y="162.97" fill="#dee0e1" textLength="151.74" lengthAdjust="spacingAndGlyphs"> Compaction model</text><text x="169.74" y="162.97" fill="#9da5a9" textLength="303.48" lengthAdjust="spacingAndGlyphs"> Follow session model</text>
13
+ <text x="18.00" y="182.37" fill="#dee0e1" textLength="227.61" lengthAdjust="spacingAndGlyphs"> Compaction thinking level</text><text x="245.61" y="182.37" fill="#9da5a9" textLength="311.91" lengthAdjust="spacingAndGlyphs"> Follow session effort · medium</text>
14
+ <text x="18.00" y="201.77" fill="#dee0e1" textLength="160.17" lengthAdjust="spacingAndGlyphs"> Jev preprocessing</text><text x="178.17" y="201.77" fill="#9da5a9" textLength="151.74" lengthAdjust="spacingAndGlyphs"> off</text>
15
+ <text x="18.00" y="221.17" fill="#dee0e1" textLength="151.74" lengthAdjust="spacingAndGlyphs"> Classifier model</text><text x="169.74" y="221.17" fill="#9da5a9" textLength="438.36" lengthAdjust="spacingAndGlyphs"> Automatic · available Pi classifiers</text>
16
+ <text x="18.00" y="240.57" fill="#dee0e1" textLength="143.31" lengthAdjust="spacingAndGlyphs"> Drop confidence</text><text x="161.31" y="240.57" fill="#9da5a9" textLength="168.60" lengthAdjust="spacingAndGlyphs"> 0.7</text>
17
+ <text x="18.00" y="259.97" fill="#dee0e1" textLength="160.17" lengthAdjust="spacingAndGlyphs"> Deletable tools →</text><text x="178.17" y="259.97" fill="#9da5a9" textLength="210.75" lengthAdjust="spacingAndGlyphs"> 9 selected</text>
18
+
19
+ <text x="18.00" y="298.77" fill="#9da5a9" textLength="893.58" lengthAdjust="spacingAndGlyphs">Enabled by default. Follow the session model and effort, or select a separate summary model. Changes apply</text>
20
+ <text x="18.00" y="318.17" fill="#9da5a9" textLength="185.46" lengthAdjust="spacingAndGlyphs">on the next operation.</text>
21
+ <text x="18.00" y="337.57" fill="#7e888e" textLength="893.58" lengthAdjust="spacingAndGlyphs">──────────────────────────────────────────────────────────────────────────────────────────────────────────</text>
22
+ <text x="18.00" y="356.97" fill="#7e888e" textLength="876.72" lengthAdjust="spacingAndGlyphs">↑↓ select · Enter change · Tab section · Ctrl+G scope · Ctrl+S reload section · Ctrl+R reset · Esc close</text>
23
+ <text x="18.00" y="376.37" fill="#7e888e" textLength="893.58" lengthAdjust="spacingAndGlyphs">──────────────────────────────────────────────────────────────────────────────────────────────────────────</text>
24
+ </svg>
package/docs/design.md ADDED
@@ -0,0 +1,444 @@
1
+ # pi-compaction 设计草案
2
+
3
+ 日期:2026-10-07
4
+ 状态:讨论稿;尚未实现插件、安装依赖或修改 Pi 配置。
5
+ 提交:本docs应该被加入gitignore 和 npm ignore,禁止提交
6
+
7
+ ## 1. 已确认的目标与边界
8
+
9
+ 新项目位于 `/Users/sy/.pi/agent/local-extensions/pi-compaction`,沿用 Lune 插件的入口、业务模块、命令、TUI 和测试分层。
10
+
11
+ 本次完整功能包括:
12
+
13
+ 1. 使用单独选择的模型执行 compact,不改变主对话模型。
14
+ 2. 模型来自 Pi 当前注册表,同时支持全部可用模型和 scoped models;Core 设置面板完成后,按 Pi 的交互规则通过 Tab 切换范围。
15
+ 3. 可选在 compact 前使用 Jev 压缩待摘要的工具结果,允许删除无用的工具调用及对应结果。
16
+ 4. 给 Jev 提供判断所需的任务背景、实际结果内容和关联证据。
17
+ 5. 保留 Pi 的原生摘要流程、历史摘要合并、近期消息边界与会话写入机制。
18
+
19
+ Jev **只在 compact 前介入**,不在每轮主模型请求前压缩上下文,也不改写工具执行时的结果。
20
+
21
+ 统一 Setting Manager 由 `pi-lune-core` 制作。本插件现在只设计业务配置契约及未来接入位置,不实现设置面板、独立配置文件、旧配置迁移或另一套 Setting Manager。设置完成前如何给业务配置赋值,仍需讨论。
22
+
23
+ ## 2. 对参考项目的判断
24
+
25
+ 参考:`pi-jev-compaction` 0.1.2,以及它依赖的 `fast-jev-compaction` 0.4.0。
26
+
27
+ ### 值得保留的部分
28
+
29
+ - 挂接 `session_before_compact`,覆盖手动 compact 和自动 compact。
30
+ - 将决策映射回原生消息,而不是用简化 transcript 重建 Pi 消息。
31
+ - 对图片、配对歧义和跨边界工具调用采取明确保护。
32
+ - 将 Pi 的取消信号传给网络请求。
33
+
34
+ ### 需要重新设计的部分
35
+
36
+ | 现状 | 问题 | 新设计 |
37
+ | --- | --- | --- |
38
+ | 只修改待摘要数组,再交给 Pi 默认 compact | 摘要仍使用 Pi 默认选择的模型 | 扩展调用公开 `compact()`,返回自定义 `CompactionResult` |
39
+ | 两段待摘要消息分别构造 Jev state | 看不到另一段、保留区和完整任务背景 | 统一构造只读判断背景,分别应用区域内变更 |
40
+ | 上游只给结果附上成功/失败、长度;完全省略结果正文 | Jev 无法知道实际结果中哪些信息重要 | 发送候选结果原文片段和相邻内容 |
41
+ | goal 取最后三个被转换成 user 的文本,每段最多 500 字符 | 可能把 custom、bashExecution、旧摘要当成用户目标;也缺少后续用户请求 | 保留真实角色、来源和时间顺序;从会话投影读取任务证据 |
42
+ | 工具参数最多 1000 字符,预算不足时进一步截短 | 长命令、补丁或路径可能失去决定性信息 | 参数属于候选调用的必要背景;不得截去关键字段后继续判定 |
43
+ | 判断“不需要完整结果”后,只保留前 300 字符 | 关键内容可能在中间或结尾 | 按原文片段选择,保持顺序与来源位置 |
44
+ | “可重新运行工具”被当成通用前提 | 旧文件版本、瞬时状态和有副作用的命令不一定可重现 | 不以可重跑作为删除依据 |
45
+ | 首条和最后六条消息自动 pinned | 消息条数不能表达任务依赖,且 Pi 已有原生保留区 | 保护依据来自区域边界、消息类型与具体证据 |
46
+ | Jev 失败后继续默认压缩,部分错误细节被吞掉 | 与本项目禁止兜底的规则冲突 | 报告具体失败并取消本次 compact |
47
+
48
+ 参考项目主要是在降低**摘要请求的输入量**。这不同于直接缩短主模型每轮输入,也不能把预处理节省量当成最终会话压缩率。
49
+
50
+ ## 3. 总体架构
51
+
52
+ ```text
53
+ Pi 手动 /compact / 自动 threshold / overflow
54
+ │
55
+ session_before_compact
56
+ │
57
+ 冻结本次配置、模型与会话身份
58
+ │
59
+ 校验摘要模型、规划请求预算
60
+ │
61
+ Jev 启用?
62
+ ├─ 否:原始 preparation 的独立副本
63
+ └─ 是:构造任务背景和候选工具索引
64
+ → 片段判断
65
+ → 整调用删除判断
66
+ → 校验并重组消息副本
67
+ │
68
+ 校验实际摘要输入预算
69
+ │
70
+ Pi 公开 compact(preparation, selectedModel, …)
71
+ │
72
+ 返回 { compaction: result }
73
+ │
74
+ Pi 写入 CompactionEntry、更新上下文
75
+
76
+ 任一步骤失败 → 报告错误 → 返回 { cancel: true }
77
+ 用户取消 → 终止请求 → 返回 { cancel: true }
78
+ ```
79
+
80
+ 职责划分:
81
+
82
+ - **Pi**:触发时机、cut point、保留区、会话树、写入 compaction entry、overflow 后的继续逻辑。
83
+ - **pi-compaction**:摘要模型选择、Jev 预处理、请求预算与运行记录。
84
+ - **Jev**:对给定原文和背景回答具体判断问题。
85
+ - **摘要模型**:生成最终检查点摘要;继续复用 Pi 的原生摘要提示词和合并流程。
86
+ - **Core Setting Manager**:未来提供配置解析、作用域、持久化和设置面板。
87
+
88
+ 不重新计算 `firstKeptEntryId`,不修改 `tokensBefore`,不在插件内写入正式 CompactionEntry。
89
+
90
+ ## 4. 指定模型执行 compact
91
+
92
+ ### 模型来源与列表
93
+
94
+ 摘要模型列表使用 `ctx.modelRegistry.getAvailable()`;scoped 范围使用 `ctx.scopedModels`,沿用其模型与 thinking 元数据。列表不能硬编码 provider/model,也不能从插件自己的配置生成目录。
95
+
96
+ 未来选择器与 Pi 对齐:搜索、当前选择标记、范围切换;存在 scoped models 时初始显示 scoped,可通过 Tab 切换 all/scoped。没有配置 scoped models 时,按 Pi 的“未限定范围”语义显示全部可用模型,不制造一个空的限制范围。
97
+
98
+ `provider + modelId` 是选择身份,显示名称只用于 UI。选择范围控制列表展示;已选择模型不能因为切换列表范围而自动变成另一模型。
99
+
100
+ 设置更新后的模型在下一次 compact 生效。本次运行冻结配置,不能一段摘要用旧模型、另一段用新模型。
101
+
102
+ ### 调用路径
103
+
104
+ 在 `session_before_compact` 内调用 Pi 导出的公开 `compact()`,并返回 `{ compaction: result }`。不能在这个钩子里调用 `ctx.compact()`,否则会再次触发同一条压缩链。
105
+
106
+ 请求通过 `ctx.modelRegistry.streamSimple()` 适配为原生 `compact()` 的 `streamFn`,由 Pi 注册的 provider 处理认证、OAuth、自定义请求选项和 endpoint。不得只使用裸 `pi-ai` 的全局请求接口,导致自定义 provider 配置丢失。
107
+
108
+ 保持 Pi 的:
109
+
110
+ - `previousSummary` 更新逻辑;
111
+ - `isSplitTurn` 和 turn-prefix 摘要;
112
+ - 文件操作记录及 readFiles/modifiedFiles;
113
+ - `customInstructions` 的原生传递行为;
114
+ - 摘要 usage 汇总;
115
+ - 单次摘要的缓存策略。
116
+
117
+ Pi 当前 split-turn 流程仅向历史摘要传递 `customInstructions`,turn-prefix 使用专门提示词。新插件保留这一行为,不在本次顺带改变提示词语义。
118
+
119
+ ### 必须显式处理的边界
120
+
121
+ - 模型不在注册表、认证失败或 provider 请求失败:取消压缩,不改用主模型。
122
+ - 选用较小窗口的摘要模型:在 stream 适配入口校验**实际序列化摘要请求**,不能拿主模型的 `tokensBefore` 作输入长度,也不能假定选中就一定装得下。启用 Jev 时,最终校验应基于预处理之后的输入,不因为原始输入过大而提前拒绝。
123
+ - 超出摘要模型窗口:报告输入估计、输出预算及模型窗口;用户改选模型或调整策略。此草案不引入另一条分层生成摘要链。
124
+ - 输出到达长度上限、为空或出现 tool call:不提交检查点。
125
+ - 独立 thinking level:按所选摘要模型的能力验证;不直接继承主模型的值,也不把非法值改成默认值。
126
+ - 列表中的 virtual model:还需验证注册表公开请求路径能否按该虚拟模型的 direct 路由执行。不能把虚拟模型对象直接当作物理 provider 模型;未验证前不得承诺与 Pi 内部 summarization routing 完全一致。
127
+
128
+ ## 5. Jev 的角色:选择原文,而非生成摘要
129
+
130
+ Jev 返回 choice、score、bool 概率,不生成新的摘要正文。它适合判断哪些现有证据应进入摘要模型。官方建议将复杂判断拆成具体问题,再由代码组合结果。[官方介绍](https://docs.typesafe.ai/introduction)
131
+
132
+ 因此预处理分成两层:
133
+
134
+ 1. **结果片段选择**:留下任务仍需要的原文内容。
135
+ 2. **整调用删除**:结果已经没有必要信息时,进一步判断调用发生过这一事实是否仍需保留。
136
+
137
+ 只要结果还有保留片段,就不得删除对应调用。写操作或命令产生的副作用不能仅凭“输出没有用”一起抹去。
138
+
139
+ ### 5.1 Jev 模型与认证
140
+ 优先使用lune settings中的注册的base url, apikey , 以及模型,
141
+
142
+ 可以复用 Pi 的 classifier 模型注册表,但是选择会被lunesettings中存在的设置覆盖:
143
+
144
+ - `getAvailableOfType("classifier")` 获取可用 classifier。
145
+ - 只展示被本插件明确支持的 Jev 模型,不把所有 classifier 当成 Jev。
146
+ - `findOfType()` 解析选择。
147
+ - `modelRegistry.classify()` 负责请求与认证。
148
+
149
+ 支持 Pi 已注册的 TypeSafe、OpenRouter Jev;实际模型 ID 以当前目录为准,不复制参考项目的固定版本预设。用户自定义 Jev 模型也应先在 Pi 中注册,并提供明确的能力和预算约束。
150
+
151
+ 摘要模型与 Jev 模型是两个独立选择,分别属于 chat 和 classifier。插件不保存或迁移参考项目的 API key。
152
+
153
+ Pi `classify()` 以 `stopReason` 表达失败,不能只等待 Promise rejection。需要检查 `stopReason`、每个必需 answer、类型和概率范围;缺失结果或非法数值是失败,不默认当成 keep。
154
+
155
+ ### 5.2 任务背景:让判断依据可追溯
156
+
157
+ 以 Pi 的**当前有效会话投影**为依据,遵守已有 compaction 与 context edits;不能扫描整个 JSONL 后把已省略的消息或其他分支重新塞回来。
158
+
159
+ 统一背景包含以下证据,不调用另一模型编造“任务状态”:
160
+
161
+ | 数据 | 用途与来源 |
162
+ | --- | --- |
163
+ | 上一次摘要 | `preparation.previousSummary`,提供累计任务背景 |
164
+ | 原始请求及用户补充 | 真实 user 消息;保留角色、entry ID、先后顺序 |
165
+ | 本次 compact 关注点 | `event.customInstructions` |
166
+ | 候选所在回合 | 该工具调用前后的用户请求、助手正文与邻近调用 |
167
+ | 最近保留区 | 从会话投影及 `firstKeptEntryId` 确定,只读;让 Jev 知道后续正在做什么 |
168
+ | 后续引用证据 | 后续明确引用的路径、符号、错误文本、任务/job ID 等,记录匹配来源 |
169
+ | 工具语义 | 工具名称、实际参数、可获得的 description/schema;历史定义不可获得时标记缺失 |
170
+ | 压缩原因 | manual / threshold / overflow;作为背景,不改变内容保护契约 |
171
+
172
+ 系统提示词中的相关任务约束可作为背景,但不能把整份提示词、全部工具 schema 和无关历史无差别发送。对代码匹配到的引用只声称“字面匹配”,不伪装成完整的语义依赖图。
173
+
174
+ 角色不可混淆:custom、bashExecution、compactionSummary、branchSummary 不转换成用户目标。thinking 原样保留在本地消息中,不作为 Jev 默认背景;助手正文和工具内容具有各自的来源标签。
175
+
176
+ 每批 state 由**共同任务锚点 + 候选所在局部回合 + 当前待评估的真实片段**组成。历史摘要是背景,不能因为它提到某件事,就认为它已经覆盖候选结果的每个细节。
177
+
178
+ Jev 官方明确指出,无关细节过多会降低判断准确度。因此目标是提供充分、相关的证据,而不是把全部历史塞满窗口。[已知限制](https://docs.typesafe.ai/model-jaggedness/jev-1.13)
179
+
180
+ ### 5.3 候选配对与保护规则
181
+
182
+ 索引应在本次两段摘要输入和只读保留区中统一建立,识别重复 ID、跨区域引用及调用/结果来源;实际改动严格限制在本次待摘要区域。
183
+
184
+ 推荐规则如下,保护原因计入统计:
185
+
186
+ - 调用与结果配对唯一、顺序合法、名称一致,才能成为候选。
187
+ - 配对跨 `messagesToSummarize` / `turnPrefixMessages` / 保留区边界时,不删除或压缩它。
188
+ - 包含图片或其他非文本结果:完整保留,不将媒体改成普通文本。
189
+ - 未配对、重复 ID 或结构异常:不作为可删候选,完整保留并记录具体原因;如异常使区域重组无法保证正确,终止本次压缩。
190
+ - 用户消息、助手正文、thinking 和非候选消息不改写。
191
+ - 工具结果 details、isError、timestamp 等非文本字段不丢失。
192
+ - 失败结果推荐完整保留,避免预处理削掉诊断证据;这是明确的候选策略,不是请求失败后的兜底。
193
+ - 后续明确引用的原文片段不能删除。
194
+ - 未获用户整调用删除许可的工具保留调用事实;bash、write、edit 等工具默认没有该许可。工具名单由用户选择,不根据名称或 annotations 推断历史副作用。
195
+
196
+ 可以压缩这些工具的冗余结果,但整调用删除还必须通过名单许可、嵌套调用完整性和独立的 classifier 判断。
197
+
198
+ ### 5.4 原文片段划分
199
+
200
+ 为每个片段建立稳定身份:区域、entry/message、toolCallId、content block、起止位置。位置与字符统计由代码计算。字符串位置统一使用 UTF-16 offset,并在切分时避免断开 Unicode surrogate pair;行数、字节数与字符位置不能混用。
201
+
202
+ 划分优先使用真实结构:日志段落、完整 stack trace、diff hunk、带路径和行号的搜索记录、代码区块或 JSON 子结构。没有可识别结构的文本按行形成有上限的片段;超长单行需要显式位置切分,不丢掉后半段。
203
+
204
+ 不能为了识别更多格式引入大量脆弱解析器。普通按行划分本身就是支持的输入形式;具体格式的结构解析器需要各自的明确契约和样例验证。
205
+
206
+ 每个候选片段的 Jev 输入包含:
207
+
208
+ - 原文正文,而非长度说明;
209
+ - 所属工具的名称与必要参数;
210
+ - 所属结果的状态和位置;
211
+ - 邻接片段或结构标题,防止单独一行失去含义;
212
+ - 任务锚点、局部回合与后续引用证据。
213
+
214
+ 相邻上下文只能供判断,不能被当成当前片段的正文重复重组。
215
+
216
+ ### 5.5 问题设计和决策规则
217
+
218
+ 不沿用“保留调用/保留完整输出”两个宽泛问题。每个片段分别判断:
219
+
220
+ 1. 是否包含当前任务或摘要关注点仍需要的信息?
221
+ 2. 是否包含尚未被其他明确证据覆盖的决定、事实或操作结果?
222
+ 3. 是否包含继续工作所需的未解决问题或诊断信息?
223
+
224
+ 使用 Pi 的 `bool` 问题,并写明 true/false 的边界。问题的 `instructions` 必须显式指向 state 中的候选 ID/字段;不能假定 answer key 自身会被模型理解。该要求来自 [System One API 说明](https://docs.typesafe.ai/api)。
225
+
226
+ 示意:
227
+
228
+ ```text
229
+ Does the text in candidates["history:tool-17:block-0:chunk-3"]
230
+ contain information needed to continue the user request shown in taskContext?
231
+
232
+ true: The exact text supplies a required fact, identifier, constraint or
233
+ diagnostic detail that is not explicitly available in the cited evidence.
234
+ false: The text is irrelevant to that request or is fully duplicated by the
235
+ explicitly cited evidence. Being possible to rerun a tool is insufficient.
236
+ ```
237
+
238
+ 删除门槛需要用代表性样本校准。讨论起点是:仅当三个保留概率均不高于 0.05,且没有命中保护规则时,才删除片段;其他有效判断明确属于 keep。这里的 0.05 是**待验证策略**,不是已证明的安全阈值。
239
+
240
+ 对结果已无保留片段、且允许整调用删除的候选,再判断“知道这次调用发生过及其参数,对后续任务是否仍有必要”。输入包括操作原文、局部对话、结果片段决策和直接关联证据。只有该保留概率也低于删除门槛,才同时删除调用与对应结果。
241
+
242
+ 不要求 Jev 写自然语言理由。审计记录保留问题版本、概率、保护规则和证据来源,不能用代码生成的标签冒充模型推理。`requestBudget` 记录本次可用窗口,`budgetFallbacks` 记录未分类候选、阶段、估算量及占位/保留调用动作;checkpoint 分开统计占位片段与模型判定删除的片段。
243
+
244
+ ### 5.6 预算、分批和一致性
245
+
246
+ Pi `ClassifierModel` 只提供 `contextWindow`,插件以其 90% 作为可用请求预算。完整 JSON 的 state、questions、instructions、criteria 与序列化开销一起使用 Pi `estimateTokens()` 估算;不再按 API 名称施加固定的 24k 单问题或 64k 总请求限制,也不把估算当成实际 tokenizer。
247
+
248
+ 分批算法先合并能装入窗口的候选;同一候选的多个问题装不下时,按问题拆分请求。每个问题保留对应候选的完整必需 state,问题 ID 在所有请求中只出现一次。
249
+
250
+ 单个问题仍超预算时,缩减辅助上下文:移除片段邻居、当前工具描述与 schema、局部辅助对话、保留区进展及 custom/分支辅助证据,显式标记省略来源。真实用户请求、历史摘要、custom instructions、调用参数和结果 metadata 保留完整;问题要求在剩余证据不足时保留候选。若正文仍装不下,递归切分原文,保持 UTF-16 连续覆盖、CRLF 和 surrogate pair 边界,并重新执行引用保护。
251
+
252
+ 必需背景或最小片段仍装不下时,对未保护的工具结果片段生成带原始范围和超预算原因的 `placeholder` 决策,继续处理其他候选。占位决策没有模型概率,不视为模型批准删除;包含占位的调用不进入整调用删除阶段。整调用判断超预算时保留原调用与结果外壳,并记录 `keep-call`,不改写参数或 metadata。
253
+
254
+ 分批采用有上限的并发;第一批错误取消其他未完成请求。具体并发数是运行策略;Jev 和摘要均不设置 deadline,统一跟随 Pi 的 `abortCompaction()` 取消信号。
255
+
256
+ 全部决策完成、所有 ID 和位置校验通过后,才构造最终消息副本。任何批次失败、用户取消或会话身份变化,都不提交部分结果。
257
+
258
+ ### 5.7 重组结果
259
+
260
+ - 保留片段按原顺序、原文字节/位置重组,不改写代码、路径或错误内容。
261
+ - 间隔插入明确的省略标记,记录删除的行/字符范围;超预算占位采用独立标记,说明该内容未经分类,不与模型判定的省略合并。
262
+ - 调用需要保留但结果正文已全部删除时,保留原生 toolResult 外壳及明确的省略说明;不能制造工具配对缺口。
263
+ - 整调用删除只移除对应 toolCall block 和 toolResult;同一助手消息中的正文、thinking 与其他调用继续保留。
264
+ - 摘要输入的区域边界不合并;`fileOps` 沿用预处理之前的原生记录。
265
+ - 结果内容采用不可变重组。未改动的消息和 metadata 保持原样。
266
+
267
+ 这一步不修改会话历史。正式会话仅在最终摘要成功后由 Pi 增加 CompactionEntry。
268
+
269
+ ## 6. 配置契约与 Core 接入
270
+
271
+ 设置由 Core SettingsManager 管理全局/项目作用域。`version: 2` 仅用于持久化迁移;UI 展示独立摘要模型、thinking、预处理开关、classifier、删除阈值和工具选择子菜单。
272
+
273
+ ```ts
274
+ interface CompactionOptions {
275
+ summaryModel: { provider: string; id: string };
276
+ summaryThinkingLevel: ModelThinkingLevel;
277
+ jev: { enabled: false } | { enabled: true; model: { provider: string; id: string } | null };
278
+ policy: { deleteThreshold: number; deletableTools: readonly string[] };
279
+ }
280
+ ```
281
+
282
+ classifier 的 null 表示每次执行从 Pi 可用集合中选择第一项;固定选择必须仍然可用。模型能力与认证由 Pi Registry 管理,自定义模型通过 extension provider registration 提供。插件不再保存 API key、base URL 或 context tokens。
283
+
284
+ `CompactionPolicy` 只保存用户意图。安全余量、chunk 初始上限、自适应切分、并发和 batching 都是实现参数;请求容量来自 Pi classifier 的 `contextWindow`。Core 的共享选择器支持异步 typed availability 与数组多选,插件负责具体策略含义。
285
+
286
+ 工具列表在打开子菜单时通过 `pi.getAllTools()` 动态发现,持久化 key 是 transcript 使用的 `tool.name`。新工具默认不勾选;annotation 只做提示。已保存但未注册的工具显示为 Unavailable,保留选择直到用户明确取消。`indexTools()` 继续仅按用户名单与嵌套调用完整性判断整调用删除资格。
287
+
288
+ ## 7. UI 与运行记录
289
+
290
+ 交互展示建议沿用 Lune Dock 协议,同时必须包含为安装lune Dock时的展示样式:插件提供单行 base/detail/full 完整快照,拥有自己的渲染、颜色和详情面板。
291
+
292
+ - base:`Compact` 及运行状态。
293
+ - detail:所选摘要模型、Jev 开关或执行阶段。
294
+ - full:阶段、批次进度、已评估结果数与预处理节省估计。
295
+ - activate:打开本插件运行详情;统一配置入口由 Core 面板负责。
296
+
297
+ 任务阶段:准备、Jev 片段判断、整调用判断、摘要生成、等待 Pi 确认、完成/失败/取消。生成摘要返回前不能显示“已完成”;最终以 `session_compact` 确认正式提交。
298
+
299
+ 复杂任务显示批次完成数与阶段,避免只有一个无信息的 spinner。这是 Pi TUI 的实时进度,不适用 Python tqdm。
300
+
301
+ 运行记录建议包含:触发原因、模型身份、策略版本、保护/候选数、片段删除数、整调用删除数、各阶段耗时、Jev usage、摘要 usage、预处理前后输入估计、提交状态和完整错误链。
302
+
303
+ “Jev 预处理节省”与“最终会话压缩”分别展示;缺少实际 token usage 时明确标为估计。总成本只有所有请求均提供完整计费信息时才能显示确定数值。
304
+
305
+ 成功提交后可把不含正文和凭证的简要统计放入 `CompactionEntry.details.luneCompaction`,保留原生顶层 `readFiles`、`modifiedFiles`。完整原文和逐片段决策默认仅保存在本次运行内存里;磁盘审计导出应是用户显式操作。
306
+
307
+ Dock 展示和设置接入均属于草案,不能让 UI 辅助故障导致已经提交的摘要被再次生成。
308
+
309
+ ## 8. 失败、取消与生命周期
310
+
311
+ 插件边界处理错误的目的只有两个:报告真实原因,阻止默认压缩继续执行。不得添加自动改模型、关闭 Jev、忽略坏 answer 或沿用原始输入继续生成摘要等兜底。
312
+
313
+ Pi 当前扩展 runner 会捕获 handler 的异常,因此**只 throw 不足以实现严格失败**。需要在 handler 边界保留错误链、向 TUI 或非交互错误通道报告,并返回 `{ cancel: true }`。
314
+
315
+ 宿主的该结果仅能表达 cancel;Pi 后续可能把此情况记录为 cancelled/aborted,而不是携带 Jev 原始错误的 failed。原始错误必须由插件自己的运行记录与通知保留,不能宣称宿主会自动保存它。
316
+
317
+ 关联取消信号覆盖 Jev 和摘要请求。用户取消不显示成 provider 故障;timeout、401、429、网络失败及 answer 无效分别保留原因。取消之后到达的响应不再参与重组。
318
+
319
+ 运行绑定 session ID、leaf ID 和生命周期 generation。session_shutdown、切换/分叉、reload 后释放 UI 订阅与运行记录引用,禁止旧任务更新新会话。
320
+
321
+ 插件不额外实现自动重启或跨模型重试。Pi/provider 原生的网络重试应单独记录,后续实现需确认如何取得并传递宿主 retry policy;不能声称公开扩展 context 已提供该配置。
322
+
323
+ 同一会话应只启用一个返回自定义 compaction 的扩展;迁移时停用参考项目。Pi 当前 before-hook 成功结果存在“后一个覆盖前一个”的行为,公开接口不能可靠检测其他扩展是否也注册了同一 handler,不能承诺自动解决所有冲突。
324
+
325
+ ## 9. 建议的代码结构
326
+
327
+ ```text
328
+ pi-compaction/
329
+ ├── src/
330
+ │ ├── index.ts
331
+ │ ├── core/
332
+ │ │ ├── compaction-controller.ts
333
+ │ │ ├── compaction-types.ts
334
+ │ │ ├── compaction-policy.ts
335
+ │ │ └── compaction-run.ts
336
+ │ ├── models/
337
+ │ │ ├── model-catalog.ts
338
+ │ │ └── summary-stream.ts
339
+ │ ├── jev/
340
+ │ │ ├── task-context.ts
341
+ │ │ ├── tool-index.ts
342
+ │ │ ├── result-chunks.ts
343
+ │ │ ├── request-planner.ts
344
+ │ │ ├── questions.ts
345
+ │ │ ├── decisions.ts
346
+ │ │ └── apply-decisions.ts
347
+ │ ├── commands/
348
+ │ │ └── compaction.ts
349
+ │ └── tui/
350
+ │ ├── compaction-dock-contribution.ts
351
+ │ └── panel/
352
+ │ ├── compaction-panel.ts
353
+ │ └── compaction-panel-renderer.ts
354
+ ├── test/
355
+ │ ├── unit/
356
+ │ ├── integration/
357
+ │ ├── fixtures/
358
+ │ └── tui/
359
+ ├── docs/design.md
360
+ ├── package.json
361
+ ├── tsconfig.json
362
+ ├── README.md
363
+ └── LICENSE
364
+ ```
365
+
366
+ `index.ts` 只组装和注册生命周期;controller 管运行状态;Jev 模块尽量使用可单独验证的数据变换;TUI 不负责网络和摘要业务。
367
+
368
+ 建议沿用现有 Lune 的 TypeScript 源入口和 Node 内置测试组织。未来 Settings 接入层在 Core 契约确定后加入,业务模块不依赖其未完成 API。
369
+
370
+ 不把 `fast-jev-compaction` 作为决策依赖:它的 state、问题、截断和失败策略正是本次需要替换的部分。若后续复用参考项目的代码片段,再按 MIT 要求保留对应署名与许可证。
371
+
372
+ ## 10. 验证与验收
373
+
374
+ ### 行为验证
375
+
376
+ - model 列表包含 Pi 自定义模型,all/scoped 与 Tab 切换语义一致。
377
+ - 指定摘要模型真正执行请求;主模型、thinking 与模型选择历史不被改变。
378
+ - 手动、threshold、overflow 均走同一预处理和摘要链。
379
+ - split turn、previousSummary、customInstructions、fileOps 与 usage 均保持原生语义。
380
+ - 配对歧义、跨区域配对、混合 assistant block、媒体及错误结果遵守保护契约。
381
+ - 每个删除片段都曾以真实正文进入合法请求;中部/尾部关键信息可保留。
382
+ - 多批判断保持来源位置,任意一批失败都不会提交部分处理结果。
383
+ - Jev 或摘要失败、空摘要、长度终止、认证失败、预算超限不会触发主模型默认压缩。
384
+ - 取消、session 切换、reload 和迟到响应不会修改其他会话。
385
+ - 通过真实 Pi 宿主验证成功写入及失败不写入,不只 mock handler。
386
+
387
+ ### Jev 小批量质量验证
388
+
389
+ 必须使用代表性的中日文/英文任务,以及 read、搜索、diff、测试日志、shell 和自定义工具输出。样例应包含任务改口、旧文件版本、尾部诊断、已解决错误、重复输出、瞬时状态和诱导分类的工具文本。
390
+
391
+ 对照原始输入、参考项目策略和新策略,检查必要证据召回、错误删除率、实际输入节省、请求数和耗时。不能只看删除比例,也不能用“模型按 mock 分数执行了删除”证明 Jev 判断正确。
392
+
393
+ 中日文质量需要单独验证;Jev 官方说明其主要训练语言为英文。[模型规格](https://docs.typesafe.ai/models)
394
+
395
+ 真实付费请求的预算和范围在执行前确认,本轮设计不进行服务调用。
396
+
397
+ ### 本轮已完成的验证
398
+
399
+ - 阅读了参考项目、上游决策库、Lune Shell/Question/Dock 结构和 Core 当前设置类型。
400
+ - 对照了本地 Pi SDK 1.0.0 与实际 CLI 1.0.4 的公开模型和压缩接口。
401
+ - 在 Pi 1.0.4 上运行了无网络的原生 `compact()` 小批量验证:指定测试模型,两次 split-turn 摘要请求,检查 prior summary、custom instructions、边界 ID、文件记录、禁用缓存及 usage 汇总,均通过。
402
+ - 该验证使用注入的离线 stream,不证明真实 provider、virtual model 路由、Jev 判断质量或完整新插件已经可用。
403
+
404
+ ## 11. 待讨论的具体决策
405
+
406
+ 1. **设置完成前的可用入口**:等 Core 契约完成后一起接入,还是允许临时的、仅本会话生效的 `/pi-compaction model` 与 `/pi-compaction jev` 命令?后一种不持久化设置,但仍需用户确认其范围。
407
+ 2. **候选保护策略**:是否接受失败结果完整保留、未知副作用不删除整调用、跨摘要区域配对不变这些明确规则?
408
+ 3. **算法方向**:是否接受“结果片段选择 + 整调用删除判断”,而非让另一个生成模型逐条改写工具结果?回答:接受
409
+ 4. **运行详情 UI**:是否接入 Dock 并提供可查看决策统计的详情面板? 回答:是
410
+ 5. **独立思考等级和真实验证预算**:在实现契约确认时一起明确;删除阈值只能在样本验证后确定。回答:允许配置独立的思考等级
411
+
412
+ 以上未确认内容均为设计提议,不在本轮自行实现。
413
+
414
+ ## 12. 代码依据
415
+
416
+ 关键本地源文件:
417
+
418
+ - `/Users/sy/.pi/agent/local-extensions/pi-jev-compaction/extensions/fast-jev-compaction.ts`:原有 before-compact 挂接和异常兜底。
419
+ - `/Users/sy/.pi/agent/local-extensions/pi-jev-compaction/src/adapter.ts`:配对、区域处理、原生消息映射和截断。
420
+ - `/Users/sy/.pi/agent/local-extensions/pi-jev-compaction/node_modules/fast-jev-compaction/dist/state.js`:省略结果正文、goal 和 state 收缩策略。
421
+ - `/Users/sy/.pi/agent/local-extensions/pi-jev-compaction/node_modules/fast-jev-compaction/dist/compact.js`:原有问题、阈值、pinned 与决策流程。
422
+ - `/opt/homebrew/lib/node_modules/@earendil-works/pi-coding-agent/dist/core/model-registry.d.ts`:chat/classifier 模型与请求入口。
423
+ - `/opt/homebrew/lib/node_modules/@earendil-works/pi-coding-agent/dist/core/compaction/compaction.js`:原生摘要、split turn 与文件记录。
424
+ - `/opt/homebrew/lib/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session.js`:手动/自动压缩、自定义结果和提交边界。
425
+ - `/opt/homebrew/lib/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/runner.js`:异常捕获及 before-hook 结果覆盖。
426
+ - `/opt/homebrew/lib/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/model-selector.js`:all/scoped 选择语义。
427
+ - `/Users/sy/.pi/agent/local-extensions/pi-shell-inspector/src/shell/shell-dock-contribution.ts`:现有 Dock 快照和生命周期分层。
428
+ - `/Users/sy/.pi/agent/local-extensions/pi-lune-core/src/settings/types.ts`:当前未完成的设置契约。
429
+
430
+ ## 13. 2026-10-09 取消契约确认
431
+
432
+ 对照当前 Pi SDK 1.0.4,手动和自动 compact 都没有固定的总 deadline;交互界面 Esc 调用 `abortCompaction()`,取消信号传入 `session_before_compact`。用户确认 Jev 和摘要均不设置 deadline,统一跟随 Pi 用户取消及会话失效信号。删除旧运行配置和设置中的 `deadlineMs`,不保留兼容字段。
433
+
434
+ ## 14. 2026-10-09 Core 根入口与模型身份清理
435
+
436
+ 插件运行配置与持久设置统一使用 Core `ModelReference`(`{ provider, id }`),删除独立模型身份和字段转换。Core 引用统一由 `@lune_99/pi-lune-extensions-core` 根入口取得。虚拟摘要模型交给 Pi Registry `streamSimple()` 进行 direct 路由;0 模型限制采用 Pi 的未声明语义,只有已声明的窗口参与本地预算校验,不提供猜测上限。设置接入使用单份初始化结果,保留调用方资源所有权和初始化错误可见性。
437
+
438
+ ## 15. 2026-10-09 原生 SDK 简化
439
+
440
+ 用户确认保留独立摘要 thinking,并完全采用 Recap 的 Pi API 行为:存储值不因换模型而改写,候选由 `getSupportedThinkingLevels()` 提供,显示与执行使用 `clampThinkingLevel()`。配置模块保留为本插件提交给 Core 的 schema 与 Jev 参数解释;SDK 没有导出全局 thinking 枚举常量,存储 schema 使用 Pi `StringEnum`。模型直接由 Pi `ctx.modelRegistry.find()` 查找,取消等待使用 Pi `raceWithAbortSignal()`,摘要错误事件使用 Pi `lazyStream()`,文本提取使用 `contentText()`,Jev 请求预算估算使用 Pi `estimateTokens()`。删除自写摘要模型限制、token 估算算法和摘要窗口预检;原生 compact/provider 负责输出预算及请求错误,工具调用拒绝仍由原生 compact 执行。
441
+
442
+ ## 16. 2026-10-09 宿主取消契约与加载边界
443
+
444
+ 用户确认取消行为与 Pi 一致,取代前述额外的 `raceWithAbortSignal()` 等待保障。插件普通 await 宿主请求,向 `ctx.modelRegistry.streamSimple()` 和 `classify()` 传入 Pi compact signal,并在请求前、响应后、批次启动与提交前检查取消/会话状态。对不响应取消的 provider,不另造抢先结束等待的机制;迟到结果不得提交。自定义 Jev endpoint 通过内置 TypeSafe provider 与 `ctx.modelRegistry.classify()` 执行,保留显式 URL/key/model 权威配置。删除 SDK 子模块导入及原生 ESM alias 绕行,不修改 Pi 加载器。