feat: /compact 走 ACP 压缩管线 + i18n + usageTriggerPercent - #119
Conversation
- /compact 拦截 Pi 内置 compaction,改走 ACP compress 管线(acquireLock → processTurn → summarizeRange → applyCompression → 返回 compaction entry) - 失败(无 model/无 range/kernel 拒绝)回退 Pi 默认压缩,永不 cancel - 新增 acp.json 配置项:language(zh/en,覆盖 LANG 检测)、usageTriggerPercent(0-100,默认 25,0=禁用) - /acp-settings 新增语言选项,切换后立即生效无需重启 - i18n 完善:nudge 附加文本(压缩块列表、最小字符数提示)支持中文化 - 修复 config.ts 注释错位(usageTriggerPercent 文档与 timeout 注释混在一起) Co-authored-by: Orca <help@stably.ai>
49a8623 to
487a18f
Compare
# Conflicts: # src/compress-tool.ts # src/runtime.ts # tests/state.test.ts
…cast, i18n /compact notify strings
|
这里面内容比较多有一些涉及到重构方面.我需要拆分合并 |
- Pure function module clean-output.ts with O(n) dedupe using Map indexing
- Dedup globally repeated non-code lines (≥2 occurrences → ×N tag)
- Skip indented lines and code-anchored lines (syntax: {}, ;, ))
- Collapse \r progress-bar frames to final frame
- Collapse runs of ≥2 blank lines to one
- Wire into tool_result hook after cap, skip isError outputs
- Config: toolOutputClean (default true)
- 11 tests covering npm alternation, code immunity, CRLF, order
- Restore HEAD's session_before_compact interception (ACP compression for /compact) that was lost in the earlier conflict resolution, merged with master's delegate usage tracking (resolveDelegate, resetDelegateUsage) - Restore user-config.ts merged version (usageTriggerPercent/language + delegate/compress/displayUsage) - Update kernel threshold test to 0.0.21 defaults (0.55/0.8/1) - 282 tests pass, typecheck + build clean
autoCompress blocks the main reply for up to 60s while the compression model summarizes. Notify via ctx.ui before the blocking call so the user knows ACP is working, not hung.
|
你可能要重新弄了 |
Both config keys existed in config.ts but were missing from the settings UI. usageTriggerPercent: 0-100, 0=disabled (default 25); toolOutputClean: on/off boolean (default on).
- Extract TUI callback patch logic into exported applySetting(id, value) so validation (usageTriggerPercent 0-100, boolean/numeric/language branches) is unit-testable without a TUI mock - fmt() now treats null like undefined (acp.json "usageTriggerPercent": null shows default 25 instead of literal "null") - 5 new tests: range validation, boolean mapping, numeric rejection, language clear, unknown id
…onflicts) Conflicts resolved in 5 files, HEAD-side wins where it supersedes: - commands.ts: keep i18n imports + t() description, drop master dupes - config.ts: keep declare module + full field set, drop base/master dupes - index.ts: keep master's setDelegateDisplayUsage, restore indentation - user-config.ts: keep full KNOWN set + interface fields - tests/config.test.ts: HEAD version (0.0.21 thresholds + resolveDelegate) is a superset of master (0.0.20 thresholds) — took ours wholesale Verification: typecheck pass, 287 tests (286 pass, 1 skipped), build pass.
- tests/config.test.ts: registry acp-kernel 0.0.21 defaults are 0.75/0.95/0.95 (same as 0.0.20), not 0.55/0.8/1. The 0.55 values came from a locally overlaid unpublished master build (0.0.22 behavior); CI installs real 0.0.21 from npm. - tests/commands.test.ts: withTempHome now also sets USERPROFILE — Windows os.homedir() reads USERPROFILE, not HOME, so saveConfig tests read the real user config instead of the temp dir. - Local node_modules restored via npm ci (acp-kernel 0.0.21).
|
我现在着手把这个合并进去 因为前面的部分重构已结束 |
|
@21307369 感谢这个 PR。/compact 走 ACP 管线的方向是对的,但这个 PR 体量很大(3139 行)捆绑了不少东西,而且有几处设计需要调整。详细过审后建议拆成多个独立 PR,下面逐项说明。 1.
|
| PR | 内容 | 优先级 |
|---|---|---|
| A | resolveToFilePath 符号链接安全修复 |
高,可先合 |
| B | /compact → ACP(接 resolvePrompts + 修范围选择 + 独立测试) |
中 |
| C | clean-output(bash 去重,纯 tool_result 展示) | 中 |
| D | i18n 仅展示层(注入模型文本保持英文) | 低,看受众 |
| 去掉 | acp_summary_ 内联、usageTriggerPercent、module augmentation |
— |
整体方向认可,麻烦按上面拆分调整。有问题继续讨论 👍
|
上面模型回复的,有不准确的地方,我来纠正 1. acp_summary_ 不能改成内联 user 消息(需还原)补充,丢弃内核的消息,这是巧妙的地方 .为什么丢掉内核的总结 因为模型调用工具,compress 本身就是压缩本身.如果不丢弃就重复.这是opencode-acp的经验. 5. i18n 会影响模型注入的提示词(需改造)现在支持自定义提示词. |
Intercept Pi's session_before_compact: instead of cancelling native compaction, pick a compressible span (selectRangeSpan), summarize it with a model, and applyCompression, then hand the summary back to Pi as the compaction result. On any failure (no compressible ranges, no usable model, unparseable response, kernel rejection, exception) return undefined so Pi falls back to its own compaction rather than losing context. The summary prompt is built from the kernel's load-bearing compression rules (compressPhilosophy + howToCompressRules) via the Prompts interface, so /compact honors acp.json prompt overrides and stays consistent with the compress tool — NOT a hand-rolled prompt that would drift from the rules. Model resolution: explicit compressModel (provider:modelId in acp.json) wins, else the current session model (zero-config). Adds @earendil-works/pi-ai as a devDependency for the complete() type (kept external at runtime via tsup). Extracted from #119 (lsmir2).
变更摘要
/compact 拦截 → ACP 压缩管线
wireCompactionDisable从简单 cancel 改为完整 ACP 压缩流程:acquireLock → processTurn → 取最大可压缩 range →summarizeRange(压缩模型生成 summary)→applyCompression→ 返回 Pi compaction entry{ cancel: true }(Pi 手动 /compact 会因此抛 "Compaction cancelled")summarizeRange()函数(src/auto-compress.ts),供 /compact handler 和自动压缩共用session_before_compacthandler 阻塞前 TUI notify "ACP 正在压缩上下文",避免用户误以为卡死ctx.ui?.notify?.(t("compact.compressing", ...)))工具输出清洗(bash 去重去噪)
src/clean-output.ts纯函数模块:折叠 bash 输出的无缩进重复行(≥2 次标×N)、去\r覆盖、折叠连续空行{};)误伤率 0.24%tool_result钩子注入(src/tool-guardrails.ts),toolOutputClean?: boolean配置,默认true新增 acp.json 配置项
language:"zh"|"en",覆盖 LANG 检测;/acp-settings新增语言选项,切换后立即生效无需重启usageTriggerPercent:0-100,默认 25,0=禁用。上下文使用率到达该水位即注入压缩提示(独立于 kernel 的 growth 驱动)toolOutputClean:bash 工具输出清洗开关,默认true/acp-settings补齐usageTriggerPercent(0-100 校验,0=禁用)与toolOutputClean(开关)两项 UI配置 UI 可测试化重构
applySetting(id, value)(src/commands.ts):patch 构建 + 校验逻辑(boolean/数字 0-100/语言)从 TUI 回调中解耦,无需 mock TUI 即可单测fmt()对null与undefined同等处理(配置写null时显示默认值而非字面量)i18n 完善
合并 master(delegate 追踪 + compress config)
resetDelegateUsage、setDelegateDisplayUsage、resolveDelegate)集成到 session 生命周期delegate/compress/displayUsage+usageTriggerPercent/language(src/user-config.ts)src/footer-status.ts)修复
maxContextLimitPct: 0.55、emergencyThresholdPct: 0.8、truncate.threshold: 1)config.ts注释错位:usageTriggerPercent文档混入了toolBashDefaultTimeout的注释块declare module "acp-kernel"扩展 Config 类型,透传自定义字段新增/修改文件
src/auto-compress.ts(301 行)、src/clean-output.ts(124 行)、src/footer-status.ts(51 行)、src/i18n.ts(143 行)、src/fleet-widget.ts(9 行)auto-compress.test.ts、clean-output.test.ts、commands.test.ts(settings)、i18n.test.ts、footer-status.test.ts、delegate-entry.test.tssrc/index.ts(+171/-27)、src/commands.ts(+334/-33)、src/config.ts(+96/-5)、src/tool-guardrails.ts(+30/-9)、src/delegate-tool.ts(+249/-37)等CONFIGURATION.md/CONFIGURATION.zh-CN.md(237 行)验证
tsc --noEmit通过npm test287 通过(fail 0)npm run build通过(716.8 KB)