Documentation
¶
Overview ¶
Package orchestrator manages the Phase 2 orchestrator + worker lifecycle: it spawns Claude Code sessions with the hive-aware system prompt, runs the mailbox router on a tick, and registers agents in the hive. See .ai/05-orchestration.md and .ai/07-orchestrator.md.
Index ¶
Constants ¶
const OrchestratorID = hive.OrchestratorAgentID
OrchestratorID is the fixed hive agent id for the orchestrator session.
Variables ¶
This section is empty.
Functions ¶
func SystemPrompt ¶
SystemPrompt returns the orchestrator system prompt with the hive home path appended, so the session knows where its inbox/outbox and the task board live.
Types ¶
type Orchestrator ¶
type Orchestrator struct {
Hive *hive.Hive
Store *store.Store
Spawner Spawner
Log *slog.Logger
// PromptFile is the path the orchestrator system prompt is written to for
// --append-system-prompt-file (defaults to <hive>/.orchestrator-prompt.md).
PromptFile string
// Cwd is the repo the orchestrator and workers operate on.
Cwd string
// RouterTick is how often mail is delivered (default 2s).
RouterTick time.Duration
// KickDelay is how long to wait for the freshly-spawned TUI to be ready for
// input before writing the kick message (default 2500ms).
KickDelay time.Duration
// Verify runs a task's done_criteria and moves it out of `verifying`
// (→ done | in_progress | needs_you). Injected by the daemon as a closure over
// board.VerifyTask so the orchestrator need not import board. nil ⇒
// verification is driven elsewhere (or disabled in tests).
Verify func(ctx context.Context, taskID string) error
// WakeThrottle bounds how often an idle session is re-kicked to process new
// mail (default 20s), so a still-working agent is not spammed every tick.
WakeThrottle time.Duration
// Now returns the current time (overridable in tests).
Now func() time.Time
// BaseCtx is the daemon-lifetime context the router and kick goroutines run
// under. It must NOT be the per-request context passed to Start — that is
// cancelled the instant the HTTP handler returns, which would kill the router
// immediately. The daemon sets this to its run context. If nil, Start falls
// back to a non-cancellable copy of the Start context.
BaseCtx context.Context
// contains filtered or unexported fields
}
Orchestrator owns the orchestrator session and the worker fleet, and runs the mailbox router on a tick.
func (*Orchestrator) AgentIDForSession ¶
func (o *Orchestrator) AgentIDForSession(sessionID string) string
AgentIDForSession maps a Caprock session id back to its hive agent id (for the Stop-loop decision, which needs the agent whose inbox to check).
func (*Orchestrator) SpawnWorker ¶
SpawnWorker registers a worker in the hive and spawns its session. Idempotent per worker id: if already running, returns the existing session.
func (*Orchestrator) Start ¶
func (o *Orchestrator) Start(ctx context.Context) (string, error)
Start registers the orchestrator agent, spawns its session with the hive-aware system prompt, and begins the router loop. Returns the session id.
func (*Orchestrator) TaskForAgent ¶
func (o *Orchestrator) TaskForAgent(agentID string) string
TaskForAgent returns the id of the live (non-terminal) task assigned to an agent, or "" if none. It arms the Stop-hook forced-continue guard, which is keyed per (session, task). The orchestrator itself is never assigned a task.
type Spawner ¶
type Spawner interface {
Spawn(ctx context.Context, req agents.SpawnRequest) (*agents.Agent, error)
Get(sessionID string) (*agents.Agent, bool)
ClaudeAvailable() bool
// Input writes typed bytes into an owned session's PTY (the kick message).
Input(sessionID string, data []byte) error
}
Spawner is the subset of agents.Manager the orchestrator needs.