Documentation
¶
Overview ¶
Package commander implements the three-tier capability execution: native (deterministic commands, no model), agent (AI CLI via adapter), and manual (human-notified). Design doc §6.
Index ¶
- func AdapterDir() string
- func InjectionNotice(d InjectionDecision, agent string) string
- func IsAuthorizationRefusal(stderr string) bool
- func LookPath(name string) bool
- func WithMemoryFiles(ctx context.Context, paths []string) context.Context
- func WithProgress(ctx context.Context, fn ProgressFunc) context.Context
- type AdapterRequest
- type AgentCandidate
- type AgentResult
- type Executor
- type FileContext
- type InjectionDecision
- type NativeResult
- type Plan
- type ProgressFunc
- type Result
- type Router
- func (r *Router) Execute(ctx context.Context, plan Plan, prompt string, cwd string, authorized bool) Result
- func (r *Router) InjectionDecision(adapter string) InjectionDecision
- func (r *Router) MatchAgent(required []string) (string, ledger.Agent, bool)
- func (r *Router) MatchManual(required []string) (ledger.ManualAbility, bool)
- func (r *Router) MatchNative(required []string) (ledger.NativeAbility, bool)
- func (r *Router) RankAgents(required []string) []AgentCandidate
- func (r *Router) Route(required []string) (Plan, error)
- func (r *Router) SetAdapterRunner(fn func(ctx context.Context, adapter, prompt, cwd string) AgentResult)
- func (r *Router) SetAgentProber(fn func(name string, ag ledger.Agent) bool)
- func (r *Router) SetPolicy(injection config.InjectionConfig, routing config.RoutingConfig)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AdapterDir ¶ added in v0.0.3
func AdapterDir() string
AdapterDir returns the directory the current process resolves adapter scripts from. The self-updater uses it to install updated adapter scripts beside the running binary without re-deriving the resolution rules.
func InjectionNotice ¶ added in v0.0.2
func InjectionNotice(d InjectionDecision, agent string) string
InjectionNotice renders the explicit one-line announcement prepended to the task output whenever a model injection happens, so the user always sees what was injected and why (no secrets included).
func IsAuthorizationRefusal ¶ added in v0.0.4
IsAuthorizationRefusal reports whether a failure string carries the tier-2 authorization refusal. The retry loop uses it to skip pointless re-runs: a policy refusal is deterministic — another attempt cannot produce consent.
func WithMemoryFiles ¶ added in v0.0.2
WithMemoryFiles attaches the node's memory file paths (absolute) to an execution context; runAdapterProcess copies them into AdapterRequest so an agent that received the prompt manifest can read the listed files itself.
func WithProgress ¶ added in v0.0.2
func WithProgress(ctx context.Context, fn ProgressFunc) context.Context
WithProgress attaches a progress sink to an execution context. Adapters emit NDJSON progress objects on stderr; runAdapterProcess parses them and forwards the note here, so the task's event timeline fills in while the agent runs instead of only when it finishes. Nil/absent = no sink; the parsing still isolates progress lines from the diagnostic stderr.
Types ¶
type AdapterRequest ¶
type AdapterRequest struct {
Prompt string `json:"prompt"`
TimeoutS int `json:"timeout_s"`
CWD string `json:"cwd,omitempty"`
// MemoryFiles lists the absolute paths of the node's personal memory
// files (A3 selective loading). The prompt carries the manifest (file
// index + summaries); this list gives the orchestration layer's view of
// the same files so adapters that support file access can let the agent
// read only what it needs instead of the whole memory content.
MemoryFiles []string `json:"memory_files,omitempty"`
}
AdapterRequest is written to the adapter's stdin.
type AgentCandidate ¶ added in v0.0.2
AgentCandidate is one scored agent match produced by RankAgents.
type AgentResult ¶
AgentResult is what an adapter returns.
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor runs native commands with a timeout and captures output. It never invokes an LLM — native commands are deterministic by contract.
func NewExecutor ¶
func NewExecutor() *Executor
NewExecutor creates a native executor. Default timeout 5m, no working dir.
func (*Executor) Run ¶
Run executes a command and returns its result. ctx may carry a shorter deadline than e.timeout.
type FileContext ¶
type FileContext struct {
Type string `json:"type"`
Repo string `json:"repo,omitempty"`
Branch string `json:"branch,omitempty"`
Commit string `json:"commit,omitempty"`
Scope []string `json:"scope,omitempty"`
Env map[string]string `json:"env,omitempty"`
}
FileContext is the file-type task context (design doc §12.5). It records repo identity plus optional scope so the executor knows what to touch.
func PackFileContext ¶
PackFileContext builds a FileContext from a local repo path. If the path is a git repo, branch + commit are captured so a full snapshot can be reconstructed or fetched elsewhere.
func (*FileContext) Hash ¶
func (fc *FileContext) Hash() string
Hash returns a reproducible SHA-256 of the context (excluding volatile paths). Used as the context_store key and pointer hit check.
type InjectionDecision ¶ added in v0.0.2
type InjectionDecision struct {
Inject bool
Reason string
Model string // model name injected (empty when Inject is false)
BaseURL string // endpoint injected (empty when Inject is false)
}
InjectionDecision is the outcome of the model-injection policy check for one agent adapter: whether panda overrides the agent's model endpoint via env, and a secret-free human-readable reason for announcements/audit.
type NativeResult ¶
NativeResult is the outcome of a deterministic command.
type Plan ¶
type Plan struct {
Kind string // native | agent | manual
Ability string
Command string
Args []string
Tier int // native command tier (defense §16)
Agent string
Adapter string
Notify string
// Alternates lists the remaining matching agents in score order. When
// the primary agent's CLI is unavailable at execution time, execAgent
// falls back through this chain.
Alternates []string
}
Plan describes how to execute a task on this node.
type ProgressFunc ¶ added in v0.0.2
type ProgressFunc func(note string)
ProgressFunc receives one adapter progress note (a short human-readable line, e.g. "Bash: du -ah | sort -rh") as the agent works.
type Result ¶
type Result struct {
OK bool
ExitCode int
Stdout string
Stderr string
Tokens int
Cost float64
NeedManual bool
// Agent is the agent that actually executed (may differ from the plan's
// primary when the fallback chain kicked in). Empty for non-agent plans
// and when no candidate was usable at all.
Agent string
}
Result is the normalized execution result (design doc P0-33).
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router matches a task's required abilities against a node's capability card and produces an execution plan (native command / agent adapter / manual notification).
func NewRouter ¶
func NewRouter(card ledger.Card, executor *Executor, model config.ModelConfig, injection config.InjectionConfig, routing config.RoutingConfig) *Router
NewRouter builds a router from this node's capability card. The model config is injected into agent adapter subprocesses only as the injection policy allows (default auto: agent-native credentials win); routing honors the preferred-agents bonus and falls back across scored candidates.
func (*Router) Execute ¶
func (r *Router) Execute(ctx context.Context, plan Plan, prompt string, cwd string, authorized bool) Result
Execute runs the plan and returns a formatted result. authorized is the user's explicit consent to run Tier-2 (irreversible) commands; a Tier-2 native command without it is refused before execution.
func (*Router) InjectionDecision ¶ added in v0.0.2
func (r *Router) InjectionDecision(adapter string) InjectionDecision
InjectionDecision evaluates the configured injection.model strategy for the adapter that drives an agent. It never logs or returns secrets — only the model name and endpoint, which are not sensitive.
Strategy (injection.model):
- never: no injection, unconditionally.
- always: always inject the panda model endpoint (legacy behavior).
- auto: inject only when the agent carries no model credentials of its own (env vars, login state / config files — both from the agent's registry credential manifest) AND panda has a model key configured; otherwise the agent's native model wins.
func (*Router) MatchAgent ¶
MatchAgent finds the best-scoring configured agent that satisfies any of required — either by name ("agent:<name>", the form the device summary advertises) or by one of its declared capabilities. Scoring is capability match × cost_tier discount plus the preferred-agents bonus (see RankAgents); the deterministic tie-break keeps repeated runs stable.
func (*Router) MatchManual ¶
func (r *Router) MatchManual(required []string) (ledger.ManualAbility, bool)
MatchManual finds a manual ability whose id matches any of required.
func (*Router) MatchNative ¶
func (r *Router) MatchNative(required []string) (ledger.NativeAbility, bool)
Match finds the first native ability whose id matches any of required.
func (*Router) RankAgents ¶ added in v0.0.2
func (r *Router) RankAgents(required []string) []AgentCandidate
RankAgents scores every agent that satisfies any of required and returns the candidates sorted by descending score (ties broken by name, so the choice stays deterministic across map iteration orders).
Score = capability match (1.0 exact / 0.9 token-subset) × cost_tier discount + preferred-agents bonus. A requirement of the form "agent:<name>" pins that exact agent — an explicit user choice never fans out to substitutes.
func (*Router) Route ¶
Route decides how to execute a task with the given required abilities. Priority: native > agent > manual (design doc §6.4).
func (*Router) SetAdapterRunner ¶
func (r *Router) SetAdapterRunner(fn func(ctx context.Context, adapter, prompt, cwd string) AgentResult)
SetAdapterRunner overrides the agent adapter invocation. It is a test seam: suites that need to exercise agent execution without spawning a real LLM CLI (e.g. scope-drift interception in core) inject a fake here.
func (*Router) SetAgentProber ¶ added in v0.0.2
SetAgentProber overrides the agent availability probe. Test seam: suites with a fake adapter runner normally pair it with an always-available probe.
func (*Router) SetPolicy ¶ added in v0.0.2
func (r *Router) SetPolicy(injection config.InjectionConfig, routing config.RoutingConfig)
SetPolicy swaps the injection/routing policy after construction (the core builds its router before the full config is wired through).