fix: restore manual context compaction for direct models

Local direct-model text conversations could not use manual context compaction,
and disabling automatic compression prevented saved summaries from being reused.
Restore the composer action regardless of the automatic setting or threshold,
use the selected summary connection, and persist summaries for subsequent
requests while retaining recent turns and full conversation history.

Image connections, remote channel conversations, and SSH projects remain outside
the local direct-model compaction workflow. Add focused regressions, a local
Electron end-to-end test, and an opt-in two-request live probe.

Validation: staged snapshot passed typecheck, changed-file ESLint, 13 focused
tests, and the Electron end-to-end test with two local HTTP fixture requests.
No additional real-model calls were made during commit verification.

Release note: 修复本地直连文本模型无法手动压缩上下文的问题。现在关闭自动压缩或尚未达到触发阈值时,也可点击“压缩上下文”;摘要会随会话保存并用于后续对话,同时保留最近轮次和完整历史。
This commit is contained in:
mesalogo
2026-09-28 22:21:47 +08:00
parent 1603871f7c
commit 4baf4ec142
14 changed files with 552 additions and 47 deletions
@@ -261,6 +261,29 @@ DeepSeek Harness 和托管 SSH 路径不注入这些工具。既有功能的 Win
MCP 代理复用 Provider 发现快照规则,托管 SSH Runtime 不经过该本机构造路径。本次未
修改远端 Agent、桥接或启动器。
## 2026-09-28 本地直连手动压缩
- 本地直连文本会话复用“压缩上下文”按钮、摘要状态和会话保存路径,支持关闭自动压缩时
手动执行。当前连接选择、图像排除、强制压缩和最新轮次保留规则见
[技术设计](./technical-design.md#101-本地直连手动压缩)。未修改远端 Agent、桥接或启动器;
model 入口排除远程会话与 SSH 项目,本地 IPC 仍拒绝 SSH 执行空间。
- 三个目标文件 `App.test.tsx`、`ipc.test.ts`、`model-runtime.test.ts`:569 passed、2 skipped。
覆盖入口点击、自动关闭和低于阈值、运行中禁用、图像排除、摘要保存与后续请求、当前及指定
摘要连接选择。补入远程通道入口排除后,App 手动压缩专项复跑 7 passed;最终类型检查和
本次文件 ESLint 再次通过。
- `manual-compaction.electron.test.ts`:真实 App、preload、IPC、模型工厂和 SQLite 路径通过。
2 次本机 HTTP fixture 请求验证较早历史被摘要替换、最新轮次保留、完整历史仍在数据库,
页面重载后摘要可读,新建 Runtime 实际使用该摘要。
- `manual-compaction-live.electron.test.ts`:真实配置文本模型最终通过,2 次请求完成摘要及
新 Runtime 续问。三轮探针累计 6 次真实文本模型请求;前两轮失败来自探针用未转义摘要
匹配 JSON payload,修正断言后通过。原设置文件未改变,未记录凭据。
- `npm run typecheck` 和本次涉及文件的 ESLint 通过。全仓 `npm run lint` 有 10 个错误,
位于已有侧栏探针 `sidebar-final-probe.ts`、`sidebar-final-run.mjs`,保留未修改。
- 全量 `npm test`:5407 passed、85 skipped、2 failed。失败分别为已有侧栏探针的新建按钮
溢出断言(`magic-notes-capture.electron.test.ts`)及魔法笔记布局 Electron 超时
(`magic-notes-layout.electron.test.ts`);手动压缩 Electron 回归通过。未执行构建或跨平台
真机测试,不将全仓验证记为全绿。
## 进度维护要求
- 只有真实生产路径完成并验证后才能勾选实施项。
@@ -451,6 +451,18 @@ type SubagentActor =
处理。Continue 接收完整历史,已有有效摘要只替换其覆盖的前缀,剩余消息全部交给原生
Runtime;GoodBuddy 不再额外保留最后 20 条或限制为 128,000 字符。
### 10.1 本地直连手动压缩
`agentCompactConversation` 接受 `model`,结果保留实际 provider,压缩策略为
`goodbuddy-summary`。摘要来源为 `current` 时,IPC 使用 `applyRuntimeSelection`
解析后的当前直连连接;来源为 `profile` 时,使用既有指定摘要连接配置。
图像连接不进入文本摘要路径,SSH 执行空间仍由本地 IPC 拒绝。
`ModelAgentRuntime.compactConversation` 复用 `prepareCompressedRequest` 的强制压缩,
跳过自动开关和触发阈值,保留最新轮次。返回的 `contextCompressionState` 沿用会话保存,
不删除历史正文。后续请求校验摘要覆盖范围后,用摘要替换已覆盖前缀;即使关闭自动压缩,
已保存的有效摘要仍会使用。
## 11. 性能
- Shell 探测按执行服务实例缓存,不在每轮模型调用重复探测。
@@ -21,6 +21,11 @@
Job、Subjob 和 Run 继续是内部对象,不创建树形 UI、独立路由或操作菜单。
本地直连文本会话复用输入区已有的“压缩上下文”按钮,不依赖原生 Runtime 快照,
也不因自动压缩关闭或上下文低于触发阈值而隐藏。运行中或压缩中按钮禁用;图像连接、
远程通道会话和 SSH 项目不显示直连模型压缩入口。完成后沿用应用通知及压缩后上下文估算,
摘要随会话保存。压缩行为见[技术设计](./technical-design.md#101-本地直连手动压缩)。
## 2. 设置中的能力目录
直连模型工具目录使用两个本机开发分组: