owner

package
v0.45.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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 that turns the heartbeat on gets when it does not name its own numbers. They only apply once "enabled" is explicitly true (see HeartbeatSettings): the evaluator only looks at a file's mtime and cannot tell a job that stalled from one that was deliberately parked or already finished, so it stays off until asked for.

View Source
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.

View Source
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.

View Source
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.

View Source
const ProjectFile = "PROJECT.md"

ProjectFile is the only book file injected into a prompt: the index the owner is responsible for keeping accurate.

Variables

View Source
var (
	DefaultAvatarShapes = []string{"circle", "squircle", "blob", "hexagon", "drop", "pill"}
	AvatarShapes        = append(slices.Clone(DefaultAvatarShapes),
		"triangle", "cloud", "flower", "ghost", "bean", "diamond", "shield", "bell")
	AvatarColors = []string{"peach", "mauve", "sage", "sky", "azure", "rose", "mint", "lilac"}
	AvatarTones  = []string{"deep", "dark", "pale"}
)

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, and the six after them) are therefore selectable only — in AvatarShapes, never in the pool.

AvatarTones is the third axis: the same eight hues at three lightnesses. It is optional in owner.json and an empty tone means "deep", the body every owner had before tones existed, so an owner.json without one is drawn exactly as before. The default never picks a tone for the same reason the shape pool never grows.

View Source
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

func BookSection(ownerName, projectIndex string) string

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

func DetectCanonicalRef(root string) string

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

func MigrateAvatarColor(id string) string

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

func RolePrompt(ownerName, canonicalRef, prefs string) string

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

type Avatar struct {
	Shape string `json:"shape"`
	Color string `json:"color"`
	Tone  string `json:"tone,omitempty"`
}

Avatar is the mark. Shape and colour are required once the value is non-empty; a zero Avatar means "never chosen" and resolves to DefaultAvatar. Tone is optional: empty is "deep".

func DefaultAvatar

func DefaultAvatar(codebaseKey string) Avatar

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.

func (Avatar) IsZero

func (a Avatar) IsZero() bool

IsZero reports whether nothing was chosen.

func (Avatar) Valid

func (a Avatar) Valid() bool

Valid reports whether every axis is one of the closed lists (an empty tone included, since it is the default one).

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 an owner that never mentions it, one with the block but no "enabled" key, and an explicit false all read the same: off. The evaluator only sees a file's mtime, not whether the work behind it stopped, was parked on purpose, or is simply done, so it only runs when the owner.json asks for it with "enabled": true.

type HeartbeatSettings

type HeartbeatSettings struct {
	Enabled     bool
	IdleMinutes int
	StaleDays   int
}

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

func (o Owner) ResolvedAvatar() Avatar

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 ReportsUnreadableLane struct {
	Path string
	Err  error
}

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store reads and writes owners under a config directory.

func Default

func Default() (*Store, error)

Default builds a Store over the resolved config directory, or an error when there is none.

func NewStore

func NewStore(configDir string) *Store

NewStore builds a Store over a moa config root (~/.config/moa).

func (*Store) BookDir

func (s *Store) BookDir(key string) string

BookDir is the owner's book directory for a codebase.

func (*Store) CodebaseDir

func (s *Store) CodebaseDir(key string) string

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

func (s *Store) Delete(key string) error

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

func (s *Store) FindByCodebase(key string) (Owner, bool, error)

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) FindByDir

func (s *Store) FindByDir(dir string) (Owner, bool, error)

FindByDir returns the owner responsible for a working directory.

func (*Store) FindByID

func (s *Store) FindByID(id string) (Owner, bool, error)

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) List

func (s *Store) List() ([]Owner, error)

List returns every owner on disk, sorted by name.

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

func (s *Store) LoadReports(key string) ([]Report, error)

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

func (s *Store) OwnerPrefs(key string) string

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

func (s *Store) ProjectIndex(key string) string

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) Save

func (s *Store) Save(own Owner) error

Save writes owner.json atomically.

func (*Store) SaveHeartbeatState

func (s *Store) SaveHeartbeatState(key string, state HeartbeatState) error

SaveHeartbeatState replaces the record atomically.

func (*Store) SaveReports

func (s *Store) SaveReports(key string, reports []Report) error

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.

Jump to

Keyboard shortcuts

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