Documentation
¶
Overview ¶
Background-task helpers. `bee bg` spawns detached child engines and drops their stdout/stderr under <beeHome>/sessions/bg/<session-id>.log. Pure helpers — no exec, no syscall — so the package stays portable.
Result fan-in helpers. Plain functions over []Result so callers can compose them without bringing in the Pool dependency.
Queen-and-workers orchestration.
The Queen runs three or four phases:
- decompose: ask Planner Runner to split the task into ≤8 sub-tasks (JSON objects pairing role + task).
- dispatch: round-robin sub-tasks to Workers, fan out via goroutines.
- review: (optional) hand worker outputs to Critic for a short critique.
- synthesize: hand all worker outputs (plus critique if any) back to Planner for a final summary.
Pool from spawn.go (slice 4A) is preferred when available; this file uses direct goroutine fan-out so the queen still builds even if 4A is missing.
Fan-out orchestrator. Spawns up to MaxConcurrency workers in parallel, each driving its own Engine via the Runner contract. Results stream out on a channel as workers finish; cancellation propagates through ctx.
Package hive implements multi-bee orchestration: fan-out (Pool), queen-and- workers (Queen), and the result fan-in primitives both share.
A Worker wraps a single loop.Engine running in its own goroutine. The TUI visual concept lives in internal/tui/hive.go and is intentionally separate.
Index ¶
- Constants
- func EnsureLogDir(sessionID string) (string, error)
- func LogDir() (string, error)
- func LogPath(sessionID string) (string, error)
- func MergeText(results []Result) string
- func ReadPid(sessionID string) (int, error)
- func Summary(results []Result) string
- func WritePid(sessionID string, pid int) error
- type Pool
- type Queen
- type QueenResult
- type Result
- type Role
- type Runner
- type State
- type SubTask
- type Worker
Constants ¶
const MaxSubTasks = 8
MaxSubTasks caps how many sub-tasks the queen will accept from the planner. matches the prompt budget; defends against runaway plans.
Variables ¶
This section is empty.
Functions ¶
func EnsureLogDir ¶
EnsureLogDir creates the parent directory for LogPath and returns the fully-qualified log path. Idempotent.
func LogPath ¶
LogPath returns the absolute path where a background session's combined stdout/stderr should be written. It does not create anything on disk.
func MergeText ¶
MergeText concatenates the final text from each successful worker into a single transcript with `## <name>` headers. Failed workers are omitted.
Types ¶
type Pool ¶
Pool manages a bounded set of concurrent Workers.
func NewPool ¶
NewPool builds a Pool with the given concurrency cap. A non-positive cap is treated as 1 — refusing to run any work would surprise callers.
func (*Pool) Run ¶
Run dispatches submitted workers up to MaxConcurrency at a time. Each worker's Engine.Run is invoked with a context derived from ctx. Results land on the returned channel as workers finish; the channel closes once all workers are done (including those skipped by cancellation).
func (*Pool) Submit ¶
Submit registers a Worker with the pool. State starts at pending. Safe to call before Run; calling after Run is a no-op for that worker because the dispatcher has already iterated the snapshot.
func (*Pool) WorkersSnapshot ¶
WorkersSnapshot returns a shallow copy of the Worker pointer slice for observers (TUI, tests). The pointed-to Worker structs are still shared, so reading State/Started/Ended is a live view.
type Queen ¶
type Queen struct {
Planner Runner
Workers []Runner
Critic Runner
MaxParallel int // 0 => len(Workers)
}
Queen orchestrates a planner Runner and N worker Runners. Critic is optional; when set, its output is appended to the synthesize prompt.
type QueenResult ¶
QueenResult is the aggregate of one Queen.Run.
type Result ¶
type Result struct {
WorkerID string
Name string
Task string
Final string
Err error
Started time.Time
Ended time.Time
}
Result is what a Worker emits on completion. Final is the final assistant text; Err is non-nil if the run failed.
type Role ¶
type Role string
Role names a hive specialist. Each role pairs a tuned system prompt with a tool allowlist. The queen.go / pool.go wiring decides defaults when a role's AllowedTools is empty.
const ( RoleQueen Role = "queen" RoleSubqueen Role = "subqueen" RoleBuilder Role = "builder" RoleScoutPlanner Role = "scout_planner" RoleForeman Role = "foreman" RoleSage Role = "sage" RoleArchivist Role = "archivist" RoleForager Role = "forager" RoleDiviner Role = "diviner" RoleCritic Role = "critic" RoleEye Role = "eye" )
func ParseRole ¶
ParseRole accepts the canonical name (case-insensitive) and returns the Role + ok. Whitespace is trimmed.
func (Role) AllowedTools ¶
AllowedTools returns the tool names this role may invoke. Empty slice means "all tools" — caller decides default. Returned slice is a copy.
func (Role) SystemPrompt ¶
SystemPrompt returns the role-tuned system prompt text. Empty for unknown roles.
func (Role) Temperature ¶
Temperature returns the recommended sampling temperature for the role.
type Runner ¶
Runner is the contract Pool and Queen both rely on. It exists so callers can inject a stub Runner in tests instead of a real loop.Engine.