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/types/agent.ts
CHANGED
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
// Copyright 2026 Robert Winter / Complete Ideas
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
/**
|
|
4
|
-
* Agent — a consciousness boundary.
|
|
5
|
-
* Each agent has its own isolated memory space with capacity budgets.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export interface Agent {
|
|
9
|
-
id: string;
|
|
10
|
-
name: string;
|
|
11
|
-
createdAt: Date;
|
|
12
|
-
config: AgentConfig;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface AgentConfig {
|
|
16
|
-
// Salience filter thresholds
|
|
17
|
-
salienceThreshold: number; // Below this → discard
|
|
18
|
-
stagingThreshold: number; // Below salience but above this → staging buffer
|
|
19
|
-
stagingTtlMs: number; // Default TTL for staging entries
|
|
20
|
-
|
|
21
|
-
// Capacity budgets (eviction triggers when exceeded)
|
|
22
|
-
maxActiveEngrams: number; // Hard cap on active memory
|
|
23
|
-
maxStagingEngrams: number; // Hard cap on staging buffer
|
|
24
|
-
maxEdgesPerEngram: number; // Prevent graph explosion
|
|
25
|
-
|
|
26
|
-
// Activation pipeline tuning
|
|
27
|
-
activationLimit: number; // Max results per activation query
|
|
28
|
-
hebbianRate: number; // Learning rate for association strengthening
|
|
29
|
-
decayExponent: number; // ACT-R d parameter (default 0.5)
|
|
30
|
-
edgeDecayHalfLifeDays: number; // How fast unused edges weaken
|
|
31
|
-
|
|
32
|
-
// Connection engine
|
|
33
|
-
connectionThreshold: number; // Min resonance score to form a connection
|
|
34
|
-
connectionCheckIntervalMs: number;
|
|
35
|
-
|
|
36
|
-
// Consolidation
|
|
37
|
-
consolidationIntervalMs: number; // How often to check for merge candidates
|
|
38
|
-
consolidationSimilarity: number; // Threshold for merging similar engrams
|
|
39
|
-
|
|
40
|
-
// Confidence updates
|
|
41
|
-
feedbackPositiveBoost: number; // How much positive feedback increases confidence
|
|
42
|
-
feedbackNegativePenalty: number; // How much negative feedback decreases confidence
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export const DEFAULT_AGENT_CONFIG: AgentConfig = {
|
|
46
|
-
salienceThreshold: 0.4,
|
|
47
|
-
stagingThreshold: 0.2,
|
|
48
|
-
stagingTtlMs: 24 * 60 * 60 * 1000, // 24 hours
|
|
49
|
-
|
|
50
|
-
maxActiveEngrams: 10_000,
|
|
51
|
-
maxStagingEngrams: 1_000,
|
|
52
|
-
maxEdgesPerEngram: 20,
|
|
53
|
-
|
|
54
|
-
activationLimit: 10,
|
|
55
|
-
hebbianRate: 0.25,
|
|
56
|
-
decayExponent: 0.5,
|
|
57
|
-
edgeDecayHalfLifeDays: 7,
|
|
58
|
-
|
|
59
|
-
connectionThreshold: 0.7,
|
|
60
|
-
connectionCheckIntervalMs: 60_000,
|
|
61
|
-
|
|
62
|
-
consolidationIntervalMs: 300_000, // 5 minutes
|
|
63
|
-
consolidationSimilarity: 0.85,
|
|
64
|
-
|
|
65
|
-
feedbackPositiveBoost: 0.05,
|
|
66
|
-
feedbackNegativePenalty: 0.1,
|
|
67
|
-
};
|
|
1
|
+
// Copyright 2026 Robert Winter / Complete Ideas
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
/**
|
|
4
|
+
* Agent — a consciousness boundary.
|
|
5
|
+
* Each agent has its own isolated memory space with capacity budgets.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export interface Agent {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
createdAt: Date;
|
|
12
|
+
config: AgentConfig;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface AgentConfig {
|
|
16
|
+
// Salience filter thresholds
|
|
17
|
+
salienceThreshold: number; // Below this → discard
|
|
18
|
+
stagingThreshold: number; // Below salience but above this → staging buffer
|
|
19
|
+
stagingTtlMs: number; // Default TTL for staging entries
|
|
20
|
+
|
|
21
|
+
// Capacity budgets (eviction triggers when exceeded)
|
|
22
|
+
maxActiveEngrams: number; // Hard cap on active memory
|
|
23
|
+
maxStagingEngrams: number; // Hard cap on staging buffer
|
|
24
|
+
maxEdgesPerEngram: number; // Prevent graph explosion
|
|
25
|
+
|
|
26
|
+
// Activation pipeline tuning
|
|
27
|
+
activationLimit: number; // Max results per activation query
|
|
28
|
+
hebbianRate: number; // Learning rate for association strengthening
|
|
29
|
+
decayExponent: number; // ACT-R d parameter (default 0.5)
|
|
30
|
+
edgeDecayHalfLifeDays: number; // How fast unused edges weaken
|
|
31
|
+
|
|
32
|
+
// Connection engine
|
|
33
|
+
connectionThreshold: number; // Min resonance score to form a connection
|
|
34
|
+
connectionCheckIntervalMs: number;
|
|
35
|
+
|
|
36
|
+
// Consolidation
|
|
37
|
+
consolidationIntervalMs: number; // How often to check for merge candidates
|
|
38
|
+
consolidationSimilarity: number; // Threshold for merging similar engrams
|
|
39
|
+
|
|
40
|
+
// Confidence updates
|
|
41
|
+
feedbackPositiveBoost: number; // How much positive feedback increases confidence
|
|
42
|
+
feedbackNegativePenalty: number; // How much negative feedback decreases confidence
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const DEFAULT_AGENT_CONFIG: AgentConfig = {
|
|
46
|
+
salienceThreshold: 0.4,
|
|
47
|
+
stagingThreshold: 0.2,
|
|
48
|
+
stagingTtlMs: 24 * 60 * 60 * 1000, // 24 hours
|
|
49
|
+
|
|
50
|
+
maxActiveEngrams: 10_000,
|
|
51
|
+
maxStagingEngrams: 1_000,
|
|
52
|
+
maxEdgesPerEngram: 20,
|
|
53
|
+
|
|
54
|
+
activationLimit: 10,
|
|
55
|
+
hebbianRate: 0.25,
|
|
56
|
+
decayExponent: 0.5,
|
|
57
|
+
edgeDecayHalfLifeDays: 7,
|
|
58
|
+
|
|
59
|
+
connectionThreshold: 0.7,
|
|
60
|
+
connectionCheckIntervalMs: 60_000,
|
|
61
|
+
|
|
62
|
+
consolidationIntervalMs: 300_000, // 5 minutes
|
|
63
|
+
consolidationSimilarity: 0.85,
|
|
64
|
+
|
|
65
|
+
feedbackPositiveBoost: 0.05,
|
|
66
|
+
feedbackNegativePenalty: 0.1,
|
|
67
|
+
};
|
package/src/types/checkpoint.ts
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
// Copyright 2026 Robert Winter / Complete Ideas
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
/**
|
|
4
|
-
* Checkpoint types — conscious state preservation across compaction.
|
|
5
|
-
*
|
|
6
|
-
* ConsciousState: explicit structured snapshot (saved by agent)
|
|
7
|
-
* AutoCheckpoint: implicit lightweight tracking (updated on every write/recall)
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
export interface ConsciousState {
|
|
11
|
-
currentTask: string;
|
|
12
|
-
decisions: string[];
|
|
13
|
-
activeFiles: string[];
|
|
14
|
-
nextSteps: string[];
|
|
15
|
-
relatedMemoryIds: string[];
|
|
16
|
-
notes: string;
|
|
17
|
-
episodeId: string | null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface AutoCheckpoint {
|
|
21
|
-
lastWriteId: string | null;
|
|
22
|
-
lastRecallContext: string | null;
|
|
23
|
-
lastRecallIds: string[];
|
|
24
|
-
lastActivityAt: Date;
|
|
25
|
-
writeCountSinceConsolidation: number;
|
|
26
|
-
recallCountSinceConsolidation: number;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface CheckpointRow {
|
|
30
|
-
agentId: string;
|
|
31
|
-
auto: AutoCheckpoint;
|
|
32
|
-
executionState: ConsciousState | null;
|
|
33
|
-
checkpointAt: Date | null;
|
|
34
|
-
lastConsolidationAt: Date | null;
|
|
35
|
-
lastMiniConsolidationAt: Date | null;
|
|
36
|
-
updatedAt: Date;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface RestoreResult {
|
|
40
|
-
executionState: ConsciousState | null;
|
|
41
|
-
checkpointAt: Date | null;
|
|
42
|
-
recalledMemories: Array<{ id: string; concept: string; content: string; score: number }>;
|
|
43
|
-
lastWrite: { id: string; concept: string; content: string } | null;
|
|
44
|
-
idleMs: number;
|
|
45
|
-
miniConsolidationTriggered: boolean;
|
|
46
|
-
}
|
|
1
|
+
// Copyright 2026 Robert Winter / Complete Ideas
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
/**
|
|
4
|
+
* Checkpoint types — conscious state preservation across compaction.
|
|
5
|
+
*
|
|
6
|
+
* ConsciousState: explicit structured snapshot (saved by agent)
|
|
7
|
+
* AutoCheckpoint: implicit lightweight tracking (updated on every write/recall)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export interface ConsciousState {
|
|
11
|
+
currentTask: string;
|
|
12
|
+
decisions: string[];
|
|
13
|
+
activeFiles: string[];
|
|
14
|
+
nextSteps: string[];
|
|
15
|
+
relatedMemoryIds: string[];
|
|
16
|
+
notes: string;
|
|
17
|
+
episodeId: string | null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface AutoCheckpoint {
|
|
21
|
+
lastWriteId: string | null;
|
|
22
|
+
lastRecallContext: string | null;
|
|
23
|
+
lastRecallIds: string[];
|
|
24
|
+
lastActivityAt: Date;
|
|
25
|
+
writeCountSinceConsolidation: number;
|
|
26
|
+
recallCountSinceConsolidation: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface CheckpointRow {
|
|
30
|
+
agentId: string;
|
|
31
|
+
auto: AutoCheckpoint;
|
|
32
|
+
executionState: ConsciousState | null;
|
|
33
|
+
checkpointAt: Date | null;
|
|
34
|
+
lastConsolidationAt: Date | null;
|
|
35
|
+
lastMiniConsolidationAt: Date | null;
|
|
36
|
+
updatedAt: Date;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface RestoreResult {
|
|
40
|
+
executionState: ConsciousState | null;
|
|
41
|
+
checkpointAt: Date | null;
|
|
42
|
+
recalledMemories: Array<{ id: string; concept: string; content: string; score: number }>;
|
|
43
|
+
lastWrite: { id: string; concept: string; content: string } | null;
|
|
44
|
+
idleMs: number;
|
|
45
|
+
miniConsolidationTriggered: boolean;
|
|
46
|
+
}
|
package/src/types/engram.ts
CHANGED
|
@@ -46,6 +46,15 @@ export interface Engram {
|
|
|
46
46
|
// Memory type (content classification)
|
|
47
47
|
memoryType: MemoryType;
|
|
48
48
|
|
|
49
|
+
// Optional story-time / sequence ordering (0.8 Cluster A). NULL for engrams
|
|
50
|
+
// without a caller-supplied sequence. Used by `sortBy: "sequence"` on search
|
|
51
|
+
// and by /memory/latest-by-tag (0.8 Cluster C).
|
|
52
|
+
sequence: number | null;
|
|
53
|
+
|
|
54
|
+
// Typed references to other engrams (0.8 Cluster A schema; wired to HTTP
|
|
55
|
+
// in Cluster D). Stored as JSON in references_json column.
|
|
56
|
+
references: EngramReference[] | null;
|
|
57
|
+
|
|
49
58
|
// Supersession — "this replaces that" (not retraction — original wasn't wrong, just outdated)
|
|
50
59
|
supersededBy: string | null; // ID of the engram that replaced this one
|
|
51
60
|
supersedes: string | null; // ID of the engram this one replaces
|
|
@@ -56,7 +65,7 @@ export interface Engram {
|
|
|
56
65
|
blockedBy: string | null; // ID of blocking engram/task
|
|
57
66
|
}
|
|
58
67
|
|
|
59
|
-
export type EngramStage = 'staging' | 'active' | 'consolidated' | 'archived';
|
|
68
|
+
export type EngramStage = 'staging' | 'active' | 'consolidated' | 'fading' | 'archived';
|
|
60
69
|
|
|
61
70
|
export type TaskStatus = 'open' | 'in_progress' | 'blocked' | 'done';
|
|
62
71
|
export type TaskPriority = 'urgent' | 'high' | 'medium' | 'low';
|
|
@@ -71,7 +80,39 @@ export type TaskPriority = 'urgent' | 'high' | 'medium' | 'low';
|
|
|
71
80
|
* ephemeral: Temporary context (debugging traces, session-specific notes).
|
|
72
81
|
* Stronger time decay, lower recall priority.
|
|
73
82
|
*/
|
|
74
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Memory class — write-time classification controlling salience behavior
|
|
85
|
+
* and downstream retrieval semantics.
|
|
86
|
+
*
|
|
87
|
+
* canonical: Source-of-truth memories. Salience floor 0.7, never stage.
|
|
88
|
+
* Surfaced via cognitive `/activate` and deterministic queries.
|
|
89
|
+
*
|
|
90
|
+
* working: Default. Observations, findings, progress notes. Standard
|
|
91
|
+
* salience rules apply. Surfaced via all retrieval paths.
|
|
92
|
+
*
|
|
93
|
+
* ephemeral: Temporary context. Stronger time decay, lower recall priority.
|
|
94
|
+
*
|
|
95
|
+
* structural: (0.8+) System-written event-log records — chapter analyses,
|
|
96
|
+
* promise advancements, materialized-view feeds. Salience floor
|
|
97
|
+
* 0.7 like canonical, but EXCLUDED from cognitive `/activate`
|
|
98
|
+
* by default (callers opt in via `includeStructural: true`),
|
|
99
|
+
* skip temporal-adjacency edges, skip default embedding. Used
|
|
100
|
+
* for high-volume deterministic substrate where cognitive
|
|
101
|
+
* retrieval would just add noise.
|
|
102
|
+
*/
|
|
103
|
+
export type MemoryClass = 'canonical' | 'working' | 'ephemeral' | 'structural';
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Typed cross-record link stored alongside an engram in references_json.
|
|
107
|
+
* Wired through HTTP in 0.8 Cluster D; schema slot added in Cluster A.
|
|
108
|
+
*/
|
|
109
|
+
export interface EngramReference {
|
|
110
|
+
type: 'advances' | 'resolves' | 'subverts' | 'abandons' | 'extends' | 'supersedes';
|
|
111
|
+
/** ID of the referenced engram. Either this or matchConcept must be set. */
|
|
112
|
+
matchEngramId?: string;
|
|
113
|
+
/** Concept of the referenced engram (resolved at write time in 0.8 D). */
|
|
114
|
+
matchConcept?: string;
|
|
115
|
+
}
|
|
75
116
|
|
|
76
117
|
/**
|
|
77
118
|
* Memory type — content classification for retrieval routing.
|
|
@@ -113,6 +154,10 @@ export interface EngramCreate {
|
|
|
113
154
|
taskStatus?: TaskStatus;
|
|
114
155
|
taskPriority?: TaskPriority;
|
|
115
156
|
blockedBy?: string;
|
|
157
|
+
/** Optional story-time / sequence ordering (0.8 Cluster A). */
|
|
158
|
+
sequence?: number;
|
|
159
|
+
/** Typed cross-record links (0.8 Cluster A schema; HTTP in Cluster D). */
|
|
160
|
+
references?: EngramReference[];
|
|
116
161
|
}
|
|
117
162
|
|
|
118
163
|
/**
|
|
@@ -145,6 +190,20 @@ export interface ActivationResult {
|
|
|
145
190
|
phaseScores: PhaseScores; // Per-phase breakdown for explainability
|
|
146
191
|
why: string; // Human-readable explanation
|
|
147
192
|
associations: Association[];
|
|
193
|
+
/**
|
|
194
|
+
* Recall confidence — score-distribution-aware signal in [0, 1].
|
|
195
|
+
* Same value on every result in the same recall (it describes the
|
|
196
|
+
* *set*, not the individual). Computed once after final ranking.
|
|
197
|
+
* See `src/engine/confidence.ts` for the formula.
|
|
198
|
+
*/
|
|
199
|
+
confidence?: number;
|
|
200
|
+
/**
|
|
201
|
+
* Confidence-adaptive content preview (Paper 3: cognitive teaming).
|
|
202
|
+
* Set when the query opts in via `granularity: 'compact' | 'auto'`.
|
|
203
|
+
* Trades depth for breadth — short when the agent should scan a diverse
|
|
204
|
+
* set, full when there is a clear winner worth absorbing in full.
|
|
205
|
+
*/
|
|
206
|
+
summary?: string;
|
|
148
207
|
}
|
|
149
208
|
|
|
150
209
|
/**
|
|
@@ -183,11 +242,36 @@ export interface ActivationQuery {
|
|
|
183
242
|
useReranker?: boolean; // Enable cross-encoder re-ranking (default: true)
|
|
184
243
|
useExpansion?: boolean; // Enable query expansion (default: true)
|
|
185
244
|
abstentionThreshold?: number; // Min reranker score to return results (default: 0)
|
|
245
|
+
/**
|
|
246
|
+
* Opt-in confidence-based abstention. When set, the recall returns []
|
|
247
|
+
* if the computed recall confidence (see src/engine/confidence.ts) falls
|
|
248
|
+
* below the threshold. Independent of `abstentionThreshold` (reranker-based);
|
|
249
|
+
* uses score-distribution shape rather than reranker score.
|
|
250
|
+
* Typical values: 0.10 (strict — only abstain on clearly noisy queries),
|
|
251
|
+
* 0.25 (balanced), 0.40 (aggressive — only return high-confidence recall).
|
|
252
|
+
*/
|
|
253
|
+
requireConfidence?: number;
|
|
186
254
|
internal?: boolean; // Skip access count increment, Hebbian update, and event logging (for system calls)
|
|
187
255
|
memoryType?: MemoryType; // Filter by memory type (episodic, semantic, procedural)
|
|
188
256
|
mode?: QueryMode; // Pipeline mode — 'auto' by default
|
|
189
257
|
workspace?: string; // Search across all agents in this workspace (hive mode). If unset, agent-scoped only.
|
|
190
258
|
bm25Only?: boolean; // Skip embedding — fast text-only retrieval for bulk/benchmark scenarios
|
|
259
|
+
/**
|
|
260
|
+
* Output granularity (Paper 3: cognitive teaming, Brill 2018 ACT-R collaboration).
|
|
261
|
+
* Controls how much engram content the activation engine surfaces back to the caller,
|
|
262
|
+
* trading depth for breadth based on recall quality.
|
|
263
|
+
*
|
|
264
|
+
* 'full' (default): no change — callers get the raw engram with full content.
|
|
265
|
+
* 'compact': every result gets a short `summary` field (first ~200 chars of content).
|
|
266
|
+
* Engram body is unchanged; callers can choose summary or content.
|
|
267
|
+
* 'auto': confidence-adaptive. When the recall has a clear winner (confidence
|
|
268
|
+
* ≥ AWM_GRANULARITY_AUTO_THRESHOLD, default 0.4), the top result keeps a
|
|
269
|
+
* full-content summary and lower-ranked results get compact ones —
|
|
270
|
+
* the agent absorbs the strong match in detail and scans alternatives.
|
|
271
|
+
* When confidence is low, all results get compact summaries so the
|
|
272
|
+
* agent can scan a diverse set without drowning in content.
|
|
273
|
+
*/
|
|
274
|
+
granularity?: 'full' | 'compact' | 'auto';
|
|
191
275
|
}
|
|
192
276
|
|
|
193
277
|
/**
|
|
@@ -198,11 +282,25 @@ export interface SearchQuery {
|
|
|
198
282
|
agentId: string;
|
|
199
283
|
text?: string; // Exact or partial text match
|
|
200
284
|
concept?: string; // Exact concept match
|
|
201
|
-
|
|
285
|
+
/** Tag filter — AND semantics. Existing field kept for compat; equivalent to `tagsAll`.
|
|
286
|
+
* If both `tags` and `tagsAll` are passed, results match tags from both arrays
|
|
287
|
+
* (intersection of both AND-filters). */
|
|
288
|
+
tags?: string[];
|
|
289
|
+
/** AND-filter: engram must have ALL of these tags. Alias for legacy `tags`. (0.8 Cluster B) */
|
|
290
|
+
tagsAll?: string[];
|
|
291
|
+
/** OR-filter: engram must have AT LEAST ONE of these tags. (0.8 Cluster B) */
|
|
292
|
+
tagsAny?: string[];
|
|
293
|
+
/** NOT-filter: engram must have NONE of these tags. (0.8 Cluster B) */
|
|
294
|
+
tagsNone?: string[];
|
|
202
295
|
stage?: EngramStage;
|
|
203
296
|
retracted?: boolean;
|
|
204
297
|
limit?: number;
|
|
205
298
|
offset?: number;
|
|
299
|
+
/** Sort field. Defaults to `lastAccessed` (existing behavior preserved when
|
|
300
|
+
* unspecified). `sequence` sorts NULL last. (0.8 Cluster B) */
|
|
301
|
+
sortBy?: 'createdAt' | 'sequence' | 'salience' | 'confidence' | 'lastAccessed';
|
|
302
|
+
/** Sort direction. Default `desc`. (0.8 Cluster B) */
|
|
303
|
+
sortOrder?: 'asc' | 'desc';
|
|
206
304
|
}
|
|
207
305
|
|
|
208
306
|
/**
|
package/src/types/eval.ts
CHANGED
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
// Copyright 2026 Robert Winter / Complete Ideas
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
/**
|
|
4
|
-
* Evaluation types — measuring whether memory actually helps.
|
|
5
|
-
*
|
|
6
|
-
* Four measurement dimensions:
|
|
7
|
-
* 1. Retrieval quality (precision, recall, latency)
|
|
8
|
-
* 2. Connection quality (edge utility, stability)
|
|
9
|
-
* 3. Staging accuracy (promotion precision, discard regret)
|
|
10
|
-
* 4. Task impact (with/without memory comparison)
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Single activation event record — logged for offline analysis.
|
|
15
|
-
*/
|
|
16
|
-
export interface ActivationEvent {
|
|
17
|
-
id: string;
|
|
18
|
-
agentId: string;
|
|
19
|
-
timestamp: Date;
|
|
20
|
-
context: string;
|
|
21
|
-
resultsReturned: number;
|
|
22
|
-
topScore: number;
|
|
23
|
-
latencyMs: number;
|
|
24
|
-
engramIds: string[];
|
|
25
|
-
feedback?: RetrievalFeedbackEvent[];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface RetrievalFeedbackEvent {
|
|
29
|
-
engramId: string;
|
|
30
|
-
useful: boolean;
|
|
31
|
-
timestamp: Date;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Staging lifecycle event — tracks promote/discard decisions.
|
|
36
|
-
*/
|
|
37
|
-
export interface StagingEvent {
|
|
38
|
-
engramId: string;
|
|
39
|
-
agentId: string;
|
|
40
|
-
action: 'promoted' | 'discarded' | 'expired';
|
|
41
|
-
resonanceScore: number | null;
|
|
42
|
-
timestamp: Date;
|
|
43
|
-
ageMs: number; // How long it lived in staging
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Aggregate metrics snapshot — computed periodically.
|
|
48
|
-
*/
|
|
49
|
-
export interface EvalMetrics {
|
|
50
|
-
agentId: string;
|
|
51
|
-
timestamp: Date;
|
|
52
|
-
window: string; // e.g., "24h", "7d"
|
|
53
|
-
|
|
54
|
-
// Retrieval quality
|
|
55
|
-
activationCount: number;
|
|
56
|
-
avgPrecisionAtK: number; // Of returned results, % judged useful
|
|
57
|
-
avgLatencyMs: number;
|
|
58
|
-
p95LatencyMs: number;
|
|
59
|
-
|
|
60
|
-
// Connection quality
|
|
61
|
-
totalEdges: number;
|
|
62
|
-
edgesUsedInActivation: number;
|
|
63
|
-
edgeUtilityRate: number; // % of edges that contributed to retrieval
|
|
64
|
-
avgEdgeSurvivalDays: number;
|
|
65
|
-
|
|
66
|
-
// Staging accuracy
|
|
67
|
-
totalStaged: number;
|
|
68
|
-
promotedCount: number;
|
|
69
|
-
discardedCount: number;
|
|
70
|
-
promotionPrecision: number; // % of promoted items later used
|
|
71
|
-
discardRegret: number; // % of discarded items agent re-introduced
|
|
72
|
-
|
|
73
|
-
// Memory health
|
|
74
|
-
activeEngramCount: number;
|
|
75
|
-
stagingEngramCount: number;
|
|
76
|
-
retractedCount: number;
|
|
77
|
-
consolidatedCount: number;
|
|
78
|
-
avgConfidence: number;
|
|
79
|
-
|
|
80
|
-
// Contamination tracking
|
|
81
|
-
staleUsageCount: number; // Activations using outdated engrams
|
|
82
|
-
retractionRate: number; // Rate of memories being invalidated
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Task trial — for with/without memory comparison.
|
|
87
|
-
*/
|
|
88
|
-
export interface TaskTrial {
|
|
89
|
-
id: string;
|
|
90
|
-
agentId: string;
|
|
91
|
-
taskDescription: string;
|
|
92
|
-
memoryEnabled: boolean;
|
|
93
|
-
startedAt: Date;
|
|
94
|
-
completedAt: Date | null;
|
|
95
|
-
success: boolean | null;
|
|
96
|
-
stepsToCompletion: number;
|
|
97
|
-
errorsEncountered: number;
|
|
98
|
-
memoriesActivated: number;
|
|
99
|
-
userCorrections: number;
|
|
100
|
-
}
|
|
1
|
+
// Copyright 2026 Robert Winter / Complete Ideas
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
/**
|
|
4
|
+
* Evaluation types — measuring whether memory actually helps.
|
|
5
|
+
*
|
|
6
|
+
* Four measurement dimensions:
|
|
7
|
+
* 1. Retrieval quality (precision, recall, latency)
|
|
8
|
+
* 2. Connection quality (edge utility, stability)
|
|
9
|
+
* 3. Staging accuracy (promotion precision, discard regret)
|
|
10
|
+
* 4. Task impact (with/without memory comparison)
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Single activation event record — logged for offline analysis.
|
|
15
|
+
*/
|
|
16
|
+
export interface ActivationEvent {
|
|
17
|
+
id: string;
|
|
18
|
+
agentId: string;
|
|
19
|
+
timestamp: Date;
|
|
20
|
+
context: string;
|
|
21
|
+
resultsReturned: number;
|
|
22
|
+
topScore: number;
|
|
23
|
+
latencyMs: number;
|
|
24
|
+
engramIds: string[];
|
|
25
|
+
feedback?: RetrievalFeedbackEvent[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface RetrievalFeedbackEvent {
|
|
29
|
+
engramId: string;
|
|
30
|
+
useful: boolean;
|
|
31
|
+
timestamp: Date;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Staging lifecycle event — tracks promote/discard decisions.
|
|
36
|
+
*/
|
|
37
|
+
export interface StagingEvent {
|
|
38
|
+
engramId: string;
|
|
39
|
+
agentId: string;
|
|
40
|
+
action: 'promoted' | 'discarded' | 'expired';
|
|
41
|
+
resonanceScore: number | null;
|
|
42
|
+
timestamp: Date;
|
|
43
|
+
ageMs: number; // How long it lived in staging
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Aggregate metrics snapshot — computed periodically.
|
|
48
|
+
*/
|
|
49
|
+
export interface EvalMetrics {
|
|
50
|
+
agentId: string;
|
|
51
|
+
timestamp: Date;
|
|
52
|
+
window: string; // e.g., "24h", "7d"
|
|
53
|
+
|
|
54
|
+
// Retrieval quality
|
|
55
|
+
activationCount: number;
|
|
56
|
+
avgPrecisionAtK: number; // Of returned results, % judged useful
|
|
57
|
+
avgLatencyMs: number;
|
|
58
|
+
p95LatencyMs: number;
|
|
59
|
+
|
|
60
|
+
// Connection quality
|
|
61
|
+
totalEdges: number;
|
|
62
|
+
edgesUsedInActivation: number;
|
|
63
|
+
edgeUtilityRate: number; // % of edges that contributed to retrieval
|
|
64
|
+
avgEdgeSurvivalDays: number;
|
|
65
|
+
|
|
66
|
+
// Staging accuracy
|
|
67
|
+
totalStaged: number;
|
|
68
|
+
promotedCount: number;
|
|
69
|
+
discardedCount: number;
|
|
70
|
+
promotionPrecision: number; // % of promoted items later used
|
|
71
|
+
discardRegret: number; // % of discarded items agent re-introduced
|
|
72
|
+
|
|
73
|
+
// Memory health
|
|
74
|
+
activeEngramCount: number;
|
|
75
|
+
stagingEngramCount: number;
|
|
76
|
+
retractedCount: number;
|
|
77
|
+
consolidatedCount: number;
|
|
78
|
+
avgConfidence: number;
|
|
79
|
+
|
|
80
|
+
// Contamination tracking
|
|
81
|
+
staleUsageCount: number; // Activations using outdated engrams
|
|
82
|
+
retractionRate: number; // Rate of memories being invalidated
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Task trial — for with/without memory comparison.
|
|
87
|
+
*/
|
|
88
|
+
export interface TaskTrial {
|
|
89
|
+
id: string;
|
|
90
|
+
agentId: string;
|
|
91
|
+
taskDescription: string;
|
|
92
|
+
memoryEnabled: boolean;
|
|
93
|
+
startedAt: Date;
|
|
94
|
+
completedAt: Date | null;
|
|
95
|
+
success: boolean | null;
|
|
96
|
+
stepsToCompletion: number;
|
|
97
|
+
errorsEncountered: number;
|
|
98
|
+
memoriesActivated: number;
|
|
99
|
+
userCorrections: number;
|
|
100
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// Copyright 2026 Robert Winter / Complete Ideas
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
export * from './engram.js';
|
|
4
|
-
export * from './agent.js';
|
|
5
|
-
export * from './eval.js';
|
|
6
|
-
export * from './checkpoint.js';
|
|
1
|
+
// Copyright 2026 Robert Winter / Complete Ideas
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
export * from './engram.js';
|
|
4
|
+
export * from './agent.js';
|
|
5
|
+
export * from './eval.js';
|
|
6
|
+
export * from './checkpoint.js';
|