Documentation
¶
Overview ¶
Package memory loads project instruction files (AGENTS.md, CLAUDE.md, GEMINI.md, BLITZ.md), the files they import, and rule files, which are added to the agents' system prompt. Rules scoped to paths are handed out when the agent first touches a matching file (see Rules).
Index ¶
- Constants
- Variables
- func Append(workspace, file, text string) (string, error)
- func DeleteNote(dir, name string) error
- func Imports(content string) []string
- func NotesDir(workspace string) string
- func Render(docs []Doc, scoped ...bool) string
- func RenderNotes(notes []Note) string
- func RenderRecent(recent []RecentSession) string
- func RenderRules(rules []*Rule) string
- func Stamp(workspace string, cfg config.MemoryConfig, loaded Loaded) string
- func SummariesDir(notesDir string) string
- func TrackedByGit(path string) bool
- type Doc
- type Loaded
- type Note
- type Options
- type RecentSession
- type Rule
- type Summary
Constants ¶
const ( NoteFact = "fact" NotePreference = "preference" NoteCorrection = "correction" )
The kinds of note.
Variables ¶
var ErrNoNote = errors.New("no such note")
ErrNoNote means no note has the name (or several start with it).
var ErrUnknownKind = errors.New("a note is a fact, a preference or a correction")
ErrUnknownKind means a note kind that isn't fact, preference or correction.
Functions ¶
func Imports ¶
Imports returns the @path imports in an instruction file, in order, ignoring fenced code blocks and inline code. A token counts as a path when it has a "/" or a file extension, so "@team" stays text.
func Render ¶
Render formats docs as a system-prompt section. scoped says whether path-scoped rules exist, so the agent knows to expect them.
func RenderNotes ¶
RenderNotes is the notes as the agent's instructions carry them: the newest first, up to maxNotesBytes, framed as what they are.
func RenderRecent ¶ added in v0.8.8
func RenderRecent(recent []RecentSession) string
RenderRecent is the earlier sessions as a new session's first prompt carries them: when each was, what it was, and where it stood, the latest one's summary in full, and how to read the others. Empty when there are none.
func RenderRules ¶
RenderRules formats rules handed out with a tool result.
func Stamp ¶ added in v0.6.5
func Stamp(workspace string, cfg config.MemoryConfig, loaded Loaded) string
Stamp is what the files LoadAll would read hold now: the path, size and time of each instruction file it looks for (missing ones too, so one created later changes it), every rule file in the rule folders, and each file loaded reads imported. Comparing it with the stamp taken when they were loaded says whether to load them again; it reads no file.
func SummariesDir ¶ added in v0.8.8
SummariesDir is where the summaries are kept in a workspace's notes folder (NotesDir).
func TrackedByGit ¶
TrackedByGit reports whether git tracks path, for warning about personal files that were committed. Git runs with fsmonitor off: the repository's config may name commands.
Types ¶
type Doc ¶
type Doc struct {
Path string
Content string
Truncated bool
// ImportedFrom is the file whose @path import loaded this one ("" for
// files found by name).
ImportedFrom string
// Local marks a personal file (BLITZ.local.md) that shouldn't be
// committed.
Local bool
}
Doc is one loaded instructions file.
type Loaded ¶
type Loaded struct {
Docs []Doc // always in the prompt (unscoped rules included)
Rules []Rule // scoped rules, handed out by path
// Problems are the rule files left out, and why: front matter that
// doesn't parse, or paths none of which can be read as a glob.
Problems []string
}
Loaded is everything Load found.
func LoadAll ¶
func LoadAll(workspace string, cfg config.MemoryConfig, opts ...Options) Loaded
LoadAll returns instruction files and rules: the global file and global rules first, then, for each directory from the repository root (the nearest ancestor containing .git, if any) down to the workspace, the files named in cfg.Files, then cfg.LocalFiles, then the rule files in cfg.RuleDirs, so more specific files come last. Files a loaded file imports (@path) follow it. The same file, or the same content under another name (CLAUDE.md copying AGENTS.md), loads once.
type Note ¶
type Note struct {
Name string // its file's name, without .md
Kind string
Text string
Time time.Time
Path string
}
Note is one saved note.
type Options ¶
type Options struct {
// Blocked reports paths that must never be read (the sandbox's
// blocked_paths): an import of one is skipped.
Blocked func(abs string) bool
}
Options refine loading.
type RecentSession ¶ added in v0.8.8
RecentSession is an earlier session for RenderRecent: its summary when one has been written.
type Rule ¶
type Rule struct {
Path string // the rule file
Content string
// Paths are globs relative to Root.
Paths []string
Root string
// contains filtered or unexported fields
}
Rule is a rule file scoped to paths: it applies once the agent reads or edits a file matching one of Paths.
type Summary ¶ added in v0.8.8
type Summary struct {
Session string // the session's ID
Title string // the session's title when it was written
Messages int // how many of the session's messages it covers
Updated time.Time // when the last of those was written
Text string // the summary, Markdown
Path string
}
Summary is one session's summary.
func FindSummary ¶ added in v0.8.8
FindSummary is session id's summary in dir (os.ErrNotExist when none).
func SaveSummary ¶ added in v0.8.8
SaveSummary writes s to dir, replacing the session's earlier summary.