Documentation
¶
Overview ¶
Package route is the router engine: it keys state by thread, turn and request fingerprint, asks the classifier on a turn's first step and in background reviews, runs the policy, checks the compatibility group and context fit, pins a decision for retries, and publishes decisions and snapshots. It implements proxy.Decider, proxy.Observer and control.Handler without importing those packages. Every error fails open: no rewrite.
Index ¶
- Constants
- type Command
- type Decision
- type Deps
- type Engine
- func (e *Engine) Apply(c Command) (err error)
- func (e *Engine) Decide(ctx context.Context, req *responses.Request, m responses.Meta) (rw responses.Rewrite, ok bool)
- func (e *Engine) Observe(m responses.Meta, served string, u responses.Usage, status int)
- func (e *Engine) SettingsUpdated(threadID string, r config.Route)
- func (e *Engine) Snapshot() Snapshot
- type Finding
- type FindingKind
- type Mode
- type Op
- type Reading
- type Share
- type Sink
- type Snapshot
- type Stats
- type Switch
Constants ¶
const ( ReasonActivityUp policy.Reason = "activity-up" ReasonActivityDown policy.Reason = "activity-down" ReasonActivityPending policy.Reason = "activity-pending" ReasonObserved policy.Reason = "observed" ReasonContinue policy.Reason = "continue" )
Reasons the engine adds to policy's: activity moves inside a tier, a move up on the turn's own tool calls, and a later step keeping the turn's route.
const ( MaxThreads = 256 RecentKept = 64 StripCells = 48 )
Bounds on remembered state.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct {
Op Op `json:"op"`
Tier config.Tier `json:"tier,omitempty"`
Preset config.Preset `json:"preset,omitempty"`
}
Command is what the TUI or hook asks the engine to do.
type Decision ¶
type Decision struct {
ThreadID string
TurnID string
Step int
Tier config.Tier
Activity config.Activity
Route config.Route
Original config.Route
Rewritten bool
Reason policy.Reason
Why string
Support string
Estimate *policy.Estimate
Reading *Reading
MidTurn bool
At time.Time
}
Decision is one per-request outcome.
type Deps ¶
type Deps struct {
Config config.Config
Catalog catalog.Source
Classifier classifier.Asker
Now func() time.Time
Sink Sink
Logger *slog.Logger
}
Deps are the engine's boundaries.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine routes user steps. All state lives under mu; step serializes the requests of one thread so a classifier call never runs under mu.
func (*Engine) Apply ¶
Apply runs a control command: pin or unpin the next turn's tier, pause or resume routing, or pick a policy preset. Pause writes each routed thread's own route back to its settings; resume also ends manual mode. A panic is logged and returned as an error.
func (*Engine) Decide ¶
func (e *Engine) Decide(ctx context.Context, req *responses.Request, m responses.Meta) (rw responses.Rewrite, ok bool)
Decide returns the rewrite for one request, or false to forward it unchanged. Any panic or error forwards unchanged.
func (*Engine) Observe ¶
Observe records a reply: the cache ledger, the thread's size, and the session stats when the reply answers a routed step.
func (*Engine) SettingsUpdated ¶
SettingsUpdated takes a thread/settings/updated notification. A value the router wrote is its echo; any other value is the user's own pick (plan D12): the thread goes manual until resume. A panic is logged and dropped.
type Finding ¶
type Finding struct {
Kind FindingKind
Text string
}
Finding is one WORTH A LOOK line derived from the session's facts.
type FindingKind ¶
type FindingKind string
FindingKind names what a WORTH A LOOK finding is about, and so where the user changes it.
const ( FindingClassifier FindingKind = "classifier" // paused or failing FindingManual FindingKind = "manual" // the footer model was picked with /model FindingContext FindingKind = "context" // the context guard kept larger windows FindingBlocked FindingKind = "blocked" // configured routes outside the group FindingCache FindingKind = "cache" // low cache reuse after switches )
type Reading ¶
type Reading struct {
Tiers map[config.Tier]float64
Activity config.Activity
ActivityP float64
Alternates []Share
}
Reading is the classifier answer the decision's turn runs on, for display: the probability per tier, and the activity answer with its probability and the two likeliest alternates. Tiers holds only the tiers the answer scored.
type Sink ¶
Sink receives decisions and snapshots; the launcher fans them out to the app-server client and the control socket. Called outside engine locks. OnDecision runs inside Decide, before the request goes upstream, and holds that thread's next step so its settings writes keep their order; an implementation must not block on I/O (queue it instead).
type Snapshot ¶
type Snapshot struct {
// Seq orders snapshots: they are taken under the engine lock but
// published after it, so a consumer drops one older than it holds.
Seq uint64
At time.Time
Mode Mode
Preset config.Preset
Pin *config.Tier
Baseline config.Route
Last *Decision
Recent []Decision
Classifier classifier.Health
ClassifierOff bool // no classifier configured (e.g. its key is unset)
ClassifierLabel string
ClassifierMedian time.Duration
Routes map[config.Tier]config.Route
Group catalog.Group
Blocked []string
Policy config.Policy
Stats Stats
ApproxTokens int
Window int
Worth []Finding
}
Snapshot is the full state the control socket publishes and the TUI renders.
type Stats ¶
type Stats struct {
Since time.Time
Replies int
Switches int
ByTier map[config.Tier]int
ByActivity map[config.Activity]int
Strip []config.Tier
RepliesPerCell int
LastSwitch *Switch
CacheReusePct int
LastInputTokens int
LastCachedTokens int
UncachedSwitchTokens int
FitHeld int
RoutedUSD float64
BaselineUSD float64
}
Stats sums the session since its first routed reply. LastInputTokens and LastCachedTokens are the last routed reply's; FitHeld counts the steps the context guard moved off the policy's tier.