mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
5f826f4448
The /context command previously showed only the hard budget compression threshold (contextWindow - maxTokens), which confused users who expected to see the soft summarization trigger from summarize_token_percent. This commit adds SummarizeAtTokens alongside the existing CompressAtTokens so that both thresholds are visible: - Compress at: contextWindow - maxTokens (hard budget, triggers proactive compression when exceeded) - Summarize at: contextWindow * summarizeTokenPercent / 100 (soft trigger, matches maybeSummarize's threshold) The fix updates the /context command output, the Web UI popover, and the pico channel WebSocket payload. Fixes #2968
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package commands
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
func contextCommand() Definition {
|
|
return Definition{
|
|
Name: "context",
|
|
Description: "Show current session context and token usage",
|
|
Usage: "/context",
|
|
Handler: func(_ context.Context, req Request, rt *Runtime) error {
|
|
if rt == nil || rt.GetContextStats == nil {
|
|
return req.Reply(unavailableMsg)
|
|
}
|
|
stats := rt.GetContextStats()
|
|
if stats == nil {
|
|
return req.Reply("No active session context.")
|
|
}
|
|
return req.Reply(formatContextStats(stats))
|
|
},
|
|
}
|
|
}
|
|
|
|
func formatContextStats(s *ContextStats) string {
|
|
remaining := s.CompressAtTokens - s.UsedTokens
|
|
if remaining < 0 {
|
|
remaining = 0
|
|
}
|
|
usedWindowPercent := s.UsedTokens * 100 / max(s.TotalTokens, 1)
|
|
msg := fmt.Sprintf(
|
|
"Context usage \nMessages: %d \nUsed: ~%d / %d tokens (%d%%) \nCompress at: %d tokens \nSummarize at: %d tokens \nCompression progress: %d%% \nRemaining: ~%d tokens",
|
|
s.MessageCount,
|
|
s.UsedTokens,
|
|
s.TotalTokens,
|
|
usedWindowPercent,
|
|
s.CompressAtTokens,
|
|
s.SummarizeAtTokens,
|
|
s.UsedPercent,
|
|
remaining,
|
|
)
|
|
return msg
|
|
}
|