create-ai-memory 0.14.2 → 0.15.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 +369 -293
- package/bin/ai-mem-mcp.js +2 -0
- package/bin/ai-mem-serve.js +11 -1
- package/bin/create-ai-memory.js +11 -1
- package/hooks/claude/session-start.sh +9 -0
- package/hooks/claude/session-summary.sh +21 -2
- package/install.sh +3 -3
- package/package.json +1 -1
- package/shell/adapters.zsh +15 -0
- package/shell/ai-mem.zsh +645 -26
- package/web/viewer.html +25 -2
package/README.md
CHANGED
|
@@ -33,75 +33,40 @@ npm create ai-memory@latest
|
|
|
33
33
|
|
|
34
34
|
## The problem
|
|
35
35
|
|
|
36
|
-
Every AI coding session starts from zero.
|
|
36
|
+
Every AI coding session starts from zero. The moment a thread ends, the agent
|
|
37
|
+
forgets what was built, why each choice was made, and where you left off.
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
next run begins blind.
|
|
42
|
-
|
|
43
|
-
You pay the same tax on every run:
|
|
44
|
-
|
|
45
|
-
- **Agent amnesia.** Accumulated project knowledge vanishes when the thread closes.
|
|
46
|
-
- **Lost decisions.** Why a choice was made is nowhere; the next run re-litigates it.
|
|
47
|
-
- **Reload overhead.** You re-explain the stack, constraints, and conventions from scratch.
|
|
48
|
-
- **No continuity.** Nothing carries "where I left off" into the next session.
|
|
49
|
-
|
|
50
|
-
Switching agents makes it worse. Each CLI is its own island with its own memory,
|
|
51
|
-
or none. Knowledge earned in Claude doesn't reach Codex.
|
|
39
|
+
You pay it again on the next run: re-explaining the stack, re-litigating
|
|
40
|
+
settled decisions, losing "where I was". Switching agents makes it worse —
|
|
41
|
+
each CLI is its own island, so what Claude learned never reaches Codex.
|
|
52
42
|
|
|
53
43
|
## How it works
|
|
54
44
|
|
|
55
|
-
Keep the memory outside the chat, in plain Markdown on disk, and inject it
|
|
56
|
-
whichever agent you launch. A
|
|
57
|
-
Because it is just files, the same vault opens
|
|
58
|
-
[Obsidian](https://obsidian.md)
|
|
59
|
-
|
|
45
|
+
Keep the memory outside the chat, in plain Markdown on disk, and inject it
|
|
46
|
+
into whichever agent you launch. A thread is disposable; the vault is
|
|
47
|
+
permanent. Because it is just files, the same vault opens in
|
|
48
|
+
[Obsidian](https://obsidian.md) with graph view and backlinks — though
|
|
49
|
+
nothing here requires it.
|
|
60
50
|
|
|
61
|
-
|
|
51
|
+
Three layers, each injected at the right scope:
|
|
62
52
|
|
|
63
53
|
| Layer | Lives in | Injected | Holds |
|
|
64
54
|
|---|---|---|---|
|
|
65
|
-
| **Global** | `_Global_Profile.md`, `_Standards.md` | every session
|
|
66
|
-
| **Project** | `_projects/<repo>.md` | sessions in that repo | purpose, architecture, constraints,
|
|
55
|
+
| **Global** | `_Global_Profile.md`, `_Standards.md` | every session | who you are, your rules, commit policy |
|
|
56
|
+
| **Project** | `_projects/<repo>.md` | sessions in that repo | purpose, architecture, constraints, decisions |
|
|
67
57
|
| **Session** | `_session_logs/<repo>/<timestamp>.md` | next session as carryover | what changed, blockers, next steps |
|
|
68
58
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
$ claude-start
|
|
74
|
-
│
|
|
75
|
-
├─ resolve the project from the current git repo
|
|
76
|
-
├─ create a fresh session log from the template
|
|
77
|
-
├─ gather: Global Profile + Standards (who you are)
|
|
78
|
-
│ Project note (this repo)
|
|
79
|
-
│ prior session's outcome (where you left off, inlined)
|
|
80
|
-
├─ ask which session skills to enable (optional)
|
|
81
|
-
└─ launch the agent with all of it as the first prompt
|
|
82
|
-
│
|
|
83
|
-
▼
|
|
84
|
-
…you work…
|
|
85
|
-
│
|
|
86
|
-
▼
|
|
87
|
-
on exit, a hook writes an auto session log
|
|
88
|
-
(branch, commits made, uncommitted changes)
|
|
89
|
-
→ the NEXT session inherits it as carryover
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
The prior session's outcome is extracted from the log and inlined into the opening
|
|
93
|
-
prompt directly — not just a path the agent is told to go read. No separate file,
|
|
94
|
-
no index, nothing new in the vault: it's read straight out of the session log you
|
|
95
|
-
already have, every launch.
|
|
96
|
-
|
|
97
|
-
One environment variable, `AI_MEM_ROOT`, points at the vault, so the whole system
|
|
98
|
-
moves between machines by pointing at the same folder.
|
|
59
|
+
The prior session's outcome is **inlined into the opening prompt**, not left
|
|
60
|
+
as a path the agent is told to go read. One environment variable,
|
|
61
|
+
`AI_MEM_ROOT`, points at the vault, so the whole system moves between
|
|
62
|
+
machines by pointing at the same folder.
|
|
99
63
|
|
|
100
64
|
## The full loop
|
|
101
65
|
|
|
102
66
|
Agents read the vault through `ai-mem.zsh` at launch and write to it through a Stop
|
|
103
67
|
hook at close. You read the same files in Obsidian, or through `ai-mem-search` and
|
|
104
|
-
`ai-mem-lint`.
|
|
68
|
+
`ai-mem-lint`. Overnight, `ai-mem-sleep` tidies the same folder. Neither side gets a
|
|
69
|
+
privileged interface — it's the same folder either way.
|
|
105
70
|
|
|
106
71
|
```mermaid
|
|
107
72
|
sequenceDiagram
|
|
@@ -110,6 +75,7 @@ sequenceDiagram
|
|
|
110
75
|
participant Shell as claude-start
|
|
111
76
|
participant Agent as Claude Code
|
|
112
77
|
participant Vault as _Ai_Memory
|
|
78
|
+
participant Sleep as ai-mem-sleep
|
|
113
79
|
participant Backup as git backup (optional)
|
|
114
80
|
|
|
115
81
|
You->>Shell: claude-start
|
|
@@ -126,14 +92,22 @@ sequenceDiagram
|
|
|
126
92
|
Agent->>Vault: rewrite Auto Session Log (branch, commits, changes)
|
|
127
93
|
Agent->>Backup: commit + push, if the vault is git-backed
|
|
128
94
|
Note over Vault: nothing overwritten -- a fresh file every session
|
|
95
|
+
Note over Sleep: overnight, unattended -- installed by ai-mem-sleep-schedule
|
|
96
|
+
Sleep->>Vault: archive session logs older than 90d, newest 5 per project kept
|
|
97
|
+
Sleep->>Vault: lint links, flag dangling wikilinks and consolidation candidates
|
|
98
|
+
Sleep->>Backup: commit + push the archive move, if the vault is git-backed
|
|
99
|
+
Note over Vault,Sleep: _lessons/ are never archived and never pruned
|
|
129
100
|
You->>Shell: claude-start (next time)
|
|
130
101
|
Shell->>Vault: read prior session again
|
|
131
102
|
Note over Shell,Vault: now includes what just happened
|
|
132
103
|
```
|
|
133
104
|
|
|
134
|
-
Everything through step 10 touches only files on your machine. Step 11
|
|
135
|
-
only network
|
|
136
|
-
vault yourself; skip that and everything stays local,
|
|
105
|
+
Everything through step 10 touches only files on your machine. Step 11 and
|
|
106
|
+
step 14 are the only network calls in the whole loop, and both only exist if
|
|
107
|
+
you set up a git-backed vault yourself; skip that and everything stays local,
|
|
108
|
+
always. The overnight pass (steps 12-14) is the pruning half of the loop --
|
|
109
|
+
what decays, what is consolidated, and what is never touched is set out in
|
|
110
|
+
[Memory hygiene](#memory-hygiene).
|
|
137
111
|
|
|
138
112
|
## See a full session
|
|
139
113
|
|
|
@@ -167,7 +141,7 @@ exec zsh
|
|
|
167
141
|
Then, from inside any git repo:
|
|
168
142
|
|
|
169
143
|
```sh
|
|
170
|
-
claude-start # or codex-start /
|
|
144
|
+
claude-start # or codex-start / agy-start / cursor-start / opencode-start
|
|
171
145
|
```
|
|
172
146
|
|
|
173
147
|
The agent opens already knowing your standards, this project, and where you left
|
|
@@ -193,6 +167,8 @@ off last time.
|
|
|
193
167
|
- [Install](#install)
|
|
194
168
|
- [Commands](#commands)
|
|
195
169
|
- [How search works](#how-search-works)
|
|
170
|
+
- [What it costs](#what-it-costs-and-what-it-cannot-do)
|
|
171
|
+
- [Memory hygiene](#memory-hygiene)
|
|
196
172
|
|
|
197
173
|
</td>
|
|
198
174
|
<td valign="top" width="33%">
|
|
@@ -213,6 +189,8 @@ off last time.
|
|
|
213
189
|
|
|
214
190
|
**Project**
|
|
215
191
|
|
|
192
|
+
- [Why not just CLAUDE.md?](#why-not-just-claudemd)
|
|
193
|
+
- [Troubleshooting](#troubleshooting)
|
|
216
194
|
- [Why plain files](#why-plain-files)
|
|
217
195
|
- [Tests](#tests)
|
|
218
196
|
- [FAQ](#faq)
|
|
@@ -247,7 +225,7 @@ Every number below is reproducible with the command beside it.
|
|
|
247
225
|
|
|
248
226
|
| | before | after | |
|
|
249
227
|
|---|---|---|---|
|
|
250
|
-
| Launch prompt | 7,207 | **4,
|
|
228
|
+
| Launch prompt | 7,207 | **4,046** | −44%, mirrored notes injected once ([why](#mirrored-notes-are-not-injected-twice)) and inlined notes capped ([why](#every-path-into-the-prompt-is-bounded)) |
|
|
251
229
|
| Search result, common term | 10,234 | **1,752** | −83%, bounded output ([why](#how-search-works)) |
|
|
252
230
|
| Lesson index, 96 lessons | — | **+829** | ~8 tokens per lesson, names only ([why](#lessons-are-indexed-not-injected)) |
|
|
253
231
|
|
|
@@ -263,7 +241,8 @@ AI_MEM_SEARCH_LIMIT=999999 ai-mem-search postgres | wc -c
|
|
|
263
241
|
|
|
264
242
|
| | |
|
|
265
243
|
|---|---|
|
|
266
|
-
| Search, common term,
|
|
244
|
+
| Search, common term, 501-note vault | **0.07 s** |
|
|
245
|
+
| Search at 2,000 / 10,000 notes | 1.3 s / 7.2 s — linear, see [limits](#what-it-costs-and-what-it-cannot-do) |
|
|
267
246
|
| Shell startup cost of the module | **< 0.01 s** |
|
|
268
247
|
| Recency sort, v0.11.0 regression fix | 25.4 s → **0.54 s** (47×) |
|
|
269
248
|
|
|
@@ -286,7 +265,7 @@ implementations rather than guessing.
|
|
|
286
265
|
| Runtime dependencies | **0** |
|
|
287
266
|
| Package | **35 kB** (99.7 kB unpacked, 19 files) |
|
|
288
267
|
| Index, daemon, database, embeddings | **none** — a note is searchable the moment it is written |
|
|
289
|
-
| Tests | **
|
|
268
|
+
| Tests | **305**, no network, no framework |
|
|
290
269
|
|
|
291
270
|
```sh
|
|
292
271
|
npm pack --dry-run && zsh tests/run.sh
|
|
@@ -329,35 +308,40 @@ optional. Set `AI_MEM_ROOT` in `~/.zshrc` first if you do not want the default
|
|
|
329
308
|
|
|
330
309
|
| Command | What it does |
|
|
331
310
|
|---|---|
|
|
332
|
-
| `claude-start` · `codex-start` · `gemini-start` · `cursor-start` · `opencode-start` | Launch an agent with full vault context and the session-skill picker |
|
|
311
|
+
| `claude-start` · `codex-start` · `agy-start` · `gemini-start` · `cursor-start` · `opencode-start` | Launch an agent with full vault context and the session-skill picker |
|
|
333
312
|
| `ai-start [project]` | Prepare the session (project note and fresh log) without launching an agent |
|
|
334
313
|
| `ai-context [project]` | Print the vault context block for the current repo, and arm the git commit guard |
|
|
335
314
|
| `ai-note <text>` | Append a timestamped note to today's session log while you work |
|
|
336
315
|
| `ai-lesson <topic-slug> <problem> <solution>` | Append a dated Problem/Solution entry to a cross-project `_lessons/<topic-slug>.md` -- decisions, mistakes, solutions worth recalling outside the current project |
|
|
337
|
-
| `ai-mem-
|
|
338
|
-
| `ai-mem-
|
|
316
|
+
| `ai-mem-ingest --source-id <id> --title <t> --date <ISO> [...]` | File a distilled external artifact -- a meeting, a recorded call, a video, a voice note -- as one note in `_transcripts/`. Writes the summary, decisions, action items, attendee `[[wikilinks]]` and a link to the source; it never embeds the raw transcript body, because a full transcript is bulk the agent pays for and rarely needs. Re-ingesting the same `--source-id` updates that one note instead of filing a second copy. `ai-mem-search` covers `_transcripts/` with no extra path |
|
|
317
|
+
| `ai-mem-lint [--fix]` | Check the vault's links: orphaned session logs, dangling `previous` links, unreferenced project notes, notes missing the `type:` field, and **dangling `[[wikilinks]]`** -- a link pointing at a note that does not exist (a dead edge in the graph), reported but never auto-removed. `--fix` backfills `type:` into session logs written before the field existed |
|
|
318
|
+
| `ai-mem-search <term> [project]` | Case-insensitive literal search across the vault (or one project's logs). Lessons rank first, and within them by *reinforcement* -- a lesson recalled more often (more dated entries) ranks above a once-seen one -- then by date; archived logs (see `ai-mem-sleep`) are skipped. Paths print relative to a root stated once in the header. Output is capped (`AI_MEM_SEARCH_LIMIT`, default 25) with an explicit `N hidden` notice, because the usual caller is an agent with a finite context window. Also resolves any `[[wikilink]]` on a matched line to its project note -- one hop out along the graph, always on, not a flag to remember |
|
|
319
|
+
| `ai-mem-sleep [--apply]` | The vault's "bedtime" pass: archive stale session logs, flag consolidation candidates, and lint, in one run. Session logs older than `AI_MEM_SLEEP_DAYS` (default 90) move out of the hot search path -- always keeping the newest `AI_MEM_SLEEP_KEEP` (default 5) per project -- while `_lessons/` are never touched, because durable failure->fix knowledge is exactly what must survive. Dry-run by default; `--apply` moves logs into each project's `_archive/` (reversible via git) and backs up |
|
|
320
|
+
| `ai-mem-sleep-schedule [--install\|--uninstall] [--at HH:MM]` | Run the bedtime pass on its own, nightly (default 03:00). macOS installs a launchd agent; other platforms a crontab entry. The scheduled job sources the module first, since a cron/launchd shell does not read `~/.zshrc`. Dry-run by default -- prints exactly what it would install; `--install` schedules it, `--uninstall` removes it |
|
|
339
321
|
| `ai-mem-serve [port] [--no-open]` | Open the vault as a browsable graph on `127.0.0.1`. Agents run this for you when you ask to see your memory (see [Graph view](#graph-view)) |
|
|
340
322
|
| `ai-mem-vault-backup` | Commit and push the vault if it's git-backed. `ai-note`/`ai-lesson` already call this; use it directly after editing a session log or project note by hand |
|
|
341
323
|
|
|
324
|
+
`codex-note` and `codex-lesson` are aliases of `ai-note` and `ai-lesson`, for
|
|
325
|
+
muscle memory inside a Codex session; they behave identically.
|
|
326
|
+
|
|
342
327
|
Project is auto-resolved from the current git repo; pass a name to override.
|
|
343
328
|
|
|
344
329
|
## How search works
|
|
345
330
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
is findable the second you write it.
|
|
331
|
+
Reads your notes directly, every time. No index, no daemon, no embeddings —
|
|
332
|
+
nothing to rebuild and nothing that can go stale. A note is findable the
|
|
333
|
+
second you write it.
|
|
350
334
|
|
|
351
335
|
```mermaid
|
|
352
336
|
flowchart TD
|
|
353
337
|
A(["You look for a word"]) --> B{"Did you name<br/>a project?"}
|
|
354
|
-
B -->|"no"| C["Look through<br/>
|
|
338
|
+
B -->|"no"| C["Look through every note<br/>outside _archive/"]
|
|
355
339
|
B -->|"yes"| D["Look only inside<br/>that project"]
|
|
356
340
|
C --> E["Read them all.<br/>Capitals don't matter.<br/>Punctuation means itself."]
|
|
357
341
|
D --> E
|
|
358
342
|
E -->|"found nothing"| F["<b>Says so, plainly.</b><br/>Never a blank screen you<br/>could mistake for 'none exist'"]
|
|
359
343
|
E -->|"found something"| G["Newest first"]
|
|
360
|
-
G --> H["Show
|
|
344
|
+
G --> H["Show a few from each note<br/>and say how many more there are"]
|
|
361
345
|
H --> I["Follow any linked note one step,<br/>with a one-line summary of it"]
|
|
362
346
|
I --> J(["What you read"])
|
|
363
347
|
|
|
@@ -369,152 +353,211 @@ flowchart TD
|
|
|
369
353
|
class J done
|
|
370
354
|
```
|
|
371
355
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
That is the whole idea. The rest of this section is the mechanism -- one
|
|
376
|
-
`grep -rniF`, then a sort, then a cap -- and why each piece is the way it is.
|
|
377
|
-
Every flag exists because the alternative produced a wrong answer on a real
|
|
378
|
-
vault. Skip it unless you are changing the code.
|
|
356
|
+
The shaded boxes are the two that matter: an empty result that **says** it is
|
|
357
|
+
empty, and an output short enough to read to the end.
|
|
379
358
|
|
|
380
359
|
```console
|
|
381
360
|
$ ai-mem-search prisma
|
|
382
|
-
|
|
361
|
+
240 match(es) for 'prisma'
|
|
383
362
|
paths below /Users/you/_Ai_Memory
|
|
384
363
|
--
|
|
385
364
|
_session_logs/checkout-api/checkout-api-2026-08-31_00-00-00.md:56: - **A green deploy log is not evidence a migration ran.** Verify against `_prisma_migrations`.
|
|
386
|
-
_session_logs/checkout-api/checkout-api-2026-08-31_00-00-00.md:55: - **`prisma migrate deploy` cannot see `prisma/migrations/<name>.sql`.** Only `<name>/migration.sql`. It skips loose files silently -- a [...]
|
|
387
365
|
...
|
|
388
366
|
--
|
|
389
|
-
showing
|
|
367
|
+
showing 25 of 240 (215 hidden), across 25 file(s), at most 1 line(s) each -- for more lines per file raise AI_MEM_SEARCH_PER_FILE, or narrow with: ai-mem-search 'prisma' <project>
|
|
390
368
|
```
|
|
391
369
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
explicit `no matches` message is exactly what makes it look authoritative.
|
|
395
|
-
Measured on a real vault: `precompact` found 0 matches case-sensitively and 3
|
|
396
|
-
with `-i`; `Postgres` found 56 versus 90.
|
|
397
|
-
|
|
398
|
-
**Literal, not regex (`-F`).** The caller is usually an agent passing free
|
|
399
|
-
text, where a stray `.`, `(` or `|` must match itself. `ai-mem-search .env`
|
|
400
|
-
finds `.env`, not every four-character string ending in `env`.
|
|
401
|
-
|
|
402
|
-
**Newest first.** The sort key is the `YYYY-MM-DD_HH-MM-SS` embedded in the
|
|
403
|
-
log filename. For a time series the most recent match is usually the relevant
|
|
404
|
-
one, so a large result set stays useful at a glance without any relevance
|
|
405
|
-
ranking. Files with no timestamp in the name (`_Global_Profile.md`, project
|
|
406
|
-
notes) sort last.
|
|
407
|
-
|
|
408
|
-
**Bounded output.** The count comes first, before the results -- you need the
|
|
409
|
-
size of the result set to interpret it. Then at most `AI_MEM_SEARCH_LIMIT`
|
|
410
|
-
lines (default 40), and if anything was withheld, an explicit `N hidden` line
|
|
411
|
-
with the command to narrow. This is for the agent, not for you: an unbounded
|
|
412
|
-
dump of a common term ran ~29k tokens, overflowed the host's tool-response
|
|
413
|
-
cap, and got silently truncated -- leaving the agent unable to tell "hidden"
|
|
414
|
-
from "absent". Near-miss padding is also the most damaging kind of distractor
|
|
415
|
-
for a model, so fewer clean hits beat more of them.
|
|
416
|
-
|
|
417
|
-
**Compact lines.** The vault root is printed once in the header and stripped
|
|
418
|
-
from every result path (a third to a half of all output bytes on a real
|
|
419
|
-
vault, no information lost). Lines longer than 200 characters are clamped
|
|
420
|
-
with `[...]`, since prose notes routinely run long.
|
|
421
|
-
|
|
422
|
-
**One hop out.** Any `[[wikilink]]` on a matched line is resolved to its
|
|
423
|
-
project note and shown with a one-line excerpt under `one hop out:`. A
|
|
424
|
-
`_lessons` entry names the projects it came from, so a hit there tells you
|
|
425
|
-
where it happened without a second search. Always on, not a flag to remember.
|
|
370
|
+
Under the hood it is one `grep -rniF`, a sort, and a cap. Each choice exists
|
|
371
|
+
because the alternative gave a wrong answer on a real vault:
|
|
426
372
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
373
|
+
| choice | why |
|
|
374
|
+
|---|---|
|
|
375
|
+
| **Case-insensitive** | A false empty is the worst answer a memory tool can give. `precompact` found 0 case-sensitively and 3 with `-i`; `Postgres` 56 vs 90. |
|
|
376
|
+
| **Literal, not regex** | The caller is usually an agent passing free text, where a stray `.` or `(` must match itself. |
|
|
377
|
+
| **Lessons first, then newest** | Session logs outnumber lessons ~4:1 and are always newer, so recency alone buried them — searching `snapshot` returned 25 logs and none of the 3 lessons answering it. A lesson now outranks newer chatter. |
|
|
378
|
+
| **Bounded output** | Unbounded, a common term ran ~29k tokens and was silently truncated by the host — leaving the agent unable to tell *hidden* from *absent*. |
|
|
379
|
+
| **One line per file** | Until the budget binds. Spends it on distinct notes rather than the chattiest one. |
|
|
380
|
+
| **Compact lines** | Vault root printed once and stripped from every path; lines over 200 chars clamped. |
|
|
381
|
+
| **One hop out** | Any `[[wikilink]]` on a hit resolves to its project note with a one-line excerpt, so a lesson tells you where it happened without a second search. |
|
|
382
|
+
|
|
383
|
+
### What it costs, and what it cannot do
|
|
384
|
+
|
|
385
|
+
Measured, not estimated. Reproduce with `ai-mem-search <term>`.
|
|
386
|
+
|
|
387
|
+
**Matching is substring, case-insensitive, literal** — not word matching, not
|
|
388
|
+
stemming, not fuzzy:
|
|
389
|
+
|
|
390
|
+
| query | matches | |
|
|
391
|
+
|---|---|---|
|
|
392
|
+
| `git` | 765 | substring — also hits `github` |
|
|
393
|
+
| `github` | 255 | a subset of the above |
|
|
394
|
+
| `Postgres` / `POSTGRES` / `postgre` | 93 each | case ignored, prefix matches |
|
|
395
|
+
| `.env` | 131 | the dot is literal |
|
|
396
|
+
| `env` | 307 | more — `.env` is narrower |
|
|
397
|
+
| `postgress` *(typo)* | **0** | **no fuzzy matching** |
|
|
398
|
+
|
|
399
|
+
That last row is the limit: a misspelling finds nothing.
|
|
400
|
+
|
|
401
|
+
**Search one distinctive word, not a sentence.** Matching is literal
|
|
402
|
+
substring, so the whole error line `command not found: sed` finds **nothing**
|
|
403
|
+
while `command not found` finds it — and a bare tool name like `sed` returns
|
|
404
|
+
1,012 irrelevant lines. Pick the most unusual word in the symptom and try two
|
|
405
|
+
or three separately.
|
|
406
|
+
|
|
407
|
+
**Token cost is bounded and flat:**
|
|
408
|
+
|
|
409
|
+
| matches | tokens |
|
|
410
|
+
|---|---|
|
|
411
|
+
| 0 | ~23 |
|
|
412
|
+
| 240 | ~1,224 |
|
|
413
|
+
| 10,198 | ~1,270 |
|
|
414
|
+
|
|
415
|
+
Forty times the matches for the same cost.
|
|
416
|
+
|
|
417
|
+
**Speed is linear in vault size**, dominated by how many lines match:
|
|
418
|
+
|
|
419
|
+
| vault | rare term | common term |
|
|
420
|
+
|---|---|---|
|
|
421
|
+
| 501 notes *(real)* | — | **0.07 s** |
|
|
422
|
+
| 2,000 *(synthetic)* | 0.35 s | 1.29 s |
|
|
423
|
+
| 10,000 | 1.74 s | 7.20 s |
|
|
436
424
|
|
|
437
|
-
|
|
438
|
-
|
|
425
|
+
Comfortable to a few thousand notes — years of daily logs. Past ~10k, scope
|
|
426
|
+
it: `ai-mem-search <term> <project>`. If that is not enough, this is the wrong
|
|
427
|
+
tool and you want a real index.
|
|
439
428
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
429
|
+
### Is it used while you code, or only at launch?
|
|
430
|
+
|
|
431
|
+
**Pushed once at launch** (~4,300 tokens): your profile, standards, the
|
|
432
|
+
project note's path, a digest of the last session, and the lesson topics.
|
|
433
|
+
The last session is the newest log with content. A log that is still the
|
|
434
|
+
unfilled template (a session opened and closed without notes) is skipped.
|
|
435
|
+
|
|
436
|
+
**Pulled on demand after that.** Nothing re-injects. The agent reaches the
|
|
437
|
+
vault mid-session only by running `ai-mem-search` itself — which the launch
|
|
438
|
+
prompt tells it to do before solving anything, and again whenever it hits a
|
|
439
|
+
blocker.
|
|
440
|
+
|
|
441
|
+
So: a reference library the agent is told to consult, not a memory it thinks
|
|
442
|
+
with. Two consequences — launch a bare `claude` instead of `claude-start` and
|
|
443
|
+
you get **no vault context at all**, and whether it helps mid-build depends on
|
|
444
|
+
the agent actually searching.
|
|
443
445
|
|
|
444
446
|
### Mirrored notes are not injected twice
|
|
445
447
|
|
|
446
|
-
`_Standards.md` ships declaring `mirror_of: _Global_Profile.md
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
448
|
+
`_Standards.md` ships declaring `mirror_of: _Global_Profile.md`. The launch
|
|
449
|
+
prompt reads both, so injecting both in full restates text the model just
|
|
450
|
+
read.
|
|
451
|
+
|
|
452
|
+
When a note declares `mirror_of:`, only the differing lines are injected,
|
|
453
|
+
under a marker naming what was elided. On a real vault, 72 of the mirror's 80
|
|
454
|
+
unique lines were verbatim duplicates: **launch prompt 7,200 → 4,300 tokens,
|
|
455
|
+
nothing lost.**
|
|
450
456
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
457
|
+
Matching is exact and line-by-line, so anything reworded survives. It fails
|
|
458
|
+
**open** — no frontmatter, a missing source, or an empty diff all inject the
|
|
459
|
+
note in full. Injecting twice costs tokens; dropping a note costs the agent
|
|
460
|
+
context it was promised.
|
|
461
|
+
|
|
462
|
+
### Every path into the prompt is bounded
|
|
463
|
+
|
|
464
|
+
The launch prompt is paid **every session, in every project**, so anything
|
|
465
|
+
that can grow without limit is a cost that compounds silently.
|
|
466
|
+
|
|
467
|
+
| what reaches the prompt | bound |
|
|
468
|
+
|---|---|
|
|
469
|
+
| Profile and standards | **8,000 chars** each (`AI_MEM_NOTE_MAX_CHARS`) |
|
|
470
|
+
| Previous session outcome | 4 fields, 500 chars each |
|
|
471
|
+
| Lesson index | 200 slugs, names only |
|
|
472
|
+
| Project note | **a path, not its contents** |
|
|
473
|
+
| `ai-mem-search` output | flat: 765 matches cost the same as 240 |
|
|
474
|
+
|
|
475
|
+
The profile was the one exception. It grew to 12,405 chars and pushed the
|
|
476
|
+
launch prompt from 4,321 tokens to 5,125 without anything reporting it —
|
|
477
|
+
a 19% rise nobody asked for. Capping it brought it to **4,046**.
|
|
478
|
+
|
|
479
|
+
Truncation always states the real total and where to read the rest:
|
|
454
480
|
|
|
455
481
|
```text
|
|
456
|
-
|
|
457
|
-
(mirror of _Global_Profile.md, shown above -- only the lines that differ from it are repeated here)
|
|
458
|
-
## Standards Addendum
|
|
459
|
-
* Keep `_Standards.md` and `_Global_Profile.md` in lockstep when shared rules change.
|
|
460
|
-
...
|
|
482
|
+
[truncated at 8000 of 12405 chars -- read the rest with: cat "…/_Global_Profile.md"]
|
|
461
483
|
```
|
|
462
484
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
is a real edit. The comparison fails **open** in every uncertain case: no
|
|
469
|
-
frontmatter, a missing source, a `mirror_of` containing a path separator, or
|
|
470
|
-
a diff that would leave nothing all inject the note in full. Injecting a note
|
|
471
|
-
twice costs tokens; dropping one costs the agent context it was promised, and
|
|
472
|
-
those are not the same kind of mistake.
|
|
485
|
+
That line matters more than the saving. A truncated note the agent cannot
|
|
486
|
+
distinguish from a complete one is worse than a long one: it would answer
|
|
487
|
+
from half a profile believing it had all of it. The cut also lands on a line
|
|
488
|
+
boundary, because Markdown severed mid-line can leave half a heading or an
|
|
489
|
+
unterminated code fence, which reads as content rather than as damage.
|
|
473
490
|
|
|
474
491
|
### Lessons are indexed, not injected
|
|
475
492
|
|
|
476
|
-
`
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
finding one by search means guessing a term for knowledge it does not know
|
|
480
|
-
it has.
|
|
481
|
-
|
|
482
|
-
So the launch prompt lists **every lesson slug and no lesson bodies**:
|
|
493
|
+
`_lessons/` entries are the only notes true across projects, and the hardest
|
|
494
|
+
to find — searching for one means guessing a term for knowledge you don't
|
|
495
|
+
know you have. So the launch prompt lists **every lesson slug and no bodies**:
|
|
483
496
|
|
|
484
497
|
```text
|
|
485
|
-
- Lessons already recorded (96), listed by topic slug only
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
prisma-connection-pool-exhaustion, decimal-money-precision-js, react-hydration-mismatch, ...
|
|
498
|
+
- Lessons already recorded (96), listed by topic slug only. If one looks
|
|
499
|
+
relevant, read it with `ai-mem-search <slug>` before solving again.
|
|
500
|
+
prisma-connection-pool-exhaustion, decimal-money-precision-js, ...
|
|
489
501
|
```
|
|
490
502
|
|
|
491
|
-
A slug is the lesson
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
503
|
+
A slug is the lesson compressed: `prisma-connection-pool-exhaustion` tells
|
|
504
|
+
you whether to open it without opening it. ~8-10 tokens each, so the index
|
|
505
|
+
grows slowly: 96 lessons cost ~830, and a vault grown to 182 lessons costs
|
|
506
|
+
~1,740 (`ai-context | grep -A3 'Lessons already recorded' | wc -c`, chars divided
|
|
507
|
+
by ~4).
|
|
495
508
|
|
|
496
|
-
Newest first, capped at `AI_MEM_LESSON_INDEX_LIMIT` (200)
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
near-miss titles is the most damaging kind of distractor for a model -- the
|
|
500
|
-
same reason `ai-mem-search` bounds its own output. A vault with no lessons
|
|
501
|
-
adds nothing to the prompt at all.
|
|
509
|
+
Newest first, capped at `AI_MEM_LESSON_INDEX_LIMIT` (200). The cap matters —
|
|
510
|
+
past a few hundred, most titles are irrelevant to any given session, and a
|
|
511
|
+
long tail of near-misses is the most damaging kind of distractor for a model.
|
|
502
512
|
|
|
503
|
-
|
|
513
|
+
Returns non-zero on no matches, a missing term, or an unknown project, so
|
|
514
|
+
it composes in a script.
|
|
504
515
|
|
|
505
|
-
|
|
506
|
-
`gitignore`. No stemming, no fuzzy matching, no synonyms, no relevance
|
|
507
|
-
ranking, no vector search. A term you half-remember will miss.
|
|
516
|
+
## Memory hygiene
|
|
508
517
|
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
`postgres` before `postgres connection pool timeout`, then add the project
|
|
513
|
-
argument once you can see roughly where the answer lives.
|
|
518
|
+
A second brain that only grows, rots. Old session logs bury the recent ones,
|
|
519
|
+
near-duplicate lessons pile up, and a dead `[[link]]` points at a note that is
|
|
520
|
+
no longer there. Search then spends more tokens to return worse results.
|
|
514
521
|
|
|
515
|
-
|
|
516
|
-
|
|
522
|
+
create-ai-memory keeps the vault healthy with the two-sided strategy a brain
|
|
523
|
+
uses: it strengthens what gets used and lets the rest fade, but it never throws
|
|
524
|
+
away what was hard to learn.
|
|
517
525
|
|
|
526
|
+
| move | what it does | command |
|
|
527
|
+
|---|---|---|
|
|
528
|
+
| **Strengthen** | A lesson recalled again ranks higher, not just newer -- long-term potentiation for the vault. | `ai-mem-search` ranking |
|
|
529
|
+
| **Consolidate** | Many session logs about one thing distil into a single durable lesson. | `ai-lesson` |
|
|
530
|
+
| **Decay** | Old session logs move out of the hot search path into `_archive/`, still on disk and in git. | `ai-mem-sleep` |
|
|
531
|
+
| **Prune (detect)** | A dangling `[[wikilink]]` -- a dead edge -- is surfaced, never auto-removed. | `ai-mem-lint` |
|
|
532
|
+
| **Schedule** | Run the whole pass nightly on its own. | `ai-mem-sleep-schedule` |
|
|
533
|
+
|
|
534
|
+
**One rule is inviolable: a lesson is never pruned.** The failure-to-fix records
|
|
535
|
+
in `_lessons/` are the durable knowledge -- the answer you may need once every
|
|
536
|
+
six months when an old blocker returns -- and pruning by disuse would delete
|
|
537
|
+
exactly those. Only the ephemeral layer (session logs) decays, and even it is
|
|
538
|
+
archived, not deleted. Reinforcement acts on lessons; decay acts on logs; the
|
|
539
|
+
two never cross.
|
|
540
|
+
|
|
541
|
+
### Where the model comes from
|
|
542
|
+
|
|
543
|
+
The design is modeled on how a brain manages memory. It is a design analogy,
|
|
544
|
+
not a claim to reproduce the biology. Two ideas guided it:
|
|
545
|
+
|
|
546
|
+
- **Synaptic pruning and homeostasis.** An infant brain overproduces neural
|
|
547
|
+
connections, then removes the weak or unused ones from experience -- "use it
|
|
548
|
+
or lose it" -- which is what keeps it efficient. A vault that only appends is
|
|
549
|
+
the brain that never prunes.
|
|
550
|
+
- **Long-term potentiation (LTP).** A pathway that fires repeatedly is
|
|
551
|
+
strengthened. That is the half a naive "drop the old" policy forgets, and the
|
|
552
|
+
half `ai-mem-search`'s reinforcement adds.
|
|
553
|
+
|
|
554
|
+
Framing these as one scheduled maintenance pass -- consolidation, decay,
|
|
555
|
+
garbage collection, and graph pruning, run while the agent "sleeps" -- follows
|
|
556
|
+
Andrew Orobator, ["Your Agent Needs a Bedtime"][bedtime], and the wider NeuroAI
|
|
557
|
+
work that applies synaptic pruning to artificial networks. Its rule that error
|
|
558
|
+
recoveries are never pruned is the same rule stated above.
|
|
559
|
+
|
|
560
|
+
[bedtime]: https://medium.com/@andreworobator/your-agent-needs-a-bedtime-cc594be3f993
|
|
518
561
|
|
|
519
562
|
## Session skills (optional)
|
|
520
563
|
|
|
@@ -597,6 +640,9 @@ $AI_MEM_ROOT/
|
|
|
597
640
|
_lessons/
|
|
598
641
|
_lesson_template.md scaffold for new lesson topics
|
|
599
642
|
<topic-slug>.md cross-project decisions/mistakes, filed by ai-lesson
|
|
643
|
+
_transcripts/
|
|
644
|
+
<source-id>.md distilled meetings, calls, videos and voice notes,
|
|
645
|
+
filed by ai-mem-ingest
|
|
600
646
|
```
|
|
601
647
|
|
|
602
648
|
Notes are created from templates on first use and never overwritten. Edit
|
|
@@ -605,64 +651,52 @@ are sanitized placeholders.
|
|
|
605
651
|
|
|
606
652
|
## Open Knowledge Format
|
|
607
653
|
|
|
608
|
-
[
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
agent, static file server, Obsidian, MkDocs, or graph viewer without a
|
|
654
|
+
[OKF](https://github.com/GoogleCloudPlatform/open-knowledge-format) is
|
|
655
|
+
Google's vendor-neutral spec for portable, agent-readable knowledge. A bundle
|
|
656
|
+
is just a directory tree of markdown files — shippable as a repo, tarball or
|
|
657
|
+
zip, readable by any agent, Obsidian, MkDocs or graph viewer without a
|
|
613
658
|
translation layer.
|
|
614
659
|
|
|
615
|
-
Your vault is one
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
root](https://github.com/GoogleCloudPlatform/knowledge-catalog/blob/main/okf/SPEC.md)
|
|
620
|
-
— `index.md` and `log.md` are optional — and names exactly one required
|
|
621
|
-
frontmatter key: *"`type` is the only always-required key; a concept carrying
|
|
622
|
-
just `type` is fully conformant."*
|
|
660
|
+
Your vault is one, by convergence rather than adoption. The
|
|
661
|
+
[spec](https://github.com/GoogleCloudPlatform/knowledge-catalog/blob/main/okf/SPEC.md)
|
|
662
|
+
requires no file at the bundle root and exactly one frontmatter key:
|
|
663
|
+
*"`type` is the only always-required key."*
|
|
623
664
|
|
|
624
665
|
| OKF | Here |
|
|
625
666
|
|---|---|
|
|
626
|
-
| Markdown
|
|
667
|
+
| Markdown in a directory hierarchy | ✅ |
|
|
627
668
|
| YAML frontmatter | ✅ every note |
|
|
628
|
-
| **`type` — the only required key** | ✅ `ai-project-context`, `ai-lesson`, `ai-session-log`,
|
|
629
|
-
| Recommended
|
|
630
|
-
| Cross-links as
|
|
631
|
-
| `index.md` / `log.md` | optional in the spec; not generated
|
|
669
|
+
| **`type` — the only required key** | ✅ `ai-project-context`, `ai-lesson`, `ai-session-log`, … |
|
|
670
|
+
| Recommended `title` / `description` / `tags` | ⚠️ partial |
|
|
671
|
+
| Cross-links as markdown links | ⚠️ `[[wikilink]]` instead |
|
|
672
|
+
| `index.md` / `log.md` | optional in the spec; not generated |
|
|
632
673
|
| No SDK, no account, git-versionable | ✅ |
|
|
633
674
|
|
|
634
|
-
One real deviation: **links stay Obsidian-style
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
consumer would not follow them — though the spec already requires consumers
|
|
638
|
-
to tolerate links that do not resolve.
|
|
675
|
+
One real deviation: **links stay Obsidian-style**, because the graph view and
|
|
676
|
+
backlinks are much of why anyone keeps a vault. No `index.md` is generated —
|
|
677
|
+
`grep` never reads one and a materialized index goes stale on rename.
|
|
639
678
|
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
exactly the thing that goes stale when a file is renamed. The lesson index is
|
|
643
|
-
built at launch from the directory itself for the same reason.
|
|
644
|
-
|
|
645
|
-
Session logs predate the `type` field, so a vault that has been in use holds
|
|
646
|
-
notes without it. `ai-mem-lint` counts them, and `ai-mem-lint --fix`
|
|
647
|
-
backfills:
|
|
679
|
+
Session logs predate the `type` field, so a vault in use holds notes without
|
|
680
|
+
it:
|
|
648
681
|
|
|
649
682
|
```console
|
|
650
|
-
$ ai-mem-lint
|
|
651
|
-
350 session log(s) missing the `type:` frontmatter field (Open Knowledge Format requires it). Fix with: ai-mem-lint --fix
|
|
652
|
-
|
|
653
683
|
$ ai-mem-lint --fix
|
|
654
684
|
backfilled `type: ai-session-log` into 350 session log(s)
|
|
655
685
|
```
|
|
656
686
|
|
|
657
|
-
|
|
658
|
-
frontmatter block for a note that had none, and is idempotent — running it
|
|
659
|
-
twice does not stack a second field.
|
|
687
|
+
Edits in place, preserves frontmatter and body, idempotent.
|
|
660
688
|
|
|
661
689
|
## Add another agent
|
|
662
690
|
|
|
663
691
|
Launchers are not hardcoded. Each agent is one small adapter, and the
|
|
664
|
-
`<name>-start` function is generated for you. `claude`, `codex`, `
|
|
665
|
-
`cursor`, and `opencode` ship built in.
|
|
692
|
+
`<name>-start` function is generated for you. `claude`, `codex`, `agy`,
|
|
693
|
+
`gemini`, `cursor`, and `opencode` ship built in.
|
|
694
|
+
|
|
695
|
+
`agy` is the [Antigravity CLI](https://antigravity.google), which in practice
|
|
696
|
+
has replaced the Gemini CLI. Both adapters ship: `gemini-start` still works
|
|
697
|
+
for anyone using it, and `agy-start` is the one to reach for now.
|
|
698
|
+
|
|
699
|
+
To add `aider`:
|
|
666
700
|
|
|
667
701
|
1. Define the adapter in `shell/adapters.zsh`. It receives `$1` memory prompt,
|
|
668
702
|
`$2` mode block, and `$3` onward extra args:
|
|
@@ -674,7 +708,7 @@ Launchers are not hardcoded. Each agent is one small adapter, and the
|
|
|
674
708
|
```
|
|
675
709
|
2. Register it in `~/.zshrc` before sourcing, or edit the default:
|
|
676
710
|
```zsh
|
|
677
|
-
export AI_MEM_AGENTS="claude codex gemini cursor opencode aider"
|
|
711
|
+
export AI_MEM_AGENTS="claude codex agy gemini cursor opencode aider"
|
|
678
712
|
```
|
|
679
713
|
3. `aider-start` now exists. No core edits.
|
|
680
714
|
|
|
@@ -694,56 +728,37 @@ an agent-run command.
|
|
|
694
728
|
|
|
695
729
|
### Graph view
|
|
696
730
|
|
|
697
|
-
`ai-mem-search` answers a question you already knew to ask. This
|
|
698
|
-
other one — what is in there
|
|
699
|
-
connected.
|
|
731
|
+
`ai-mem-search` answers a question you already knew to ask. This answers the
|
|
732
|
+
other one — what is in there, and what turned out to be connected.
|
|
700
733
|
|
|
701
|
-
|
|
702
|
-
"show me my context" — and it will: the launch prompt tells terminal agents
|
|
703
|
-
the viewer exists, and GUI clients get an `open_graph` tool over MCP. Running
|
|
704
|
-
it by hand stays available:
|
|
734
|
+
Ask the agent ("open my memory") or run it:
|
|
705
735
|
|
|
706
736
|
```sh
|
|
707
737
|
ai-mem-serve # opens a browser at http://127.0.0.1:7777
|
|
708
|
-
ai-mem-serve 8080 --no-open
|
|
709
738
|
```
|
|
710
739
|
|
|
711
|
-
Asked twice, the second call finds the first still listening and just opens
|
|
712
|
-
the tab. An agent should not have to check whether it is already running, and
|
|
713
|
-
a port collision with **its own** server is not a failure worth reporting —
|
|
714
|
-
though a port held by something else still is.
|
|
715
|
-
|
|
716
740
|

|
|
717
741
|
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
- **Selecting a note** dims everything it is not connected to, shows the note
|
|
725
|
-
rendered beside the graph, and lists what it links to.
|
|
726
|
-
- **Durable knowledge** is the default view. Session logs usually outnumber
|
|
727
|
-
everything else several times over and all point at their project, which
|
|
728
|
-
buries the projects and lessons inside a hairball. Switch to *Everything* to
|
|
729
|
-
see them.
|
|
730
|
-
- **Search** and the legend both filter; `/` focuses the search box.
|
|
731
|
-
|
|
732
|
-
Bound to `127.0.0.1` only, deliberately. The vault holds project history and
|
|
733
|
-
operational detail, and a viewer for it has no business being reachable from
|
|
734
|
-
the network. Zero dependencies — the layout is a small force simulation rather
|
|
735
|
-
than a charting library, so it works with no network at all.
|
|
742
|
+
Nodes are coloured by `type` and sized by how many notes link to them.
|
|
743
|
+
Selecting one dims everything unconnected and renders the note beside the
|
|
744
|
+
graph. *Durable knowledge* is the default view — session logs usually
|
|
745
|
+
outnumber everything else and bury the rest. A note carrying a dangling
|
|
746
|
+
`[[link]]` wears a dashed red ring, so a dead edge is visible in the graph as
|
|
747
|
+
well as in the note (where it renders dotted and unclickable).
|
|
736
748
|
|
|
737
|
-
|
|
749
|
+
Loopback only, deliberately: the vault holds project history. Zero
|
|
750
|
+
dependencies — the layout is a small force simulation, not a charting
|
|
751
|
+
library, so it works offline. Run it twice and the second call just opens the
|
|
752
|
+
tab, unless another vault holds the port.
|
|
738
753
|
|
|
739
|
-
|
|
740
|
-
prompt. **A GUI opened from the Dock never runs one** — there is no daemon and
|
|
741
|
-
no background service, so Claude Desktop and the Cursor GUI would otherwise
|
|
742
|
-
see nothing.
|
|
754
|
+
### GUI clients (MCP)
|
|
743
755
|
|
|
744
|
-
|
|
756
|
+
The launchers reach an agent through its opening prompt. **A GUI opened from
|
|
757
|
+
the Dock never runs one**, so Claude Desktop and the Cursor GUI would see
|
|
758
|
+
nothing. `ai-mem-mcp` is their channel.
|
|
745
759
|
|
|
746
760
|
**Claude Desktop** — `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
761
|
+
(**Cursor** — `~/.cursor/mcp.json`, same shape):
|
|
747
762
|
|
|
748
763
|
```json
|
|
749
764
|
{
|
|
@@ -756,37 +771,41 @@ see nothing.
|
|
|
756
771
|
}
|
|
757
772
|
```
|
|
758
773
|
|
|
759
|
-
**Cursor** — `~/.cursor/mcp.json`, same shape.
|
|
760
|
-
|
|
761
774
|
Six tools, read **and** write, so a GUI session is not a dead end:
|
|
762
|
-
`search_memory`, `get_context`, `read_note`, `add_note`, `add_lesson`,
|
|
763
|
-
`open_graph
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
**Making a GUI behave like a launcher.** In a terminal the vault is pushed
|
|
773
|
-
into the agent's opening prompt. Over MCP nothing is pushed, and a model with
|
|
774
|
-
no reason to suspect a memory exists will simply never call a tool. The server
|
|
775
|
-
returns MCP's `instructions` field at startup -- a short standing brief to read
|
|
776
|
-
context first, search before solving, and write back afterwards. That one
|
|
777
|
-
field is the difference between a vault the GUI *could* reach and one it
|
|
778
|
-
actually uses.
|
|
779
|
-
|
|
780
|
-
**On cost.** Tool schemas are re-sent every turn, so their prose is a
|
|
781
|
-
recurring tax; the `instructions` brief is sent once. Behaviour guidance
|
|
782
|
-
therefore lives in `instructions` and the descriptions stay terse. Adding the
|
|
783
|
-
write tools cost nothing per turn as a result: six tools now total ~429
|
|
784
|
-
tokens against ~380 for the original four, with a one-time ~227 for the brief.
|
|
775
|
+
`search_memory`, `get_context`, `read_note`, `add_note`, `add_lesson`,
|
|
776
|
+
`open_graph`. Each shells out to the same zsh functions the CLI uses — one
|
|
777
|
+
implementation, not a copy that drifts. A note written from Claude Desktop is
|
|
778
|
+
committed and pushed exactly like one written in a terminal.
|
|
779
|
+
|
|
780
|
+
MCP's `instructions` field carries a standing brief (read context first,
|
|
781
|
+
search before solving, write back after) — without it a model has no reason
|
|
782
|
+
to suspect a memory exists. Tool descriptions stay terse because schemas are
|
|
783
|
+
re-sent every turn: six tools cost ~429 tokens/turn, the brief ~290 once.
|
|
785
784
|
|
|
786
785
|
**Do not register this for a terminal agent.** Claude Code, Codex, Gemini and
|
|
787
|
-
opencode
|
|
788
|
-
|
|
789
|
-
|
|
786
|
+
opencode have a shell and should call `ai-mem-search` directly.
|
|
787
|
+
|
|
788
|
+
**A desktop app that has a shell but no launcher** (the Codex app, for
|
|
789
|
+
example) gets no vault context, because nothing runs `codex-start` for it.
|
|
790
|
+
Without instructions, it guesses: it takes the newest log in the vault, which
|
|
791
|
+
can be a different project. Put the rules in the app's global instruction file
|
|
792
|
+
(`~/.codex/AGENTS.md` for Codex). A GUI app does not read `~/.zshrc`, so give
|
|
793
|
+
the vault path and the module path explicitly:
|
|
794
|
+
|
|
795
|
+
```md
|
|
796
|
+
## AI memory vault
|
|
797
|
+
Before you answer a question about a project, load its context:
|
|
798
|
+
`AI_MEM_ROOT=/abs/path/_Ai_Memory zsh -c 'source /abs/path/create-ai-memory/shell/ai-mem.zsh; ai-context <project>'`
|
|
799
|
+
- <project> is the name the user gives, or the git repo folder name.
|
|
800
|
+
- If the user gives no project and the folder is not a git repo, STOP and ask.
|
|
801
|
+
A folder that is not a repo does not give a project name. Do not guess.
|
|
802
|
+
- If `_projects/<project>.md` does not exist, ask before you continue:
|
|
803
|
+
`ai-context` makes a new empty project for a name that is not correct.
|
|
804
|
+
- Skip this step if the prompt already contains vault context.
|
|
805
|
+
- To record a note, use the same form with `AI_MEM_ACTIVE_PROJECT=<project>` added
|
|
806
|
+
and `ai-note "<text>"`. Outside a repo, that variable names the project.
|
|
807
|
+
Each shell command starts a new process, so set it on every call.
|
|
808
|
+
```
|
|
790
809
|
|
|
791
810
|
### Claude Code hooks
|
|
792
811
|
The files live in `hooks/claude/`. Record repo `HEAD` at session start, then on
|
|
@@ -800,7 +819,11 @@ the session can never get stuck refusing to compact. It only guards
|
|
|
800
819
|
auto-compact, not a deliberate `/compact`. Merge `settings.snippet.json` into
|
|
801
820
|
`~/.claude/settings.json`, replacing `<AI_MEM_HOME>` with an absolute path.
|
|
802
821
|
All three hooks no-op for plain `claude` runs; they gate on
|
|
803
|
-
`$AI_MEM_ACTIVE_SESSION_LOG`.
|
|
822
|
+
`$AI_MEM_ACTIVE_SESSION_LOG`. That variable stays exported in your shell after
|
|
823
|
+
the agent exits, so the session-start and Stop hooks also check
|
|
824
|
+
`$AI_MEM_ACTIVE_GIT_DIR`: they write only in the repo the session was launched
|
|
825
|
+
in, or a worktree of it. A later plain `claude` in a different repo does not
|
|
826
|
+
put that repo's commits in the wrong project's log. This is Claude-Code-specific -- other agents
|
|
804
827
|
(Codex, Gemini, etc.) have no equivalent pre-compaction hook, so jotting
|
|
805
828
|
things down with `ai-note`/`codex-note` as you go still matters there.
|
|
806
829
|
|
|
@@ -824,10 +847,63 @@ git -C <repo> config core.hooksPath .githooks
|
|
|
824
847
|
| Env var | Default | Purpose |
|
|
825
848
|
|---|---|---|
|
|
826
849
|
| `AI_MEM_ROOT` | `$HOME/.ai-memory/_Ai_Memory` | Vault root. Point at any folder, including an existing Obsidian vault |
|
|
827
|
-
| `AI_MEM_AGENTS` | `claude codex gemini cursor opencode` | Space-separated agents to generate `-start` functions for |
|
|
850
|
+
| `AI_MEM_AGENTS` | `claude codex agy gemini cursor opencode` | Space-separated agents to generate `-start` functions for |
|
|
828
851
|
| `AI_MEM_SKILLS` / `AI_MEM_SKILL_ORDER` | empty | Your per-session skills (see above) |
|
|
829
852
|
| `AI_MEM_LESSON_INDEX_LIMIT` | `200` | Lesson slugs listed in the launch prompt before it truncates to the newest. Names only -- bodies are never injected |
|
|
830
|
-
| `
|
|
853
|
+
| `AI_MEM_NOTE_MAX_CHARS` | `8000` | Cap on what one inlined note contributes to the launch prompt. Truncation states the real total and the path. `0` disables it |
|
|
854
|
+
| `AI_MEM_SEARCH_LIMIT` | `25` | Result lines `ai-mem-search` prints before it truncates. The default is sized for an agent's context window; raise it when you are reading the output yourself (see [How search works](#how-search-works)) |
|
|
855
|
+
| `AI_MEM_HOME` | the module's own directory | Exported by the module when it is sourced, not set by you. A cron job, a launchd agent or any non-interactive shell can re-source the module with `zsh -c 'source "$AI_MEM_HOME/ai-mem.zsh"; ...'` instead of a hard-coded path |
|
|
856
|
+
| `AI_MEM_SEARCH_PER_FILE` | `1` | Lines shown per file once the cap binds. Spreads results across notes instead of on the chattiest one; ignored when every match already fits |
|
|
857
|
+
|
|
858
|
+
## Why not just CLAUDE.md?
|
|
859
|
+
|
|
860
|
+
You probably already have one. Keep it — this does a different job, and the
|
|
861
|
+
tool defers to it by design.
|
|
862
|
+
|
|
863
|
+
| | `CLAUDE.md` / `AGENTS.md` | create-ai-memory |
|
|
864
|
+
|---|---|---|
|
|
865
|
+
| Holds | rules and conventions | what happened, decided, and broke |
|
|
866
|
+
| Changes | when you edit it | every session, automatically |
|
|
867
|
+
| Scope | that one repo | global + per-repo + cross-project lessons |
|
|
868
|
+
| Agents | one vendor's file per agent | one vault, five CLIs |
|
|
869
|
+
| Answers | *"how should you work here?"* | *"what did we already try?"* |
|
|
870
|
+
|
|
871
|
+
A `CLAUDE.md` is a standing instruction. It does not know that last Tuesday
|
|
872
|
+
you found the connection pool was sized below the worker count, or that the
|
|
873
|
+
same bug bit a different repo in March. That is what accumulates here.
|
|
874
|
+
|
|
875
|
+
They compose: the injected profile explicitly tells the agent that repo-local
|
|
876
|
+
instruction files **override it** for that repo. Nothing to migrate, nothing
|
|
877
|
+
to delete.
|
|
878
|
+
|
|
879
|
+
## Troubleshooting
|
|
880
|
+
|
|
881
|
+
**`claude-start` works but the agent has no memory of anything.**
|
|
882
|
+
You launched plain `claude`. Nothing hooks it — the vault reaches the agent
|
|
883
|
+
through the launcher's opening prompt, so a bare CLI gets none of it.
|
|
884
|
+
|
|
885
|
+
**A command "isn't installed" right after an upgrade.**
|
|
886
|
+
Your shell is stale. These are zsh functions loaded when the terminal opened;
|
|
887
|
+
editing or upgrading the module changes nothing in a shell already running.
|
|
888
|
+
Open a new terminal, or `exec zsh`. `which` under bash will not find them
|
|
889
|
+
either — use `command -v`.
|
|
890
|
+
|
|
891
|
+
**The agent's "Project context" is bracket placeholders.**
|
|
892
|
+
The project note was never filled in. The launch prompt now says so and asks
|
|
893
|
+
the agent to fill it from the repo; you can also edit
|
|
894
|
+
`_projects/<repo>.md` yourself. It is read at every launch for that repo, so
|
|
895
|
+
it is worth ten minutes once.
|
|
896
|
+
|
|
897
|
+
**`ai-mem-lint` reports orphaned session logs.**
|
|
898
|
+
Their `project:` frontmatter is not a `[[wikilink]]`, usually because the
|
|
899
|
+
vault's session template predates the current one. Scaffolding only fills in
|
|
900
|
+
*missing* files, so an existing vault keeps its old templates. Run
|
|
901
|
+
`ai-mem-lint --fix`.
|
|
902
|
+
|
|
903
|
+
**Search returns nothing for a term you are sure you wrote.**
|
|
904
|
+
Matching is literal substring with no fuzzy matching, so a typo finds zero.
|
|
905
|
+
Search one distinctive word rather than a phrase or a whole error line — see
|
|
906
|
+
[what it costs](#what-it-costs-and-what-it-cannot-do).
|
|
831
907
|
|
|
832
908
|
## Why plain files
|
|
833
909
|
|
|
@@ -854,11 +930,11 @@ afternoon and carry anywhere.
|
|
|
854
930
|
|
|
855
931
|
Offline unit suite (throwaway vault and git repo, no network): path guarding,
|
|
856
932
|
project resolution, session prep, the context prompt, the skill picker, launcher
|
|
857
|
-
generation, adapter dispatch, the commit token, `ai-note`, and
|
|
858
|
-
file.
|
|
933
|
+
generation, adapter dispatch, the commit token, `ai-note`, `ai-mem-ingest`, and
|
|
934
|
+
the cursor rule file.
|
|
859
935
|
|
|
860
936
|
```sh
|
|
861
|
-
zsh tests/run.sh # offline unit tests (
|
|
937
|
+
zsh tests/run.sh # offline unit tests (340 assertions)
|
|
862
938
|
zsh tests/smoke.sh # live: launches each agent headlessly, checks it responds
|
|
863
939
|
```
|
|
864
940
|
|