agent-working-memory 0.11.0 → 0.12.3
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 +71 -297
- package/dist/adapters/claude-code.d.ts.map +1 -1
- package/dist/adapters/claude-code.js +63 -3
- package/dist/adapters/claude-code.js.map +1 -1
- package/dist/adapters/common.d.ts.map +1 -1
- package/dist/adapters/common.js +358 -306
- package/dist/adapters/common.js.map +1 -1
- package/dist/api/routes.d.ts.map +1 -1
- package/dist/api/routes.js +29 -7
- package/dist/api/routes.js.map +1 -1
- package/dist/coordination/routes.d.ts.map +1 -1
- package/dist/coordination/routes.js +174 -170
- package/dist/coordination/routes.js.map +1 -1
- package/dist/core/embeddings.d.ts.map +1 -1
- package/dist/core/embeddings.js +4 -1
- package/dist/core/embeddings.js.map +1 -1
- package/dist/core/entity-extract.d.ts +3 -0
- package/dist/core/entity-extract.d.ts.map +1 -0
- package/dist/core/entity-extract.js +47 -0
- package/dist/core/entity-extract.js.map +1 -0
- package/dist/core/format-recall.d.ts +16 -0
- package/dist/core/format-recall.d.ts.map +1 -0
- package/dist/core/format-recall.js +24 -0
- package/dist/core/format-recall.js.map +1 -0
- package/dist/core/query-expander.js +1 -1
- package/dist/core/query-expander.js.map +1 -1
- package/dist/core/reranker.js +1 -1
- package/dist/core/reranker.js.map +1 -1
- package/dist/core/salience.d.ts.map +1 -1
- package/dist/core/salience.js +14 -2
- package/dist/core/salience.js.map +1 -1
- package/dist/core/whoami.d.ts +24 -0
- package/dist/core/whoami.d.ts.map +1 -0
- package/dist/core/whoami.js +66 -0
- package/dist/core/whoami.js.map +1 -0
- package/dist/core/write-pipeline.d.ts +9 -0
- package/dist/core/write-pipeline.d.ts.map +1 -1
- package/dist/core/write-pipeline.js +109 -68
- package/dist/core/write-pipeline.js.map +1 -1
- package/dist/core/write-telemetry.d.ts +33 -0
- package/dist/core/write-telemetry.d.ts.map +1 -0
- package/dist/core/write-telemetry.js +110 -0
- package/dist/core/write-telemetry.js.map +1 -0
- package/dist/engine/activation.d.ts +22 -12
- package/dist/engine/activation.d.ts.map +1 -1
- package/dist/engine/activation.js +133 -17
- package/dist/engine/activation.js.map +1 -1
- package/dist/engine/consolidation-scheduler.d.ts +1 -1
- package/dist/engine/consolidation-scheduler.js +1 -1
- package/dist/engine/consolidation.d.ts +1 -0
- package/dist/engine/consolidation.d.ts.map +1 -1
- package/dist/engine/consolidation.js +18 -0
- package/dist/engine/consolidation.js.map +1 -1
- package/dist/engine/eval.d.ts.map +1 -1
- package/dist/engine/eval.js +5 -1
- package/dist/engine/eval.js.map +1 -1
- package/dist/hooks/sidecar.d.ts +26 -0
- package/dist/hooks/sidecar.d.ts.map +1 -1
- package/dist/hooks/sidecar.js +30 -0
- package/dist/hooks/sidecar.js.map +1 -1
- package/dist/index.js +20 -2
- package/dist/index.js.map +1 -1
- package/dist/mcp.d.ts +2 -1
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +222 -108
- package/dist/mcp.js.map +1 -1
- package/dist/recipes/index.d.ts +57 -0
- package/dist/recipes/index.d.ts.map +1 -0
- package/dist/recipes/index.js +81 -0
- package/dist/recipes/index.js.map +1 -0
- package/dist/storage/pglite-schema.d.ts.map +1 -1
- package/dist/storage/pglite-schema.js +27 -0
- package/dist/storage/pglite-schema.js.map +1 -1
- package/dist/storage/pglite.d.ts +5 -0
- package/dist/storage/pglite.d.ts.map +1 -1
- package/dist/storage/pglite.js +180 -138
- package/dist/storage/pglite.js.map +1 -1
- package/dist/storage/postgres.d.ts +5 -0
- package/dist/storage/postgres.d.ts.map +1 -1
- package/dist/storage/postgres.js +180 -138
- package/dist/storage/postgres.js.map +1 -1
- package/dist/storage/sqlite.d.ts +9 -0
- package/dist/storage/sqlite.d.ts.map +1 -1
- package/dist/storage/sqlite.js +394 -326
- package/dist/storage/sqlite.js.map +1 -1
- package/dist/types/engram.d.ts +14 -0
- package/dist/types/engram.d.ts.map +1 -1
- package/dist/types/engram.js.map +1 -1
- package/package.json +1 -1
- package/src/adapters/claude-code.ts +66 -3
- package/src/adapters/common.ts +567 -515
- package/src/api/routes.ts +999 -971
- package/src/coordination/routes.ts +2155 -2150
- package/src/core/embeddings.ts +4 -1
- package/src/core/entity-extract.ts +47 -0
- package/src/core/format-recall.ts +25 -0
- package/src/core/query-expander.ts +1 -1
- package/src/core/reranker.ts +1 -1
- package/src/core/salience.ts +529 -514
- package/src/core/whoami.ts +92 -0
- package/src/core/write-pipeline.ts +60 -8
- package/src/core/write-telemetry.ts +131 -0
- package/src/engine/activation.ts +1468 -1369
- package/src/engine/consolidation-scheduler.ts +1 -1
- package/src/engine/consolidation.ts +887 -869
- package/src/engine/eval.ts +6 -1
- package/src/hooks/sidecar.ts +55 -0
- package/src/index.ts +248 -227
- package/src/mcp.ts +1387 -1270
- package/src/recipes/index.ts +125 -0
- package/src/storage/pglite-schema.ts +27 -0
- package/src/storage/pglite.ts +1420 -1372
- package/src/storage/postgres.ts +1523 -1475
- package/src/storage/sqlite.ts +1936 -1861
- package/src/types/engram.ts +22 -0
package/dist/adapters/common.js
CHANGED
|
@@ -164,311 +164,363 @@ export function upsertAwmSection(filePath, newContent, options = {}) {
|
|
|
164
164
|
writeFileSync(filePath, rebuilt);
|
|
165
165
|
return `${fname}: AWM section updated (preserved surrounding content)`;
|
|
166
166
|
}
|
|
167
|
-
export const AWM_INSTRUCTION_CONTENT = `
|
|
168
|
-
## Memory (AWM) — MANDATORY
|
|
169
|
-
|
|
170
|
-
**AWM is THE memory system.** Use it via the \`agent-working-memory\` MCP server
|
|
171
|
-
(preferred) or HTTP at \`http://127.0.0.1:8400\` (fallback). The file-based
|
|
172
|
-
auto-memory at \`~/.claude/projects/.../memory/*.md\` is a LEGACY bootstrap path —
|
|
173
|
-
**do not write new memories to it.** All persistent knowledge goes through AWM.
|
|
174
|
-
|
|
175
|
-
If MCP tools aren't loaded at session start, use ToolSearch with
|
|
176
|
-
\`select:mcp__agent-working-memory__memory_recall,mcp__agent-working-memory__memory_write\`
|
|
177
|
-
to load them. If the MCP server isn't responsive, restart with \`/mcp\` or use
|
|
178
|
-
the HTTP endpoints (\`POST /memory/write-batch\`, \`POST /memory/activate\`)
|
|
179
|
-
directly — but **DO NOT fall back to markdown files**. Files drift the moment
|
|
180
|
-
you write them; AWM stays current because every agent reads + writes the same store.
|
|
181
|
-
|
|
182
|
-
### Lifecycle (always do these, in this order)
|
|
183
|
-
1. **Session start**: call \`memory_restore\` to recover previous context. If it reports the
|
|
184
|
-
store is empty/new (or recall keeps returning nothing), **warm-start first**: recall the
|
|
185
|
-
\`onboard a new project\` skill and follow it — or call \`onboard_scan\` on the project's
|
|
186
|
-
docs/repo, refine the candidates, run \`onboard_questions\`, and save the good ones with
|
|
187
|
-
\`memory_write\` (canonical). A cold store is nearly useless until it's seeded.
|
|
188
|
-
2. **Starting a task**: call \`memory_task_begin\` (checkpoints + recalls relevant memories).
|
|
189
|
-
3. **During work**: call \`memory_recall\` BEFORE stating any fact, BEFORE searching
|
|
190
|
-
the filesystem, BEFORE making architectural decisions. Recall is ~300ms — cheaper
|
|
191
|
-
than one filesystem search.
|
|
192
|
-
4. **As you learn things**: call \`memory_write\` proactively. Don't batch.
|
|
193
|
-
5. **Finishing a task**: call \`memory_task_end\` with a summary.
|
|
194
|
-
6. **Auto-checkpoint** is handled by hooks (compaction, session-end, 15-min timer). No action needed.
|
|
195
|
-
|
|
196
|
-
### Write memory when:
|
|
197
|
-
- A project decision is made or changed
|
|
198
|
-
- A root cause is discovered after debugging
|
|
199
|
-
- A reusable implementation pattern is established
|
|
200
|
-
- A user preference, constraint, or requirement is clarified
|
|
201
|
-
- A prior assumption is found to be wrong
|
|
202
|
-
- A significant piece of work is completed
|
|
203
|
-
|
|
204
|
-
### Writing for recall (the highest-leverage section)
|
|
205
|
-
A memory's recall quality is set the moment you write it. AWM is fast at
|
|
206
|
-
finding what's findable — but if the write is shaped wrong, no retriever
|
|
207
|
-
can rescue it. Be slightly more verbose at the front than feels natural:
|
|
208
|
-
the first 1-2 sentences are what BM25, the embedding model, and concept
|
|
209
|
-
extraction all see most strongly.
|
|
210
|
-
|
|
211
|
-
- **Lead with the rule or fact.** Don't open with context or backstory.
|
|
212
|
-
"Don't mock the database in integration tests." comes first; the reason
|
|
213
|
-
comes second. Recall scans the head of the body, not the tail.
|
|
214
|
-
- **Pick the most specific topic.** Not \`auth\` — \`auth-magic-link-rate-limit\`.
|
|
215
|
-
Topic is a hard filter at recall time. Generic topics hide the memory in
|
|
216
|
-
a noisy bucket where it competes with everything else in the area.
|
|
217
|
-
- **Include 2+ retrievable identifiers.** File paths, function names, table
|
|
218
|
-
columns, ticket IDs, exact error strings, the literal terms a future query
|
|
219
|
-
will use. \`AccountingService.closePeriod()\` beats "the accounting code."
|
|
220
|
-
\`tblMemberDetails.activation_date\` beats "the activation column."
|
|
221
|
-
\`schema/072-period-close.sql\` beats "the migration."
|
|
222
|
-
- **Write in the vocabulary of the future question.** When you imagine asking
|
|
223
|
-
this in three months, what nouns will you use? Use those nouns. Don't
|
|
224
|
-
paraphrase the user's domain language into your own neutral summary.
|
|
225
|
-
- **Reserve canonical for stable invariants.** Decisions, requirements,
|
|
226
|
-
hard facts, cross-agent shared context. Working class (default) is correct
|
|
227
|
-
for findings, observations, and progress notes. The canonical floor is
|
|
228
|
-
0.7 salience — overusing it pollutes the canonical layer and the floor
|
|
229
|
-
loses meaning.
|
|
230
|
-
- **Include the why for feedback memories.** A rule without a reason can't
|
|
231
|
-
be applied to edge cases. "Don't mock the database" is brittle. "Don't
|
|
232
|
-
mock the database — last quarter mocked tests masked a broken migration"
|
|
233
|
-
is portable to new situations.
|
|
234
|
-
|
|
235
|
-
### Tagging rules (REQUIRED — AWM's prefix-tag retrieval boost depends on these)
|
|
236
|
-
|
|
237
|
-
Every \`memory_write\` should pass these structured fields. AWM stores each as a
|
|
238
|
-
prefix-tag like \`proj=\`, \`topic=\`, \`intent=\`, etc. and uses them for BM25
|
|
239
|
-
and entity-bridge boosts at recall time.
|
|
240
|
-
|
|
241
|
-
| Field | Required? | Format | Example |
|
|
242
|
-
|---|---|---|---|
|
|
243
|
-
| \`project\` | **YES** | one short word matching the current project | \`"EquiHub"\`, \`"AWM"\`, \`"USEA-Agent"\` |
|
|
244
|
-
| \`topic\` | **YES** | one or more lowercase area words | \`"database-migration"\`, \`"benchmarks"\` |
|
|
245
|
-
| \`intent\` | **YES** | one of: \`decision\` / \`finding\` / \`todo\` / \`question\` / \`context\` | \`"finding"\` |
|
|
246
|
-
| \`confidence_level\` | **YES** | \`verified\` (tested) / \`observed\` (read in code) / \`assumed\` (reasoning) | \`"verified"\` |
|
|
247
|
-
| \`source\` | recommended | \`code-reading\` / \`debugging\` / \`discussion\` / \`research\` / \`testing\` / \`observation\` | \`"testing"\` |
|
|
248
|
-
| \`memory_class\` | when stable | \`canonical\` (source-of-truth, 0.7 floor, never staged) / \`working\` (default) / \`ephemeral\` | \`"canonical"\` |
|
|
249
|
-
| \`session_id\` | recommended | current conversation ID for entity-bridge boost | autogenerated |
|
|
250
|
-
| \`tags\` | when applicable | extra prefix-tags for IDs and dates | \`["ticket=18360", "date=2026-05-11"]\` |
|
|
251
|
-
|
|
252
|
-
**Always add identifier tags when present in the content:**
|
|
253
|
-
- \`ticket=<id>\` for Freshdesk tickets
|
|
254
|
-
- \`member=<id>\` for member IDs
|
|
255
|
-
- \`horse=<id>\` for horse_member_id
|
|
256
|
-
- \`usef=<id>\` for USEF lookups
|
|
257
|
-
- \`date=YYYY-MM-DD\` for temporal anchoring (ISO format)
|
|
258
|
-
- \`person=<Name>\` for stakeholder quotes / decisions
|
|
259
|
-
- \`version=<X.Y.Z>\` for release-specific findings
|
|
260
|
-
|
|
261
|
-
###
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
167
|
+
export const AWM_INSTRUCTION_CONTENT = `
|
|
168
|
+
## Memory (AWM) — MANDATORY
|
|
169
|
+
|
|
170
|
+
**AWM is THE memory system.** Use it via the \`agent-working-memory\` MCP server
|
|
171
|
+
(preferred) or HTTP at \`http://127.0.0.1:8400\` (fallback). The file-based
|
|
172
|
+
auto-memory at \`~/.claude/projects/.../memory/*.md\` is a LEGACY bootstrap path —
|
|
173
|
+
**do not write new memories to it.** All persistent knowledge goes through AWM.
|
|
174
|
+
|
|
175
|
+
If MCP tools aren't loaded at session start, use ToolSearch with
|
|
176
|
+
\`select:mcp__agent-working-memory__memory_recall,mcp__agent-working-memory__memory_write\`
|
|
177
|
+
to load them. If the MCP server isn't responsive, restart with \`/mcp\` or use
|
|
178
|
+
the HTTP endpoints (\`POST /memory/write-batch\`, \`POST /memory/activate\`)
|
|
179
|
+
directly — but **DO NOT fall back to markdown files**. Files drift the moment
|
|
180
|
+
you write them; AWM stays current because every agent reads + writes the same store.
|
|
181
|
+
|
|
182
|
+
### Lifecycle (always do these, in this order)
|
|
183
|
+
1. **Session start**: call \`memory_restore\` to recover previous context. If it reports the
|
|
184
|
+
store is empty/new (or recall keeps returning nothing), **warm-start first**: recall the
|
|
185
|
+
\`onboard a new project\` skill and follow it — or call \`onboard_scan\` on the project's
|
|
186
|
+
docs/repo, refine the candidates, run \`onboard_questions\`, and save the good ones with
|
|
187
|
+
\`memory_write\` (canonical). A cold store is nearly useless until it's seeded.
|
|
188
|
+
2. **Starting a task**: call \`memory_task_begin\` (checkpoints + recalls relevant memories).
|
|
189
|
+
3. **During work**: call \`memory_recall\` BEFORE stating any fact, BEFORE searching
|
|
190
|
+
the filesystem, BEFORE making architectural decisions. Recall is ~300ms — cheaper
|
|
191
|
+
than one filesystem search.
|
|
192
|
+
4. **As you learn things**: call \`memory_write\` proactively. Don't batch.
|
|
193
|
+
5. **Finishing a task**: call \`memory_task_end\` with a summary.
|
|
194
|
+
6. **Auto-checkpoint** is handled by hooks (compaction, session-end, 15-min timer). No action needed.
|
|
195
|
+
|
|
196
|
+
### Write memory when:
|
|
197
|
+
- A project decision is made or changed
|
|
198
|
+
- A root cause is discovered after debugging
|
|
199
|
+
- A reusable implementation pattern is established
|
|
200
|
+
- A user preference, constraint, or requirement is clarified
|
|
201
|
+
- A prior assumption is found to be wrong
|
|
202
|
+
- A significant piece of work is completed
|
|
203
|
+
|
|
204
|
+
### Writing for recall (the highest-leverage section)
|
|
205
|
+
A memory's recall quality is set the moment you write it. AWM is fast at
|
|
206
|
+
finding what's findable — but if the write is shaped wrong, no retriever
|
|
207
|
+
can rescue it. Be slightly more verbose at the front than feels natural:
|
|
208
|
+
the first 1-2 sentences are what BM25, the embedding model, and concept
|
|
209
|
+
extraction all see most strongly.
|
|
210
|
+
|
|
211
|
+
- **Lead with the rule or fact.** Don't open with context or backstory.
|
|
212
|
+
"Don't mock the database in integration tests." comes first; the reason
|
|
213
|
+
comes second. Recall scans the head of the body, not the tail.
|
|
214
|
+
- **Pick the most specific topic.** Not \`auth\` — \`auth-magic-link-rate-limit\`.
|
|
215
|
+
Topic is a hard filter at recall time. Generic topics hide the memory in
|
|
216
|
+
a noisy bucket where it competes with everything else in the area.
|
|
217
|
+
- **Include 2+ retrievable identifiers.** File paths, function names, table
|
|
218
|
+
columns, ticket IDs, exact error strings, the literal terms a future query
|
|
219
|
+
will use. \`AccountingService.closePeriod()\` beats "the accounting code."
|
|
220
|
+
\`tblMemberDetails.activation_date\` beats "the activation column."
|
|
221
|
+
\`schema/072-period-close.sql\` beats "the migration."
|
|
222
|
+
- **Write in the vocabulary of the future question.** When you imagine asking
|
|
223
|
+
this in three months, what nouns will you use? Use those nouns. Don't
|
|
224
|
+
paraphrase the user's domain language into your own neutral summary.
|
|
225
|
+
- **Reserve canonical for stable invariants.** Decisions, requirements,
|
|
226
|
+
hard facts, cross-agent shared context. Working class (default) is correct
|
|
227
|
+
for findings, observations, and progress notes. The canonical floor is
|
|
228
|
+
0.7 salience — overusing it pollutes the canonical layer and the floor
|
|
229
|
+
loses meaning.
|
|
230
|
+
- **Include the why for feedback memories.** A rule without a reason can't
|
|
231
|
+
be applied to edge cases. "Don't mock the database" is brittle. "Don't
|
|
232
|
+
mock the database — last quarter mocked tests masked a broken migration"
|
|
233
|
+
is portable to new situations.
|
|
234
|
+
|
|
235
|
+
### Tagging rules (REQUIRED — AWM's prefix-tag retrieval boost depends on these)
|
|
236
|
+
|
|
237
|
+
Every \`memory_write\` should pass these structured fields. AWM stores each as a
|
|
238
|
+
prefix-tag like \`proj=\`, \`topic=\`, \`intent=\`, etc. and uses them for BM25
|
|
239
|
+
and entity-bridge boosts at recall time.
|
|
240
|
+
|
|
241
|
+
| Field | Required? | Format | Example |
|
|
242
|
+
|---|---|---|---|
|
|
243
|
+
| \`project\` | **YES** | one short word matching the current project | \`"EquiHub"\`, \`"AWM"\`, \`"USEA-Agent"\` |
|
|
244
|
+
| \`topic\` | **YES** | one or more lowercase area words | \`"database-migration"\`, \`"benchmarks"\` |
|
|
245
|
+
| \`intent\` | **YES** | one of: \`decision\` / \`finding\` / \`todo\` / \`question\` / \`context\` | \`"finding"\` |
|
|
246
|
+
| \`confidence_level\` | **YES** | \`verified\` (tested) / \`observed\` (read in code) / \`assumed\` (reasoning) | \`"verified"\` |
|
|
247
|
+
| \`source\` | recommended | \`code-reading\` / \`debugging\` / \`discussion\` / \`research\` / \`testing\` / \`observation\` | \`"testing"\` |
|
|
248
|
+
| \`memory_class\` | when stable | \`canonical\` (source-of-truth, 0.7 floor, never staged) / \`working\` (default) / \`ephemeral\` | \`"canonical"\` |
|
|
249
|
+
| \`session_id\` | recommended | current conversation ID for entity-bridge boost | autogenerated |
|
|
250
|
+
| \`tags\` | when applicable | extra prefix-tags for IDs and dates | \`["ticket=18360", "date=2026-05-11"]\` |
|
|
251
|
+
|
|
252
|
+
**Always add identifier tags when present in the content:**
|
|
253
|
+
- \`ticket=<id>\` for Freshdesk tickets
|
|
254
|
+
- \`member=<id>\` for member IDs
|
|
255
|
+
- \`horse=<id>\` for horse_member_id
|
|
256
|
+
- \`usef=<id>\` for USEF lookups
|
|
257
|
+
- \`date=YYYY-MM-DD\` for temporal anchoring (ISO format)
|
|
258
|
+
- \`person=<Name>\` for stakeholder quotes / decisions
|
|
259
|
+
- \`version=<X.Y.Z>\` for release-specific findings
|
|
260
|
+
|
|
261
|
+
### Entity index — exact-match recall for named things (default off)
|
|
262
|
+
Structured identifier tags (\`ticket=\`, \`person=\`, \`horse=\`, \`member=\`, bare 4+ digit
|
|
263
|
+
ids, etc.) feed a dedicated entity inverted index, separate from BM25/embedding scoring.
|
|
264
|
+
A query naming an entity ("ticket 19252", "Kaleigh Collett") can reach the memory through
|
|
265
|
+
this index even when the wording doesn't lexically match — it's a deterministic exact
|
|
266
|
+
lookup, immune to vocabulary mismatch. Keep identifier tags exact and consistent for
|
|
267
|
+
this reason, not just for the BM25 boost described above.
|
|
268
|
+
|
|
269
|
+
Off by default; opt in with \`AWM_ENTITY_INDEX_FETCH=1\` (bounded by
|
|
270
|
+
\`AWM_ENTITY_INDEX_CAP\`, default 12). Matched entities get no score boost — they're
|
|
271
|
+
guaranteed a reranker audition instead, so the cross-encoder alone decides whether they
|
|
272
|
+
surface. Worth trialing on identifier-heavy workloads (ticket/event numbers, named
|
|
273
|
+
people/things you refer to by name often); not yet the default pending evaluation.
|
|
274
|
+
|
|
275
|
+
### Temporal validity — memories that expire or start in the future
|
|
276
|
+
\`memory_write\` accepts \`valid_from\` / \`valid_to\` (ISO dates). Use \`valid_to\` on
|
|
277
|
+
**operational** facts with a real shelf life — a deploy state, "waiting on X's reply",
|
|
278
|
+
a ticket status — so the memory expires instead of relying on you to remember it's
|
|
279
|
+
stale. Recall renders \`[valid until …]\` on results carrying this field. Use
|
|
280
|
+
\`valid_from\` for a fact that becomes true on a known future date (a policy change, a
|
|
281
|
+
season that hasn't started yet). Don't set either for durable facts — most memories
|
|
282
|
+
don't need them.
|
|
283
|
+
|
|
284
|
+
### Memory classes (controls how strictly the salience filter gates the write)
|
|
285
|
+
- \`memory_class: canonical\` — source-of-truth memories. Floor 0.7 salience, never staged.
|
|
286
|
+
Use for: user-stated decisions, project requirements, verified architectural facts,
|
|
287
|
+
cross-agent shared context. **In a hive (multi-agent) setup, always use \`canonical\`
|
|
288
|
+
for writes that other agents must be able to recall** — the default \`working\` class
|
|
289
|
+
may get filtered.
|
|
290
|
+
- \`memory_class: working\` (default) — observations and findings. Salience-gated.
|
|
291
|
+
- \`memory_class: ephemeral\` — short-lived context that should decay quickly.
|
|
292
|
+
|
|
293
|
+
### Salience auto-promotion (defense in depth)
|
|
294
|
+
The salience filter automatically promotes certain content patterns even if you forget
|
|
295
|
+
to set \`memory_class\` explicitly:
|
|
296
|
+
- **User feedback** — content starting with "Robert said…", "Katherine directed…",
|
|
297
|
+
"Nancy decided…" etc. auto-promotes to canonical. So quoting the user verbatim
|
|
298
|
+
always preserves the decision.
|
|
299
|
+
- **Verified operational records** — content with an action verb (Submitted, Finalized,
|
|
300
|
+
Completed, Reconciled, Triaged, Posted, Resolved, Stamped, Pushed, Deployed, Migrated,
|
|
301
|
+
Imported, Exported, Backfilled) plus 2+ concrete identifiers (ISO date \`YYYY-MM-DD\`,
|
|
302
|
+
or contextual numeric IDs like "event 18969", "ticket #18330", "USEF 341980") gets
|
|
303
|
+
a 0.45 salience floor. So batch summaries with real IDs survive even when topic
|
|
304
|
+
terms repeat.
|
|
305
|
+
|
|
306
|
+
If neither pattern applies and you want a memory to definitely survive, set
|
|
307
|
+
\`memory_class: canonical\` explicitly. Don't rely on auto-promotion for important writes.
|
|
308
|
+
|
|
309
|
+
### Recall memory when:
|
|
310
|
+
- **BEFORE stating ANY fact about how a system works** — recall first; if AWM doesn't
|
|
311
|
+
have it, read the code. Never guess and present it as fact.
|
|
312
|
+
- **BEFORE searching the filesystem** — recall first; AWM is faster and has cross-session
|
|
313
|
+
knowledge that file search doesn't.
|
|
314
|
+
- Starting work on a new task or subsystem
|
|
315
|
+
- Re-entering code you haven't touched recently
|
|
316
|
+
- After a failed attempt — check if there's prior knowledge
|
|
317
|
+
- Before refactoring or making architectural changes
|
|
318
|
+
- When a topic comes up that you might have prior context on
|
|
319
|
+
|
|
320
|
+
Recall is fast (~300ms typical). Use it freely.
|
|
321
|
+
|
|
322
|
+
### Recall strategy (when one query isn't enough)
|
|
323
|
+
AWM's adaptive retrieval handles most query variations natively — synonym
|
|
324
|
+
expansion, multi-channel scoring, embedding + BM25 + reranker agreement.
|
|
325
|
+
A single recall is usually enough.
|
|
326
|
+
|
|
327
|
+
When it isn't:
|
|
328
|
+
- **If the first recall returns nothing or returns the wrong things, reformulate.**
|
|
329
|
+
Try a second query with different phrasing — synonyms, more specific nouns,
|
|
330
|
+
the exact identifier from the code rather than the conceptual name. Two or
|
|
331
|
+
three recalls cost less than one filesystem search.
|
|
332
|
+
- **Use the words a domain expert would use, not generic English.** "Period
|
|
333
|
+
close lock" not "accounting feature"; "magic link rate limit" not "auth issue."
|
|
334
|
+
- **For broad exploration, pass \`mode: "exploratory"\`** — wider candidate
|
|
335
|
+
pool, lower precision floor. For specific lookups, leave mode unset (auto).
|
|
336
|
+
- **Don't ensemble more than 3 reformulations.** If three different phrasings
|
|
337
|
+
return nothing, the memory probably isn't there — read the code instead of
|
|
338
|
+
burning more recalls.
|
|
339
|
+
|
|
340
|
+
### Recall tuning (0.8.x — opt-in parameters for higher-quality recall)
|
|
341
|
+
Default \`memory_recall\` is tuned for the common case. The 0.8.x recall pipeline
|
|
342
|
+
exposes four opt-in parameters that change the cost/quality tradeoff. Use them
|
|
343
|
+
when the default doesn't match what you actually need.
|
|
344
|
+
|
|
345
|
+
- **\`granularity: 'compact'\`** — every result carries a 200-char \`summary\`
|
|
346
|
+
field with a query-aware snippet (the densest window of query terms in the
|
|
347
|
+
content). Use this when you expect to scan 5+ results to find one — saves
|
|
348
|
+
~70% of recall output tokens. The full content stays available in
|
|
349
|
+
\`engram.content\` if you want to drill into a specific result.
|
|
350
|
+
- **\`granularity: 'auto'\`** — confidence-adaptive. If the top result is a clear
|
|
351
|
+
winner, it gets a longer summary while the rest are compact. If confidence
|
|
352
|
+
is uniform across results, everything is compact. Use when you don't know
|
|
353
|
+
in advance whether one result will dominate.
|
|
354
|
+
- **\`require_confidence: 0.10 | 0.25 | 0.40\`** — opt-in abstention. AWM
|
|
355
|
+
returns \`[]\` instead of low-confidence noise. Use when you're about to ACT
|
|
356
|
+
on the recalled fact (grounding a decision, citing the memory verbatim,
|
|
357
|
+
contradicting a prior assumption). Thresholds: \`0.10\` strict — only abstain
|
|
358
|
+
on garbage; \`0.25\` balanced; \`0.40\` aggressive — prefer "I don't know"
|
|
359
|
+
over "best of bad." When abstention fires (empty result), treat it as a
|
|
360
|
+
signal — either the memory genuinely isn't there (read the code) or your
|
|
361
|
+
query missed (reformulate). Don't retry without the threshold.
|
|
362
|
+
- **\`workspace: "<name>"\`** — hive-mode recall across all agents in the
|
|
363
|
+
workspace. Use when other agents may have written canonical knowledge you
|
|
364
|
+
need. Default is agent-scoped (your own memories only). Can also be set
|
|
365
|
+
globally via the \`AWM_WORKSPACE\` env var.
|
|
366
|
+
|
|
367
|
+
### Keep memory fresh
|
|
368
|
+
- After recalling a memory, if you observe the real state is different → call
|
|
369
|
+
\`memory_supersede\` immediately with the corrected version.
|
|
370
|
+
- After using a recalled memory: call \`memory_feedback\` (useful/not-useful) so the
|
|
371
|
+
activation engine learns what's valuable.
|
|
372
|
+
- If you discover a memory is factually wrong: \`memory_retract\` to remove it.
|
|
373
|
+
- **If you bypass AWM (file-memory, in-context notes, "I'll just remember"), the memory
|
|
374
|
+
drifts out of date. The system relies on you to keep it current. This is the #1
|
|
375
|
+
failure mode.**
|
|
376
|
+
|
|
377
|
+
### Cognition recipes — YOU do the thinking, AWM keeps the result (0.11.x)
|
|
378
|
+
AWM contains no LLM. When memory needs real thinking — distilling a repeatable
|
|
379
|
+
procedure, reflecting on a failure — AWM hands YOU a versioned recipe (prompt +
|
|
380
|
+
strict output shape) and you run it as a SEPARATE focused pass, then write the
|
|
381
|
+
result back as an ordinary memory with provenance.
|
|
382
|
+
|
|
383
|
+
- \`memory_task_end\` responses include the recipe invitations. Honor the gates:
|
|
384
|
+
skill-derivation only after a genuinely procedural task (3+ tool calls or a
|
|
385
|
+
delegated sub-task); friction-lesson only after a failure/retry/wrong assumption.
|
|
386
|
+
- Run each recipe as its own focused pass — do NOT bundle it with other
|
|
387
|
+
reasoning; bundled passes reliably drop the output.
|
|
388
|
+
- Write back exactly per the recipe's contract: \`origin_class: 'recipe'\` +
|
|
389
|
+
\`recipe_id\` (e.g. \`skill-derivation@1\`), concept prefixed \`skill: \` or
|
|
390
|
+
\`lesson: \`. AWM validates the shape and rejects malformed or unknown-recipe
|
|
391
|
+
writes with the contract echoed back — fix and retry, don't drop the insight.
|
|
392
|
+
- Re-deriving the same skill name reinforces the existing memory instead of
|
|
393
|
+
duplicating it, so don't fear writing a skill you may have written before.
|
|
394
|
+
|
|
395
|
+
### Content fade — write-and-forget is safe (0.8.x)
|
|
396
|
+
Un-recalled engrams gradually fade their content while preserving cue pathways
|
|
397
|
+
(concept + tags + embedding stay intact). This is Paper 1 — storage
|
|
398
|
+
degradation. Practical implications:
|
|
399
|
+
|
|
400
|
+
- **Don't manually purge memories** to "save space." The system already
|
|
401
|
+
compresses unused content. Old memories stay findable via cue match even
|
|
402
|
+
when their body has decayed.
|
|
403
|
+
- **Don't over-pin with \`memory_class: canonical\`** to fight fade. Canonical
|
|
404
|
+
only changes salience gating at write time, not fade behavior. Fade
|
|
405
|
+
affects un-recalled engrams of any class.
|
|
406
|
+
- **Recall keeps content alive.** Every recall touches the engram and resets
|
|
407
|
+
its fade clock. Frequently-recalled memories stay full-fidelity automatically.
|
|
408
|
+
- **Supersede is the right tool for stale facts.** When you observe a memory
|
|
409
|
+
is outdated, call \`memory_supersede\` — the new version inherits the old
|
|
410
|
+
one's coherent associations (counter-narrative replacement, 0.8.x) so cue
|
|
411
|
+
pathways carry forward to the replacement.
|
|
412
|
+
|
|
413
|
+
### Example — good vs bad memory_write
|
|
414
|
+
|
|
415
|
+
**BAD** (no prefix tags, vague concept, can't be recalled by future queries):
|
|
416
|
+
\`\`\`
|
|
417
|
+
memory_write(
|
|
418
|
+
concept="found a bug",
|
|
419
|
+
content="The thing I was looking at was broken so I fixed it."
|
|
420
|
+
)
|
|
421
|
+
\`\`\`
|
|
422
|
+
|
|
423
|
+
**GOOD** (rich identifiers, structured metadata, prefix tags):
|
|
424
|
+
\`\`\`
|
|
425
|
+
memory_write(
|
|
426
|
+
concept="EquiHub period-close BLOCKED check missing server-side",
|
|
427
|
+
content="apps/web/app/(accounting)/accounting/period-close/page.tsx had client-only BLOCKED enforcement. Fixed by adding server-side check in AccountingService.closePeriod() per schema/072-period-close.sql. Without server-side check a malicious request could bypass via direct API call.",
|
|
428
|
+
project="EquiHub",
|
|
429
|
+
topic="accounting",
|
|
430
|
+
intent="finding",
|
|
431
|
+
confidence_level="verified",
|
|
432
|
+
source="debugging",
|
|
433
|
+
memory_class="canonical",
|
|
434
|
+
tags=["ticket=18360", "person=Robert", "date=2026-05-11", "topic=period-close", "topic=security"]
|
|
435
|
+
)
|
|
436
|
+
\`\`\`
|
|
437
|
+
|
|
438
|
+
### Also:
|
|
439
|
+
- To track work items: memory_task_add, memory_task_update, memory_task_list, memory_task_next
|
|
440
|
+
- \`memory_whoami\` (MCP tool) / \`GET /whoami\` — identify the instance you're actually
|
|
441
|
+
talking to: agent id, workspace, mode, backend, store path, code provenance, sibling
|
|
442
|
+
agent spaces sharing the store. Call this FIRST whenever you're unsure which store,
|
|
443
|
+
which agent identity, or which running code you're dealing with — before reasoning
|
|
444
|
+
about AWM's own state from a stale memory or an assumed port number.
|
|
445
|
+
- AWM is shared across all agents in real time. When any agent writes or supersedes a
|
|
446
|
+
memory, every other agent can recall it immediately — but only within the same
|
|
447
|
+
workspace and agent scope.
|
|
448
|
+
|
|
449
|
+
### Output compression (token efficiency, output-only)
|
|
450
|
+
When a tool returns a LARGE STRUCTURED result you need to keep in context — a JSON
|
|
451
|
+
array of records, query rows, a log dump, an API response — pass it through
|
|
452
|
+
\`compress_output\` first. It re-encodes the data as TOON (a compact, lossless,
|
|
453
|
+
schema-aware tabular form of JSON), cutting ~50-65% of the tokens at no
|
|
454
|
+
comprehension cost. This is output-only: it never changes the data or your memories.
|
|
455
|
+
- Use it on big STRUCTURED outputs, not on prose. Prose is returned unchanged —
|
|
456
|
+
for trimming memory prose, use recall \`granularity: 'compact'\` instead.
|
|
457
|
+
- It returns a \`ref\`; call \`retrieve_original(ref)\` if you later need the exact
|
|
458
|
+
verbatim source (e.g. to hand it to another tool unchanged).
|
|
459
|
+
- Don't bother for small outputs — it only compresses when the saving is worthwhile
|
|
460
|
+
and falls back to plain JSON if TOON wouldn't reproduce the data exactly.
|
|
461
|
+
|
|
462
|
+
### Backend (SQLite vs PGlite, 0.8.x)
|
|
463
|
+
AWM ships two storage backends. The installer picks SQLite by default; both
|
|
464
|
+
are functionally equivalent for cognitive workloads, but differ in operational
|
|
465
|
+
guarantees:
|
|
466
|
+
|
|
467
|
+
- **SQLite** (default) — embedded, **multi-process safe** via WAL mode. Best
|
|
468
|
+
for single-machine setups and MCP scenarios where multiple Claude Code
|
|
469
|
+
sessions may open the same database concurrently.
|
|
470
|
+
- **PGlite** — embedded Postgres (WASM) with pgvector. **Single-process only**
|
|
471
|
+
— two MCP processes against the same \`memory-pglite/\` directory will
|
|
472
|
+
abort the second. Pick via \`AWM_STORE_BACKEND=pglite\` and
|
|
473
|
+
\`AWM_DB_PATH=path/to/memory-pglite\`.
|
|
474
|
+
- **Auto-detect** — if \`AWM_DB_PATH\` points to a directory that already
|
|
475
|
+
exists, AWM detects PGlite; a file → SQLite. No explicit
|
|
476
|
+
\`AWM_STORE_BACKEND\` needed when an existing DB is present.
|
|
477
|
+
|
|
478
|
+
For the comparison table (recall quality parity, BM25 vs \`ts_rank_cd\`,
|
|
479
|
+
multi-process guarantees), see \`docs/pglite-feature-parity.md\`.
|
|
480
|
+
|
|
481
|
+
### Diagnostics / escape hatches (env vars, only if you know why)
|
|
482
|
+
The 0.7.6→0.7.14 work cut recall latency from 11s to ~300ms. The 0.8.x work
|
|
483
|
+
added the write-path rewrite (per-write 300+ ms → under 10ms) and PGlite
|
|
484
|
+
parity tuning. Each optimization is gated by an env-var so it can be disabled
|
|
485
|
+
for A/B testing if a regression appears in your workload:
|
|
486
|
+
|
|
487
|
+
Recall pipeline (0.7.x):
|
|
488
|
+
- \`AWM_DISABLE_POOL_FILTER=1\` — disables the candidate pool reduction
|
|
489
|
+
pre-filter in recall. Reverts to scoring all active candidates.
|
|
490
|
+
- \`AWM_ENTITY_INDEX_FETCH=1\` — see "Entity index" above (0.12.x, default off).
|
|
491
|
+
- \`AWM_DISABLE_SLIM_CACHE=1\` — disables the in-memory slim cache.
|
|
492
|
+
Reverts to per-recall SQL fetch + Buffer→Float32Array conversion.
|
|
493
|
+
- \`AWM_DISABLE_RERANK_SKIP=1\` — disables the cross-encoder skip on
|
|
494
|
+
clear-winner queries. Forces every recall through the reranker.
|
|
495
|
+
- \`AWM_DISABLE_EXPANSION_CACHE=1\` — disables the query expansion skip
|
|
496
|
+
heuristic + LRU cache. Forces every recall through flan-t5-small.
|
|
497
|
+
|
|
498
|
+
Write pipeline + lifecycle (0.8.x, plus 0.12.x telemetry):
|
|
499
|
+
- \`AWM_SLOW_WRITE_MS=250\` (0.12.x) — any write slower than this logs one stderr
|
|
500
|
+
line with a phase-time breakdown (embed/novelty/persist, event-loop lag,
|
|
501
|
+
embed-model cold-load ms). \`0\` disables. Useful for diagnosing why a session's
|
|
502
|
+
first write/recall feels slow.
|
|
503
|
+
- \`AWM_REINFORCE_MAX_CONTENT_LEN=1500\` — max chars an engram's content
|
|
504
|
+
can grow to via merge-on-reinforce (drop-oldest on overflow). Higher =
|
|
505
|
+
preserves more reinforced detail; lower = leaner recall output.
|
|
506
|
+
- \`AWM_REINFORCE_MERGE_CONTENT=0\` — disable content merge on reinforce.
|
|
507
|
+
Reverts to pre-0.8.5 behavior (discard new content, only bump confidence).
|
|
508
|
+
- \`AWM_NOVELTY_EMBED=0\` — disable the cosine channel in novelty
|
|
509
|
+
computation. BM25-only fallback. Reverts to pre-0.8.5 novelty.
|
|
510
|
+
- \`AWM_GRANULARITY_COMPACT_LEN=200\` — char budget for query-aware snippet
|
|
511
|
+
in \`granularity: 'compact'\` mode.
|
|
512
|
+
- \`AWM_GRANULARITY_FULL_LEN=1000\` — char budget for the top result in
|
|
513
|
+
\`granularity: 'auto'\` mode when there's a clear winner.
|
|
514
|
+
|
|
515
|
+
PGlite backend (0.8.x):
|
|
516
|
+
- \`AWM_PGLITE_BM25_M=1\` — multiplier on PGlite \`ts_rank_cd\` to calibrate
|
|
517
|
+
against SQLite FTS5 BM25 distribution. M=1 (default) is passthrough;
|
|
518
|
+
higher M boosts PGlite scores at the cost of recall-ranking precision
|
|
519
|
+
(see CHANGELOG 0.8.5 follow-up).
|
|
520
|
+
- \`AWM_IVFFLAT_PROBES=5\` — pgvector ivfflat probes per query. Higher =
|
|
521
|
+
more accurate, slower.
|
|
522
|
+
|
|
523
|
+
In production, leave these all unset. Use only when diagnosing a suspected
|
|
524
|
+
recall-quality regression.
|
|
473
525
|
`.trimStart();
|
|
474
526
|
//# sourceMappingURL=common.js.map
|