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
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* 3. Prune weakest edges when per-engram cap exceeded
|
|
8
8
|
* 4. Decay unused association weights over time
|
|
9
9
|
*/
|
|
10
|
-
import type { EngramStore } from '../storage/
|
|
10
|
+
import type { IEngramStore as EngramStore } from '../storage/store.js';
|
|
11
11
|
import type { AgentConfig } from '../types/agent.js';
|
|
12
12
|
export declare class EvictionEngine {
|
|
13
13
|
private store;
|
|
@@ -16,14 +16,14 @@ export declare class EvictionEngine {
|
|
|
16
16
|
* Check capacity budgets and evict if needed.
|
|
17
17
|
* Returns count of evicted engrams.
|
|
18
18
|
*/
|
|
19
|
-
enforceCapacity(agentId: string, config: AgentConfig): {
|
|
19
|
+
enforceCapacity(agentId: string, config: AgentConfig): Promise<{
|
|
20
20
|
evicted: number;
|
|
21
21
|
edgesPruned: number;
|
|
22
|
-
}
|
|
22
|
+
}>;
|
|
23
23
|
/**
|
|
24
24
|
* Decay all association weights based on time since last activation.
|
|
25
25
|
* Run periodically (e.g., daily).
|
|
26
26
|
*/
|
|
27
|
-
decayEdges(agentId: string, halfLifeDays?: number): number
|
|
27
|
+
decayEdges(agentId: string, halfLifeDays?: number): Promise<number>;
|
|
28
28
|
}
|
|
29
29
|
//# sourceMappingURL=eviction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eviction.d.ts","sourceRoot":"","sources":["../../src/engine/eviction.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"eviction.d.ts","sourceRoot":"","sources":["../../src/engine/eviction.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,YAAY,IAAI,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,qBAAa,cAAc;IACzB,OAAO,CAAC,KAAK,CAAc;gBAEf,KAAK,EAAE,WAAW;IAI9B;;;OAGG;IACG,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IA8C9G;;;OAGG;IACG,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,GAAE,MAAU,GAAG,OAAO,CAAC,MAAM,CAAC;CAuB7E"}
|
package/dist/engine/eviction.js
CHANGED
|
@@ -19,39 +19,39 @@ export class EvictionEngine {
|
|
|
19
19
|
* Check capacity budgets and evict if needed.
|
|
20
20
|
* Returns count of evicted engrams.
|
|
21
21
|
*/
|
|
22
|
-
enforceCapacity(agentId, config) {
|
|
22
|
+
async enforceCapacity(agentId, config) {
|
|
23
23
|
let evicted = 0;
|
|
24
24
|
let edgesPruned = 0;
|
|
25
25
|
// Active engram budget
|
|
26
|
-
const activeCount = this.store.getActiveCount(agentId);
|
|
26
|
+
const activeCount = await this.store.getActiveCount(agentId);
|
|
27
27
|
if (activeCount > config.maxActiveEngrams) {
|
|
28
28
|
const excess = activeCount - config.maxActiveEngrams;
|
|
29
|
-
const candidates = this.store.getEvictionCandidates(agentId, excess);
|
|
29
|
+
const candidates = await this.store.getEvictionCandidates(agentId, excess);
|
|
30
30
|
for (const engram of candidates) {
|
|
31
|
-
this.store.updateStage(engram.id, 'archived');
|
|
31
|
+
await this.store.updateStage(engram.id, 'archived');
|
|
32
32
|
evicted++;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
// Staging budget
|
|
36
|
-
const stagingCount = this.store.getStagingCount(agentId);
|
|
36
|
+
const stagingCount = await this.store.getStagingCount(agentId);
|
|
37
37
|
if (stagingCount > config.maxStagingEngrams) {
|
|
38
|
-
const expired = this.store.getExpiredStaging();
|
|
38
|
+
const expired = await this.store.getExpiredStaging();
|
|
39
39
|
for (const engram of expired) {
|
|
40
|
-
this.store.deleteEngram(engram.id);
|
|
40
|
+
await this.store.deleteEngram(engram.id);
|
|
41
41
|
evicted++;
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
// Edge pruning — cap per engram
|
|
45
|
-
const engrams = this.store.getEngramsByAgent(agentId, 'active');
|
|
45
|
+
const engrams = await this.store.getEngramsByAgent(agentId, 'active');
|
|
46
46
|
for (const engram of engrams) {
|
|
47
|
-
const edgeCount = this.store.countAssociationsFor(engram.id);
|
|
47
|
+
const edgeCount = await this.store.countAssociationsFor(engram.id);
|
|
48
48
|
if (edgeCount > config.maxEdgesPerEngram) {
|
|
49
49
|
// Remove weakest edges until under cap
|
|
50
50
|
let toRemove = edgeCount - config.maxEdgesPerEngram;
|
|
51
51
|
while (toRemove > 0) {
|
|
52
|
-
const weakest = this.store.getWeakestAssociation(engram.id);
|
|
52
|
+
const weakest = await this.store.getWeakestAssociation(engram.id);
|
|
53
53
|
if (weakest) {
|
|
54
|
-
this.store.deleteAssociation(weakest.id);
|
|
54
|
+
await this.store.deleteAssociation(weakest.id);
|
|
55
55
|
edgesPruned++;
|
|
56
56
|
}
|
|
57
57
|
toRemove--;
|
|
@@ -64,8 +64,8 @@ export class EvictionEngine {
|
|
|
64
64
|
* Decay all association weights based on time since last activation.
|
|
65
65
|
* Run periodically (e.g., daily).
|
|
66
66
|
*/
|
|
67
|
-
decayEdges(agentId, halfLifeDays = 7) {
|
|
68
|
-
const associations = this.store.getAllAssociations(agentId);
|
|
67
|
+
async decayEdges(agentId, halfLifeDays = 7) {
|
|
68
|
+
const associations = await this.store.getAllAssociations(agentId);
|
|
69
69
|
let decayed = 0;
|
|
70
70
|
for (const assoc of associations) {
|
|
71
71
|
const daysSince = (Date.now() - assoc.lastActivated.getTime()) / (1000 * 60 * 60 * 24);
|
|
@@ -74,11 +74,11 @@ export class EvictionEngine {
|
|
|
74
74
|
const newWeight = decayAssociation(assoc.weight, daysSince, halfLifeDays);
|
|
75
75
|
if (newWeight < 0.01) {
|
|
76
76
|
// Below minimum useful weight — prune
|
|
77
|
-
this.store.deleteAssociation(assoc.id);
|
|
77
|
+
await this.store.deleteAssociation(assoc.id);
|
|
78
78
|
decayed++;
|
|
79
79
|
}
|
|
80
80
|
else if (Math.abs(newWeight - assoc.weight) > 0.001) {
|
|
81
|
-
this.store.upsertAssociation(assoc.fromEngramId, assoc.toEngramId, newWeight, assoc.type, assoc.confidence);
|
|
81
|
+
await this.store.upsertAssociation(assoc.fromEngramId, assoc.toEngramId, newWeight, assoc.type, assoc.confidence);
|
|
82
82
|
decayed++;
|
|
83
83
|
}
|
|
84
84
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eviction.js","sourceRoot":"","sources":["../../src/engine/eviction.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,sCAAsC;AACtC;;;;;;;;GAQG;AAIH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,OAAO,cAAc;IACjB,KAAK,CAAc;IAE3B,YAAY,KAAkB;QAC5B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,eAAe,CAAC,OAAe,EAAE,MAAmB;
|
|
1
|
+
{"version":3,"file":"eviction.js","sourceRoot":"","sources":["../../src/engine/eviction.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,sCAAsC;AACtC;;;;;;;;GAQG;AAIH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,OAAO,cAAc;IACjB,KAAK,CAAc;IAE3B,YAAY,KAAkB;QAC5B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,eAAe,CAAC,OAAe,EAAE,MAAmB;QACxD,IAAI,OAAO,GAAG,CAAC,CAAC;QAChB,IAAI,WAAW,GAAG,CAAC,CAAC;QAEpB,uBAAuB;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I,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,EAAE,CAAC;gBACtD,MAAM,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAChC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,UAAU,EAAE,SAAS,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,UAAU,CAC9E,CAAC;gBACF,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
|
|
@@ -9,23 +9,111 @@
|
|
|
9
9
|
* 2. An invalidation association is created
|
|
10
10
|
* 3. Optionally, a counter-engram with correct info is created
|
|
11
11
|
* 4. Confidence of associated engrams is reduced (contamination check)
|
|
12
|
+
*
|
|
13
|
+
* AWM 0.8.5 — Coherence-weighted propagation (2026-05-26)
|
|
14
|
+
* --------------------------------------------------------
|
|
15
|
+
* The Continued Influence Effect (Carrillo et al., ICCM 2025) shows that
|
|
16
|
+
* misinformation persists in human cognition because it lives inside a
|
|
17
|
+
* *coherent narrative*, not as an isolated fact. Correcting one chunk doesn't
|
|
18
|
+
* displace the narrative unless the correction also propagates through the
|
|
19
|
+
* connected structure.
|
|
20
|
+
*
|
|
21
|
+
* Translation: when we retract an engram, we compute a `cohesion` score for
|
|
22
|
+
* its 2-hop neighborhood and use it to amplify or dampen the contamination
|
|
23
|
+
* penalty on neighbors:
|
|
24
|
+
*
|
|
25
|
+
* - Dense narrative cluster (high internal-edge density + shared tags)
|
|
26
|
+
* → penalty amplified (~1.5×). The whole cluster shares the wrong story.
|
|
27
|
+
*
|
|
28
|
+
* - Isolated engram (sparse edges, divergent tags)
|
|
29
|
+
* → penalty dampened (~0.5×). No narrative to disrupt.
|
|
30
|
+
*
|
|
31
|
+
* - Cross-domain bridge (low cohesion across an edge)
|
|
32
|
+
* → bridge weight reduced but far-side neighbors barely affected.
|
|
33
|
+
*
|
|
34
|
+
* Cohesion is computed at retract time (no schema/consolidation changes).
|
|
35
|
+
* Cost: bounded by MAX_AFFECTED (20 nodes) × one batched `getAssociationsForBatch`
|
|
36
|
+
* call — typically 10-25ms.
|
|
12
37
|
*/
|
|
13
|
-
import type { EngramStore } from '../storage/
|
|
14
|
-
import type { Retraction } from '../types/index.js';
|
|
38
|
+
import type { IEngramStore as EngramStore } from '../storage/store.js';
|
|
39
|
+
import type { Retraction, Engram } from '../types/index.js';
|
|
40
|
+
/** Result of cohesion analysis on a 2-hop neighborhood. */
|
|
41
|
+
export interface NeighborhoodCohesion {
|
|
42
|
+
/** internal_edges / (internal_edges + external_edges) across the subgraph. [0, 1] */
|
|
43
|
+
graphDensity: number;
|
|
44
|
+
/** mean jaccard(source.tags, neighbor.tags) across non-source subgraph members. [0, 1] */
|
|
45
|
+
tagOverlap: number;
|
|
46
|
+
/** Combined cohesion in [0, 1] — graphDensity blended with tagOverlap bonus. */
|
|
47
|
+
score: number;
|
|
48
|
+
/** How many engrams the cohesion was computed over (excluding the source). */
|
|
49
|
+
subgraphSize: number;
|
|
50
|
+
}
|
|
15
51
|
export declare class RetractionEngine {
|
|
16
52
|
private store;
|
|
17
53
|
constructor(store: EngramStore);
|
|
18
54
|
/**
|
|
19
55
|
* Retract a memory — mark it invalid and optionally create a correction.
|
|
20
56
|
*/
|
|
21
|
-
retract(retraction: Retraction): {
|
|
57
|
+
retract(retraction: Retraction): Promise<{
|
|
22
58
|
retractedId: string;
|
|
23
59
|
correctionId: string | null;
|
|
24
60
|
associatesAffected: number;
|
|
25
|
-
|
|
61
|
+
cohesion: NeighborhoodCohesion;
|
|
62
|
+
narrativeEdgesInherited: number;
|
|
63
|
+
}>;
|
|
64
|
+
/**
|
|
65
|
+
* Counter-narrative replacement helper.
|
|
66
|
+
*
|
|
67
|
+
* When a correction engram is created to replace a retracted memory, the
|
|
68
|
+
* correction inherits the retracted's strong-edge neighbors. This implements
|
|
69
|
+
* the "narrative replacement" mechanism the Continued Influence Effect paper
|
|
70
|
+
* argues is necessary for corrections to take hold: people don't drop
|
|
71
|
+
* misinformation when only one chunk is corrected; the surrounding context
|
|
72
|
+
* has to be reconnected to the new correct fact.
|
|
73
|
+
*
|
|
74
|
+
* Rules:
|
|
75
|
+
* - Inherit only edges where weight >= NARRATIVE_INHERIT_MIN (0.4). Weak
|
|
76
|
+
* edges aren't really part of the narrative.
|
|
77
|
+
* - Skip edge types with special semantics: `invalidation` (the link
|
|
78
|
+
* between retracted and correction itself), `causal` (specific cause
|
|
79
|
+
* relationships, not narrative cohesion), `temporal` (chronological
|
|
80
|
+
* sequence, not story structure).
|
|
81
|
+
* - Skip neighbors that are themselves retracted — no point connecting
|
|
82
|
+
* a correction to other wrong memories.
|
|
83
|
+
* - Inherited edge weight = original × 0.7 (reduced — the correction
|
|
84
|
+
* experienced this context only indirectly, through the retracted memory).
|
|
85
|
+
* - Cap at NARRATIVE_INHERIT_MAX (10) edges, sorted by weight desc, to
|
|
86
|
+
* bound the blast radius on highly-connected hubs.
|
|
87
|
+
*
|
|
88
|
+
* Returns the number of edges actually inherited.
|
|
89
|
+
*/
|
|
90
|
+
private static readonly NARRATIVE_INHERIT_MIN;
|
|
91
|
+
private static readonly NARRATIVE_INHERIT_MAX;
|
|
92
|
+
private static readonly NARRATIVE_INHERIT_WEIGHT_SCALE;
|
|
93
|
+
private static readonly NARRATIVE_INHERIT_SKIP_TYPES;
|
|
94
|
+
inheritNarrativeEdges(retractedId: string, correctionId: string): Promise<number>;
|
|
95
|
+
/**
|
|
96
|
+
* Compute the narrative cohesion of `source`'s neighborhood within `depth` hops.
|
|
97
|
+
*
|
|
98
|
+
* Cohesion combines two signals:
|
|
99
|
+
* - **Graph density**: How tightly interconnected are the neighbors?
|
|
100
|
+
* internal_edges / (internal_edges + external_edges) across the subgraph.
|
|
101
|
+
* - **Tag overlap**: How much do the neighbors share semantic tags with the source?
|
|
102
|
+
* mean jaccard(source.tags, neighbor.tags).
|
|
103
|
+
*
|
|
104
|
+
* Both signals contribute on a [0, 1] scale; the combined score is
|
|
105
|
+
* `density × (1 + tagOverlap)` clamped to [0, 1]. A score of 0.5 is the
|
|
106
|
+
* "neutral" point where retraction penalty is unchanged from the legacy
|
|
107
|
+
* formula.
|
|
108
|
+
*
|
|
109
|
+
* Cost: O(subgraphSize × avg_degree) BFS + 1 batched fetch. Bounded by
|
|
110
|
+
* MAX_AFFECTED (20). Typical: ~10-25ms.
|
|
111
|
+
*/
|
|
112
|
+
computeNeighborhoodCohesion(source: Engram, depth?: number): Promise<NeighborhoodCohesion>;
|
|
26
113
|
/**
|
|
27
114
|
* Reduce confidence of engrams associated with a retracted engram.
|
|
28
|
-
* Propagates up to maxDepth hops with decaying penalty (50% per hop)
|
|
115
|
+
* Propagates up to maxDepth hops with decaying penalty (50% per hop) and
|
|
116
|
+
* cohesion-weighted amplification.
|
|
29
117
|
* Capped at MAX_AFFECTED to prevent cascading through the graph.
|
|
30
118
|
*/
|
|
31
119
|
private static readonly MAX_AFFECTED;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retraction.d.ts","sourceRoot":"","sources":["../../src/engine/retraction.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"retraction.d.ts","sourceRoot":"","sources":["../../src/engine/retraction.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,KAAK,EAAE,YAAY,IAAI,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,KAAK,EAAE,UAAU,EAAe,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEzE,2DAA2D;AAC3D,MAAM,WAAW,oBAAoB;IACnC,qFAAqF;IACrF,YAAY,EAAE,MAAM,CAAC;IACrB,0FAA0F;IAC1F,UAAU,EAAE,MAAM,CAAC;IACnB,gFAAgF;IAChF,KAAK,EAAE,MAAM,CAAC;IACd,8EAA8E;IAC9E,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,KAAK,CAAc;gBAEf,KAAK,EAAE,WAAW;IAI9B;;OAEG;IACG,OAAO,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC;QAC7C,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;QAC5B,kBAAkB,EAAE,MAAM,CAAC;QAC3B,QAAQ,EAAE,oBAAoB,CAAC;QAC/B,uBAAuB,EAAE,MAAM,CAAC;KACjC,CAAC;IAwDF;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,CAAO;IACpD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,CAAM;IACnD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,8BAA8B,CAAO;IAC7D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,4BAA4B,CAEjD;IAEG,qBAAqB,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAuCvF;;;;;;;;;;;;;;;;OAgBG;IACG,2BAA2B,CAC/B,MAAM,EAAE,MAAM,EACd,KAAK,GAAE,MAAU,GAChB,OAAO,CAAC,oBAAoB,CAAC;IA2FhC;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAM;YAE5B,4BAA4B;CA+C3C"}
|
|
@@ -11,6 +11,31 @@
|
|
|
11
11
|
* 2. An invalidation association is created
|
|
12
12
|
* 3. Optionally, a counter-engram with correct info is created
|
|
13
13
|
* 4. Confidence of associated engrams is reduced (contamination check)
|
|
14
|
+
*
|
|
15
|
+
* AWM 0.8.5 — Coherence-weighted propagation (2026-05-26)
|
|
16
|
+
* --------------------------------------------------------
|
|
17
|
+
* The Continued Influence Effect (Carrillo et al., ICCM 2025) shows that
|
|
18
|
+
* misinformation persists in human cognition because it lives inside a
|
|
19
|
+
* *coherent narrative*, not as an isolated fact. Correcting one chunk doesn't
|
|
20
|
+
* displace the narrative unless the correction also propagates through the
|
|
21
|
+
* connected structure.
|
|
22
|
+
*
|
|
23
|
+
* Translation: when we retract an engram, we compute a `cohesion` score for
|
|
24
|
+
* its 2-hop neighborhood and use it to amplify or dampen the contamination
|
|
25
|
+
* penalty on neighbors:
|
|
26
|
+
*
|
|
27
|
+
* - Dense narrative cluster (high internal-edge density + shared tags)
|
|
28
|
+
* → penalty amplified (~1.5×). The whole cluster shares the wrong story.
|
|
29
|
+
*
|
|
30
|
+
* - Isolated engram (sparse edges, divergent tags)
|
|
31
|
+
* → penalty dampened (~0.5×). No narrative to disrupt.
|
|
32
|
+
*
|
|
33
|
+
* - Cross-domain bridge (low cohesion across an edge)
|
|
34
|
+
* → bridge weight reduced but far-side neighbors barely affected.
|
|
35
|
+
*
|
|
36
|
+
* Cohesion is computed at retract time (no schema/consolidation changes).
|
|
37
|
+
* Cost: bounded by MAX_AFFECTED (20 nodes) × one batched `getAssociationsForBatch`
|
|
38
|
+
* call — typically 10-25ms.
|
|
14
39
|
*/
|
|
15
40
|
export class RetractionEngine {
|
|
16
41
|
store;
|
|
@@ -20,17 +45,18 @@ export class RetractionEngine {
|
|
|
20
45
|
/**
|
|
21
46
|
* Retract a memory — mark it invalid and optionally create a correction.
|
|
22
47
|
*/
|
|
23
|
-
retract(retraction) {
|
|
24
|
-
const target = this.store.getEngram(retraction.targetEngramId);
|
|
48
|
+
async retract(retraction) {
|
|
49
|
+
const target = await this.store.getEngram(retraction.targetEngramId);
|
|
25
50
|
if (!target) {
|
|
26
51
|
throw new Error(`Engram ${retraction.targetEngramId} not found`);
|
|
27
52
|
}
|
|
28
53
|
// Mark the original as retracted
|
|
29
|
-
this.store.retractEngram(target.id, null);
|
|
54
|
+
await this.store.retractEngram(target.id, null);
|
|
30
55
|
let correctionId = null;
|
|
56
|
+
let narrativeEdgesInherited = 0;
|
|
31
57
|
// Create counter-engram if correction content provided
|
|
32
58
|
if (retraction.counterContent) {
|
|
33
|
-
const correction = this.store.createEngram({
|
|
59
|
+
const correction = await this.store.createEngram({
|
|
34
60
|
agentId: retraction.agentId,
|
|
35
61
|
concept: `correction:${target.concept}`,
|
|
36
62
|
content: retraction.counterContent,
|
|
@@ -41,29 +67,219 @@ export class RetractionEngine {
|
|
|
41
67
|
});
|
|
42
68
|
correctionId = correction.id;
|
|
43
69
|
// Create invalidation link
|
|
44
|
-
this.store.upsertAssociation(correction.id, target.id, 1.0, 'invalidation', 1.0);
|
|
70
|
+
await this.store.upsertAssociation(correction.id, target.id, 1.0, 'invalidation', 1.0);
|
|
45
71
|
// Update retracted_by to point to correction
|
|
46
|
-
this.store.retractEngram(target.id, correction.id);
|
|
72
|
+
await this.store.retractEngram(target.id, correction.id);
|
|
73
|
+
// Counter-narrative replacement (Carrillo et al ICCM 2025):
|
|
74
|
+
// The correction must take over the retracted memory's narrative position,
|
|
75
|
+
// not just contradict it. Inherit edges from the retracted's strong
|
|
76
|
+
// neighbors so the correction lives in the same context that the wrong
|
|
77
|
+
// memory occupied.
|
|
78
|
+
narrativeEdgesInherited = await this.inheritNarrativeEdges(target.id, correction.id);
|
|
79
|
+
}
|
|
80
|
+
// Compute cohesion of the target's neighborhood. A dense/cohesive
|
|
81
|
+
// neighborhood means the retracted memory was part of a coherent
|
|
82
|
+
// narrative; we propagate the contamination penalty more aggressively.
|
|
83
|
+
const cohesion = await this.computeNeighborhoodCohesion(target, 2);
|
|
84
|
+
// Reduce confidence of associated engrams (contamination spread).
|
|
85
|
+
// Depth 2 with cohesion-weighted penalty, capped at MAX_AFFECTED nodes.
|
|
86
|
+
const associatesAffected = await this.propagateConfidenceReduction(target.id, 0.1, 2, cohesion.score);
|
|
87
|
+
return { retractedId: target.id, correctionId, associatesAffected, cohesion, narrativeEdgesInherited };
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Counter-narrative replacement helper.
|
|
91
|
+
*
|
|
92
|
+
* When a correction engram is created to replace a retracted memory, the
|
|
93
|
+
* correction inherits the retracted's strong-edge neighbors. This implements
|
|
94
|
+
* the "narrative replacement" mechanism the Continued Influence Effect paper
|
|
95
|
+
* argues is necessary for corrections to take hold: people don't drop
|
|
96
|
+
* misinformation when only one chunk is corrected; the surrounding context
|
|
97
|
+
* has to be reconnected to the new correct fact.
|
|
98
|
+
*
|
|
99
|
+
* Rules:
|
|
100
|
+
* - Inherit only edges where weight >= NARRATIVE_INHERIT_MIN (0.4). Weak
|
|
101
|
+
* edges aren't really part of the narrative.
|
|
102
|
+
* - Skip edge types with special semantics: `invalidation` (the link
|
|
103
|
+
* between retracted and correction itself), `causal` (specific cause
|
|
104
|
+
* relationships, not narrative cohesion), `temporal` (chronological
|
|
105
|
+
* sequence, not story structure).
|
|
106
|
+
* - Skip neighbors that are themselves retracted — no point connecting
|
|
107
|
+
* a correction to other wrong memories.
|
|
108
|
+
* - Inherited edge weight = original × 0.7 (reduced — the correction
|
|
109
|
+
* experienced this context only indirectly, through the retracted memory).
|
|
110
|
+
* - Cap at NARRATIVE_INHERIT_MAX (10) edges, sorted by weight desc, to
|
|
111
|
+
* bound the blast radius on highly-connected hubs.
|
|
112
|
+
*
|
|
113
|
+
* Returns the number of edges actually inherited.
|
|
114
|
+
*/
|
|
115
|
+
static NARRATIVE_INHERIT_MIN = 0.4;
|
|
116
|
+
static NARRATIVE_INHERIT_MAX = 10;
|
|
117
|
+
static NARRATIVE_INHERIT_WEIGHT_SCALE = 0.7;
|
|
118
|
+
static NARRATIVE_INHERIT_SKIP_TYPES = new Set([
|
|
119
|
+
'invalidation', 'causal', 'temporal',
|
|
120
|
+
]);
|
|
121
|
+
async inheritNarrativeEdges(retractedId, correctionId) {
|
|
122
|
+
const associations = await this.store.getAssociationsFor(retractedId);
|
|
123
|
+
// Filter to inheritable edges
|
|
124
|
+
const candidates = [];
|
|
125
|
+
for (const assoc of associations) {
|
|
126
|
+
if (RetractionEngine.NARRATIVE_INHERIT_SKIP_TYPES.has(assoc.type))
|
|
127
|
+
continue;
|
|
128
|
+
if (assoc.weight < RetractionEngine.NARRATIVE_INHERIT_MIN)
|
|
129
|
+
continue;
|
|
130
|
+
const neighborId = assoc.fromEngramId === retractedId ? assoc.toEngramId : assoc.fromEngramId;
|
|
131
|
+
if (neighborId === correctionId)
|
|
132
|
+
continue; // don't self-loop
|
|
133
|
+
candidates.push({ neighborId, weight: assoc.weight, confidence: assoc.confidence, type: assoc.type });
|
|
134
|
+
}
|
|
135
|
+
// Sort by weight desc, take top N
|
|
136
|
+
candidates.sort((a, b) => b.weight - a.weight);
|
|
137
|
+
const top = candidates.slice(0, RetractionEngine.NARRATIVE_INHERIT_MAX);
|
|
138
|
+
if (top.length === 0)
|
|
139
|
+
return 0;
|
|
140
|
+
// Filter out retracted neighbors (would inherit edges to wrong memories)
|
|
141
|
+
const neighborEngrams = await this.store.getEngramsByIds(top.map(c => c.neighborId));
|
|
142
|
+
const neighborMap = new Map(neighborEngrams.map(e => [e.id, e]));
|
|
143
|
+
let inherited = 0;
|
|
144
|
+
for (const c of top) {
|
|
145
|
+
const neighbor = neighborMap.get(c.neighborId);
|
|
146
|
+
if (!neighbor || neighbor.retracted)
|
|
147
|
+
continue;
|
|
148
|
+
const newWeight = c.weight * RetractionEngine.NARRATIVE_INHERIT_WEIGHT_SCALE;
|
|
149
|
+
await this.store.upsertAssociation(correctionId, c.neighborId, newWeight, 'connection', // Reuse existing type; semantically these ARE connections from the correction's perspective.
|
|
150
|
+
c.confidence);
|
|
151
|
+
inherited++;
|
|
152
|
+
}
|
|
153
|
+
return inherited;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Compute the narrative cohesion of `source`'s neighborhood within `depth` hops.
|
|
157
|
+
*
|
|
158
|
+
* Cohesion combines two signals:
|
|
159
|
+
* - **Graph density**: How tightly interconnected are the neighbors?
|
|
160
|
+
* internal_edges / (internal_edges + external_edges) across the subgraph.
|
|
161
|
+
* - **Tag overlap**: How much do the neighbors share semantic tags with the source?
|
|
162
|
+
* mean jaccard(source.tags, neighbor.tags).
|
|
163
|
+
*
|
|
164
|
+
* Both signals contribute on a [0, 1] scale; the combined score is
|
|
165
|
+
* `density × (1 + tagOverlap)` clamped to [0, 1]. A score of 0.5 is the
|
|
166
|
+
* "neutral" point where retraction penalty is unchanged from the legacy
|
|
167
|
+
* formula.
|
|
168
|
+
*
|
|
169
|
+
* Cost: O(subgraphSize × avg_degree) BFS + 1 batched fetch. Bounded by
|
|
170
|
+
* MAX_AFFECTED (20). Typical: ~10-25ms.
|
|
171
|
+
*/
|
|
172
|
+
async computeNeighborhoodCohesion(source, depth = 2) {
|
|
173
|
+
// BFS to collect the subgraph nodes
|
|
174
|
+
const subgraphIds = new Set([source.id]);
|
|
175
|
+
let frontier = [source.id];
|
|
176
|
+
for (let d = 0; d < depth; d++) {
|
|
177
|
+
const next = [];
|
|
178
|
+
// Batch-fetch associations for the current frontier
|
|
179
|
+
const assocs = await this.store.getAssociationsForBatch(frontier);
|
|
180
|
+
for (const id of frontier) {
|
|
181
|
+
const list = assocs.get(id) ?? [];
|
|
182
|
+
for (const a of list) {
|
|
183
|
+
if (a.type === 'invalidation')
|
|
184
|
+
continue;
|
|
185
|
+
const neighbor = a.fromEngramId === id ? a.toEngramId : a.fromEngramId;
|
|
186
|
+
if (subgraphIds.has(neighbor))
|
|
187
|
+
continue;
|
|
188
|
+
if (subgraphIds.size >= RetractionEngine.MAX_AFFECTED)
|
|
189
|
+
break;
|
|
190
|
+
subgraphIds.add(neighbor);
|
|
191
|
+
next.push(neighbor);
|
|
192
|
+
}
|
|
193
|
+
if (subgraphIds.size >= RetractionEngine.MAX_AFFECTED)
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
if (next.length === 0)
|
|
197
|
+
break;
|
|
198
|
+
frontier = next;
|
|
199
|
+
}
|
|
200
|
+
const subgraphSize = subgraphIds.size - 1; // exclude source
|
|
201
|
+
if (subgraphSize === 0) {
|
|
202
|
+
// No neighbors at all — fully isolated engram.
|
|
203
|
+
return { graphDensity: 0, tagOverlap: 0, score: 0, subgraphSize: 0 };
|
|
204
|
+
}
|
|
205
|
+
// Fetch all subgraph members' associations in one batch.
|
|
206
|
+
const allIds = Array.from(subgraphIds);
|
|
207
|
+
const allAssocs = await this.store.getAssociationsForBatch(allIds);
|
|
208
|
+
// Count internal vs external edges across the subgraph.
|
|
209
|
+
let internalEdges = 0;
|
|
210
|
+
let externalEdges = 0;
|
|
211
|
+
const seenEdge = new Set(); // de-dupe (each edge appears twice in BFS by endpoint)
|
|
212
|
+
for (const id of allIds) {
|
|
213
|
+
const list = allAssocs.get(id) ?? [];
|
|
214
|
+
for (const a of list) {
|
|
215
|
+
if (a.type === 'invalidation')
|
|
216
|
+
continue;
|
|
217
|
+
// Canonical edge key (alphabetical) for de-duping
|
|
218
|
+
const key = a.fromEngramId < a.toEngramId
|
|
219
|
+
? `${a.fromEngramId}|${a.toEngramId}`
|
|
220
|
+
: `${a.toEngramId}|${a.fromEngramId}`;
|
|
221
|
+
if (seenEdge.has(key))
|
|
222
|
+
continue;
|
|
223
|
+
seenEdge.add(key);
|
|
224
|
+
const internal = subgraphIds.has(a.fromEngramId) && subgraphIds.has(a.toEngramId);
|
|
225
|
+
if (internal)
|
|
226
|
+
internalEdges++;
|
|
227
|
+
else
|
|
228
|
+
externalEdges++;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const totalEdges = internalEdges + externalEdges;
|
|
232
|
+
const graphDensity = totalEdges > 0 ? internalEdges / totalEdges : 0;
|
|
233
|
+
// Compute tag overlap (source vs each subgraph member).
|
|
234
|
+
const sourceTags = new Set(source.tags ?? []);
|
|
235
|
+
let tagOverlapSum = 0;
|
|
236
|
+
let tagOverlapCount = 0;
|
|
237
|
+
if (sourceTags.size > 0) {
|
|
238
|
+
// Fetch all subgraph engrams to read tags
|
|
239
|
+
const neighborIds = allIds.filter(id => id !== source.id);
|
|
240
|
+
const engrams = await this.store.getEngramsByIds(neighborIds);
|
|
241
|
+
for (const e of engrams) {
|
|
242
|
+
const neighborTags = new Set(e.tags ?? []);
|
|
243
|
+
if (neighborTags.size === 0)
|
|
244
|
+
continue;
|
|
245
|
+
const intersection = [...sourceTags].filter(t => neighborTags.has(t)).length;
|
|
246
|
+
const union = sourceTags.size + neighborTags.size - intersection;
|
|
247
|
+
const jaccard = union > 0 ? intersection / union : 0;
|
|
248
|
+
tagOverlapSum += jaccard;
|
|
249
|
+
tagOverlapCount++;
|
|
250
|
+
}
|
|
47
251
|
}
|
|
48
|
-
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
|
|
252
|
+
const tagOverlap = tagOverlapCount > 0 ? tagOverlapSum / tagOverlapCount : 0;
|
|
253
|
+
// Combine: graph density × tag-modulated weight. Density alone saturates
|
|
254
|
+
// quickly in small subgraphs (everything is internal); tag overlap is the
|
|
255
|
+
// signal that distinguishes a genuine narrative from an incidental cluster.
|
|
256
|
+
// score = density * (0.5 + 0.5 * tagOverlap)
|
|
257
|
+
// - max (density=1, tagOverlap=1) → 1.0 (canonical narrative)
|
|
258
|
+
// - hub (density=1, tagOverlap=0) → 0.5 (structurally connected but no shared story)
|
|
259
|
+
// - half (density=0.5, tagOverlap=0.5) → 0.375
|
|
260
|
+
// - zero (density=0) → 0 (no neighborhood)
|
|
261
|
+
const rawScore = graphDensity * (0.5 + 0.5 * tagOverlap);
|
|
262
|
+
const score = Math.max(0, Math.min(1, rawScore));
|
|
263
|
+
return { graphDensity, tagOverlap, score, subgraphSize };
|
|
52
264
|
}
|
|
53
265
|
/**
|
|
54
266
|
* Reduce confidence of engrams associated with a retracted engram.
|
|
55
|
-
* Propagates up to maxDepth hops with decaying penalty (50% per hop)
|
|
267
|
+
* Propagates up to maxDepth hops with decaying penalty (50% per hop) and
|
|
268
|
+
* cohesion-weighted amplification.
|
|
56
269
|
* Capped at MAX_AFFECTED to prevent cascading through the graph.
|
|
57
270
|
*/
|
|
58
271
|
static MAX_AFFECTED = 20;
|
|
59
|
-
propagateConfidenceReduction(engramId, penalty, maxDepth, currentDepth = 0, visited = new Set()) {
|
|
272
|
+
async propagateConfidenceReduction(engramId, penalty, maxDepth, cohesionScore, currentDepth = 0, visited = new Set()) {
|
|
60
273
|
if (currentDepth >= maxDepth)
|
|
61
274
|
return 0;
|
|
62
275
|
if (visited.size >= RetractionEngine.MAX_AFFECTED)
|
|
63
276
|
return 0;
|
|
64
277
|
visited.add(engramId);
|
|
278
|
+
// Cohesion multiplier: 0.5 (isolated) → 1.5 (densely coherent narrative).
|
|
279
|
+
// At cohesion=0.5 (neutral), multiplier=1.0, preserving legacy behavior.
|
|
280
|
+
const cohesionMultiplier = 0.5 + cohesionScore;
|
|
65
281
|
let affected = 0;
|
|
66
|
-
const associations = this.store.getAssociationsFor(engramId);
|
|
282
|
+
const associations = await this.store.getAssociationsFor(engramId);
|
|
67
283
|
for (const assoc of associations) {
|
|
68
284
|
if (assoc.type === 'invalidation')
|
|
69
285
|
continue; // Don't penalize corrections
|
|
@@ -74,17 +290,20 @@ export class RetractionEngine {
|
|
|
74
290
|
: assoc.fromEngramId;
|
|
75
291
|
if (visited.has(neighborId))
|
|
76
292
|
continue;
|
|
77
|
-
const neighbor = this.store.getEngram(neighborId);
|
|
293
|
+
const neighbor = await this.store.getEngram(neighborId);
|
|
78
294
|
if (!neighbor || neighbor.retracted)
|
|
79
295
|
continue;
|
|
80
|
-
// Scale penalty by association weight
|
|
296
|
+
// Scale penalty by association weight, depth decay (50% per hop),
|
|
297
|
+
// and cohesion multiplier (narrative-aware amplification).
|
|
81
298
|
const depthDecay = Math.pow(0.5, currentDepth);
|
|
82
|
-
const scaledPenalty = penalty * assoc.weight * depthDecay;
|
|
299
|
+
const scaledPenalty = penalty * assoc.weight * depthDecay * cohesionMultiplier;
|
|
83
300
|
const newConfidence = Math.max(0.1, neighbor.confidence - scaledPenalty);
|
|
84
|
-
this.store.updateConfidence(neighborId, newConfidence);
|
|
301
|
+
await this.store.updateConfidence(neighborId, newConfidence);
|
|
85
302
|
affected++;
|
|
86
|
-
// Recurse to next depth
|
|
87
|
-
|
|
303
|
+
// Recurse to next depth — cohesion is computed once at the source
|
|
304
|
+
// and applied uniformly through the propagation. Recomputing per-hop
|
|
305
|
+
// would be expensive and could cause oscillation.
|
|
306
|
+
affected += await this.propagateConfidenceReduction(neighborId, penalty, maxDepth, cohesionScore, currentDepth + 1, visited);
|
|
88
307
|
}
|
|
89
308
|
return affected;
|
|
90
309
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retraction.js","sourceRoot":"","sources":["../../src/engine/retraction.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,sCAAsC;AACtC
|
|
1
|
+
{"version":3,"file":"retraction.js","sourceRoot":"","sources":["../../src/engine/retraction.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,sCAAsC;AACtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAiBH,MAAM,OAAO,gBAAgB;IACnB,KAAK,CAAc;IAE3B,YAAY,KAAkB;QAC5B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,UAAsB;QAOlC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;QACrE,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,UAAU,UAAU,CAAC,cAAc,YAAY,CAAC,CAAC;QACnE,CAAC;QAED,iCAAiC;QACjC,MAAM,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QAEhD,IAAI,YAAY,GAAkB,IAAI,CAAC;QACvC,IAAI,uBAAuB,GAAG,CAAC,CAAC;QAEhC,uDAAuD;QACvD,IAAI,UAAU,CAAC,cAAc,EAAE,CAAC;YAC9B,MAAM,UAAU,GAAG,MAAM,IAAI,C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olidation — provisional encoding
|
|
11
11
|
* that only persists if reactivated.
|
|
12
12
|
*/
|
|
13
|
-
import type { EngramStore } from '../storage/
|
|
13
|
+
import type { IEngramStore as EngramStore } from '../storage/store.js';
|
|
14
14
|
import type { ActivationEngine } from './activation.js';
|
|
15
15
|
export declare class StagingBuffer {
|
|
16
16
|
private store;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"staging.d.ts","sourceRoot":"","sources":["../../src/engine/staging.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"staging.d.ts","sourceRoot":"","sources":["../../src/engine/staging.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,YAAY,IAAI,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,qBAAa,aAAa;IACxB,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,aAAa,CAA+C;gBAExD,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,gBAAgB;IAKxD;;OAEG;IACH,KAAK,CAAC,UAAU,GAAE,MAAe,GAAG,IAAI;IAIxC,IAAI,IAAI,IAAI;IAOZ;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;QAAC,SAAS,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;CA4BpE"}
|
package/dist/engine/staging.js
CHANGED
|
@@ -38,7 +38,7 @@ export class StagingBuffer {
|
|
|
38
38
|
async sweep() {
|
|
39
39
|
const promoted = [];
|
|
40
40
|
const discarded = [];
|
|
41
|
-
const expired = this.store.getExpiredStaging();
|
|
41
|
+
const expired = await this.store.getExpiredStaging();
|
|
42
42
|
for (const engram of expired) {
|
|
43
43
|
// Check if this engram resonates with active memory
|
|
44
44
|
const results = await this.engine.activate({
|
|
@@ -50,12 +50,12 @@ export class StagingBuffer {
|
|
|
50
50
|
});
|
|
51
51
|
if (results.length > 0) {
|
|
52
52
|
// Resonance found — promote to active
|
|
53
|
-
this.store.updateStage(engram.id, 'active');
|
|
53
|
+
await this.store.updateStage(engram.id, 'active');
|
|
54
54
|
promoted.push(engram.id);
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
57
57
|
// No resonance — discard
|
|
58
|
-
this.store.deleteEngram(engram.id);
|
|
58
|
+
await this.store.deleteEngram(engram.id);
|
|
59
59
|
discarded.push(engram.id);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"staging.js","sourceRoot":"","sources":["../../src/engine/staging.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,sCAAsC;AACtC;;;;;;;;;;;GAWG;AAKH,MAAM,OAAO,aAAa;IAChB,KAAK,CAAc;IACnB,MAAM,CAAmB;IACzB,aAAa,GAA0C,IAAI,CAAC;IAEpE,YAAY,KAAkB,EAAE,MAAwB;QACtD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,aAAqB,MAAM;QAC/B,IAAI,CAAC,aAAa,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,UAAU,CAAC,CAAC;IACnE,CAAC;IAED,IAAI;QACF,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACvB,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YAClC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC5B,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACT,MAAM,QAAQ,GAAa,EAAE,CAAC;QAC9B,MAAM,SAAS,GAAa,EAAE,CA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