Commit ad91fce
authored
feat: add facts/knowledge notes memory class alongside instincts (#68)
Closes #65
## Summary
- Introduces **facts** — a second memory class for declarative knowledge
that doesn't fit the trigger→action instinct model (e.g. "The test DB
port is 3306", "Use `pnpm build:fast` to compile")
- Facts are **user-driven**: created in-session via four new LLM tools
(`fact_write`, `fact_read`, `fact_list`, `fact_delete`) — the user says
"remember that X" and Pi stores it directly
- The background analyzer does **not** detect facts from observations;
it only runs decay and cleanup passes on them (keeping the design simple
and reliable)
- Facts are injected into the system prompt as a `## Project Knowledge`
block after the instincts block, using the remaining char budget
## New files
| File | Purpose |
|---|---|
| `src/fact-parser.ts` | Parse/serialize fact `.md` files (YAML
frontmatter + body); mirrors `instinct-parser.ts` without
`trigger`/`action`/`graduated_to` |
| `src/fact-store.ts` | CRUD with 5s mtime-based cache; mirrors
`instinct-store.ts` |
| `src/fact-decay.ts` | Passive confidence decay (−0.05/week); reuses
`applyPassiveDecay` from `confidence.ts` |
| `src/fact-cleanup.ts` | Flagged removal, zero-confirmation TTL, hard
cap; no contradiction detection |
| `src/fact-tools.ts` | Registers `fact_write`, `fact_read`,
`fact_list`, `fact_delete` LLM tools |
| `src/*.test.ts` | Tests for all new modules (834 tests total, all
passing) |
## Modified files
- **`types.ts`** — `Fact` interface + `FactScope`/`FactSource`; three
new `Config` fields
- **`storage.ts`** — `getProjectFactsDir`/`getGlobalFactsDir` helpers;
`ensureStorageLayout` creates `facts/personal` dirs
- **`instinct-injector.ts`** — `buildFactsInjectionBlock` + `## Project
Knowledge` block appended after instincts
- **`instinct-status.ts`** — `/instinct-status` now shows a `Facts /
Knowledge Notes` section
- **`cli/analyze.ts`** — `runFactCleanupPass` + `runFactDecayPass` wired
into both analysis and consolidation passes
- **`index.ts`** — `registerAllFactTools` called in `session_start`
- **`README.md`** — Facts feature section, injection example, tool
table, config table, storage layout
## Test plan
- [ ] `npm run check -w packages/pi-continuous-learning` passes (834
tests, lint, typecheck)
- [ ] Tell Pi "remember that the test DB port is 3306" — verify Pi calls
`fact_write` and the file appears in
`~/.pi/continuous-learning/projects/<hash>/facts/personal/`
- [ ] Run `/instinct-status` — verify a `Facts / Knowledge Notes`
section appears
- [ ] Run `pi-cl-analyze` — verify it completes without error
(decay/cleanup pass runs on empty facts dirs)
- [ ] Ask Pi "what facts do I have?" — verify it calls `fact_list`1 parent 2924d9e commit ad91fce
20 files changed
Lines changed: 1682 additions & 9 deletions
File tree
- packages/pi-continuous-learning
- src
- cli
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
83 | 87 | | |
84 | 88 | | |
85 | 89 | | |
| |||
159 | 163 | | |
160 | 164 | | |
161 | 165 | | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
162 | 182 | | |
163 | 183 | | |
164 | 184 | | |
| |||
185 | 205 | | |
186 | 206 | | |
187 | 207 | | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
188 | 212 | | |
189 | | - | |
| 213 | + | |
190 | 214 | | |
191 | 215 | | |
192 | 216 | | |
| |||
363 | 387 | | |
364 | 388 | | |
365 | 389 | | |
366 | | - | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
367 | 394 | | |
368 | 395 | | |
369 | 396 | | |
| |||
385 | 412 | | |
386 | 413 | | |
387 | 414 | | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
388 | 418 | | |
389 | 419 | | |
390 | 420 | | |
| |||
400 | 430 | | |
401 | 431 | | |
402 | 432 | | |
| 433 | + | |
403 | 434 | | |
404 | 435 | | |
405 | 436 | | |
406 | 437 | | |
407 | 438 | | |
| 439 | + | |
408 | 440 | | |
409 | 441 | | |
410 | 442 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
| |||
290 | 292 | | |
291 | 293 | | |
292 | 294 | | |
| 295 | + | |
| 296 | + | |
293 | 297 | | |
294 | 298 | | |
295 | 299 | | |
| |||
627 | 631 | | |
628 | 632 | | |
629 | 633 | | |
| 634 | + | |
| 635 | + | |
630 | 636 | | |
631 | 637 | | |
632 | 638 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
95 | 99 | | |
96 | 100 | | |
97 | 101 | | |
| |||
122 | 126 | | |
123 | 127 | | |
124 | 128 | | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
125 | 132 | | |
126 | 133 | | |
127 | 134 | | |
| |||
Lines changed: 164 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
0 commit comments