improved compacting algo and token visibility

This commit is contained in:
Luxferre
2026-08-16 08:20:57 +03:00
parent d1597444d0
commit b84f98a2cc
2 changed files with 14 additions and 6 deletions
+12 -4
View File
@@ -727,7 +727,7 @@ func llm(ctx context.Context, cfg *Cfg, msgs []Message, tools []map[string]any)
if cfg.Stream { p["stream_options"] = map[string]any{"include_usage": true} } if cfg.Stream { p["stream_options"] = map[string]any{"include_usage": true} }
for k, v := range cfg.Raw { for k, v := range cfg.Raw {
switch k { switch k {
case "endpoint", "api_key", "timeout", "shell_timeout", "max_al_iterations", "color", "context_window": case "endpoint", "model", "temperature", "stream", "api_key", "timeout", "shell_timeout", "max_al_iterations", "color", "context_window":
continue continue
default: default:
var jv any var jv any
@@ -1409,9 +1409,10 @@ func main() {
sigCtx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) sigCtx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
var usg Usage var usg Usage
msgs, usg, err = AL(sigCtx, &cfg, msgs, sp, 0) msgs, usg, err = AL(sigCtx, &cfg, msgs, sp, 0)
interrupted := sigCtx.Err() != nil
cancel() cancel()
if err != nil { if err != nil {
if errors.Is(err, context.Canceled) || sigCtx.Err() != nil { if interrupted || errors.Is(err, context.Canceled) {
fmt.Println(c("\n[interrupted]", 33)) fmt.Println(c("\n[interrupted]", 33))
} else { } else {
fmt.Println(c("[error: "+err.Error()+"]", 31)) fmt.Println(c("[error: "+err.Error()+"]", 31))
@@ -1481,9 +1482,10 @@ func main() {
fmt.Println(c("[compacting conversation...]", 33)) fmt.Println(c("[compacting conversation...]", 33))
sigCtx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) sigCtx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
nm, sm, err := compact(sigCtx, &cfg, msgs) nm, sm, err := compact(sigCtx, &cfg, msgs)
interrupted := sigCtx.Err() != nil
cancel() cancel()
if err != nil { if err != nil {
if errors.Is(err, context.Canceled) || sigCtx.Err() != nil { if interrupted || errors.Is(err, context.Canceled) {
fmt.Println(c("\n[interrupted]", 33)) fmt.Println(c("\n[interrupted]", 33))
} else { } else {
fmt.Println(c("[compact failed: "+err.Error()+"]", 31)) fmt.Println(c("[compact failed: "+err.Error()+"]", 31))
@@ -1542,9 +1544,10 @@ func main() {
turnMsgs = append(turnMsgs, Message{Role: "user", Content: strp(u)}) turnMsgs = append(turnMsgs, Message{Role: "user", Content: strp(u)})
sigCtx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) sigCtx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
resMsgs, usg, err := AL(sigCtx, &cfg, turnMsgs, sp, 0) resMsgs, usg, err := AL(sigCtx, &cfg, turnMsgs, sp, 0)
interrupted := sigCtx.Err() != nil
cancel() cancel()
if err != nil { if err != nil {
if errors.Is(err, context.Canceled) || sigCtx.Err() != nil { if interrupted || errors.Is(err, context.Canceled) {
fmt.Println(c("\n[interrupted]", 33)) fmt.Println(c("\n[interrupted]", 33))
} else { } else {
fmt.Println(c("[error: "+err.Error()+"]", 31)) fmt.Println(c("[error: "+err.Error()+"]", 31))
@@ -1564,9 +1567,14 @@ func main() {
fmt.Println(c("[compacting conversation...]", 33)) fmt.Println(c("[compacting conversation...]", 33))
sigCtx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) sigCtx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
nm, sm, err := compact(sigCtx, &cfg, msgs) nm, sm, err := compact(sigCtx, &cfg, msgs)
interrupted := sigCtx.Err() != nil
cancel() cancel()
if err != nil { if err != nil {
if interrupted || errors.Is(err, context.Canceled) {
fmt.Println(c("\n[interrupted]", 33))
} else {
fmt.Println(c("[compact failed: "+err.Error()+"]", 31)) fmt.Println(c("[compact failed: "+err.Error()+"]", 31))
}
} else { } else {
msgs = nm msgs = nm
autosave(msgs) autosave(msgs)
+1 -1
View File
@@ -1,5 +1,5 @@
endpoint=https://opencode.ai/zen/v1 endpoint=https://opencode.ai/zen/v1
model=big-pickle model=hy3-free
temperature=0.7 temperature=0.7
api_key=- api_key=-
stream=true stream=true