@@ -6,7 +6,12 @@ import { saveSessionState } from "../state/persistence"
66import { COMPRESS_TOOL_SPEC } from "../prompts"
77import { getCurrentParams , countAllMessageTokens , countTokens } from "../strategies/utils"
88import type { AssistantMessage } from "@opencode-ai/sdk/v2"
9- import { findStringInMessages , collectToolIdsInRange , collectMessageIdsInRange } from "./utils"
9+ import {
10+ findStringInMessages ,
11+ collectToolIdsInRange ,
12+ collectMessageIdsInRange ,
13+ findSummaryAnchorForBoundary ,
14+ } from "./utils"
1015import { sendCompressNotification } from "../ui/notification"
1116import { buildCompressionGraphData , cacheSystemPromptTokens } from "../ui/utils"
1217import { prune as applyPruneTransforms } from "../messages/prune"
@@ -183,17 +188,19 @@ export function createCompressTool(ctx: ToolContext): ReturnType<typeof tool> {
183188 summaries : state . compressSummaries . length ,
184189 } ,
185190 )
186- // TODO: This takes the first summary text match and does not error on
187- // multiple matching summaries (ambiguous fallback).
188- const s = state . compressSummaries . find ( ( s ) => s . summary . includes ( startString ) )
191+ const s = findSummaryAnchorForBoundary (
192+ state . compressSummaries ,
193+ startString ,
194+ "startString" ,
195+ )
189196 if ( s ) {
190197 rawStartIndex = messages . findIndex ( ( m ) => m . info . id === s . anchorMessageId )
191198 clog . info ( C . COMPRESS , `✓ Start resolved via summary anchor` , {
192199 anchorMessageId : s . anchorMessageId ,
193200 rawStartIndex,
194201 } )
195202 } else {
196- clog . error (
203+ clog . warn (
197204 C . COMPRESS ,
198205 `✗ Start not found in any summary either\nCannot resolve boundary` ,
199206 )
@@ -208,17 +215,19 @@ export function createCompressTool(ctx: ToolContext): ReturnType<typeof tool> {
208215 summaries : state . compressSummaries . length ,
209216 } ,
210217 )
211- // TODO: This takes the first summary text match and does not error on
212- // multiple matching summaries (ambiguous fallback).
213- const s = state . compressSummaries . find ( ( s ) => s . summary . includes ( endString ) )
218+ const s = findSummaryAnchorForBoundary (
219+ state . compressSummaries ,
220+ endString ,
221+ "endString" ,
222+ )
214223 if ( s ) {
215224 rawEndIndex = messages . findIndex ( ( m ) => m . info . id === s . anchorMessageId )
216225 clog . info ( C . COMPRESS , `✓ End resolved via summary anchor` , {
217226 anchorMessageId : s . anchorMessageId ,
218227 rawEndIndex,
219228 } )
220229 } else {
221- clog . error (
230+ clog . warn (
222231 C . COMPRESS ,
223232 `✗ End not found in any summary either\nCannot resolve boundary` ,
224233 )
@@ -398,16 +407,6 @@ export function createCompressTool(ctx: ToolContext): ReturnType<typeof tool> {
398407
399408 state . stats . pruneTokenCounter += estimatedCompressedTokens
400409
401- const rawStartResult = {
402- messageId : anchorMessageId ,
403- messageIndex : rawStartIndex ,
404- }
405- const rawEndMessageId = messages [ rawEndIndex ] ?. info . id || endResult . messageId
406- const rawEndResult = {
407- messageId : rawEndMessageId ,
408- messageIndex : rawEndIndex ,
409- }
410-
411410 const currentParams = getCurrentParams ( state , messages , logger )
412411 const summaryTokens = countTokens ( args . content . summary )
413412
0 commit comments