@timmeck/brain-core 1.5.1 → 1.6.0
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 +10 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/memory/base-memory-engine.d.ts +19 -0
- package/dist/memory/base-memory-engine.js +35 -0
- package/dist/memory/base-memory-engine.js.map +1 -0
- package/dist/memory/types.d.ts +88 -0
- package/dist/memory/types.js +2 -0
- package/dist/memory/types.js.map +1 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -32,6 +32,8 @@ Brain Core extracts the common infrastructure used across all Brain MCP servers
|
|
|
32
32
|
| **BaseSynapseManager** | Abstract synapse manager with strengthen/weaken/activate/findPath/decay |
|
|
33
33
|
| **BaseLearningEngine** | Abstract timer-managed learning engine with error handling |
|
|
34
34
|
| **BaseResearchEngine** | Abstract timer-managed research engine with optional initial delay |
|
|
35
|
+
| **BaseMemoryEngine** | Abstract timer-managed memory engine for expiry/consolidation/decay (new in v1.6) |
|
|
36
|
+
| **Memory Types** | Shared types for Memory, Session, Remember/Recall/Session interfaces (new in v1.6) |
|
|
35
37
|
| **Utils** | Path normalization, data dir resolution, SHA-256 hashing |
|
|
36
38
|
|
|
37
39
|
## Installation
|
|
@@ -141,6 +143,7 @@ class MyRouter implements IpcRouter {
|
|
|
141
143
|
├── Synapses ───── Hebbian, Decay, Activation, Pathfinder, BaseSynapseManager
|
|
142
144
|
├── Learning ───── BaseLearningEngine (abstract, timer-managed)
|
|
143
145
|
├── Research ───── BaseResearchEngine (abstract, timer-managed)
|
|
146
|
+
├── Memory ────── BaseMemoryEngine, MemoryRecord, SessionRecord, shared interfaces
|
|
144
147
|
└── Cross-Brain ── CrossBrainClient, CrossBrainNotifier
|
|
145
148
|
```
|
|
146
149
|
|
|
@@ -148,10 +151,10 @@ class MyRouter implements IpcRouter {
|
|
|
148
151
|
|
|
149
152
|
| Brain | Version | Purpose | Ports |
|
|
150
153
|
|-------|---------|---------|-------|
|
|
151
|
-
| [Brain](https://github.com/timmeck/brain) | v2.
|
|
154
|
+
| [Brain](https://github.com/timmeck/brain) | v2.2.0 | Error memory, code intelligence & persistent context | 7777/7778 |
|
|
152
155
|
| [Trading Brain](https://github.com/timmeck/trading-brain) | v1.2.0 | Adaptive trading intelligence | 7779/7780 |
|
|
153
156
|
| [Marketing Brain](https://github.com/timmeck/marketing-brain) | v0.4.0 | Content strategy & social media | 7781/7782/7783 |
|
|
154
|
-
| [Brain Core](https://github.com/timmeck/brain-core) | v1.
|
|
157
|
+
| [Brain Core](https://github.com/timmeck/brain-core) | v1.6.0 | Shared infrastructure (this package) | — |
|
|
155
158
|
|
|
156
159
|
All three brains are standalone — brain-core is an **optional** shared dependency that eliminates ~600 lines of duplicated code across the ecosystem.
|
|
157
160
|
|
|
@@ -178,7 +181,7 @@ notifier.notifyPeer('trading-brain', 'insight:created', { insightId: 7 });
|
|
|
178
181
|
Abstract base classes eliminate timer boilerplate from learning and research engines:
|
|
179
182
|
|
|
180
183
|
```typescript
|
|
181
|
-
import { BaseLearningEngine, BaseResearchEngine } from '@timmeck/brain-core';
|
|
184
|
+
import { BaseLearningEngine, BaseResearchEngine, BaseMemoryEngine } from '@timmeck/brain-core';
|
|
182
185
|
|
|
183
186
|
class MyLearningEngine extends BaseLearningEngine {
|
|
184
187
|
runCycle() { /* your learning logic */ }
|
|
@@ -187,6 +190,10 @@ class MyLearningEngine extends BaseLearningEngine {
|
|
|
187
190
|
class MyResearchEngine extends BaseResearchEngine {
|
|
188
191
|
runCycle() { /* your research logic */ }
|
|
189
192
|
}
|
|
193
|
+
|
|
194
|
+
class MyMemoryEngine extends BaseMemoryEngine {
|
|
195
|
+
runCycle() { /* expiry checks, consolidation, importance decay */ }
|
|
196
|
+
}
|
|
190
197
|
```
|
|
191
198
|
|
|
192
199
|
Visit the [Brain Hub](https://timmeck.github.io/brain-hub/) for the full ecosystem overview.
|
package/dist/index.d.ts
CHANGED
|
@@ -30,6 +30,8 @@ export { BaseLearningEngine } from './learning/base-engine.js';
|
|
|
30
30
|
export type { LearningEngineConfig } from './learning/base-engine.js';
|
|
31
31
|
export { BaseResearchEngine } from './research/base-engine.js';
|
|
32
32
|
export type { ResearchEngineConfig } from './research/base-engine.js';
|
|
33
|
+
export type { MemoryRecord, SessionRecord, MemoryCategory, MemorySource, SessionOutcome, RememberInput, RecallInput, StartSessionInput, EndSessionInput, MemoryRepoInterface, SessionRepoInterface, MemoryEngineConfig, } from './memory/types.js';
|
|
34
|
+
export { BaseMemoryEngine } from './memory/base-memory-engine.js';
|
|
33
35
|
export { CrossBrainClient } from './cross-brain/client.js';
|
|
34
36
|
export type { BrainPeer } from './cross-brain/client.js';
|
|
35
37
|
export { CrossBrainNotifier } from './cross-brain/notifications.js';
|
package/dist/index.js
CHANGED
|
@@ -29,6 +29,7 @@ export { BaseSynapseManager } from './synapses/synapse-manager.js';
|
|
|
29
29
|
// ── Engines ───────────────────────────────────────────────
|
|
30
30
|
export { BaseLearningEngine } from './learning/base-engine.js';
|
|
31
31
|
export { BaseResearchEngine } from './research/base-engine.js';
|
|
32
|
+
export { BaseMemoryEngine } from './memory/base-memory-engine.js';
|
|
32
33
|
// ── Cross-Brain ────────────────────────────────────────────
|
|
33
34
|
export { CrossBrainClient } from './cross-brain/client.js';
|
|
34
35
|
export { CrossBrainNotifier } from './cross-brain/notifications.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,8DAA8D;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEzE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EA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,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE,6DAA6D;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAU/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAElE,8DAA8D;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { MemoryEngineConfig } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Abstract base class for memory engines.
|
|
4
|
+
* Handles timer lifecycle for periodic memory maintenance:
|
|
5
|
+
* - Expiry checks (deactivate expired memories)
|
|
6
|
+
* - Consolidation (merge similar memories)
|
|
7
|
+
* - Importance decay (reduce importance of never-recalled memories)
|
|
8
|
+
*
|
|
9
|
+
* Subclasses implement runCycle().
|
|
10
|
+
*/
|
|
11
|
+
export declare abstract class BaseMemoryEngine {
|
|
12
|
+
protected config: MemoryEngineConfig;
|
|
13
|
+
protected timer: ReturnType<typeof setInterval> | null;
|
|
14
|
+
protected logger: import("winston").Logger;
|
|
15
|
+
constructor(config: MemoryEngineConfig);
|
|
16
|
+
start(): void;
|
|
17
|
+
stop(): void;
|
|
18
|
+
abstract runCycle(): unknown;
|
|
19
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { getLogger } from '../utils/logger.js';
|
|
2
|
+
/**
|
|
3
|
+
* Abstract base class for memory engines.
|
|
4
|
+
* Handles timer lifecycle for periodic memory maintenance:
|
|
5
|
+
* - Expiry checks (deactivate expired memories)
|
|
6
|
+
* - Consolidation (merge similar memories)
|
|
7
|
+
* - Importance decay (reduce importance of never-recalled memories)
|
|
8
|
+
*
|
|
9
|
+
* Subclasses implement runCycle().
|
|
10
|
+
*/
|
|
11
|
+
export class BaseMemoryEngine {
|
|
12
|
+
config;
|
|
13
|
+
timer = null;
|
|
14
|
+
logger = getLogger();
|
|
15
|
+
constructor(config) {
|
|
16
|
+
this.config = config;
|
|
17
|
+
}
|
|
18
|
+
start() {
|
|
19
|
+
this.timer = setInterval(() => {
|
|
20
|
+
try {
|
|
21
|
+
this.runCycle();
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
this.logger.error('Memory engine cycle error', { error: String(err) });
|
|
25
|
+
}
|
|
26
|
+
}, this.config.intervalMs);
|
|
27
|
+
}
|
|
28
|
+
stop() {
|
|
29
|
+
if (this.timer) {
|
|
30
|
+
clearInterval(this.timer);
|
|
31
|
+
this.timer = null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=base-memory-engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-memory-engine.js","sourceRoot":"","sources":["../../src/memory/base-memory-engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG/C;;;;;;;;GAQG;AACH,MAAM,OAAgB,gBAAgB;IAId;IAHZ,KAAK,GAA0C,IAAI,CAAC;IACpD,MAAM,GAAG,SAAS,EAAE,CAAC;IAE/B,YAAsB,MAA0B;QAA1B,WAAM,GAAN,MAAM,CAAoB;IAAG,CAAC;IAEpD,KAAK;QACH,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;YAC5B,IAAI,CAAC;gBACH,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,2BAA2B,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACzE,CAAC;QACH,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAC7B,CAAC;IAED,IAAI;QACF,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC1B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QACpB,CAAC;IACH,CAAC;CAGF"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export type MemoryCategory = 'preference' | 'decision' | 'context' | 'fact' | 'goal' | 'lesson';
|
|
2
|
+
export type MemorySource = 'explicit' | 'inferred' | 'hook';
|
|
3
|
+
export type SessionOutcome = 'completed' | 'paused' | 'abandoned';
|
|
4
|
+
export interface MemoryRecord {
|
|
5
|
+
id: number;
|
|
6
|
+
project_id: number | null;
|
|
7
|
+
session_id: number | null;
|
|
8
|
+
category: MemoryCategory;
|
|
9
|
+
key: string | null;
|
|
10
|
+
content: string;
|
|
11
|
+
importance: number;
|
|
12
|
+
source: MemorySource;
|
|
13
|
+
tags: string | null;
|
|
14
|
+
expires_at: string | null;
|
|
15
|
+
superseded_by: number | null;
|
|
16
|
+
active: number;
|
|
17
|
+
created_at: string;
|
|
18
|
+
updated_at: string;
|
|
19
|
+
embedding: Buffer | null;
|
|
20
|
+
}
|
|
21
|
+
export interface SessionRecord {
|
|
22
|
+
id: number;
|
|
23
|
+
session_id: string;
|
|
24
|
+
project_id: number | null;
|
|
25
|
+
started_at: string;
|
|
26
|
+
ended_at: string | null;
|
|
27
|
+
summary: string | null;
|
|
28
|
+
goals: string | null;
|
|
29
|
+
outcome: SessionOutcome | null;
|
|
30
|
+
metadata: string | null;
|
|
31
|
+
embedding: Buffer | null;
|
|
32
|
+
}
|
|
33
|
+
export interface RememberInput {
|
|
34
|
+
content: string;
|
|
35
|
+
category: MemoryCategory;
|
|
36
|
+
key?: string;
|
|
37
|
+
importance?: number;
|
|
38
|
+
source?: MemorySource;
|
|
39
|
+
tags?: string[];
|
|
40
|
+
projectId?: number;
|
|
41
|
+
sessionId?: number;
|
|
42
|
+
expiresAt?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface RecallInput {
|
|
45
|
+
query: string;
|
|
46
|
+
category?: MemoryCategory;
|
|
47
|
+
projectId?: number;
|
|
48
|
+
limit?: number;
|
|
49
|
+
activeOnly?: boolean;
|
|
50
|
+
}
|
|
51
|
+
export interface StartSessionInput {
|
|
52
|
+
sessionId?: string;
|
|
53
|
+
projectId?: number;
|
|
54
|
+
goals?: string[];
|
|
55
|
+
metadata?: Record<string, unknown>;
|
|
56
|
+
}
|
|
57
|
+
export interface EndSessionInput {
|
|
58
|
+
sessionId: number;
|
|
59
|
+
summary: string;
|
|
60
|
+
outcome?: SessionOutcome;
|
|
61
|
+
}
|
|
62
|
+
export interface MemoryRepoInterface {
|
|
63
|
+
create(data: Omit<MemoryRecord, 'id' | 'created_at' | 'updated_at'>): number;
|
|
64
|
+
getById(id: number): MemoryRecord | undefined;
|
|
65
|
+
findByKey(projectId: number | null, key: string): MemoryRecord | undefined;
|
|
66
|
+
findByCategory(category: MemoryCategory, projectId?: number, limit?: number): MemoryRecord[];
|
|
67
|
+
findActive(projectId?: number, limit?: number): MemoryRecord[];
|
|
68
|
+
search(query: string, limit?: number): MemoryRecord[];
|
|
69
|
+
supersede(oldId: number, newId: number): void;
|
|
70
|
+
deactivate(id: number): void;
|
|
71
|
+
expireOld(): number;
|
|
72
|
+
update(id: number, data: Partial<MemoryRecord>): void;
|
|
73
|
+
}
|
|
74
|
+
export interface SessionRepoInterface {
|
|
75
|
+
create(data: Omit<SessionRecord, 'id'>): number;
|
|
76
|
+
getById(id: number): SessionRecord | undefined;
|
|
77
|
+
findBySessionId(sessionId: string): SessionRecord | undefined;
|
|
78
|
+
findByProject(projectId: number, limit?: number): SessionRecord[];
|
|
79
|
+
findRecent(limit?: number): SessionRecord[];
|
|
80
|
+
update(id: number, data: Partial<SessionRecord>): void;
|
|
81
|
+
search(query: string, limit?: number): SessionRecord[];
|
|
82
|
+
}
|
|
83
|
+
export interface MemoryEngineConfig {
|
|
84
|
+
intervalMs: number;
|
|
85
|
+
expiryCheckEnabled: boolean;
|
|
86
|
+
consolidationEnabled: boolean;
|
|
87
|
+
importanceDecayDays: number;
|
|
88
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/memory/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timmeck/brain-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Shared core infrastructure for the Brain ecosystem — IPC, MCP, CLI, DB connection, and utilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -29,7 +29,9 @@
|
|
|
29
29
|
"./synapses/activation": "./dist/synapses/activation.js",
|
|
30
30
|
"./synapses/pathfinder": "./dist/synapses/pathfinder.js",
|
|
31
31
|
"./synapses/synapse-manager": "./dist/synapses/synapse-manager.js",
|
|
32
|
-
"./cross-brain": "./dist/cross-brain/client.js"
|
|
32
|
+
"./cross-brain": "./dist/cross-brain/client.js",
|
|
33
|
+
"./memory/types": "./dist/memory/types.js",
|
|
34
|
+
"./memory/base-memory-engine": "./dist/memory/base-memory-engine.js"
|
|
33
35
|
},
|
|
34
36
|
"scripts": {
|
|
35
37
|
"build": "tsc",
|