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 GateExtension(cfg GateConfig) extension.Extension
- func GuardExtension(dir string, ...) extension.Extension
- 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
- func WritesBook(dir, tool string, args map[string]any) bool
- func WritesBookFrom(dir, cwd, tool string, args map[string]any) bool
- type Entry
- type GateConfig
- type Hit
- type Index
Constants ¶
const ArchiveDir = "archivo/"
ArchiveDir is where the nightly dreaming moves superseded text, verbatim.
const GuardMessage = "" /* 296-byte string literal not displayed */
GuardMessage is what the model is told when a call is refused.
const ( // MaxIndexBytes is how much of PROJECT.md a session is given (the owner // package injects exactly this), so it is also how big the index may be. MaxIndexBytes = 8 * 1024 )
const OwnerFile = "OWNER.md"
OwnerFile is the user's instructions 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 instructions 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 GateExtension ¶ added in v0.49.0
func GateExtension(cfg GateConfig) extension.Extension
GateExtension returns the owner session's action gate.
func GuardExtension ¶ added in v0.49.0
func GuardExtension(dir string, cwd func(ctx context.Context, tool string, args map[string]any) string) extension.Extension
GuardExtension refuses, in an owner's session, the calls that would write the book directory without going through the book tool.
cwd tells where the session's shell is when a command starts (its persisted directory, or the one the call names); nil means unknown.
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.
func WriteFile ¶
WriteFile replaces one book file, through the same path guard and the same atomic write the tool uses.
func WritesBook ¶ added in v0.49.0
WritesBook reports whether a tool call would write inside the book directory by a route other than the book tool.
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.
type GateConfig ¶ added in v0.49.0
type GateConfig struct {
Dir string // the book directory
LogPath string // JSON lines; the pilot's record, never leaves the host
Enabled func() bool // read on every turn and call, so the switch is live
}
GateConfig wires the gate to one owner.
type Hit ¶
type Hit struct {
Path string
Title string
Area string
Snippet string
Score float64
// contains filtered or unexported fields
}
Hit is one ranked sheet: enough to decide whether to read it, never enough to answer from the list alone.
func SearchBook ¶
SearchBook ranks the book's files against a free-text query. It is exported for callers outside the tool (tests, future HTTP search) and is the single implementation: the tool formats what this returns.
The dreaming's archive (archivo/) is left out: it holds what was superseded, and a reader looking for the current state must not find it first (the user's decision of 11/11). The tool can ask for it explicitly.
type Index ¶ added in v0.49.0
type Index struct {
// contains filtered or unexported fields
}
Index is a book scanned and tokenized once, for a caller that searches the same book several times or needs the scan done before the query is known.