mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
7a7e205cc8
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.
46 lines
1.1 KiB
Go
46 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%%) \nHistory: ~%d tokens \nCompress at: %d tokens \nSummarize at: %d tokens \nCompression progress: %d%% \nRemaining: ~%d tokens",
|
|
s.MessageCount,
|
|
s.UsedTokens,
|
|
s.TotalTokens,
|
|
usedWindowPercent,
|
|
s.HistoryTokens,
|
|
s.CompressAtTokens,
|
|
s.SummarizeAtTokens,
|
|
s.UsedPercent,
|
|
remaining,
|
|
)
|
|
return msg
|
|
}
|