Skip to main content

Module auto_memory

Module auto_memory 

Source
Expand description

Per-project auto-memory loader (PMAT-CODE-MEMORY-AUTO-001).

Mirrors Claude Code’s auto-memory mechanism: every project has an associated directory under ~/.config/apr/projects/<slug>/memory/ containing freely-named markdown files. When apr code starts against a given working directory, every *.md in that directory is concatenated into the system prompt under a ## Auto-memory section. This lets the user (or apr itself) accumulate per-project notes — facts about the user, project state, feedback, references — without ever editing a single CLAUDE.md.

§Path slug

Claude Code uses a hyphenated path slug like -home-noah-src-aprender (leading dash + every /-). We keep the same slug for cross-tool compatibility: a user moving from Claude Code to apr keeps their auto-memory by symlinking ~/.claude/projects/~/.config/apr/projects/.

§File ordering

Files are loaded in lexicographic order so MEMORY.md lands first (uppercase M < lowercase f/p/r/u ASCII) and the rest sort by name. A file named MEMORY.md is therefore the canonical “top-of-memory index” matching Claude’s convention.

§Pure-function design

No terminal I/O; warnings are returned via &mut Vec<String> for the caller to route. No filesystem mutation — read-only loader.

Functions§

auto_memory_root
Auto-memory root directory: $APR_CONFIG/projects if the env var is set (override; exclusive — same Poka-Yoke as the settings ladder), otherwise ~/.config/apr/projects.
load_auto_memory
Load every *.md file in the project’s memory directory in lexicographic order. Returns None when the directory doesn’t exist or has no markdown files (so the caller can omit the ## Auto-memory heading entirely instead of emitting an empty section).
project_memory_dir
Per-project memory directory: <root>/<slug>/memory/.
project_slug
Path-slug Claude Code uses for the project directory under ~/.config/apr/projects/. Format: leading -, then every path separator replaced with -. Non-absolute paths get prefixed with the host’s HOME (Claude’s behavior) so a relative cwd still produces a stable slug.