agent-working-memory 0.8.5 → 0.8.7

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 (53) hide show
  1. package/README.md +4 -2
  2. package/dist/adapters/common.d.ts.map +1 -1
  3. package/dist/adapters/common.js +108 -8
  4. package/dist/adapters/common.js.map +1 -1
  5. package/dist/api/routes.js +1 -1
  6. package/dist/cli/migrate.js +29 -29
  7. package/dist/cli.js +1 -1
  8. package/dist/coordination/circuit-breaker.js +23 -23
  9. package/dist/core/lite-compress.d.ts +26 -0
  10. package/dist/core/lite-compress.d.ts.map +1 -0
  11. package/dist/core/lite-compress.js +105 -0
  12. package/dist/core/lite-compress.js.map +1 -0
  13. package/dist/mcp.d.ts +5 -1
  14. package/dist/mcp.d.ts.map +1 -1
  15. package/dist/mcp.js +58 -4
  16. package/dist/mcp.js.map +1 -1
  17. package/dist/storage/pglite-schema.js +143 -143
  18. package/dist/storage/pglite.js +138 -138
  19. package/package.json +4 -3
  20. package/src/adapters/common.ts +108 -8
  21. package/src/api/index.ts +3 -3
  22. package/src/api/routes.ts +1 -1
  23. package/src/cli/migrate.ts +307 -307
  24. package/src/cli.ts +1 -1
  25. package/src/coordination/circuit-breaker.ts +83 -83
  26. package/src/coordination/failure-modes.ts +50 -50
  27. package/src/core/decay.ts +63 -63
  28. package/src/core/embeddings.ts +110 -110
  29. package/src/core/index.ts +5 -5
  30. package/src/core/lite-compress.ts +129 -0
  31. package/src/core/logger.ts +36 -36
  32. package/src/core/ml-worker-entry.ts +194 -194
  33. package/src/core/ml-worker.ts +281 -281
  34. package/src/core/query-expander.ts +122 -122
  35. package/src/core/reranker.ts +119 -119
  36. package/src/engine/confidence.ts +120 -120
  37. package/src/engine/connections.ts +162 -162
  38. package/src/engine/consolidation-scheduler.ts +242 -242
  39. package/src/engine/eval.ts +102 -102
  40. package/src/engine/eviction.ts +101 -101
  41. package/src/engine/index.ts +8 -8
  42. package/src/engine/retraction.ts +366 -366
  43. package/src/engine/staging.ts +74 -74
  44. package/src/mcp.ts +70 -4
  45. package/src/storage/factory.ts +147 -147
  46. package/src/storage/index.ts +3 -3
  47. package/src/storage/pglite-schema.ts +166 -166
  48. package/src/storage/pglite.ts +1363 -1363
  49. package/src/storage/store.ts +80 -80
  50. package/src/types/agent.ts +67 -67
  51. package/src/types/checkpoint.ts +46 -46
  52. package/src/types/eval.ts +100 -100
  53. package/src/types/index.ts +6 -6
package/README.md CHANGED
@@ -29,7 +29,7 @@ npm install -g agent-working-memory
29
29
  awm setup --global
