Documentation
¶
Overview ¶
Package owner persists the project owner of a codebase: the single agent that holds a project's criteria, reads reports from the ordinary sessions working on it, and keeps a curated book about it.
An owner lives in the codebase directory the memory store already uses:
~/.config/moa/codebases/<key>/owner.json the entity ~/.config/moa/codebases/<key>/book/ its curated notes
where <key> is core.CodebaseKey(root), so every git worktree of one repository answers to the same owner — the same identity memory is scoped by. There is at most one owner per codebase; a session is a child of that owner when its cwd resolves to the same key, without any manual link.
Index ¶
- Constants
- Variables
- func BookSection(ownerName, projectIndex string) string
- func DetectCanonicalRef(root string) string
- func MigrateAvatarColor(id string) string
- func RolePrompt(ownerName, canonicalRef, prefs string) string
- type Avatar
- type Heartbeat
- type HeartbeatSettings
- type HeartbeatState
- type Owner
- type Report
- type ReportPending
- type ReportsOutbox
- type ReportsUnreadableLane
- type Store
- func (s *Store) BookDir(key string) string
- func (s *Store) CodebaseDir(key string) string
- func (s *Store) Create(root, name, model, thinking string, answerAsks bool, avatar Avatar) (Owner, error)
- func (s *Store) Delete(key string) error
- func (s *Store) FindByCodebase(key string) (Owner, bool, error)
- func (s *Store) FindByDir(dir string) (Owner, bool, error)
- func (s *Store) FindByID(id string) (Owner, bool, error)
- func (s *Store) List() ([]Owner, error)
- func (s *Store) LoadHeartbeatState(key string) HeartbeatState
- func (s *Store) LoadReports(key string) ([]Report, error)
- func (s *Store) LoadReportsOutbox(key string) (ReportsOutbox, error)
- func (s *Store) OwnerPrefs(key string) string
- func (s *Store) ProjectIndex(key string) string
- func (s *Store) Save(own Owner) error
- func (s *Store) SaveHeartbeatState(key string, state HeartbeatState) error
- func (s *Store) SaveReports(key string, reports []Report) error
- func (s *Store) SaveReportsOutbox(key string, out ReportsOutbox, reports []Report) (ReportsOutbox, error)
Constants ¶
const ( DefaultHeartbeatIdleMinutes = 30 DefaultHeartbeatStaleDays = 7 // HeartbeatInterval is how often the evaluator looks. It is not how often // the owner is woken: most ticks find nothing new and end in silence. HeartbeatInterval = 5 * time.Minute )
HeartbeatDefaults are the thresholds an owner.json without a heartbeat block gets. The field is additive: every owner written before it existed keeps working, with these numbers.
const BookDeltaNone = "none"
BookDeltaNone is the value a session uses to say its work changes nothing in the book. It is deliberately distinguishable from an absent delta.
const MaxOwnerPrefsBytes = 16 * 1024
MaxOwnerPrefsBytes caps what OWNER.md contributes to the owner's prompt. It is the user's file and nobody trims it for them, so the prompt does.
const MaxProjectBytes = 8 * 1024
MaxProjectBytes caps what PROJECT.md contributes to a session prompt. It is paid on every turn of every child, so the index is bounded even if the owner lets the file grow.
const ProjectFile = "PROJECT.md"
ProjectFile is the only book file injected into a prompt: the index the owner is responsible for keeping accurate.
Variables ¶
var ( DefaultAvatarShapes = []string{"circle", "squircle", "blob", "hexagon", "drop", "pill"} AvatarShapes = append(slices.Clone(DefaultAvatarShapes), "triangle", "cloud") AvatarColors = []string{"peach", "mauve", "sage", "sky", "azure", "rose", "mint", "lilac"} )
AvatarShapes and AvatarColors are closed lists: anything else is refused on create rather than stored and silently dropped by whatever draws it.
DefaultAvatarShapes is the pool the deterministic default hashes over, and it must never change: DefaultAvatar is `hash % len(pool)`, so appending to it would silently re-face every owner that never chose one. Shapes added later (triangle, cloud) are therefore selectable only — in AvatarShapes, never in the pool.
var ( // ErrExists is returned when a codebase already has an owner: the one // owner per codebase rule is what makes "the owner of this project" // answerable without asking which one. ErrExists = errors.New("this codebase already has an owner") // ErrNotFound reports that no owner.json exists for the requested key/id. ErrNotFound = errors.New("owner not found") // ErrNoConfigDir reports that the config directory could not be resolved, // which disables owners entirely rather than writing to a relative path. ErrNoConfigDir = errors.New("cannot resolve the moa config directory") )
Functions ¶
func BookSection ¶
BookSection is the prompt section injected into every session of a codebase that has an owner: the owner's index (PROJECT.md) plus who the owner is.
Only the index is injected. The rest of the book is read on demand with the book tool, the same layering memory uses — a project's knowledge can be hundreds of pages, and none of it is worth paying for on every turn.
func DetectCanonicalRef ¶
DetectCanonicalRef asks the repository which branch is canonical: origin/HEAD when the remote says so, otherwise master or main if one of them exists. A directory that is not a repository (or a git that does not answer) gives "", which every reader renders as an explicit unknown rather than guessing a name.
It is stored in owner.json and meant to be edited by hand: a project whose truth lives on "develop" says so there.
func MigrateAvatarColor ¶
MigrateAvatarColor answers what to draw for a stored colour id: itself while it is still listed, its replacement when it was renamed, and "" when it is neither — which is what makes the caller fall back to the deterministic default rather than draw nothing.
func RolePrompt ¶
RolePrompt is the owner's own role, injected only into the owner's conversation: what it is, what the book is, when it writes it, what it never decides, and that its job is everything open at once rather than whatever was last said to it.
prefs is book/OWNER.md, the user's preferences for this project. It is placed AFTER the invariants and explicitly subordinated to them: a preferences file that could say "merge when tests pass" would otherwise be a way to grant the owner what the product deliberately withholds.
"You never approve permissions" is policy for a cooperative agent, not a security barrier: the owner runs with bash like any other session and could do by hand what it is told not to authorize. What actually bounds it is the capability set of each session — its permission mode and allowed paths.
Types ¶
type Avatar ¶
Avatar is the mark. Both fields are required once the value is non-empty; a zero Avatar means "never chosen" and resolves to DefaultAvatar.
func DefaultAvatar ¶
DefaultAvatar is the deterministic mark of a codebase. Hashed from the codebase key rather than the name, so renaming an owner does not change its face, and with two independent seeds, or shape and colour would march in lockstep and the 48 combinations would collapse to 8.
type Heartbeat ¶
type Heartbeat struct {
Enabled *bool `json:"enabled,omitempty"`
IdleMinutes int `json:"idle_minutes,omitempty"`
StaleDays int `json:"stale_days,omitempty"`
}
Heartbeat is the per-owner configuration. Enabled is a pointer so "absent" (default on) is distinguishable from an explicit false.
type HeartbeatSettings ¶
HeartbeatSettings is the resolved configuration, defaults applied.
type HeartbeatState ¶
type HeartbeatState struct {
Announced map[string]time.Time `json:"announced"`
LastBeat time.Time `json:"last_beat,omitzero"`
}
HeartbeatState is the persisted memory of the last beat: the facts announced, keyed by a stable identity (see the evaluator in pkg/serve), and when.
type Owner ¶
type Owner struct {
ID string `json:"id"`
Name string `json:"name"`
CodebaseKey string `json:"codebase_key"`
Root string `json:"root"`
SessionID string `json:"session_id,omitempty"`
Model string `json:"model,omitempty"`
Thinking string `json:"thinking,omitempty"`
// AnswerAsks allows the owner to resolve a child's ask_user. Permissions
// are never delegated: only questions.
AnswerAsks bool `json:"answer_asks"`
// CanonicalRef is the branch whose state areas/ describes (see git.go).
// Detected once at creation and editable by hand; empty means the position
// is unknown, which readers state explicitly instead of guessing. Additive:
// an owner.json written before it existed simply has no canonical ref.
CanonicalRef string `json:"canonical_ref,omitempty"`
// Avatar is the identity mark (see avatar.go). Additive and optional: an
// owner without one resolves to DefaultAvatar(CodebaseKey), so an owner.json
// written before avatars existed needs no migration.
Avatar Avatar `json:"avatar,omitzero"`
// Heartbeat tunes the owner's own clock (see heartbeat.go). Additive and
// optional: nil means the defaults.
Heartbeat *Heartbeat `json:"heartbeat,omitempty"`
Created time.Time `json:"created"`
}
Owner is the persisted entity. Model and Thinking are the conversation's defaults at creation time; the session owns them afterwards, like any other.
func (Owner) HeartbeatSettings ¶
func (o Owner) HeartbeatSettings() HeartbeatSettings
HeartbeatSettings resolves the owner's configuration.
func (Owner) ResolvedAvatar ¶
ResolvedAvatar is what a client should draw: the chosen mark, or the deterministic default when none was chosen or the stored one is not in the closed lists any more.
type Report ¶
type Report struct {
ID string `json:"id"`
SessionID string `json:"session_id"`
Title string `json:"title,omitempty"`
CWD string `json:"cwd,omitempty"`
Origin string `json:"origin"`
Status string `json:"status"`
FinalText string `json:"final_text,omitempty"`
Pending *ReportPending `json:"pending,omitempty"`
// BookDelta is what the session says its work changes about the book,
// lifted from the FULL final message before FinalText was abridged:
// a delta that only exists in the part that was cut is a delta the
// owner never applies. Empty means the session did not say (the owner has
// to ask); "none" is the session saying nothing changes, which is an answer.
BookDelta string `json:"book_delta,omitempty"`
// GitAvailable reports that the three fields below were ALL answered. It
// exists because a partial answer is indistinguishable from good news: a
// branch with no head and dirty=false reads as verified, committed work
// when it may only mean `git status` timed out. False means the position
// is unknown and the owner is told so.
GitAvailable bool `json:"git_available,omitempty"`
// Branch / Head / Dirty place the work in the repository, which is what
// decides where the delta goes: the canonical branch (see Owner.
// CanonicalRef) updates areas/, any other branch updates work/. Only
// meaningful when GitAvailable.
Branch string `json:"branch,omitempty"`
Head string `json:"head,omitempty"`
Dirty bool `json:"dirty,omitempty"`
// BackgroundCount is how much autonomous work was still running when the
// turn was reported: async subagents, background bash jobs, verifiers. A
// report describes a completed semantic turn, not a quiet session — a
// child that leaves a dev server running is done with what it was asked,
// and the owner has to be told the difference. Zero (and absent from the
// outbox) means the session had fully quiesced.
BackgroundCount int `json:"background_count,omitempty"`
At string `json:"at,omitempty"` // RFC3339
}
Report is one child session's outcome on its way to the owner. It is the persisted shape of the outbox: the serve layer builds it from a run outcome and renders it into the message the owner reads.
It lives here, next to the store, because the outbox file has to be readable at startup before any session exists — recovery happens before the manager has runtimes to ask.
type ReportPending ¶
type ReportPending struct {
Kind string `json:"kind"` // question | permission
ID string `json:"id,omitempty"`
Text string `json:"text,omitempty"`
}
ReportPending is what a blocked session is waiting for, carried literally so the owner reads the question (or the permission) as it was asked rather than a paraphrase of it.
type ReportsOutbox ¶
type ReportsOutbox struct {
Reports []Report
Lanes []string
CanonicalPath string
ActivePath string
Unreadable []ReportsUnreadableLane
CanonicalUnreadable bool
// ActiveRecoveryOwned is an incomplete-load recovery lane this coordinator
// created exclusively. It is safe to update, but never to use as evidence
// that the original lanes may be removed.
ActiveRecoveryOwned bool
// Incomplete means enumeration or target selection failed after some lanes
// were read. Saves must use a new recovery lane and must not remove sources.
Incomplete bool
IncompleteErr error
}
ReportsOutbox is the set of readable report lanes a coordinator owns. The canonical lane is deliberately not included when it cannot be decoded: its bytes belong to the person repairing it, not to the next atomic save.
type ReportsUnreadableLane ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store reads and writes owners under a config directory.
func Default ¶
Default builds a Store over the resolved config directory, or an error when there is none.
func (*Store) CodebaseDir ¶
CodebaseDir is ~/.config/moa/codebases/<key>.
func (*Store) Create ¶
func (s *Store) Create(root, name, model, thinking string, answerAsks bool, avatar Avatar) (Owner, error)
Create writes a new owner for the codebase containing root and seeds its book with a PROJECT.md template. root is canonicalized so the stored path is the one CodebaseKey was computed from.
avatar is the chosen identity mark. A zero one takes the deterministic default of the codebase; a non-zero one that is not in the closed lists is refused rather than stored, so nothing on disk can be undrawable.
func (*Store) Delete ¶
Delete removes owner.json. The book is deliberately kept: it is curated project knowledge that outlives the agent that wrote it, and a new owner for the same codebase picks it up.
func (*Store) FindByCodebase ¶
FindByCodebase returns the owner of a codebase key, if any. A malformed owner.json is an error rather than "no owner": silently treating it as absent would let a second owner be created over the first.
func (*Store) FindByID ¶
FindByID scans the codebase directories for an owner with this ID. Owners are few (one per project), so a scan is cheaper than a second index that could disagree with the files.
func (*Store) LoadHeartbeatState ¶
func (s *Store) LoadHeartbeatState(key string) HeartbeatState
LoadHeartbeatState returns what the previous beats announced. A missing or unreadable file is an empty state: the worst case is one repeated nudge, which is cheaper than refusing to beat at all.
func (*Store) LoadReports ¶
LoadReports returns the pending outbox of a codebase. A missing file is an empty outbox; a malformed one is an error, so a coordinator never silently drops reports it cannot read.
func (*Store) LoadReportsOutbox ¶
func (s *Store) LoadReportsOutbox(key string) (ReportsOutbox, error)
LoadReportsOutbox reads every readable report lane. Recovery lanes are kept separate from an unreadable canonical file, so accepting another report can never replace evidence a person needs to repair.
func (*Store) OwnerPrefs ¶
OwnerPrefs returns book/OWNER.md: the user's preferences for how this owner should work. It is read through the same loader PROJECT.md uses, so editing it reaches a live conversation on /reload, and it is never written by the owner (pkg/book refuses it): instructions the agent can rewrite are not instructions.
func (*Store) ProjectIndex ¶
ProjectIndex returns PROJECT.md truncated to MaxProjectBytes, or "" when the book has none. A missing or unreadable file is not an error: the prompt simply carries no book section.
func (*Store) SaveHeartbeatState ¶
func (s *Store) SaveHeartbeatState(key string, state HeartbeatState) error
SaveHeartbeatState replaces the record atomically.
func (*Store) SaveReports ¶
SaveReports replaces the outbox atomically. An empty list removes the file rather than leaving an empty array behind.
func (*Store) SaveReportsOutbox ¶
func (s *Store) SaveReportsOutbox(key string, out ReportsOutbox, reports []Report) (ReportsOutbox, error)
SaveReportsOutbox durably replaces the readable outbox lanes. It only removes old readable lanes after the replacement is on disk. An unreadable canonical or recovery lane is never a source and is therefore untouched.