agent-working-memory 0.8.6 → 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 +13 -0
  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 +13 -0
  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"}
@@ -395,6 +395,19 @@ memory_write(
395
395
  - AWM is shared across all agents in real time. When any agent writes or supersedes a
396
396
  memory, every other agent can recall it immediately.
397
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
+
398
411
  ### Backend (SQLite vs PGlite, 0.8.x)
399
412
  AWM ships two storage backends. The installer picks SQLite by default; both
400
413
  are functionally equivalent for cognitive workloads, but differ in operational
@@ -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,OAAO,IAAI,SAAS,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGzC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtC,gEAAgE;AAChE,MAAM,UAAU,kBAAkB;IAChC,uEAAuE;IACvE,OAAO,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AACxC,CAAC;AAED,2EA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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.6',
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.6',
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;;;;;;;;;;;;;;;;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G,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"}
package/dist/mcp.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * Runs as a stdio-based MCP server that Claude Code connects to directly.
7
7
  * Uses the storage and engine layers in-process (no HTTP overhead).
8
8
  *
9
- * Tools exposed (12):
9
+ * Tools exposed (16):
10
10
  * memory_write — store a memory (salience filter decides disposition)
11
11
  * memory_recall — activate memories by context (cognitive retrieval)
12
12
  * memory_feedback — report whether a recalled memory was useful
@@ -19,6 +19,10 @@
19
19
  * memory_task_update — change task status, priority, or blocking
20
20
  * memory_task_list — list tasks filtered by status
21
21
  * memory_task_next — get the highest-priority actionable task
22
+ * memory_task_begin — start a task (auto-checkpoint + recall)
23
+ * memory_task_end — end a task (write summary + checkpoint)
24
+ * compress_output — encode structured tool output as TOON (token-efficient, lossless)
25
+ * retrieve_original — get the verbatim source for a compress_output ref
22
26
  *
23
27
  * Run: npx tsx src/mcp.ts
24
28
  * Config: add to ~/.claude.json or .mcp.json
@@ -65,6 +69,7 @@ import { DEFAULT_AGENT_CONFIG } from './types/agent.js';
65
69
  import { embed } from './core/embeddings.js';
66
70
  import { startSidecar } from './hooks/sidecar.js';
67
71
  import { initLogger, log, getLogPath } from './core/logger.js';
72
+ import { liteCompress, retrieveOriginal } from './core/lite-compress.js';
68
73
  import { queryPeerDecisions, formatPeerDecisions } from './coordination/peer-decisions.js';
69
74
  // --- Incognito Mode ---
70
75
  // When AWM_INCOGNITO=1, register zero tools. Claude won't see memory tools at all.
@@ -72,7 +77,7 @@ import { queryPeerDecisions, formatPeerDecisions } from './coordination/peer-dec
72
77
  const INCOGNITO = process.env.AWM_INCOGNITO === '1' || process.env.AWM_INCOGNITO === 'true';
73
78
  if (INCOGNITO) {
74
79
  console.error('AWM: incognito mode — all memory tools disabled, nothing will be recorded');
75
- const server = new McpServer({ name: 'agent-working-memory', version: '0.8.6' });
80
+ const server = new McpServer({ name: 'agent-working-memory', version: '0.8.7' });
76
81
  const transport = new StdioServerTransport();
77
82
  server.connect(transport).catch(err => {
78
83
  console.error('MCP server failed:', err);
@@ -84,7 +89,20 @@ else {
84
89
  // --- Setup ---
85
90
  const BACKEND = getConfiguredBackend();
86
91
  const DB_PATH = process.env.AWM_DB_PATH ?? (BACKEND === 'pglite' ? 'memory-pglite' : 'memory.db');
87
- const AGENT_ID = process.env.AWM_AGENT_ID ?? process.env.WORKER_NAME ?? 'claude-code';
92
+ // Fallback agent selection when AWM_AGENT_ID/WORKER_NAME are unset: derive from
93
+ // the project directory so plain `claude` launches still bind to the right
94
+ // store. Personal-Projects -> 'personal'; everything else -> 'work' (the
95
+ // primary store). MUST stay in sync with the SessionStart hook
96
+ // (~/.claude/hooks/awm-session-start.ps1) so the hook's restore and the
97
+ // server's reads/writes never diverge. Guard the AWM package's own path
98
+ // (it lives under Personal-Projects) so a stray server cwd can't mis-bind.
99
+ function deriveAgentFromDir() {
100
+ const dir = (process.env.CLAUDE_PROJECT_DIR ?? process.cwd()).replace(/\\/g, '/');
101
+ if (/\/AgentSynapse\//i.test(dir))
102
+ return 'work';
103
+ return /\/Personal-Projects(\/|$)/i.test(dir) ? 'personal' : 'work';
104
+ }
105
+ const AGENT_ID = process.env.AWM_AGENT_ID ?? process.env.WORKER_NAME ?? deriveAgentFromDir();
88
106
  const HOOK_PORT = parseInt(process.env.AWM_HOOK_PORT ?? '8401', 10);
89
107
  const HOOK_SECRET = process.env.AWM_HOOK_SECRET ?? null;
90
108
  initLogger(DB_PATH);
@@ -108,7 +126,7 @@ else {
108
126
  let coordDb = null;
109
127
  const server = new McpServer({
110
128
  name: 'agent-working-memory',
111
- version: '0.8.6',
129
+ version: '0.8.7',
112
130
  });
113
131
  server.registerResource('awm-overview', 'awm://server/overview', {
114
132
  title: 'AWM Overview',
@@ -910,6 +928,42 @@ This captures what was accomplished so future sessions can recall it.`, {
910
928
  }],
911
929
  };
912
930
  });
931
+ server.tool('compress_output', `Compress a STRUCTURED tool output (JSON object/array, query rows, log records) into TOON —
932
+ a compact, schema-aware tabular encoding — before putting it in your context. Cuts ~50-65%
933
+ of the tokens on uniform arrays at zero comprehension cost (validated: models read TOON as
934
+ accurately as JSON). Use this on large tool results you need to keep in context.
935
+
936
+ Output-only and safe: it never changes the data. Non-JSON / prose is returned unchanged.
937
+ TOON is only emitted when it reproduces the input exactly (self-verified round-trip);
938
+ otherwise you get plain JSON back. When compressed, you also get a 'ref' — call
939
+ retrieve_original(ref) to get the verbatim source back if you ever need it.`, {
940
+ output: z.string().describe('The tool output to compress — JSON text (preferred) or any string. Non-JSON is returned unchanged.'),
941
+ min_saving_chars: z.number().optional().describe('Only emit TOON if it saves at least this many characters (default 40).'),
942
+ }, async (params) => {
943
+ const r = liteCompress(params.output, { minSavingChars: params.min_saving_chars });
944
+ log(AGENT_ID, 'compress', `${r.format} ${r.charsBefore}->${r.charsAfter} chars (${(r.ratio * 100).toFixed(0)}%)${r.ref ? ` ref=${r.ref}` : ''}`);
945
+ const header = r.format === 'toon'
946
+ ? `[TOON, ${(r.ratio * 100).toFixed(0)}% smaller — compact lossless JSON; read as data, ref=${r.ref}]\n`
947
+ : '';
948
+ return {
949
+ content: [{ type: 'text', text: header + r.text }],
950
+ };
951
+ });
952
+ server.tool('retrieve_original', `Retrieve the verbatim original text for a 'ref' returned by compress_output. Use this when
953
+ you need the exact, uncompressed source (e.g. to pass it to another tool unchanged). Returns
954
+ an error if the ref has expired (originals are kept for the most recent compressions only).`, {
955
+ ref: z.string().describe('The ref handle returned by compress_output (e.g. "awm_orig_12").'),
956
+ }, async (params) => {
957
+ const original = retrieveOriginal(params.ref);
958
+ if (original === undefined) {
959
+ return {
960
+ content: [{ type: 'text', text: `Error: ref "${params.ref}" not found or expired.` }],
961
+ };
962
+ }
963
+ return {
964
+ content: [{ type: 'text', text: original }],
965
+ };
966
+ });
913
967
  // --- Start ---
914
968
  async function main() {
915
969
  const transport = new StdioServerTransport();