MCPcopy Create free account
hub / github.com/diillson/chatcli / compactHistoryIfNeeded

Method compactHistoryIfNeeded

cli/cli_llm.go:186–201  ·  view source on GitHub ↗

compactHistoryIfNeeded runs the proxy-payload pre-flight warning and triggers history compaction when the current chat history exceeds the configured budget. Compaction errors leave cli.history untouched so the turn can still proceed with the un-compacted history.

(ctx context.Context)

Source from the content-addressed store, hash-verified

184// configured budget. Compaction errors leave cli.history untouched so the
185// turn can still proceed with the un-compacted history.
186func (cli *ChatCLI) compactHistoryIfNeeded(ctx context.Context) {
187 cfg := DefaultCompactConfig(cli.Provider, cli.Model)
188 cli.warnIfHistoryExceedsProxyCap(cfg)
189 if !cli.historyCompactor.NeedsCompaction(cli.history, cfg) {
190 return
191 }
192 cli.historyCompactor.SetStatusCallback(func(stage CompactStage, msg string) {
193 fmt.Printf("\r\033[K %s\n", msg)
194 _ = os.Stdout.Sync()
195 })
196 compacted, err := cli.historyCompactor.Compact(ctx, cli.history, cli.Client, cfg)
197 cli.historyCompactor.SetStatusCallback(nil)
198 if err == nil {
199 cli.history = compacted
200 }
201}
202
203// warnIfHistoryExceedsProxyCap fires a once-per-session notice when the
204// uncompacted history is large enough that a corporate proxy could start

Callers 1

processLLMRequestMethod · 0.95

Calls 6

DefaultCompactConfigFunction · 0.85
SetStatusCallbackMethod · 0.80
SyncMethod · 0.80
CompactMethod · 0.80
NeedsCompactionMethod · 0.45

Tested by

no test coverage detected