Documentation
¶
Overview ¶
Package hive owns the on-disk orchestration state (Phase 2): one directory per registered project workspace holding agents, tasks, approvals, mailboxes and an append-only ledger. Files are the source of truth; SQLite mirrors them for the UI and is rebuildable by rescan. The hive is the single git committer — agents never run git on it. See .ai/05-orchestration.md.
Index ¶
- Constants
- func CanTransition(from, to string) bool
- func TransitionRoute(from, to string) []string
- type Hive
- func (h *Hive) ArchiveInbox(agentID string, keep func(Message) bool) (int, error)
- func (h *Hive) CreateTask(t Task) error
- func (h *Hive) Deliver() (int, error)
- func (h *Hive) GetTask(id string) (Task, error)
- func (h *Hive) Inbox(agentID string) ([]Message, error)
- func (h *Hive) InboxCount(agentID string) int
- func (h *Hive) Ledger() ([]LedgerEntry, error)
- func (h *Hive) ListTasks() ([]Task, error)
- func (h *Hive) RegisterAgent(id, identity string) error
- func (h *Hive) Seed() error
- func (h *Hive) Send(m Message) (string, error)
- func (h *Hive) UpdateTask(id string, mut func(*Task) error) (Task, error)
- type LedgerEntry
- type Message
- type Task
Constants ¶
const ( KindAssign = "assign" KindResult = "result" KindQuestion = "question" KindEscalation = "escalation" )
Message kinds.
const ( OrchestratorAgentID = "orchestrator" VerifierAgentID = "verifier" )
Well-known agent ids that appear as a message `from`/`to`. Shared here so the orchestrator and the verifier agree on them without a package cycle or drifting string literals.
const ( StatusInbox = "inbox" StatusAssigned = "assigned" StatusInProgress = "in_progress" StatusVerifying = "verifying" StatusNeedsYou = "needs_you" StatusDone = "done" StatusFailed = "failed" )
Task statuses (kanban columns).
Variables ¶
This section is empty.
Functions ¶
func CanTransition ¶
CanTransition reports whether from→to is an allowed board move.
func TransitionRoute ¶ added in v0.12.0
TransitionRoute returns the shortest sequence of legal single steps from `from` to `to` (excluding `from`, including `to`), or nil when `to` is unreachable. It exists because UpdateTask validates start-vs-end only: a caller that needs a multi-hop move (verification finishing a task the orchestrator left in `in_progress`, say) must apply the steps one at a time, and a caller that silently skips an illegal move strands the task instead.
Types ¶
type Hive ¶
type Hive struct {
Root string
// contains filtered or unexported fields
}
Layout:
<hive>/
agents/<agent-id>/{identity.md, memory.md, inbox/, outbox/}
tasks/<task-id>.md
approvals/<id>.json
ledger.jsonl
func (*Hive) ArchiveInbox ¶ added in v0.4.0
ArchiveInbox drains an agent's inbox of messages for which keep returns false, moving them to a sibling `processed/` dir (an audit trail, not a delete). It returns how many were archived. The router uses this to retire fire-once `assign` messages after the worker has picked the task up, so the Stop-loop — which forces continuation while the inbox is non-empty — releases and the worker can stop cleanly. Without it a consumed assign lingers forever, pinning the worker in a re-kick/poll loop. Agents never run git on the hive, so the router (single writer) owns this move, per .ai/05-orchestration.md.
func (*Hive) CreateTask ¶
CreateTask writes a new task file in the inbox column and ledgers it.
func (*Hive) Deliver ¶
Deliver moves every message from every outbox into the recipient's inbox and ledgers each delivery. This is the router's single-writer step. Returns the number delivered.
func (*Hive) GetTask ¶
GetTask reads one task. The id is validated because it is not always user-supplied-and-DB-checked: board.VerifyTask, board.Approve, board.OverBudget and moveTo all reach this directly, and ListTasks returns the `id` parsed from *inside* a task file — so a hand-written file could name `../../x` and turn the next read or UpdateTask write into a path traversal.
func (*Hive) InboxCount ¶
InboxCount returns how many messages an agent has waiting (the Stop-loop check).
func (*Hive) Ledger ¶
func (h *Hive) Ledger() ([]LedgerEntry, error)
Ledger reads the full ledger (newest last).
func (*Hive) RegisterAgent ¶
RegisterAgent creates an agent's directory tree with identity/memory files.
func (*Hive) Seed ¶ added in v0.15.0
Seed writes a README into a *fresh* hive, so the directory documents itself.
A new hive used to be three empty directories with no clue what belonged in them. The README says what the directory is and shows the task file format. It is written only if absent, so Seed never overwrites a user's work.
It used to write an example task too, into tasks/ in the inbox. A sample in the queue is work: the board showed it as waiting and the orchestrator assigned it, with checks (go test, go vet) guessed for a repository the seed had never looked at. The format now lives in the README, and the dashboard's templates (with checks detected from the repo) are the starting points.
type LedgerEntry ¶
type LedgerEntry struct {
Ts int64 `json:"ts"` // unix ms
Kind string `json:"kind"`
AgentID string `json:"agent_id,omitempty"`
TaskID string `json:"task_id,omitempty"`
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
Note string `json:"note,omitempty"`
}
LedgerEntry is one append-only record of a hive state transition.
type Message ¶
type Message struct {
From string `json:"from"`
To string `json:"to"`
Ts int64 `json:"ts"`
TaskID string `json:"task_id,omitempty"`
Kind string `json:"kind"` // assign | result | question | escalation
Body string `json:"body"`
// Name is the on-disk filename (set on read).
Name string `json:"name,omitempty"`
}
Message is a mailbox file: markdown with YAML frontmatter {from,to,ts,task_id?,kind} and a free-form body. See .ai/05-orchestration.md § Mailbox message.
type Task ¶
type Task struct {
ID string `yaml:"id" json:"id"`
Title string `yaml:"title" json:"title"`
Status string `yaml:"status" json:"status"`
Assignee string `yaml:"assignee" json:"assignee"`
BudgetUSD float64 `yaml:"budget_usd" json:"budget_usd"`
DoneCriteria []string `yaml:"done_criteria" json:"done_criteria"`
VerifyRoundsUsed int `yaml:"verify_rounds_used" json:"verify_rounds_used"`
Body string `yaml:"-" json:"body"`
}
Task mirrors tasks/<id>.md (YAML frontmatter + free-form body). See .ai/05-orchestration.md § Task file. Statuses are the kanban columns.