@timmeck/brain-core 1.2.0 → 1.5.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 +64 -14
- package/brain.log +6 -0
- package/dist/config/__tests__/loader.test.d.ts +1 -0
- package/dist/config/__tests__/loader.test.js +85 -0
- package/dist/config/__tests__/loader.test.js.map +1 -0
- package/dist/config/loader.d.ts +15 -0
- package/dist/config/loader.js +39 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/cross-brain/__tests__/notifications.test.d.ts +1 -0
- package/dist/cross-brain/__tests__/notifications.test.js +52 -0
- package/dist/cross-brain/__tests__/notifications.test.js.map +1 -0
- package/dist/cross-brain/notifications.d.ts +25 -0
- package/dist/cross-brain/notifications.js +51 -0
- package/dist/cross-brain/notifications.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -1
- package/dist/learning/__tests__/base-engine.test.d.ts +1 -0
- package/dist/learning/__tests__/base-engine.test.js +49 -0
- package/dist/learning/__tests__/base-engine.test.js.map +1 -0
- package/dist/learning/base-engine.d.ts +16 -0
- package/dist/learning/base-engine.js +30 -0
- package/dist/learning/base-engine.js.map +1 -0
- package/dist/math/__tests__/time-decay.test.d.ts +1 -0
- package/dist/math/__tests__/time-decay.test.js +37 -0
- package/dist/math/__tests__/time-decay.test.js.map +1 -0
- package/dist/math/__tests__/wilson-score.test.d.ts +1 -0
- package/dist/math/__tests__/wilson-score.test.js +43 -0
- package/dist/math/__tests__/wilson-score.test.js.map +1 -0
- package/dist/math/time-decay.d.ts +10 -0
- package/dist/math/time-decay.js +16 -0
- package/dist/math/time-decay.js.map +1 -0
- package/dist/math/wilson-score.d.ts +10 -0
- package/dist/math/wilson-score.js +21 -0
- package/dist/math/wilson-score.js.map +1 -0
- package/dist/research/__tests__/base-engine.test.d.ts +1 -0
- package/dist/research/__tests__/base-engine.test.js +56 -0
- package/dist/research/__tests__/base-engine.test.js.map +1 -0
- package/dist/research/base-engine.d.ts +20 -0
- package/dist/research/base-engine.js +46 -0
- package/dist/research/base-engine.js.map +1 -0
- package/dist/synapses/__tests__/activation.test.d.ts +1 -0
- package/dist/synapses/__tests__/activation.test.js +87 -0
- package/dist/synapses/__tests__/activation.test.js.map +1 -0
- package/dist/synapses/__tests__/decay.test.d.ts +1 -0
- package/dist/synapses/__tests__/decay.test.js +73 -0
- package/dist/synapses/__tests__/decay.test.js.map +1 -0
- package/dist/synapses/__tests__/hebbian.test.d.ts +1 -0
- package/dist/synapses/__tests__/hebbian.test.js +95 -0
- package/dist/synapses/__tests__/hebbian.test.js.map +1 -0
- package/dist/synapses/__tests__/pathfinder.test.d.ts +1 -0
- package/dist/synapses/__tests__/pathfinder.test.js +74 -0
- package/dist/synapses/__tests__/pathfinder.test.js.map +1 -0
- package/dist/synapses/__tests__/synapse-manager.test.d.ts +1 -0
- package/dist/synapses/__tests__/synapse-manager.test.js +94 -0
- package/dist/synapses/__tests__/synapse-manager.test.js.map +1 -0
- package/dist/synapses/activation.d.ts +6 -0
- package/dist/synapses/activation.js +54 -0
- package/dist/synapses/activation.js.map +1 -0
- package/dist/synapses/decay.d.ts +9 -0
- package/dist/synapses/decay.js +26 -0
- package/dist/synapses/decay.js.map +1 -0
- package/dist/synapses/hebbian.d.ts +12 -0
- package/dist/synapses/hebbian.js +45 -0
- package/dist/synapses/hebbian.js.map +1 -0
- package/dist/synapses/pathfinder.d.ts +6 -0
- package/dist/synapses/pathfinder.js +54 -0
- package/dist/synapses/pathfinder.js.map +1 -0
- package/dist/synapses/synapse-manager.d.ts +35 -0
- package/dist/synapses/synapse-manager.js +72 -0
- package/dist/synapses/synapse-manager.js.map +1 -0
- package/dist/synapses/types.d.ts +85 -0
- package/dist/synapses/types.js +7 -0
- package/dist/synapses/types.js.map +1 -0
- package/eslint.config.js +14 -0
- package/package.json +17 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pathfinder.test.js","sourceRoot":"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,GAAG,CAAC,QAAQ,EAAE,CAAC;QAC9B,MAAM,CAAC,MAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
// Mock logger before importing BaseSynapseManager
|
|
3
|
+
vi.mock('../../utils/logger.js', () => ({
|
|
4
|
+
getLogger: () => ({
|
|
5
|
+
debug: vi.fn(),
|
|
6
|
+
info: vi.fn(),
|
|
7
|
+
warn: vi.fn(),
|
|
8
|
+
error: vi.fn(),
|
|
9
|
+
}),
|
|
10
|
+
}));
|
|
11
|
+
import { BaseSynapseManager } from '../synapse-manager.js';
|
|
12
|
+
function synapse(overrides = {}) {
|
|
13
|
+
return {
|
|
14
|
+
id: 1,
|
|
15
|
+
source_type: 'a', source_id: 1,
|
|
16
|
+
target_type: 'b', target_id: 1,
|
|
17
|
+
synapse_type: 'test',
|
|
18
|
+
weight: 0.5,
|
|
19
|
+
activation_count: 1,
|
|
20
|
+
last_activated_at: new Date().toISOString(),
|
|
21
|
+
metadata: null,
|
|
22
|
+
created_at: new Date().toISOString(),
|
|
23
|
+
updated_at: new Date().toISOString(),
|
|
24
|
+
...overrides,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function mockRepo() {
|
|
28
|
+
return {
|
|
29
|
+
findBySourceTarget: vi.fn().mockReturnValue(synapse()),
|
|
30
|
+
create: vi.fn().mockReturnValue(1),
|
|
31
|
+
getById: vi.fn().mockReturnValue(synapse()),
|
|
32
|
+
update: vi.fn(),
|
|
33
|
+
delete: vi.fn(),
|
|
34
|
+
getOutgoing: vi.fn().mockReturnValue([]),
|
|
35
|
+
getIncoming: vi.fn().mockReturnValue([]),
|
|
36
|
+
findInactiveSince: vi.fn().mockReturnValue([]),
|
|
37
|
+
topByWeight: vi.fn().mockReturnValue([synapse()]),
|
|
38
|
+
topDiverse: vi.fn().mockReturnValue([synapse()]),
|
|
39
|
+
countNodes: vi.fn().mockReturnValue(10),
|
|
40
|
+
totalCount: vi.fn().mockReturnValue(25),
|
|
41
|
+
avgWeight: vi.fn().mockReturnValue(0.5),
|
|
42
|
+
countByType: vi.fn().mockReturnValue({ test: 25 }),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const config = {
|
|
46
|
+
initialWeight: 0.1,
|
|
47
|
+
learningRate: 0.15,
|
|
48
|
+
pruneThreshold: 0.05,
|
|
49
|
+
decayHalfLifeDays: 45,
|
|
50
|
+
decayAfterDays: 14,
|
|
51
|
+
maxDepth: 3,
|
|
52
|
+
minActivationWeight: 0.2,
|
|
53
|
+
};
|
|
54
|
+
describe('BaseSynapseManager', () => {
|
|
55
|
+
let repo;
|
|
56
|
+
let manager;
|
|
57
|
+
beforeEach(() => {
|
|
58
|
+
repo = mockRepo();
|
|
59
|
+
manager = new BaseSynapseManager(repo, config);
|
|
60
|
+
});
|
|
61
|
+
it('strengthen delegates to hebbian', () => {
|
|
62
|
+
const result = manager.strengthen({ type: 'a', id: 1 }, { type: 'b', id: 2 }, 'test');
|
|
63
|
+
expect(result).toBeDefined();
|
|
64
|
+
expect(repo.update).toHaveBeenCalled();
|
|
65
|
+
});
|
|
66
|
+
it('weaken delegates to hebbian', () => {
|
|
67
|
+
manager.weaken(1, 0.5);
|
|
68
|
+
expect(repo.getById).toHaveBeenCalledWith(1);
|
|
69
|
+
});
|
|
70
|
+
it('find delegates to repo', () => {
|
|
71
|
+
manager.find({ type: 'a', id: 1 }, { type: 'b', id: 1 }, 'test');
|
|
72
|
+
expect(repo.findBySourceTarget).toHaveBeenCalled();
|
|
73
|
+
});
|
|
74
|
+
it('activate uses config defaults', () => {
|
|
75
|
+
manager.activate({ type: 'a', id: 1 });
|
|
76
|
+
expect(repo.getOutgoing).toHaveBeenCalled();
|
|
77
|
+
});
|
|
78
|
+
it('runDecay returns results', () => {
|
|
79
|
+
const result = manager.runDecay();
|
|
80
|
+
expect(result).toEqual({ decayed: 0, pruned: 0 });
|
|
81
|
+
});
|
|
82
|
+
it('getNetworkStats returns stats', () => {
|
|
83
|
+
const stats = manager.getNetworkStats();
|
|
84
|
+
expect(stats.totalNodes).toBe(10);
|
|
85
|
+
expect(stats.totalSynapses).toBe(25);
|
|
86
|
+
expect(stats.avgWeight).toBe(0.5);
|
|
87
|
+
});
|
|
88
|
+
it('getStrongestSynapses delegates to repo', () => {
|
|
89
|
+
const result = manager.getStrongestSynapses(10);
|
|
90
|
+
expect(result).toHaveLength(1);
|
|
91
|
+
expect(repo.topByWeight).toHaveBeenCalledWith(10);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
//# sourceMappingURL=synapse-manager.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"synapse-manager.test.js","sourceRoot":"","sources":["../../../src/synapses/__tests__/synapse-manager.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAE9D,kDAAkD;AAClD,EAAE,CAAC,IAAI,CAAC,uBAAuB,EAAE,GAAG,EAAE,CAAC,CAAC;IACtC,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC;QAChB,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE;QACd,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE;QACb,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE;QACb,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE;KACf,CAAC;CACH,CAAC,CAAC,CAAC;AAEJ,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAG3D,SAAS,OAAO,CAAC,YAAoC,EAAE;IACrD,OAAO;QACL,EAAE,EAAE,CAAC;QACL,WAAW,EAAE,GAAG,EAAE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,MAAM,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAC;QAChD,MAAM,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QAC/B,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { NodeRef, ActivationResult, SynapseRepoInterface } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Spreading activation through the synapse network.
|
|
4
|
+
* BFS traversal that propagates energy through weighted connections.
|
|
5
|
+
*/
|
|
6
|
+
export declare function spreadingActivation(repo: SynapseRepoInterface, startNode: NodeRef, maxDepth?: number, minWeight?: number): ActivationResult[];
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spreading activation through the synapse network.
|
|
3
|
+
* BFS traversal that propagates energy through weighted connections.
|
|
4
|
+
*/
|
|
5
|
+
export function spreadingActivation(repo, startNode, maxDepth = 3, minWeight = 0.2) {
|
|
6
|
+
const visited = new Set();
|
|
7
|
+
const results = [];
|
|
8
|
+
const queue = [{ node: startNode, depth: 0, pathWeight: 1.0, path: [] }];
|
|
9
|
+
while (queue.length > 0) {
|
|
10
|
+
const current = queue.shift();
|
|
11
|
+
const key = `${current.node.type}:${current.node.id}`;
|
|
12
|
+
if (visited.has(key))
|
|
13
|
+
continue;
|
|
14
|
+
if (current.depth > maxDepth)
|
|
15
|
+
continue;
|
|
16
|
+
if (current.pathWeight < minWeight)
|
|
17
|
+
continue;
|
|
18
|
+
visited.add(key);
|
|
19
|
+
if (current.depth > 0) {
|
|
20
|
+
results.push({
|
|
21
|
+
node: current.node,
|
|
22
|
+
activation: current.pathWeight,
|
|
23
|
+
depth: current.depth,
|
|
24
|
+
path: current.path,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
const outgoing = repo.getOutgoing(current.node.type, current.node.id);
|
|
28
|
+
const incoming = repo.getIncoming(current.node.type, current.node.id);
|
|
29
|
+
for (const synapse of outgoing) {
|
|
30
|
+
const nextWeight = current.pathWeight * synapse.weight;
|
|
31
|
+
if (nextWeight >= minWeight) {
|
|
32
|
+
queue.push({
|
|
33
|
+
node: { type: synapse.target_type, id: synapse.target_id },
|
|
34
|
+
depth: current.depth + 1,
|
|
35
|
+
pathWeight: nextWeight,
|
|
36
|
+
path: [...current.path, `--${synapse.synapse_type}-->`],
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
for (const synapse of incoming) {
|
|
41
|
+
const nextWeight = current.pathWeight * synapse.weight;
|
|
42
|
+
if (nextWeight >= minWeight) {
|
|
43
|
+
queue.push({
|
|
44
|
+
node: { type: synapse.source_type, id: synapse.source_id },
|
|
45
|
+
depth: current.depth + 1,
|
|
46
|
+
pathWeight: nextWeight,
|
|
47
|
+
path: [...current.path, `<--${synapse.synapse_type}--`],
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return results.sort((a, b) => b.activation - a.activation);
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=activation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activation.js","sourceRoot":"","sources":["../../src/synapses/activation.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CACjC,IAA0B,EAC1B,SAAkB,EAClB,WAAmB,CAAC,EACpB,YAAoB,GAAG;IAEvB,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,MAAM,OAAO,GAAuB,EAAE,CAAC;IAEvC,MAAM,KAAK,GAKN,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;IAEhE,OAAO,KA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AAE;oBAC1D,KAAK,EAAE,OAAO,CAAC,KAAK,GAAG,CAAC;oBACxB,UAAU,EAAE,UAAU;oBACtB,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,KAAK,OAAO,CAAC,YAAY,KAAK,CAAC;iBACxD,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;YACvD,IAAI,UAAU,IAAI,SAAS,EAAE,CAAC;gBAC5B,KAAK,CAAC,IAAI,CAAC;oBACT,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,WAAW,EAAE,EAAE,EAAE,OAAO,CAAC,SAAS,EAAE;oBAC1D,KAAK,EAAE,OAAO,CAAC,KAAK,GAAG,CAAC;oBACxB,UAAU,EAAE,UAAU;oBACtB,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,YAAY,IAAI,CAAC;iBACxD,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC;AAC7D,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DecayConfig, SynapseRepoInterface } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Apply time-based decay to all stale synapses.
|
|
4
|
+
* Prunes synapses that decay below the threshold.
|
|
5
|
+
*/
|
|
6
|
+
export declare function decayAll(repo: SynapseRepoInterface, config: DecayConfig): {
|
|
7
|
+
decayed: number;
|
|
8
|
+
pruned: number;
|
|
9
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { timeDecayFactor } from '../math/time-decay.js';
|
|
2
|
+
/**
|
|
3
|
+
* Apply time-based decay to all stale synapses.
|
|
4
|
+
* Prunes synapses that decay below the threshold.
|
|
5
|
+
*/
|
|
6
|
+
export function decayAll(repo, config) {
|
|
7
|
+
const cutoff = new Date();
|
|
8
|
+
cutoff.setDate(cutoff.getDate() - config.decayAfterDays);
|
|
9
|
+
const stale = repo.findInactiveSince(cutoff.toISOString());
|
|
10
|
+
let pruned = 0;
|
|
11
|
+
let decayed = 0;
|
|
12
|
+
for (const synapse of stale) {
|
|
13
|
+
const factor = timeDecayFactor(synapse.last_activated_at, config.decayHalfLifeDays);
|
|
14
|
+
const newWeight = synapse.weight * factor;
|
|
15
|
+
if (newWeight < config.pruneThreshold) {
|
|
16
|
+
repo.delete(synapse.id);
|
|
17
|
+
pruned++;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
repo.update(synapse.id, { weight: newWeight });
|
|
21
|
+
decayed++;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return { decayed, pruned };
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=decay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decay.js","sourceRoot":"","sources":["../../src/synapses/decay.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD;;;GAGG;AACH,MAAM,UAAU,QAAQ,CACtB,IAA0B,EAC1B,MAAmB;IAEnB,MAAM,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;IAC1B,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;IAEzD,MAAM,KAAK,GAAG,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;IAC3D,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,IAAI,OAAO,GAAG,CAAC,CAAC;IAEhB,KAAK,MAAM,OAAO,IAAI,KAAK,EAAE,CAAC;QAC5B,MAAM,MAAM,GAAG,eAAe,CAAC,OAAO,CAAC,iBAAiB,EAAE,MAAM,CAAC,iBAAiB,CAAC,CAAC;QACpF,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;QAE1C,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,EAAE,CAAC;YACtC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACxB,MAAM,EAAE,CAAC;QACX,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;YAC/C,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { NodeRef, SynapseRecord, HebbianConfig, SynapseRepoInterface } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Hebbian learning: strengthen a synapse between two nodes.
|
|
4
|
+
* If the synapse exists, weight grows asymptotically toward 1.0.
|
|
5
|
+
* If new, creates with initialWeight.
|
|
6
|
+
*/
|
|
7
|
+
export declare function strengthen(repo: SynapseRepoInterface, source: NodeRef, target: NodeRef, synapseType: string, config: HebbianConfig, context?: Record<string, unknown>): SynapseRecord;
|
|
8
|
+
/**
|
|
9
|
+
* Weaken a synapse by a multiplicative factor.
|
|
10
|
+
* Prunes if weight drops below threshold.
|
|
11
|
+
*/
|
|
12
|
+
export declare function weaken(repo: SynapseRepoInterface, synapseId: number, config: HebbianConfig, factor?: number): void;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hebbian learning: strengthen a synapse between two nodes.
|
|
3
|
+
* If the synapse exists, weight grows asymptotically toward 1.0.
|
|
4
|
+
* If new, creates with initialWeight.
|
|
5
|
+
*/
|
|
6
|
+
export function strengthen(repo, source, target, synapseType, config, context) {
|
|
7
|
+
const existing = repo.findBySourceTarget(source.type, source.id, target.type, target.id, synapseType);
|
|
8
|
+
if (existing) {
|
|
9
|
+
// Hebbian: weight grows logarithmically, saturates at 1.0
|
|
10
|
+
const newWeight = Math.min(1.0, existing.weight + (1.0 - existing.weight) * config.learningRate);
|
|
11
|
+
repo.update(existing.id, {
|
|
12
|
+
weight: newWeight,
|
|
13
|
+
activation_count: existing.activation_count + 1,
|
|
14
|
+
last_activated_at: new Date().toISOString(),
|
|
15
|
+
});
|
|
16
|
+
return { ...existing, weight: newWeight, activation_count: existing.activation_count + 1 };
|
|
17
|
+
}
|
|
18
|
+
const id = repo.create({
|
|
19
|
+
source_type: source.type,
|
|
20
|
+
source_id: source.id,
|
|
21
|
+
target_type: target.type,
|
|
22
|
+
target_id: target.id,
|
|
23
|
+
synapse_type: synapseType,
|
|
24
|
+
weight: config.initialWeight,
|
|
25
|
+
metadata: context ? JSON.stringify(context) : null,
|
|
26
|
+
});
|
|
27
|
+
return repo.getById(id);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Weaken a synapse by a multiplicative factor.
|
|
31
|
+
* Prunes if weight drops below threshold.
|
|
32
|
+
*/
|
|
33
|
+
export function weaken(repo, synapseId, config, factor = 0.5) {
|
|
34
|
+
const synapse = repo.getById(synapseId);
|
|
35
|
+
if (!synapse)
|
|
36
|
+
return;
|
|
37
|
+
const newWeight = synapse.weight * factor;
|
|
38
|
+
if (newWeight < config.pruneThreshold) {
|
|
39
|
+
repo.delete(synapseId);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
repo.update(synapseId, { weight: newWeight });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=hebbian.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hebbian.js","sourceRoot":"","sources":["../../src/synapses/hebbian.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,UAAU,C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AAC;AAED;;;GAGG;AACH,MAAM,UAAU,MAAM,CACpB,IAA0B,EAC1B,SAAiB,EACjB,MAAqB,EACrB,SAAiB,GAAG;IAEpB,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACxC,IAAI,CAAC,OAAO;QAAE,OAAO;IAErB,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;IAC1C,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,EAAE,CAAC;QACtC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACzB,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;IAChD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PathNode, SynapsePath, SynapseRepoInterface } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Find the highest-weight path between two nodes in the synapse network.
|
|
4
|
+
* Uses BFS with bidirectional traversal (outgoing + incoming).
|
|
5
|
+
*/
|
|
6
|
+
export declare function findPath(repo: SynapseRepoInterface, from: PathNode, to: PathNode, maxDepth?: number): SynapsePath | null;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Find the highest-weight path between two nodes in the synapse network.
|
|
3
|
+
* Uses BFS with bidirectional traversal (outgoing + incoming).
|
|
4
|
+
*/
|
|
5
|
+
export function findPath(repo, from, to, maxDepth = 5) {
|
|
6
|
+
const visited = new Set();
|
|
7
|
+
const queue = [{ node: from, path: [], totalWeight: 1.0 }];
|
|
8
|
+
let bestPath = null;
|
|
9
|
+
while (queue.length > 0) {
|
|
10
|
+
const current = queue.shift();
|
|
11
|
+
const key = `${current.node.type}:${current.node.id}`;
|
|
12
|
+
if (visited.has(key))
|
|
13
|
+
continue;
|
|
14
|
+
visited.add(key);
|
|
15
|
+
if (current.node.type === to.type && current.node.id === to.id) {
|
|
16
|
+
if (!bestPath || current.totalWeight > bestPath.totalWeight) {
|
|
17
|
+
bestPath = {
|
|
18
|
+
from,
|
|
19
|
+
to,
|
|
20
|
+
synapses: current.path,
|
|
21
|
+
totalWeight: current.totalWeight,
|
|
22
|
+
hops: current.path.length,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (current.path.length >= maxDepth)
|
|
28
|
+
continue;
|
|
29
|
+
const outgoing = repo.getOutgoing(current.node.type, current.node.id);
|
|
30
|
+
for (const synapse of outgoing) {
|
|
31
|
+
const targetKey = `${synapse.target_type}:${synapse.target_id}`;
|
|
32
|
+
if (!visited.has(targetKey)) {
|
|
33
|
+
queue.push({
|
|
34
|
+
node: { type: synapse.target_type, id: synapse.target_id },
|
|
35
|
+
path: [...current.path, synapse],
|
|
36
|
+
totalWeight: current.totalWeight * synapse.weight,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const incoming = repo.getIncoming(current.node.type, current.node.id);
|
|
41
|
+
for (const synapse of incoming) {
|
|
42
|
+
const sourceKey = `${synapse.source_type}:${synapse.source_id}`;
|
|
43
|
+
if (!visited.has(sourceKey)) {
|
|
44
|
+
queue.push({
|
|
45
|
+
node: { type: synapse.source_type, id: synapse.source_id },
|
|
46
|
+
path: [...current.path, synapse],
|
|
47
|
+
totalWeight: current.totalWeight * synapse.weight,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return bestPath;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=pathfinder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pathfinder.js","sourceRoot":"","sources":["../../src/synapses/pathfinder.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,QAAQ,CACtB,IAA0B,EAC1B,IAAc,EACd,EAAY,EACZ,WAAmB,CAAC;IAE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|
+
export interface SynapseManagerConfig {
|
|
3
|
+
initialWeight: number;
|
|
4
|
+
learningRate: number;
|
|
5
|
+
pruneThreshold: number;
|
|
6
|
+
decayHalfLifeDays: number;
|
|
7
|
+
decayAfterDays: number;
|
|
8
|
+
maxDepth: number;
|
|
9
|
+
minActivationWeight: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Base synapse manager shared across all brains.
|
|
13
|
+
* Each brain extends this with domain-specific context methods
|
|
14
|
+
* (e.g. getErrorContext, getPostContext, getTradeContext).
|
|
15
|
+
*/
|
|
16
|
+
export declare class BaseSynapseManager {
|
|
17
|
+
protected repo: SynapseRepoInterface;
|
|
18
|
+
protected config: SynapseManagerConfig;
|
|
19
|
+
protected logger: import("winston").Logger;
|
|
20
|
+
constructor(repo: SynapseRepoInterface, config: SynapseManagerConfig);
|
|
21
|
+
strengthen(source: NodeRef, target: NodeRef, synapseType: string, context?: Record<string, unknown>): SynapseRecord;
|
|
22
|
+
weaken(synapseId: number, factor?: number): void;
|
|
23
|
+
find(source: NodeRef, target: NodeRef, synapseType: string): SynapseRecord | undefined;
|
|
24
|
+
activate(startNode: NodeRef, maxDepth?: number, minWeight?: number): ActivationResult[];
|
|
25
|
+
findPath(from: NodeRef, to: NodeRef, maxDepth?: number): SynapsePath | null;
|
|
26
|
+
runDecay(): {
|
|
27
|
+
decayed: number;
|
|
28
|
+
pruned: number;
|
|
29
|
+
};
|
|
30
|
+
getStrongestSynapses(limit?: number): SynapseRecord[];
|
|
31
|
+
getDiverseSynapses(perType?: number): SynapseRecord[];
|
|
32
|
+
getNetworkStats(): NetworkStats;
|
|
33
|
+
private hebbianConfig;
|
|
34
|
+
private decayConfig;
|
|
35
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { strengthen, weaken } from './hebbian.js';
|
|
2
|
+
import { decayAll } from './decay.js';
|
|
3
|
+
import { spreadingActivation } from './activation.js';
|
|
4
|
+
import { findPath } from './pathfinder.js';
|
|
5
|
+
import { getLogger } from '../utils/logger.js';
|
|
6
|
+
/**
|
|
7
|
+
* Base synapse manager shared across all brains.
|
|
8
|
+
* Each brain extends this with domain-specific context methods
|
|
9
|
+
* (e.g. getErrorContext, getPostContext, getTradeContext).
|
|
10
|
+
*/
|
|
11
|
+
export class BaseSynapseManager {
|
|
12
|
+
repo;
|
|
13
|
+
config;
|
|
14
|
+
logger = getLogger();
|
|
15
|
+
constructor(repo, config) {
|
|
16
|
+
this.repo = repo;
|
|
17
|
+
this.config = config;
|
|
18
|
+
}
|
|
19
|
+
strengthen(source, target, synapseType, context) {
|
|
20
|
+
this.logger.debug(`Strengthening synapse ${source.type}:${source.id} --${synapseType}--> ${target.type}:${target.id}`);
|
|
21
|
+
return strengthen(this.repo, source, target, synapseType, this.hebbianConfig(), context);
|
|
22
|
+
}
|
|
23
|
+
weaken(synapseId, factor = 0.5) {
|
|
24
|
+
this.logger.debug(`Weakening synapse ${synapseId} by factor ${factor}`);
|
|
25
|
+
weaken(this.repo, synapseId, this.hebbianConfig(), factor);
|
|
26
|
+
}
|
|
27
|
+
find(source, target, synapseType) {
|
|
28
|
+
return this.repo.findBySourceTarget(source.type, source.id, target.type, target.id, synapseType);
|
|
29
|
+
}
|
|
30
|
+
activate(startNode, maxDepth, minWeight) {
|
|
31
|
+
return spreadingActivation(this.repo, startNode, maxDepth ?? this.config.maxDepth, minWeight ?? this.config.minActivationWeight);
|
|
32
|
+
}
|
|
33
|
+
findPath(from, to, maxDepth) {
|
|
34
|
+
return findPath(this.repo, from, to, maxDepth ?? this.config.maxDepth + 2);
|
|
35
|
+
}
|
|
36
|
+
runDecay() {
|
|
37
|
+
this.logger.info('Running synapse decay cycle');
|
|
38
|
+
const result = decayAll(this.repo, this.decayConfig());
|
|
39
|
+
this.logger.info(`Decay complete: ${result.decayed} decayed, ${result.pruned} pruned`);
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
getStrongestSynapses(limit = 20) {
|
|
43
|
+
return this.repo.topByWeight(limit);
|
|
44
|
+
}
|
|
45
|
+
getDiverseSynapses(perType = 25) {
|
|
46
|
+
return this.repo.topDiverse(perType);
|
|
47
|
+
}
|
|
48
|
+
getNetworkStats() {
|
|
49
|
+
return {
|
|
50
|
+
totalNodes: this.repo.countNodes(),
|
|
51
|
+
totalSynapses: this.repo.totalCount(),
|
|
52
|
+
avgWeight: this.repo.avgWeight(),
|
|
53
|
+
nodesByType: {},
|
|
54
|
+
synapsesByType: this.repo.countByType(),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
hebbianConfig() {
|
|
58
|
+
return {
|
|
59
|
+
initialWeight: this.config.initialWeight,
|
|
60
|
+
learningRate: this.config.learningRate,
|
|
61
|
+
pruneThreshold: this.config.pruneThreshold,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
decayConfig() {
|
|
65
|
+
return {
|
|
66
|
+
decayHalfLifeDays: this.config.decayHalfLifeDays,
|
|
67
|
+
decayAfterDays: this.config.decayAfterDays,
|
|
68
|
+
pruneThreshold: this.config.pruneThreshold,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=synapse-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"synapse-manager.js","sourceRoot":"","sources":["../../src/synapses/synapse-manager.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAY/C;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IAIjB;IACA;IAJF,MAAM,GAAG,SAAS,EAAE,CAAC;IAE/B,YACY,IAA0B,EAC1B,M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ChD,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,cAAc;YAC1C,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,cAAc;SAC3C,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic synapse network types for the Brain ecosystem.
|
|
3
|
+
* Each brain provides its own NodeType/SynapseType string unions,
|
|
4
|
+
* but the record shape and algorithms are shared.
|
|
5
|
+
*/
|
|
6
|
+
export interface NodeRef {
|
|
7
|
+
type: string;
|
|
8
|
+
id: number;
|
|
9
|
+
}
|
|
10
|
+
export interface SynapseRecord {
|
|
11
|
+
id: number;
|
|
12
|
+
source_type: string;
|
|
13
|
+
source_id: number;
|
|
14
|
+
target_type: string;
|
|
15
|
+
target_id: number;
|
|
16
|
+
synapse_type: string;
|
|
17
|
+
weight: number;
|
|
18
|
+
activation_count: number;
|
|
19
|
+
last_activated_at: string;
|
|
20
|
+
metadata: string | null;
|
|
21
|
+
created_at: string;
|
|
22
|
+
updated_at: string;
|
|
23
|
+
}
|
|
24
|
+
export interface ActivationResult {
|
|
25
|
+
node: NodeRef;
|
|
26
|
+
activation: number;
|
|
27
|
+
depth: number;
|
|
28
|
+
path: string[];
|
|
29
|
+
}
|
|
30
|
+
export interface PathNode {
|
|
31
|
+
type: string;
|
|
32
|
+
id: number;
|
|
33
|
+
}
|
|
34
|
+
export interface SynapsePath {
|
|
35
|
+
from: PathNode;
|
|
36
|
+
to: PathNode;
|
|
37
|
+
synapses: SynapseRecord[];
|
|
38
|
+
totalWeight: number;
|
|
39
|
+
hops: number;
|
|
40
|
+
}
|
|
41
|
+
export interface NetworkStats {
|
|
42
|
+
totalNodes: number;
|
|
43
|
+
totalSynapses: number;
|
|
44
|
+
avgWeight: number;
|
|
45
|
+
nodesByType: Record<string, number>;
|
|
46
|
+
synapsesByType: Record<string, number>;
|
|
47
|
+
}
|
|
48
|
+
export interface HebbianConfig {
|
|
49
|
+
initialWeight: number;
|
|
50
|
+
learningRate: number;
|
|
51
|
+
pruneThreshold: number;
|
|
52
|
+
}
|
|
53
|
+
export interface DecayConfig {
|
|
54
|
+
decayHalfLifeDays: number;
|
|
55
|
+
decayAfterDays: number;
|
|
56
|
+
pruneThreshold: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Interface that synapse repositories must implement
|
|
60
|
+
* for the shared algorithms to work.
|
|
61
|
+
*/
|
|
62
|
+
export interface SynapseRepoInterface {
|
|
63
|
+
findBySourceTarget(sourceType: string, sourceId: number, targetType: string, targetId: number, synapseType: string): SynapseRecord | undefined;
|
|
64
|
+
create(data: {
|
|
65
|
+
source_type: string;
|
|
66
|
+
source_id: number;
|
|
67
|
+
target_type: string;
|
|
68
|
+
target_id: number;
|
|
69
|
+
synapse_type: string;
|
|
70
|
+
weight: number;
|
|
71
|
+
metadata: string | null;
|
|
72
|
+
}): number;
|
|
73
|
+
getById(id: number): SynapseRecord | undefined;
|
|
74
|
+
update(id: number, data: Partial<SynapseRecord>): void;
|
|
75
|
+
delete(id: number): void;
|
|
76
|
+
getOutgoing(nodeType: string, nodeId: number): SynapseRecord[];
|
|
77
|
+
getIncoming(nodeType: string, nodeId: number): SynapseRecord[];
|
|
78
|
+
findInactiveSince(cutoffIso: string): SynapseRecord[];
|
|
79
|
+
topByWeight(limit: number): SynapseRecord[];
|
|
80
|
+
topDiverse(perType: number): SynapseRecord[];
|
|
81
|
+
countNodes(): number;
|
|
82
|
+
totalCount(): number;
|
|
83
|
+
avgWeight(): number;
|
|
84
|
+
countByType(): Record<string, number>;
|
|
85
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/synapses/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import tseslint from 'typescript-eslint';
|
|
2
|
+
|
|
3
|
+
export default tseslint.config(
|
|
4
|
+
...tseslint.configs.recommended,
|
|
5
|
+
{
|
|
6
|
+
ignores: ['dist/', 'node_modules/', '**/*.js', '**/*.d.ts'],
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
rules: {
|
|
10
|
+
'@typescript-eslint/no-explicit-any': 'warn',
|
|
11
|
+
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timmeck/brain-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.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",
|
|
@@ -20,12 +20,24 @@
|
|
|
20
20
|
"./mcp/http-server": "./dist/mcp/http-server.js",
|
|
21
21
|
"./cli/colors": "./dist/cli/colors.js",
|
|
22
22
|
"./api/server": "./dist/api/server.js",
|
|
23
|
+
"./math/wilson-score": "./dist/math/wilson-score.js",
|
|
24
|
+
"./math/time-decay": "./dist/math/time-decay.js",
|
|
25
|
+
"./config/loader": "./dist/config/loader.js",
|
|
26
|
+
"./synapses/types": "./dist/synapses/types.js",
|
|
27
|
+
"./synapses/hebbian": "./dist/synapses/hebbian.js",
|
|
28
|
+
"./synapses/decay": "./dist/synapses/decay.js",
|
|
29
|
+
"./synapses/activation": "./dist/synapses/activation.js",
|
|
30
|
+
"./synapses/pathfinder": "./dist/synapses/pathfinder.js",
|
|
31
|
+
"./synapses/synapse-manager": "./dist/synapses/synapse-manager.js",
|
|
23
32
|
"./cross-brain": "./dist/cross-brain/client.js"
|
|
24
33
|
},
|
|
25
34
|
"scripts": {
|
|
26
35
|
"build": "tsc",
|
|
27
36
|
"dev": "tsx src/index.ts",
|
|
28
|
-
"test": "vitest"
|
|
37
|
+
"test": "vitest",
|
|
38
|
+
"lint": "eslint src/",
|
|
39
|
+
"lint:fix": "eslint src/ --fix",
|
|
40
|
+
"test:coverage": "vitest --coverage"
|
|
29
41
|
},
|
|
30
42
|
"keywords": [
|
|
31
43
|
"brain",
|
|
@@ -53,8 +65,11 @@
|
|
|
53
65
|
"devDependencies": {
|
|
54
66
|
"@types/better-sqlite3": "^7.6.12",
|
|
55
67
|
"@types/node": "^22.0.0",
|
|
68
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
69
|
+
"eslint": "^9.39.3",
|
|
56
70
|
"tsx": "^4.19.0",
|
|
57
71
|
"typescript": "^5.7.0",
|
|
72
|
+
"typescript-eslint": "^8.56.1",
|
|
58
73
|
"vitest": "^3.0.0"
|
|
59
74
|
}
|
|
60
75
|
}
|