Files
gnoma/internal/session/session.go
T
vikingowl b0b393517e feat: M6 context intelligence — token tracker + truncation compaction
internal/context/:
- Tracker: monitors token usage with OK/Warning/Critical states
  (thresholds from CC: 20K warning buffer, 13K autocompact buffer)
- TruncateStrategy: drops oldest messages, preserves system prompt +
  recent N turns, adds compaction boundary marker
- Window: manages message history with auto-compaction trigger,
  circuit breaker after 3 consecutive failures

Engine integration:
- Context window tracks usage per turn
- Auto-compacts when critical threshold reached
- History syncs with context window after compaction

TUI status bar:
- Token count with percentage (tokens: 1234 (5%))
- Color-coded: green=ok, yellow=warning, red=critical

Session Status extended: TokensMax, TokenPercent, TokenState.
7 context tests.
2026-04-03 18:46:03 +02:00

68 lines
1.5 KiB
Go

package session
import (
"somegit.dev/Owlibou/gnoma/internal/engine"
"somegit.dev/Owlibou/gnoma/internal/stream"
)
// SessionState tracks the current state of a session.
type SessionState int
const (
StateIdle SessionState = iota
StateStreaming
StateToolExec
StateCancelled
StateError
StateClosed
)
func (s SessionState) String() string {
switch s {
case StateIdle:
return "idle"
case StateStreaming:
return "streaming"
case StateToolExec:
return "tool_exec"
case StateCancelled:
return "cancelled"
case StateError:
return "error"
case StateClosed:
return "closed"
default:
return "unknown"
}
}
// Status holds observable session state.
type Status struct {
State SessionState
Provider string
Model string
TokensUsed int64
TokensMax int64
TokenPercent int // 0-100
TokenState string // "ok", "warning", "critical"
TurnCount int
}
// Session is the boundary between UI and engine.
// All communication is via channels. No shared mutable state.
type Session interface {
// Send submits user input and begins an agentic turn.
Send(input string) error
// Events returns the channel that receives streaming events.
// A new channel is created per Send(). Closed when the turn completes.
Events() <-chan stream.Event
// TurnResult returns the completed Turn after Events() is drained.
TurnResult() (*engine.Turn, error)
// Cancel aborts the current turn.
Cancel()
// Close shuts down the session.
Close() error
// Status returns current session state.
Status() Status
}