agent-working-memory 0.13.0 → 0.14.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 (104) hide show
  1. package/README.md +200 -238
  2. package/dist/adapters/common.d.ts +6 -0
  3. package/dist/adapters/common.d.ts.map +1 -1
  4. package/dist/adapters/common.js +457 -362
  5. package/dist/adapters/common.js.map +1 -1
  6. package/dist/api/routes.d.ts.map +1 -1
  7. package/dist/api/routes.js +24 -8
  8. package/dist/api/routes.js.map +1 -1
  9. package/dist/core/alias-map.d.ts +16 -0
  10. package/dist/core/alias-map.d.ts.map +1 -0
  11. package/dist/core/alias-map.js +102 -0
  12. package/dist/core/alias-map.js.map +1 -0
  13. package/dist/core/embeddings.d.ts +17 -0
  14. package/dist/core/embeddings.d.ts.map +1 -1
  15. package/dist/core/embeddings.js +52 -1
  16. package/dist/core/embeddings.js.map +1 -1
  17. package/dist/core/model-cache.d.ts +28 -0
  18. package/dist/core/model-cache.d.ts.map +1 -0
  19. package/dist/core/model-cache.js +50 -0
  20. package/dist/core/model-cache.js.map +1 -0
  21. package/dist/core/query-expander.d.ts.map +1 -1
  22. package/dist/core/query-expander.js +2 -0
  23. package/dist/core/query-expander.js.map +1 -1
  24. package/dist/core/recall-config.d.ts +52 -0
  25. package/dist/core/recall-config.d.ts.map +1 -0
  26. package/dist/core/recall-config.js +110 -0
  27. package/dist/core/recall-config.js.map +1 -0
  28. package/dist/core/rerank-window.d.ts +61 -0
  29. package/dist/core/rerank-window.d.ts.map +1 -0
  30. package/dist/core/rerank-window.js +153 -0
  31. package/dist/core/rerank-window.js.map +1 -0
  32. package/dist/core/rerank2.d.ts +62 -0
  33. package/dist/core/rerank2.d.ts.map +1 -0
  34. package/dist/core/rerank2.js +75 -0
  35. package/dist/core/rerank2.js.map +1 -0
  36. package/dist/core/reranker.d.ts.map +1 -1
  37. package/dist/core/reranker.js +2 -0
  38. package/dist/core/reranker.js.map +1 -1
  39. package/dist/core/retrieval-text.d.ts +55 -0
  40. package/dist/core/retrieval-text.d.ts.map +1 -0
  41. package/dist/core/retrieval-text.js +87 -0
  42. package/dist/core/retrieval-text.js.map +1 -0
  43. package/dist/core/temporal-query.d.ts +61 -0
  44. package/dist/core/temporal-query.d.ts.map +1 -0
  45. package/dist/core/temporal-query.js +168 -0
  46. package/dist/core/temporal-query.js.map +1 -0
  47. package/dist/core/token-budget.d.ts +75 -0
  48. package/dist/core/token-budget.d.ts.map +1 -0
  49. package/dist/core/token-budget.js +136 -0
  50. package/dist/core/token-budget.js.map +1 -0
  51. package/dist/core/whoami.d.ts +11 -0
  52. package/dist/core/whoami.d.ts.map +1 -1
  53. package/dist/core/whoami.js +10 -0
  54. package/dist/core/whoami.js.map +1 -1
  55. package/dist/core/write-pipeline.d.ts.map +1 -1
  56. package/dist/core/write-pipeline.js +6 -3
  57. package/dist/core/write-pipeline.js.map +1 -1
  58. package/dist/engine/activation.d.ts.map +1 -1
  59. package/dist/engine/activation.js +135 -32
  60. package/dist/engine/activation.js.map +1 -1
  61. package/dist/hooks/prime.d.ts +77 -0
  62. package/dist/hooks/prime.d.ts.map +1 -0
  63. package/dist/hooks/prime.js +92 -0
  64. package/dist/hooks/prime.js.map +1 -0
  65. package/dist/hooks/sidecar.d.ts.map +1 -1
  66. package/dist/hooks/sidecar.js +39 -0
  67. package/dist/hooks/sidecar.js.map +1 -1
  68. package/dist/mcp.js +134 -102
  69. package/dist/mcp.js.map +1 -1
  70. package/dist/storage/pglite.d.ts.map +1 -1
  71. package/dist/storage/pglite.js +10 -2
  72. package/dist/storage/pglite.js.map +1 -1
  73. package/dist/storage/postgres.d.ts.map +1 -1
  74. package/dist/storage/postgres.js +10 -2
  75. package/dist/storage/postgres.js.map +1 -1
  76. package/dist/storage/sqlite.d.ts.map +1 -1
  77. package/dist/storage/sqlite.js +12 -2
  78. package/dist/storage/sqlite.js.map +1 -1
  79. package/dist/types/engram.d.ts +7 -0
  80. package/dist/types/engram.d.ts.map +1 -1
  81. package/package.json +3 -2
  82. package/src/adapters/common.ts +666 -567
  83. package/src/api/routes.ts +1015 -999
  84. package/src/core/alias-map.ts +97 -0
  85. package/src/core/embeddings.ts +172 -113
  86. package/src/core/model-cache.ts +51 -0
  87. package/src/core/query-expander.ts +2 -0
  88. package/src/core/recall-config.ts +115 -0
  89. package/src/core/rerank-window.ts +158 -0
  90. package/src/core/rerank2.ts +82 -0
  91. package/src/core/reranker.ts +2 -0
  92. package/src/core/retrieval-text.ts +82 -0
  93. package/src/core/temporal-query.ts +193 -0
  94. package/src/core/token-budget.ts +160 -0
  95. package/src/core/whoami.ts +110 -92
  96. package/src/core/write-pipeline.ts +6 -3
  97. package/src/engine/activation.ts +1568 -1468
  98. package/src/hooks/prime.ts +136 -0
  99. package/src/hooks/sidecar.ts +43 -0
  100. package/src/mcp.ts +1422 -1387
  101. package/src/storage/pglite.ts +10 -2
  102. package/src/storage/postgres.ts +10 -2
  103. package/src/storage/sqlite.ts +12 -2
  104. package/src/types/engram.ts +7 -0
