Documentation
¶
Overview ¶
Package board is the Phase 2 task board: it bridges the hive's task files and mailboxes to the SQLite mirror and the API. It also answers the Stop hook to force a worker to keep going while its inbox is non-empty (the autonomy engine), with a hard per-(session,task) guard. See .ai/05-orchestration.md.
Index ¶
- Constants
- Variables
- func IsDestructive(command string) (bool, string)
- func ScreenDoneCriteria(criteria []string) []string
- func WorktreePath(repo, workerID string) string
- type Board
- func (b *Board) Approvals(ctx context.Context) (any, error)
- func (b *Board) Approve(ctx context.Context, id string, approve bool) error
- func (b *Board) Create(ctx context.Context, req any) (any, error)
- func (b *Board) Get(ctx context.Context, id string) (any, error)
- func (b *Board) List(ctx context.Context) (any, error)
- func (b *Board) Rescan(ctx context.Context) error
- func (b *Board) StopDecision(ctx context.Context, sessionID, agentID, taskID string) []byte
- func (b *Board) Verify(ctx context.Context, taskID, cwd string) (VerifyResult, error)
- func (b *Board) VerifyTask(ctx context.Context, id string) (VerifyResult, error)
- type CommandRun
- type CreateRequest
- type VerifyResult
Constants ¶
const MaxForcedContinues = 10
MaxForcedContinues is the Stop-loop guard: after this many forced continues for one (session, task), Caprock escalates to the human instead (default 10).
const MaxVerifyRounds = 3
MaxVerifyRounds is the verification-bounce guard (default 3): after this many failed rounds a task escalates to needs_you instead of bouncing again.
const VerifyCommandTimeout = 5 * time.Minute
VerifyCommandTimeout bounds a single done_criteria command.
Variables ¶
var DestructivePatterns = []*regexp.Regexp{ regexp.MustCompile(`\brm\s+(-[a-zA-Z]*\s+)*-[a-zA-Z]*[rf]`), regexp.MustCompile(`\brm\s+-[a-zA-Z]*f`), regexp.MustCompile(`\bgit\s+push\b`), regexp.MustCompile(`\bgit\s+.*\bpush\s+.*--force|\bgit\s+push\s+-f\b`), regexp.MustCompile(`\bgit\s+reset\s+--hard\b`), regexp.MustCompile(`\bgit\s+clean\s+-[a-zA-Z]*[dfx]`), regexp.MustCompile(`\bsudo\b`), regexp.MustCompile(`\b(shutdown|reboot|halt|poweroff)\b`), regexp.MustCompile(`\bmkfs\b|\bdd\s+if=`), regexp.MustCompile(`>\s*/dev/sd|\bfdisk\b`), regexp.MustCompile(`\bcurl\b.*\|\s*(sh|bash)\b|\bwget\b.*\|\s*(sh|bash)\b`), regexp.MustCompile(`\bkubectl\s+delete\b|\bterraform\s+(destroy|apply)\b`), regexp.MustCompile(`\bnpm\s+publish\b|\bcargo\s+publish\b|\btwine\s+upload\b|\bgoreleaser\s+release\b`), regexp.MustCompile(`:\(\)\s*\{.*\|.*&\s*\}`), }
DestructivePatterns are commands a task must not run unattended — they land the task in needs_you for a human to approve instead. Conservative on purpose: these are irreversible or outside-the-repo actions. Users can extend the list via config later; this is the built-in floor. See .ai/05-orchestration.md § Approvals.
Functions ¶
func IsDestructive ¶
IsDestructive reports whether a command matches the destructive policy, and the first pattern it matched (for the escalation message).
func ScreenDoneCriteria ¶
ScreenDoneCriteria returns the destructive commands among a task's done_criteria (empty when all are safe). The verification runner uses this to send a task to needs_you instead of running a dangerous command unattended.
func WorktreePath ¶
WorktreePath returns the worktree dir for a worker under the repo, matching how the orchestrator's worker spawn creates it.
Types ¶
type Board ¶
type Board struct {
Hive *hive.Hive
Store *store.Store
Bus *bus.Bus
Log *slog.Logger
Now func() time.Time
// RepoCwd is the repo tasks operate on; verification commands run in the
// assigned worker's worktree under it, or in RepoCwd when there is no worktree.
RepoCwd string
// contains filtered or unexported fields
}
Board wires the hive, store mirror and bus.
func (*Board) Approve ¶
Approve/reject a task in the needs-you column, feeding the decision back to the orchestrator via a mailbox message.
func (*Board) Rescan ¶
Rescan rebuilds the SQLite task mirror from the hive files (source of truth).
func (*Board) StopDecision ¶
StopDecision answers a worker's Stop hook: block (force continue) while the worker's inbox is non-empty and the guard is not exhausted; else allow the stop. Returns the JSON body to relay to Claude Code, or nil to allow.
func (*Board) Verify ¶
Verify runs a task's done_criteria in the worker's worktree. All green ⇒ the task moves to done. Any red ⇒ it bounces back to the worker with the failing output (up to MaxVerifyRounds, then it escalates to needs_you). Cwd is the directory the commands run in (the worker's worktree, or the repo).
func (*Board) VerifyTask ¶
VerifyTask (controller entry) resolves the worktree for the assigned worker and runs verification.
type CommandRun ¶
type CommandRun struct {
Command string `json:"command"`
ExitCode int `json:"exit_code"`
Output string `json:"output"`
Passed bool `json:"passed"`
}
CommandRun is one done_criteria command's result.
type CreateRequest ¶
type CreateRequest struct {
ID string `json:"id"`
Title string `json:"title"`
BudgetUSD float64 `json:"budget_usd"`
DoneCriteria []string `json:"done_criteria"`
Body string `json:"body"`
}
CreateRequest is the POST /v1/tasks body.
type VerifyResult ¶
type VerifyResult struct {
TaskID string `json:"task_id"`
Round int `json:"round"`
Passed bool `json:"passed"`
Commands []CommandRun `json:"commands"`
Status string `json:"status"` // the task's new status
Escalated bool `json:"escalated"`
}
VerifyResult reports the outcome of running a task's done_criteria.