agent-working-memory 0.10.0 → 0.12.0

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 (136) hide show
  1. package/README.md +118 -19
  2. package/dist/adapters/claude-code.d.ts.map +1 -1
  3. package/dist/adapters/claude-code.js +63 -3
  4. package/dist/adapters/claude-code.js.map +1 -1
  5. package/dist/adapters/common.d.ts.map +1 -1
  6. package/dist/adapters/common.js +329 -302
  7. package/dist/adapters/common.js.map +1 -1
  8. package/dist/api/routes.d.ts.map +1 -1
  9. package/dist/api/routes.js +31 -8
  10. package/dist/api/routes.js.map +1 -1
  11. package/dist/cli/migrate.js +29 -29
  12. package/dist/cli.js +82 -2
  13. package/dist/cli.js.map +1 -1
  14. package/dist/coordination/circuit-breaker.js +23 -23
  15. package/dist/coordination/routes.d.ts.map +1 -1
  16. package/dist/coordination/routes.js +174 -170
  17. package/dist/coordination/routes.js.map +1 -1
  18. package/dist/core/embeddings.d.ts.map +1 -1
  19. package/dist/core/embeddings.js +3 -0
  20. package/dist/core/embeddings.js.map +1 -1
  21. package/dist/core/entity-extract.d.ts +3 -0
  22. package/dist/core/entity-extract.d.ts.map +1 -0
  23. package/dist/core/entity-extract.js +47 -0
  24. package/dist/core/entity-extract.js.map +1 -0
  25. package/dist/core/salience.d.ts.map +1 -1
  26. package/dist/core/salience.js +14 -2
  27. package/dist/core/salience.js.map +1 -1
  28. package/dist/core/whoami.d.ts +24 -0
  29. package/dist/core/whoami.d.ts.map +1 -0
  30. package/dist/core/whoami.js +66 -0
  31. package/dist/core/whoami.js.map +1 -0
  32. package/dist/core/write-pipeline.d.ts +9 -0
  33. package/dist/core/write-pipeline.d.ts.map +1 -1
  34. package/dist/core/write-pipeline.js +109 -68
  35. package/dist/core/write-pipeline.js.map +1 -1
  36. package/dist/core/write-telemetry.d.ts +33 -0
  37. package/dist/core/write-telemetry.d.ts.map +1 -0
  38. package/dist/core/write-telemetry.js +110 -0
  39. package/dist/core/write-telemetry.js.map +1 -0
  40. package/dist/engine/activation.d.ts +22 -12
  41. package/dist/engine/activation.d.ts.map +1 -1
  42. package/dist/engine/activation.js +133 -17
  43. package/dist/engine/activation.js.map +1 -1
  44. package/dist/engine/consolidation-scheduler.d.ts +1 -1
  45. package/dist/engine/consolidation-scheduler.js +1 -1
  46. package/dist/engine/consolidation.d.ts +1 -0
  47. package/dist/engine/consolidation.d.ts.map +1 -1
  48. package/dist/engine/consolidation.js +18 -0
  49. package/dist/engine/consolidation.js.map +1 -1
  50. package/dist/engine/eval.d.ts.map +1 -1
  51. package/dist/engine/eval.js +5 -1
  52. package/dist/engine/eval.js.map +1 -1
  53. package/dist/index.js +21 -2
  54. package/dist/index.js.map +1 -1
  55. package/dist/mcp.d.ts +2 -1
  56. package/dist/mcp.d.ts.map +1 -1
  57. package/dist/mcp.js +212 -97
  58. package/dist/mcp.js.map +1 -1
  59. package/dist/onboard/index.d.ts +68 -0
  60. package/dist/onboard/index.d.ts.map +1 -0
  61. package/dist/onboard/index.js +265 -0
  62. package/dist/onboard/index.js.map +1 -0
  63. package/dist/recipes/index.d.ts +57 -0
  64. package/dist/recipes/index.d.ts.map +1 -0
  65. package/dist/recipes/index.js +81 -0
  66. package/dist/recipes/index.js.map +1 -0
  67. package/dist/storage/pglite-schema.d.ts.map +1 -1
  68. package/dist/storage/pglite-schema.js +170 -143
  69. package/dist/storage/pglite-schema.js.map +1 -1
  70. package/dist/storage/pglite.d.ts +5 -0
  71. package/dist/storage/pglite.d.ts.map +1 -1
  72. package/dist/storage/pglite.js +180 -138
  73. package/dist/storage/pglite.js.map +1 -1
  74. package/dist/storage/postgres.d.ts +5 -0
  75. package/dist/storage/postgres.d.ts.map +1 -1
  76. package/dist/storage/postgres.js +44 -2
  77. package/dist/storage/postgres.js.map +1 -1
  78. package/dist/storage/sqlite.d.ts +9 -0
  79. package/dist/storage/sqlite.d.ts.map +1 -1
  80. package/dist/storage/sqlite.js +394 -326
  81. package/dist/storage/sqlite.js.map +1 -1
  82. package/dist/types/engram.d.ts +14 -0
  83. package/dist/types/engram.d.ts.map +1 -1
  84. package/dist/types/engram.js.map +1 -1
  85. package/dist/version.d.ts +2 -0
  86. package/dist/version.d.ts.map +1 -0
  87. package/dist/version.js +27 -0
  88. package/dist/version.js.map +1 -0
  89. package/package.json +9 -1
  90. package/src/adapters/claude-code.ts +66 -3
  91. package/src/adapters/common.ts +538 -511
  92. package/src/api/index.ts +3 -3
  93. package/src/api/routes.ts +999 -970
  94. package/src/cli/migrate.ts +307 -307
  95. package/src/cli.ts +77 -2
  96. package/src/coordination/circuit-breaker.ts +83 -83
  97. package/src/coordination/failure-modes.ts +50 -50
  98. package/src/coordination/routes.ts +2155 -2150
  99. package/src/core/decay.ts +63 -63
  100. package/src/core/embeddings.ts +113 -110
  101. package/src/core/entity-extract.ts +47 -0
  102. package/src/core/index.ts +5 -5
  103. package/src/core/logger.ts +36 -36
  104. package/src/core/ml-worker-entry.ts +194 -194
  105. package/src/core/ml-worker.ts +281 -281
  106. package/src/core/query-expander.ts +122 -122
  107. package/src/core/reranker.ts +119 -119
  108. package/src/core/salience.ts +529 -514
  109. package/src/core/whoami.ts +92 -0
  110. package/src/core/write-pipeline.ts +60 -8
  111. package/src/core/write-telemetry.ts +131 -0
  112. package/src/engine/activation.ts +1468 -1369
  113. package/src/engine/confidence.ts +120 -120
  114. package/src/engine/consolidation-scheduler.ts +242 -242
  115. package/src/engine/consolidation.ts +887 -869
  116. package/src/engine/eval.ts +107 -102
  117. package/src/engine/eviction.ts +101 -101
  118. package/src/engine/index.ts +8 -8
  119. package/src/engine/retraction.ts +366 -366
  120. package/src/engine/staging.ts +74 -74
  121. package/src/index.ts +248 -226
  122. package/src/mcp.ts +1341 -1211
  123. package/src/onboard/index.ts +298 -0
  124. package/src/recipes/index.ts +125 -0
  125. package/src/storage/index.ts +3 -3
  126. package/src/storage/pglite-schema.ts +193 -166
  127. package/src/storage/pglite.ts +1420 -1372
  128. package/src/storage/postgres.ts +50 -2
  129. package/src/storage/sqlite.ts +1936 -1861
  130. package/src/storage/store.ts +80 -80
  131. package/src/types/agent.ts +67 -67
  132. package/src/types/checkpoint.ts +46 -46
  133. package/src/types/engram.ts +22 -0
  134. package/src/types/eval.ts +100 -100
  135. package/src/types/index.ts +6 -6
  136. package/src/version.ts +26 -0
