agent-working-memory 0.8.6 → 0.8.7
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 +4 -2
- package/dist/adapters/common.d.ts.map +1 -1
- package/dist/adapters/common.js +13 -0
- package/dist/adapters/common.js.map +1 -1
- package/dist/api/routes.js +1 -1
- package/dist/cli/migrate.js +29 -29
- package/dist/cli.js +1 -1
- package/dist/coordination/circuit-breaker.js +23 -23
- package/dist/core/lite-compress.d.ts +26 -0
- package/dist/core/lite-compress.d.ts.map +1 -0
- package/dist/core/lite-compress.js +105 -0
- package/dist/core/lite-compress.js.map +1 -0
- package/dist/mcp.d.ts +5 -1
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +58 -4
- package/dist/mcp.js.map +1 -1
- package/dist/storage/pglite-schema.js +143 -143
- package/dist/storage/pglite.js +138 -138
- package/package.json +4 -3
- package/src/adapters/common.ts +13 -0
- package/src/api/index.ts +3 -3
- package/src/api/routes.ts +1 -1
- package/src/cli/migrate.ts +307 -307
- package/src/cli.ts +1 -1
- package/src/coordination/circuit-breaker.ts +83 -83
- package/src/coordination/failure-modes.ts +50 -50
- package/src/core/decay.ts +63 -63
- package/src/core/embeddings.ts +110 -110
- package/src/core/index.ts +5 -5
- package/src/core/lite-compress.ts +129 -0
- package/src/core/logger.ts +36 -36
- package/src/core/ml-worker-entry.ts +194 -194
- package/src/core/ml-worker.ts +281 -281
- package/src/core/query-expander.ts +122 -122
- package/src/core/reranker.ts +119 -119
- package/src/engine/confidence.ts +120 -120
- package/src/engine/connections.ts +162 -162
- package/src/engine/consolidation-scheduler.ts +242 -242
- 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 -366
- package/src/engine/staging.ts +74 -74
- package/src/mcp.ts +70 -4
- package/src/storage/factory.ts +147 -147
- package/src/storage/index.ts +3 -3
- package/src/storage/pglite-schema.ts +166 -166
- package/src/storage/pglite.ts +1363 -1363
- package/src/storage/store.ts +80 -80
- package/src/types/agent.ts +67 -67
- package/src/types/checkpoint.ts +46 -46
- package/src/types/eval.ts +100 -100
- package/src/types/index.ts +6 -6
package/src/storage/store.ts
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
// Copyright 2026 Robert Winter / Complete Ideas
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
/**
|
|
4
|
-
* Backend-agnostic storage contract for AWM.
|
|
5
|
-
*
|
|
6
|
-
* AWM 0.8.x introduces a pluggable storage layer:
|
|
7
|
-
* - SQLiteEngramStore: better-sqlite3 + FTS5 + BLOB embeddings (current default)
|
|
8
|
-
* - PGliteEngramStore: @electric-sql/pglite + pgvector + tsvector (opt-in via
|
|
9
|
-
* `AWM_STORE_BACKEND=pglite`, planned default in 0.9.x)
|
|
10
|
-
* - PostgresEngramStore: real Postgres backend for scale (planned, post-1.0)
|
|
11
|
-
*
|
|
12
|
-
* All backends provide the same public surface — defined here as `IEngramStore`.
|
|
13
|
-
* The cognitive engines (activation, consolidation, Hebbian, eviction, etc.)
|
|
14
|
-
* accept `IEngramStore` and work against any conforming backend.
|
|
15
|
-
*
|
|
16
|
-
* The interface is derived from the SQLite implementation via TypeScript's
|
|
17
|
-
* `Omit<>` so it stays in sync automatically. SQLite-specific methods
|
|
18
|
-
* (DB handle access, WAL checkpointing, slim-cache management, integrity
|
|
19
|
-
* checks) are excluded — these are implementation-internal and don't belong
|
|
20
|
-
* in a backend-agnostic contract.
|
|
21
|
-
*
|
|
22
|
-
* Future backends MUST implement every method on `IEngramStore`. They MAY
|
|
23
|
-
* additionally expose backend-specific methods (e.g., PGlite-specific tooling,
|
|
24
|
-
* Postgres pool management) — those are not part of the contract.
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
import type { EngramStore as SqliteEngramStore } from './sqlite.js';
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Backend-specific methods on SqliteEngramStore that are NOT part of the
|
|
31
|
-
* shared contract. Other backends may provide functionally-similar methods
|
|
32
|
-
* under different names or not at all.
|
|
33
|
-
*/
|
|
34
|
-
type SqliteSpecificMethods =
|
|
35
|
-
| 'getDb' // Returns better-sqlite3 Database — SQLite-only API
|
|
36
|
-
| 'integrityCheck' // SQLite PRAGMA integrity_check
|
|
37
|
-
| 'walCheckpoint' // SQLite WAL checkpoint
|
|
38
|
-
| 'stopWalCheckpointTimer'
|
|
39
|
-
| 'backup' // SQLite backup API; PGlite/Postgres use pg_dump
|
|
40
|
-
| 'warmSlimCache' // In-memory cache pre-population (SQLite-specific perf opt)
|
|
41
|
-
| 'resetSlimCache'
|
|
42
|
-
| 'getSlimCacheStats'
|
|
43
|
-
| 'transaction'; // SQLite sync transaction helper — PGlite uses withTransaction
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* MaybePromise — covariant union that lets sync and async backends share one contract.
|
|
47
|
-
*
|
|
48
|
-
* Engines `await` every store call. `await T` resolves to T immediately when
|
|
49
|
-
* the backend is sync (SQLite, returning bare values) and resolves the Promise
|
|
50
|
-
* when the backend is async (PGlite). Both shapes satisfy the same interface.
|
|
51
|
-
*/
|
|
52
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Turn every method return type R into `MaybePromise<Awaited<R>>` so the
|
|
56
|
-
* contract accepts both sync and async backends.
|
|
57
|
-
*/
|
|
58
|
-
type AsyncifyMethods<T> = {
|
|
59
|
-
[K in keyof T]: T[K] extends (...args: infer A) => infer R
|
|
60
|
-
? (...args: A) => MaybePromise<Awaited<R>>
|
|
61
|
-
: T[K];
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* The backend-agnostic storage contract.
|
|
66
|
-
*
|
|
67
|
-
* Any class with this shape can be used as the EngramStore for the AWM
|
|
68
|
-
* cognitive engines. New backends should `implements IEngramStore` to get
|
|
69
|
-
* compile-time enforcement of the full surface.
|
|
70
|
-
*/
|
|
71
|
-
export type IEngramStore = AsyncifyMethods<Omit<SqliteEngramStore, SqliteSpecificMethods>>;
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Convenience type-only re-export so consumers can `import type { EngramStore }`
|
|
75
|
-
* from this module and get the backend-agnostic contract instead of the
|
|
76
|
-
* SQLite-specific class. Existing imports from `'../storage/sqlite.js'`
|
|
77
|
-
* continue to work and resolve to the SQLite class (which is a structural
|
|
78
|
-
* supertype of IEngramStore).
|
|
79
|
-
*/
|
|
80
|
-
export type EngramStore = IEngramStore;
|
|
1
|
+
// Copyright 2026 Robert Winter / Complete Ideas
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
/**
|
|
4
|
+
* Backend-agnostic storage contract for AWM.
|
|
5
|
+
*
|
|
6
|
+
* AWM 0.8.x introduces a pluggable storage layer:
|
|
7
|
+
* - SQLiteEngramStore: better-sqlite3 + FTS5 + BLOB embeddings (current default)
|
|
8
|
+
* - PGliteEngramStore: @electric-sql/pglite + pgvector + tsvector (opt-in via
|
|
9
|
+
* `AWM_STORE_BACKEND=pglite`, planned default in 0.9.x)
|
|
10
|
+
* - PostgresEngramStore: real Postgres backend for scale (planned, post-1.0)
|
|
11
|
+
*
|
|
12
|
+
* All backends provide the same public surface — defined here as `IEngramStore`.
|
|
13
|
+
* The cognitive engines (activation, consolidation, Hebbian, eviction, etc.)
|
|
14
|
+
* accept `IEngramStore` and work against any conforming backend.
|
|
15
|
+
*
|
|
16
|
+
* The interface is derived from the SQLite implementation via TypeScript's
|
|
17
|
+
* `Omit<>` so it stays in sync automatically. SQLite-specific methods
|
|
18
|
+
* (DB handle access, WAL checkpointing, slim-cache management, integrity
|
|
19
|
+
* checks) are excluded — these are implementation-internal and don't belong
|
|
20
|
+
* in a backend-agnostic contract.
|
|
21
|
+
*
|
|
22
|
+
* Future backends MUST implement every method on `IEngramStore`. They MAY
|
|
23
|
+
* additionally expose backend-specific methods (e.g., PGlite-specific tooling,
|
|
24
|
+
* Postgres pool management) — those are not part of the contract.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import type { EngramStore as SqliteEngramStore } from './sqlite.js';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Backend-specific methods on SqliteEngramStore that are NOT part of the
|
|
31
|
+
* shared contract. Other backends may provide functionally-similar methods
|
|
32
|
+
* under different names or not at all.
|
|
33
|
+
*/
|
|
34
|
+
type SqliteSpecificMethods =
|
|
35
|
+
| 'getDb' // Returns better-sqlite3 Database — SQLite-only API
|
|
36
|
+
| 'integrityCheck' // SQLite PRAGMA integrity_check
|
|
37
|
+
| 'walCheckpoint' // SQLite WAL checkpoint
|
|
38
|
+
| 'stopWalCheckpointTimer'
|
|
39
|
+
| 'backup' // SQLite backup API; PGlite/Postgres use pg_dump
|
|
40
|
+
| 'warmSlimCache' // In-memory cache pre-population (SQLite-specific perf opt)
|
|
41
|
+
| 'resetSlimCache'
|
|
42
|
+
| 'getSlimCacheStats'
|
|
43
|
+
| 'transaction'; // SQLite sync transaction helper — PGlite uses withTransaction
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* MaybePromise — covariant union that lets sync and async backends share one contract.
|
|
47
|
+
*
|
|
48
|
+
* Engines `await` every store call. `await T` resolves to T immediately when
|
|
49
|
+
* the backend is sync (SQLite, returning bare values) and resolves the Promise
|
|
50
|
+
* when the backend is async (PGlite). Both shapes satisfy the same interface.
|
|
51
|
+
*/
|
|
52
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Turn every method return type R into `MaybePromise<Awaited<R>>` so the
|
|
56
|
+
* contract accepts both sync and async backends.
|
|
57
|
+
*/
|
|
58
|
+
type AsyncifyMethods<T> = {
|
|
59
|
+
[K in keyof T]: T[K] extends (...args: infer A) => infer R
|
|
60
|
+
? (...args: A) => MaybePromise<Awaited<R>>
|
|
61
|
+
: T[K];
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The backend-agnostic storage contract.
|
|
66
|
+
*
|
|
67
|
+
* Any class with this shape can be used as the EngramStore for the AWM
|
|
68
|
+
* cognitive engines. New backends should `implements IEngramStore` to get
|
|
69
|
+
* compile-time enforcement of the full surface.
|
|
70
|
+
*/
|
|
71
|
+
export type IEngramStore = AsyncifyMethods<Omit<SqliteEngramStore, SqliteSpecificMethods>>;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Convenience type-only re-export so consumers can `import type { EngramStore }`
|
|
75
|
+
* from this module and get the backend-agnostic contract instead of the
|
|
76
|
+
* SQLite-specific class. Existing imports from `'../storage/sqlite.js'`
|
|
77
|
+
* continue to work and resolve to the SQLite class (which is a structural
|
|
78
|
+
* supertype of IEngramStore).
|
|
79
|
+
*/
|
|
80
|
+
export type EngramStore = IEngramStore;
|
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/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';
|