Documentation
¶
Overview ¶
Package book implements the project owner's book: the curated, on-disk record of a project that lives beside its memory (~/.config/moa/codebases/<key>/book/).
Memory holds atomic operational facts any session may write. The book holds criteria and narrative, and has a single author: the owner. That is why it is a separate store with a separate tool — two write policies cannot share one.
Only PROJECT.md is injected into a prompt (see pkg/owner). Everything else is read on demand through this tool, so the book can grow without taxing every turn.
Index ¶
- Constants
- Variables
- func CleanPath(rel string) string
- func NewTool(dir string, writable bool) core.Tool
- func ReadFile(dir, rel string) ([]byte, error)
- func ReadOnlyVariant(t core.Tool) (core.Tool, bool)
- func RelativeAge(d time.Duration) string
- func Template() map[string]string
- func WriteFile(dir, rel string, content []byte) error
- type Entry
- type Hit
Constants ¶
const OwnerFile = "OWNER.md"
OwnerFile is the user's preferences file, read into the owner's prompt.
const ToolName = "book"
ToolName is the registered name, so callers can find the tool in a registry without repeating the literal.
Variables ¶
var ErrTooLarge = fmt.Errorf("the file is larger than %dKB; split it across book files", maxWriteBytes/1024)
ErrTooLarge reports a write past maxWriteBytes.
var ReservedFiles = map[string]bool{ "OWNER.md": true, }
ReservedFiles are book paths the owner's tool must never write. OWNER.md is the user's half of the contract — the preferences the owner is given — and an agent that can rewrite its own instructions has none.
Functions ¶
func CleanPath ¶
CleanPath normalizes a book path to the one form every rule is applied to: slash-separated, no leading "./", no trailing slash. It is the first thing any action does with a path, so "./OWNER.md" and "areas/../OWNER.md" are the same file to the reserved-file check and to the walk.
func NewTool ¶
NewTool builds the book tool over dir. When writable is false the tool offers reading only: every session of the codebase reads the book, but only the owner writes it, and a tool that merely refused at execution time would still invite the attempt on every turn.
func ReadFile ¶
ReadFile returns one book file verbatim, refusing anything that would leave the book (resolve is the single guard, shared with the tool). The tool's 64KB truncation is deliberately NOT applied: it exists to protect a prompt, and a person opening a file wants the file.
func ReadOnlyVariant ¶
ReadOnlyVariant returns the reading half of a book tool. It exists for subagents: a child inherits its parent's tools, and an owner's child must be able to read the book without rewriting the project's record from the paragraph of context it was handed. It reports false for any tool that is not the book.
The downgrade is the schema as well as the check: a child offered "write" in its tool list would attempt it every time the task sounds like note-taking. It also hides the reserved files — book/OWNER.md is the user's instructions to the owner, and "never to children" has to be invisibility, not a refusal to write.
func RelativeAge ¶
RelativeAge says how long ago something happened, at the resolution a decision is made on: minutes for today, hours, then days. The phrase carries its own "ago" so "just now ago" cannot happen. It is exported because the owner's sessions listing answers the same question about a conversation.
func Template ¶
Template is the initial book: one file per part of the schema, each explaining in two lines what belongs in it. It is a shape to fill, not content invented on the project's behalf — an owner that inherits invented facts cannot tell them from verified ones.
There is deliberately no example area: a seeded areas/example/ is a sheet about nothing that the owner has to recognise as fake on every listing and every search. The shape of an area and of a sheet is explained inside areas/README.md instead.
Paths are book-relative and slash-separated.
Types ¶
type Entry ¶
type Entry struct {
Path string `json:"path"`
Bytes int64 `json:"bytes"`
Modified time.Time `json:"modified"`
}
Entry is one file of the book as an API caller sees it: the path the book speaks (relative, slash-separated) and how big it is, so a list can be drawn without reading every file.
func Files ¶
Files lists the book for a reader that is not the model: same walk the tool's "list" action does, with the sizes a UI needs and no truncation notice in the middle of the data. A missing book directory is an empty book, not an error: an owner whose book was never seeded still has a book page to open.