@@ -512,7 +512,11 @@ export class PGliteEngramStore {
512
512
  sql += ` AND id != $${params.length + 1}`;
513
513
  params.push(excludeId);
514
514
  }
515
- sql += ` ORDER BY created_at DESC LIMIT 1`;
515
+ // FIX 2026-08-23: created_at is millisecond-resolution, so two engrams written in
516
+ // the same millisecond TIE and "most recent" became whichever row the engine
517
+ // happened to return. Postgres has no stable insert-order column (ctid moves on
518
+ // update/vacuum), so id is the tiebreak: deterministic, though not chronological.
519
+ sql += ` ORDER BY created_at DESC, id DESC LIMIT 1`;
516
520
  const result = await this.db.query<any>(sql, params);
517
521
  return result.rows.length > 0 ? rowToEngram(result.rows[0]) : null;
518
522
  }
@@ -734,7 +738,11 @@ export class PGliteEngramStore {
734
738
  params.push(tagLike(tag));
735
739
  }
736
740
  }
737
- sql += ` ORDER BY created_at DESC LIMIT 1`;
741
+ // FIX 2026-08-23: created_at is millisecond-resolution, so two engrams written in
742
+ // the same millisecond TIE and "most recent" became whichever row the engine
743
+ // happened to return. Postgres has no stable insert-order column (ctid moves on
744
+ // update/vacuum), so id is the tiebreak: deterministic, though not chronological.
745
+ sql += ` ORDER BY created_at DESC, id DESC LIMIT 1`;
738
746
  const result = await this.db.query<any>(sql, params);
739
747
  return result.rows.length > 0 ? rowToEngram(result.rows[0]) : null;
740
748
  }
@@ -611,7 +611,11 @@ export class PostgresEngramStore {
611
611
  sql += ` AND id != $${params.length + 1}`;
612
612
  params.push(excludeId);
613
613
  }
