humemory 0.2.1

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.
Files changed (81) hide show
  1. package/.githooks/post-commit +22 -0
  2. package/AGENTS.md +328 -0
  3. package/CHANGELOG.md +198 -0
  4. package/LICENSE +21 -0
  5. package/README.md +488 -0
  6. package/bin/humemory.js +19 -0
  7. package/dist/agent/claude-hook.d.ts +15 -0
  8. package/dist/agent/claude-hook.js +38 -0
  9. package/dist/agent/commit-closer.d.ts +60 -0
  10. package/dist/agent/commit-closer.js +125 -0
  11. package/dist/agent/learning-extractor.d.ts +10 -0
  12. package/dist/agent/learning-extractor.js +75 -0
  13. package/dist/agent/session-context.d.ts +63 -0
  14. package/dist/agent/session-context.js +216 -0
  15. package/dist/agent/session-parser.d.ts +12 -0
  16. package/dist/agent/session-parser.js +85 -0
  17. package/dist/api/dream-routes.d.ts +7 -0
  18. package/dist/api/dream-routes.js +40 -0
  19. package/dist/api/intentions-routes.d.ts +23 -0
  20. package/dist/api/intentions-routes.js +252 -0
  21. package/dist/api/memory-routes.d.ts +10 -0
  22. package/dist/api/memory-routes.js +277 -0
  23. package/dist/api/scripts-routes.d.ts +13 -0
  24. package/dist/api/scripts-routes.js +129 -0
  25. package/dist/api/server.d.ts +33 -0
  26. package/dist/api/server.js +157 -0
  27. package/dist/cli/index.d.ts +2 -0
  28. package/dist/cli/index.js +798 -0
  29. package/dist/core/clock.d.ts +38 -0
  30. package/dist/core/clock.js +52 -0
  31. package/dist/core/cue-arg.d.ts +19 -0
  32. package/dist/core/cue-arg.js +72 -0
  33. package/dist/core/cues.d.ts +138 -0
  34. package/dist/core/cues.js +372 -0
  35. package/dist/core/decay.d.ts +49 -0
  36. package/dist/core/decay.js +157 -0
  37. package/dist/core/dreamer.d.ts +114 -0
  38. package/dist/core/dreamer.js +427 -0
  39. package/dist/core/embeddings.d.ts +79 -0
  40. package/dist/core/embeddings.js +133 -0
  41. package/dist/core/event-bus.d.ts +71 -0
  42. package/dist/core/event-bus.js +67 -0
  43. package/dist/core/hybrid.d.ts +33 -0
  44. package/dist/core/hybrid.js +63 -0
  45. package/dist/core/llm-generator.d.ts +18 -0
  46. package/dist/core/llm-generator.js +69 -0
  47. package/dist/core/sanitize.d.ts +57 -0
  48. package/dist/core/sanitize.js +87 -0
  49. package/dist/core/scripts.d.ts +55 -0
  50. package/dist/core/scripts.js +96 -0
  51. package/dist/core/search.d.ts +42 -0
  52. package/dist/core/search.js +173 -0
  53. package/dist/core/trust.d.ts +48 -0
  54. package/dist/core/trust.js +57 -0
  55. package/dist/core/types.d.ts +333 -0
  56. package/dist/core/types.js +1 -0
  57. package/dist/core/vector-clusterer.d.ts +53 -0
  58. package/dist/core/vector-clusterer.js +113 -0
  59. package/dist/index.d.ts +28 -0
  60. package/dist/index.js +18 -0
  61. package/dist/mcp/server.d.ts +22 -0
  62. package/dist/mcp/server.js +158 -0
  63. package/dist/store/sqlite.d.ts +240 -0
  64. package/dist/store/sqlite.js +1653 -0
  65. package/docs/TESTING.md +244 -0
  66. package/package.json +95 -0
  67. package/public/app/galaxy-f42190mq.js +10 -0
  68. package/public/app/index-2cf31xxn.css +1 -0
  69. package/public/app/index-epqg22cp.js +1 -0
  70. package/public/app/index-f9h80bzq.js +12 -0
  71. package/public/app/index-gbfwa9vq.js +2 -0
  72. package/public/app/index-kvhc17mz.js +2 -0
  73. package/public/app/index-pbd5t4dj.js +2 -0
  74. package/public/app/index.html +12 -0
  75. package/public/app/promenade-cnzzpm73.js +4111 -0
  76. package/public/app/river-tyawhh8w.js +13 -0
  77. package/public/session.html +659 -0
  78. package/scripts/consolidate.js +46 -0
  79. package/scripts/hook-post-commit.ts +80 -0
  80. package/scripts/hook-session-start.ts +92 -0
  81. package/scripts/hook-session.ts +60 -0
