memory

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 20 Imported by: 1 module, 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 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

View Source
const (
	NoteFact       = "fact"
	NotePreference = "preference"
	NoteCorrection = "correction"
)

The kinds of note.

Variables

View Source
var ErrNoNote = errors.New("no such note")

ErrNoNote means no note has the name (or several start with it).

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

func Append(workspace, file, text string) (string, error)

Append adds a bullet to <workspace>/<file>, creating it if needed.

func DeleteNote

func DeleteNote(dir, name string) error

DeleteNote removes dir's note name.

func Imports

func Imports(content string) []string

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 NotesDir

func NotesDir(workspace string) string

NotesDir is where workspace's notes are kept.

func Render

func Render(docs []Doc, scoped ...bool) string

Render formats docs as a system-prompt section. scoped says whether path-scoped rules exist, so the agent knows to expect them.

func RenderNotes

func RenderNotes(notes []Note) string

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

func RenderRules(rules []*Rule) string

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

func SummariesDir(notesDir string) string

SummariesDir is where the summaries are kept in a workspace's notes folder (NotesDir).

func TrackedByGit

func TrackedByGit(path string) bool

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.

func Load

func Load(workspace string, cfg config.MemoryConfig, opts ...Options) []Doc

Load returns the instruction files to put in the prompt: see LoadAll.

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.

func FindNote

func FindNote(dir, name string) (Note, error)

FindNote is dir's note name (or the only one whose name starts so).

func Notes

func Notes(dir string) ([]Note, error)

Notes are dir's notes, newest first.

func SaveNote

func SaveNote(dir, kind, text string) (Note, error)

SaveNote keeps text as a note of kind in dir and returns it.

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

type RecentSession struct {
	ID      string
	Title   string
	Updated time.Time
	Summary *Summary
}

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.

func (*Rule) Matches

func (r *Rule) Matches(abs string) bool

Matches reports whether the absolute file path abs is one this rule applies to.

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

func FindSummary(dir, id string) (Summary, error)

FindSummary is session id's summary in dir (os.ErrNotExist when none).

func SaveSummary added in v0.8.8

func SaveSummary(dir string, s Summary) (Summary, error)

SaveSummary writes s to dir, replacing the session's earlier summary.

func Summaries added in v0.8.8

func Summaries(dir string) ([]Summary, error)

Summaries are dir's summaries, the most recently updated session first.

func (Summary) Stands added in v0.8.8

func (s Summary) Stands() string

Stands is the summary's "Where it stands" line: its first paragraph of prose, for a list of sessions.

Jump to

Keyboard shortcuts

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