614
- sql += ` ORDER BY created_at DESC LIMIT 1`;
614
+ // FIX 2026-08-23: created_at is millisecond-resolution, so two engrams written in
615
+ // the same millisecond TIE and "most recent" became whichever row the engine
616
+ // happened to return. Postgres has no stable insert-order column (ctid moves on
617
+ // update/vacuum), so id is the tiebreak: deterministic, though not chronological.
618
+ sql += ` ORDER BY created_at DESC, id DESC LIMIT 1`;
615
619
  const result = await this.q<any>(sql, params);
616
620
  return result.rows.length > 0 ? rowToEngram(result.rows[0]) : null;
617
621
  }
@@ -833,7 +837,11 @@ export class PostgresEngramStore {
833
837
  params.push(tagLike(tag));
834
838
  }
835
839
  }
836
- sql += ` ORDER BY created_at DESC LIMIT 1`;
840
+ // FIX 2026-08-23: created_at is millisecond-resolution, so two engrams written in
841
+ // the same millisecond TIE and "most recent" became whichever row the engine
842
+ // happened to return. Postgres has no stable insert-order column (ctid moves on
843
+ // update/vacuum), so id is the tiebreak: deterministic, though not chronological.
844
+ sql += ` ORDER BY created_at DESC, id DESC LIMIT 1`;
837
845
  const result = await this.q<any>(sql, params);
838
846
  return result.rows.length > 0 ? rowToEngram(result.rows[0]) : null;
839
847
  }
@@ -956,7 +956,12 @@ export class EngramStore {
956
956
  sql += ' AND id != ?';
957
957
  params.push(excludeId);
958
958
  }
959
- sql += ' ORDER BY created_at DESC LIMIT 1';
959
+ // FIX 2026-08-23: created_at is millisecond-resolution ISO text, so two engrams
960
+ // written in the same millisecond TIE and "most recent" became whichever row the
961
+ // engine happened to return. Surfaced on Linux (same-ms writes) while passing on
962
+ // Windows, whose coarser timer separated them. rowid is monotonic with insert
963
+ // order, so it is both deterministic AND chronologically correct as a tiebreak.
964
+ sql += ' ORDER BY created_at DESC, rowid DESC LIMIT 1';
960
965
  const row = this.db.prepare(sql).get(...params) as any;
961
966
  return row ? this.rowToEngram(row) : null;
962
967
  }
@@ -1058,7 +1063,12 @@ export class EngramStore {
1058
1063
  params.push(`%"${tag}"%`);
1059
1064
  }
1060
1065
  }
1061
- sql += ' ORDER BY created_at DESC LIMIT 1';
1066
+ // FIX 2026-08-23: created_at is millisecond-resolution ISO text, so two engrams
1067
+ // written in the same millisecond TIE and "most recent" became whichever row the
1068
+ // engine happened to return. Surfaced on Linux (same-ms writes) while passing on
1069
+ // Windows, whose coarser timer separated them. rowid is monotonic with insert
1070
+ // order, so it is both deterministic AND chronologically correct as a tiebreak.
1071
+ sql += ' ORDER BY created_at DESC, rowid DESC LIMIT 1';
1062
1072
  const row = this.db.prepare(sql).get(...params) as any;
1063
1073
  return row ? this.rowToEngram(row) : null;
1064
1074
  }
@@ -278,6 +278,13 @@ export interface ActivationQuery {
278
278
  memoryType?: MemoryType; // Filter by memory type (episodic, semantic, procedural)
279
279
  mode?: QueryMode; // Pipeline mode — 'auto' by default
280
280
  workspace?: string; // Search across all agents in this workspace (hive mode). If unset, agent-scoped only.
281
+ /**
282
+ * Anchor for relative temporal expressions ("last Friday", "last week").
283
+ * Defaults to now. Passed explicitly by evals so a fixture stays
284
+ * reproducible — with the wall clock, "last week" would silently mean
285
+ * something different on every run.
286
+ */
287
+ asOf?: number;
281
288
  bm25Only?: boolean; // Skip embedding — fast text-only retrieval for bulk/benchmark scenarios
282
289
  /**
283
290
  * Output granularity (Paper 3: cognitive teaming, Brill 2018 ACT-R collaboration).