fix(context): expose history tokens and remove leaked state files

Address remaining review feedback: 1) Add HistoryTokens field to ContextUsage/ContextStats, showing history-only token count in /context and frontend UI alongside SummarizeAtTokens so users can see the actual summarization trigger comparison. 2) Remove .codebuddy/github-contribute/ state files accidentally included in the PR.
This commit is contained in:
程智超0668000959
2026-06-06 00:28:32 +08:00
parent b6030f054d
commit 7a7e205cc8
15 changed files with 25 additions and 90 deletions
+1
View File
@@ -352,6 +352,7 @@ func (al *AgentLoop) buildCommandsRuntime(
return &commands.ContextStats{
UsedTokens: usage.UsedTokens,
TotalTokens: usage.TotalTokens,
HistoryTokens: usage.HistoryTokens,
CompressAtTokens: usage.CompressAtTokens,
SummarizeAtTokens: usage.SummarizeAtTokens,
UsedPercent: usage.UsedPercent,
+4 -6
View File
@@ -64,12 +64,9 @@ func computeContextUsage(agent *AgentInstance, sessionKey string) *bus.ContextUs
// summarizeAt = soft summarization trigger: matches maybeSummarize's
// threshold (contextWindow * SummarizeTokenPercent / 100).
//
// NOTE: The engine's maybeSummarize compares this threshold against
// history-message tokens only (via estimateTokens), while UsedTokens
// (shown in /context) includes system prompt, summary, and tool
// definitions on top of history tokens. A "Used > SummarizeAt" display
// does not necessarily mean summarization will fire — the engine may
// still consider the history-token budget to be under threshold.
// The engine compares this against history-message tokens ONLY (not
// UsedTokens). HistoryTokens is exposed alongside UsedTokens so the
// UI can show both values and avoid user confusion.
summarizeAt := contextWindow * agent.SummarizeTokenPercent / 100
if summarizeAt <= 0 {
summarizeAt = compressAt
@@ -86,6 +83,7 @@ func computeContextUsage(agent *AgentInstance, sessionKey string) *bus.ContextUs
return &bus.ContextUsage{
UsedTokens: usedTokens,
TotalTokens: contextWindow,
HistoryTokens: historyTokens,
CompressAtTokens: compressAt,
SummarizeAtTokens: summarizeAt,
UsedPercent: usedPercent,