@monoes/memory 1.0.5 → 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.
- package/README.md +72 -840
- package/dist/atomic-file.d.ts +17 -0
- package/dist/atomic-file.d.ts.map +1 -0
- package/dist/atomic-file.js +27 -0
- package/dist/atomic-file.js.map +1 -0
- package/dist/cache-manager.d.ts +0 -0
- package/dist/cache-manager.d.ts.map +1 -1
- package/dist/cache-manager.js +0 -0
- package/dist/cache-manager.js.map +1 -1
- package/dist/checkpointer.d.ts +13 -0
- package/dist/checkpointer.d.ts.map +1 -1
- package/dist/checkpointer.js +69 -6
- package/dist/checkpointer.js.map +1 -1
- package/dist/controller-registry.d.ts +2 -8
- package/dist/controller-registry.d.ts.map +1 -1
- package/dist/controller-registry.js +4 -49
- package/dist/controller-registry.js.map +1 -1
- package/dist/database-provider.d.ts +0 -0
- package/dist/database-provider.d.ts.map +0 -0
- package/dist/database-provider.js +0 -0
- package/dist/database-provider.js.map +1 -1
- package/dist/hnsw-index.d.ts +0 -0
- package/dist/hnsw-index.d.ts.map +1 -1
- package/dist/hnsw-index.js +0 -0
- package/dist/hnsw-index.js.map +1 -1
- package/dist/index.d.ts +0 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -17
- package/dist/index.js.map +1 -1
- package/dist/knowledge/document-chunker.d.ts +0 -0
- package/dist/knowledge/document-chunker.d.ts.map +0 -0
- package/dist/knowledge/document-chunker.js +0 -0
- package/dist/knowledge/document-chunker.js.map +1 -1
- package/dist/knowledge/index.d.ts +0 -0
- package/dist/knowledge/index.d.ts.map +0 -0
- package/dist/knowledge/index.js +0 -0
- package/dist/knowledge/index.js.map +0 -0
- package/dist/knowledge/knowledge-retriever.d.ts +0 -0
- package/dist/knowledge/knowledge-retriever.d.ts.map +1 -1
- package/dist/knowledge/knowledge-retriever.js +0 -0
- package/dist/knowledge/knowledge-retriever.js.map +1 -1
- package/dist/knowledge/knowledge-store.d.ts +0 -0
- package/dist/knowledge/knowledge-store.d.ts.map +1 -1
- package/dist/knowledge/knowledge-store.js +0 -0
- package/dist/knowledge/knowledge-store.js.map +0 -0
- package/dist/lancedb-backend.d.ts +5 -0
- package/dist/lancedb-backend.d.ts.map +1 -1
- package/dist/lancedb-backend.js +70 -12
- package/dist/lancedb-backend.js.map +1 -1
- package/dist/math-utils.d.ts +0 -0
- package/dist/math-utils.d.ts.map +0 -0
- package/dist/math-utils.js +0 -0
- package/dist/math-utils.js.map +0 -0
- package/dist/migration.d.ts +1 -0
- package/dist/migration.d.ts.map +1 -1
- package/dist/migration.js +50 -21
- package/dist/migration.js.map +1 -1
- package/dist/prompt-version-store.d.ts +0 -0
- package/dist/prompt-version-store.d.ts.map +1 -1
- package/dist/prompt-version-store.js +0 -0
- package/dist/prompt-version-store.js.map +0 -0
- package/dist/query-builder.d.ts +0 -0
- package/dist/query-builder.d.ts.map +1 -1
- package/dist/query-builder.js +0 -0
- package/dist/query-builder.js.map +1 -1
- package/dist/sqlite-backend.d.ts +0 -0
- package/dist/sqlite-backend.d.ts.map +1 -1
- package/dist/sqlite-backend.js +38 -9
- package/dist/sqlite-backend.js.map +1 -1
- package/dist/sqljs-backend.d.ts +1 -0
- package/dist/sqljs-backend.d.ts.map +1 -1
- package/dist/sqljs-backend.js +64 -13
- package/dist/sqljs-backend.js.map +1 -1
- package/dist/types/checkpoint.d.ts +0 -0
- package/dist/types/checkpoint.d.ts.map +0 -0
- package/dist/types/checkpoint.js +0 -0
- package/dist/types/checkpoint.js.map +0 -0
- package/dist/types.d.ts +1 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -0
- package/dist/types.js.map +1 -1
- package/package.json +12 -13
- package/dist/agent-memory-scope.d.ts +0 -131
- package/dist/agent-memory-scope.d.ts.map +0 -1
- package/dist/agent-memory-scope.js +0 -230
- package/dist/agent-memory-scope.js.map +0 -1
- package/dist/auto-memory-bridge.d.ts +0 -230
- package/dist/auto-memory-bridge.d.ts.map +0 -1
- package/dist/auto-memory-bridge.js +0 -736
- package/dist/auto-memory-bridge.js.map +0 -1
- package/dist/episodic-store.d.ts +0 -58
- package/dist/episodic-store.d.ts.map +0 -1
- package/dist/episodic-store.js +0 -160
- package/dist/episodic-store.js.map +0 -1
- package/dist/learning-bridge.d.ts +0 -180
- package/dist/learning-bridge.d.ts.map +0 -1
- package/dist/learning-bridge.js +0 -566
- package/dist/learning-bridge.js.map +0 -1
- package/dist/memory-graph.d.ts +0 -125
- package/dist/memory-graph.d.ts.map +0 -1
- package/dist/memory-graph.js +0 -429
- package/dist/memory-graph.js.map +0 -1
- package/dist/procedural/action-record.d.ts +0 -19
- package/dist/procedural/action-record.d.ts.map +0 -1
- package/dist/procedural/action-record.js +0 -51
- package/dist/procedural/action-record.js.map +0 -1
- package/dist/procedural/action-sequence-extractor.d.ts +0 -25
- package/dist/procedural/action-sequence-extractor.d.ts.map +0 -1
- package/dist/procedural/action-sequence-extractor.js +0 -91
- package/dist/procedural/action-sequence-extractor.js.map +0 -1
- package/dist/procedural/index.d.ts +0 -14
- package/dist/procedural/index.d.ts.map +0 -1
- package/dist/procedural/index.js +0 -13
- package/dist/procedural/index.js.map +0 -1
- package/dist/procedural/learned-skill.d.ts +0 -17
- package/dist/procedural/learned-skill.d.ts.map +0 -1
- package/dist/procedural/learned-skill.js +0 -73
- package/dist/procedural/learned-skill.js.map +0 -1
- package/dist/procedural/skill-registry.d.ts +0 -25
- package/dist/procedural/skill-registry.d.ts.map +0 -1
- package/dist/procedural/skill-registry.js +0 -56
- package/dist/procedural/skill-registry.js.map +0 -1
- package/dist/procedural/types.d.ts +0 -67
- package/dist/procedural/types.d.ts.map +0 -1
- package/dist/procedural/types.js +0 -15
- package/dist/procedural/types.js.map +0 -1
- package/dist/tiers/contextual.d.ts +0 -45
- package/dist/tiers/contextual.d.ts.map +0 -1
- package/dist/tiers/contextual.js +0 -109
- package/dist/tiers/contextual.js.map +0 -1
- package/dist/tiers/entity.d.ts +0 -46
- package/dist/tiers/entity.d.ts.map +0 -1
- package/dist/tiers/entity.js +0 -106
- package/dist/tiers/entity.js.map +0 -1
- package/dist/tiers/index.d.ts +0 -4
- package/dist/tiers/index.d.ts.map +0 -1
- package/dist/tiers/index.js +0 -4
- package/dist/tiers/index.js.map +0 -1
- package/dist/tiers/short-term.d.ts +0 -42
- package/dist/tiers/short-term.d.ts.map +0 -1
- package/dist/tiers/short-term.js +0 -90
- package/dist/tiers/short-term.js.map +0 -1
package/dist/tiers/entity.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* EntityMemory — Named-entity 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"}
|
package/dist/tiers/entity.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* EntityMemory — Named-entity 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
|
-
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
11
|
-
import { dirname } from 'node:path';
|
|
12
|
-
export class EntityMemory {
|
|
13
|
-
dbPath;
|
|
14
|
-
constructor(dbPath) {
|
|
15
|
-
this.dbPath = dbPath;
|
|
16
|
-
// Ensure parent directory exists
|
|
17
|
-
const dir = dirname(this.dbPath);
|
|
18
|
-
if (!existsSync(dir)) {
|
|
19
|
-
mkdirSync(dir, { recursive: true });
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
// ---- Mutation ----
|
|
23
|
-
/**
|
|
24
|
-
* Store (or upsert) a fact. If a fact with the same (entity, factType)
|
|
25
|
-
* already exists it is replaced.
|
|
26
|
-
*/
|
|
27
|
-
store(fact) {
|
|
28
|
-
const all = this.readAll();
|
|
29
|
-
const idx = all.findIndex((f) => f.entity === fact.entity && f.factType === fact.factType);
|
|
30
|
-
if (idx >= 0) {
|
|
31
|
-
all[idx] = fact;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
all.push(fact);
|
|
35
|
-
}
|
|
36
|
-
this.writeAll(all);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Delete facts for an entity, optionally scoped to a factType.
|
|
40
|
-
* Returns the number of facts removed.
|
|
41
|
-
*/
|
|
42
|
-
delete(entity, factType) {
|
|
43
|
-
const all = this.readAll();
|
|
44
|
-
const remaining = all.filter((f) => {
|
|
45
|
-
if (f.entity !== entity)
|
|
46
|
-
return true;
|
|
47
|
-
if (factType !== undefined && f.factType !== factType)
|
|
48
|
-
return true;
|
|
49
|
-
return false;
|
|
50
|
-
});
|
|
51
|
-
const removed = all.length - remaining.length;
|
|
52
|
-
if (removed > 0)
|
|
53
|
-
this.writeAll(remaining);
|
|
54
|
-
return removed;
|
|
55
|
-
}
|
|
56
|
-
/** Remove all facts whose expiresAt is in the past. */
|
|
57
|
-
pruneExpired() {
|
|
58
|
-
const now = Date.now();
|
|
59
|
-
const all = this.readAll();
|
|
60
|
-
const remaining = all.filter((f) => f.expiresAt === undefined || f.expiresAt > now);
|
|
61
|
-
const removed = all.length - remaining.length;
|
|
62
|
-
if (removed > 0)
|
|
63
|
-
this.writeAll(remaining);
|
|
64
|
-
return removed;
|
|
65
|
-
}
|
|
66
|
-
// ---- Retrieval ----
|
|
67
|
-
/**
|
|
68
|
-
* Retrieve all non-expired facts for an entity,
|
|
69
|
-
* sorted by confidence descending.
|
|
70
|
-
*/
|
|
71
|
-
retrieve(entity) {
|
|
72
|
-
const now = Date.now();
|
|
73
|
-
return this.readAll()
|
|
74
|
-
.filter((f) => f.entity === entity &&
|
|
75
|
-
(f.expiresAt === undefined || f.expiresAt > now))
|
|
76
|
-
.sort((a, b) => b.confidence - a.confidence);
|
|
77
|
-
}
|
|
78
|
-
/** Return all non-expired facts of a given type. */
|
|
79
|
-
findByFactType(factType) {
|
|
80
|
-
const now = Date.now();
|
|
81
|
-
return this.readAll().filter((f) => f.factType === factType &&
|
|
82
|
-
(f.expiresAt === undefined || f.expiresAt > now));
|
|
83
|
-
}
|
|
84
|
-
// ---- Lifecycle ----
|
|
85
|
-
/** No-op for file-based storage. */
|
|
86
|
-
close() {
|
|
87
|
-
// intentionally empty
|
|
88
|
-
}
|
|
89
|
-
// ---- Private helpers ----
|
|
90
|
-
readAll() {
|
|
91
|
-
if (!existsSync(this.dbPath))
|
|
92
|
-
return [];
|
|
93
|
-
const raw = readFileSync(this.dbPath, 'utf-8').trim();
|
|
94
|
-
if (raw.length === 0)
|
|
95
|
-
return [];
|
|
96
|
-
return raw
|
|
97
|
-
.split('\n')
|
|
98
|
-
.filter(Boolean)
|
|
99
|
-
.map((line) => JSON.parse(line));
|
|
100
|
-
}
|
|
101
|
-
writeAll(facts) {
|
|
102
|
-
const data = facts.map((f) => JSON.stringify(f)).join('\n');
|
|
103
|
-
writeFileSync(this.dbPath, data.length > 0 ? data + '\n' : '', 'utf-8');
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
//# sourceMappingURL=entity.js.map
|
package/dist/tiers/entity.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../src/tiers/entity.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAYpC,MAAM,OAAO,YAAY;IACN,MAAM,CAAS;IAEhC,YAAY,MAAc;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,iCAAiC;QACjC,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACjC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACrB,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;IAED,qBAAqB;IAErB;;;OAGG;IACH,KAAK,CAAC,IAAgB;QACpB,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAC3B,MAAM,GAAG,GAAG,GAAG,CAAC,SAAS,CACvB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,QAAQ,CAChE,CAAC;QACF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AAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAe,CAAC,CAAC;IACnD,CAAC;IAEO,QAAQ,CAAC,KAAmB;QAClC,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC5D,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IAC1E,CAAC;CACF"}
|
package/dist/tiers/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tiers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/tiers/index.js
DELETED
package/dist/tiers/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tiers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAmB,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAuB,MAAM,iBAAiB,CAAC"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ShortTermMemory — In-memory Map-based buffer (Task 09)
|
|
3
|
-
*
|
|
4
|
-
* Holds entries for the current run only. Supports FIFO eviction
|
|
5
|
-
* when capacity is exceeded and bulk flush to a long-term backend.
|
|
6
|
-
*
|
|
7
|
-
* @module v1/memory/tiers/short-term
|
|
8
|
-
*/
|
|
9
|
-
import type { MemoryEntry, IMemoryBackend } from '../types.js';
|
|
10
|
-
export declare class ShortTermMemory {
|
|
11
|
-
/** Insertion-ordered map for FIFO eviction */
|
|
12
|
-
private buffer;
|
|
13
|
-
private readonly capacity;
|
|
14
|
-
constructor(capacity?: number);
|
|
15
|
-
/**
|
|
16
|
-
* Store an entry. If the buffer exceeds capacity the oldest entry
|
|
17
|
-
* (first inserted) is evicted.
|
|
18
|
-
*/
|
|
19
|
-
store(entry: MemoryEntry): void;
|
|
20
|
-
retrieve(id: string): MemoryEntry | undefined;
|
|
21
|
-
/**
|
|
22
|
-
* Simple substring search across entry content and key fields.
|
|
23
|
-
* Returns up to `limit` matches ordered by most-recent insertion.
|
|
24
|
-
*/
|
|
25
|
-
search(query: string, limit?: number): MemoryEntry[];
|
|
26
|
-
/**
|
|
27
|
-
* Return a stable copy of all currently buffered entries without mutating
|
|
28
|
-
* the buffer. Used by callers (e.g. TierManager) that need to process
|
|
29
|
-
* entries alongside a flush operation.
|
|
30
|
-
*/
|
|
31
|
-
snapshot(): MemoryEntry[];
|
|
32
|
-
/**
|
|
33
|
-
* Promote all buffered entries to the given long-term backend,
|
|
34
|
-
* then clear the buffer. Returns the number of flushed entries.
|
|
35
|
-
*/
|
|
36
|
-
flush(longTermStore: IMemoryBackend): Promise<number>;
|
|
37
|
-
/** Remove all entries from the buffer. */
|
|
38
|
-
clear(): void;
|
|
39
|
-
/** Current number of entries in the buffer. */
|
|
40
|
-
get size(): number;
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=short-term.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"short-term.d.ts","sourceRoot":"","sources":["../../src/tiers/short-term.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE/D,qBAAa,eAAe;IAC1B,8CAA8C;IAC9C,OAAO,CAAC,MAAM,CAAuC;IACrD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;gBAEtB,QAAQ,SAAM;IAM1B;;;OAGG;IACH,KAAK,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI;IAmB/B,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IAI7C;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,WAAW,EAAE;IAoBhD;;;;OAIG;IACH,QAAQ,IAAI,WAAW,EAAE;IAIzB;;;OAGG;IACG,KAAK,CAAC,aAAa,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;IAU3D,0CAA0C;IAC1C,KAAK,IAAI,IAAI;IAIb,+CAA+C;IAC/C,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"}
|
package/dist/tiers/short-term.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ShortTermMemory — In-memory Map-based buffer (Task 09)
|
|
3
|
-
*
|
|
4
|
-
* Holds entries for the current run only. Supports FIFO eviction
|
|
5
|
-
* when capacity is exceeded and bulk flush to a long-term backend.
|
|
6
|
-
*
|
|
7
|
-
* @module v1/memory/tiers/short-term
|
|
8
|
-
*/
|
|
9
|
-
export class ShortTermMemory {
|
|
10
|
-
/** Insertion-ordered map for FIFO eviction */
|
|
11
|
-
buffer = new Map();
|
|
12
|
-
capacity;
|
|
13
|
-
constructor(capacity = 500) {
|
|
14
|
-
this.capacity = capacity;
|
|
15
|
-
}
|
|
16
|
-
// ---- Mutation ----
|
|
17
|
-
/**
|
|
18
|
-
* Store an entry. If the buffer exceeds capacity the oldest entry
|
|
19
|
-
* (first inserted) is evicted.
|
|
20
|
-
*/
|
|
21
|
-
store(entry) {
|
|
22
|
-
// If key already exists, delete first so re-insertion moves it to end
|
|
23
|
-
if (this.buffer.has(entry.id)) {
|
|
24
|
-
this.buffer.delete(entry.id);
|
|
25
|
-
}
|
|
26
|
-
this.buffer.set(entry.id, entry);
|
|
27
|
-
// FIFO eviction — remove oldest entries until within capacity
|
|
28
|
-
while (this.buffer.size > this.capacity) {
|
|
29
|
-
const oldest = this.buffer.keys().next().value;
|
|
30
|
-
if (oldest !== undefined) {
|
|
31
|
-
this.buffer.delete(oldest);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
// ---- Retrieval ----
|
|
36
|
-
retrieve(id) {
|
|
37
|
-
return this.buffer.get(id);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Simple substring search across entry content and key fields.
|
|
41
|
-
* Returns up to `limit` matches ordered by most-recent insertion.
|
|
42
|
-
*/
|
|
43
|
-
search(query, limit = 10) {
|
|
44
|
-
const lowerQuery = query.toLowerCase();
|
|
45
|
-
const results = [];
|
|
46
|
-
// Iterate in reverse insertion order (newest first) without a full array copy
|
|
47
|
-
const entries = Array.from(this.buffer.values());
|
|
48
|
-
for (let i = entries.length - 1; i >= 0; i--) {
|
|
49
|
-
if (results.length >= limit)
|
|
50
|
-
break;
|
|
51
|
-
const entry = entries[i];
|
|
52
|
-
const haystack = `${entry.key} ${entry.content}`.toLowerCase();
|
|
53
|
-
if (haystack.includes(lowerQuery)) {
|
|
54
|
-
results.push(entry);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return results;
|
|
58
|
-
}
|
|
59
|
-
// ---- Lifecycle ----
|
|
60
|
-
/**
|
|
61
|
-
* Return a stable copy of all currently buffered entries without mutating
|
|
62
|
-
* the buffer. Used by callers (e.g. TierManager) that need to process
|
|
63
|
-
* entries alongside a flush operation.
|
|
64
|
-
*/
|
|
65
|
-
snapshot() {
|
|
66
|
-
return Array.from(this.buffer.values());
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Promote all buffered entries to the given long-term backend,
|
|
70
|
-
* then clear the buffer. Returns the number of flushed entries.
|
|
71
|
-
*/
|
|
72
|
-
async flush(longTermStore) {
|
|
73
|
-
const entries = Array.from(this.buffer.values());
|
|
74
|
-
if (entries.length === 0)
|
|
75
|
-
return 0;
|
|
76
|
-
await longTermStore.bulkInsert(entries);
|
|
77
|
-
const count = entries.length;
|
|
78
|
-
this.buffer.clear();
|
|
79
|
-
return count;
|
|
80
|
-
}
|
|
81
|
-
/** Remove all entries from the buffer. */
|
|
82
|
-
clear() {
|
|
83
|
-
this.buffer.clear();
|
|
84
|
-
}
|
|
85
|
-
/** Current number of entries in the buffer. */
|
|
86
|
-
get size() {
|
|
87
|
-
return this.buffer.size;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
//# sourceMappingURL=short-term.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"short-term.js","sourceRoot":"","sources":["../../src/tiers/short-term.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,MAAM,OAAO,eAAe;IAC1B,8CAA8C;IACtC,MAAM,GAA6B,IAAI,GAAG,EAAE,CAAC;IACpC,QAAQ,CAAS;IAElC,YAAY,QAAQ,GAAG,GAAG;QACxB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,qBAAqB;IAErB;;;OAGG;IACH,KAAK,CAAC,KAAkB;QACtB,sEAAsE;QACtE,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;YAC9B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC/B,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QAEjC,8DAA8D;QAC9D,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;YACxC,MAAM,MAAM,GA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