mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-18 07:01:30 +00:00
Fix auto-compaction TUI integration and cut point logic
- Trigger auto-compaction after agent_end instead of during message_end - Show CompactionComponent after auto-compaction (same as manual /compact) - Fix cut point to include bash executions before kept user message - Stop backward scan at compaction, assistant, user, or toolResult boundaries
This commit is contained in:
parent
75c2eea151
commit
4227fd5996
3 changed files with 46 additions and 20 deletions
|
|
@ -94,7 +94,11 @@ function findTurnBoundaries(entries: SessionEntry[], startIndex: number, endInde
|
|||
|
||||
/**
|
||||
* Find the cut point in session entries that keeps approximately `keepRecentTokens`.
|
||||
* Returns the entry index of the first message to keep (a user message for turn integrity).
|
||||
* Returns the entry index of the first entry to keep.
|
||||
*
|
||||
* The cut point targets a user message (turn boundary), but then scans backwards
|
||||
* to include any preceding non-turn entries (bash executions, settings changes, etc.)
|
||||
* that should logically be part of the kept context.
|
||||
*
|
||||
* Only considers entries between `startIndex` and `endIndex` (exclusive).
|
||||
*/
|
||||
|
|
@ -150,6 +154,25 @@ export function findCutPoint(
|
|||
}
|
||||
}
|
||||
|
||||
// Scan backwards from cutIndex to include any non-turn entries (bash, settings, etc.)
|
||||
// that should logically be part of the kept context
|
||||
while (cutIndex > startIndex) {
|
||||
const prevEntry = entries[cutIndex - 1];
|
||||
// Stop at compaction boundaries
|
||||
if (prevEntry.type === "compaction") {
|
||||
break;
|
||||
}
|
||||
if (prevEntry.type === "message") {
|
||||
const role = prevEntry.message.role;
|
||||
// Stop if we hit an assistant, user, or tool result (all part of previous turn)
|
||||
if (role === "assistant" || role === "user" || role === "toolResult") {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Include this non-turn entry (bash, settings change, etc.)
|
||||
cutIndex--;
|
||||
}
|
||||
|
||||
return cutIndex;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue