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)
| 184 | // configured budget. Compaction errors leave cli.history untouched so the |
| 185 | // turn can still proceed with the un-compacted history. |
| 186 | func (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 |
no test coverage detected