package/README.md ADDED
@@ -0,0 +1,488 @@
1
+ # humemory
2
+
3
+ > **Memory for AI agents that forgets like a human — and resurfaces like one.**
4
+
5
+ humemory is a memory engine that does not behave like a database. It behaves like
6
+ a brain. Traces **decay** through five levels (full detail → summary → essentials →
7
+ keywords → lost/merged), recall **reinforces** them, and — this is the part that
8
+ matters — the right memory comes back to you **before you ask for it**.
9
+
10
+ Most "agent memory" is a searchable log. You query it, it returns rows. humemory's
11
+ reason to exist is the opposite move: a memory that **surfaces the relevant trace
12
+ on a contextual cue**, the way you remember to buy milk when you walk past the shop,
13
+ not when you run a full-text search for "milk".
14
+
15
+ ---
16
+
17
+ ## Two halves of a brain
18
+
19
+ humemory is built in two halves. The first is shipped. The second is its destiny.
20
+
21
+ ### 1. Retrospective memory — *what was learned* ✅ built
22
+
23
+ Past learnings are **encoded**, then **degraded** over time on a human curve:
24
+
25
+ | Level | Name | Lifespan | Holds |
26
+ |-------|------|----------|-------|
27
+ | L0 | full detail | fresh (<24h) | complete content |
28
+ | L1 | summary | days | LLM-generated résumé |
29
+ | L2 | essential | weeks | the gist |
30
+ | L3 | keywords | months | BM25 retrieval tokens |
31
+ | L4 | lost / merged | beyond | folded into a sibling trace |
32
+
33
+ Recall resists decay. Saillance (mnemonic strength, 0–100) and recall count slow
34
+ the curve. A **photographic** flag pins critical traces so they never fade.
35
+
36
+ **Inverse search** queries the *degraded* layers first (cheap, L3 keywords) and
37
+ escalates toward full content only on a match — the human recall pattern, fast by
38
+ construction.
39
+
40
+ A Claude Code `Stop` hook already auto-encodes the learnings of each dev session.
41
+
42
+ ### 2. Prospective memory — *what to resurface* 🎯 the destiny
43
+
44
+ The second half (see `AGENTS.md` → Phase 5) is what gives humemory its life:
45
+
46
+ - **Prospective memory** — store an *intention* that fires on a **cue** (a time, or
47
+ an event: opening a file, switching branch, hitting an error), not on a search.
48
+ - **Zeigarnik effect** — an **open loop** stays salient near consciousness until it
49
+ is closed. A `git commit` is the synaptic release that purges it.
50
+ - **Cognitive scripts** — context-triggered routines, pre-loaded, ready to run.
51
+
52
+ Concretely: on `SessionStart`, humemory reads the open loops and the
53
+ decayed-but-relevant traces for the current directory/branch and **injects them as
54
+ context** — "yesterday you left *refactor fn X* open" — instead of waiting to be
55
+ queried.
56
+
57
+ ---
58
+
59
+ ## Quick start
60
+
61
+ ```bash
62
+ pnpm install
63
+ pnpm build:web # bundle the React front (bun's own bundler, no extra tooling)
64
+ pnpm start:api # API + dashboards → http://localhost:3456
65
+ pnpm cli status # state of the memory palace
66
+ pnpm test # bun test — backend and React components, one runner
67
+ ```
68
+
69
+ The React app is served at **`/`** (and `/app`). The original vanilla dashboard
70
+ has been removed — the React front reached parity first, and git keeps the old
71
+ one if it is ever needed.
72
+
73
+ The visualisations are **wrapped, not rewritten**: d3 owns its SVG subtree and
74
+ three.js its WebGL canvas, so they stay imperative inside a `useEffect`. Only the
75
+ parts built from `innerHTML` strings — the trace dashboard, the replay player,
76
+ the merge panel — became JSX. Each visualisation is code-split and loaded on
77
+ demand; three.js alone is half a megabyte, and nobody who never opens the
78
+ promenade should download it.
79
+
80
+ Run `pnpm build:web` before `pnpm start:api`, or `/` answers 503 telling you so.
81
+
82
+ ### Open loops (prospective memory)
83
+
84
+ ```bash
85
+ # arm a loop, with a file cue and a weekly reminder
86
+ pnpm cli intent add "refactor token validation" -d ./src/auth \
87
+ -c 'event:file_open:src/auth/service.ts' -c 'cron:0 9 * * 1' -e 2026-12-31
88
+
89
+ pnpm cli intent list # armed loops (--all for every status)
90
+ pnpm cli intent close loop-a1b2c3d4 --commit deadbee
91
+ pnpm cli intent resolve # expire overdue loops, fire due deadlines
92
+ ```
93
+
94
+ Cue formats: `time:<ISO>`, `cron:<5-field expr>`, `event:file_open:<path>`,
95
+ `event:branch_switch:<branch>`, `event:error_pattern:<regex>`.
96
+
97
+ Directories are resolved to absolute paths on write — a loop armed on a relative
98
+ path would never match the `SessionStart` hook, which looks the project up by
99
+ `process.cwd()`.
100
+
101
+ Over HTTP: `POST /intentions`, `GET /intentions?status=armed&directory=…`,
102
+ `GET /intentions/:id`, `POST /intentions/:id/close`, `POST /intentions/:id/fire`,
103
+ `DELETE /intentions/:id`, `POST /cues`, `GET /cues`, `POST /events`,
104
+ `POST /cues/resolve`.
105
+
106
+ ### Closing loops from git
107
+
108
+ ```bash
109
+ git config core.hooksPath .githooks # in this repo
110
+ ```
111
+
112
+ For another project, copy `.githooks/post-commit` into it and point
113
+ `HUMEMORY_HOME` at your humemory checkout — the database is shared across
114
+ projects, the code is not:
115
+
116
+ ```bash
117
+ export HUMEMORY_HOME=/path/to/humemory
118
+ ```
119
+
120
+ Write `Closes loop-a1b2c3d4` in a commit message and that loop is closed, its
121
+ SHA recorded, its remaining cues cancelled. Everything else is only **suggested**:
122
+ the hook scores the overlap between the files you touched and the loop's text,
123
+ and prints candidates. It never closes on a guess — closing the wrong loop costs
124
+ more than leaving one open.
125
+
126
+ ```
127
+ 💡 Loops this commit may have touched:
128
+ loop-e99166cd — Refactor the auth middleware
129
+ overlaps: auth, middleware
130
+
131
+ To close: pnpm cli intent close loop-e99166cd
132
+ ```
133
+
134
+ ### Wiring the Claude Code hooks
135
+
136
+ Two hooks, both optional and both fail-open — neither will ever block a session:
137
+
138
+ ```jsonc
139
+ // ~/.claude/settings.json
140
+ {
141
+ "hooks": {
142
+ // start of session: injects open loops + relevant decayed traces as context
143
+ "SessionStart": [{ "matcher": "", "hooks": [
144
+ { "type": "command", "command": "bun /path/to/humemory/scripts/hook-session-start.ts" }
145
+ ]}],
146
+ // end of session: encodes what was learned
147
+ "Stop": [{ "matcher": "", "hooks": [
148
+ { "type": "command", "command": "bun /path/to/humemory/scripts/hook-session.ts" }
149
+ ]}]
150
+ }
151
+ }
152
+ ```
153
+
154
+ `SessionStart` reads the current directory and git branch, expires stale loops,
155
+ fires any due time cues, and writes a markdown block on stdout — which Claude Code
156
+ injects into the session. Nothing relevant means nothing written.
157
+
158
+ | Env var | Default | Effect |
159
+ | --- | --- | --- |
160
+ | `HUMEMORY_DB` | `data/humemory.db` | database path |
161
+ | `HUMEMORY_DIR` | `cwd` | mental place to scope loops and traces to |
162
+ | `HUMEMORY_SESSION_BUDGET` | `10` | max items listed per section |
163
+ | `HUMEMORY_SAILLANCE_MIN` | `60` | salience floor for recalling a decayed trace |
164
+ | `HUMEMORY_VERBOSE` | unset | `1` logs a one-line summary on stderr |
165
+
166
+ ---
167
+
168
+ ## Why it exists
169
+
170
+ A log remembers everything and reminds you of nothing. A human memory forgets most
171
+ of it and hands you the one thing that matters, at the moment it matters. humemory
172
+ is an attempt to give an AI agent the second kind.
173
+
174
+ ## Stack
175
+
176
+ TypeScript · `bun:sqlite` (WAL) · `flexsearch` (BM25) · `hono` (API) ·
177
+ `commander` (CLI) · `@anthropic-ai/sdk` (level generation).
178
+
179
+ ---
180
+
181
+ ## Usage
182
+
183
+ ### Installation
184
+
185
+ ```bash
186
+ pnpm install
187
+ ```
188
+
189
+ ### CLI Commands
190
+
191
+ The CLI provides several commands to interact with humemory:
192
+
193
+ - **Encode a new memory trace**:
194
+ ```bash
195
+ pnpm cli encode "Your memory content here"
196
+ ```
197
+ Options:
198
+ - `-d, --directory <dir>`: Mental space (project)
199
+ - `-s, --session <id>`: Encoding context
200
+ - `-k, --keywords <tags>`: Retrieval cues (comma-separated)
201
+ - `-l1, --level1 <summary>`: Summary for consolidation N1
202
+ - `-l2, --level2 <essential>`: Essential for consolidation N2
203
+ - `-l3, --level3 <keywords>`: Trace for fast search N3
204
+ - `-t, --type <type>`: Memory type (episodic/semantic/procedural)
205
+ - `--auto`: Auto-generate N1/N2/N3 via LLM (requires ANTHROPIC_API_KEY)
206
+ - `--photographic`: Photographic mode — disable degradation
207
+
208
+ - **Search for memory traces**:
209
+ ```bash
210
+ pnpm cli search "your query"
211
+ ```
212
+ Options:
213
+ - `-d, --directory <dir>`: Filter by mental space
214
+ - `-s, --session <id>`: Filter by context
215
+ - `-l, --level <max>`: Max consolidation state (0-4)
216
+ - `-n, --limit <n>`: Number of traces
217
+ - `-t, --type <type>`: Filter by type (episodic/semantic/procedural)
218
+ - `--from <date>`: Start date YYYY-MM-DD
219
+ - `--to <date>`: End date YYYY-MM-DD
220
+ - `--min-saillance <n>`: Minimum mnemonic strength (0-100)
221
+ - `--min-recalls <n>`: Minimum reactivations
222
+
223
+ - **Reactivate a memory trace**:
224
+ ```bash
225
+ pnpm cli recall <id>
226
+ ```
227
+
228
+ - **List memory traces**:
229
+ ```bash
230
+ pnpm cli list
231
+ ```
232
+ Options:
233
+ - `-n, --limit <n>`: Number of traces
234
+ - `-l, --level <level>`: Filter by state (0-4)
235
+ - `-t, --type <type>`: Filter by type (episodic/semantic/procedural)
236
+
237
+ - **Update decay**:
238
+ ```bash
239
+ pnpm cli decay
240
+ ```
241
+
242
+ - **Toggle photographic mode**:
243
+ ```bash
244
+ pnpm cli photo <id>
245
+ ```
246
+ Options:
247
+ - `--off`: Disable photographic mode
248
+
249
+ - **Find similar traces**:
250
+ ```bash
251
+ pnpm cli similar <id>
252
+ ```
253
+ Options:
254
+ - `-n, --limit <n>`: Number of results
255
+ - `-t, --threshold <n>`: Minimum score (0-100)
256
+
257
+ - **Merge traces**:
258
+ ```bash
259
+ pnpm cli merge <sourceId> <targetId>
260
+ ```
261
+ Options:
262
+ - `--auto`: Merge content via LLM
263
+
264
+ - **Delete a memory trace**:
265
+ ```bash
266
+ pnpm cli delete <id>
267
+ ```
268
+
269
+ - **Show memory palace status**:
270
+ ```bash
271
+ pnpm cli status
272
+ ```
273
+
274
+ - **Import a Claude Code session**:
275
+ ```bash
276
+ pnpm cli import-session <file>
277
+ ```
278
+ Options:
279
+ - `-d, --directory <dir>`: Project mental space
280
+ - `-n, --max <n>`: Max learnings to extract
281
+
282
+ ### API
283
+
284
+ Start the API server:
285
+
286
+ ```bash
287
+ pnpm start:api
288
+ ```
289
+
290
+ The API will be available at `http://localhost:3456`. You can interact with it using the following endpoints:
291
+
292
+ - `POST /memories`: Add a new memory
293
+ - `GET /memories`: List memories
294
+ - `GET /memories/:id`: Fetch a specific memory
295
+ - `POST /memories/:id/recall`: Bump recall and saillance
296
+ - `POST /memories/:id/similar`: Find similar memories
297
+ - `POST /memories/:id/merge`: Merge memories
298
+ - `POST /memories/:id/photo`: Toggle photographic mode
299
+ - `DELETE /memories/:id`: Forget a memory
300
+ - `GET /search?query=X`: Inverse search
301
+ - `POST /decay`: Run consolidation
302
+ - `GET /status`: Pool stats
303
+
304
+ ### Dashboard
305
+
306
+ The dashboard is available at `http://localhost:3456` when the API server is running. It provides a visual interface to interact with humemory.
307
+
308
+ ---
309
+
310
+ ## Examples
311
+
312
+ ### Encoding a memory
313
+
314
+ ```bash
315
+ pnpm cli encode "Fixed the critical bug in the authentication module" \
316
+ -d "my-project" \
317
+ -k "bug,authentication,critical" \
318
+ -t "episodic" \
319
+ --auto
320
+ ```
321
+
322
+ ### Searching for memories
323
+
324
+ ```bash
325
+ pnpm cli search "authentication bug" \
326
+ -d "my-project" \
327
+ --min-saillance 50
328
+ ```
329
+
330
+ ### Reactivating a memory
331
+
332
+ ```bash
333
+ pnpm cli recall "memory-id-here"
334
+ ```
335
+
336
+ ### Listing memories
337
+
338
+ ```bash
339
+ pnpm cli list -l 0 -t "episodic"
340
+ ```
341
+
342
+ ### Updating decay
343
+
344
+ ```bash
345
+ pnpm cli decay
346
+ ```
347
+
348
+ ### Toggling photographic mode
349
+
350
+ ```bash
351
+ pnpm cli photo "memory-id-here" --off
352
+ ```
353
+
354
+ ### Finding similar traces
355
+
356
+ ```bash
357
+ pnpm cli similar "memory-id-here" -n 3 -t 70
358
+ ```
359
+
360
+ ### Merging traces
361
+
362
+ ```bash
363
+ pnpm cli merge "source-memory-id" "target-memory-id" --auto
364
+ ```
365
+
366
+ ### Deleting a memory
367
+
368
+ ```bash
369
+ pnpm cli delete "memory-id-here"
370
+ ```
371
+
372
+ ### Showing memory palace status
373
+
374
+ ```bash
375
+ pnpm cli status
376
+ ```
377
+
378
+ ### Importing a Claude Code session
379
+
380
+ ```bash
381
+ pnpm cli import-session "session-file.txt" -d "my-project" -n 5
382
+ ```
383
+
384
+ ---
385
+
386
+ ## Development
387
+
388
+ ### Building the project
389
+
390
+ ```bash
391
+ pnpm build
392
+ ```
393
+
394
+ ### Running tests
395
+
396
+ ```bash
397
+ pnpm test
398
+ ```
399
+
400
+ ### Watching tests
401
+
402
+ ```bash
403
+ pnpm test:watch
404
+ ```
405
+
406
+ ### Running the CLI directly
407
+
408
+ ```bash
409
+ pnpm cli <command>
410
+ ```
411
+
412
+ ### Manual consolidation
413
+
414
+ ```bash
415
+ pnpm consolidate
416
+ ```
417
+
418
+ ---
419
+
420
+ ## Concepts
421
+
422
+ | Field | Cognitive term (French, as in the code) | Meaning |
423
+ |-------|-----------|---------|
424
+ | `createdAt` | Encodage | trace formation |
425
+ | `lastRecalled` | Dernière réactivation | last conscious retrieval |
426
+ | `recallCount` | Réactivations | recalls (reinforce) |
427
+ | `saillance` | Force mnésique | trace strength 0–100 |
428
+ | `decayRate` | Taux d'oubli | degradation speed |
429
+ | `sessionId` | Contexte d'encodage | encoding context |
430
+ | `directory` | Lieu mental | conceptual space (project) |
431
+ | `currentLevel` | État de consolidation | decay stage 0–4 |
432
+ | `keywords` | Indices de récupération | retrieval cues |
433
+ | `memoryType` | Type | episodic / semantic / procedural |
434
+
435
+ **Decay thresholds:** L0→L1 ~24h · L1→L2 ~1 week · L2→L3 ~1 month · L3→L4 beyond.
436
+ Slowing factors: `recallCount * 0.3`, saillance >70 → 1.5× slower, content >500 chars,
437
+ keywords >5. `photographic: true` disables decay entirely.
438
+
439
+ **Memory types:** `episodic` (events), `semantic` (facts), `procedural` (skills).
440
+
441
+ ---
442
+
443
+ ## Roadmap
444
+
445
+ ### ✅ Done — Sprints 1–4
446
+ - Core decay + inverse search; `bun:sqlite` store (WAL, write-queue serialization)
447
+ - CLI + Hono API + web dashboard ("palais de mémoire")
448
+ - Nightly cron consolidation (`0 3 * * *`)
449
+ - LLM auto-generation of L1/L2/L3 (Claude Haiku + prompt caching)
450
+ - Similar-detection + merge (L4); enriched search (type/period/saillance/recalls)
451
+ - Photographic mode; Claude Code `Stop` hook → session learning capture
452
+
453
+ ### 🎯 Phase 5 — Prospective memory (the destiny)
454
+ > Corrected plan in **[PHASE5_PLAN.md](./PHASE5_PLAN.md)**. Summary:
455
+
456
+ - [x] **5.0 Preconditions** — cross-process SQLite advisory lock and injectable
457
+ event bus in the test env, both shipped (S5-00a, S5-00b).
458
+ - [x] **5.1 Data model** — dedicated `intentions` table (not a new `MemoryType`,
459
+ intentions don't follow the retrospective decay curve) + `cues` table with
460
+ typed `trigger_spec`. One intention → N cues.
461
+ - [x] **5.2 Cue resolver** — time cues (ISO/cron) and event cues (file_open,
462
+ branch_switch, error_pattern). Decay rule: `armed` → saillance pinned at 100;
463
+ `fired` not `closed` → normal decay (Zeigarnik fades); `closed` → archived.
464
+ - [x] **5.3 Hooks** — `SessionStart` injects context (`scripts/hook-session-start.ts`,
465
+ budget via `HUMEMORY_SESSION_BUDGET`); git `post-commit` closes loops via the
466
+ explicit `Closes loop-<id>` marker, and only *suggests* on file-overlap.
467
+ - [x] **5.4 CLI/API** — `pnpm cli intent {add,list,close,fire,resolve}`,
468
+ `POST /intentions`, `POST /cues`, `POST /events`, `POST /cues/resolve`.
469
+
470
+ **Deferred to Phase 6** — Cognitive scripts (spec needed before code).
471
+
472
+ ### 🛣️ Beyond
473
+ - Shared multi-project DB with concurrency lock (WAL + advisory) — done (Sprint 5 / S5-00a)
474
+ - OpenCode / other-agent integration; export/import memories between projects
475
+
476
+ ---
477
+
478
+ ## Known issues
479
+ - ~~SQLite multi-process: advisory lock~~ — fixed in Sprint 5 (S5-00a): WAL + write-queue (Sprint 4) plus file-based cross-process `AdvisoryLock`.
480
+ - `tests/fixtures/` missing — suites seed ad hoc literals (BUG-05, due with S5-00b).
481
+ - `vitest.config.ts` orphaned; suite runs under `bun test` (BUG-06).
482
+ - `tsc` global can shadow local — `pnpm build` is `tsc -p tsconfig.json`.
483
+
484
+ ## Notes
485
+ - Shared DB: `data/humemory.db` · API port `3456` (`PORT` env)
486
+ - Stack: TypeScript · `bun:sqlite` · `flexsearch` · `hono` · `commander` · `@anthropic-ai/sdk`
487
+ - `CLAUDE.md` is a thin Claude-Code-specific quick-start that delegates to
488
+ `AGENTS.md`; `AGENTS.md` remains the canonical source of truth.
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * Point d'entrée de la CLI.
4
+ *
5
+ * humemory tourne sous bun, pas sous node : le store utilise `bun:sqlite`, que
6
+ * le loader ESM de node ne sait pas résoudre. Le shebang vise donc bun, et le
7
+ * garde ci-dessous rattrape l'appel explicite `node bin/humemory.js` avec un
8
+ * message lisible plutôt qu'un ERR_UNSUPPORTED_ESM_URL_SCHEME.
9
+ */
10
+
11
+ if (typeof Bun === 'undefined') {
12
+ console.error(
13
+ 'humemory a besoin de bun (le store utilise bun:sqlite).\n' +
14
+ 'Installe-le : https://bun.sh — puis relance `humemory` ou `bun bin/humemory.js`.'
15
+ );
16
+ process.exit(1);
17
+ }
18
+
19
+ await import('../dist/cli/index.js');
@@ -0,0 +1,15 @@
1
+ import type { LLMClient } from '../core/llm-generator.js';
2
+ export interface HookOptions {
3
+ dbPath: string;
4
+ directory?: string;
5
+ maxLearnings?: number;
6
+ client?: LLMClient;
7
+ verbose?: boolean;
8
+ }
9
+ export interface HookResult {
10
+ sessionId: string;
11
+ directory: string;
12
+ memoriesStored: number;
13
+ learnings: string[];
14
+ }
15
+ export declare function processSession(rawTranscript: string, options: HookOptions): Promise<HookResult>;
@@ -0,0 +1,38 @@
1
+ import { SQLiteStore } from '../store/sqlite.js';
2
+ import { parseClaudeHookPayload } from './session-parser.js';
3
+ import { extractLearnings } from './learning-extractor.js';
4
+ import Anthropic from '@anthropic-ai/sdk';
5
+ export async function processSession(rawTranscript, options) {
6
+ const directory = options.directory ?? process.cwd();
7
+ const client = options.client ?? new Anthropic();
8
+ const session = parseClaudeHookPayload(rawTranscript, directory);
9
+ const learnings = await extractLearnings(session, client, options.maxLearnings ?? 5);
10
+ if (learnings.length === 0) {
11
+ return { sessionId: session.sessionId, directory: session.directory, memoriesStored: 0, learnings: [] };
12
+ }
13
+ const store = new SQLiteStore(options.dbPath);
14
+ const stored = [];
15
+ try {
16
+ for (const learning of learnings) {
17
+ await store.add({
18
+ content: learning.content,
19
+ directory: session.directory,
20
+ day: new Date().toISOString().split('T')[0],
21
+ keywords: learning.keywords,
22
+ sessionId: session.sessionId,
23
+ memoryType: learning.memoryType,
24
+ level3Keywords: learning.level3Keywords,
25
+ });
26
+ stored.push(learning.content.slice(0, 80));
27
+ }
28
+ }
29
+ finally {
30
+ store.close();
31
+ }
32
+ return {
33
+ sessionId: session.sessionId,
34
+ directory: session.directory,
35
+ memoriesStored: stored.length,
36
+ learnings: stored,
37
+ };
38
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Closing loops from commits — Phase 5.3.2.
3
+ *
4
+ * The gesture that purges an open loop is the commit. Two paths:
5
+ *
6
+ * 1. **Explicit** — `Closes loop-a1b2c3d4` in the message. The author's
7
+ * intention, unambiguous: close it.
8
+ * 2. **Heuristic** — overlap between the files touched and the loop's text. This
9
+ * **never** closes anything automatically: it suggests. Closing the wrong loop
10
+ * costs more than leaving one open.
11
+ *
12
+ * The logic lives here so it stays testable; `scripts/hook-post-commit.ts` only
13
+ * queries git and prints.
14
+ */
15
+ import type { Intention, IntentionStore } from '../core/types.js';
16
+ export interface CommitInfo {
17
+ sha: string;
18
+ message: string;
19
+ files: string[];
20
+ /** Mental place of the repository — bounds the heuristic to the current project. */
21
+ directory: string;
22
+ }
23
+ export interface CloseSuggestion {
24
+ intention: Intention;
25
+ score: number;
26
+ /** Tokens shared between the commit's files and the loop's content. */
27
+ matched: string[];
28
+ }
29
+ export interface CommitCloseResult {
30
+ closed: Intention[];
31
+ suggestions: CloseSuggestion[];
32
+ /** Ids mentioned in the message but unknown or ambiguous. */
33
+ unresolved: string[];
34
+ }
35
+ /** Suggestion threshold: at least one meaningful shared token. */
36
+ export declare const SUGGESTION_THRESHOLD = 1;
37
+ /** Maximum suggestions shown — beyond that it is noise. */
38
+ export declare const MAX_SUGGESTIONS = 3;
39
+ /** Splits a text into meaningful tokens, without accents or case. */
40
+ export declare function tokenize(text: string): string[];
41
+ /** Tokens drawn from a file path: directory segments plus the name without its extension. */
42
+ export declare function tokenizePath(path: string): string[];
43
+ /**
44
+ * Overlap between a commit's files and a loop's content.
45
+ *
46
+ * Deliberately crude: this score closes nothing, it only ranks suggestions put
47
+ * to a human.
48
+ */
49
+ export declare function scoreOverlap(intention: Intention, files: string[]): CloseSuggestion['matched'];
50
+ /**
51
+ * Applies a commit to the open loops.
52
+ *
53
+ * Closes the ones named explicitly (and cancels their remaining cues — a cue
54
+ * outliving its loop is a ghost wake-up). For the rest, it only suggests.
55
+ */
56
+ export declare function applyCommitToLoops(store: IntentionStore, commit: CommitInfo, memories?: {
57
+ verify(id: string, by?: string): Promise<unknown>;
58
+ }): Promise<CommitCloseResult>;
59
+ /** Renders the report printed after a commit. Empty string when there is nothing to say. */
60
+ export declare function renderCommitReport(result: CommitCloseResult): string;