mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
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:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user