@timmeck/trading-brain 1.0.0 → 1.2.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/Dockerfile +21 -0
- package/README.md +32 -0
- package/dashboard.html +486 -0
- package/dist/api/server.d.ts +3 -16
- package/dist/api/server.js +4 -123
- package/dist/api/server.js.map +1 -1
- package/dist/cli/colors.d.ts +10 -26
- package/dist/cli/colors.js +3 -62
- package/dist/cli/colors.js.map +1 -1
- package/dist/cli/commands/dashboard.d.ts +2 -0
- package/dist/cli/commands/dashboard.js +174 -0
- package/dist/cli/commands/dashboard.js.map +1 -0
- package/dist/cli/commands/insights.js +0 -1
- package/dist/cli/commands/insights.js.map +1 -1
- package/dist/cli/commands/network.js +0 -2
- package/dist/cli/commands/network.js.map +1 -1
- package/dist/cli/commands/peers.d.ts +2 -0
- package/dist/cli/commands/peers.js +38 -0
- package/dist/cli/commands/peers.js.map +1 -0
- package/dist/cli/commands/query.js +0 -1
- package/dist/cli/commands/query.js.map +1 -1
- package/dist/cli/commands/rules.js +0 -1
- package/dist/cli/commands/rules.js.map +1 -1
- package/dist/cli/commands/status.js +0 -1
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/config.js +2 -29
- package/dist/config.js.map +1 -1
- package/dist/dashboard/renderer.d.ts +17 -0
- package/dist/dashboard/renderer.js +130 -0
- package/dist/dashboard/renderer.js.map +1 -0
- package/dist/dashboard/server.d.ts +15 -0
- package/dist/dashboard/server.js +116 -0
- package/dist/dashboard/server.js.map +1 -0
- package/dist/db/connection.d.ts +1 -2
- package/dist/db/connection.js +1 -18
- package/dist/db/connection.js.map +1 -1
- package/dist/hooks/post-tool-use.d.ts +2 -0
- package/dist/hooks/post-tool-use.js +108 -0
- package/dist/hooks/post-tool-use.js.map +1 -0
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/ipc/__tests__/protocol.test.d.ts +1 -0
- package/dist/ipc/__tests__/protocol.test.js +89 -0
- package/dist/ipc/__tests__/protocol.test.js.map +1 -0
- package/dist/ipc/client.d.ts +1 -16
- package/dist/ipc/client.js +1 -94
- package/dist/ipc/client.js.map +1 -1
- package/dist/ipc/protocol.d.ts +1 -8
- package/dist/ipc/protocol.js +1 -28
- package/dist/ipc/protocol.js.map +1 -1
- package/dist/ipc/router.d.ts +2 -0
- package/dist/ipc/router.js +30 -0
- package/dist/ipc/router.js.map +1 -1
- package/dist/ipc/server.d.ts +1 -18
- package/dist/ipc/server.js +1 -141
- package/dist/ipc/server.js.map +1 -1
- package/dist/learning/learning-engine.d.ts +2 -5
- package/dist/learning/learning-engine.js +3 -14
- package/dist/learning/learning-engine.js.map +1 -1
- package/dist/mcp/http-server.d.ts +1 -7
- package/dist/mcp/http-server.js +6 -111
- package/dist/mcp/http-server.js.map +1 -1
- package/dist/mcp/server.js +5 -60
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tools.js +36 -0
- package/dist/mcp/tools.js.map +1 -1
- package/dist/research/research-engine.d.ts +2 -5
- package/dist/research/research-engine.js +3 -18
- package/dist/research/research-engine.js.map +1 -1
- package/dist/signals/__tests__/fingerprint.test.d.ts +1 -0
- package/dist/signals/__tests__/fingerprint.test.js +164 -0
- package/dist/signals/__tests__/fingerprint.test.js.map +1 -0
- package/dist/signals/__tests__/wilson-score.test.d.ts +1 -0
- package/dist/signals/__tests__/wilson-score.test.js +65 -0
- package/dist/signals/__tests__/wilson-score.test.js.map +1 -0
- package/dist/signals/wilson-score.d.ts +1 -10
- package/dist/signals/wilson-score.js +2 -18
- package/dist/signals/wilson-score.js.map +1 -1
- package/dist/synapses/decay.d.ts +1 -0
- package/dist/synapses/decay.js +2 -0
- package/dist/synapses/decay.js.map +1 -1
- package/dist/trading-core.d.ts +2 -0
- package/dist/trading-core.js +15 -4
- package/dist/trading-core.js.map +1 -1
- package/dist/types/ipc.types.d.ts +1 -11
- package/dist/utils/__tests__/hash.test.d.ts +1 -0
- package/dist/utils/__tests__/hash.test.js +23 -0
- package/dist/utils/__tests__/hash.test.js.map +1 -0
- package/dist/utils/__tests__/paths.test.d.ts +1 -0
- package/dist/utils/__tests__/paths.test.js +60 -0
- package/dist/utils/__tests__/paths.test.js.map +1 -0
- package/dist/utils/events.d.ts +4 -8
- package/dist/utils/events.js +2 -14
- package/dist/utils/events.js.map +1 -1
- package/dist/utils/hash.d.ts +1 -1
- package/dist/utils/hash.js +1 -4
- package/dist/utils/hash.js.map +1 -1
- package/dist/utils/logger.d.ts +3 -2
- package/dist/utils/logger.js +8 -35
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/paths.d.ts +2 -1
- package/dist/utils/paths.js +4 -13
- package/dist/utils/paths.js.map +1 -1
- package/eslint.config.js +14 -0
- package/package.json +9 -2
- package/src/api/server.ts +0 -160
- package/src/cli/colors.ts +0 -80
- package/src/cli/commands/config.ts +0 -76
- package/src/cli/commands/doctor.ts +0 -62
- package/src/cli/commands/export.ts +0 -24
- package/src/cli/commands/import.ts +0 -44
- package/src/cli/commands/insights.ts +0 -30
- package/src/cli/commands/network.ts +0 -43
- package/src/cli/commands/query.ts +0 -28
- package/src/cli/commands/rules.ts +0 -27
- package/src/cli/commands/start.ts +0 -93
- package/src/cli/commands/status.ts +0 -64
- package/src/cli/commands/stop.ts +0 -33
- package/src/cli/ipc-helper.ts +0 -22
- package/src/config.ts +0 -103
- package/src/db/connection.ts +0 -22
- package/src/db/migrations/001_core.ts +0 -43
- package/src/db/migrations/002_synapses.ts +0 -44
- package/src/db/migrations/003_learning.ts +0 -49
- package/src/db/migrations/004_research.ts +0 -30
- package/src/db/migrations/index.ts +0 -60
- package/src/db/repositories/calibration.repository.ts +0 -86
- package/src/db/repositories/chain.repository.ts +0 -70
- package/src/db/repositories/graph.repository.ts +0 -103
- package/src/db/repositories/insight.repository.ts +0 -80
- package/src/db/repositories/rule.repository.ts +0 -67
- package/src/db/repositories/signal.repository.ts +0 -48
- package/src/db/repositories/synapse.repository.ts +0 -71
- package/src/db/repositories/trade.repository.ts +0 -97
- package/src/graph/weighted-graph.ts +0 -194
- package/src/index.ts +0 -55
- package/src/ipc/client.ts +0 -112
- package/src/ipc/protocol.ts +0 -35
- package/src/ipc/router.ts +0 -113
- package/src/ipc/server.ts +0 -150
- package/src/learning/calibrator.ts +0 -57
- package/src/learning/chain-detector.ts +0 -43
- package/src/learning/learning-engine.ts +0 -94
- package/src/learning/pattern-extractor.ts +0 -53
- package/src/mcp/http-server.ts +0 -118
- package/src/mcp/server.ts +0 -72
- package/src/mcp/tools.ts +0 -256
- package/src/research/research-engine.ts +0 -223
- package/src/services/analytics.service.ts +0 -68
- package/src/services/insight.service.ts +0 -29
- package/src/services/signal.service.ts +0 -109
- package/src/services/strategy.service.ts +0 -130
- package/src/services/synapse.service.ts +0 -58
- package/src/services/trade.service.ts +0 -139
- package/src/signals/fingerprint.ts +0 -93
- package/src/signals/wilson-score.ts +0 -17
- package/src/synapses/decay.ts +0 -19
- package/src/synapses/hebbian.ts +0 -23
- package/src/synapses/synapse-manager.ts +0 -112
- package/src/trading-core.ts +0 -285
- package/src/types/config.types.ts +0 -60
- package/src/types/ipc.types.ts +0 -8
- package/src/utils/events.ts +0 -42
- package/src/utils/hash.ts +0 -5
- package/src/utils/logger.ts +0 -48
- package/src/utils/paths.ts +0 -19
- package/tsconfig.json +0 -18
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { Buffer } from 'node:buffer';
|
|
3
|
+
import { encodeMessage, MessageDecoder } from '../protocol.js';
|
|
4
|
+
const sampleMessage = {
|
|
5
|
+
id: '1',
|
|
6
|
+
type: 'request',
|
|
7
|
+
method: 'ping',
|
|
8
|
+
params: { ts: 123 },
|
|
9
|
+
};
|
|
10
|
+
describe('encodeMessage', () => {
|
|
11
|
+
it('produces a buffer starting with a 4-byte big-endian length prefix', () => {
|
|
12
|
+
const buf = encodeMessage(sampleMessage);
|
|
13
|
+
const payloadLength = buf.readUInt32BE(0);
|
|
14
|
+
expect(buf.length).toBe(4 + payloadLength);
|
|
15
|
+
});
|
|
16
|
+
it('payload is valid JSON matching the original message', () => {
|
|
17
|
+
const buf = encodeMessage(sampleMessage);
|
|
18
|
+
const payloadLength = buf.readUInt32BE(0);
|
|
19
|
+
const json = buf.subarray(4, 4 + payloadLength).toString('utf8');
|
|
20
|
+
expect(JSON.parse(json)).toEqual(sampleMessage);
|
|
21
|
+
});
|
|
22
|
+
it('encodes a minimal notification message', () => {
|
|
23
|
+
const msg = { id: '2', type: 'notification' };
|
|
24
|
+
const buf = encodeMessage(msg);
|
|
25
|
+
const payloadLength = buf.readUInt32BE(0);
|
|
26
|
+
const decoded = JSON.parse(buf.subarray(4, 4 + payloadLength).toString('utf8'));
|
|
27
|
+
expect(decoded).toEqual(msg);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
describe('MessageDecoder', () => {
|
|
31
|
+
it('decodes a single complete frame', () => {
|
|
32
|
+
const decoder = new MessageDecoder();
|
|
33
|
+
const frame = encodeMessage(sampleMessage);
|
|
34
|
+
const messages = decoder.feed(frame);
|
|
35
|
+
expect(messages).toHaveLength(1);
|
|
36
|
+
expect(messages[0]).toEqual(sampleMessage);
|
|
37
|
+
});
|
|
38
|
+
it('decodes multiple frames fed at once', () => {
|
|
39
|
+
const decoder = new MessageDecoder();
|
|
40
|
+
const msg1 = { id: '1', type: 'request', method: 'a' };
|
|
41
|
+
const msg2 = { id: '2', type: 'response', result: 42 };
|
|
42
|
+
const combined = Buffer.concat([encodeMessage(msg1), encodeMessage(msg2)]);
|
|
43
|
+
const messages = decoder.feed(combined);
|
|
44
|
+
expect(messages).toHaveLength(2);
|
|
45
|
+
expect(messages[0]).toEqual(msg1);
|
|
46
|
+
expect(messages[1]).toEqual(msg2);
|
|
47
|
+
});
|
|
48
|
+
it('handles partial frames across multiple feed() calls', () => {
|
|
49
|
+
const decoder = new MessageDecoder();
|
|
50
|
+
const frame = encodeMessage(sampleMessage);
|
|
51
|
+
// Split the frame in the middle
|
|
52
|
+
const splitPoint = Math.floor(frame.length / 2);
|
|
53
|
+
const part1 = frame.subarray(0, splitPoint);
|
|
54
|
+
const part2 = frame.subarray(splitPoint);
|
|
55
|
+
const firstResult = decoder.feed(part1);
|
|
56
|
+
expect(firstResult).toHaveLength(0);
|
|
57
|
+
const secondResult = decoder.feed(part2);
|
|
58
|
+
expect(secondResult).toHaveLength(1);
|
|
59
|
+
expect(secondResult[0]).toEqual(sampleMessage);
|
|
60
|
+
});
|
|
61
|
+
it('handles byte-by-byte feeding', () => {
|
|
62
|
+
const decoder = new MessageDecoder();
|
|
63
|
+
const frame = encodeMessage(sampleMessage);
|
|
64
|
+
const messages = [];
|
|
65
|
+
for (let i = 0; i < frame.length; i++) {
|
|
66
|
+
const result = decoder.feed(Buffer.from([frame[i]]));
|
|
67
|
+
messages.push(...result);
|
|
68
|
+
}
|
|
69
|
+
expect(messages).toHaveLength(1);
|
|
70
|
+
expect(messages[0]).toEqual(sampleMessage);
|
|
71
|
+
});
|
|
72
|
+
it('reset() clears internal buffer', () => {
|
|
73
|
+
const decoder = new MessageDecoder();
|
|
74
|
+
const frame = encodeMessage(sampleMessage);
|
|
75
|
+
// Feed a partial frame then reset
|
|
76
|
+
decoder.feed(frame.subarray(0, 3));
|
|
77
|
+
decoder.reset();
|
|
78
|
+
// Feed a complete frame after reset
|
|
79
|
+
const messages = decoder.feed(frame);
|
|
80
|
+
expect(messages).toHaveLength(1);
|
|
81
|
+
expect(messages[0]).toEqual(sampleMessage);
|
|
82
|
+
});
|
|
83
|
+
it('returns empty array when fed an empty buffer', () => {
|
|
84
|
+
const decoder = new MessageDecoder();
|
|
85
|
+
const messages = decoder.feed(Buffer.alloc(0));
|
|
86
|
+
expect(messages).toHaveLength(0);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
//# sourceMappingURL=protocol.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.test.js","sourceRoot":"","sources":["../../../src/ipc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MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/C,MAAM,CAAC,QAAQ,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/ipc/client.d.ts
CHANGED
|
@@ -1,16 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare class IpcClient {
|
|
3
|
-
private pipeName;
|
|
4
|
-
private timeout;
|
|
5
|
-
private socket;
|
|
6
|
-
private decoder;
|
|
7
|
-
private pending;
|
|
8
|
-
private onNotification?;
|
|
9
|
-
constructor(pipeName?: string, timeout?: number);
|
|
10
|
-
connect(): Promise<void>;
|
|
11
|
-
request(method: string, params?: unknown): Promise<unknown>;
|
|
12
|
-
setNotificationHandler(handler: (msg: IpcMessage) => void): void;
|
|
13
|
-
disconnect(): void;
|
|
14
|
-
get connected(): boolean;
|
|
15
|
-
private handleMessage;
|
|
16
|
-
}
|
|
1
|
+
export { IpcClient } from '@timmeck/brain-core';
|
package/dist/ipc/client.js
CHANGED
|
@@ -1,95 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { randomUUID } from 'node:crypto';
|
|
3
|
-
import { encodeMessage, MessageDecoder } from './protocol.js';
|
|
4
|
-
import { getPipeName } from '../utils/paths.js';
|
|
5
|
-
export class IpcClient {
|
|
6
|
-
pipeName;
|
|
7
|
-
timeout;
|
|
8
|
-
socket = null;
|
|
9
|
-
decoder = new MessageDecoder();
|
|
10
|
-
pending = new Map();
|
|
11
|
-
onNotification;
|
|
12
|
-
constructor(pipeName = getPipeName(), timeout = 5000) {
|
|
13
|
-
this.pipeName = pipeName;
|
|
14
|
-
this.timeout = timeout;
|
|
15
|
-
}
|
|
16
|
-
connect() {
|
|
17
|
-
return new Promise((resolve, reject) => {
|
|
18
|
-
this.socket = net.createConnection(this.pipeName, () => {
|
|
19
|
-
resolve();
|
|
20
|
-
});
|
|
21
|
-
this.socket.on('data', (chunk) => {
|
|
22
|
-
const messages = this.decoder.feed(chunk);
|
|
23
|
-
for (const msg of messages) {
|
|
24
|
-
this.handleMessage(msg);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
this.socket.on('error', (err) => {
|
|
28
|
-
reject(err);
|
|
29
|
-
for (const [id, req] of this.pending) {
|
|
30
|
-
clearTimeout(req.timer);
|
|
31
|
-
req.reject(new Error(`Connection error: ${err.message}`));
|
|
32
|
-
this.pending.delete(id);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
this.socket.on('close', () => {
|
|
36
|
-
for (const [id, req] of this.pending) {
|
|
37
|
-
clearTimeout(req.timer);
|
|
38
|
-
req.reject(new Error('Connection closed'));
|
|
39
|
-
this.pending.delete(id);
|
|
40
|
-
}
|
|
41
|
-
this.socket = null;
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
request(method, params) {
|
|
46
|
-
return new Promise((resolve, reject) => {
|
|
47
|
-
if (!this.socket || this.socket.destroyed) {
|
|
48
|
-
return reject(new Error('Not connected'));
|
|
49
|
-
}
|
|
50
|
-
const id = randomUUID();
|
|
51
|
-
const timer = setTimeout(() => {
|
|
52
|
-
this.pending.delete(id);
|
|
53
|
-
reject(new Error(`Request timeout: ${method} (${this.timeout}ms)`));
|
|
54
|
-
}, this.timeout);
|
|
55
|
-
this.pending.set(id, { resolve, reject, timer });
|
|
56
|
-
const msg = { id, type: 'request', method, params };
|
|
57
|
-
this.socket.write(encodeMessage(msg));
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
setNotificationHandler(handler) {
|
|
61
|
-
this.onNotification = handler;
|
|
62
|
-
}
|
|
63
|
-
disconnect() {
|
|
64
|
-
for (const [id, req] of this.pending) {
|
|
65
|
-
clearTimeout(req.timer);
|
|
66
|
-
req.reject(new Error('Client disconnecting'));
|
|
67
|
-
this.pending.delete(id);
|
|
68
|
-
}
|
|
69
|
-
this.socket?.destroy();
|
|
70
|
-
this.socket = null;
|
|
71
|
-
this.decoder.reset();
|
|
72
|
-
}
|
|
73
|
-
get connected() {
|
|
74
|
-
return this.socket !== null && !this.socket.destroyed;
|
|
75
|
-
}
|
|
76
|
-
handleMessage(msg) {
|
|
77
|
-
if (msg.type === 'response') {
|
|
78
|
-
const req = this.pending.get(msg.id);
|
|
79
|
-
if (!req)
|
|
80
|
-
return;
|
|
81
|
-
clearTimeout(req.timer);
|
|
82
|
-
this.pending.delete(msg.id);
|
|
83
|
-
if (msg.error) {
|
|
84
|
-
req.reject(new Error(msg.error.message));
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
req.resolve(msg.result);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
else if (msg.type === 'notification') {
|
|
91
|
-
this.onNotification?.(msg);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
1
|
+
export { IpcClient } from '@timmeck/brain-core';
|
|
95
2
|
//# sourceMappingURL=client.js.map
|
package/dist/ipc/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/ipc/client.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/ipc/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/ipc/protocol.d.ts
CHANGED
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { IpcMessage } from '../types/ipc.types.js';
|
|
3
|
-
export declare function encodeMessage(msg: IpcMessage): Buffer;
|
|
4
|
-
export declare class MessageDecoder {
|
|
5
|
-
private buffer;
|
|
6
|
-
feed(chunk: Buffer): IpcMessage[];
|
|
7
|
-
reset(): void;
|
|
8
|
-
}
|
|
1
|
+
export { encodeMessage, MessageDecoder } from '@timmeck/brain-core';
|
package/dist/ipc/protocol.js
CHANGED
|
@@ -1,29 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export function encodeMessage(msg) {
|
|
3
|
-
const json = JSON.stringify(msg);
|
|
4
|
-
const payload = Buffer.from(json, 'utf8');
|
|
5
|
-
const frame = Buffer.alloc(4 + payload.length);
|
|
6
|
-
frame.writeUInt32BE(payload.length, 0);
|
|
7
|
-
payload.copy(frame, 4);
|
|
8
|
-
return frame;
|
|
9
|
-
}
|
|
10
|
-
export class MessageDecoder {
|
|
11
|
-
buffer = Buffer.alloc(0);
|
|
12
|
-
feed(chunk) {
|
|
13
|
-
this.buffer = Buffer.concat([this.buffer, chunk]);
|
|
14
|
-
const messages = [];
|
|
15
|
-
while (this.buffer.length >= 4) {
|
|
16
|
-
const length = this.buffer.readUInt32BE(0);
|
|
17
|
-
if (this.buffer.length < 4 + length)
|
|
18
|
-
break;
|
|
19
|
-
const json = this.buffer.subarray(4, 4 + length).toString('utf8');
|
|
20
|
-
this.buffer = this.buffer.subarray(4 + length);
|
|
21
|
-
messages.push(JSON.parse(json));
|
|
22
|
-
}
|
|
23
|
-
return messages;
|
|
24
|
-
}
|
|
25
|
-
reset() {
|
|
26
|
-
this.buffer = Buffer.alloc(0);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
1
|
+
export { encodeMessage, MessageDecoder } from '@timmeck/brain-core';
|
|
29
2
|
//# sourceMappingURL=protocol.js.map
|
package/dist/ipc/protocol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/ipc/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/ipc/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/ipc/router.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type { ResearchEngine } from '../research/research-engine.js';
|
|
|
9
9
|
import type { RuleRepository } from '../db/repositories/rule.repository.js';
|
|
10
10
|
import type { ChainRepository } from '../db/repositories/chain.repository.js';
|
|
11
11
|
import type { CalibrationRepository } from '../db/repositories/calibration.repository.js';
|
|
12
|
+
import type { CrossBrainClient } from '@timmeck/brain-core';
|
|
12
13
|
export interface Services {
|
|
13
14
|
trade: TradeService;
|
|
14
15
|
signal: SignalService;
|
|
@@ -21,6 +22,7 @@ export interface Services {
|
|
|
21
22
|
calRepo: CalibrationRepository;
|
|
22
23
|
learning?: LearningEngine;
|
|
23
24
|
research?: ResearchEngine;
|
|
25
|
+
crossBrain?: CrossBrainClient;
|
|
24
26
|
}
|
|
25
27
|
export declare class IpcRouter {
|
|
26
28
|
private services;
|
package/dist/ipc/router.js
CHANGED
|
@@ -64,6 +64,36 @@ export class IpcRouter {
|
|
|
64
64
|
// This will be wired in TradingCore
|
|
65
65
|
return { success: true, message: 'Reset not available via IPC — use CLI' };
|
|
66
66
|
}],
|
|
67
|
+
// ─── Cross-Brain Notifications ──────────────────────────
|
|
68
|
+
['cross-brain.notify', (params) => {
|
|
69
|
+
const { source, event, data, timestamp } = p(params);
|
|
70
|
+
logger.info(`Cross-brain notification from ${source}: ${event}`);
|
|
71
|
+
return { received: true, source, event, timestamp };
|
|
72
|
+
}],
|
|
73
|
+
// ─── Ecosystem ────────────────────────────────────────
|
|
74
|
+
['ecosystem.status', async () => {
|
|
75
|
+
if (!s.crossBrain)
|
|
76
|
+
return { peers: [] };
|
|
77
|
+
const peers = await s.crossBrain.broadcast('status');
|
|
78
|
+
return { self: 'trading-brain', peers };
|
|
79
|
+
}],
|
|
80
|
+
['ecosystem.queryPeer', async (params) => {
|
|
81
|
+
if (!s.crossBrain)
|
|
82
|
+
throw new Error('Cross-brain client not available');
|
|
83
|
+
const { peer, method, args } = p(params);
|
|
84
|
+
const result = await s.crossBrain.query(peer, method, args);
|
|
85
|
+
if (result === null)
|
|
86
|
+
throw new Error(`Peer '${peer}' not available`);
|
|
87
|
+
return result;
|
|
88
|
+
}],
|
|
89
|
+
// ─── Status (cross-brain) ─────────────────────────────
|
|
90
|
+
['status', () => ({
|
|
91
|
+
name: 'trading-brain',
|
|
92
|
+
version: '1.1.0',
|
|
93
|
+
uptime: Math.floor(process.uptime()),
|
|
94
|
+
pid: process.pid,
|
|
95
|
+
methods: this.listMethods().length,
|
|
96
|
+
})],
|
|
67
97
|
]);
|
|
68
98
|
}
|
|
69
99
|
}
|
package/dist/ipc/router.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/ipc/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/ipc/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAc/C,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;AAmB3B,MAAM,OAAO,SAAS;IAGA;IAFZ,OAAO,CAA6B;IAE5C,YAAoB,QAAkB;QAAlB,aAAQ,GAAR,QAAQ,CAAU;QACpC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;IACvC,CAAC;IAED,MAAM,CAAC,MAAc,EAAE,MAAe;QACpC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACzC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,mBAAmB,MAAM,EAAE,CAAC,CAAC;QAC/C,CAAC;QAED,MAAM,CAAC,KAAK,CAAC,QAAQ,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;QAC3C,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QAC/B,MAAM,CAAC,KAAK,CAAC,QAAQ,MAAM,SAAS,CAA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E,OAAO,MAAM,CAAC;gBAChB,CAAC,CAAC;YAEF,yDAAyD;YACzD,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC;oBAChB,IAAI,EAAE,eAAe;oBACrB,OAAO,EAAE,OAAO;oBAChB,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;oBACpC,GAAG,EAAE,OAAO,CAAC,GAAG;oBAChB,OAAO,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,MAAM;iBACnC,CAAC,CAAC;SACJ,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/dist/ipc/server.d.ts
CHANGED
|
@@ -1,18 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { IpcRouter } from './router.js';
|
|
3
|
-
export declare class IpcServer {
|
|
4
|
-
private router;
|
|
5
|
-
private pipeName;
|
|
6
|
-
private server;
|
|
7
|
-
private clients;
|
|
8
|
-
private logger;
|
|
9
|
-
constructor(router: IpcRouter, pipeName: string);
|
|
10
|
-
start(): void;
|
|
11
|
-
private createServer;
|
|
12
|
-
private listen;
|
|
13
|
-
private recoverStalePipe;
|
|
14
|
-
private handleMessage;
|
|
15
|
-
notify(clientId: string | null, notification: Omit<IpcMessage, 'id' | 'type'>): void;
|
|
16
|
-
getClientCount(): number;
|
|
17
|
-
stop(): void;
|
|
18
|
-
}
|
|
1
|
+
export { IpcServer } from '@timmeck/brain-core';
|
package/dist/ipc/server.js
CHANGED
|
@@ -1,142 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import { randomUUID } from 'node:crypto';
|
|
4
|
-
import { getLogger } from '../utils/logger.js';
|
|
5
|
-
import { encodeMessage, MessageDecoder } from './protocol.js';
|
|
6
|
-
export class IpcServer {
|
|
7
|
-
router;
|
|
8
|
-
pipeName;
|
|
9
|
-
server = null;
|
|
10
|
-
clients = new Map();
|
|
11
|
-
logger = getLogger();
|
|
12
|
-
constructor(router, pipeName) {
|
|
13
|
-
this.router = router;
|
|
14
|
-
this.pipeName = pipeName;
|
|
15
|
-
}
|
|
16
|
-
start() {
|
|
17
|
-
this.createServer();
|
|
18
|
-
this.listen();
|
|
19
|
-
}
|
|
20
|
-
createServer() {
|
|
21
|
-
this.server = net.createServer((socket) => {
|
|
22
|
-
const clientId = randomUUID();
|
|
23
|
-
this.clients.set(clientId, socket);
|
|
24
|
-
const decoder = new MessageDecoder();
|
|
25
|
-
this.logger.info(`IPC client connected: ${clientId}`);
|
|
26
|
-
socket.on('data', (chunk) => {
|
|
27
|
-
const messages = decoder.feed(chunk);
|
|
28
|
-
for (const msg of messages) {
|
|
29
|
-
this.handleMessage(clientId, msg, socket);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
socket.on('close', () => {
|
|
33
|
-
this.logger.info(`IPC client disconnected: ${clientId}`);
|
|
34
|
-
this.clients.delete(clientId);
|
|
35
|
-
});
|
|
36
|
-
socket.on('error', (err) => {
|
|
37
|
-
this.logger.error(`IPC client ${clientId} error:`, err);
|
|
38
|
-
this.clients.delete(clientId);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
listen(retried = false) {
|
|
43
|
-
if (!this.server)
|
|
44
|
-
return;
|
|
45
|
-
this.server.on('error', (err) => {
|
|
46
|
-
if (err.code === 'EADDRINUSE' && !retried) {
|
|
47
|
-
this.logger.warn(`IPC pipe in use, attempting to recover stale pipe: ${this.pipeName}`);
|
|
48
|
-
this.recoverStalePipe();
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
this.logger.error('IPC server error:', err);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
this.server.listen(this.pipeName, () => {
|
|
55
|
-
this.logger.info(`IPC server listening on ${this.pipeName}`);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
recoverStalePipe() {
|
|
59
|
-
const probe = net.createConnection(this.pipeName);
|
|
60
|
-
probe.on('connect', () => {
|
|
61
|
-
probe.destroy();
|
|
62
|
-
this.logger.error('IPC pipe is held by another running daemon. Stop it first with: trading stop');
|
|
63
|
-
});
|
|
64
|
-
probe.on('error', () => {
|
|
65
|
-
probe.destroy();
|
|
66
|
-
this.logger.info('Stale IPC pipe detected, reclaiming...');
|
|
67
|
-
if (process.platform !== 'win32') {
|
|
68
|
-
try {
|
|
69
|
-
fs.unlinkSync(this.pipeName);
|
|
70
|
-
}
|
|
71
|
-
catch { /* ignore */ }
|
|
72
|
-
}
|
|
73
|
-
this.createServer();
|
|
74
|
-
this.server.on('error', (err) => {
|
|
75
|
-
this.logger.error('IPC server error after recovery:', err);
|
|
76
|
-
});
|
|
77
|
-
this.server.listen(this.pipeName, () => {
|
|
78
|
-
this.logger.info(`IPC server recovered and listening on ${this.pipeName}`);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
probe.setTimeout(2000, () => {
|
|
82
|
-
probe.destroy();
|
|
83
|
-
this.logger.warn('IPC pipe probe timed out, treating as stale');
|
|
84
|
-
if (process.platform !== 'win32') {
|
|
85
|
-
try {
|
|
86
|
-
fs.unlinkSync(this.pipeName);
|
|
87
|
-
}
|
|
88
|
-
catch { /* ignore */ }
|
|
89
|
-
}
|
|
90
|
-
this.createServer();
|
|
91
|
-
this.server.on('error', (err) => {
|
|
92
|
-
this.logger.error('IPC server error after timeout recovery:', err);
|
|
93
|
-
});
|
|
94
|
-
this.server.listen(this.pipeName, () => {
|
|
95
|
-
this.logger.info(`IPC server recovered (timeout) and listening on ${this.pipeName}`);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
handleMessage(clientId, msg, socket) {
|
|
100
|
-
if (msg.type !== 'request' || !msg.method)
|
|
101
|
-
return;
|
|
102
|
-
try {
|
|
103
|
-
const result = this.router.handle(msg.method, msg.params);
|
|
104
|
-
const response = { id: msg.id, type: 'response', result };
|
|
105
|
-
socket.write(encodeMessage(response));
|
|
106
|
-
}
|
|
107
|
-
catch (err) {
|
|
108
|
-
const response = {
|
|
109
|
-
id: msg.id, type: 'response',
|
|
110
|
-
error: { code: -1, message: err instanceof Error ? err.message : String(err) },
|
|
111
|
-
};
|
|
112
|
-
socket.write(encodeMessage(response));
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
notify(clientId, notification) {
|
|
116
|
-
const msg = { id: randomUUID(), type: 'notification', ...notification };
|
|
117
|
-
const encoded = encodeMessage(msg);
|
|
118
|
-
if (clientId) {
|
|
119
|
-
const socket = this.clients.get(clientId);
|
|
120
|
-
if (socket && !socket.destroyed)
|
|
121
|
-
socket.write(encoded);
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
for (const socket of this.clients.values()) {
|
|
125
|
-
if (!socket.destroyed)
|
|
126
|
-
socket.write(encoded);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
getClientCount() {
|
|
131
|
-
return this.clients.size;
|
|
132
|
-
}
|
|
133
|
-
stop() {
|
|
134
|
-
for (const socket of this.clients.values())
|
|
135
|
-
socket.destroy();
|
|
136
|
-
this.clients.clear();
|
|
137
|
-
this.server?.close();
|
|
138
|
-
this.server = null;
|
|
139
|
-
this.logger.info('IPC server stopped');
|
|
140
|
-
}
|
|
141
|
-
}
|
|
1
|
+
export { IpcServer } from '@timmeck/brain-core';
|
|
142
2
|
//# sourceMappingURL=server.js.map
|
package/dist/ipc/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/ipc/server.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/ipc/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -5,7 +5,8 @@ import type { CalibrationRepository } from '../db/repositories/calibration.repos
|
|
|
5
5
|
import type { SynapseManager } from '../synapses/synapse-manager.js';
|
|
6
6
|
import type { WeightedGraph } from '../graph/weighted-graph.js';
|
|
7
7
|
import type { CalibrationConfig, LearningConfig } from '../types/config.types.js';
|
|
8
|
-
|
|
8
|
+
import { BaseLearningEngine } from '@timmeck/brain-core';
|
|
9
|
+
export declare class LearningEngine extends BaseLearningEngine {
|
|
9
10
|
private learningConfig;
|
|
10
11
|
private cal;
|
|
11
12
|
private tradeRepo;
|
|
@@ -14,13 +15,9 @@ export declare class LearningEngine {
|
|
|
14
15
|
private calRepo;
|
|
15
16
|
private synapseManager;
|
|
16
17
|
private graph;
|
|
17
|
-
private timer;
|
|
18
18
|
private lastPatternExtraction;
|
|
19
19
|
private lastDecay;
|
|
20
|
-
private logger;
|
|
21
20
|
constructor(learningConfig: LearningConfig, cal: CalibrationConfig, tradeRepo: TradeRepository, ruleRepo: RuleRepository, chainRepo: ChainRepository, calRepo: CalibrationRepository, synapseManager: SynapseManager, graph: WeightedGraph);
|
|
22
|
-
start(): void;
|
|
23
|
-
stop(): void;
|
|
24
21
|
getCalibration(): CalibrationConfig;
|
|
25
22
|
runCycle(): void;
|
|
26
23
|
/** Manual trigger for a full learning cycle */
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { extractPatterns } from './pattern-extractor.js';
|
|
2
2
|
import { calibrate } from './calibrator.js';
|
|
3
|
-
import { getLogger } from '../utils/logger.js';
|
|
4
3
|
import { getEventBus } from '../utils/events.js';
|
|
5
|
-
|
|
4
|
+
import { BaseLearningEngine } from '@timmeck/brain-core';
|
|
5
|
+
export class LearningEngine extends BaseLearningEngine {
|
|
6
6
|
learningConfig;
|
|
7
7
|
cal;
|
|
8
8
|
tradeRepo;
|
|
@@ -11,11 +11,10 @@ export class LearningEngine {
|
|
|
11
11
|
calRepo;
|
|
12
12
|
synapseManager;
|
|
13
13
|
graph;
|
|
14
|
-
timer = null;
|
|
15
14
|
lastPatternExtraction = 0;
|
|
16
15
|
lastDecay = 0;
|
|
17
|
-
logger = getLogger();
|
|
18
16
|
constructor(learningConfig, cal, tradeRepo, ruleRepo, chainRepo, calRepo, synapseManager, graph) {
|
|
17
|
+
super(learningConfig);
|
|
19
18
|
this.learningConfig = learningConfig;
|
|
20
19
|
this.cal = cal;
|
|
21
20
|
this.tradeRepo = tradeRepo;
|
|
@@ -25,16 +24,6 @@ export class LearningEngine {
|
|
|
25
24
|
this.synapseManager = synapseManager;
|
|
26
25
|
this.graph = graph;
|
|
27
26
|
}
|
|
28
|
-
start() {
|
|
29
|
-
this.timer = setInterval(() => this.runCycle(), this.learningConfig.intervalMs);
|
|
30
|
-
this.logger.info(`Learning engine started (interval: ${this.learningConfig.intervalMs}ms)`);
|
|
31
|
-
}
|
|
32
|
-
stop() {
|
|
33
|
-
if (this.timer) {
|
|
34
|
-
clearInterval(this.timer);
|
|
35
|
-
this.timer = null;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
27
|
getCalibration() {
|
|
39
28
|
return { ...this.cal };
|
|
40
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"learning-engine.js","sourceRoot":"","sources":["../../src/learning/learning-engine.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"learning-engine.js","sourceRoot":"","sources":["../../src/learning/learning-engine.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,MAAM,OAAO,cAAe,SAAQ,kBAAkB;IAK1C;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAXF,qBAAqB,GAAG,CAAC,CAAC;IAC1B,SAAS,GAAG,CAAC,C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AG,CAAC,IAAI,CAAC,eAAe,EAAE,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QAChG,CAAC;QAED,mBAAmB;QACnB,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IAC5D,CAAC;IAED,+CAA+C;IAC/C,SAAS;QACP,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChB,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;QACrC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC;IACrE,CAAC;CACF"}
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import type { IpcRouter } from '../ipc/router.js';
|
|
2
2
|
export declare class McpHttpServer {
|
|
3
|
-
private
|
|
4
|
-
private router;
|
|
5
|
-
private server;
|
|
6
|
-
private transports;
|
|
7
|
-
private logger;
|
|
3
|
+
private inner;
|
|
8
4
|
constructor(port: number, router: IpcRouter);
|
|
9
5
|
start(): void;
|
|
10
6
|
stop(): void;
|
|
11
7
|
getClientCount(): number;
|
|
12
|
-
private handleSSE;
|
|
13
|
-
private handleMessage;
|
|
14
8
|
}
|