Documentation
¶
Overview ¶
Package memory is a durable, scoped note store that survives a session.
WHAT IT IS FOR. A session ends and everything it worked out goes with it — the convention this repo actually follows, the decision behind a strange- looking guard, the finding an audit already confirmed. AGENTS.md holds what someone sat down and wrote; this holds what accumulates, and it is scoped so the two do not become one file nobody prunes.
NOT A SECOND PLAN STORE. The "no new store" invariant is about PLAN STATE — "plan state is session events", ARCHITECTURE.md — because two stores for one fact eventually disagree. Notes are not derivable from any event log, so there is nothing here for a second store to contradict.
THE SAFETY RULES ARE PLAN_STORE'S, deliberately reused rather than rewritten: an allow-list name that cannot spell a traversal component, containment of every operation to a handle on the workspace (internal/pathjail), and an O_EXCL temp file renamed into place. A note store is a write primitive pointed at a path the model chooses, which is the same shape as "save my plan" and needs the same answers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrBadName = errors.New("a memory name must be lowercase, start with a letter, use only letters, digits and hyphen, be at most 64 characters, and not be a reserved device name") ErrNoStore = errors.New("memory is not available in this run") ErrTooLarge = fmt.Errorf("a memory note may be at most %d bytes", maxNoteBytes) ErrNotFound = errors.New("no such memory") ErrBadScope = errors.New(`scope must be "project" or "local"`) // ErrNameClash is a note whose stored spelling differs from the one asked // for. On a case-insensitive filesystem the two are the same file, so writing // the second destroys the first — and List, which matches the extension // exactly, does not show it, so the model is told the store is empty right // before it overwrites something. ErrNameClash = errors.New("a differently spelled note already occupies this name") // ErrUnreadable is a path the confined handle will not open while it is // plainly present on disk. Distinct from ErrNotFound, which is the answer // that let a tampered store present as an empty one, and distinct from // ErrIsSymlink, which names a reparse point this process could actually // identify as one — a junction is not identifiable that way, and neither is // a directory the process may not enter. ErrUnreadable = errors.New("the memory store exists but could not be read") // ErrNotPrivate is returned rather than writing a local note the repository // would then track. The local scope's whole promise is that the note stays on // this machine, and a promise that degrades quietly is worse than one that // refuses. It covers both ways the promise can fail: an ignore rule that does // not cover the store, and a store git already tracks — where no ignore rule // applies at all. ErrNotPrivate = errors.New("a note saved to the local memory store would not stay on this machine") // ErrIsSymlink is pathjail's refusal, kept under this package's own name so // callers testing for it keep working. It now covers a Windows junction as // well as a symlink, which the old ModeSymlink-only check did not. ErrIsSymlink = pathjail.ErrReparse )
Functions ¶
func Forget ¶
Forget removes a note. Missing is not an error: the caller asked for it to be gone, and it is.
func ValidName ¶
ValidName reports whether a name is storable.
The reserved check is separate from the pattern because it is a different kind of rule: the pattern says which characters may appear, this says which otherwise-legal spellings the platform will not let git carry.
func Write ¶
Write stores a note, replacing any note of the same name in the same scope.
Every step runs against a handle on the containment root, so the directory this lands in cannot be changed underneath it: create the tree, refuse a link at the destination, write an O_EXCL temp file with an unpredictable name, rename into place. An edit is therefore atomic, and a crash mid-write leaves the previous note rather than a half-written one.
Types ¶
type Note ¶
type Note struct {
Name string
// Description is the one-line summary from frontmatter. It is what a listing
// shows, so a reader can decide what to open WITHOUT reading everything —
// which is the whole reason notes carry frontmatter at all.
Description string
Scope Scope
Body string
}
Note is one stored memory.
func List ¶
List returns every note in the given scopes, project first, each sorted by name, along with any store that could not be read.
LOCAL SHADOWS NOTHING. Unlike saved plans, where project shadows user because a repo's own plan is what its contributors should get, both scopes are listed: they hold different KINDS of thing, and hiding one behind the other would lose a note rather than resolve a conflict.
The error is JOINED rather than returned in place of the notes: a store that cannot be read must be reported, but the notes that did read are still the best answer available, and dropping them would turn one unreadable file into an empty memory.
type Paths ¶
type Paths struct {
// Root is the containment boundary. Every operation below is performed
// relative to a handle on it, so no component of ProjectDir or LocalDir can
// redirect a write or a delete outside the tree. Empty means no store: a
// boundary is not optional, because without one the directories below are
// just strings the filesystem re-resolves on every syscall.
Root string
ProjectDir string
LocalDir string
}
Paths locates the two scopes. An empty directory means that scope is simply unavailable, and a write to it is refused with a reason rather than silently written somewhere else.
func DefaultPaths ¶
DefaultPaths puts project memory beside the repo and local memory in a subdirectory of it.
The local store makes itself private on first write (keepLocalScopePrivate) rather than relying on a line in the workspace's .gitignore: this runs in whatever repository the user opened, and a rule that lives in one repo's ignore file protects only that repo.
func (Paths) Available ¶
Available reports whether this run has a usable store.
ROOT COUNTS, and that is the fix rather than a nicety. openScope refuses a blank Root with ErrNoStore, and List treats ErrNoStore as "that scope is not configured" and moves on — so a Paths carrying both directories and no Root produced an empty listing, and the caller told the user there were no notes when the store was in fact switched off. Callers ask here instead of testing the fields themselves, so the rule has one home and cannot drift.
type Scope ¶
type Scope string
Scope is where a note lives, and who else sees it.
const ( // ScopeProject is checked in beside the repo: shared with everyone who clones // it, and therefore reviewed like any other file in the tree. ScopeProject Scope = "project" // ScopeLocal is this machine only. The natural home for anything specific to // one checkout, one operator, or one afternoon. ScopeLocal Scope = "local" )
func DefaultScopeOrder ¶
func DefaultScopeOrder() []Scope
DefaultScopeOrder returns a COPY. Handing out the backing slice would let a caller reorder the resolution every other caller depends on.
func ResolveScopes ¶
ResolveScopes turns a requested scope into the scopes to search.
ONE place decides, because there were two and they disagreed: the write path validated through memory.Scope and refused an unknown value, while the read path mapped every unrecognised spelling to BOTH stores. A typo therefore widened access on the only path where widening matters, and a perfectly valid "project" was ignored on the listing path, which always read both. An empty request means "search everywhere"; anything non-empty must be a scope this package knows.