@monoes/memory 1.0.4 → 1.0.6

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 (154) hide show
  1. package/README.md +72 -840
  2. package/dist/atomic-file.d.ts +17 -0
  3. package/dist/atomic-file.d.ts.map +1 -0
  4. package/dist/atomic-file.js +27 -0
  5. package/dist/atomic-file.js.map +1 -0
  6. package/dist/cache-manager.d.ts +0 -0
  7. package/dist/cache-manager.d.ts.map +1 -1
  8. package/dist/cache-manager.js +0 -0
  9. package/dist/cache-manager.js.map +1 -1
  10. package/dist/checkpointer.d.ts +13 -0
  11. package/dist/checkpointer.d.ts.map +1 -1
  12. package/dist/checkpointer.js +69 -6
  13. package/dist/checkpointer.js.map +1 -1
  14. package/dist/controller-registry.d.ts +2 -8
  15. package/dist/controller-registry.d.ts.map +1 -1
  16. package/dist/controller-registry.js +4 -49
  17. package/dist/controller-registry.js.map +1 -1
  18. package/dist/database-provider.d.ts +0 -0
  19. package/dist/database-provider.d.ts.map +0 -0
  20. package/dist/database-provider.js +0 -0
  21. package/dist/database-provider.js.map +1 -1
  22. package/dist/hnsw-index.d.ts +0 -0
  23. package/dist/hnsw-index.d.ts.map +1 -1
  24. package/dist/hnsw-index.js +0 -0
  25. package/dist/hnsw-index.js.map +1 -1
  26. package/dist/index.d.ts +0 -22
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +0 -19
  29. package/dist/index.js.map +1 -1
  30. package/dist/knowledge/document-chunker.d.ts +0 -0
  31. package/dist/knowledge/document-chunker.d.ts.map +0 -0
  32. package/dist/knowledge/document-chunker.js +0 -0
  33. package/dist/knowledge/document-chunker.js.map +1 -1
  34. package/dist/knowledge/index.d.ts +0 -0
  35. package/dist/knowledge/index.d.ts.map +0 -0
  36. package/dist/knowledge/index.js +0 -0
  37. package/dist/knowledge/index.js.map +0 -0
  38. package/dist/knowledge/knowledge-retriever.d.ts +0 -0
  39. package/dist/knowledge/knowledge-retriever.d.ts.map +1 -1
  40. package/dist/knowledge/knowledge-retriever.js +0 -0
  41. package/dist/knowledge/knowledge-retriever.js.map +1 -1
  42. package/dist/knowledge/knowledge-store.d.ts +0 -0
  43. package/dist/knowledge/knowledge-store.d.ts.map +1 -1
  44. package/dist/knowledge/knowledge-store.js +0 -0
  45. package/dist/knowledge/knowledge-store.js.map +0 -0
  46. package/dist/lancedb-backend.d.ts +5 -0
  47. package/dist/lancedb-backend.d.ts.map +1 -1
  48. package/dist/lancedb-backend.js +70 -12
  49. package/dist/lancedb-backend.js.map +1 -1
  50. package/dist/math-utils.d.ts +0 -0
  51. package/dist/math-utils.d.ts.map +0 -0
  52. package/dist/math-utils.js +0 -0
  53. package/dist/math-utils.js.map +0 -0
  54. package/dist/migration.d.ts +1 -0
  55. package/dist/migration.d.ts.map +1 -1
  56. package/dist/migration.js +50 -21
  57. package/dist/migration.js.map +1 -1
  58. package/dist/prompt-version-store.d.ts +0 -0
  59. package/dist/prompt-version-store.d.ts.map +1 -1
  60. package/dist/prompt-version-store.js +0 -0
  61. package/dist/prompt-version-store.js.map +0 -0
  62. package/dist/query-builder.d.ts +0 -0
  63. package/dist/query-builder.d.ts.map +1 -1
  64. package/dist/query-builder.js +0 -0
  65. package/dist/query-builder.js.map +1 -1
  66. package/dist/sqlite-backend.d.ts +0 -0
  67. package/dist/sqlite-backend.d.ts.map +1 -1
  68. package/dist/sqlite-backend.js +38 -9
  69. package/dist/sqlite-backend.js.map +1 -1
  70. package/dist/sqljs-backend.d.ts +1 -0
  71. package/dist/sqljs-backend.d.ts.map +1 -1
  72. package/dist/sqljs-backend.js +64 -13
  73. package/dist/sqljs-backend.js.map +1 -1
  74. package/dist/types/checkpoint.d.ts +0 -0
  75. package/dist/types/checkpoint.d.ts.map +0 -0
  76. package/dist/types/checkpoint.js +0 -0
  77. package/dist/types/checkpoint.js.map +0 -0
  78. package/dist/types.d.ts +1 -4
  79. package/dist/types.d.ts.map +1 -1
  80. package/dist/types.js +0 -0
  81. package/dist/types.js.map +1 -1
  82. package/package.json +12 -13
  83. package/dist/agent-memory-scope.d.ts +0 -131
  84. package/dist/agent-memory-scope.d.ts.map +0 -1
  85. package/dist/agent-memory-scope.js +0 -230
  86. package/dist/agent-memory-scope.js.map +0 -1
  87. package/dist/auto-memory-bridge.d.ts +0 -230
  88. package/dist/auto-memory-bridge.d.ts.map +0 -1
  89. package/dist/auto-memory-bridge.js +0 -736
  90. package/dist/auto-memory-bridge.js.map +0 -1
  91. package/dist/diskann-backend.d.ts +0 -126
  92. package/dist/diskann-backend.d.ts.map +0 -1
  93. package/dist/diskann-backend.js +0 -336
  94. package/dist/diskann-backend.js.map +0 -1
  95. package/dist/episodic-store.d.ts +0 -58
  96. package/dist/episodic-store.d.ts.map +0 -1
  97. package/dist/episodic-store.js +0 -160
  98. package/dist/episodic-store.js.map +0 -1
  99. package/dist/learning-bridge.d.ts +0 -180
  100. package/dist/learning-bridge.d.ts.map +0 -1
  101. package/dist/learning-bridge.js +0 -566
  102. package/dist/learning-bridge.js.map +0 -1
  103. package/dist/memory-graph.d.ts +0 -125
  104. package/dist/memory-graph.d.ts.map +0 -1
  105. package/dist/memory-graph.js +0 -429
  106. package/dist/memory-graph.js.map +0 -1
  107. package/dist/partitioned-hnsw.d.ts +0 -65
  108. package/dist/partitioned-hnsw.d.ts.map +0 -1
  109. package/dist/partitioned-hnsw.js +0 -209
  110. package/dist/partitioned-hnsw.js.map +0 -1
  111. package/dist/procedural/action-record.d.ts +0 -19
  112. package/dist/procedural/action-record.d.ts.map +0 -1
  113. package/dist/procedural/action-record.js +0 -51
  114. package/dist/procedural/action-record.js.map +0 -1
  115. package/dist/procedural/action-sequence-extractor.d.ts +0 -25
  116. package/dist/procedural/action-sequence-extractor.d.ts.map +0 -1
  117. package/dist/procedural/action-sequence-extractor.js +0 -91
  118. package/dist/procedural/action-sequence-extractor.js.map +0 -1
  119. package/dist/procedural/index.d.ts +0 -14
  120. package/dist/procedural/index.d.ts.map +0 -1
  121. package/dist/procedural/index.js +0 -13
  122. package/dist/procedural/index.js.map +0 -1
  123. package/dist/procedural/learned-skill.d.ts +0 -17
  124. package/dist/procedural/learned-skill.d.ts.map +0 -1
  125. package/dist/procedural/learned-skill.js +0 -73
  126. package/dist/procedural/learned-skill.js.map +0 -1
  127. package/dist/procedural/skill-registry.d.ts +0 -25
  128. package/dist/procedural/skill-registry.d.ts.map +0 -1
  129. package/dist/procedural/skill-registry.js +0 -56
  130. package/dist/procedural/skill-registry.js.map +0 -1
  131. package/dist/procedural/types.d.ts +0 -67
  132. package/dist/procedural/types.d.ts.map +0 -1
  133. package/dist/procedural/types.js +0 -15
  134. package/dist/procedural/types.js.map +0 -1
  135. package/dist/tier-manager.d.ts +0 -79
  136. package/dist/tier-manager.d.ts.map +0 -1
  137. package/dist/tier-manager.js +0 -173
  138. package/dist/tier-manager.js.map +0 -1
  139. package/dist/tiers/contextual.d.ts +0 -45
  140. package/dist/tiers/contextual.d.ts.map +0 -1
  141. package/dist/tiers/contextual.js +0 -109
  142. package/dist/tiers/contextual.js.map +0 -1
  143. package/dist/tiers/entity.d.ts +0 -46
  144. package/dist/tiers/entity.d.ts.map +0 -1
  145. package/dist/tiers/entity.js +0 -106
  146. package/dist/tiers/entity.js.map +0 -1
  147. package/dist/tiers/index.d.ts +0 -4
  148. package/dist/tiers/index.d.ts.map +0 -1
  149. package/dist/tiers/index.js +0 -4
  150. package/dist/tiers/index.js.map +0 -1
  151. package/dist/tiers/short-term.d.ts +0 -42
  152. package/dist/tiers/short-term.d.ts.map +0 -1
  153. package/dist/tiers/short-term.js +0 -90
  154. package/dist/tiers/short-term.js.map +0 -1