@@ -127,6 +127,11 @@ function rowToEngram(row: any): Engram {
127
127
  blockedBy: (row.blocked_by as string | null) ?? null,
128
128
  sequence: row.sequence == null ? null : Number(row.sequence),
129
129
  references: row.references_json ? JSON.parse(row.references_json as string) : null,
130
+ originClass: (row.origin_class as string | null) ?? null,
131
+ writerSession: (row.writer_session as string | null) ?? null,
132
+ recipeId: (row.recipe_id as string | null) ?? null,
133
+ validFrom: (row.valid_from as string | null) ?? null,
134
+ validTo: (row.valid_to as string | null) ?? null,
130
135
  } as Engram;
131
136
  }
132
137
 
@@ -358,13 +363,15 @@ export class PostgresEngramStore {
358
363
  confidence, salience, access_count, last_accessed, created_at,
359
364
  salience_features, reason_codes, stage, ttl, retracted,
360
365
  tags, memory_type, memory_class, supersedes, episode_id,
361
- task_status, task_priority, blocked_by, sequence, references_json
366
+ task_status, task_priority, blocked_by, sequence, references_json,
367
+ origin_class, writer_session, recipe_id, valid_from, valid_to
362
368
  ) VALUES (
363
369
  $1, $2, $3, $4, $5::vector, $6,
364
370
  $7, $8, 0, $9, $10,
365
371
  $11, $12, 'active', $13, FALSE,
366
372
  $14, $15, $16, $17, $18,
367
- $19, $20, $21, $22, $23
373
+ $19, $20, $21, $22, $23,
374
+ $24, $25, $26, $27, $28
368
375
  )`,
369
376
  [
370
377
  id,
@@ -390,6 +397,11 @@ export class PostgresEngramStore {
390
397
  (input as any).sequence ?? null,
391
398
  input.references && input.references.length > 0
392
399
  ? JSON.stringify(input.references) : null,
400
+ input.originClass ?? null,
401
+ input.writerSession ?? null,
402
+ input.recipeId ?? null,
403
+ input.validFrom ?? null,
404
+ input.validTo ?? null,
393
405
  ],
394
406
  );
395
407
 
@@ -1290,6 +1302,42 @@ export class PostgresEngramStore {
1290
1302
  );
1291
1303
  }
1292
1304
 
1305
+ /** Distinct agent ids present in this store (D3 whoami; includes all stages). */
1306
+ async listAgentIds(): Promise<string[]> {
1307
+ const res = await this.pool.query('SELECT DISTINCT agent_id FROM engrams ORDER BY agent_id');
1308
+ return (res.rows as Array<{ agent_id: string }>).map(r => r.agent_id);
1309
+ }
1310
+
1311
+ async recordEntityMentions(engramId: string, agentId: string, entities: string[]): Promise<void> {
1312
+ if (!entities || entities.length === 0) return;
1313
+ for (const entity of entities) {
1314
+ await this.pool.query(
1315
+ 'INSERT INTO entity_mentions (entity, engram_id, agent_id) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING',
1316
+ [entity, engramId, agentId],
1317
+ );
1318
+ }
1319
+ }
1320
+
1321
+ async searchEntities(term: string, limit: number = 8): Promise<string[]> {
1322
+ const t = term.toLowerCase().replace(/[%_]/g, '');
1323
+ if (!t) return [];
1324
+ const res = await this.pool.query(
1325
+ `SELECT DISTINCT entity FROM (
1326
+ SELECT entity FROM entity_mentions WHERE entity LIKE $1
1327
+ UNION SELECT entity FROM entity_aliases WHERE alias LIKE $1
1328
+ ) u LIMIT $2`, [`%${t}%`, limit]);
1329
+ return (res.rows as Array<{ entity: string }>).map(r => r.entity);
1330
+ }
1331
+
1332
+ async getEngramIdsByEntity(entity: string, agentId?: string): Promise<string[]> {
1333
+ const alias = await this.pool.query('SELECT entity FROM entity_aliases WHERE alias = $1', [entity.toLowerCase()]);
1334
+ const resolved = (alias.rows as Array<{ entity: string }>)[0]?.entity ?? entity.toLowerCase();
1335
+ const res = agentId
1336
+ ? await this.pool.query('SELECT engram_id FROM entity_mentions WHERE entity = $1 AND agent_id = $2', [resolved, agentId])
1337
+ : await this.pool.query('SELECT engram_id FROM entity_mentions WHERE entity = $1', [resolved]);
1338
+ return (res.rows as Array<{ engram_id: string }>).map(r => r.engram_id);
1339
+ }
1340
+
1293
1341
  async getCheckpoint(agentId: string): Promise<CheckpointRow | null> {
1294
1342
  await this.readyPromise;
1295
1343
  const result = await this.q<any>(