agents

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 13 Imported by: 0

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

View Source
const MergeBase = "main"

MergeBase is the branch every agent rebases onto. Hardcoded for v1.

Variables

This section is empty.

Functions

func MergeLockPath

func MergeLockPath() (string, error)

MergeLockPath returns ~/.bee/agents/merge.lock.

func MergerLoop

func MergerLoop(ctx context.Context, repoRoot string, interval time.Duration)

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 Root

func Root() (string, error)

Root returns ~/.bee/agents (created on demand).

func WorktreePath

func WorktreePath(id string) (string, error)

WorktreePath returns ~/.bee/agents/worktrees/<id>.

func WorktreeRoot

func WorktreeRoot() (string, error)

WorktreeRoot returns ~/.bee/agents/worktrees.

Types

type ClearResult

type ClearResult struct {
	Removed []string
	Errors  map[string]error
}

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

type MergeAttempt struct {
	SessionID string
	OK        bool
	Conflict  bool
	Err       error
	Output    string
}

MergeAttempt is the outcome of one merge pass.

func TryMerge

func TryMerge(ctx context.Context, repoRoot string, st bgreg.Status) MergeAttempt

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

func AcquireLock() (*MergeLock, bool, error)

AcquireLock attempts to take the merge lock. Returns ok=false (no error) when another live process holds it; the caller can retry later.

func (*MergeLock) Release

func (l *MergeLock) Release()

Release removes the lock file. Safe to call on a nil receiver.

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.

Jump to

Keyboard shortcuts

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