30
30
  ```
31
31
 
32
- Restart Claude Code. That's it — 14 memory tools appear automatically.
32
+ Restart Claude Code. That's it — 16 memory tools appear automatically.
33
33
 
34
34
  ### Upgrading
35
35
 
@@ -142,7 +142,7 @@ All evals are reproducible. See [Testing & Evaluation](#testing--evaluation).
142
142
 
143
143
  ## Features
144
144
 
145
- ### Memory Tools (14)
145
+ ### Memory Tools (16)
146
146
 
147
147
  | Tool | Purpose |
148
148
  |------|---------|
@@ -160,6 +160,8 @@ All evals are reproducible. See [Testing & Evaluation](#testing--evaluation).
160
160
  | `memory_task_next` | Get the highest-priority actionable task |
161
161
  | `memory_task_begin` | Start a task — auto-checkpoints and recalls context |
162
162
  | `memory_task_end` | End a task — writes summary and checkpoints |
163
+ | `compress_output` | Encode a structured tool output as TOON — ~50-65% fewer tokens, lossless, output-only |
164
+ | `retrieve_original` | Get the verbatim source back for a `compress_output` ref |
163
165
 
164
166
  ### Separate Memory Pools
165
167
 
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/adapters/common.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAK/C,gEAAgE;AAChE,wBAAgB,kBAAkB,IAAI,MAAM,CAG3C;AAED,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,G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E,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAOnF;AAED,8CAA8C;AAC9C,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAUxD;AAED,8DAA8D;AAC9D,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,OAAO,GACjB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOxB;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,YAAY,GAAG;IACpD,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,CAkBA;AAED,uDAAuD;AACvD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,YAAY,CA6Bf;AAED,sBAAsB;AACtB,wBAAgB,OAAO,IAAI,MAAM,CAEhC;AAID;;;GAGG;AACH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO,GACrD,MAAM,CA8CR;AAED,eAAO,MAAM,uBAAuB,QA8SvB,CAAC"}
@@ -310,6 +310,33 @@ When it isn't:
310
310
  return nothing, the memory probably isn't there — read the code instead of
311
311
  burning more recalls.
312
312
 
313
+ ### Recall tuning (0.8.x — opt-in parameters for higher-quality recall)
314
+ Default \`memory_recall\` is tuned for the common case. The 0.8.x recall pipeline
315
+ exposes four opt-in parameters that change the cost/quality tradeoff. Use them
316
+ when the default doesn't match what you actually need.
317
+
318
+ - **\`granularity: 'compact'\`** — every result carries a 200-char \`summary\`
319
+ field with a query-aware snippet (the densest window of query terms in the
320
+ content). Use this when you expect to scan 5+ results to find one — saves
321
+ ~70% of recall output tokens. The full content stays available in
322
+ \`engram.content\` if you want to drill into a specific result.
323
+ - **\`granularity: 'auto'\`** — confidence-adaptive. If the top result is a clear
324
+ winner, it gets a longer summary while the rest are compact. If confidence
325
+ is uniform across results, everything is compact. Use when you don't know
326
+ in advance whether one result will dominate.
327
+ - **\`require_confidence: 0.10 | 0.25 | 0.40\`** — opt-in abstention. AWM
328
+ returns \`[]\` instead of low-confidence noise. Use when you're about to ACT
329
+ on the recalled fact (grounding a decision, citing the memory verbatim,
330
+ contradicting a prior assumption). Thresholds: \`0.10\` strict — only abstain
331
+ on garbage; \`0.25\` balanced; \`0.40\` aggressive — prefer "I don't know"
332
+ over "best of bad." When abstention fires (empty result), treat it as a
333
+ signal — either the memory genuinely isn't there (read the code) or your
334
+ query missed (reformulate). Don't retry without the threshold.
335
+ - **\`workspace: "<name>"\`** — hive-mode recall across all agents in the
336
+ workspace. Use when other agents may have written canonical knowledge you
337
+ need. Default is agent-scoped (your own memories only). Can also be set
338
+ globally via the \`AWM_WORKSPACE\` env var.
339
+
313
340
  ### Keep memory fresh
314
341
  - After recalling a memory, if you observe the real state is different → call
315
342
  \`memory_supersede\` immediately with the corrected version.
@@ -320,6 +347,24 @@ When it isn't:
320
347
  drifts out of date. The system relies on you to keep it current. This is the #1
321
348
  failure mode.**
322
349
 
350
+ ### Content fade — write-and-forget is safe (0.8.x)
351
+ Un-recalled engrams gradually fade their content while preserving cue pathways
352
+ (concept + tags + embedding stay intact). This is Paper 1 — storage
353
+ degradation. Practical implications:
354
+
355
+ - **Don't manually purge memories** to "save space." The system already
356
+ compresses unused content. Old memories stay findable via cue match even
357
+ when their body has decayed.
358
+ - **Don't over-pin with \`memory_class: canonical\`** to fight fade. Canonical
359
+ only changes salience gating at write time, not fade behavior. Fade
360
+ affects un-recalled engrams of any class.
361
+ - **Recall keeps content alive.** Every recall touches the engram and resets
362
+ its fade clock. Frequently-recalled memories stay full-fidelity automatically.
363
+ - **Supersede is the right tool for stale facts.** When you observe a memory
364
+ is outdated, call \`memory_supersede\` — the new version inherits the old
365
+ one's coherent associations (counter-narrative replacement, 0.8.x) so cue
366
+ pathways carry forward to the replacement.
367
+
323
368
  ### Example — good vs bad memory_write
324
369
 
325
370
  **BAD** (no prefix tags, vague concept, can't be recalled by future queries):
@@ -350,19 +395,74 @@ memory_write(
350
395
  - AWM is shared across all agents in real time. When any agent writes or supersedes a
351
396
  memory, every other agent can recall it immediately.
352
397
 
398
+ ### Output compression (token efficiency, output-only)
399
+ When a tool returns a LARGE STRUCTURED result you need to keep in context — a JSON
400
+ array of records, query rows, a log dump, an API response — pass it through
401
+ \`compress_output\` first. It re-encodes the data as TOON (a compact, lossless,
402
+ schema-aware tabular form of JSON), cutting ~50-65% of the tokens at no
403
+ comprehension cost. This is output-only: it never changes the data or your memories.
404
+ - Use it on big STRUCTURED outputs, not on prose. Prose is returned unchanged —
405
+ for trimming memory prose, use recall \`granularity: 'compact'\` instead.
406
+ - It returns a \`ref\`; call \`retrieve_original(ref)\` if you later need the exact
407
+ verbatim source (e.g. to hand it to another tool unchanged).
408
+ - Don't bother for small outputs — it only compresses when the saving is worthwhile
409
+ and falls back to plain JSON if TOON wouldn't reproduce the data exactly.
410
+
411
+ ### Backend (SQLite vs PGlite, 0.8.x)
412
+ AWM ships two storage backends. The installer picks SQLite by default; both
413
+ are functionally equivalent for cognitive workloads, but differ in operational
414
+ guarantees:
415
+
416
+ - **SQLite** (default) — embedded, **multi-process safe** via WAL mode. Best
417
+ for single-machine setups and MCP scenarios where multiple Claude Code
418
+ sessions may open the same database concurrently.
419
+ - **PGlite** — embedded Postgres (WASM) with pgvector. **Single-process only**
420
+ — two MCP processes against the same \`memory-pglite/\` directory will
421
+ abort the second. Pick via \`AWM_STORE_BACKEND=pglite\` and
422
+ \`AWM_DB_PATH=path/to/memory-pglite\`.
423
+ - **Auto-detect** — if \`AWM_DB_PATH\` points to a directory that already
424
+ exists, AWM detects PGlite; a file → SQLite. No explicit
425
+ \`AWM_STORE_BACKEND\` needed when an existing DB is present.
426
+
427
+ For the comparison table (recall quality parity, BM25 vs \`ts_rank_cd\`,
428
+ multi-process guarantees), see \`docs/pglite-feature-parity.md\`.
429
+
353
430
  ### Diagnostics / escape hatches (env vars, only if you know why)
354
- The 0.7.6→0.7.14 work cut recall latency from 11s to ~300ms. Each optimization
355
- is gated by an env-var so it can be disabled for A/B testing if a regression
356
- appears in your workload:
431
+ The 0.7.6→0.7.14 work cut recall latency from 11s to ~300ms. The 0.8.x work
432
+ added the write-path rewrite (per-write 300+ ms under 10ms) and PGlite
433
+ parity tuning. Each optimization is gated by an env-var so it can be disabled
434
+ for A/B testing if a regression appears in your workload:
357
435
 
358
- - \`AWM_DISABLE_POOL_FILTER=1\` (0.7.7+) — disables the candidate pool reduction
436
+ Recall pipeline (0.7.x):
437
+ - \`AWM_DISABLE_POOL_FILTER=1\` — disables the candidate pool reduction
359
438
  pre-filter in recall. Reverts to scoring all active candidates.
360
- - \`AWM_DISABLE_SLIM_CACHE=1\` (0.7.10+) — disables the in-memory slim cache.
439
+ - \`AWM_DISABLE_SLIM_CACHE=1\` — disables the in-memory slim cache.
361
440
  Reverts to per-recall SQL fetch + Buffer→Float32Array conversion.
362
- - \`AWM_DISABLE_RERANK_SKIP=1\` (0.7.10+) — disables the cross-encoder skip on
441
+ - \`AWM_DISABLE_RERANK_SKIP=1\` — disables the cross-encoder skip on
363
442
  clear-winner queries. Forces every recall through the reranker.
364
- - \`AWM_DISABLE_EXPANSION_CACHE=1\` (0.7.11+) — disables the query expansion
365
- skip heuristic + LRU cache. Forces every recall through flan-t5-small.
443
+ - \`AWM_DISABLE_EXPANSION_CACHE=1\` — disables the query expansion skip
444
+ heuristic + LRU cache. Forces every recall through flan-t5-small.
445
+
446
+ Write pipeline + lifecycle (0.8.x):
447
+ - \`AWM_REINFORCE_MAX_CONTENT_LEN=1500\` — max chars an engram's content
448
+ can grow to via merge-on-reinforce (drop-oldest on overflow). Higher =
449
+ preserves more reinforced detail; lower = leaner recall output.
450
+ - \`AWM_REINFORCE_MERGE_CONTENT=0\` — disable content merge on reinforce.
451
+ Reverts to pre-0.8.5 behavior (discard new content, only bump confidence).
452
+ - \`AWM_NOVELTY_EMBED=0\` — disable the cosine channel in novelty
453
+ computation. BM25-only fallback. Reverts to pre-0.8.5 novelty.
454
+ - \`AWM_GRANULARITY_COMPACT_LEN=200\` — char budget for query-aware snippet
455
+ in \`granularity: 'compact'\` mode.
456
+ - \`AWM_GRANULARITY_FULL_LEN=1000\` — char budget for the top result in
457
+ \`granularity: 'auto'\` mode when there's a clear winner.
458
+
459
+ PGlite backend (0.8.x):
460
+ - \`AWM_PGLITE_BM25_M=1\` — multiplier on PGlite \`ts_rank_cd\` to calibrate
461
+ against SQLite FTS5 BM25 distribution. M=1 (default) is passthrough;
462
+ higher M boosts PGlite scores at the cost of recall-ranking precision
463
+ (see CHANGELOG 0.8.5 follow-up).
464
+ - \`AWM_IVFFLAT_PROBES=5\` — pgvector ivfflat probes per query. Higher =
465
+ more accurate, slower.
366
466
 
367
467
  In production, leave these all unset. Use only when diagnosing a suspected
368
468
  recall-quality regression.
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/adapters/common.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,sCAAsC;AAEtC;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,O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MAAM,uBAAuB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8StC,CAAC,SAAS,EAAE,CAAC"}
@@ -694,7 +694,7 @@ export function registerRoutes(app, deps) {
694
694
  const base = {
695
695
  status: 'ok',
696
696
  timestamp: new Date().toISOString(),
697
- version: '0.8.5',
697
+ version: '0.8.7',
698
698
  coordination: coordEnabled,
699
699
  };
700
700
  if (coordEnabled && typeof deps.store.getDb === 'function') {
@@ -72,17 +72,17 @@ export async function migrate(opts) {
72
72
  const embedding = r.embedding
73
73
  ? vectorLiteral(Array.from(bufferToFloat32Array(r.embedding)))
74
74
  : null;
75
- await dst.query(`INSERT INTO engrams (
76
- id, agent_id, concept, content, embedding, embedding_model,
77
- confidence, salience, access_count, last_accessed, created_at,
78
- salience_features, reason_codes, stage, ttl,
79
- retracted, retracted_by, retracted_at, tags, memory_type,
80
- memory_class, superseded_by, supersedes, episode_id,
81
- task_status, task_priority, blocked_by, sequence, references_json
82
- ) VALUES (
83
- $1, $2, $3, $4, $5::vector, $6, $7, $8, $9, $10, $11,
84
- $12, $13, $14, $15, $16, $17, $18, $19, $20,
85
- $21, $22, $23, $24, $25, $26, $27, $28, $29
75
+ await dst.query(`INSERT INTO engrams (
76
+ id, agent_id, concept, content, embedding, embedding_model,
77
+ confidence, salience, access_count, last_accessed, created_at,
78
+ salience_features, reason_codes, stage, ttl,
79
+ retracted, retracted_by, retracted_at, tags, memory_type,
80
+ memory_class, superseded_by, supersedes, episode_id,
81
+ task_status, task_priority, blocked_by, sequence, references_json
82
+ ) VALUES (
83
+ $1, $2, $3, $4, $5::vector, $6, $7, $8, $9, $10, $11,
84
+ $12, $13, $14, $15, $16, $17, $18, $19, $20,
85
+ $21, $22, $23, $24, $25, $26, $27, $28, $29
86
86
  )`, [
87
87
  r.id, r.agent_id, r.concept, r.content, embedding, r.embedding_model,
88
88
  r.confidence, r.salience, r.access_count, r.last_accessed, r.created_at,
@@ -112,9 +112,9 @@ export async function migrate(opts) {
112
112
  for (let i = 0; i < assocRows.length; i += batchSize) {
113
113
  const batch = assocRows.slice(i, i + batchSize);
114
114
  for (const r of batch) {
115
- await dst.query(`INSERT INTO associations (
116
- id, from_engram_id, to_engram_id, weight, confidence, type,
117
- activation_count, created_at, last_activated
115
+ await dst.query(`INSERT INTO associations (
116
+ id, from_engram_id, to_engram_id, weight, confidence, type,
117
+ activation_count, created_at, last_activated
118
118
  ) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9)`, [
119
119
  r.id, r.from_engram_id, r.to_engram_id, r.weight, r.confidence,
120
120
  r.type ?? 'hebbian', r.activation_count ?? 0,
@@ -133,7 +133,7 @@ export async function migrate(opts) {
133
133
  console.log(`agents: ${agentRows.length} rows`);
134
134
  if (dst && agentRows.length > 0) {
135
135
  for (const r of agentRows) {
136
- await dst.query(`INSERT INTO agents (id, name, created_at, config) VALUES ($1,$2,$3,$4)
136
+ await dst.query(`INSERT INTO agents (id, name, created_at, config) VALUES ($1,$2,$3,$4)
137
137
  ON CONFLICT (id) DO NOTHING`, [r.id, r.name, r.created_at, r.config ?? '{}']);
138
138
  stats.agents++;
139
139
  }
@@ -148,8 +148,8 @@ export async function migrate(opts) {
148
148
  if (dst && aeRows.length > 0) {
149
149
  for (let i = 0; i < aeRows.length; i += batchSize) {
150
150
  for (const r of aeRows.slice(i, i + batchSize)) {
151
- await dst.query(`INSERT INTO activation_events
152
- (id, agent_id, timestamp, context, results_returned, top_score, latency_ms, engram_ids)
151
+ await dst.query(`INSERT INTO activation_events
152
+ (id, agent_id, timestamp, context, results_returned, top_score, latency_ms, engram_ids)
153
153
  VALUES ($1,$2,$3,$4,$5,$6,$7,$8)`, [r.id, r.agent_id, r.timestamp, r.context, r.results_returned,
154
154
  r.top_score, r.latency_ms, r.engram_ids ?? '[]']);
155
155
  stats.activationEvents++;
@@ -165,7 +165,7 @@ export async function migrate(opts) {
165
165
  console.log(`staging_events: ${seRows.length} rows`);
166
166
  if (dst && seRows.length > 0) {
167
167
  for (const r of seRows) {
168
- await dst.query(`INSERT INTO staging_events (engram_id, agent_id, action, resonance_score, timestamp, age_ms)
168
+ await dst.query(`INSERT INTO staging_events (engram_id, agent_id, action, resonance_score, timestamp, age_ms)
169
169
  VALUES ($1,$2,$3,$4,$5,$6)`, [r.engram_id, r.agent_id, r.action, r.resonance_score, r.timestamp, r.age_ms]);
170
170
  stats.stagingEvents++;
171
171
  }
@@ -179,8 +179,8 @@ export async function migrate(opts) {
179
179
  console.log(`retrieval_feedback: ${rfRows.length} rows`);
180
180
  if (dst && rfRows.length > 0) {
181
181
  for (const r of rfRows) {
182
- await dst.query(`INSERT INTO retrieval_feedback
183
- (id, activation_event_id, engram_id, useful, context, timestamp)
182
+ await dst.query(`INSERT INTO retrieval_feedback
183
+ (id, activation_event_id, engram_id, useful, context, timestamp)
184
184
  VALUES ($1,$2,$3,$4,$5,$6)`, [r.id, r.activation_event_id, r.engram_id, intToBool(r.useful), r.context, r.timestamp]);
185
185
  stats.retrievalFeedback++;
186
186
  }
@@ -199,8 +199,8 @@ export async function migrate(opts) {
199
199
  const embedding = r.embedding
200
200
  ? vectorLiteral(Array.from(bufferToFloat32Array(r.embedding)))
201
201
  : null;
202
- await dst.query(`INSERT INTO episodes
203
- (id, agent_id, label, embedding, engram_count, start_time, end_time, created_at)
202
+ await dst.query(`INSERT INTO episodes
203
+ (id, agent_id, label, embedding, engram_count, start_time, end_time, created_at)
204
204
  VALUES ($1,$2,$3,$4::vector,$5,$6,$7,$8)`, [r.id, r.agent_id, r.label, embedding, r.engram_count ?? 0,
205
205
  r.start_time, r.end_time, r.created_at]);
206
206
  stats.episodes++;
@@ -221,13 +221,13 @@ export async function migrate(opts) {
221
221
  console.log(`conscious_state: ${csRows.length} rows`);
222
222
  if (dst && csRows.length > 0) {
223
223
  for (const r of csRows) {
224
- await dst.query(`INSERT INTO conscious_state (
225
- agent_id, last_write_id, last_recall_context, last_recall_ids,
226
- last_activity_at, write_count_since_consolidation,
227
- recall_count_since_consolidation, execution_state, checkpoint_at,
228
- last_consolidation_at, last_mini_consolidation_at,
229
- consolidation_cycle_count, updated_at
230
- ) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13)
224
+ await dst.query(`INSERT INTO conscious_state (
225
+ agent_id, last_write_id, last_recall_context, last_recall_ids,
226
+ last_activity_at, write_count_since_consolidation,
227
+ recall_count_since_consolidation, execution_state, checkpoint_at,
228
+ last_consolidation_at, last_mini_consolidation_at,
229
+ consolidation_cycle_count, updated_at
230
+ ) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13)
231
231
  ON CONFLICT (agent_id) DO NOTHING`, [
232
232
  r.agent_id, r.last_write_id, r.last_recall_context,
233
233
  r.last_recall_ids ?? '[]', r.last_activity_at,
package/dist/cli.js CHANGED
@@ -309,7 +309,7 @@ async function exportMemories() {
309
309
  // Collect unique agents
310
310
  const agents = [...new Set(memories.map((m) => m.agent_id))];
311
311
  const exportData = {
312
- version: '0.8.5',
312
+ version: '0.8.7',
313
313
  exported_at: new Date().toISOString(),
314
314
  source_db: dbPath,
315
315
  agent_filter: agentFilter,
@@ -14,33 +14,33 @@ const FAILURE_THRESHOLD = 5;
14
14
  const HALF_OPEN_DELAY_MS = 30_000;
15
15
  /** Record a worker failure. Opens the circuit when consecutive failures hit the threshold. */
16
16
  export function recordFailure(db, agentId) {
17
- db.prepare(`
18
- INSERT INTO coord_circuit_state (agent_id, consecutive_failures, last_transition_at)
19
- VALUES (?, 1, datetime('now'))
20
- ON CONFLICT(agent_id) DO UPDATE SET
21
- consecutive_failures = consecutive_failures + 1,
22
- state = CASE
23
- WHEN consecutive_failures + 1 >= ${FAILURE_THRESHOLD} THEN 'open'
24
- ELSE state
25
- END,
26
- opened_at = CASE
27
- WHEN consecutive_failures + 1 >= ${FAILURE_THRESHOLD} AND (state != 'open' OR opened_at IS NULL)
28
- THEN datetime('now')
29
- ELSE opened_at
30
- END,
31
- last_transition_at = datetime('now')
17
+ db.prepare(`
18
+ INSERT INTO coord_circuit_state (agent_id, consecutive_failures, last_transition_at)
19
+ VALUES (?, 1, datetime('now'))
20
+ ON CONFLICT(agent_id) DO UPDATE SET
21
+ consecutive_failures = consecutive_failures + 1,
22
+ state = CASE
23
+ WHEN consecutive_failures + 1 >= ${FAILURE_THRESHOLD} THEN 'open'
24
+ ELSE state
25
+ END,
26
+ opened_at = CASE
27
+ WHEN consecutive_failures + 1 >= ${FAILURE_THRESHOLD} AND (state != 'open' OR opened_at IS NULL)
28
+ THEN datetime('now')
29
+ ELSE opened_at
30
+ END,
31
+ last_transition_at = datetime('now')
32
32
  `).run(agentId);
33
33
  }
34
34
  /** Record a worker success. Resets to closed regardless of prior state. */
35
35
  export function recordSuccess(db, agentId) {
36
- db.prepare(`
37
- INSERT INTO coord_circuit_state (agent_id, state, consecutive_failures, last_transition_at)
38
- VALUES (?, 'closed', 0, datetime('now'))
39
- ON CONFLICT(agent_id) DO UPDATE SET
40
- state = 'closed',
41
- consecutive_failures = 0,
42
- opened_at = NULL,
43
- last_transition_at = datetime('now')
36
+ db.prepare(`
37
+ INSERT INTO coord_circuit_state (agent_id, state, consecutive_failures, last_transition_at)
38
+ VALUES (?, 'closed', 0, datetime('now'))
39
+ ON CONFLICT(agent_id) DO UPDATE SET
40
+ state = 'closed',
41
+ consecutive_failures = 0,
42
+ opened_at = NULL,
43
+ last_transition_at = datetime('now')
44
44
  `).run(agentId);
45
45
  }
46
46
  /**
@@ -0,0 +1,26 @@
1
+ export interface CompressResult {
2
+ /** The text to put in the model's context. */
3
+ text: string;
4
+ /** 'toon' when compressed, 'json'/'passthrough' when not. */
5
+ format: 'toon' | 'json' | 'passthrough';
6
+ /** Retrieval handle for the verbatim original, or null when unchanged. */
7
+ ref: string | null;
8
+ charsBefore: number;
9
+ charsAfter: number;
10
+ /** Approx fraction of characters saved (0..1); a rough proxy for token savings. */
11
+ ratio: number;
12
+ }
13
+ export interface CompressOptions {
14
+ /** Don't bother emitting TOON unless it saves at least this many chars. Default 40. */
15
+ minSavingChars?: number;
16
+ }
17
+ /** Retrieve the verbatim original for a CCR-lite ref, or undefined if evicted. */
18
+ export declare function retrieveOriginal(ref: string): string | undefined;
19
+ /**
20
+ * Compress a structured tool output for model consumption.
21
+ *
22
+ * @param value Either a JS object/array, or a string (JSON is parsed; anything
23
+ * that isn't valid JSON is treated as prose and passed through).
24
+ */
25
+ export declare function liteCompress(value: unknown, options?: CompressOptions): CompressResult;
26
+ //# sourceMappingURL=lite-compress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lite-compress.d.ts","sourceRoot":"","sources":["../../src/core/lite-compress.ts"],"names":[],"mappings":"AA4BA,MAAM,WAAW,cAAc;IAC7B,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,6DAA6D;IAC7D,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,aAAa,CAAC;IACxC,0EAA0E;IAC1E,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,mFAAmF;IACnF,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,eAAe;IAC9B,uFAAuF;IACvF,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAkBD,kFAAkF;AAClF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEhE;AAWD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,GAAE,eAAoB,GAAG,cAAc,CA8C1F"}
@@ -0,0 +1,105 @@
1
+ // Copyright 2026 Robert Winter / Complete Ideas
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ /**
4
+ * Lite output compressor — token-efficient encoding of STRUCTURED tool output.
5
+ *
6
+ * Why this exists: agents burn tokens re-reading large structured tool results
7
+ * (JSON arrays, query rows, log dumps). Encoding them as TOON (Token-Oriented
8
+ * Object Notation — a compact, schema-aware tabular form of JSON) cuts ~50-65%
9
+ * of the tokens on uniform arrays at ZERO comprehension cost. An A/B test on
10
+ * claude-sonnet-4-6 and claude-haiku-4-5 found identical retrieval accuracy
11
+ * reading TOON vs JSON (95.8%/83.3% on both encodings, identical misses).
12
+ *
13
+ * This is OUTPUT-ONLY. It never touches stored memory content or the write
14
+ * path. It is intentionally narrow and safe:
15
+ * - Structured data (parseable JSON object/array) -> TOON, IF it round-trips
16
+ * - Prose / non-JSON -> passthrough untouched
17
+ * - TOON that would lose fidelity or barely save -> plain JSON fallback
18
+ *
19
+ * Safety: TOON (like CSV/YAML) can type-coerce ambiguous bare scalars
20
+ * (the string "123" can decode back as the number 123). So every encode is
21
+ * SELF-VERIFIED (encode -> decode -> deep-equal) and we only emit TOON when it
22
+ * reproduces the input exactly. Originals are stashed so the agent can retrieve
23
+ * the verbatim source via a CCR-lite handle if it ever needs it.
24
+ *
25
+ * No ML, no network, no I/O — a pure in-process structural transform.
26
+ */
27
+ import { encode, decode } from '@toon-format/toon';
28
+ // ── CCR-lite: stash verbatim originals, hand back a retrieval id ────────────
29
+ // Bounded FIFO so a long-lived MCP process can't leak memory.
30
+ const MAX_STORE = 512;
31
+ const _store = new Map();
32
+ let _seq = 0;
33
+ function stash(original) {
34
+ const id = `awm_orig_${++_seq}`;
35
+ _store.set(id, original);
36
+ if (_store.size > MAX_STORE) {
37
+ const oldest = _store.keys().next().value;
38
+ if (oldest !== undefined)
39
+ _store.delete(oldest);
40
+ }
41
+ return id;
42
+ }
43
+ /** Retrieve the verbatim original for a CCR-lite ref, or undefined if evicted. */
44
+ export function retrieveOriginal(ref) {
45
+ return _store.get(ref);
46
+ }
47
+ /** True if TOON encode->decode reproduces `obj` exactly (no scalar coercion drift). */
48
+ function roundTrips(obj, toon) {
49
+ try {
50
+ return JSON.stringify(decode(toon)) === JSON.stringify(obj);
51
+ }
52
+ catch {
53
+ return false;
54
+ }
55
+ }
56
+ /**
57
+ * Compress a structured tool output for model consumption.
58
+ *
59
+ * @param value Either a JS object/array, or a string (JSON is parsed; anything
60
+ * that isn't valid JSON is treated as prose and passed through).
61
+ */
62
+ export function liteCompress(value, options = {}) {
63
+ const minSaving = options.minSavingChars ?? 40;
64
+ let obj;
65
+ let jsonText;
66
+ if (typeof value === 'string') {
67
+ try {
68
+ obj = JSON.parse(value);
69
+ }
70
+ catch {
71
+ // Not JSON — prose. Leave it alone; that's granularity:compact's job.
72
+ return { text: value, format: 'passthrough', ref: null,
73
+ charsBefore: value.length, charsAfter: value.length, ratio: 0 };
74
+ }
75
+ jsonText = value;
76
+ }
77
+ else {
78
+ obj = value;
79
+ jsonText = JSON.stringify(obj, null, 2);
80
+ }
81
+ // Only structured shapes benefit; a bare scalar gains nothing.
82
+ if (obj === null || typeof obj !== 'object') {
83
+ return { text: jsonText, format: 'json', ref: null,
84
+ charsBefore: jsonText.length, charsAfter: jsonText.length, ratio: 0 };
85
+ }
86
+ let toon;
87
+ try {
88
+ toon = encode(obj);
89
+ }
90
+ catch {
91
+ return { text: jsonText, format: 'json', ref: null,
92
+ charsBefore: jsonText.length, charsAfter: jsonText.length, ratio: 0 };
93
+ }
94
+ const before = jsonText.length;
95
+ const after = toon.length;
96
+ // Reject if it doesn't round-trip exactly, or the saving isn't worth it.
97
+ if (!roundTrips(obj, toon) || before - after < minSaving) {
98
+ return { text: jsonText, format: 'json', ref: null,
99
+ charsBefore: before, charsAfter: before, ratio: 0 };
100
+ }
101
+ const ref = stash(jsonText);
102
+ return { text: toon, format: 'toon', ref,
103
+ charsBefore: before, charsAfter: after, ratio: 1 - after / before };
104
+ }
105
+ //# sourceMappingURL=lite-compress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lite-compress.js","sourceRoot":"","sources":["../../src/core/lite-compress.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,sCAAsC;AACtC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAoBnD,+EAA+E;AAC/E,8DAA8D;AAC9D,MAAM,SAAS,GAAG,GAAG,CAAC;AACtB,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;AACzC,IAAI,IAAI,GAAG,CAAC,CAAC;AAEb,SAAS,KAAK,CAAC,QAAgB;IAC7B,MAAM,EAAE,GAAG,YAAY,EAAE,IAAI,EAAE,CAAC;IAChC,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;IACzB,IAAI,MAAM,CAAC,IAAI,GAAG,SAAS,EAAE,CAAC;QAC5B,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;QAC1C,IAAI,MAAM,KAAK,SAAS;YAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,OAAO,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC;AAED,uFAAuF;AACvF,SAAS,UAAU,CAAC,GAAY,EAAE,IAAY;IAC5C,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC9D,CAAC;IA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E,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI;YACzC,WAAW,EAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IACjF,CAAC;IAED,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;IAC/B,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC;IAE1B,yEAAyE;IACzE,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,MAAM,GAAG,KAAK,GAAG,SAAS,EAAE,CAAC;QACzD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI;YACzC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IAC/D,CAAC;IAED,MAAM,GAAG,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC5B,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG;QAC/B,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,GAAG,MAAM,EAAE,CAAC;AAC/E,CAAC"}
package/dist/mcp.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * Runs as a stdio-based MCP server that Claude Code connects to directly.
5
5
  * Uses the storage and engine layers in-process (no HTTP overhead).
6
6
  *
7
- * Tools exposed (12):
7
+ * Tools exposed (16):
8
8
  * memory_write — store a memory (salience filter decides disposition)
9
9
  * memory_recall — activate memories by context (cognitive retrieval)
10
10
  * memory_feedback — report whether a recalled memory was useful
@@ -17,6 +17,10 @@
17
17
  * memory_task_update — change task status, priority, or blocking
18
18
  * memory_task_list — list tasks filtered by status
19
19
  * memory_task_next — get the highest-priority actionable task
20
+ * memory_task_begin — start a task (auto-checkpoint + recall)
21
+ * memory_task_end — end a task (write summary + checkpoint)
22
+ * compress_output — encode structured tool output as TOON (token-efficient, lossless)
23
+ * retrieve_original — get the verbatim source for a compress_output ref
20
24
  *
21
25
  * Run: npx tsx src/mcp.ts
22
26
  * Config: add to ~/.claude.json or .mcp.json
package/dist/mcp.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;GAsBG"}
1
+ {"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG"}