routing

package
v0.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package routing is Orch's pure role-routing and escalation policy core (PRD §9 roles, §10 default profiles, §11 routing and escalation). Given a host Profile, a Task's read-only/risk/difficulty facts, and the History of prior attempts, Decide picks the role, executor, and reviewer for a fresh routing, and Escalate applies the PRD §11 escalation rules when a running attempt reports trouble.

The package is deliberately narrow and fail-closed. It performs no I/O, reads no clock, and imports only internal/manifest, whose Role/Selection/Escalation types it emits verbatim so the run engine can record a decision in a PRD §13 audit manifest without a translation layer. It never ranks model strength: model identifiers are opaque strings and it trusts the profile's role semantics (config owns the model vocabulary). Degenerate profiles — where a stronger role's model equals one that has already failed — are caught by string equality on the failed set and resolved by returning to the Architect, never by guessing at a strength order.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadProfile reports a Profile with an incomplete selection: some
	// role is missing its model or effort. Routing cannot emit a valid
	// audit record from it, so it refuses rather than guess a default.
	ErrBadProfile = errors.New("routing profile is incomplete")
	// ErrBadTask reports a Task carrying an unknown risk domain — a value
	// outside the closed PRD §11 set (see Domains).
	ErrBadTask = errors.New("routing task is invalid")
	// ErrBadTrigger reports an Escalate call with a trigger outside the
	// closed set (see the Trigger constants).
	ErrBadTrigger = errors.New("escalation trigger is unknown")
	// ErrTriggerMismatch reports an escalation trigger applied to a
	// decision it does not fit — e.g. scout-uncertainty on a non-scout
	// decision, or reviewer-uncertainty on a decision whose reviewer was
	// never downgraded.
	ErrTriggerMismatch = errors.New("escalation trigger does not match the decision")
	// ErrNoStrongerRoute reports that initial routing needs a stronger
	// executor than the profile can supply because the only candidate has
	// already failed. Unlike an escalation exhaustion (which returns to
	// the Architect), this is a plan-gate problem surfaced at Decide time.
	ErrNoStrongerRoute = errors.New("no stronger executor route remains")
)

Sentinel errors callers test with errors.Is. Specifics wrap these with %w and a remediation hint (state.go / manifest.go house style) rather than replace them.

Functions

This section is empty.

Types

type Attempt

type Attempt struct {
	Role      manifest.Role
	Selection manifest.Selection
	Failed    bool
	Reason    string
}

Attempt records one prior routing attempt and its fate. Failed marks a meaningful failure that permanently retires the attempt's model (PRD §11: Orch does not repeatedly retry an underpowered model); Reason is the caller-supplied detail behind that failure.

type Decision

type Decision struct {
	Role               manifest.Role
	Executor           manifest.Selection
	Reviewer           manifest.Selection
	ReviewerDowngraded bool
	Rationale          string
}

Decision is the routing chosen for a task: the role and the exact executor and reviewer selections, plus whether the reviewer was downgraded and a human-readable rationale (PRD §13). The rationale is always non-empty and feeds manifest.RoutingRationale verbatim.

func Decide

func Decide(p Profile, t Task, h History) (Decision, error)

Decide chooses the role, executor selection, and reviewer for a task against a profile and the history of prior attempts (PRD §9–§11). It applies the first-match-wins policy table, resolving conflicts toward the stronger route (PRD §11: uncertainty favors the stronger route) and recording any refused downgrade in the rationale rather than erroring. A nil history is a fresh task.

It fails closed: an incomplete profile is ErrBadProfile and an unknown risk domain is ErrBadTask. When the only stronger executor a row calls for has already failed, initial routing is exhausted and it returns ErrNoStrongerRoute (a plan-gate problem, distinct from an escalation returning to the Architect).

type DowngradeFacts

type DowngradeFacts struct {
	Mechanical     bool
	LowRisk        bool
	FullySpecified bool
	Unsurprising   bool
}

DowngradeFacts are the four conditions PRD §11 requires before a reviewer may be downgraded: the change must be affirmatively mechanical, low-risk, fully specified, and unsurprising.

func (DowngradeFacts) Eligible

func (f DowngradeFacts) Eligible() bool

Eligible reports whether all four downgrade facts are affirmatively true. The zero value is not eligible: absence of information is never permission to downgrade review (PRD §11: uncertainty favors the stronger route).

type History

type History []Attempt

History is the ordered list of prior attempts for a task. A nil History is a fresh task with nothing retired. Both entry points take it as a required positional argument, and Escalate returns the updated History with the retired attempt appended — so the correct input to a second call is the first call's output.

func (History) FailedModel

func (h History) FailedModel(model string) bool

FailedModel reports whether any recorded attempt on model failed. The match is on the model string only: an effort bump on a model that has already failed is still a retry of that model, never a fresh route, so routing never offers it again (PRD §11).

type Outcome

type Outcome struct {
	Kind        OutcomeKind
	Decision    Decision
	Escalations []manifest.Escalation
	History     History
	Reason      string
}

