From 1e6c971f65bb3bc0e9b59f99b9a124eb08890a7c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 10 Aug 2026 22:38:13 +0000 Subject: [PATCH] Consolidate compaction group predicates Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- agent/compaction/group.go | 10 +++++++++- agent/compaction/index.go | 16 ++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/agent/compaction/group.go b/agent/compaction/group.go index 6b0584f0..c1f2f826 100644 --- a/agent/compaction/group.go +++ b/agent/compaction/group.go @@ -67,8 +67,16 @@ func newMessageGroup(kind GroupKind, messages []*message.Message, byteCount, tok } } +func (group *MessageGroup) isIncluded() bool { + return !group.IsExcluded +} + func (group *MessageGroup) isIncludedNonSystem() bool { - return !group.IsExcluded && group.Kind != GroupKindSystem + return group.isIncluded() && group.Kind != GroupKindSystem +} + +func (group *MessageGroup) isRaw() bool { + return group.Kind != GroupKindSummary } func cloneTurnIndex(turnIndex *int) *int { diff --git a/agent/compaction/index.go b/agent/compaction/index.go index 4b2f6e6d..b69b60d1 100644 --- a/agent/compaction/index.go +++ b/agent/compaction/index.go @@ -182,7 +182,7 @@ func (index *MessageIndex) AddGroup(kind GroupKind, messages []*message.Message, func (index *MessageIndex) IncludedMessages() []*message.Message { var messages []*message.Message for _, group := range index.Groups { - if !group.IsExcluded { + if group.isIncluded() { messages = append(messages, group.Messages...) } } @@ -232,7 +232,7 @@ func (index *MessageIndex) TotalTokenCount() int { func (index *MessageIndex) IncludedGroupCount() int { var total int for _, group := range index.Groups { - if !group.IsExcluded { + if group.isIncluded() { total++ } } @@ -243,7 +243,7 @@ func (index *MessageIndex) IncludedGroupCount() int { func (index *MessageIndex) IncludedMessageCount() int { var total int for _, group := range index.Groups { - if !group.IsExcluded { + if group.isIncluded() { total += group.MessageCount } } @@ -254,7 +254,7 @@ func (index *MessageIndex) IncludedMessageCount() int { func (index *MessageIndex) IncludedByteCount() int { var total int for _, group := range index.Groups { - if !group.IsExcluded { + if group.isIncluded() { total += group.ByteCount } } @@ -265,7 +265,7 @@ func (index *MessageIndex) IncludedByteCount() int { func (index *MessageIndex) IncludedTokenCount() int { var total int for _, group := range index.Groups { - if !group.IsExcluded { + if group.isIncluded() { total += group.TokenCount } } @@ -287,7 +287,7 @@ func (index *MessageIndex) TotalTurnCount() int { func (index *MessageIndex) IncludedTurnCount() int { seen := make(map[int]bool) for _, group := range index.Groups { - if !group.IsExcluded && group.TurnIndex != nil && *group.TurnIndex > 0 { + if group.isIncluded() && group.TurnIndex != nil && *group.TurnIndex > 0 { seen[*group.TurnIndex] = true } } @@ -321,7 +321,7 @@ func (index *MessageIndex) includedNonSystemGroupIndices() []int { func (index *MessageIndex) RawMessageCount() int { var total int for _, group := range index.Groups { - if group.Kind != GroupKindSummary { + if group.isRaw() { total += group.MessageCount } } @@ -331,7 +331,7 @@ func (index *MessageIndex) RawMessageCount() int { func (index *MessageIndex) includedRawMessageCount() int { var total int for _, group := range index.Groups { - if !group.IsExcluded && group.Kind != GroupKindSummary { + if group.isIncluded() && group.isRaw() { total += group.MessageCount } }