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
+23 -18
View File
@@ -2410,23 +2410,23 @@ export class ModelAgentRuntime implements AgentRuntime {
buildConversationSummaryHistory(state.summary)
)
: 0
if (
(!compression.settings.enabled && !options.force) ||
history.length === 0
) {
if (history.length === 0) {
return { request, compressed: false }
}
const plan = planContextCompression({
history: remainingHistory,
prompt: requestPrompt,
summaryTokens: currentSummaryTokens,
settings: compression.settings,
contextWindowTokens: compression.contextWindowTokens,
allowCompressLatestTurn: options.allowCompressLatestTurn,
effectiveTriggerTokens: options.effectiveTriggerTokens,
triggerContextTokens: options.triggerContextTokens
})
const plan =
!compression.settings.enabled && !options.force
? undefined
: planContextCompression({
history: remainingHistory,
prompt: requestPrompt,
summaryTokens: currentSummaryTokens,
settings: compression.settings,
contextWindowTokens: compression.contextWindowTokens,
allowCompressLatestTurn: options.allowCompressLatestTurn,
effectiveTriggerTokens: options.effectiveTriggerTokens,
triggerContextTokens: options.triggerContextTokens
})
if (!plan) {
return state
? {
@@ -4153,8 +4153,11 @@ export class ModelAgentRuntime implements AgentRuntime {
) {
throw new Error('当前模型连接不支持上下文摘要')
}
if (request.runtimeSelection.provider !== 'continue') {
throw new Error('GoodBuddy 摘要压缩仅适用于 Continue Runtime')
if (
request.runtimeSelection.provider !== 'continue' &&
request.runtimeSelection.provider !== 'model'
) {
throw new Error('GoodBuddy 摘要压缩仅适用于直连模型和 Continue Runtime')
}
if (request.contextCompressionState) {
@@ -4210,11 +4213,13 @@ export class ModelAgentRuntime implements AgentRuntime {
}
return {
result: {
provider: 'continue',
provider: request.runtimeSelection.provider,
strategy: 'goodbuddy-summary',
compacted,
detail: compacted
? '已使用 GoodBuddy 摘要压缩较早的 Continue 对话历史'
? request.runtimeSelection.provider === 'continue'
? '已使用 GoodBuddy 摘要压缩较早的 Continue 对话历史'
: '已使用 GoodBuddy 摘要压缩较早的对话历史'
: '当前对话没有可继续压缩的较早历史',
...(conversationState
? { contextCompressionState: conversationState }