← Catalog

@rackrot/pi-memory

Long-term agent memory as Markdown notes in a git-managed, Obsidian-compatible vault

Extension

Install

Install with PiG

pig install npm:@rackrot/pi-memory

Install with Pi

pi install npm:@rackrot/pi-memory
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "skills": [
    "./skills"
  ],
  "extensions": [
    "./src/index.ts"
  ]
}

README

Written by the package's publisher, shown as published in version 1.3.0 (README.md). PiG does not review it.

@rackrot/pi-memory

Long-term memory for the pi agent: Markdown notes with YAML frontmatter in a git repo that doubles as an Obsidian vault. The agent searches, reads, writes and archives notes with tools; humans edit the same files.

Setup

1. Install

pi install npm:@rackrot/pi-memory

2. Choose a root

memory.root is the directory the agent searches and (under <agentDir>/) writes. Pick one of three cases.

A new, dedicated vault. Any empty directory, e.g. ~/Vault. /memory-init creates the git repo and the agent folder. Open it in Obsidian later if you like.

An existing Obsidian vault, e.g. ~/Documents/Obsidian/MyVault.

  • The agent can search and read every .md in it (not .obsidian, .git, .trash, node_modules, or the archive).
  • It writes only under <root>/Agent/ (the agentDir). .obsidian/ is never created or modified, and pi's built-in write/edit are blocked for .git, .obsidian and the archive. Shell commands are not inspected.
  • In Obsidian you will see an Agent/ folder. Its notes are normal Markdown with frontmatter and [[links]], so graph view and Dataview queries work on them.
  • You and the agent edit the same files. The agent only stages the paths it wrote (never git add -A), so your uncommitted edits are never swept into its commits. If you change a note the agent has read, its next write to it is refused until it re-reads it (the stale-write guard).

A parent folder of several vaults, e.g. ~/Documents/Obsidian. This works, but Agent/ is created at the parent, outside every vault, and the whole tree is indexed. /memory-init warns about this; usually it is better to point root at one vault.

3. Configure

memory.root, agentDir and projects are read from the global config only (a project config can never redirect where the agent writes); ~ is expanded. The file is <agentDir>/rackrot/config.json (or .jsonc), where <agentDir> is pi's agent dir (~/.pi/agent). Create it with /rackrot-init or edit it with /rackrot-config memory. All other keys may also go in <cwd>/.pi/rackrot.json(c); the project layer wins.

{
	"memory": {
		"root": "~/Documents/Obsidian/MyVault", // required, global config only
		"agentDir": "Agent", // folder under root the agent writes to; global config only
		"projects": "Projects", // folder under agentDir, one subfolder per project; global config only
		"project": "my-app", // optional: override the slug derived from the git remote
		"autoInject": true, // add overview, open handoffs and pinned notes to the system prompt
		"commitIntervalMinutes": 5, // 0 = commit only at session end
		"push": "session", // "session" pushes at session end; "never" keeps it local
		"injectBudgetChars": 12000,
		"embedding": { "provider": "onnx", "model": "Xenova/bge-small-en-v1.5" }, // {"provider": "none"} = BM25 only
		"summary": {
			"model": "anthropic/claude-haiku-5-5", // no default: unset skips the summary worker
			"enabled": true,
			"minChanges": 3,
			"timeoutSeconds": 60
		}
	}
}

embedding and optional reranker fall back to skillIndex.embedding / skillIndex.reranker, then to the default onnx model. Without memory.root the package does nothing except offer /memory-init.

4. Run /memory-init

One command for the whole setup; safe to re-run.

  1. memory.root unset: prints the config path and a JSON snippet, nothing else.
  2. Checks the root: offers to create it if missing, rejects a file. Reports whether it is an existing Obsidian vault (only Agent/ is written) or a parent of several vaults.
  3. Warns when the root sits in iCloud (Mobile Documents), Dropbox, OneDrive or Google Drive, where .git is known to corrupt. When creating a new repo there it asks whether to keep the git data outside the folder (git init --separate-git-dir, stored under <agentDir>/rackrot/memory/git/); default is no. An existing .git is never moved.
  4. Not a git repo: asks, then git init -b main. Global git config is never changed.
  5. Creates <agentDir>/ and <agentDir>/<projects>/, and appends missing lines to .gitignore and .gitattributes (existing lines are never rewritten).
  6. Commits only .gitignore / .gitattributes as memory: initialize agent folder (explicit paths). Your notes are not committed. If git has no user.name/user.email the commit is skipped and the exact git config commands are printed; run /memory-init again afterwards.
  7. Prints next steps based on the real state (no remote, remote without upstream, or sync active). Re-running on a set-up vault makes no new commit.

5. Add a remote and push

Optional; without a remote the agent still commits locally.

git -C "<root>" remote add origin <url>
git -C "<root>" push -u origin main

Create an empty, private repo first (Forgejo, GitHub, ...): vault notes are private data. Review git status and commit the notes you want in the repo yourself before the first push, since init does not. Once the branch has an upstream, the agent pushes at session end (push: "session"). If the root is in a synced folder, see the warning above and do not put .git there.

6. Several devices

On each device clone the repo, set memory.root to the clone, and run /memory-init. At session start the agent runs git pull --rebase --autostash (needs an upstream), and again at session end before pushing. On a conflict the rebase is aborted, you are notified, and auto-commit and push are disabled for that session. Resolve it by hand in the vault (git pull --rebase, fix, git push); the next session syncs again. Pushes are never forced.

7. Obsidian git plugin and mobile

Don't run obsidian-git's auto-commit/auto-push on the same device while the agent's commit timer is active, unless you accept that both of them commit and pull in the same repo (they serialise only on the agent's own lock). On mobile, sync through whatever you already use; the agent only needs the files and, on desktop, the git repo.

8. Troubleshooting

SymptomCause / fix
Nothing happens, only /memory-init existsmemory.root is unset in the global config. Run /memory-init for the exact steps.
"is not a git repo; notes are not versioned"Run /memory-init, or git init yourself. Notes still work without versioning.
"git sync disabled for this session" after a pushPush rejected (no upstream, remote ahead, auth). Fix in the vault with git pull --rebase / git push -u origin main; restart the session.
First search is slow, or downloads filesThe onnx embedding model downloads on first use. Set embedding.provider to none to skip it.
Search says it fell back to BM25Embeddings failed or are off (provider: none); results are keyword-only. Check the embedding config and network.
memory_write refuses to update a noteIt was not read in this session, or the file changed since it was read. memory_read it again, then write.

Layout

<root>/<agentDir>/                      global agent notes
<root>/<agentDir>/archive/              archived notes (read-only)
<root>/<agentDir>/<projects>/<slug>/    Overview.md, Decisions/, Log/, Handoffs/

The slug is the repo name from the origin remote, else the git top-level folder, else the cwd folder. Overview.md records the remote; if a different remote already owns that slug, <org>-<repo> is used. Local paths are never stored, so project notes work across machines. Notes have type, created, updated, source, and optionally pin, status (handoffs) and confidence.

Tools

memory_search (project, global, vault or all; BM25 plus vectors, optional reranker), memory_read, memory_write, memory_archive, memory_sync. memory_write:

  • refuses to create a note whose title and body are at least 60% word-similar (Jaccard) to an existing one in the same folder;
  • refuses to update a note that was not read in this session, or whose file changed since it was read;
  • refuses bodies that look like secrets (AWS keys, GitHub tokens, private keys, sk- keys, password|secret|token = ...);
  • only writes under <agentDir>/;
  • takes supersedes: [paths] for notes it replaces: they get status: superseded and superseded_by in frontmatter, stay searchable (marked [superseded by ...], ranked after current notes) and are left out of the injection. The new note records supersedes.

Search indexes every .md under the root (not .obsidian, .git, .trash, node_modules, or the archive) in an SQLite database at <agentDir of pi>/rackrot/memory/index.db, outside the vault. Embeddings are built in the background; if they fail, search falls back to BM25 and says so.

Each project's Overview.md ends with an auto-generated note index between <!-- memory:index:start --> and <!-- memory:index:end --> (Decisions, Log newest first, Handoffs, other; summary from frontmatter summary or the first body line). It is rebuilt without an LLM after every project memory_write and memory_archive (which also bumps the frontmatter counter summary-changes), and nothing outside the markers is touched.

Summary worker

The prose above the markers is kept up to date by a one-shot, tool-less model call (callModel from @rackrot/pi-core/model-call, the same mechanism as pi-council). At session end, before the final commit, if the project has at least summary.minChanges (default 3) note writes/archives since the last summary, the worker sends the current prose, the note list and the bodies of notes changed since summarized (1500 chars each, 12000 total) and replaces the prose, keeping the marker block and frontmatter, resetting summary-changes and setting summarized. Output is dropped if empty, over ~3000 characters, containing the markers, or matching the secret scan; it is also skipped when a human edited Overview.md since the session last saw it or while the call ran. Any failure (timeout, auth, model) is reported and never blocks the final commit or push. A lone Overview commit reads refresh summary.

Config under memory.summary (either layer): model (provider/id or {model, thinking}; no default — unset skips the worker, and the session's own model is never used, to avoid surprise cost), enabled (default true), minChanges (3), timeoutSeconds (60). /memory-summarize runs it now for the current project, ignoring minChanges and enabled. At most one call per project per session.

Capture worker

Notes are also written for the agent. Every capture.everyTurns (default 10) finished agent runs (one per user message), before pi compacts the context, and at session end, a one-shot model call reads the transcript since its last run (user and assistant prose only) and the project's existing note list, and proposes at most capture.maxNotes (3) decisions, lessons, rules or facts. Status, progress and anything already noted are excluded by the prompt. Each proposal goes through the same path as memory_write: secret scan, near-duplicate refusal, the decision-model injection check when enabled, and a title that already exists is never overwritten. A proposal may name an existing note it replaces, which is then marked superseded. Notes get source: session and session: frontmatter. It runs in the background after agent_end, at most one at a time, and any failure is silent; if the call fails the next run retries the same stretch. A short info message says what was written.

Config under memory.capture (either layer): enabled (default true), model (provider/id; falls back to summary.model, and with neither capture is skipped, never the session model), everyTurns (10), maxNotes (3), mode (auto writes notes; stage writes them to the project's Inbox/ with the same frontmatter so you can review and move them, and proposes no supersession), timeoutSeconds (60). Everything is also in /rackrot-config under Memory. Under Magic Context, which drops tool output without an event pi exposes, there is no trigger for that drop; the every-N-turns run is what limits loss.

Session digests

At session end the same model that refreshes the Overview (memory.summary.model; unset skips this too) also writes Agent/Projects/<slug>/Log/<date> <session>.md: a digest of the session's user and assistant prose (tool calls and results are not sent; the last 24000 characters are kept), saying what was asked, what was decided and why, and what was left open. Sessions with fewer than 3 user messages are skipped; output that is empty, over 6000 characters or matching the secret scan is dropped. Notes written during the session carry its id in session: frontmatter. Digests are ordinary log notes: searchable, never injected. They answer "why did we decide X" when the decision note alone does not. The transcript is sent to the summary model, so pick one you are happy to show session text to.

Decision model (optional)

memory.decision (global layer only, since it names an endpoint that receives note text) enables a System One model, the same config as skillIndex.decision: enabled (default false), provider (typesafe for any /v1/systemone endpoint, or laya for local ONNX), baseUrl, model, apiKeyEnv, threshold (default 0.5), injectionThreshold (default 0.7; blocking a write needs more certainty than advice does). It answers yes/no questions with a probability:

  • On memory_write (one batched call): a note that looks like instructions aimed at an AI agent is not written; a note that looks like current status gets a hint to write it as a handoff; neighbours the note seems to outdate are named so it can be rewritten with supersedes.
  • On memory_search: results the model judges unrelated to the query are dropped; when none remain the answer says memory likely does not cover it.

Both fail open: if the model errors, the write or search goes through with a line saying the check was skipped. node eval/decision.ts --base-url ... --model ... --api-key-env ... prints precision and recall per question at several thresholds on a small labelled synthetic set (eval/decision.json); calibrate on your own notes before relying on a threshold, since cutoffs differ per model. Relevance filtering can drop a useful note the model misjudges; if search seems to miss things, lower threshold or turn the decision model off.

With autoInject, each turn's system prompt gets the project Overview (skipped while it has no prose and no notes; the index is cut first when over budget), open handoffs and pinned notes, cut to injectBudgetChars. The section is built on the first turn and returned unchanged until the next compaction, so notes written or edited mid-session (including in Obsidian) show up after compaction or in the next session. A section that changed every write would change the system prompt each time and break prompt caching and Magic Context's cache-aware deferral. It sits under its own memory section key, so it does not collide with Magic Context's magic_context one, and memory_* tools do not overlap its ctx_* tools (its own ctx_memory store is separate from this vault).

Consolidation

pi-memory consolidate [--project <slug>] [--dry-run] (also started detached at session end when consolidate.enabled and the last run of the project was more than minDays ago) cleans up each project's agent notes. Nothing is ever deleted: notes are archived or superseded, so git revert of the single consolidate memory commit (its message lists every change) undoes a run. It needs the same git, config and memory.root as the session; --project omitted means every project folder. Each step is independent and fails open: an error is logged and the run goes on.

  1. Deterministic, no model: notes superseded for more than supersededDays (by file mtime) are archived; session digests in Log/ older than logDays are archived; a superseded_by that points at no note is cleared so the note is current again.
  2. Decision model (memory.decision, required for this step; without it only step 1 runs): for each note, most recently changed first, it asks whether a BM25 neighbour that is newer makes it outdated, whether a neighbour is a duplicate, and, for notes with a status, whether it is stale.
  3. Merge (duplicate): the consolidate model writes one merged note with supersedes: [a, b] and source: consolidate; both originals are archived. The text must pass the secret scan, a 4000-character cap and the injection check (decision enabled and not skipped); otherwise both originals stay and the verdict is listed for review. Without a model, duplicates are only listed.
  4. Apply by confidence. In auto mode (default) a verdict at or above autoThreshold is applied (outdated: superseded; duplicate: merged; stale: archived). A verdict from reviewThreshold up to autoThreshold is written to Inbox/Consolidation <date>.md in the project folder. In review mode nothing is applied and every verdict goes there. In auto mode notes of type handoff or rule, notes whose source is not agent, session or consolidate (human-written), and notes modified in the last 24 hours are never changed, only listed. Each change checks the note's content hash again right before writing. maxChanges is opt-in: unset means uncapped; past the cap, verdicts are listed.
  5. Validate (opt-in, consolidate.validate.enabled, not in review mode). A second, separate model re-checks every pending verdict in the project's Inbox/Consolidation *.md files, this run's and earlier ones. Each review line ends in an HTML comment (<!-- consolidate: {...} -->, hidden in Obsidian's reading view) holding the kind, probability, note paths, their content hashes and a status. A verdict whose note no longer exists or whose hash differs is marked expired without a model call. Otherwise the validator gets the notes (4000 characters each), argues for and against and answers act, reject or unsure: act applies the change through the same code as step 4 (merge keeps the secret scan, length cap and injection check) and ticks the line; reject marks it rejected and it is never asked again; unsure keeps it pending with the reason noted, so it is asked again next run. The step never acts on handoff/rule notes, human-written notes or notes modified in the last 24 hours (they stay pending, no model call); maxChanges counts validator changes too, and validate.maxPerRun limits the calls. In a dry run the validator may be called but nothing is applied or marked. Errors leave the item pending. Each outcome is a validate line in the change log (result: act, reject, unsure, expired, or pending when blocked; reason and hashes, no bodies) and run-end carries validated counts.
  6. The index is rebuilt and, when something changed, the Overview prose is refreshed (consolidate model), then one commit consolidate memory and, with push: session, a push.

Only one run per vault: a lease file Agent/.consolidate/lease.json (holder, timestamp, 10-minute TTL, refreshed per note) is taken with an exclusive create; a second run exits with a message.

Change log. Agent/Projects/<slug>/.consolidate/changes-YYYY-MM-DD.jsonl, append-only, one file per day, committed with the run; files older than logRetentionDays are deleted at the start of the next run. One JSON line per event: ts, runId, project, mode, action (supersede, archive, merge, prune-log, fix-link, skip, queue-review, validate, run-start, run-end), notes, result, reason (rule text, or decider question with probability and thresholds), before / after content hashes, applied, error. run-end has counts, capped and base (the commit HEAD was at before the run; the new commit is the one after it). Note bodies are never logged. A dry run writes the same lines with applied: false, changes no note, and does not pull or commit. state.json next to the log records the last run.

Config under memory.consolidate (either layer; also in /rackrot-config under Memory): enabled (false), model (provider/id or {model, thinking}; falls back to summary.model, never the session model; the session-end trigger also needs one), mode (auto | review, default auto), minDays (7), autoThreshold (0.9), reviewThreshold (0.6, at most autoThreshold), maxChanges (unset), supersededDays (30), logDays (90), logRetentionDays (15), timeoutSeconds (120, per model call), validate (enabled false, model with no default and no fallback, not even to consolidate.model, so the check stays independent; maxPerRun 20; timeoutSeconds 120). The decision model's own threshold is not used here. Probabilities are model-specific: start with mode: "review" and --dry-run, and calibrate the thresholds on your own notes.

Several agents at once

Any number of pi sessions can use one vault. Git work (commit, pull, push) is serialised across processes by <git dir>/pi-memory.lock; a session that finds it busy skips that run and tries again later instead of disabling sync. Each session commits only the paths it wrote (commit --only), and before a final sync or memory_sync it also adopts paths other sessions journalled but never committed, so little is left uncommitted when pull --rebase --autostash runs. Notes are written to a temp file and renamed; creating a note uses an exclusive link, so two sessions creating the same title cannot overwrite each other (the second is told to memory_read and update), and updating a note re-checks its hash at write time. memory_write syncs the shared search index first, so near-duplicate refusal sees notes other sessions wrote seconds ago. The Overview index is rebuilt again under the git lock just before each commit, so the committed index lists every session's notes. Not handled: two sessions editing the same note's body at nearly the same moment still end with a refusal for one of them, not a merge.

Git

All git runs through git -C <root> without a shell. Only the files the agent wrote are staged (git add -- <paths>, never -A), so your uncommitted work in the vault is never swept into agent commits. Commits are memory(<slug|global>): add X; update Y; archive Z, made every commitIntervalMinutes (0 = only at session end). At session start and end: pull --rebase --autostash; at the end, push when push is session. Never force. A pull conflict aborts the rebase, notifies you and disables auto-commit and push for the session; a push failure does the same. Git work is serialised with <root>/.git/pi-memory.lock. A root that is not a git repo still works, without versioning.

The paths a session wrote are also listed in <root>/.git/pi-memory-dirty-*.json until they are committed. If pi is killed, or sync was disabled, the next session commits them at start. When the pull re-applies your own uncommitted edits and they conflict with what came in, git leaves conflict markers in those files: you are told which files, sync stops for the session, and your edits are also kept in git stash list. At session end the summary worker, final sync and embeddings get 30 seconds in total; what is left is committed by the next session.

Limits

  • Notes are never deleted; archive only moves them.
  • Duplicate detection is lexical, not semantic.
  • Markdown only; attachments are ignored.
  • Concurrent sessions on one vault serialise on the lock but can still produce rebase conflicts.