agent-working-memory 0.7.17 → 0.8.5
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 +156 -15
- package/dist/adapters/common.js +202 -202
- package/dist/adapters/http.js +22 -22
- package/dist/api/routes.d.ts +1 -1
- package/dist/api/routes.d.ts.map +1 -1
- package/dist/api/routes.js +258 -79
- package/dist/api/routes.js.map +1 -1
- package/dist/cli/migrate.d.ts +42 -0
- package/dist/cli/migrate.d.ts.map +1 -0
- package/dist/cli/migrate.js +268 -0
- package/dist/cli/migrate.js.map +1 -0
- package/dist/cli.js +147 -103
- package/dist/cli.js.map +1 -1
- package/dist/coordination/circuit-breaker.d.ts +24 -0
- package/dist/coordination/circuit-breaker.d.ts.map +1 -0
- package/dist/coordination/circuit-breaker.js +70 -0
- package/dist/coordination/circuit-breaker.js.map +1 -0
- package/dist/coordination/failure-modes.d.ts +21 -0
- package/dist/coordination/failure-modes.d.ts.map +1 -0
- package/dist/coordination/failure-modes.js +49 -0
- package/dist/coordination/failure-modes.js.map +1 -0
- package/dist/coordination/peer-decisions.js +7 -7
- package/dist/coordination/routes.d.ts.map +1 -1
- package/dist/coordination/routes.js +44 -1
- package/dist/coordination/routes.js.map +1 -1
- package/dist/coordination/schema.d.ts.map +1 -1
- package/dist/coordination/schema.js +18 -0
- package/dist/coordination/schema.js.map +1 -1
- package/dist/coordination/schemas.d.ts +9 -9
- package/dist/coordination/stale.d.ts +9 -1
- package/dist/coordination/stale.d.ts.map +1 -1
- package/dist/coordination/stale.js +53 -9
- package/dist/coordination/stale.js.map +1 -1
- package/dist/core/embeddings.d.ts +16 -10
- package/dist/core/embeddings.d.ts.map +1 -1
- package/dist/core/embeddings.js +54 -38
- package/dist/core/embeddings.js.map +1 -1
- package/dist/core/ml-worker-entry.d.ts +17 -0
- package/dist/core/ml-worker-entry.d.ts.map +1 -0
- package/dist/core/ml-worker-entry.js +193 -0
- package/dist/core/ml-worker-entry.js.map +1 -0
- package/dist/core/ml-worker.d.ts +59 -0
- package/dist/core/ml-worker.d.ts.map +1 -0
- package/dist/core/ml-worker.js +253 -0
- package/dist/core/ml-worker.js.map +1 -0
- package/dist/core/query-expander.d.ts +13 -15
- package/dist/core/query-expander.d.ts.map +1 -1
- package/dist/core/query-expander.js +48 -54
- package/dist/core/query-expander.js.map +1 -1
- package/dist/core/reranker.d.ts +9 -19
- package/dist/core/reranker.d.ts.map +1 -1
- package/dist/core/reranker.js +33 -35
- package/dist/core/reranker.js.map +1 -1
- package/dist/core/salience.d.ts +32 -5
- package/dist/core/salience.d.ts.map +1 -1
- package/dist/core/salience.js +201 -28
- package/dist/core/salience.js.map +1 -1
- package/dist/core/write-pipeline.d.ts +10 -2
- package/dist/core/write-pipeline.d.ts.map +1 -1
- package/dist/core/write-pipeline.js +218 -49
- package/dist/core/write-pipeline.js.map +1 -1
- package/dist/engine/activation.d.ts +2 -2
- package/dist/engine/activation.d.ts.map +1 -1
- package/dist/engine/activation.js +238 -115
- package/dist/engine/activation.js.map +1 -1
- package/dist/engine/confidence.d.ts +62 -0
- package/dist/engine/confidence.d.ts.map +1 -0
- package/dist/engine/confidence.js +100 -0
- package/dist/engine/confidence.js.map +1 -0
- package/dist/engine/connections.d.ts +47 -8
- package/dist/engine/connections.d.ts.map +1 -1
- package/dist/engine/connections.js +83 -22
- package/dist/engine/connections.js.map +1 -1
- package/dist/engine/consolidation-scheduler.d.ts +46 -10
- package/dist/engine/consolidation-scheduler.d.ts.map +1 -1
- package/dist/engine/consolidation-scheduler.js +170 -50
- package/dist/engine/consolidation-scheduler.js.map +1 -1
- package/dist/engine/consolidation.d.ts +16 -2
- package/dist/engine/consolidation.d.ts.map +1 -1
- package/dist/engine/consolidation.js +143 -44
- package/dist/engine/consolidation.js.map +1 -1
- package/dist/engine/eval.d.ts +2 -2
- package/dist/engine/eval.d.ts.map +1 -1
- package/dist/engine/eval.js +9 -9
- package/dist/engine/eval.js.map +1 -1
- package/dist/engine/eviction.d.ts +4 -4
- package/dist/engine/eviction.d.ts.map +1 -1
- package/dist/engine/eviction.js +15 -15
- package/dist/engine/eviction.js.map +1 -1
- package/dist/engine/retraction.d.ts +93 -5
- package/dist/engine/retraction.d.ts.map +1 -1
- package/dist/engine/retraction.js +238 -19
- package/dist/engine/retraction.js.map +1 -1
- package/dist/engine/staging.d.ts +1 -1
- package/dist/engine/staging.d.ts.map +1 -1
- package/dist/engine/staging.js +3 -3
- package/dist/engine/staging.js.map +1 -1
- package/dist/hooks/sidecar.d.ts +1 -1
- package/dist/hooks/sidecar.d.ts.map +1 -1
- package/dist/hooks/sidecar.js +4 -4
- package/dist/hooks/sidecar.js.map +1 -1
- package/dist/index.js +48 -31
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +167 -141
- package/dist/mcp.js.map +1 -1
- package/dist/storage/factory.d.ts +55 -0
- package/dist/storage/factory.d.ts.map +1 -0
- package/dist/storage/factory.js +135 -0
- package/dist/storage/factory.js.map +1 -0
- package/dist/storage/pglite-schema.d.ts +20 -0
- package/dist/storage/pglite-schema.d.ts.map +1 -0
- package/dist/storage/pglite-schema.js +165 -0
- package/dist/storage/pglite-schema.js.map +1 -0
- package/dist/storage/pglite.d.ts +187 -0
- package/dist/storage/pglite.d.ts.map +1 -0
- package/dist/storage/pglite.js +1114 -0
- package/dist/storage/pglite.js.map +1 -0
- package/dist/storage/sqlite.d.ts +117 -0
- package/dist/storage/sqlite.d.ts.map +1 -1
- package/dist/storage/sqlite.js +357 -8
- package/dist/storage/sqlite.js.map +1 -1
- package/dist/storage/store.d.ts +63 -0
- package/dist/storage/store.d.ts.map +1 -0
- package/dist/storage/store.js +27 -0
- package/dist/storage/store.js.map +1 -0
- package/dist/types/engram.d.ts +92 -2
- package/dist/types/engram.d.ts.map +1 -1
- package/dist/types/engram.js.map +1 -1
- package/package.json +3 -1
- package/src/adapters/claude-code.ts +218 -218
- package/src/adapters/codex.ts +252 -252
- package/src/adapters/common.ts +411 -411
- package/src/adapters/cursor.ts +135 -135
- package/src/adapters/http.ts +93 -93
- package/src/adapters/index.ts +31 -31
- package/src/adapters/types.ts +75 -75
- package/src/api/index.ts +3 -3
- package/src/api/routes.ts +970 -714
- package/src/cli/migrate.ts +307 -0
- package/src/cli.ts +755 -719
- package/src/coordination/circuit-breaker.ts +83 -0
- package/src/coordination/events.ts +90 -90
- package/src/coordination/failure-modes.ts +50 -0
- package/src/coordination/peer-decisions.ts +105 -105
- package/src/coordination/plugin-loader.ts +60 -60
- package/src/coordination/plugin.ts +44 -44
- package/src/coordination/routes.ts +56 -1
- package/src/coordination/schema.ts +13 -0
- package/src/coordination/stale.ts +80 -11
- package/src/coordination/types.ts +311 -311
- package/src/coordination/write-mutex.ts +69 -69
- package/src/core/auto-tagger.ts +168 -168
- package/src/core/decay.ts +63 -63
- package/src/core/embeddings.ts +110 -93
- package/src/core/index.ts +5 -5
- package/src/core/logger.ts +36 -36
- package/src/core/ml-worker-entry.ts +194 -0
- package/src/core/ml-worker.ts +281 -0
- package/src/core/query-expander.ts +122 -128
- package/src/core/reranker.ts +119 -125
- package/src/core/salience.ts +200 -33
- package/src/core/write-pipeline.ts +521 -343
- package/src/engine/activation.ts +235 -109
- package/src/engine/confidence.ts +120 -0
- package/src/engine/connections.ts +162 -103
- package/src/engine/consolidation-scheduler.ts +242 -125
- package/src/engine/consolidation.ts +138 -45
- package/src/engine/eval.ts +102 -102
- package/src/engine/eviction.ts +101 -101
- package/src/engine/index.ts +8 -8
- package/src/engine/retraction.ts +366 -116
- package/src/engine/staging.ts +74 -74
- package/src/hooks/sidecar.ts +5 -5
- package/src/index.ts +226 -212
- package/src/mcp.ts +1145 -1121
- package/src/storage/factory.ts +147 -0
- package/src/storage/index.ts +3 -3
- package/src/storage/pglite-schema.ts +166 -0
- package/src/storage/pglite.ts +1363 -0
- package/src/storage/sqlite.ts +402 -7
- package/src/storage/store.ts +80 -0
- package/src/types/agent.ts +67 -67
- package/src/types/checkpoint.ts +46 -46
- package/src/types/engram.ts +101 -3
- package/src/types/eval.ts +100 -100
- package/src/types/index.ts +6 -6
package/src/engine/eviction.ts
CHANGED
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
// Copyright 2026 Robert Winter / Complete Ideas
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
/**
|
|
4
|
-
* Eviction Engine — capacity enforcement and edge pruning.
|
|
5
|
-
*
|
|
6
|
-
* When memory budgets are exceeded:
|
|
7
|
-
* 1. Archive lowest-value active engrams
|
|
8
|
-
* 2. Delete expired staging engrams
|
|
9
|
-
* 3. Prune weakest edges when per-engram cap exceeded
|
|
10
|
-
* 4. Decay unused association weights over time
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import type { EngramStore } from '../storage/
|
|
14
|
-
import type { AgentConfig } from '../types/agent.js';
|
|
15
|
-
import { decayAssociation } from '../core/hebbian.js';
|
|
16
|
-
|
|
17
|
-
export class EvictionEngine {
|
|
18
|
-
private store: EngramStore;
|
|
19
|
-
|
|
20
|
-
constructor(store: EngramStore) {
|
|
21
|
-
this.store = store;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Check capacity budgets and evict if needed.
|
|
26
|
-
* Returns count of evicted engrams.
|
|
27
|
-
*/
|
|
28
|
-
enforceCapacity(agentId: string, config: AgentConfig): { evicted: number; edgesPruned: number } {
|
|
29
|
-
let evicted = 0;
|
|
30
|
-
let edgesPruned = 0;
|
|
31
|
-
|
|
32
|
-
// Active engram budget
|
|
33
|
-
const activeCount = this.store.getActiveCount(agentId);
|
|
34
|
-
if (activeCount > config.maxActiveEngrams) {
|
|
35
|
-
const excess = activeCount - config.maxActiveEngrams;
|
|
36
|
-
const candidates = this.store.getEvictionCandidates(agentId, excess);
|
|
37
|
-
for (const engram of candidates) {
|
|
38
|
-
this.store.updateStage(engram.id, 'archived');
|
|
39
|
-
evicted++;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Staging budget
|
|
44
|
-
const stagingCount = this.store.getStagingCount(agentId);
|
|
45
|
-
if (stagingCount > config.maxStagingEngrams) {
|
|
46
|
-
const expired = this.store.getExpiredStaging();
|
|
47
|
-
for (const engram of expired) {
|
|
48
|
-
this.store.deleteEngram(engram.id);
|
|
49
|
-
evicted++;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Edge pruning — cap per engram
|
|
54
|
-
const engrams = this.store.getEngramsByAgent(agentId, 'active');
|
|
55
|
-
for (const engram of engrams) {
|
|
56
|
-
const edgeCount = this.store.countAssociationsFor(engram.id);
|
|
57
|
-
if (edgeCount > config.maxEdgesPerEngram) {
|
|
58
|
-
// Remove weakest edges until under cap
|
|
59
|
-
let toRemove = edgeCount - config.maxEdgesPerEngram;
|
|
60
|
-
while (toRemove > 0) {
|
|
61
|
-
const weakest = this.store.getWeakestAssociation(engram.id);
|
|
62
|
-
if (weakest) {
|
|
63
|
-
this.store.deleteAssociation(weakest.id);
|
|
64
|
-
edgesPruned++;
|
|
65
|
-
}
|
|
66
|
-
toRemove--;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return { evicted, edgesPruned };
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Decay all association weights based on time since last activation.
|
|
76
|
-
* Run periodically (e.g., daily).
|
|
77
|
-
*/
|
|
78
|
-
decayEdges(agentId: string, halfLifeDays: number = 7): number {
|
|
79
|
-
const associations = this.store.getAllAssociations(agentId);
|
|
80
|
-
let decayed = 0;
|
|
81
|
-
|
|
82
|
-
for (const assoc of associations) {
|
|
83
|
-
const daysSince = (Date.now() - assoc.lastActivated.getTime()) / (1000 * 60 * 60 * 24);
|
|
84
|
-
if (daysSince < 0.5) continue; // Skip recently activated
|
|
85
|
-
|
|
86
|
-
const newWeight = decayAssociation(assoc.weight, daysSince, halfLifeDays);
|
|
87
|
-
if (newWeight < 0.01) {
|
|
88
|
-
// Below minimum useful weight — prune
|
|
89
|
-
this.store.deleteAssociation(assoc.id);
|
|
90
|
-
decayed++;
|
|
91
|
-
} else if (Math.abs(newWeight - assoc.weight) > 0.001) {
|
|
92
|
-
this.store.upsertAssociation(
|
|
93
|
-
assoc.fromEngramId, assoc.toEngramId, newWeight, assoc.type, assoc.confidence
|
|
94
|
-
);
|
|
95
|
-
decayed++;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return decayed;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
1
|
+
// Copyright 2026 Robert Winter / Complete Ideas
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
/**
|
|
4
|
+
* Eviction Engine — capacity enforcement and edge pruning.
|
|
5
|
+
*
|
|
6
|
+
* When memory budgets are exceeded:
|
|
7
|
+
* 1. Archive lowest-value active engrams
|
|
8
|
+
* 2. Delete expired staging engrams
|
|
9
|
+
* 3. Prune weakest edges when per-engram cap exceeded
|
|
10
|
+
* 4. Decay unused association weights over time
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { IEngramStore as EngramStore } from '../storage/store.js';
|
|
14
|
+
import type { AgentConfig } from '../types/agent.js';
|
|
15
|
+
import { decayAssociation } from '../core/hebbian.js';
|
|
16
|
+
|
|
17
|
+
export class EvictionEngine {
|
|
18
|
+
private store: EngramStore;
|
|
19
|
+
|
|
20
|
+
constructor(store: EngramStore) {
|
|
21
|
+
this.store = store;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Check capacity budgets and evict if needed.
|
|
26
|
+
* Returns count of evicted engrams.
|
|
27
|
+
*/
|
|
28
|
+
async enforceCapacity(agentId: string, config: AgentConfig): Promise<{ evicted: number; edgesPruned: number }> {
|
|
29
|
+
let evicted = 0;
|
|
30
|
+
let edgesPruned = 0;
|
|
31
|
+
|
|
32
|
+
// Active engram budget
|
|
33
|
+
const activeCount = await this.store.getActiveCount(agentId);
|
|
34
|
+
if (activeCount > config.maxActiveEngrams) {
|
|
35
|
+
const excess = activeCount - config.maxActiveEngrams;
|
|
36
|
+
const candidates = await this.store.getEvictionCandidates(agentId, excess);
|
|
37
|
+
for (const engram of candidates) {
|
|
38
|
+
await this.store.updateStage(engram.id, 'archived');
|
|
39
|
+
evicted++;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Staging budget
|
|
44
|
+
const stagingCount = await this.store.getStagingCount(agentId);
|
|
45
|
+
if (stagingCount > config.maxStagingEngrams) {
|
|
46
|
+
const expired = await this.store.getExpiredStaging();
|
|
47
|
+
for (const engram of expired) {
|
|
48
|
+
await this.store.deleteEngram(engram.id);
|
|
49
|
+
evicted++;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Edge pruning — cap per engram
|
|
54
|
+
const engrams = await this.store.getEngramsByAgent(agentId, 'active');
|
|
55
|
+
for (const engram of engrams) {
|
|
56
|
+
const edgeCount = await this.store.countAssociationsFor(engram.id);
|
|
57
|
+
if (edgeCount > config.maxEdgesPerEngram) {
|
|
58
|
+
// Remove weakest edges until under cap
|
|
59
|
+
let toRemove = edgeCount - config.maxEdgesPerEngram;
|
|
60
|
+
while (toRemove > 0) {
|
|
61
|
+
const weakest = await this.store.getWeakestAssociation(engram.id);
|
|
62
|
+
if (weakest) {
|
|
63
|
+
await this.store.deleteAssociation(weakest.id);
|
|
64
|
+
edgesPruned++;
|
|
65
|
+
}
|
|
66
|
+
toRemove--;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return { evicted, edgesPruned };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Decay all association weights based on time since last activation.
|
|
76
|
+
* Run periodically (e.g., daily).
|
|
77
|
+
*/
|
|
78
|
+
async decayEdges(agentId: string, halfLifeDays: number = 7): Promise<number> {
|
|
79
|
+
const associations = await this.store.getAllAssociations(agentId);
|
|
80
|
+
let decayed = 0;
|
|
81
|
+
|
|
82
|
+
for (const assoc of associations) {
|
|
83
|
+
const daysSince = (Date.now() - assoc.lastActivated.getTime()) / (1000 * 60 * 60 * 24);
|
|
84
|
+
if (daysSince < 0.5) continue; // Skip recently activated
|
|
85
|
+
|
|
86
|
+
const newWeight = decayAssociation(assoc.weight, daysSince, halfLifeDays);
|
|
87
|
+
if (newWeight < 0.01) {
|
|
88
|
+
// Below minimum useful weight — prune
|
|
89
|
+
await this.store.deleteAssociation(assoc.id);
|
|
90
|
+
decayed++;
|
|
91
|
+
} else if (Math.abs(newWeight - assoc.weight) > 0.001) {
|
|
92
|
+
await this.store.upsertAssociation(
|
|
93
|
+
assoc.fromEngramId, assoc.toEngramId, newWeight, assoc.type, assoc.confidence
|
|
94
|
+
);
|
|
95
|
+
decayed++;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return decayed;
|
|
100
|
+
}
|
|
101
|
+
}
|
package/src/engine/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
// Copyright 2026 Robert Winter / Complete Ideas
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
export * from './activation.js';
|
|
4
|
-
export * from './staging.js';
|
|
5
|
-
export * from './connections.js';
|
|
6
|
-
export * from './eviction.js';
|
|
7
|
-
export * from './retraction.js';
|
|
8
|
-
export * from './eval.js';
|
|
1
|
+
// Copyright 2026 Robert Winter / Complete Ideas
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
export * from './activation.js';
|
|
4
|
+
export * from './staging.js';
|
|
5
|
+
export * from './connections.js';
|
|
6
|
+
export * from './eviction.js';
|
|
7
|
+
export * from './retraction.js';
|
|
8
|
+
export * from './eval.js';
|