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
@@ -0,0 +1,22 @@
1
+ #!/bin/sh
2
+ # humemory — closes the open loops this commit purged.
3
+ #
4
+ # Enable in THIS repository:
5
+ # git config core.hooksPath .githooks
6
+ #
7
+ # Enable in ANOTHER project: copy this file into its .githooks/ and export
8
+ # HUMEMORY_HOME pointing at your humemory checkout. Without it the script would
9
+ # be looked up inside the committed repository, where it does not exist — the
10
+ # database is shared across projects, the code is not.
11
+ # export HUMEMORY_HOME=/path/to/humemory
12
+ #
13
+ # Only closes loops named explicitly ("Closes loop-a1b2c3d4"); the rest is
14
+ # suggested. Never fails: the commit is already written.
15
+
16
+ command -v bun >/dev/null 2>&1 || exit 0
17
+
18
+ HOME_DIR="${HUMEMORY_HOME:-$(git rev-parse --show-toplevel)}"
19
+ SCRIPT="$HOME_DIR/scripts/hook-post-commit.ts"
20
+
21
+ [ -f "$SCRIPT" ] || exit 0
22
+ bun "$SCRIPT" || true
package/AGENTS.md ADDED
@@ -0,0 +1,328 @@
1
+ # AGENTS.md — humemory
2
+
3
+ **Memory for AI agents that forgets like a human — and resurfaces like one.**
4
+
5
+ Canonical guide for any agent (Claude Code, OpenCode, …) working *on* this repo.
6
+ For the project's identity and "why", read [README.md](./README.md) first.
7
+
8
+ ---
9
+
10
+ ## 🎯 Vision — two halves of a brain
11
+
12
+ humemory has two halves, both built as of Phase 8 (2026-08-08). The direction
13
+ was **Direction 1**, chosen 2026-06-17; everything below is the shipped result.
14
+
15
+ 1. **Retrospective** ✅ — past learnings **decay** through 5 levels (detail → summary
16
+ → essential → keywords → lost/merged); recall reinforces; inverse search hits the
17
+ degraded layers first.
18
+ 2. **Prospective** ✅ — intentions that fire on a **cue** (time/event), **Zeigarnik**
19
+ open loops that stay salient until a `commit` closes them, and context-triggered
20
+ **scripts** that fade on disuse rather than time. A memory that resurfaces
21
+ *before* it is queried. See Phases 5 and 8.
22
+
23
+ On top of both: a **trust layer** (Phase 6) so several agents can write to one
24
+ store without a wrong lesson becoming indestructible, a **dreamer** (6.1) that
25
+ proposes cross-session/cross-agent patterns for human review, an **MCP server**
26
+ (6.2) so Claude/Codex/Kimi/OpenCode share one memory, and **vector search**
27
+ (Phase 7) as an opt-in second retrieval lane alongside BM25.
28
+
29
+ The conceptual source for the prospective half is `SCRATCHPAD.md` (memoire
30
+ prospective, scripts cognitifs, effet Zeigarnik).
31
+
32
+ ---
33
+
34
+ ## ⚙️ Commands
35
+
36
+ ```bash
37
+ pnpm install
38
+ pnpm build # tsc -p tsconfig.json → dist/
39
+ pnpm dev # watch src/cli/index.ts (bun)
40
+ pnpm start:api # HTTP API + dashboard on :3456
41
+ pnpm cli <cmd> # run CLI directly
42
+ pnpm test # bun test, single pass
43
+ pnpm test:watch # bun test --watch
44
+ pnpm consolidate # manual decay pass (cron-friendly)
45
+ ```
46
+
47
+ Single test file: `bun test tests/humemory.test.ts`
48
+
49
+ ---
50
+
51
+ ## 📦 Structure
52
+
53
+ ```
54
+ src/
55
+ ├── core/
56
+ │ ├── types.ts # Memory, DecayLevel, SearchQuery, MemoryStore iface
57
+ │ ├── decay.ts # degradation curve + thresholds
58
+ │ ├── search.ts # inverse search (BM25, degraded-first)
59
+ │ └── llm-generator.ts # auto-generate L1/L2/L3 via Claude Haiku (prompt cache)
60
+ ├── store/
61
+ │ └── sqlite.ts # bun:sqlite store (WAL), findSimilar/merge/setPhotographic
62
+ ├── agent/
63
+ │ ├── session-parser.ts # parse Claude Code session transcripts
64
+ │ ├── learning-extractor.ts # extract decisions/bugs/solutions
65
+ │ ├── claude-hook.ts # Stop-hook → auto-encode session learnings
66
+ │ └── session-context.ts # SessionStart → markdown block (open loops + traces)
67
+ ├── core/
68
+ │ ├── clock.ts # Clock seam (systemClock / FakeClock)
69
+ │ ├── event-bus.ts # AppEvent + InMemoryEventBus
70
+ │ ├── cue-arg.ts # cue syntax, shared by the CLI and the React form
71
+ │ └── cues.ts # cue resolver, cron matcher, loop ids
72
+ ├── api/server.ts # Hono HTTP API + serves public/ dashboard
73
+ ├── cli/index.ts # commander CLI
74
+ └── index.ts # library exports
75
+ web/ # React front (bun bundler → public/app, served at /app)
76
+ scripts/hook-session.ts # Claude Code Stop hook → encode learnings
77
+ scripts/hook-session-start.ts # Claude Code SessionStart hook → inject context
78
+ tests/ # bun test (hermetic; helpers/ + fixtures/)
79
+ data/humemory.db # shared DB (created on first run)
80
+ ```
81
+
82
+ ---
83
+
84
+ ## 🧠 Concepts (cognitive-neuroscience naming)
85
+
86
+ | Field | Cognitive term (French, as in the code) | Meaning |
87
+ |-------|-----------|---------|
88
+ | `createdAt` | Encodage | trace formation |
89
+ | `lastRecalled` | Dernière réactivation | last conscious retrieval |
90
+ | `recallCount` | Réactivations | recalls (reinforce) |
91
+ | `saillance` | Force mnésique | trace strength 0–100 |
92
+ | `decayRate` | Taux d'oubli | degradation speed |
93
+ | `sessionId` | Contexte d'encodage | encoding context |
94
+ | `directory` | Lieu mental | conceptual space (project) |
95
+ | `currentLevel` | État de consolidation | decay stage 0–4 |
96
+ | `keywords` | Indices de récupération | retrieval cues |
97
+ | `memoryType` | Type | episodic / semantic / procedural |
98
+
99
+ **Decay thresholds:** L0→L1 ~24h · L1→L2 ~1 week · L2→L3 ~1 month · L3→L4 beyond.
100
+ Slowing factors: `recallCount * 0.3`, saillance >70 → 1.5× slower, content >500 chars,
101
+ keywords >5. `photographic: true` disables decay entirely.
102
+
103
+ **Memory types:** `episodic` (events), `semantic` (facts), `procedural` (skills).
104
+
105
+ ---
106
+
107
+ ## 🌐 API (`:3456`, `PORT` env to override)
108
+
109
+ | Method | Path | Description |
110
+ |--------|------|-------------|
111
+ | POST | `/memories` | add |
112
+ | GET | `/memories` | list (limit, level, type) |
113
+ | GET | `/memories/:id` | fetch one |
114
+ | POST | `/memories/:id/recall` | bump recall + saillance |
115
+ | POST | `/memories/:id/similar` | find similar |
116
+ | POST | `/memories/:id/merge` | merge (L4) |
117
+ | POST | `/memories/:id/photo` | toggle photographic |
118
+ | DELETE | `/memories/:id` | forget |
119
+ | GET | `/search?query=X` | inverse search |
120
+ | POST | `/decay` | run consolidation |
121
+ | GET | `/status` | pool stats |
122
+
123
+ ---
124
+
125
+ ## 🧪 Autonomous test environment — REQUIRED
126
+
127
+ **Non-negotiable design constraint** (set 2026-06-17). Every test run MUST be
128
+ hermetic, deterministic, and network-free. Full spec: **[docs/TESTING.md](./docs/TESTING.md)**.
129
+
130
+ Core rules:
131
+ - **Isolated DB per run** — never touch `data/humemory.db`; use an in-memory or
132
+ temp-file `bun:sqlite` instance, torn down after each suite.
133
+ - **Injectable clock** — decay is time-driven, so time must be a parameter, not
134
+ `Date.now()`. Tests fast-forward a fake clock to assert L0→L4 transitions.
135
+ - **Mocked LLM** — no calls to Anthropic in tests; `LLMClient` is stubbed with
136
+ deterministic fixtures. CI runs with no `ANTHROPIC_API_KEY`.
137
+ - **Fixtures, not live data** — seed memories from `tests/fixtures/`.
138
+ - **Deterministic** — same input ⇒ same output; no wall-clock, no randomness, no
139
+ ordering by `Date.now()`.
140
+
141
+ This environment is the precondition for Phase 5: prospective/Zeigarnik logic is
142
+ clock- and event-driven and cannot be trusted without it.
143
+
144
+ ---
145
+
146
+ ## 📊 Roadmap
147
+
148
+ ### ✅ Done — Sprints 1–4
149
+ - Core decay + inverse search; `bun:sqlite` store (WAL, write-queue serialization)
150
+ - CLI + Hono API + web dashboard ("palais de mémoire")
151
+ - Nightly cron consolidation (`0 3 * * *`)
152
+ - LLM auto-generation of L1/L2/L3 (Claude Haiku + prompt caching)
153
+ - Similar-detection + merge (L4); enriched search (type/period/saillance/recalls)
154
+ - Photographic mode; Claude Code `Stop` hook → session learning capture
155
+
156
+ ### 🎯 Phase 5 — Prospective memory (the destiny)
157
+ > Detailed corrected plan in **[PHASE5_PLAN.md](./PHASE5_PLAN.md)**. Summary below.
158
+
159
+ **Preconditions (5.0, blocking):**
160
+ - [x] Cross-process SQLite advisory lock (closes Bug #3 below) — shipped, `AdvisoryLock` in `src/store/sqlite.ts`
161
+ - [x] Injectable event bus in the test env (Phase 5 is event-driven, not just clock-driven) — shipped as S5-00b, `src/core/event-bus.ts`
162
+
163
+ **Data model (5.1): ✅ shipped (S5-01).** Dedicated `intentions` table (NOT a new `MemoryType` —
164
+ intentions have a future trigger, status, and different decay rules than retrospective
165
+ traces) + `cues` table with typed `trigger_spec` (time = ISO/cron, event = file_open /
166
+ branch_switch / error_pattern). One intention → N cues.
167
+
168
+ **Cue resolver (5.2): ✅ shipped (S5-02), `src/core/cues.ts`.** `resolveTimeCues(now)` + `resolveEventCues(event)` + expiry.
169
+ Decay × intention rule: `armed` → saillance pinned at 100, no decay (open loop stays
170
+ salient); `fired` not `closed` → normal decay (Zeigarnik fades over time); `closed`
171
+ → archived.
172
+
173
+ **Hooks (5.3): ✅ shipped (S5-03a, S5-03b).**
174
+ - `scripts/hook-session-start.ts` — Claude Code `SessionStart` hook resolves cues for
175
+ the current `cwd` + `git branch --show-current`, emits a structured markdown block
176
+ on stdout (configurable budget via `HUMEMORY_SESSION_BUDGET`). Logic lives in
177
+ `src/agent/session-context.ts`.
178
+ - `.githooks/post-commit` → `scripts/hook-post-commit.ts` — parses the commit message
179
+ for `Closes loop-<id>` and closes those loops, cancelling their cues. File-overlap
180
+ scoring only ever *suggests*, never closes: logic in `src/agent/commit-closer.ts`.
181
+ Set `HUMEMORY_HOME` when installing the hook into another project — the database is
182
+ shared across projects, the code is not.
183
+
184
+ **CLI/API (5.4): ✅ shipped (S5-04).** `pnpm cli intent {add,list,close,fire,resolve}`
185
+ (cue args like `event:file_open:src/a.ts`, `cron:0 9 * * 1`) + `POST /intentions`,
186
+ `GET /intentions`, `POST /intentions/:id/{close,fire}`, `POST /cues`, `POST /events`,
187
+ `POST /cues/resolve` — in `src/api/intentions-routes.ts`, mounted by the server.
188
+
189
+ **Cognitive scripts → Phase 8 ✅ shipped (2026-08-08).** See below.
190
+
191
+ ### 🎯 Phase 6 — Trusted memory & "Dreaming" ✅ shipped (2026-08-08)
192
+ > Approved plan in **[PHASE6_PLAN.md](./PHASE6_PLAN.md)**. Summary below.
193
+ > Drafted collaboratively by Kimi + Claude; history in PROPOSAL.md (git-ignored).
194
+
195
+ **Goal:** make the shared store *trustworthy* when several agents write to it,
196
+ and make it *learn across sessions* instead of only decaying trace by trace.
197
+
198
+ **6.0 — Trust layer: ✅ shipped.**
199
+ - [x] **6.0.3 first** — SessionStart injection hardening: `<humemory-untrusted>`
200
+ wrapping, marker-escape defence, length caps (`src/core/sanitize.ts`)
201
+ - [x] **6.0.1** — Provenance migration: `source` / `agent` / `verified` /
202
+ `verification_reason` / `device` / `refuted_count` on `memories` + `intentions`.
203
+ Verification is **earned by evidence** (cross-agent corroboration via the
204
+ dreamer, grounding in an explicitly-closed loop, cross-agent reuse in
205
+ `recall(id, agent)`); trust score (`src/core/trust.ts`) separate from
206
+ saillance; decay slowdown capped at 2.5× on the *product* of multipliers.
207
+ `device` = `$HUMEMORY_DEVICE` || hostname — localization now, sync later.
208
+ - [x] **6.0.4** — `level_revisions` versions derived levels before merge
209
+ overwrites them; `unmerge` reverts. Retention: last 5 per memory.
210
+ - [x] **6.0.2** — `contradictions`: loser saillance ÷4 (floor 5), excluded from
211
+ context but searchable; tiered authority keyed on `verification_reason`;
212
+ revocation recomputes saillance; CLI `contradict`, API `/contradicts`.
213
+
214
+ **6.1 — Dreaming: ✅ shipped** (`pnpm dream`, `src/core/dreamer.ts`). Clusters
215
+ recurring traces across sessions/agents (KeywordClusterer behind a `Clusterer`
216
+ interface — vectors are Phase 7), scores clusters on `base(source)` only,
217
+ writes **idempotent** `dream_proposals` (14-day expiry) reviewed via
218
+ `pnpm cli dream review` / `approve` / `reject`; API `GET /dreams`,
219
+ `POST /dreams/:id/approve|reject`. Nothing touches `memories` or `AGENTS.md`
220
+ without approval. Dream kinds: `promote_semantic`, `merge_cluster`,
221
+ `contradiction`, `close_stale_loop`, `update_agents_md` (suggestion only).
222
+
223
+ **6.2 — MCP server: ✅ shipped** (`pnpm mcp`, `src/mcp/server.ts`, stdio).
224
+ Tools `humemory_add / search / recall / intent_add / intent_close / dreams` —
225
+ Claude, Codex, Kimi, OpenCode share one store with agent attribution on every
226
+ write (`agent` arg or `$HUMEMORY_AGENT`; `HUMEMORY_DB` override for tests).
227
+
228
+ **Client registration** — the repo ships `.mcp.json` (Claude Code project
229
+ scope, `HUMEMORY_AGENT=claude`). For other agents, register the same server
230
+ with their own identity:
231
+
232
+ | Agent | Config | `HUMEMORY_AGENT` |
233
+ |-------|--------|------------------|
234
+ | Claude Code | `.mcp.json` at repo root (shipped) | `claude` |
235
+ | Kimi Code | same shape in the Kimi MCP config | `kimi` |
236
+ | Codex | same shape in the Codex MCP config | `codex` |
237
+ | OpenCode | `opencode.json` → `mcp` section | `opencode` |
238
+
239
+ Server entry: `bun run src/mcp/server.ts` (stdio). Every agent MUST set its
240
+ own `HUMEMORY_AGENT` — attribution is what powers cross-agent `reused`
241
+ verification and the dreamer's cross-agent recurrence signal.
242
+
243
+ ### 🎯 Phase 8 — Cognitive scripts ✅ shipped (2026-08-08)
244
+ > Approved plan in **[PHASE8_PLAN.md](./PHASE8_PLAN.md)**. Drafted by Kimi, annotated
245
+ > and implemented (8.4/8.5, plus contradictions-target-scripts) by Claude after Kimi
246
+ > ran out of quota mid-phase. Dialogue log: [PHASE8_DIALOG.md](./PHASE8_DIALOG.md).
247
+
248
+ **Goal:** not "remember this fact" but "when this situation occurs, run this
249
+ drill" — a named, cue-triggered, versioned bundle of ordered steps, injected as
250
+ one block into the session context when its cue fires. Explicitly rejected
251
+ shapes: template (steps are data, not text interpolation), chained intentions
252
+ (a script has its own lifecycle, not a re-implementation of one on a model that
253
+ has none), permanent system prompt (fires on context, not every session), tool
254
+ bundle (scripts are markdown any CLI agent reads, humemory stays agent-agnostic).
255
+
256
+ - **8.1 — data model.** `scripts` table (draft/active/archived, fire-bumped
257
+ saillance, `pinned` = photographic equivalent, same 6.0.1 provenance columns
258
+ as intentions). `cues` rebuilt from `intention_id` to generic
259
+ `target_kind`/`target_id` so one cue mechanism arms intentions or scripts —
260
+ the project's first non-additive migration (SQLite table rebuild:
261
+ create-new/copy/drop/rename, reused twice more below).
262
+ - **8.2 — injection.** One drill per context block max (two firing together is
263
+ a smell, not a case to accommodate); tie-break on *effective* saillance
264
+ (disuse included, not the raw value). Same 6.0.3 sandboxing as traces:
265
+ human-authored renders bare, everything else wrapped in
266
+ `<humemory-untrusted>`, escape-attempt telemetry on every render path.
267
+ - **8.3 — authoring & trust.** Three paths: human (`script add` → active
268
+ directly), agent (`script propose` → draft, human activates), dreamer-mined
269
+ (→ draft, see 8.5). Draft scripts never fire.
270
+ - **8.4 — disuse decay, the inverse Zeigarnik.** Scripts fade on *disuse*, not
271
+ time: active + unfired 60 days → −10 saillance/month past the grace period;
272
+ under 20 → auto-archived (searchable, never injected) with a `script_archived`
273
+ dream-proposal notice so the archival is human-visible; firing resets the
274
+ clock entirely; `pinned` scripts are exempt. **Correction kills the
275
+ script:** `contradictions.loser_id` now targets a script as well as a memory
276
+ (`loser_kind` column, same table-rebuild migration pattern as 8.1's cues) — a
277
+ memory contradicting a script archives it outright (not a saillance
278
+ collapse, that scale already means disuse) rather than proposal-gated
279
+ (scripts carry no `verified` field to be asymmetric about). Revocation
280
+ restores `active` but leaves cues cancelled — re-arming stays a deliberate
281
+ human act.
282
+ - **8.5 — dreamer mining.** A `script_candidate` proposal kind: a "correction"
283
+ is redefined as a trace that **won an active contradiction** (reusing 6.0.2
284
+ rather than inventing a new tag) — cluster ≥2 corrections sharing a
285
+ directory, draft steps from the raw content (oldest first, capped, no LLM),
286
+ file as a proposal. Approval lands the script as `draft`, never `active` —
287
+ same "reviewer saw a summary, not every word" caution already applied to
288
+ `promote_semantic`.
289
+
290
+ CLI: `pnpm cli script {add,list,activate,archive,fire}`, `contradict` now
291
+ accepts a script id as the loser. API: `POST/GET /scripts`,
292
+ `POST /scripts/:id/{activate,archive,fire}`.
293
+
294
+ ### 🛣️ Beyond
295
+ - Shared multi-project DB with concurrency lock (WAL + advisory) — done (Sprint 5 / S5-00a)
296
+ - **Phase 7: vector memory** ✅ shipped (2026-08-08) — `Embedder` interface +
297
+ offline ONNX embeddings (bge-m3 q8 default, 1024 dims; e5-base/small via
298
+ `--model`), `VectorClusterer` with per-model calibrated thresholds
299
+ (`CLUSTER_THRESHOLDS`), hybrid RRF search (`search --semantic`),
300
+ `embed backfill`, `dream run --window <days>`.
301
+ **Calibration (7.5, 4 rounds — CLOSED):** no local lightweight embedder
302
+ reaches a P=1.0 corroboration gate on 52 pairs incl. hard negatives
303
+ (bge-m3 false max 0.908 > true min 0.691) → **vector auto-corroboration
304
+ permanently disabled** (0.99 sentinel; keyword path keeps metadata-only
305
+ corroboration). Best clusterer: bge-m3 @ 0.740 (F1 0.89). Default dream
306
+ clusterer stays `keyword`, `vector` opt-in. Details:
307
+ [PHASE7_PLAN.md](./PHASE7_PLAN.md), dialogue log
308
+ [PHASE7_DIALOG.md](./PHASE7_DIALOG.md)
309
+ - Multi-device sync of the shared store (the `device` column from 6.0.1 makes
310
+ it migration-free; conflict policy TBD)
311
+ - OpenCode / other-agent integration; export/import memories between projects
312
+
313
+ ---
314
+
315
+ ## 🐛 Known issues
316
+ - ~~SQLite multi-process: advisory lock~~ — fixed in Sprint 5 (S5-00a): WAL + write-queue (Sprint 4) plus file-based cross-process `AdvisoryLock`.
317
+ - ~~`tests/fixtures/` missing~~ — closed: `tests/fixtures/{memories,events,loops}.basic.json` +
318
+ `tests/helpers/fixtures.ts` shipped with S5-00b. New Phase 6/7/8 suites still lean on inline
319
+ literals for scenario-specific content (fine per [docs/TESTING.md](./docs/TESTING.md)'s own
320
+ rule — a fixture is for shared corpora, not a one-off case a test is *about*).
321
+ - `vitest.config.ts` orphaned; suite runs under `bun test` (BUG-06).
322
+ - `tsc` global can shadow local — `pnpm build` is `tsc -p tsconfig.json`.
323
+
324
+ ## 📝 Notes
325
+ - Shared DB: `data/humemory.db` · API port `3456` (`PORT` env)
326
+ - Stack: TypeScript · `bun:sqlite` · `flexsearch` · `hono` · `commander` · `@anthropic-ai/sdk`
327
+ - `CLAUDE.md` is a thin quick-start companion that points back to this file; this
328
+ AGENTS.md remains the canonical source of truth for project vision and concepts.
package/CHANGELOG.md ADDED
@@ -0,0 +1,198 @@
1
+ # Changelog
2
+
3
+ ## [0.2.1] - 2026-08-09
4
+ **Features:**
5
+ - correction kills the script — contradictions target scripts too
6
+ - script_candidate dreamer mining from contradiction winners
7
+ - archival notice — script_archived dream proposal on disuse
8
+ - script injection into the SessionStart block
9
+ - script CLI + API with draft gate
10
+ - scripts table + cues target_kind migration + resolver fan-out
11
+ - round 4 — bge-m3 default, per-model cluster thresholds, calibration CLOSED
12
+ - --window <days> CLI flag + DreamOptions.windowDays override
13
+ - e5-base round 2 — corroboration re-enabled at 0.855, defaults flipped
14
+ - calibrate vector thresholds — cluster 0.855, vector corroboration disabled (e5-small overlap)
15
+ - vector memory — embedders, vector clusterer, hybrid search
16
+ - MCP server — one unified memory for every agent
17
+ - dreaming — cross-session consolidation with human gate
18
+ - contradictions — collapse without deletion
19
+ - version derived levels before merge overwrite + unmerge
20
+ - provenance & evidence-earned trust layer
21
+ - injection hardening on SessionStart re-injection
22
+ - serve the React app at /, keep the vanilla dashboard at /legacy
23
+ - replay, merge, encoding and advanced filters — parity reached
24
+ - port the dashboard views to React — wrapped, not rewritten
25
+ - prospective tab — loops, tension, cues, closure
26
+ - React shell — bun bundler, shared types, component tests
27
+ - post-commit hook — a commit closes the loop
28
+ - CLI intent commands + prospective HTTP routes
29
+ - SessionStart hook — inject open loops as context
30
+ - cue resolver — time cues, event cues, expiry
31
+ - prospective data model — intentions & cues tables
32
+ - autonomous test environment — clock seam + event bus
33
+ - add status snapshot for development phase and sprint progress
34
+ - implement cross-process advisory lock for SQLite (closes Bug #3)
35
+ - add internal script runner for bmad-method skill
36
+ - update README.md with usage instructions and examples; add three.js dependency
37
+ - consolidate documentation into README.md, add testing guidelines
38
+ - SQLite WAL mode, write queue serialization, build docs
39
+ - photographic badge, merge UI, filtres avancés
40
+ - photographic mode — désactiver dégradation pour traces critiques
41
+ - search enrichie — filtres type, date, saillance, recalls
42
+ - hook agent Claude Code — parse sessions, extraction apprentissages
43
+ - détection et fusion de souvenirs similaires
44
+ - auto-génération niveaux N1/N2/N3 via LLM
45
+
46
+ **Bug Fixes:**
47
+ - thread the fake clock into every runDreamer() call
48
+ - round 3 — hard negatives falsify the 0.855 gate, corroboration back OFF
49
+ - establish agent identity instead of accepting it
50
+ - implement corroboration, stop dream output rendering bare
51
+ - prevent path traversal in static handlers + land roadmap dashboard work
52
+ - update dev scripts to use bun and add mcp.json for context-mode
53
+ - migrate better-sqlite3 → bun:sqlite, fix build config
54
+
55
+ **Documentation:**
56
+ - re-flag escapedMarkers gap in script rendering — shipped in 8.2 unfixed
57
+ - note escapedMarkers not counted for script steps in 8.2 WIP
58
+ - note the leftover intention_id call site breaking the cues rebuild
59
+ - annotate the Phase 8 draft, answer Kimi's three open questions
60
+ - cognitive scripts spec — cue-triggered drill bundles, draft pending approval
61
+ - reply to round 4 — calibration closed, per-model thresholds are the right shape
62
+ - reply to round 3 — agree hard negatives need a stronger signal, not more fixture
63
+ - reply on the Phase 7 dialog log
64
+ - fix the sequencing row that still said embed-on-add
65
+ - integrate Claude's annotations A1-A5 into the plan
66
+ - annotate the Phase 7 draft against the tree at 8bd4d50
67
+ - Phase 7 draft plan — vector memory (embeddings)
68
+ - mark Phase 6 shipped in the roadmap (6.0.3 → 6.2)
69
+ - approve Phase 6 plan — trusted memory & dreaming
70
+
71
+ **Tests:**
72
+ - attribute-injection defence on the untrusted marker
73
+
74
+ **Chores:**
75
+ - ship .mcp.json + per-agent MCP registration table
76
+ - untrack .claude/settings.local.json (local file)
77
+ - gitignore PROPOSAL.md (agent collaboration draft)
78
+ - MIT license, and the whole codebase in English
79
+ - remove the vanilla dashboard
80
+ - prepare the 0.2.0 release
81
+ - clear the tracked debt — testable routes, hermetic suites
82
+ - resync status with actual code state
83
+ - record 37/37 test pass after bun install — QA-02 resolved
84
+ - status Sprint 3 UX done — 98% progress
85
+ - status Sprint 2 completed — 37/37 tests, 95% progress
86
+ - init bmad-method with project status, bugs, roadmap
87
+
88
+ **CI/CD:**
89
+ - add GitHub Actions CI + release workflows
90
+
91
+ **Other:**
92
+ - docs+fix: close the three gaps between the code and its own record
93
+ - Refactor TracesTab and related components for improved clarity and consistency
94
+ - audit: fix 3 critical issues
95
+ - init: initial commit
96
+
97
+
98
+
99
+ Notable changes to humemory. Format loosely follows [Keep a Changelog](https://keepachangelog.com/);
100
+ versions are pre-1.0, so minor bumps carry breaking changes when they need to.
101
+
102
+ ## [0.2.0] — 2026-07-31
103
+
104
+ The release where the second half of the brain arrives. humemory no longer only
105
+ remembers what happened; it resurfaces what you left unfinished.
106
+
107
+ ### Added — prospective memory (Phase 5)
108
+
109
+ - **Intentions and cues.** An open loop is stored as an `intention` with one or
110
+ more `cues` that wake it — a date, a cron expression, or an event
111
+ (`file_open`, `branch_switch`, `error_pattern`). Tables are created idempotently,
112
+ so an existing database migrates on next open.
113
+ - **Cue resolver** (`src/core/cues.ts`) — `resolveTimeCues`, `resolveEventCues`,
114
+ `fire`, `expireStale`. Cron matching is in-house (no dependency added) and
115
+ carries a seven-day catch-up window, because the resolver runs at session start
116
+ rather than as a daemon.
117
+ - **Decay rules for intentions.** `armed` stays pinned at salience 100 — an open
118
+ loop does not fade. Once `fired` and not `closed`, it relaxes ten points a day
119
+ as the Zeigarnik pull weakens. `closed` and `expired` sit flat.
120
+ - **`SessionStart` hook** (`scripts/hook-session-start.ts`) — writes a markdown
121
+ block on stdout with the open loops and the decayed-but-still-salient traces of
122
+ the current project, which Claude Code injects into the session. Nothing
123
+ relevant means nothing written.
124
+ - **`post-commit` hook** (`.githooks/post-commit`) — `Closes loop-a1b2c3d4` in a
125
+ commit message closes that loop, records the SHA and cancels its cues.
126
+ File-overlap scoring only ever *suggests*; it never closes on a guess.
127
+ - **CLI** `intent add|list|close|fire|resolve`, with cues typed as
128
+ `event:file_open:src/a.ts`, `cron:0 9 * * 1`, `time:<ISO>`.
129
+ - **HTTP** `POST/GET /intentions`, `GET /intentions/:id`,
130
+ `POST /intentions/:id/{close,fire}`, `DELETE /intentions/:id`, `POST/GET /cues`,
131
+ `POST /events`, `POST /cues/resolve`. Payloads are validated: a malformed
132
+ trigger is rejected rather than stored as a cue that never fires.
133
+
134
+ ### Added — React front end
135
+
136
+ - A React app served at **`/`** (and `/app`), bundled by bun itself — no
137
+ additional build tooling. Six tabs: loops, traces, river, galaxy, replay,
138
+ promenade.
139
+ - Front-end types are imported from `src/core/types.ts`; the salience of a loop
140
+ comes from `intentionSaillance`, the same function the backend uses. Nothing is
141
+ reimplemented on the client.
142
+ - Visualisations are code-split and loaded on demand — three.js alone is half a
143
+ megabyte.
144
+ - The original vanilla dashboard is removed once the React front reached parity;
145
+ `/css/*`, `/js/*` and `/assets/*` go with it, shrinking the static surface.
146
+
147
+ ### Added — test environment
148
+
149
+ - `Clock` seam (`systemClock` / `FakeClock`) threaded through the store and the
150
+ search engine, so decay transitions are asserted without waiting.
151
+ - `InMemoryEventBus` with awaited dispatch — a test never needs a `setTimeout`.
152
+ - `tests/helpers/` and `tests/fixtures/`; component tests run under `bun test`
153
+ with happy-dom, so there is one runner for the whole project.
154
+ - A guard that throws if a test opens the production database.
155
+
156
+ ### Fixed
157
+
158
+ - Cross-process SQLite advisory lock (closes the long-standing Bug #3).
159
+ - `PRAGMA foreign_keys=ON` — without it the `ON DELETE CASCADE` from cues to
160
+ intentions was decorative and left orphans behind.
161
+ - Mental places are resolved to absolute paths on write. A loop armed on
162
+ `./src/auth` would never have matched the hook, which looks projects up by
163
+ `process.cwd()` — a silent failure.
164
+ - `promenade` attached five listeners to `document`/`window` and removed none;
165
+ switching tabs left the keyboard driving an invisible camera. `river` kept its
166
+ playback interval running and abandoned its tooltip in the body.
167
+ - The forgetting curve was implemented twice — once in `src/core/decay.ts`, once
168
+ in `public/js/decay.js`. The React path uses the former only.
169
+ - The published CLI was broken under node: `bin/humemory.js` declared a node
170
+ shebang while the store imports `bun:sqlite`. It now targets bun and explains
171
+ itself if run under node.
172
+ - The CLI version was hard-coded and had drifted; it is read from `package.json`.
173
+ - Path traversal in the static handlers (CWE-22), fixed with a containment guard
174
+ that the React routes reuse.
175
+
176
+ ### Changed
177
+
178
+ - `HUMEMORY_DB` is honoured by the API, the CLI and both hooks alike.
179
+ - `server.ts` shrank from 469 to 217 lines; routes live in `memory-routes.ts` and
180
+ `intentions-routes.ts`, each taking its store as a parameter and therefore
181
+ testable.
182
+ - `pnpm build` now builds the library and the front end.
183
+
184
+ ### Removed
185
+
186
+ - The vanilla dashboard (`public/index.html`, `public/js/*`, `public/css/*`) and
187
+ the static routes that served it. `public/session.html` stays — it is a
188
+ separate, self-contained page.
189
+ - `vitest.config.ts` — orphaned, and blind to `.test.tsx` since the front landed.
190
+
191
+ ---
192
+
193
+ ## [0.1.0]
194
+
195
+ Retrospective memory: five-level decay, inverse search over degraded layers,
196
+ recall reinforcement, photographic mode, LLM-generated summary levels, merge of
197
+ similar traces, SQLite store in WAL mode, HTTP API, CLI, and the vanilla
198
+ dashboard with its five visualisations.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 medyll
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.