Outcome is the result of an escalation. On a reroute Decision holds the new routing and Escalations records the change(s) for the audit manifest; on a return-to-architect Decision is zero and Escalations is empty. History is always the input history with any retired attempt appended (the correct input to a follow-up Escalate), and Reason is a non-empty human-readable summary.

func Escalate

func Escalate(p Profile, d Decision, h History, tr Trigger, detail string) (Outcome, error)

Escalate applies a PRD §11 escalation to a decision. It appends a failed Attempt for every model it retires (one meaningful failure retires a model permanently) and emits a manifest.Escalation for each selection change with At left empty for the run engine to stamp. A trigger that does not fit the decision is ErrTriggerMismatch and an unknown trigger is ErrBadTrigger; a return to the Architect is a first-class Outcome, never an error.

Cross-cutting rule: any executor reroute on a downgraded-reviewer decision also restores the strong reviewer and emits a second escalation record — a task that needed escalation was, by evidence, not "unsurprising".

type OutcomeKind

type OutcomeKind string

OutcomeKind distinguishes the two shapes an Escalate result takes.

const (
	// OutcomeReroute is a new executor and/or reviewer selection to run.
	OutcomeReroute OutcomeKind = "reroute"
	// OutcomeReturnToArchitect hands the task back to the Architect: the
	// escalation ladder is exhausted or the trouble is architectural.
	// Decision is the zero value — there is no executor route to run.
	OutcomeReturnToArchitect OutcomeKind = "return-to-architect"
)

type Profile

type Profile struct {
	Architect       manifest.Selection
	Scout           manifest.Selection
	Implementer     manifest.Selection
	Specialist      manifest.Selection
	Reviewer        manifest.Selection
	ReviewDowngrade manifest.Selection
}

Profile is the per-host model/effort assignment routing consumes. Its six selections mirror config.Roles (PRD §10) one-for-one, but routing does not import config: the run engine maps each config.RoleProfile to a manifest.Selection and hands the result here, keeping this package off the TOML chain.

type RiskDomain

type RiskDomain string

RiskDomain is one of the sensitive domains PRD §11 routes directly to a Specialist executor plus a strong Reviewer. The set is closed: any other value is an unknown domain and rejected as ErrBadTask.

const (
	RiskSecurity              RiskDomain = "security"
	RiskAuthentication        RiskDomain = "authentication"
	RiskAuthorization         RiskDomain = "authorization"
	RiskSecrets               RiskDomain = "secrets"
	RiskCryptography          RiskDomain = "cryptography"
	RiskMigrations            RiskDomain = "migrations"
	RiskConcurrency           RiskDomain = "concurrency"
	RiskDataIntegrity         RiskDomain = "data-integrity"
	RiskDestructiveOperations RiskDomain = "destructive-operations"
)

func Domains

func Domains() []RiskDomain

Domains returns the nine risk domains in canonical order. Rationale strings render present domains in this order, so the audit record is deterministic regardless of the caller's Task ordering.

func (RiskDomain) Valid

func (d RiskDomain) Valid() bool

Valid reports whether d is a member of the closed risk-domain set.

type Task

type Task struct {
	// ReadOnly marks work that only reads the repository (PRD §9 Scout).
	ReadOnly bool
	// UnusuallyDifficult marks work whose implementation is itself hard
	// (PRD §9 Specialist), forcing a specialist regardless of risk.
	UnusuallyDifficult bool
	// RiskDomains lists the sensitive domains the change touches; any
	// non-empty set forces a specialist plus a strong reviewer (PRD §11).
	RiskDomains []RiskDomain
	// Downgrade holds the caller's affirmative claims about the change.
	// It only ever weakens the reviewer, and only when Eligible.
	Downgrade DowngradeFacts
}

Task carries the routing-relevant facts about one unit of work. All fields default to the safe answer: a zero Task is a read/write, low-difficulty change with no risk domains and no downgrade permission, which Decide routes to a plain implementer with a strong reviewer.

type Trigger

type Trigger string

Trigger names a PRD §11 escalation event a running attempt can raise. The set is closed; any other value is ErrBadTrigger.

const (
	// TriggerScoutUncertainty: a scout reports it cannot resolve the work
	// read-only; escalate to the specialist model in read-only mode.
	TriggerScoutUncertainty Trigger = "scout-uncertainty"
	// TriggerImplementerHardExecution: an implementer finds execution
	// unusually hard; transfer the worktree to a specialist.
	TriggerImplementerHardExecution Trigger = "implementer-hard-execution"
	// TriggerWeakModelFailure: one meaningful failure of an underpowered
	// model; climb one tier rather than retry.
	TriggerWeakModelFailure Trigger = "weak-model-failure"
	// TriggerReviewerUncertainty: a downgraded reviewer reports doubt;
	// escalate to a complete strong-model review. A strong reviewer's
	// doubt is architectural-ambiguity, not this.
	TriggerReviewerUncertainty Trigger = "reviewer-uncertainty"
	// TriggerArchitecturalAmbiguity: unresolved design ambiguity from any
	// role; return to the Architect.
	TriggerArchitecturalAmbiguity Trigger = "architectural-ambiguity"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL