pi-memoria 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,367 +1,115 @@
1
1
  # pi-memoria
2
2
 
3
- Agent-first long-term memory for [pi](https://github.com/badlogic/pi-mono).
4
-
5
- memoria gives a coding agent a memory it can actually rely on: a plain-markdown
6
- library on disk, a prose briefing that is loaded into every session, and
7
- automatic recall that searches the whole library on every prompt — in well under
8
- a millisecond.
9
-
10
- - **Nothing is lost behind an API.** Every memory is a markdown file you can
11
- read, edit, grep, diff and version.
12
- - **Past conversations are searchable too.** When the library has nothing, the
13
- agent can search the raw transcripts of earlier sessions before saying it does
14
- not remember.
15
- - **Recall is automatic.** Relevant notes are injected before the model answers,
16
- so it does not have to remember to ask.
17
- - **Broad topics, never fact files.** `likes-apples.md` is a defect; facts
18
- accumulate in `food-preferences.md`.
19
- - **Names are handles.** Aliases make every nickname, full name or former name
20
- resolve to the same note. Re-filing or consolidating notes also keeps retired
21
- note ids usable as references.
22
- - **Zero runtime dependencies.** No database, no server, no embedding service, no
23
- build step. Retrieval is a BM25 index kept in memory.
3
+ Long-term memory for [pi](https://pi.dev). Saves preferences, project context and
4
+ past decisions as Markdown files, then retrieves relevant notes in later sessions.
24
5
 
25
- ```
26
- ┌──────────────────────────────────────────────────────────────┐
27
- │ layer 1 MEMORY.md always in the system prompt │
28
- │ layer 2 auto-recall best matches injected per prompt │
29
- │ layer 3 memoria_recall the agent can search deeper │
30
- │ layer 4 plain markdown read/grep the files directly │
31
- └──────────────────────────────────────────────────────────────┘
32
- ```
33
-
34
- Measured on the bundled corpus: **recall@5 = 100%, recall@1 = 92.5%** over 40
35
- questions (paraphrases, typos, aliases, CJK, identifiers, superseded notes) with
36
- an average query time of **0.16 ms** (`npm run eval`).
37
-
38
- ## Contents
39
-
40
- - [Install](#install)
41
- - [Quick start](#quick-start)
42
- - [How it works](#how-it-works)
43
- - [The memory library](#the-memory-library)
44
- - [Tools](#tools)
45
- - [Commands](#commands)
46
- - [Configuration](#configuration)
47
- - [Scopes: personal, project, read-only](#scopes-personal-project-read-only)
48
- - [Synonyms](#synonyms)
49
- - [Model reranking](#model-reranking)
50
- - [Automatic session learning](#automatic-session-learning)
51
- - [Session recall](#session-recall-past-conversations)
52
- - [Backup and migration](#backup-and-migration)
53
- - [Performance](#performance)
54
- - [Privacy and durability](#privacy-and-durability)
55
- - [Troubleshooting](#troubleshooting)
56
- - [Development](#development)
57
- - [Design notes and limits](#design-notes-and-limits)
58
- - [License](#license)
6
+ Memory lives in your agent directory and follows you across projects. Search runs
7
+ locally, with no database, embedding service or additional runtime dependencies.
8
+ The agent can also search pi's saved conversations when a detail was never saved
9
+ as a note.
59
10
 
60
11
  ## Install
61
12
 
62
- ### Copy it into the extensions directory (simplest)
13
+ Requires pi and Node.js **22.19.0 or later**.
63
14
 
64
- ```bash
65
- mkdir -p ~/.pi/agent/extensions/memoria
66
- cp index.ts package.json ~/.pi/agent/extensions/memoria/
67
- cp -r src skills ~/.pi/agent/extensions/memoria/
15
+ ```sh
16
+ pi install npm:pi-memoria
68
17
  ```
69
18
 
70
- Pi discovers `extensions/memoria/index.ts` on the next start (or after
71
- `/reload`). Three notes:
72
-
73
- - **Do not copy `node_modules/`.** Pi supplies `typebox` and the
74
- `@earendil-works/pi-*` packages to extensions, so the copy works with no
75
- dependencies installed.
76
- - `package.json` is optional for this route; it carries the `pi.extensions` and
77
- `pi.skills` manifest and the peer-dependency metadata used by the package
78
- route.
79
- - The bundled skill is discovered automatically when memoria is installed as a
80
- **package** (`pi install …`). For the copy route, copy it separately if you
81
- want it: `mkdir -p ~/.pi/agent/skills && cp -r skills/memoria ~/.pi/agent/skills/`.
82
-
83
- ### Install as a pi package
84
-
85
- ```bash
86
- pi install git:github.com/rcsaquino/pi-memoria@v0.1.3
87
- pi install npm:pi-memoria # if published to npm
88
- pi install ./path/to/pi-memoria # or from a local checkout
89
- pi list
90
- pi remove git:github.com/rcsaquino/pi-memoria@v0.1.3
91
- ```
92
-
93
- `pi install` records the package in `~/.pi/agent/settings.json` (or
94
- `.pi/settings.json` with `-l`, which loads only after project trust) and clones
95
- the repository to `~/.pi/agent/git/<host>/<owner>/<repo>`. It runs
96
- `npm install --omit=dev` in the clone; this package declares the pi-provided
97
- modules as *optional* peers so npm does not fetch a second, ~450 MB copy of pi.
98
- The installed package is around 700 KB with no `node_modules`.
99
-
100
- The package also ships a skill (`skills/memoria/SKILL.md`) that teaches an agent
101
- how to maintain the library — where a fact belongs, how to consolidate notes, and
102
- what never to do.
19
+ Restart pi or run `/reload` to load the extension and its bundled skills.
20
+ No configuration is required.
103
21
 
104
- ### Try it without installing
22
+ Alternatively, install a tagged release from GitHub:
105
23
 
106
- ```bash
107
- pi --extension /path/to/memoria/index.ts
108
- # from a checkout:
109
- pi -e ./index.ts
24
+ ```sh
25
+ pi install git:github.com/rcsaquino/pi-memoria@v0.2.0
110
26
  ```
111
27
 
112
- ## Quick start
113
-
114
- Nothing to configure. In a session:
28
+ Use one installation method, not both.
115
29
 
116
- ```
117
- You: Remember that I take my coffee with oat milk and I'm lactose intolerant.
118
- Agent: [memoria_write { topic: "Dietary preferences", category: "preferences" }]
30
+ ## Use it
119
31
 
120
- ... days later, in a different project ...
32
+ Ask pi to remember something:
121
33
 
122
- You: Order me a flat white.
123
- Agent: [auto-recall surfaces "Dietary preferences — drinks oat milk; lactose intolerant"]
34
+ ```text
35
+ Remember that I use pnpm for personal projects and prefer tabs over spaces.
124
36
  ```
125
37
 
126
- Other things you can say or run:
38
+ In a later session, relevant notes are added to the agent's context automatically.
39
+ You can also ask directly:
127
40
 
128
- ```bash
129
- /memoria status # where the store is and how healthy it is
130
- /memoria store remember to renew the Datadog contract in August
131
- /memoria search datadog contract
132
- /memoria topics # review notes: facts, size, usage, merge candidates
133
- /memoria doctor # consistency problems and housekeeping hints
134
- /memoria learn # extract durable facts from this session
41
+ ```text
42
+ What package manager do I use for personal projects?
43
+ What did we decide about the deployment last week?
135
44
  ```
136
45
 
137
- ## How it works
138
-
139
- 1. **`MEMORY.md`** lives in the store root and is injected into the system
140
- prompt on every model call, capped at `hotLimit` (5000 characters). It is a
141
- short **prose** briefing — who the user is, how they work, hard constraints,
142
- the state of active work — not a log: no headings, no bullets, no
143
- annotations. Being stable, it does not invalidate the prompt cache.
144
- 2. **Auto-recall** searches the library on every user prompt and injects the
145
- best matches as a `memoria_recall` message, with ids, paths and excerpts. The
146
- previous turn is folded in at a lower weight (`autoRecallPriorWeight`) so a
147
- long earlier message cannot out-vote the current question.
148
- 3. **`memoria_recall`** lets the agent search deeper, with filters for category,
149
- tags, priority, recency, scope and score, plus an optional scoring breakdown.
150
- 4. **Plain markdown**: `library/INDEX.md` and per-category indexes provide a
151
- generated table of contents, and `read`/`grep`/`cat` work on the files.
152
- 5. **Past conversations**: if the library has nothing, the transcripts pi saved
153
- for earlier sessions are searched as a last resort, with file-and-line
154
- citations so anything found can be verified in context.
155
-
156
- Ranking combines BM25 over weighted fields (title, tags, aliases, links,
157
- summary, category, body) with boosts for exact phrases, priority, recency, query
158
- coverage, time windows ("last week"), related notes, and a demotion for notes
159
- that a newer note declares superseded. Matching is resilient: identifiers and
160
- paths match literally, plurals and verb forms match through a conservative
161
- stemmer, `kuber` finds `kubernetes`, one or two typos still hit, and CJK text is
162
- matched with unigrams and bigrams.
163
-
164
- ## The memory library
46
+ Useful commands:
165
47
 
166
- ```
167
- <agent dir>/memoria/
168
- ├── MEMORY.md always-injected prose briefing
169
- ├── config.json optional store configuration
170
- ├── synonyms.json optional query-side synonym table
171
- ├── library/
172
- │ ├── INDEX.md generated table of contents
173
- │ ├── people/<topic>.md one note per broad topic
174
- │ ├── projects/<topic>.md
175
- │ ├── preferences/<topic>.md
176
- │ ├── decisions/<topic>.md
177
- │ ├── workflows/<topic>.md
178
- │ ├── knowledge/<topic>.md
179
- │ └── inbox/<topic>.md quick captures, triaged later
180
- ├── .index/ derived: index.json|index.bin, usage.json
181
- └── .trash/ soft-deleted notes
182
- ```
48
+ | Command | Purpose |
49
+ | --- | --- |
50
+ | `/memoria` | Show store status and the briefing's size |
51
+ | `/memoria search <query>` | Search saved notes |
52
+ | `/memoria sessions <query>` | Search earlier conversations |
53
+ | `/memoria topics` | Review notes and possible duplicates |
54
+ | `/memoria doctor` | Check for consistency problems |
55
+ | `/memoria paths` | Show storage locations |
183
56
 
184
- `<agent dir>` is `~/.pi/agent` by default, or `$PI_CODING_AGENT_DIR` when pi's
185
- agent directory is customized. Because the store is user-level, memories follow
186
- you across projects: remember something in one repository and recall it in
187
- another.
188
-
189
- Pi's own conversation transcripts live next to the store at
190
- `<agent dir>/sessions/` (plus `sessions-archive/` if you keep one). They are read
191
- by [session recall](#session-recall-past-conversations) and never modified.
192
-
193
- ### Broad topics, never facts
194
-
195
- | User says | Stored as | Not as |
196
- |---|---|---|
197
- | "I like apples" | `library/preferences/food-preferences.md` → `- **Fruit** — Likes apples.` | `likes-apples.md` |
198
- | "I like pears" | appended to the same `food-preferences.md` | `likes-pears.md` |
199
- | "Alice prefers oat milk" | `library/people/alice.md` | `alice-prefers-oat-milk.md` |
200
- | "my dad is Bob" | `library/people/bob.md` → `- **Bob** — John's father, retired.` | `dad.md`, `johns-father.md` |
201
-
202
- Rules enforced by the store, not merely requested from the model:
203
-
204
- - The file name is always `slugify(topic)`. Topics that read like a single fact
205
- (`likes apples`, `I like apples`) or like a **relationship** (`John's father`,
206
- `dad`, `Alice's manager`) are rejected and the fact is filed under the category
207
- name instead (`people.md`), with an explanatory note returned to the agent.
208
- A relationship goes in the fact text; the note is named after the subject.
209
- - Writing to an existing topic **appends** under a `## Facts` section, skipping
210
- duplicates. There is no one-file-per-fact path.
211
- - A note may grow to `topicMaxChars` (default 8000) before new facts spill into
212
- `topic-2.md`.
213
- - `memoria_write` accepts `mode: "new"` to force a sibling file and
214
- `mode: "replace"` to overwrite a note deliberately.
215
- - `memoria doctor` flags any file named after a fact or a relationship.
216
-
217
- ### Names change: aliases first, renames second
218
-
219
- A person is not their name, and the first name you learn is rarely the one you
220
- keep. Notes therefore carry **aliases** in frontmatter, indexed at tag weight:
221
-
222
- ```markdown
223
- ---
224
- topic: Bob
225
- aliases: ["Robert", "Bobby", "John's father"]
226
- ---
227
- ```
57
+ Saving a fact and retrieving it are separate steps. Automatic recall searches
58
+ existing notes; it does not turn every conversation into a memory. The agent
59
+ saves a note when something is worth keeping.
228
60
 
229
- Any of `Bob`, `Robert`, `Bobby`, `John's father` — and the file name — recalls
230
- the note, so retrieval never depends on which name won the file name.
61
+ ## What gets remembered
231
62
 
232
- When the better name *is* known, `memoria_move` re-files the note:
63
+ Memoria keeps three sources of context:
233
64
 
234
- - Target free → the file is **renamed**; the note keeps its `id`, so ids read
235
- earlier in the session stay valid.
236
- - Target exists → the move reports a conflict. Set `merge: true` to combine the
237
- facts and links (duplicates skipped, nothing overwritten) and move the old
238
- file to `.trash/`. A merge refuses to discard aliases or links when their
239
- limits are full.
240
- - The previous topic, title and file name are added to the target's aliases, so
241
- old references keep working.
65
+ - **A short briefing** (`MEMORY.md`): standing preferences and context included
66
+ in the system prompt. Limited to 5,000 characters by default.
67
+ - **Topic notes** (`library/`): people, projects, decisions and other details
68
+ retrieved when relevant. Facts about the same subject accumulate in one file.
69
+ - **Saved conversations**: read-only searches of pi's transcripts, with file and
70
+ line references so the agent can check the surrounding dialogue.
242
71
 
243
- Renaming is deliberately an explicit agent action rather than a side effect of
244
- writing: renaming during an unrelated write is how you end up with `bob-2.md`
245
- and a path the agent read earlier in the session that no longer exists.
72
+ For example, several preferences belong in `preferences/dietary-preferences.md`,
73
+ not separate `likes-apples.md` and `likes-pears.md` files. Notes support aliases,
74
+ links and superseded decisions. Renaming a note preserves its identity; merging
75
+ notes requires an explicit request.
246
76
 
247
- ### Related notes and superseded notes
77
+ The default store is separate from the installed extension:
248
78
 
249
- ```markdown
250
- ---
251
- related: ["mem_1758_ab12"] # pulled into recall with the source note
252
- supersedes: ["Deploy process"] # this note replaces that one
253
- ---
254
- ```
255
-
256
- - `related` notes are appended to recall results (`related` marker) and shown by
257
- `memoria_read`, so following a reference works from either end.
258
- - A note that another note declares `supersedes` stays searchable but is
259
- **demoted and flagged** (`SUPERSEDED BY: …`). That is the recommended way to
260
- change a decision: write the new note with `supersedes` instead of deleting
261
- history.
262
- - `memoria doctor` reports dangling links and fact pairs that look contradictory
263
- (same wording, opposite polarity).
264
-
265
- ### Note format
266
-
267
- Notes are markdown with optional YAML frontmatter. Frontmatter is written
268
- automatically on the first `memoria_write`; hand-written notes without it are
269
- still indexed (the title comes from the first `#` heading, the category from the
270
- folder).
271
-
272
- ```markdown
273
- ---
274
- id: mem_1758712445123_a1b2c3
275
- title: Dietary preferences # broad topic = note title
276
- topic: Dietary preferences # drives the file name: dietary-preferences.md
277
- category: preferences
278
- tags: [alice, dietary, food]
279
- aliases: ["Dairy", "Food preferences"]
280
- related: []
281
- supersedes: []
282
- created: 2025-09-24T09:14:05.123Z
283
- updated: 2025-09-24T09:14:05.123Z
284
- last_used: 1758712445123 # refreshed lazily on recall
285
- source: agent
286
- confidence: high
287
- priority: normal
288
- summary: Oat milk in coffee; lactose intolerant.
289
- ---
290
-
291
- # Dietary preferences
292
-
293
- ## Facts
294
-
295
- - **Drinks** — Drinks oat milk in flat whites; avoids dairy.
296
- - **Fruit** — Likes apples and pears; dislikes durian.
79
+ ```text
80
+ ~/.pi/agent/memoria/
81
+ ├── MEMORY.md
82
+ ├── config.json # optional settings
83
+ ├── library/
84
+ │ ├── people/
85
+ │ ├── projects/
86
+ │ └── preferences/
87
+ ├── .index/ # rebuildable search data
88
+ └── .trash/ # recoverable deleted notes
297
89
  ```
298
90
 
299
- Fields: `topic` (broad grouping, drives the file name), `priority`
300
- (`low|normal|high|critical`, boosts ranking), `confidence`, `tags`, `aliases`
301
- (all indexed), `related`, `supersedes`, `summary` (used in listings and recall),
302
- `last_used` (maintained by the store), and `category` (kept in sync with the
303
- folder). Unknown keys are preserved verbatim through updates.
304
-
305
- ## Tools
306
-
307
- | Tool | Purpose |
308
- |---|---|
309
- | `memoria_recall` | Search long-term memory. Filters by category, tags, priority, recency, scope; options for `include_body`, `min_score`, `explain`, `rerank`, `drop_superseded`, prefix/fuzzy control. |
310
- | `memoria_write` | Add a fact to a broad **topic note** (`topic`, `content`, optional `label`, category, tags, aliases, related, supersedes, summary, priority). Creates the note on first use and appends afterwards. |
311
- | `memoria_read` | Read a full note by id, path or alias, with its aliases, related notes and superseding notes. |
312
- | `memoria_move` | Re-file a note under a better broad topic (`from`, `topic`, optional `category`, `merge`, `keep_alias`). Renames when the target is free; set `merge: true` to combine with an occupied target. |
313
- | `memoria_sessions` | Search the transcripts of earlier conversations (`action: "search"`, plus `since_days`, `project`, `include_tools`, `user_only`) and read the surrounding dialogue (`action: "read"`, `path`, `line`, `window`) before quoting it. |
314
- | `memoria_hot` | Read/add/remove/replace/compact `MEMORY.md`, the always-in-context briefing. |
315
- | `memoria_list` | Browse categories, titles, ids, tags, aliases and summaries. |
316
- | `memoria_forget` | Move a note to `.trash/` (recoverable). |
317
- | `memoria_export` | Dump the store to JSONL, inline or to a file. |
318
- | `memoria_import` | Restore from JSONL (`mode: merge|replace|skip`, `dry_run`). |
319
-
320
- The agent's system prompt teaches it when to use them, so you normally do not
321
- have to ask.
322
-
323
- ## Commands
324
-
325
- ```
326
- /memoria Store status, index stats, MEMORY.md budget
327
- /memoria search <query> Ranked results with snippets (--primary/--project/--all)
328
- /memoria store <text> Quick capture into library/inbox
329
- /memoria read <id|path> Print a full note
330
- /memoria move <ref> <topic> [--merge] Re-file a note; opt into merging an occupied target
331
- /memoria hot Show MEMORY.md
332
- /memoria topics Review notes: facts, size, usage, merge candidates
333
- /memoria diff [days] Memories created or updated recently (default 7 days)
334
- /memoria sessions <query> Search earlier conversations (--days=N --project=X --tools --user)
335
- /memoria sessions --read <path> <line> [--window=N] Show the surrounding dialogue
336
- /memoria doctor Consistency problems and housekeeping hints
337
- /memoria export [file] Dump the store to JSONL (default ./memoria-export-<date>.jsonl)
338
- /memoria export --hot [file] Write MEMORY.md alone as an "about me" document
339
- /memoria import <file> Restore from JSONL (--merge|--replace|--skip, --dry-run)
340
- /memoria learn Extract durable memories from the current session
341
- /memoria reindex Rebuild the search index from disk
342
- /memoria index Regenerate library/INDEX.md files
343
- /memoria paths Print store paths
344
- /memoria forget <id> Move a note to .trash
345
- ```
91
+ If you set `PI_CODING_AGENT_DIR`, the store follows that directory. You can read
92
+ and edit notes with a text editor; the index picks up changes automatically.
346
93
 
347
94
  ## Configuration
348
95
 
349
- Create `config.json` in the store root (`~/.pi/agent/memoria/config.json`) to
350
- override any default. Everything is optional; unknown or malformed values fall
351
- back to the default rather than failing.
96
+ Create `~/.pi/agent/memoria/config.json` to override defaults. For example, to
97
+ add a project store and teach search an abbreviation:
352
98
 
353
99
  ```json
354
100
  {
355
- "autoRecall": true,
356
- "autoRecallLimit": 6,
357
- "topicMaxWords": 6,
358
- "exclude": ["library/scratch"],
359
101
  "projectRoot": ".pi/memoria-project",
360
- "autoLearn": "on-settle",
361
102
  "synonyms": { "k8s": ["kubernetes"] }
362
103
  }
363
104
  ```
364
105
 
106
+ The primary store is user-wide. `projectRoot` adds an optional writable project
107
+ store; `extraRoots` adds read-only stores. Reranking is off by default because
108
+ it makes an additional model call per search.
109
+
110
+ <details>
111
+ <summary>All configuration options</summary>
112
+
365
113
  | Key | Default | Meaning |
366
114
  |---|---:|---|
367
115
  | `rootDir` | `"$AGENT_DIR/memoria"` | Primary store. Supports `$AGENT_DIR`, `~/`, absolute and cwd-relative paths. |
@@ -370,9 +118,10 @@ back to the default rather than failing.
370
118
  | `hotLimit` | `5000` | Hard cap for `MEMORY.md`, in characters. |
371
119
  | `snippetChars` | `280` | Body excerpt length per hit. |
372
120
  | `autoRecall` | `true` | Search the library on every user prompt. |
373
- | `autoRecallLimit` | `6` | Maximum notes injected per prompt. |
121
+ | `autoRecallLimit` | `3` | Maximum notes injected per prompt. |
122
+ | `autoRecallMinRatio` | `0.3` | Automatic hits must score at least this fraction of the strongest eligible hit; set to `0` to disable the relative cutoff. |
374
123
  | `autoRecallMinScore` | `1.4` | Score floor for auto-recall. |
375
- | `autoRecallMaxChars` | `2400` | Character budget for the injected recall block. |
124
+ | `autoRecallMaxChars` | `2400` | Strict total character budget, including wrappers and transcript fallback. |
376
125
  | `autoRecallLastTurns` | `1` | Previous turns folded into the recall query. |
377
126
  | `autoRecallPriorWeight` | `0.4` | Weight of those previous turns versus the current prompt. |
378
127
  | `bodyCacheBytes` | `8388608` | In-memory body cache budget. |
@@ -397,11 +146,6 @@ back to the default rather than failing.
397
146
  | `rerankModel` | `""` | Model id (`provider/model`); empty uses the session model. |
398
147
  | `rerankTopK` | `12` | Candidates shown to the reranker. |
399
148
  | `rerankTimeoutMs` | `2500` | Reranker budget before falling back to lexical order. |
400
- | `autoLearn` | `"off"` | `off`, `on-settle` (after the agent goes idle) or `on-shutdown`. |
401
- | `autoLearnMinTurns` | `8` | Minimum user turns before automatic extraction. |
402
- | `autoLearnMinChars` | `2000` | Minimum transcript size before automatic extraction. |
403
- | `autoLearnCooldownMs` | `21600000` | Minimum gap between automatic extractions. |
404
- | `learnChunkChars` | `12000` | Characters per extraction chunk (long sessions are chunked). |
405
149
  | `indexFormat` | `"auto"` | `auto` (binary above 20k notes), `json` or `binary`. |
406
150
  | `sessionSearch` | `true` | Search saved session transcripts at all. |
407
151
  | `sessionRoots` | `[]` | Extra transcript roots (searched before `<agent dir>/sessions`). |
@@ -412,282 +156,69 @@ back to the default rather than failing.
412
156
  | `sessionIncludeTools` | `false` | Include tool calls/results and compaction summaries by default. |
413
157
  | `sessionRipgrep` | `true` | Use a ripgrep prefilter to skip match-free transcripts when `rg` is available; without it the slower built-in scanner runs. |
414
158
 
415
- ## Scopes: personal, project, read-only
416
-
417
- - **`primary`** (default) — the user-level store at `<agent dir>/memoria`.
418
- Memories follow you across projects.
419
- - **`project`** — set `projectRoot` to keep project-specific memories in the
420
- repository (`"projectRoot": ".pi/memoria-project"`). It is writable: pass
421
- `scope: "project"` to write there, while reads default to `all`.
422
- - **`all`** — primary + project + extra roots, read paths merged.
423
- - **`extraRoots`** — additional stores that are always **read-only**, for a
424
- shared team library or an imported archive.
425
- - **`global`** — legacy alias for `primary`.
426
-
427
- Cross-store results are rank-normalized: a small store's best hit is lifted to
428
- the global best (up to 4×) instead of being drowned by a large one, and a note
429
- that exists in two stores is returned once.
430
-
431
- ## Synonyms
432
-
433
- Domain shorthand rarely appears in the notes you wrote earlier. Drop a
434
- `synonyms.json` in the store root (or inline the table in `config.json`) and
435
- expansion happens at query time, both directions, with no re-indexing:
436
-
437
- ```json
438
- {
439
- "k8s": ["kubernetes"],
440
- "postgres": ["postgresql", "pg"],
441
- "auth": ["authentication", "login"],
442
- "oncall": ["on-call", "pager"]
443
- }
444
- ```
159
+ </details>
445
160
 
446
- ## Model reranking
161
+ ## Privacy and limits
447
162
 
448
- BM25 is exact but literal: it does not know which of five plausible notes you
449
- mean. With `"rerank": true`, the top candidates (`rerankTopK`) are shown to the
450
- session model, which returns them in relevance order, within
451
- `rerankTimeoutMs`. Reranking is strictly best-effort: on timeout, error, missing
452
- auth or an unparsable reply, lexical order is used, so it can never make recall
453
- fail. It is off by default because it costs a model call per search.
163
+ **Local storage does not mean model-private memory.** The briefing, recalled
164
+ notes and returned transcript excerpts become part of the configured model's
165
+ context. With a hosted model, that content is sent to its provider. Reranking
166
+ also sends content to the configured model when enabled.
454
167
 
455
- ## Automatic session learning
168
+ - Notes are not encrypted, and memoria does not detect or redact credentials.
169
+ Do not store secrets.
170
+ - Search is lexical (BM25 with aliases, synonyms, prefix and fuzzy matching),
171
+ not embedding-based. It can miss a paraphrase with no matching terms.
172
+ - Recall is bounded. Relevant notes can be omitted by score or context limits;
173
+ transcript searches report `partial` when they run out of scan budget.
174
+ - Reranking can reorder retrieved notes, not find notes that search missed.
175
+ - Deletes move notes to `.trash/`. This is recovery, not secure erasure.
176
+ - Writes use atomic file replacement, but separate pi processes are not
177
+ coordinated as concurrent writers. Keep backups.
456
178
 
457
- `/memoria learn` extracts durable facts from the current session. Long
458
- conversations are chunked (`learnChunkChars`, at most 4 calls) and progress is
459
- shown in the status line. Set `autoLearn` to `"on-settle"` (after the agent
460
- finishes a turn) or `"on-shutdown"` to run it without asking. Guards keep it
461
- cheap: at least `autoLearnMinTurns` user turns, at least `autoLearnMinChars` of
462
- transcript, and at most one extraction per `autoLearnCooldownMs`. The default is
463
- `"off"` because it spends model tokens.
179
+ ## Backup and troubleshooting
464
180
 
465
- ## Session recall (past conversations)
181
+ Back up the store by copying `~/.pi/agent/memoria/` (or
182
+ `$PI_CODING_AGENT_DIR/memoria/`). Notes are plain markdown, so a folder copy is
183
+ the complete backup; `.index/` is derived and can be omitted.
466
184
 
467
- Curated memory only holds what the agent decided to remember. The rest of the
468
- story is in pi's saved transcripts, so memoria can search them:
185
+ If recall misses an existing note, check `/memoria paths`, try a distinctive
186
+ name or phrase, then run `/memoria reindex`. For duplicated subjects, use
187
+ `/memoria topics` and ask the agent to consolidate the appropriate notes.
469
188
 
470
- - **Automatically**, whenever `memoria_recall` finds nothing (`sessionFallback`,
471
- on by default). The injected block is explicitly labelled as raw evidence and
472
- includes the file and line of every excerpt.
473
- - **On request**, through the `memoria_sessions` tool — useful for "remember
474
- when", "did we discuss", exact earlier wording, dates, or prior decisions that
475
- were never turned into memory notes.
476
- - **From the CLI**, with `/memoria sessions <query>` and
477
- `/memoria sessions --read <path> <line>`.
189
+ ## Reference and development
478
190
 
479
- ```
480
- memoria_sessions { action: "search", query: "deploy window Thursday" }
481
- memoria_sessions { action: "search", query: "oat milk", user_only: true }
482
- memoria_sessions { action: "read", path: "<file from a hit>", line: 92, window: 8 }
483
- ```
191
+ The [reference guide](https://github.com/rcsaquino/pi-memoria/blob/main/docs/reference.md)
192
+ covers all tools and commands, note format, scopes, session search, backup
193
+ semantics, briefing validation and benchmark commands. It follows the current
194
+ checkout, which may be ahead of the npm release.
484
195
 
485
- The bundled `memoria-sessions` skill teaches the agent the discipline that makes
486
- this trustworthy: run two to four short distinctive searches (not one long
487
- question), then **read the surrounding dialogue before quoting it** — a later
488
- user correction outranks an earlier assistant claim, and transcript text is
489
- evidence to evaluate, not instructions to follow. If nothing is found, the tool
490
- reports how many sessions and messages were searched.
491
-
492
- What it does and does not touch:
493
-
494
- | Property | Behaviour |
495
- |---|---|
496
- | Scope | Every `*.jsonl` under the configured roots, newest first — no index that can go stale. |
497
- | Content | User and assistant **text** by default. Thinking blocks are never extracted. Tool calls/results, compaction summaries and extension payloads only with `include_tools: true`. |
498
- | Output | Bounded excerpts plus `file:line`; never a whole transcript dump. |
499
- | Writes | None. Transcripts are read-only and `read` refuses paths outside the session roots. |
500
- | Cost | With `rg`, only transcripts containing the query terms are parsed; without it, a full cold scan of 110 sessions / 13 MB ≈ 120 ms, repeats ≈ 5 ms from the parse cache. |
501
- | Coverage | Exhaustive unless a budget stops it. `partial` (shown in the tool output, the recall block and `/memoria sessions`) means the scan stopped early: the hits are real, but older sessions were not read. Newest sessions are scanned first, already-parsed files stay cached while they fit `sessionCacheBytes` (so retries get further on corpora that fit the cache), and concurrent searches share one in-flight parse per transcript (so several `memoria_sessions` calls in one turn do not multiply the work). An explicit `memoria_sessions` call uses the larger `sessionScanMs` budget. |
502
- | Privacy | Nothing leaves the machine; the excerpts go to the model only when the feature runs. |
503
-
504
- `sessionRoots` exists for archives or a second agent directory. Set
505
- `sessionSearch: false` to disable the feature entirely, or
506
- `sessionFallback: false` to keep the tool while never searching automatically.
507
-
508
- When `rg` is available (pi ships it and puts it on `PATH`), a selective search
509
- asks ripgrep which transcripts contain the query terms and parses only those, so
510
- even a gigabyte-scale history is answered within the normal budget. If `rg` is
511
- missing or fails, memoria falls back to reading every transcript itself and says
512
- so: the result carries a `ripgrep is not installed` note, and interactive mode
513
- shows it once per session. Large histories may then be only partially covered.
514
-
515
- Without `rg` (or for a deliberately disabled accelerator), the default
516
- `sessionScanMs` budget and `sessionCacheBytes` cache cover only part of a large
517
- corpus: searches report `partial`, and repeats are cold scans because the cache
518
- cannot retain the parsed files. Raise `sessionScanMs` so an explicit
519
- `memoria_sessions` call can cover the whole corpus in one pass, and
520
- `sessionCacheBytes` only if you have the RAM for the parsed messages (at this
521
- scale that means gigabytes). The automatic fallback remains capped at 400 ms,
522
- so on such a corpus it is always a partial scan.
523
-
524
- ## Backup and migration
525
-
526
- `memoria_export` writes JSONL — one record per line, notes plus `MEMORY.md` — to
527
- a file or returns a bounded preview. `memoria_import` restores it:
196
+ To work on the extension from a clone:
528
197
 
529
- ```
530
- memoria_export { path: "memoria-backup.jsonl" }
531
- memoria_import { path: "memoria-backup.jsonl", dry_run: true }
532
- memoria_import { path: "memoria-backup.jsonl", mode: "merge" }
198
+ ```sh
199
+ npm install
200
+ npm run typecheck
201
+ npm test
202
+ npm run eval
203
+ npm run bench
204
+ pi -e ./index.ts
533
205
  ```
534
206
 
535
- - `merge` (default) adds facts that are missing, never duplicating an id.
536
- - `replace` overwrites notes with the same id.
537
- - `skip` only imports notes that do not exist yet.
538
- - Notes keep their ids, so ids in an old transcript still resolve.
539
- - Paths are validated: an import cannot write outside `library/`, and a path
540
- already taken by a different note gets a numbered sibling instead of an
541
- overwrite.
542
-
543
- The same files remain readable as plain markdown if you stop using memoria, and
544
- the whole store is safe to commit to a private repository (`.index/` is derived
545
- and can be deleted).
546
-
547
- ## Performance
548
-
549
- `node tests/bench.ts 1000 5000` measures a worst-case corpus (50-word
550
- vocabulary, 60-word documents, so every posting list is long);
551
- `node tests/bench.ts 1000 5000 --real` uses a realistic high-vocabulary corpus
552
- (~44k distinct terms at 5k notes).
553
-
554
- | Corpus | Notes | Index size | Cold load | Reload | Search | Prefix | Fuzzy |
555
- |---|---:|---:|---:|---:|---:|---:|---:|
556
- | worst case | 1,000 | 1.3 MB | 219 ms | 23 ms | 0.35 ms | 0.22 ms | 0.32 ms |
557
- | worst case | 5,000 | 6.8 MB | 1.10 s | 109 ms | 0.89 ms | 0.66 ms | 0.94 ms |
558
- | realistic | 5,000 | 8.5 MB | 1.34 s | 134 ms | 1.20 ms | 0.64 ms | 1.02 ms |
559
- | realistic | 20,000 | 34.5 MB | 5.4 s | 543 ms | 5.88 ms | 2.63 ms | 4.30 ms |
560
-
561
- Auto-recall runs on every prompt, which is why the search path is
562
- allocation-light: a dense scratch-buffer BM25 loop, posting lists in memory, and
563
- snippets read only for the final hits. Recency scans are throttled
564
- (`scanIntervalMs`) and coalesced from filesystem events (`watcherSettleMs`), so
565
- a burst of edits costs one refresh.
566
-
567
- ## Privacy and durability
568
-
569
- - **Local only.** Nothing is sent anywhere except by the optional reranker and
570
- session learning, which use the model you already configured and only when
571
- enabled.
572
- - **Files, not a database.** Memoria never owns your data: notes are markdown
573
- with frontmatter, deletes are soft (moved to `.trash/`), and the index is
574
- derived and can be rebuilt with `/memoria reindex`.
575
- - **Crash-safe moves.** Category moves, renames and merges are journaled. On
576
- restart, a merge only removes its source after the target has all its facts
577
- and the source's former id.
578
- - **Atomic writes.** Every write goes through a temp file and rename; there is no
579
- window where a note is half-written.
580
- - **Scoped reads.** `memoria_read` only follows paths inside the memory library;
581
- transcript window reads refuse paths or symlinks outside configured roots.
582
- - **Secrets:** memoria does not scan for credentials, and the learn prompt tells
583
- the model not to store them. If you keep secrets in the store anyway, remember
584
- that recall may surface them in model context — treat the store like your shell
585
- history.
586
-
587
- ## Troubleshooting
588
-
589
- | Symptom | Fix |
590
- |---|---|
591
- | Notes exist but recall finds nothing | `/memoria reindex`; check `/memoria paths` for the store location; remember scopes (`--all` searches every root). |
592
- | A note is filed under `people.md` instead of the person's name | The topic was rejected as fact-shaped or relational. Write with the person's name as `topic` and put the relationship in the content. |
593
- | The same subject ended up in two notes | `/memoria topics` lists merge candidates with the exact `memoria_move` command; `memoria doctor` reports them too. |
594
- | `MEMORY.md` is over budget | `memoria_hot { action: "compact" }` drops the least important trailing paragraphs and returns them so you can file them into notes. |
595
- | A decision changed | Write the new note with `supersedes: ["<old id, path or title>"]`; the old note stays searchable but is demoted and flagged. |
596
- | Search misses domain shorthand | Add `synonyms.json` (see [Synonyms](#synonyms)). |
597
- | Model reranking is slow | Lower `rerankTopK`, or leave `rerank` off — lexical search is already sub-millisecond. |
598
- | Want to see what changed lately | `/memoria diff 3` for the last three days, `/memoria topics` for usage, and a session-start notification summarises changes since your previous session. |
599
- | An agent edited files and the index is stale | Filesystem events and a throttled scan pick changes up automatically; `/memoria doctor` shows the state. |
600
- | The user references something from before | The agent should search transcripts (`memoria_sessions`, or `/memoria sessions <query>`) rather than claim it does not remember; `/memoria paths` lists the session roots. |
601
- | Session search finds nothing | Try different wording, a name or a date, or `include_tools: true`; check `sessionRoots` covers the transcript location, and note that a budget-limited scan reports `partial`. |
602
-
603
- ## Development
604
-
605
- ```bash
606
- npm install # dev-only: pi host packages + typescript
607
- npm test # node:test, no build step
608
- npm run typecheck # tsc --noEmit
609
- npm run eval # recall@1/@5/MRR over the fixture corpus
610
- npm run bench # latency at 1k and 5k notes
611
- npm run bench:real # realistic high-vocabulary corpus
612
- pi -e ./index.ts # run the extension from the checkout
613
- ```
207
+ No build step is needed. See
208
+ [AGENTS.md](https://github.com/rcsaquino/pi-memoria/blob/main/AGENTS.md)
209
+ for architecture, invariants and contribution checks.
614
210
 
615
- The extension runs on Node's native type-stripping (`node >= 22.19`), which
616
- means no build step but also no `enum`, `namespace`, constructor parameter
617
- properties or `import x = require()` in the sources. Type-only imports must use
618
- `import type`, and relative imports include the `.ts` extension.
211
+ Report bugs through [GitHub Issues](https://github.com/rcsaquino/pi-memoria/issues).
212
+ Include your pi and Node versions, steps to reproduce, and relevant errors.
213
+ Remove personal memory content and credentials before sharing logs.
619
214
 
620
- Architecture, invariants and the release checklist live in
621
- [`AGENTS.md`](AGENTS.md). The short version:
215
+ ## Support My Work
622
216
 
623
- ```
624
- index.ts lifecycle hooks, system-prompt section, auto-recall, auto-learn
625
- src/types.ts shared types (no runtime imports)
626
- src/util.ts atomic writes, mutex, debounce, ids, paths
627
- src/frontmatter.ts dependency-free YAML-subset parser/serializer
628
- src/tokenize.ts identifiers, camel/snake/kebab, CJK, stemmer, trigrams
629
- src/config.ts defaults, coercion, path resolution
630
- src/store.ts filesystem: parse, write, merge, move, MEMORY.md, indexes
631
- src/index-engine.ts inverted index, persistence (JSON/binary), link resolution
632
- src/search.ts BM25, boosts, snippets, explain, related/superseded handling
633
- src/similarity.ts duplicate-topic and contradiction detection
634
- src/usage.ts hits/writes/last-used tracking
635
- src/timeexpr.ts "last week" → recency windows
636
- src/synonyms.ts query-side synonym tables
637
- src/transfer.ts JSONL export/import
638
- src/learn.ts session extraction (chunked)
639
- src/recall.ts prompt/message rendering
640
- src/rerank.ts optional model reranking
641
- src/runtime.ts roots, locks, caching, health, export/import, scopes
642
- src/tools.ts tool definitions and renderers
643
- src/commands.ts /memoria subcommands
644
- ```
217
+ If pi-memoria is useful to you, please consider supporting my work by
218
+ [buying me a coffee](https://ko-fi.com/rcsaquino). 😊
645
219
 
646
- ### Publishing your own copy
647
-
648
- 1. Push the repository to GitHub (public or private).
649
- 2. Keep `index.ts` at the package root and the `pi` manifest in `package.json`.
650
- 3. Leave the host modules as `peerDependencies` **and** mark them
651
- `"optional": true` in `peerDependenciesMeta`, keeping them in
652
- `devDependencies` for local tests only. Without that, npm installs a ~450 MB
653
- duplicate of pi into the package.
654
- 4. Tag releases (`git tag v<version> && git push --tags`) and install by tag:
655
- `pi install git:github.com/<you>/pi-memoria@v<version>`.
656
- 5. `npm pack --dry-run` should list only `index.ts`, `src/**`, `skills/**`,
657
- `README.md`, `LICENSE` and `package.json`.
658
-
659
- ## Design notes and limits
660
-
661
- - **Topic notes are the unit of storage.** This is deliberately opinionated: a
662
- file per fact fragments knowledge and makes retrieval worse. The cost is that
663
- the agent must pick a broad topic; when it picks badly, the store falls back to
664
- the category rather than creating a bad file name, and `memoria_move` fixes it
665
- later.
666
- - **Lexical, not semantic.** BM25 with a conservative stemmer, prefix and fuzzy
667
- matching is fast, deterministic and dependency-free, but it will not connect
668
- "my manager" to "Alice" without an alias or a synonym table. Embeddings would
669
- improve that; they are not worth the dependency for a store this fast.
670
- - **Cross-topic duplication is reported, not merged automatically.** The store
671
- flags two notes as duplicates only when their *names* also point at the same
672
- subject (equal slugs, or one name being a prefix/suffix of the other — e.g.
673
- `Alice` and `Alice Smith`, or a legacy `Johns father` note whose name appears
674
- as an alias). Content overlap alone is not enough: one person's note naturally
675
- describes the people around them, and merging John Doe with his father would be
676
- worse than missing a duplicate. Folding notes stays an explicit
677
- `memoria_move`, suggested on write and listed by `/memoria topics`.
678
- - **Usage is derived data.** `.index/usage.json` drives staleness and promotion
679
- hints; deleting `.index/` only loses those hints.
680
- - **Journal recovery covers moves, not arbitrary edits.** A crash between an
681
- atomic write and a trash move is repaired; a crash mid-edit of a single file
682
- leaves the previous content intact (writes are atomic).
683
- - **Model reranking instead of embeddings.** An embedding index would improve
684
- semantic matching, but pi exposes chat completions rather than an embedding
685
- API, and a vector store is a dependency this project does not want. The
686
- optional reranker gets the same effect (an LLM judging the top candidates) and
687
- degrades to lexical order on any failure. Time-scoped questions are handled by
688
- parsing the window out of the query rather than by time-decayed IDF: the note's
689
- own timestamp is the signal that matters.
220
+ <a href="https://ko-fi.com/rcsaquino" target="_blank" rel="noopener noreferrer"><img height="72" src="https://storage.ko-fi.com/cdn/kofi2.png?v=3" alt="Buy Me a Coffee at ko-fi.com" /></a>
690
221
 
691
222
  ## License
692
223
 
693
- MIT © 2026 rcsaquino. See [LICENSE](LICENSE).
224
+ [MIT](https://github.com/rcsaquino/pi-memoria/blob/main/LICENSE) © 2026 rcsaquino.