orchestrator

package
v0.37.2 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: Apache-2.0 Imports: 11 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 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

View Source
const MaxConsecutiveWakes = 10

MaxConsecutiveWakes bounds how many times in a row the router will type a kick into one agent whose inbox never clears. Past it the agent is stalled: waking it again is a Claude turn every WakeThrottle with nothing to show for it.

View Source
const OrchestratorID = hive.OrchestratorAgentID

OrchestratorID is the fixed hive agent id for the orchestrator session.

Variables

This section is empty.

Functions

func SystemPrompt

func SystemPrompt(hiveHome string) string

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
	// OverBudget moves a task that outspent its budget to needs_you and mirrors
	// it, with the reason attached. Injected by the daemon as a closure over
	// board.OverBudget for the same reason as Verify (the board owns the mirror
	// and the bus, and importing it here would cycle). nil ⇒ the router does the
	// hive-side move itself, without a mirror.
	OverBudget func(ctx context.Context, taskID, reason 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
	// MaxWakes caps how many consecutive wakes one agent gets before it is
	// declared stalled and escalated (0 ⇒ MaxConsecutiveWakes). The throttle
	// bounds the rate; this bounds the total, so a message the agent never clears
	// cannot cost one Claude turn every WakeThrottle forever.
	MaxWakes int
	// Signal stops an owned session (the same verbs as POST
	// /v1/agents/{id}/signal). Injected so the router can actually halt a worker
	// that has outspent its budget — rewriting the task file does not stop a
	// process. nil ⇒ the router can only park the task.
	Signal func(sessionID, action string) error
	// 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 New

func New(h *hive.Hive, st *store.Store, sp Spawner, cwd string, log *slog.Logger) *Orchestrator

New builds an orchestrator.

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

func (o *Orchestrator) SpawnWorker(ctx context.Context, workerID string) (string, error)

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) StopAll added in v0.15.0

func (o *Orchestrator) StopAll() int

StopAll kills the orchestrator session and every worker session it spawned, in one call, and latches the router so it does not immediately respawn them from the still-assigned tasks. It is the emergency stop: an unattended fleet running with --dangerously-skip-permissions previously had no single control that halted it, only per-agent signals a user had to know the session ids for. Returns the number of sessions stopped.

Task files are left exactly as they are — the point is to stop processes, not to rewrite the board. Starting the orchestrator again clears the latch and resumes from the files.

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.

Jump to

Keyboard shortcuts

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