@@ -1,56 +0,0 @@
1
- /**
2
- * SkillRegistry — JSONL-backed registry for learned skills.
3
- *
4
- * Part of Task 45 — Procedural Memory.
5
- */
6
- import { appendFileSync, readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs';
7
- import { dirname } from 'path';
8
- export class SkillRegistry {
9
- filePath;
10
- constructor(filePath) {
11
- this.filePath = filePath;
12
- const dir = dirname(filePath);
13
- if (!existsSync(dir)) {
14
- mkdirSync(dir, { recursive: true });
15
- }
16
- }
17
- /** Register a new learned skill */
18
- register(skill) {
19
- appendFileSync(this.filePath, JSON.stringify(skill) + '\n', 'utf-8');
20
- }
21
- /** List all registered skills */
22
- list() {
23
- if (!existsSync(this.filePath))
24
- return [];
25
- const content = readFileSync(this.filePath, 'utf-8').trim();
26
- if (!content)
27
- return [];
28
- return content.split('\n').filter(Boolean).map((line) => JSON.parse(line));
29
- }
30
- /** Get a skill by ID */
31
- get(skillId) {
32
- return this.list().find((s) => s.skillId === skillId);
33
- }
34
- /**
35
- * Find a skill that matches the same fingerprint (agentSlug + tool sequence).
36
- * Fingerprint = agentSlug + sorted tool names joined by " -> ".
37
- */
38
- findByFingerprint(skill) {
39
- const fp = this.buildFingerprint(skill);
40
- return this.list().find((s) => this.buildFingerprint(s) === fp);
41
- }
42
- /** Update a skill by ID (rewrites the entire file) */
43
- update(skillId, updated) {
44
- const all = this.list();
45
- const idx = all.findIndex((s) => s.skillId === skillId);
46
- if (idx === -1)
47
- return;
48
- all[idx] = updated;
49
- writeFileSync(this.filePath, all.map((s) => JSON.stringify(s)).join('\n') + '\n', 'utf-8');
50
- }
51
- buildFingerprint(skill) {
52
- const toolChain = skill.actionSequence.map((a) => a.toolName).join(' -> ');
53
- return `${skill.agentSlug}::${toolChain}`;
54
- }
55
- }
56
- //# sourceMappingURL=skill-registry.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"skill-registry.js","sourceRoot":"","sources":["../../src/procedural/skill-registry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACxF,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAG/B,MAAM,OAAO,aAAa;IAChB,QAAQ,CAAS;IAEzB,YAAY,QAAgB;QAC1B,IA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BAAgB,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,sDAAsD;IACtD,MAAM,CAAC,OAAe,EAAE,OAAqB;QAC3C,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QACxB,MAAM,GAAG,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC;QACxD,IAAI,GAAG,KAAK,CAAC,CAAC;YAAE,OAAO;QACvB,GAAG,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC;QACnB,aAAa,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,CAAC,CAAC;IAC7F,CAAC;IAEO,gBAAgB,CAAC,KAAmB;QAC1C,MAAM,SAAS,GAAG,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC3E,OAAO,GAAG,KAAK,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;IAC5C,CAAC;CACF"}
@@ -1,67 +0,0 @@
1
- /**
2
- * Procedural Memory Types
3
- *
4
- * Types for learning from successful agent executions.
5
- * Part of Task 45 — Procedural Memory.
6
- */
7
- /** Outcome of a single tool action */
8
- export type ActionOutcome = 'success' | 'failure' | 'partial';
9
- /** A single recorded action within an agent run */
10
- export interface ActionRecord {
11
- recordId: string;
12
- runId: string;
13
- agentId: string;
14
- agentSlug: string;
15
- toolName: string;
16
- toolInput: Record<string, unknown>;
17
- toolOutput?: string;
18
- outcome: ActionOutcome;
19
- durationMs: number;
20
- qualityScore?: number;
21
- timestamp: string;
22
- }
23
- /** Configuration for extracting learned skills from action records */
24
- export interface ExtractionConfig {
25
- /** Minimum number of successful occurrences before extraction (default 3) */
26
- minSuccessCount: number;
27
- /** Minimum average quality score threshold (default 0.75) */
28
- minAvgQualityScore: number;
29
- /** Maximum actions in a sequence (default 12) */
30
- maxSequenceLength: number;
31
- /** How far back to look in days (default 30) */
32
- lookbackDays: number;
33
- /** Minimum similarity for grouping sequences (default 0.85) */
34
- minSimilarityForGrouping: number;
35
- }
36
- /** Default extraction configuration */
37
- export declare const DEFAULT_EXTRACTION_CONFIG: ExtractionConfig;
38
- /** Trigger condition for a learned skill */
39
- export interface SkillTrigger {
40
- pattern: string;
41
- mode: 'exact' | 'semantic';
42
- minConfidence: number;
43
- }
44
- /** A learned skill extracted from repeated successful executions */
45
- export interface LearnedSkill {
46
- skillId: string;
47
- name: string;
48
- agentSlug: string;
49
- trigger: SkillTrigger;
50
- actionSequence: ActionRecord[];
51
- successCount: number;
52
- avgQualityScore: number;
53
- sourceRunIds: string[];
54
- createdAt: string;
55
- lastUpdatedAt: string;
56
- version: number;
57
- }
58
- /** A group of similar action sequences discovered by the extractor */
59
- export interface ActionSequenceGroup {
60
- agentSlug: string;
61
- fingerprint: string;
62
- sequences: ActionRecord[][];
63
- successCount: number;
64
- avgQualityScore: number;
65
- runIds: string[];
66
- }
67
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/procedural/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,sCAAsC;AACtC,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAE9D,mDAAmD;AACnD,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,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,CAAC;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB"}
@@ -1,15 +0,0 @@
1
- /**
2
- * Procedural Memory Types
3
- *
4
- * Types for learning from successful agent executions.
5
- * Part of Task 45 — Procedural Memory.
6
- */
7
- /** Default extraction configuration */
8
- export const DEFAULT_EXTRACTION_CONFIG = {
9
- minSuccessCount: 3,
10
- minAvgQualityScore: 0.75,
11
- maxSequenceLength: 12,
12
- lookbackDays: 30,
13
- minSimilarityForGrouping: 0.85,
14
- };
15
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/procedural/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAkCH,uCAAuC;AACvC,MAAM,CAAC,MAAM,yBAAyB,GAAqB;IACzD,eAAe,EAAE,CAAC;IAClB,kBAAkB,EAAE,IAAI;IACxB,iBAAiB,EAAE,EAAE;IACrB,YAAY,EAAE,EAAE;IAChB,wBAAwB,EAAE,IAAI;CAC/B,CAAC"}
@@ -1,79 +0,0 @@
1
- /**
2
- * TierManager — Routes memory operations to the correct tier (Task 09)
3
- *
4
- * Coordinates short-term (in-memory), long-term (persistent backend),
5
- * entity (JSON-lines KV), and contextual (session summaries) tiers.
6
- *
7
- * @module v1/memory/tier-manager
8
- */
9
- import type { IMemoryBackend, MemoryEntry, MemoryEntryInput, MemoryTier, TierManagerConfig } from './types.js';
10
- import { ShortTermMemory } from './tiers/short-term.js';
11
- import { EntityMemory } from './tiers/entity.js';
12
- import { ContextualMemory } from './tiers/contextual.js';
13
- import { PartitionedHNSW, type PartitionedHNSWConfig } from './partitioned-hnsw.js';
14
- import { DiskAnnBackend, type DiskAnnBackendConfig } from './diskann-backend.js';
15
- export declare class TierManager {
16
- readonly shortTerm: ShortTermMemory;
17
- readonly entity: EntityMemory;
18
- readonly contextual: ContextualMemory;
19
- /** Timestamp-partitioned HNSW for temporally-local semantic search.
20
- * Source: ICDE 2025 Timestamp-Partitioned HNSW */
21
- readonly partitionedIndex: PartitionedHNSW;
22
- /**
23
- * Optional DiskANN backend for large-scale ANN search (Tier 4).
24
- * Activated by passing `diskAnnConfig` to the constructor.
25
- * Wraps the longTermBackend so all CRUD still flows through the delegate;
26
- * `search()` uses the disk-resident graph + quantised beam search.
27
- * Source: arXiv:2305.04359
28
- */
29
- readonly diskann?: DiskAnnBackend;
30
- private readonly longTermBackend;
31
- private readonly config;
32
- constructor(longTermBackend: IMemoryBackend, config?: Partial<TierManagerConfig>, partitionedHNSWConfig?: PartitionedHNSWConfig, diskAnnConfig?: DiskAnnBackendConfig);
33
- /**
34
- * Store a memory entry, routing to the correct tier.
35
- *
36
- * - `short-term` goes to the in-memory buffer
37
- * - `long-term` (or unspecified) goes to the persistent backend
38
- *
39
- * All entries are also indexed in the timestamp-partitioned HNSW for
40
- * temporally-local search (ICDE 2025).
41
- *
42
- * Returns the generated entry ID.
43
- */
44
- store(input: MemoryEntryInput & {
45
- tier?: MemoryTier;
46
- }): Promise<string>;
47
- /**
48
- * Merged search across partitioned HNSW, short-term buffer, long-term backend,
49
- * and (when configured) DiskANN beam search.
50
- *
51
- * Order of precedence:
52
- * 1. Partitioned HNSW (newest buckets first — temporal locality)
53
- * 2. Short-term in-memory buffer
54
- * 3. Long-term persistent backend (metadata / hybrid query)
55
- * 4. DiskANN ANN search — only when diskAnnConfig was supplied; uses a
56
- * character-frequency proxy embedding as the query vector (approximation)
57
- *
58
- * Results are deduplicated by entry ID.
59
- */
60
- search(query: string, limit?: number): Promise<MemoryEntry[]>;
61
- /**
62
- * Derive a fixed-length Float32 proxy embedding from plain text.
63
- *
64
- * Maps character byte values into a 128-dimensional L2-normalised vector.
65
- * This is NOT a semantic embedding — it is solely used to drive DiskANN
66
- * beam traversal when no real embedding generator is available at this
67
- * call site. Quality of DiskANN results improves dramatically when entries
68
- * are stored with real semantic embeddings.
69
- */
70
- private static textToVec;
71
- /**
72
- * Flush the short-term buffer into the long-term backend.
73
- * Promoted entries are also added to the partitioned HNSW index so they
74
- * remain visible in partition-based searches after promotion.
75
- * Returns the number of entries promoted.
76
- */
77
- flushShortTerm(): Promise<number>;
78
- }
79
- //# sourceMappingURL=tier-manager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tier-manager.d.ts","sourceRoot":"","sources":["../src/tier-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,KAAK,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,KAAK,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEjF,qBAAa,WAAW;IACtB,QAAQ,CAAC,SAAS,EAAE,eAAe,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAC;IAEtC;uDACmD;IACnD,QAAQ,CAAC,gBAAgB,EAAE,eAAe,CAAC;IAE3C;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC;IAElC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAiB;IACjD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoB;gBAGzC,eAAe,EAAE,cAAc,EAC/B,MAAM,GAAE,OAAO,CAAC,iBAAiB,CAAM,EACvC,qBAAqB,GAAE,qBAA0B,EACjD,aAAa,CAAC,EAAE,oBAAoB;IA4BtC;;;;;;;;;;OAUG;IACG,KAAK,CAAC,KAAK,EAAE,gBAAgB,GAAG;QAAE,IAAI,CAAC,EAAE,UAAU,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAgB7E;;;;;;;;;;;;OAYG;IACG,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAmD/D;;;;;;;;OAQG;IACH,OAAO,CAAC,MAAM,CAAC,SAAS;IAYxB;;;;;OAKG;IACG,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;CAUxC"}
@@ -1,173 +0,0 @@
1
- /**
2
- * TierManager — Routes memory operations to the correct tier (Task 09)
3
- *
4
- * Coordinates short-term (in-memory), long-term (persistent backend),
5
- * entity (JSON-lines KV), and contextual (session summaries) tiers.
6
- *
7
- * @module v1/memory/tier-manager
8
- */
9
- import { createDefaultEntry } from './types.js';
10
- import { ShortTermMemory } from './tiers/short-term.js';
11
- import { EntityMemory } from './tiers/entity.js';
12
- import { ContextualMemory } from './tiers/contextual.js';
13
- import { PartitionedHNSW } from './partitioned-hnsw.js';
14
- import { DiskAnnBackend } from './diskann-backend.js';
15
- export class TierManager {
16
- shortTerm;
17
- entity;
18
- contextual;
19
- /** Timestamp-partitioned HNSW for temporally-local semantic search.
20
- * Source: ICDE 2025 Timestamp-Partitioned HNSW */
21
- partitionedIndex;
22
- /**
23
- * Optional DiskANN backend for large-scale ANN search (Tier 4).
24
- * Activated by passing `diskAnnConfig` to the constructor.
25
- * Wraps the longTermBackend so all CRUD still flows through the delegate;
26
- * `search()` uses the disk-resident graph + quantised beam search.
27
- * Source: arXiv:2305.04359
28
- */
29
- diskann;
30
- longTermBackend;
31
- config;
32
- constructor(longTermBackend, config = {}, partitionedHNSWConfig = {}, diskAnnConfig) {
33
- this.config = {
34
- shortTermCapacity: config.shortTermCapacity ?? 500,
35
- entityStorePath: config.entityStorePath ?? './data/memory/entities.jsonl',
36
- contextualNamespace: config.contextualNamespace ?? 'contextual-summaries',
37
- autoFlushOnSessionEnd: config.autoFlushOnSessionEnd ?? true,
38
- };
39
- // If diskAnnConfig is supplied, wrap longTermBackend in a DiskAnnBackend.
40
- // All CRUD still delegates to the original backend; search() uses DiskANN.
41
- if (diskAnnConfig) {
42
- const diskannBackend = new DiskAnnBackend(longTermBackend, diskAnnConfig);
43
- this.diskann = diskannBackend;
44
- this.longTermBackend = diskannBackend;
45
- }
46
- else {
47
- this.longTermBackend = longTermBackend;
48
- }
49
- this.shortTerm = new ShortTermMemory(this.config.shortTermCapacity);
50
- this.entity = new EntityMemory(this.config.entityStorePath);
51
- this.contextual = new ContextualMemory(this.longTermBackend, this.config.contextualNamespace);
52
- this.partitionedIndex = new PartitionedHNSW(partitionedHNSWConfig);
53
- }
54
- /**
55
- * Store a memory entry, routing to the correct tier.
56
- *
57
- * - `short-term` goes to the in-memory buffer
58
- * - `long-term` (or unspecified) goes to the persistent backend
59
- *
60
- * All entries are also indexed in the timestamp-partitioned HNSW for
61
- * temporally-local search (ICDE 2025).
62
- *
63
- * Returns the generated entry ID.
64
- */
65
- async store(input) {
66
- const entry = createDefaultEntry(input);
67
- const tier = input.tier ?? 'long-term';
68
- if (tier === 'short-term') {
69
- this.shortTerm.store(entry);
70
- }
71
- else {
72
- await this.longTermBackend.store(entry);
73
- }
74
- // Index in partitioned HNSW for temporal-locality search
75
- this.partitionedIndex.add(entry);
76
- return entry.id;
77
- }
78
- /**
79
- * Merged search across partitioned HNSW, short-term buffer, long-term backend,
80
- * and (when configured) DiskANN beam search.
81
- *
82
- * Order of precedence:
83
- * 1. Partitioned HNSW (newest buckets first — temporal locality)
84
- * 2. Short-term in-memory buffer
85
- * 3. Long-term persistent backend (metadata / hybrid query)
86
- * 4. DiskANN ANN search — only when diskAnnConfig was supplied; uses a
87
- * character-frequency proxy embedding as the query vector (approximation)
88
- *
89
- * Results are deduplicated by entry ID.
90
- */
91
- async search(query, limit = 10) {
92
- // 1. Partitioned HNSW — nearest neighbours in recent time buckets first
93
- const partitionedResults = this.partitionedIndex.search(null, // no raw embedding at this call-site; uses text fallback
94
- query, limit);
95
- // 2. Short-term results (synchronous)
96
- const shortResults = this.shortTerm.search(query, limit);
97
- // 3. Long-term results via the backend query interface
98
- const longResults = await this.longTermBackend.query({
99
- type: 'hybrid',
100
- content: query,
101
- limit,
102
- });
103
- // 4. DiskANN ANN search (activated when diskann is configured)
104
- // Uses a character-frequency proxy embedding to drive beam search.
105
- // Re-ranking in DiskAnnBackend.search() uses the actual stored embeddings.
106
- let annEntries = [];
107
- if (this.diskann) {
108
- try {
109
- const proxyVec = TierManager.textToVec(query);
110
- const annResults = await this.diskann.search(proxyVec, { k: limit });
111
- annEntries = annResults.map(r => r.entry);
112
- }
113
- catch {
114
- // Non-fatal; DiskANN is best-effort
115
- }
116
- }
117
- // Deduplicate by id: partitioned > short-term > long-term > diskann
118
- // Iterate each source directly to avoid allocating a combined array and to
119
- // enable early-exit between sources once the limit is reached.
120
- const seen = new Set();
121
- const merged = [];
122
- outer: for (const batch of [partitionedResults, shortResults, longResults, annEntries]) {
123
- for (const entry of batch) {
124
- if (!seen.has(entry.id)) {
125
- seen.add(entry.id);
126
- merged.push(entry);
127
- }
128
- if (merged.length >= limit)
129
- break outer;
130
- }
131
- }
132
- return merged;
133
- }
134
- /**
135
- * Derive a fixed-length Float32 proxy embedding from plain text.
136
- *
137
- * Maps character byte values into a 128-dimensional L2-normalised vector.
138
- * This is NOT a semantic embedding — it is solely used to drive DiskANN
139
- * beam traversal when no real embedding generator is available at this
140
- * call site. Quality of DiskANN results improves dramatically when entries
141
- * are stored with real semantic embeddings.
142
- */
143
- static textToVec(text, dims = 128) {
144
- const vec = new Float32Array(dims);
145
- for (let i = 0; i < text.length; i++) {
146
- vec[i % dims] += text.charCodeAt(i) / 255;
147
- }
148
- let norm = 0;
149
- for (const v of vec)
150
- norm += v * v;
151
- norm = Math.sqrt(norm) || 1;
152
- for (let i = 0; i < dims; i++)
153
- vec[i] /= norm;
154
- return vec;
155
- }
156
- /**
157
- * Flush the short-term buffer into the long-term backend.
158
- * Promoted entries are also added to the partitioned HNSW index so they
159
- * remain visible in partition-based searches after promotion.
160
- * Returns the number of entries promoted.
161
- */
162
- async flushShortTerm() {
163
- // Snapshot the entries before flush so we can index them afterwards.
164
- // ShortTermMemory.flush() clears the buffer, so we must read first.
165
- const toPromote = this.shortTerm.snapshot();
166
- const count = await this.shortTerm.flush(this.longTermBackend);
167
- for (const entry of toPromote) {
168
- this.partitionedIndex.add(entry);
169
- }
170
- return count;
171
- }
172
- }
173
- //# sourceMappingURL=tier-manager.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tier-manager.js","sourceRoot":"","sources":["../src/tier-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AASH,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,eAAe,EAA8B,MAAM,uBAAuB,CAAC;AACpF,OAAO,EAAE,cAAc,EAA6B,MAAM,sBAAsB,CAAC;AAEjF,MAAM,OAAO,WAAW;IACb,SAAS,CAAkB;IAC3B,MAAM,CAAe;IACrB,UAAU,CAAmB;IAEtC;uDACmD;IAC1C,gBAAgB,CAAkB;IAE3C;;;;;;OAMG;IACM,OAAO,CAAkB;IAEjB,eAAe,CAAiB;IAChC,MAAM,CAAoB;IAE3C,YACE,eAA+B,EAC/B,SAAqC,EAAE,EACvC,wBAA+C,EAAE,EACjD,aAAoC;QAEpC,IAAI,CAAC,MAAM,GAAG;YACZ,iBAAiB,EAAE,MAAM,CAAC,iBAAiB,IAAI,GAAG;YAClD,eAAe,EAAE,MAAM,CAAC,eAAe,IAAI,8BAA8B;YACzE,mBAAmB,EAAE,MAAM,CAAC,mBAAmB,IAAI,sBAAsB;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AC5C,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAC/D,KAAK,MAAM,KAAK,IAAI,SAAS,EAAE,CAAC;YAC9B,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACnC,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
@@ -1,45 +0,0 @@
1
- /**
2
- * ContextualMemory — Compressed session summaries (Task 09)
3
- *
4
- * Wraps an IMemoryBackend to persist session summaries and
5
- * provides token-budget-aware retrieval of relevant context.
6
- *
7
- * @module v1/memory/tiers/contextual
8
- */
9
- import type { IMemoryBackend } from '../types.js';
10
- export interface SessionSummary {
11
- sessionId: string;
12
- agentSlugs: string[];
13
- summary: string;
14
- tokenCount: number;
15
- createdAt: number;
16
- }
17
- export declare class ContextualMemory {
18
- private readonly backend;
19
- private summaries;
20
- private readonly namespace;
21
- private warmed;
22
- /** Cached newest-first sorted summary list. Invalidated on store. */
23
- private sortedCache;
24
- constructor(backend: IMemoryBackend, namespace?: string);
25
- /**
26
- * Load persisted summaries from the backend into the in-memory cache.
27
- * Called automatically before the first read so cross-session summaries
28
- * are visible without an explicit initialization step.
29
- */
30
- warm(): Promise<void>;
31
- /**
32
- * Persist a session summary both in the local map and the
33
- * backing memory store.
34
- */
35
- storeSummary(summary: SessionSummary): Promise<void>;
36
- /**
37
- * Retrieve summaries whose content matches the query (simple
38
- * substring match over the local cache), respecting a maximum
39
- * token budget. Summaries are returned newest-first.
40
- */
41
- retrieveContext(query: string, maxTokens?: number): Promise<string>;
42
- /** Look up a summary by session ID (local cache only). */
43
- getSummary(sessionId: string): SessionSummary | undefined;
44
- }
45
- //# sourceMappingURL=contextual.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"contextual.d.ts","sourceRoot":"","sources":["../../src/tiers/contextual.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAoB,MAAM,aAAa,CAAC;AAGpE,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,gBAAgB;IAQzB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAP1B,OAAO,CAAC,SAAS,CAA0C;IAC3D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,MAAM,CAAS;IACvB,qEAAqE;IACrE,OAAO,CAAC,WAAW,CAAiC;gBAGjC,OAAO,EAAE,cAAc,EACxC,SAAS,SAAyB;IAKpC;;;;OAIG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IA8B3B;;;OAGG;IACG,YAAY,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAsB1D;;;;OAIG;IACG,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,SAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IA0BvE,0DAA0D;IAC1D,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;CAG1D"}
@@ -1,109 +0,0 @@
1
- /**
2
- * ContextualMemory — Compressed session summaries (Task 09)
3
- *
4
- * Wraps an IMemoryBackend to persist session summaries and
5
- * provides token-budget-aware retrieval of relevant context.
6
- *
7
- * @module v1/memory/tiers/contextual
8
- */
9
- import { createDefaultEntry } from '../types.js';
10
- export class ContextualMemory {
11
- backend;
12
- summaries = new Map();
13
- namespace;
14
- warmed = false;
15
- /** Cached newest-first sorted summary list. Invalidated on store. */
16
- sortedCache = null;
17
- constructor(backend, namespace = 'contextual-summaries') {
18
- this.backend = backend;
19
- this.namespace = namespace;
20
- }
21
- /**
22
- * Load persisted summaries from the backend into the in-memory cache.
23
- * Called automatically before the first read so cross-session summaries
24
- * are visible without an explicit initialization step.
25
- */
26
- async warm() {
27
- if (this.warmed)
28
- return;
29
- this.warmed = true;
30
- try {
31
- const entries = await this.backend.query({
32
- type: 'hybrid',
33
- namespace: this.namespace,
34
- tags: ['session-summary'],
35
- limit: 10000,
36
- });
37
- for (const entry of entries) {
38
- const sessionId = entry.metadata?.sessionId;
39
- if (!sessionId || this.summaries.has(sessionId))
40
- continue;
41
- this.summaries.set(sessionId, {
42
- sessionId,
43
- agentSlugs: entry.metadata?.agentSlugs ?? [],
44
- summary: entry.content,
45
- tokenCount: entry.metadata?.tokenCount ?? 0,
46
- createdAt: entry.createdAt,
47
- });
48
- }
49
- this.sortedCache = null;
50
- }
51
- catch {
52
- // Backend unavailable — proceed with empty cache
53
- }
54
- }
55
- /**
56
- * Persist a session summary both in the local map and the
57
- * backing memory store.
58
- */
59
- async storeSummary(summary) {
60
- this.summaries.set(summary.sessionId, summary);
61
- this.sortedCache = null; // invalidate sort cache
62
- const input = {
63
- key: `ctx-summary:${summary.sessionId}`,
64
- content: summary.summary,
65
- namespace: this.namespace,
66
- tags: ['session-summary', ...summary.agentSlugs],
67
- metadata: {
68
- sessionId: summary.sessionId,
69
- agentSlugs: summary.agentSlugs,
70
- tokenCount: summary.tokenCount,
71
- },
72
- };
73
- const entry = createDefaultEntry(input);
74
- entry.createdAt = summary.createdAt;
75
- entry.updatedAt = summary.createdAt;
76
- await this.backend.store(entry);
77
- }
78
- /**
79
- * Retrieve summaries whose content matches the query (simple
80
- * substring match over the local cache), respecting a maximum
81
- * token budget. Summaries are returned newest-first.
82
- */
83
- async retrieveContext(query, maxTokens = 2000) {
84
- await this.warm();
85
- const lowerQuery = query.toLowerCase();
86
- if (!this.sortedCache) {
87
- this.sortedCache = Array.from(this.summaries.values()).sort((a, b) => b.createdAt - a.createdAt);
88
- }
89
- const sorted = this.sortedCache;
90
- const parts = [];
91
- let budget = maxTokens;
92
- for (const s of sorted) {
93
- if (budget <= 0)
94
- break;
95
- if (s.summary.toLowerCase().includes(lowerQuery) || lowerQuery === '') {
96
- if (s.tokenCount <= budget) {
97
- parts.push(s.summary);
98
- budget -= s.tokenCount;
99
- }
100
- }
101
- }
102
- return parts.join('\n\n');
103
- }
104
- /** Look up a summary by session ID (local cache only). */
105
- getSummary(sessionId) {
106
- return this.summaries.get(sessionId);
107
- }
108
- }
109
- //# sourceMappingURL=contextual.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"contextual.js","sourceRoot":"","sources":["../../src/tiers/contextual.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAUjD,MAAM,OAAO,gBAAgB;IAQR;IAPX,SAAS,GAAgC,IAAI,GAAG,EAAE,CAAC;IAC1C,SAAS,CAAS;IAC3B,MAAM,GAAG,KAAK,CAAC;IACvB,qEAAqE;IAC7D,WAAW,GAA4B,IAAI,CAAC;IAEpD,YACmB,OAAuB,EACxC,SAAS,GAAG,sBAAsB;QADjB,YAAO,GAAP,OAAO,CAAgB;QAGxC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,IAAI;QACR,IAAI,IAAI,CAAC,MAAM;YAAE,OAAO;QACxB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QAEnB,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;gBACvC,IAAI,EAAE,QAAQ;gBACd,SAAS,EAAE,IAAI,CAAC,SAAS;gBACzB,IAAI,EAAE,CAAC,iBAAiB,CAAC;gBACzB,KAAK,EAAE,KAAK;aACb,CAAC,CAAC;YAEH,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;gBAC5B,MAAM,SAAS,GAAG,KAAK,CAAC,QAAQ,EAAE,SAA+B,CAAC;gBAClE,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAA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key-value facts stored as JSON-lines (Task 09)
3
- *
4
- * Uses a simple `.jsonl` file for persistence (no native dependencies).
5
- * Each line is a JSON-serialised EntityFact. On mutation the full set is
6
- * rewritten — acceptable for the expected cardinality of entity facts.
7
- *
8
- * @module v1/memory/tiers/entity
9
- */
10
- export interface EntityFact {
11
- entity: string;
12
- factType: string;
13
- value: string;
14
- confidence: number;
15
- sourceRunId: string;
16
- createdAt: number;
17
- expiresAt?: number;
18
- }
19
- export declare class EntityMemory {
20
- private readonly dbPath;
21
- constructor(dbPath: string);
22
- /**
23
- * Store (or upsert) a fact. If a fact with the same (entity, factType)
24
- * already exists it is replaced.
25
- */
26
- store(fact: EntityFact): void;
27
- /**
28
- * Delete facts for an entity, optionally scoped to a factType.
29
- * Returns the number of facts removed.
30
- */
31
- delete(entity: string, factType?: string): number;
32
- /** Remove all facts whose expiresAt is in the past. */
33
- pruneExpired(): number;
34
- /**
35
- * Retrieve all non-expired facts for an entity,
36
- * sorted by confidence descending.
37
- */
38
- retrieve(entity: string): EntityFact[];
39
- /** Return all non-expired facts of a given type. */
40
- findByFactType(factType: string): EntityFact[];
41
- /** No-op for file-based storage. */
42
- close(): void;
43
- private readAll;
44
- private writeAll;
45
- }
46
- //# sourceMappingURL=entity.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../src/tiers/entity.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,MAAM,EAAE,MAAM;IAW1B;;;OAGG;IACH,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;IAa7B;;;OAGG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM;IAYjD,uDAAuD;IACvD,YAAY,IAAI,MAAM;IAatB;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,EAAE;IAWtC,oDAAoD;IACpD,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,EAAE;IAW9C,oCAAoC;IACpC,KAAK,IAAI,IAAI;IAMb,OAAO,CAAC,OAAO;IAUf,OAAO,CAAC,QAAQ;CAIjB"}