hive

package
v0.196.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 10 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 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

View Source
const (
	KindAssign     = "assign"
	KindResult     = "result"
	KindQuestion   = "question"
	KindEscalation = "escalation"
)

Message kinds.

View Source
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.

View Source
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

func CanTransition(from, to string) bool

CanTransition reports whether from→to is an allowed board move.

func TransitionRoute added in v0.12.0

func TransitionRoute(from, to string) []string

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 Open

func Open(root string) (*Hive, error)

Open creates (if needed) the hive directory structure at root.

func (*Hive) ArchiveInbox added in v0.4.0

func (h *Hive) ArchiveInbox(agentID string, keep func(Message) bool) (int, error)

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

func (h *Hive) CreateTask(t Task) error

CreateTask writes a new task file in the inbox column and ledgers it.

func (*Hive) Deliver

func (h *Hive) Deliver() (int, error)

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

func (h *Hive) GetTask(id string) (Task, error)

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) Inbox

func (h *Hive) Inbox(agentID string) ([]Message, error)

Inbox lists an agent's inbox messages, oldest first.

func (*Hive) InboxCount

func (h *Hive) InboxCount(agentID string) int

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) ListTasks

func (h *Hive) ListTasks() ([]Task, error)

ListTasks returns all tasks sorted by id.

func (*Hive) RegisterAgent

func (h *Hive) RegisterAgent(id, identity string) error

RegisterAgent creates an agent's directory tree with identity/memory files.

func (*Hive) Seed added in v0.15.0

func (h *Hive) Seed() error

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.

func (*Hive) Send

func (h *Hive) Send(m Message) (string, error)

Send writes a message into the sender's outbox. The router later delivers it.

func (*Hive) UpdateTask

func (h *Hive) UpdateTask(id string, mut func(*Task) error) (Task, error)

UpdateTask applies a mutation under the lock, validating status transitions, and ledgers the change.

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.

Jump to

Keyboard shortcuts

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