Documentation
¶
Overview ¶
Package agents drives the "bee agents" parallel-agent mode. Each agent runs in its own git worktree as a detached headless `bee run --bg-loop` process. The TUI overview spawns, lists, and merges them. State is file-based (bgreg) so the TUI can be killed and restarted without losing running agents.
Index ¶
- Constants
- func MergeLockPath() (string, error)
- func MergerLoop(ctx context.Context, repoRoot string, interval time.Duration)
- func Root() (string, error)
- func WorktreePath(id string) (string, error)
- func WorktreeRoot() (string, error)
- type ClearResult
- type MergeAttempt
- type MergeLock
- type SpawnOpts
- type SpawnResult
Constants ¶
const MergeBase = "main"
MergeBase is the branch every agent rebases onto. Hardcoded for v1.
Variables ¶
This section is empty.
Functions ¶
func MergeLockPath ¶
MergeLockPath returns ~/.bee/agents/merge.lock.
func MergerLoop ¶
MergerLoop wakes every interval and tries to merge any agent that's done but not yet merged. Caller cancels via ctx. Fully autonomous — no manual retry channel; the user attaches via `bee back` to resolve conflicts.
func WorktreePath ¶
WorktreePath returns ~/.bee/agents/worktrees/<id>.
func WorktreeRoot ¶
WorktreeRoot returns ~/.bee/agents/worktrees.
Types ¶
type ClearResult ¶
ClearResult lists ids removed and any errors hit per id.
func ClearMerged ¶
func ClearMerged(repoRoot string) ClearResult
ClearMerged removes every session whose merge state is "merged": status sidecar, inbox, worktree (if any), log. RepoRoot is needed to drop worktrees via `git worktree remove`. Sessions with WorktreePath still on disk get a best-effort plain dir removal as a fallback when git refuses (already-gone branch, etc.).
type MergeAttempt ¶
MergeAttempt is the outcome of one merge pass.
func TryMerge ¶
TryMerge attempts to rebase an agent's branch onto MergeBase and FF-merge the result back into MergeBase. The merge lock is held for the full rebase+FF window so concurrent agents serialize through this.
Outcomes:
- ok=true: branch merged into main.
- conflict=true: rebase hit conflict; an inbox message was posted to the agent to ask it to resolve. Status flips to awaiting.
- err != nil with neither flag: something unexpected; status preserved.
type MergeLock ¶
type MergeLock struct {
// contains filtered or unexported fields
}
MergeLock is an advisory single-host lock for the merge coordinator. Held for the full rebase+FF window so two agents can't race onto main. Stale locks (dead PID) are stolen on acquire.
func AcquireLock ¶
AcquireLock attempts to take the merge lock. Returns ok=false (no error) when another live process holds it; the caller can retry later.
type SpawnOpts ¶
type SpawnOpts struct {
Prompt string
Model string
Provider string
RepoRoot string // explicit; caller resolves
}
SpawnOpts configures one agent spawn. Prompt is the initial user message. Model/Provider override the user's defaults (empty = use defaults).
type SpawnResult ¶
type SpawnResult struct {
SessionID string
Branch string
WorktreePath string
PID int
LogPath string
}
SpawnResult is what the TUI shows after a successful spawn.
func Spawn ¶
func Spawn(opts SpawnOpts) (SpawnResult, error)
Spawn creates an isolated worktree, writes an initial bgreg status, then re-execs bee in headless bg-loop mode with cwd set to the worktree. The child runs detached (Setsid) so killing the TUI doesn't kill the agent.