Documentation
¶
Overview ¶
Package bgreg is the per-session status sidecar registry for background bees. The bg engine writes; the agent-view TUI reads. One JSON file per session at <beeHome>/sessions/bg/<id>.status.json, written via temp+rename for atomic replacement.
Inbox IPC. Agent-view TUI appends user follow-up messages to a per-session JSONL file; bg loop tails it from a byte cursor at every turn boundary.
Index ¶
- Variables
- func InboxAppend(sessionID, text string) error
- func InboxRemove(sessionID string) error
- func Remove(sessionID string) error
- func Truncate(s string) string
- func Update(sessionID string, fn func(*Status) error) error
- func Write(s Status) error
- type Inbox
- type MergeState
- type PruneOpts
- type PruneResult
- type State
- type Status
Constants ¶
This section is empty.
Variables ¶
var ErrStaleUpdate = errors.New("bgreg: stale update (version moved during fn)")
ErrStaleUpdate signals that the status changed during an Update callback — indicates a writer bypassed the lock (used Write directly). Callers can retry Update.
Functions ¶
func InboxAppend ¶
func InboxRemove ¶
func Update ¶
Update performs an atomic read-modify-write on the status for sessionID. fn receives a copy of the current Status; mutating fields and returning nil commits the change with a bumped Version. The status file is locked via a per-session sidecar (.lock) so concurrent Update calls — even across processes — serialize. fn returning a non-nil error aborts the write.
ErrStaleUpdate is returned if the on-disk Version advanced while fn ran (only possible if fn took longer than the lock acquisition retry window or if a writer bypassed Update — Write keeps last-writer-wins semantics).
Types ¶
type MergeState ¶
type MergeState string
MergeState tracks agent-mode branch lifecycle. Empty string for legacy bg sessions that don't run on a worktree.
const ( MergeStateNone MergeState = "" MergeStateUnmerged MergeState = "unmerged" MergeStateMerging MergeState = "merging" MergeStateMerged MergeState = "merged" MergeStateConflict MergeState = "conflict" )
type PruneOpts ¶
PruneOpts mirrors zzz.PruneOpts: thresholds are AND-ed. Zero disables the matching threshold. Active/awaiting sessions are always preserved — only terminal (done, failed) sidecars are candidates.
type PruneResult ¶
PruneResult lists removed session IDs.
func Prune ¶
func Prune(opts PruneOpts) PruneResult
Prune sweeps ~/.bee/sessions/bg/ removing terminal Status sidecars per opts.
type Status ¶
type Status struct {
SchemaV int `json:"schema_v"`
Version int `json:"version"` // monotonic write-generation, used by Update CAS
SessionID string `json:"session_id"`
PID int `json:"pid"`
State State `json:"state"`
Task string `json:"task"`
LastResponse string `json:"last_response"`
Model string `json:"model"`
Provider string `json:"provider,omitempty"`
Cwd string `json:"cwd"`
StartedAt time.Time `json:"started_at"`
UpdatedAt time.Time `json:"updated_at"`
FinishedAt time.Time `json:"finished_at,omitempty"`
// agent-mode fields. Empty / zero on legacy bg sessions.
WorktreePath string `json:"worktree_path,omitempty"`
Branch string `json:"branch,omitempty"`
MergeState MergeState `json:"merge_state,omitempty"`
ConflictMsg string `json:"conflict_msg,omitempty"`
InputTokens int `json:"input_tokens,omitempty"`
OutputTokens int `json:"output_tokens,omitempty"`
}