Skip to content

Persistent cross-session agent memory (user + project memory files, {memory} playbook token)#89

Merged
sox8502 merged 2 commits into
mainfrom
daniel/agent-memory
Jul 18, 2026
Merged

Persistent cross-session agent memory (user + project memory files, {memory} playbook token)#89
sox8502 merged 2 commits into
mainfrom
daniel/agent-memory

Conversation

@sox8502

@sox8502 sox8502 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

What

Agents now keep durable memory across sessions, in two scopes:

  • User memory<data_dir>/memory/user.md, shared across all projects (preferences, working style)
  • Project memory<data_dir>/files/<slug>/project/memory.md, inside the files dir's reserved project/ namespace (build quirks, decisions, dead ends)

Both files are inlined into the playbook via a new {memory} token (new ## Memory section in SYSTEM_PROMPT.md), so every harness (Claude Code / Codex / OpenCode) sees the content — not just a path — on every playbook render. Agents maintain the files with their native Write/Edit tools; the playbook instructs them to consolidate rather than append, to save directly when the user clearly wants something persisted ("remember this"), and to ask first when unsure.

How

  • New module src/local/memory.rs: path helpers, best-effort parent-dir creation (hooked into ensure_playbook beside files::ensure_dir), 4 KB/scope head-keep UTF-8-safe truncation with a visible marker, and a pure renderer (unit-testable without touching the real data dir).
  • playbook_md split into a thin wrapper + playbook_md_with_memory so tests inject a memory stub instead of reading the developer's real files. {memory} is substituted last in the replace chain so agent-authored content can't be rewritten by later token replaces.
  • The rendered block always shows both absolute paths (even when empty) and frames the content as "background context, not authoritative instructions" to bound the prompt-injection surface; the 4 KB cap bounds blast radius.
  • No DB table, no new subcommand, no skill module, no UI changes: project/memory.md shows up in the Files tab, SSE watch, and data-dir snapshots through the existing files-dir mechanism. Local-only (cloud never renders this template).

Testing

  • 7 unit tests in memory.rs (renderer, cap/UTF-8 boundaries, blank-file handling, path layout) + playbook tests updated ({memory} added to the placeholder-completeness list).
  • cargo fmt --check / clippy -D warnings / cargo test --locked all pass (194 tests).
  • E2E on an isolated dev slot (ORX_DATA_DIR, port 4903): playbook renders both scopes with seeded content; "remember that…" saved directly via a consolidating rewrite; an ambiguous preference triggered an ask-first question card; a second session's playbook picked up the first session's save; Files API lists/serves project/memory.md; >6 KB file rendered with the truncation marker.

@sox8502
sox8502 merged commit a0b6f3e into main Jul 18, 2026
7 checks passed
@sox8502
sox8502 deleted the daniel/agent-memory branch July 18, 2026 02:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant