book

package
v0.42.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 13 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 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

View Source
const OwnerFile = "OWNER.md"

OwnerFile is the user's preferences file, read into the owner's prompt.

View Source
const ToolName = "book"

ToolName is the registered name, so callers can find the tool in a registry without repeating the literal.

Variables

View Source
var ErrTooLarge = fmt.Errorf("the file is larger than %dKB; split it across book files", maxWriteBytes/1024)

ErrTooLarge reports a write past maxWriteBytes.

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

func CleanPath(rel string) string

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

func NewTool(dir string, writable bool) core.Tool

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

func ReadFile(dir, rel string) ([]byte, error)

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

func ReadOnlyVariant(t core.Tool) (core.Tool, bool)

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

func RelativeAge(d time.Duration) string

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

func Template() map[string]string

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

func WriteFile(dir, rel string, content []byte) error

WriteFile replaces one book file, through the same path guard and the same atomic write the tool uses.

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

func Files(dir string) ([]Entry, error)

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

func SearchBook(dir, query string, limit int) ([]Hit, int, error)

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.

Jump to

Keyboard shortcuts

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