@timmeck/marketing-brain 0.2.0 → 0.3.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.
Files changed (130) hide show
  1. package/README.md +28 -13
  2. package/dist/cli/colors.d.ts +11 -24
  3. package/dist/cli/colors.js +3 -46
  4. package/dist/cli/colors.js.map +1 -1
  5. package/dist/cli/commands/dashboard.js +1 -1
  6. package/dist/cli/commands/peers.d.ts +2 -0
  7. package/dist/cli/commands/peers.js +38 -0
  8. package/dist/cli/commands/peers.js.map +1 -0
  9. package/dist/config.js +3 -3
  10. package/dist/db/connection.d.ts +1 -2
  11. package/dist/db/connection.js +1 -18
  12. package/dist/db/connection.js.map +1 -1
  13. package/dist/hooks/post-tool-use.d.ts +2 -0
  14. package/dist/hooks/post-tool-use.js +182 -0
  15. package/dist/hooks/post-tool-use.js.map +1 -0
  16. package/dist/index.js +2 -0
  17. package/dist/index.js.map +1 -1
  18. package/dist/ipc/__tests__/protocol.test.d.ts +1 -0
  19. package/dist/ipc/__tests__/protocol.test.js +129 -0
  20. package/dist/ipc/__tests__/protocol.test.js.map +1 -0
  21. package/dist/ipc/client.d.ts +1 -13
  22. package/dist/ipc/client.js +1 -92
  23. package/dist/ipc/client.js.map +1 -1
  24. package/dist/ipc/protocol.d.ts +1 -8
  25. package/dist/ipc/protocol.js +1 -28
  26. package/dist/ipc/protocol.js.map +1 -1
  27. package/dist/ipc/router.js +8 -0
  28. package/dist/ipc/router.js.map +1 -1
  29. package/dist/ipc/server.d.ts +1 -14
  30. package/dist/ipc/server.js +1 -129
  31. package/dist/ipc/server.js.map +1 -1
  32. package/dist/marketing-core.d.ts +1 -0
  33. package/dist/marketing-core.js +6 -1
  34. package/dist/marketing-core.js.map +1 -1
  35. package/dist/mcp/server.js +5 -60
  36. package/dist/mcp/server.js.map +1 -1
  37. package/dist/types/ipc.types.d.ts +1 -11
  38. package/dist/utils/__tests__/hash.test.d.ts +1 -0
  39. package/dist/utils/__tests__/hash.test.js +30 -0
  40. package/dist/utils/__tests__/hash.test.js.map +1 -0
  41. package/dist/utils/__tests__/paths.test.d.ts +1 -0
  42. package/dist/utils/__tests__/paths.test.js +63 -0
  43. package/dist/utils/__tests__/paths.test.js.map +1 -0
  44. package/dist/utils/events.d.ts +4 -8
  45. package/dist/utils/events.js +2 -14
  46. package/dist/utils/events.js.map +1 -1
  47. package/dist/utils/hash.d.ts +1 -1
  48. package/dist/utils/hash.js +1 -4
  49. package/dist/utils/hash.js.map +1 -1
  50. package/dist/utils/logger.d.ts +3 -2
  51. package/dist/utils/logger.js +8 -35
  52. package/dist/utils/logger.js.map +1 -1
  53. package/dist/utils/paths.d.ts +2 -1
  54. package/dist/utils/paths.js +4 -13
  55. package/dist/utils/paths.js.map +1 -1
  56. package/package.json +2 -1
  57. package/.mcp.json +0 -9
  58. package/src/api/server.ts +0 -86
  59. package/src/cli/colors.ts +0 -59
  60. package/src/cli/commands/campaign.ts +0 -66
  61. package/src/cli/commands/config.ts +0 -168
  62. package/src/cli/commands/dashboard.ts +0 -165
  63. package/src/cli/commands/doctor.ts +0 -110
  64. package/src/cli/commands/export.ts +0 -40
  65. package/src/cli/commands/import.ts +0 -84
  66. package/src/cli/commands/insights.ts +0 -44
  67. package/src/cli/commands/learn.ts +0 -24
  68. package/src/cli/commands/network.ts +0 -71
  69. package/src/cli/commands/post.ts +0 -47
  70. package/src/cli/commands/query.ts +0 -108
  71. package/src/cli/commands/rules.ts +0 -27
  72. package/src/cli/commands/start.ts +0 -100
  73. package/src/cli/commands/status.ts +0 -73
  74. package/src/cli/commands/stop.ts +0 -33
  75. package/src/cli/commands/suggest.ts +0 -64
  76. package/src/cli/ipc-helper.ts +0 -22
  77. package/src/cli/update-check.ts +0 -63
  78. package/src/config.ts +0 -110
  79. package/src/dashboard/renderer.ts +0 -136
  80. package/src/dashboard/server.ts +0 -140
  81. package/src/db/connection.ts +0 -22
  82. package/src/db/migrations/001_core_schema.ts +0 -63
  83. package/src/db/migrations/002_learning_schema.ts +0 -46
  84. package/src/db/migrations/003_synapse_schema.ts +0 -27
  85. package/src/db/migrations/004_insights_schema.ts +0 -38
  86. package/src/db/migrations/005_fts_indexes.ts +0 -77
  87. package/src/db/migrations/index.ts +0 -62
  88. package/src/db/repositories/audience.repository.ts +0 -53
  89. package/src/db/repositories/campaign.repository.ts +0 -72
  90. package/src/db/repositories/engagement.repository.ts +0 -108
  91. package/src/db/repositories/insight.repository.ts +0 -100
  92. package/src/db/repositories/post.repository.ts +0 -123
  93. package/src/db/repositories/rule.repository.ts +0 -87
  94. package/src/db/repositories/strategy.repository.ts +0 -82
  95. package/src/db/repositories/synapse.repository.ts +0 -148
  96. package/src/db/repositories/template.repository.ts +0 -76
  97. package/src/index.ts +0 -69
  98. package/src/ipc/client.ts +0 -110
  99. package/src/ipc/protocol.ts +0 -35
  100. package/src/ipc/router.ts +0 -126
  101. package/src/ipc/server.ts +0 -140
  102. package/src/learning/confidence-scorer.ts +0 -36
  103. package/src/learning/learning-engine.ts +0 -254
  104. package/src/marketing-core.ts +0 -285
  105. package/src/mcp/server.ts +0 -72
  106. package/src/mcp/tools.ts +0 -216
  107. package/src/research/research-engine.ts +0 -226
  108. package/src/services/analytics.service.ts +0 -73
  109. package/src/services/audience.service.ts +0 -40
  110. package/src/services/campaign.service.ts +0 -80
  111. package/src/services/insight.service.ts +0 -54
  112. package/src/services/post.service.ts +0 -116
  113. package/src/services/rule.service.ts +0 -90
  114. package/src/services/strategy.service.ts +0 -53
  115. package/src/services/synapse.service.ts +0 -32
  116. package/src/services/template.service.ts +0 -50
  117. package/src/synapses/activation.ts +0 -80
  118. package/src/synapses/decay.ts +0 -38
  119. package/src/synapses/hebbian.ts +0 -68
  120. package/src/synapses/pathfinder.ts +0 -81
  121. package/src/synapses/synapse-manager.ts +0 -115
  122. package/src/types/config.types.ts +0 -79
  123. package/src/types/ipc.types.ts +0 -8
  124. package/src/types/post.types.ts +0 -156
  125. package/src/types/synapse.types.ts +0 -43
  126. package/src/utils/events.ts +0 -44
  127. package/src/utils/hash.ts +0 -5
  128. package/src/utils/logger.ts +0 -48
  129. package/src/utils/paths.ts +0 -19
  130. package/tsconfig.json +0 -18
@@ -1,148 +0,0 @@
1
- import type Database from 'better-sqlite3';
2
- import type { Statement } from 'better-sqlite3';
3
- import type { SynapseRecord } from '../../types/synapse.types.js';
4
-
5
- type SynapseCreate = Omit<SynapseRecord, 'id' | 'activation_count' | 'last_activated_at' | 'created_at' | 'updated_at'>;
6
- type SynapseUpdate = Partial<Omit<SynapseRecord, 'id' | 'created_at'>>;
7
-
8
- export class SynapseRepository {
9
- private stmts: Record<string, Statement>;
10
-
11
- constructor(private db: Database.Database) {
12
- this.stmts = {
13
- create: db.prepare(`
14
- INSERT INTO synapses (source_type, source_id, target_type, target_id, synapse_type, weight, metadata)
15
- VALUES (@source_type, @source_id, @target_type, @target_id, @synapse_type, @weight, @metadata)
16
- `),
17
- getById: db.prepare('SELECT * FROM synapses WHERE id = ?'),
18
- delete: db.prepare('DELETE FROM synapses WHERE id = ?'),
19
- getOutgoing: db.prepare(
20
- 'SELECT * FROM synapses WHERE source_type = ? AND source_id = ? ORDER BY weight DESC'
21
- ),
22
- getIncoming: db.prepare(
23
- 'SELECT * FROM synapses WHERE target_type = ? AND target_id = ? ORDER BY weight DESC'
24
- ),
25
- findConnected: db.prepare(`
26
- SELECT * FROM synapses
27
- WHERE (source_type = ? AND source_id = ?) OR (target_type = ? AND target_id = ?)
28
- ORDER BY weight DESC
29
- `),
30
- findBySourceTarget: db.prepare(`
31
- SELECT * FROM synapses
32
- WHERE source_type = ? AND source_id = ? AND target_type = ? AND target_id = ? AND synapse_type = ?
33
- `),
34
- findInactiveSince: db.prepare(`
35
- SELECT * FROM synapses WHERE last_activated_at < ?
36
- `),
37
- countNodes: db.prepare(`
38
- SELECT COUNT(*) as count FROM (
39
- SELECT source_type, source_id FROM synapses
40
- UNION
41
- SELECT target_type, target_id FROM synapses
42
- )
43
- `),
44
- avgWeight: db.prepare('SELECT AVG(weight) as avg_weight FROM synapses'),
45
- countByType: db.prepare('SELECT synapse_type, COUNT(*) as count FROM synapses GROUP BY synapse_type'),
46
- totalCount: db.prepare('SELECT COUNT(*) as count FROM synapses'),
47
- topByWeight: db.prepare('SELECT * FROM synapses ORDER BY weight DESC LIMIT ?'),
48
- topDiverse: db.prepare(`
49
- SELECT * FROM (
50
- SELECT *, ROW_NUMBER() OVER (PARTITION BY synapse_type ORDER BY weight DESC) as rn
51
- FROM synapses
52
- ) WHERE rn <= ? ORDER BY weight DESC
53
- `),
54
- };
55
- }
56
-
57
- create(data: SynapseCreate): number {
58
- const result = this.stmts.create.run({
59
- source_type: data.source_type,
60
- source_id: data.source_id,
61
- target_type: data.target_type,
62
- target_id: data.target_id,
63
- synapse_type: data.synapse_type,
64
- weight: data.weight,
65
- metadata: data.metadata ?? null,
66
- });
67
- return result.lastInsertRowid as number;
68
- }
69
-
70
- getById(id: number): SynapseRecord | undefined {
71
- return this.stmts.getById.get(id) as SynapseRecord | undefined;
72
- }
73
-
74
- update(id: number, data: SynapseUpdate): boolean {
75
- const fields = Object.keys(data).filter(
76
- (key) => (data as Record<string, unknown>)[key] !== undefined
77
- );
78
- if (fields.length === 0) return false;
79
-
80
- const setClauses = fields.map((field) => `${field} = @${field}`).join(', ');
81
- const stmt = this.db.prepare(
82
- `UPDATE synapses SET ${setClauses}, updated_at = datetime('now') WHERE id = @id`
83
- );
84
- const result = stmt.run({ ...data, id });
85
- return result.changes > 0;
86
- }
87
-
88
- delete(id: number): boolean {
89
- const result = this.stmts.delete.run(id);
90
- return result.changes > 0;
91
- }
92
-
93
- getOutgoing(sourceType: string, sourceId: number): SynapseRecord[] {
94
- return this.stmts.getOutgoing.all(sourceType, sourceId) as SynapseRecord[];
95
- }
96
-
97
- getIncoming(targetType: string, targetId: number): SynapseRecord[] {
98
- return this.stmts.getIncoming.all(targetType, targetId) as SynapseRecord[];
99
- }
100
-
101
- findBySourceTarget(
102
- sourceType: string, sourceId: number,
103
- targetType: string, targetId: number,
104
- synapseType: string,
105
- ): SynapseRecord | undefined {
106
- return this.stmts.findBySourceTarget.get(
107
- sourceType, sourceId, targetType, targetId, synapseType
108
- ) as SynapseRecord | undefined;
109
- }
110
-
111
- findConnected(nodeType: string, nodeId: number): SynapseRecord[] {
112
- return this.stmts.findConnected.all(nodeType, nodeId, nodeType, nodeId) as SynapseRecord[];
113
- }
114
-
115
- findInactiveSince(cutoff: string): SynapseRecord[] {
116
- return this.stmts.findInactiveSince.all(cutoff) as SynapseRecord[];
117
- }
118
-
119
- topByWeight(limit: number): SynapseRecord[] {
120
- return this.stmts.topByWeight.all(limit) as SynapseRecord[];
121
- }
122
-
123
- topDiverse(perType: number): SynapseRecord[] {
124
- return this.stmts.topDiverse.all(perType) as SynapseRecord[];
125
- }
126
-
127
- countNodes(): number {
128
- const row = this.stmts.countNodes.get() as { count: number };
129
- return row.count;
130
- }
131
-
132
- totalCount(): number {
133
- const row = this.stmts.totalCount.get() as { count: number };
134
- return row.count;
135
- }
136
-
137
- avgWeight(): number {
138
- const row = this.stmts.avgWeight.get() as { avg_weight: number | null };
139
- return row.avg_weight ?? 0;
140
- }
141
-
142
- countByType(): Record<string, number> {
143
- const rows = this.stmts.countByType.all() as Array<{ synapse_type: string; count: number }>;
144
- const result: Record<string, number> = {};
145
- for (const row of rows) result[row.synapse_type] = row.count;
146
- return result;
147
- }
148
- }
@@ -1,76 +0,0 @@
1
- import type Database from 'better-sqlite3';
2
- import type { Statement } from 'better-sqlite3';
3
- import type { ContentTemplate, ContentTemplateCreate } from '../../types/post.types.js';
4
-
5
- export class TemplateRepository {
6
- private stmts: Record<string, Statement>;
7
-
8
- constructor(private db: Database.Database) {
9
- this.stmts = {
10
- create: db.prepare(`
11
- INSERT INTO content_templates (name, structure, example, platform)
12
- VALUES (@name, @structure, @example, @platform)
13
- `),
14
- getById: db.prepare('SELECT * FROM content_templates WHERE id = ?'),
15
- listAll: db.prepare('SELECT * FROM content_templates ORDER BY avg_engagement DESC LIMIT ?'),
16
- listByPlatform: db.prepare('SELECT * FROM content_templates WHERE platform = ? ORDER BY avg_engagement DESC LIMIT ?'),
17
- countAll: db.prepare('SELECT COUNT(*) as count FROM content_templates'),
18
- search: db.prepare(`
19
- SELECT t.* FROM content_templates t
20
- JOIN content_templates_fts f ON f.rowid = t.id
21
- WHERE content_templates_fts MATCH ?
22
- ORDER BY rank
23
- LIMIT ?
24
- `),
25
- delete: db.prepare('DELETE FROM content_templates WHERE id = ?'),
26
- };
27
- }
28
-
29
- create(data: ContentTemplateCreate): number {
30
- const result = this.stmts.create.run({
31
- name: data.name,
32
- structure: data.structure,
33
- example: data.example ?? null,
34
- platform: data.platform ?? null,
35
- });
36
- return result.lastInsertRowid as number;
37
- }
38
-
39
- getById(id: number): ContentTemplate | undefined {
40
- return this.stmts.getById.get(id) as ContentTemplate | undefined;
41
- }
42
-
43
- listAll(limit: number = 50): ContentTemplate[] {
44
- return this.stmts.listAll.all(limit) as ContentTemplate[];
45
- }
46
-
47
- listByPlatform(platform: string, limit: number = 20): ContentTemplate[] {
48
- return this.stmts.listByPlatform.all(platform, limit) as ContentTemplate[];
49
- }
50
-
51
- search(query: string, limit: number = 20): ContentTemplate[] {
52
- return this.stmts.search.all(query, limit) as ContentTemplate[];
53
- }
54
-
55
- incrementUseCount(id: number): void {
56
- this.db.prepare(
57
- `UPDATE content_templates SET use_count = use_count + 1 WHERE id = ?`
58
- ).run(id);
59
- }
60
-
61
- updateAvgEngagement(id: number, avgEngagement: number): void {
62
- this.db.prepare(
63
- `UPDATE content_templates SET avg_engagement = ? WHERE id = ?`
64
- ).run(avgEngagement, id);
65
- }
66
-
67
- countAll(): number {
68
- const row = this.stmts.countAll.get() as { count: number };
69
- return row.count;
70
- }
71
-
72
- delete(id: number): boolean {
73
- const result = this.stmts.delete.run(id);
74
- return result.changes > 0;
75
- }
76
- }
package/src/index.ts DELETED
@@ -1,69 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { Command } from 'commander';
4
- import { startCommand } from './cli/commands/start.js';
5
- import { stopCommand } from './cli/commands/stop.js';
6
- import { statusCommand } from './cli/commands/status.js';
7
- import { doctorCommand } from './cli/commands/doctor.js';
8
- import { postCommand } from './cli/commands/post.js';
9
- import { campaignCommand } from './cli/commands/campaign.js';
10
- import { insightsCommand } from './cli/commands/insights.js';
11
- import { rulesCommand } from './cli/commands/rules.js';
12
- import { suggestCommand } from './cli/commands/suggest.js';
13
- import { dashboardCommand } from './cli/commands/dashboard.js';
14
- import { importCommand } from './cli/commands/import.js';
15
- import { exportCommand } from './cli/commands/export.js';
16
- import { learnCommand } from './cli/commands/learn.js';
17
- import { networkCommand } from './cli/commands/network.js';
18
- import { queryCommand } from './cli/commands/query.js';
19
- import { configCommand } from './cli/commands/config.js';
20
- import { checkForUpdate, getCurrentVersion } from './cli/update-check.js';
21
-
22
- const program = new Command();
23
-
24
- program
25
- .name('marketing')
26
- .description('Marketing Brain — Self-Learning Marketing Intelligence System')
27
- .version(getCurrentVersion());
28
-
29
- program.addCommand(startCommand());
30
- program.addCommand(stopCommand());
31
- program.addCommand(statusCommand());
32
- program.addCommand(doctorCommand());
33
- program.addCommand(postCommand());
34
- program.addCommand(campaignCommand());
35
- program.addCommand(insightsCommand());
36
- program.addCommand(rulesCommand());
37
- program.addCommand(suggestCommand());
38
- program.addCommand(dashboardCommand());
39
- program.addCommand(importCommand());
40
- program.addCommand(exportCommand());
41
- program.addCommand(learnCommand());
42
- program.addCommand(networkCommand());
43
- program.addCommand(queryCommand());
44
- program.addCommand(configCommand());
45
-
46
- // Hidden: MCP server (called by Claude Code)
47
- program
48
- .command('mcp-server')
49
- .description('Start MCP server (stdio transport, used by Claude Code)')
50
- .action(async () => {
51
- const { startMcpServer } = await import('./mcp/server.js');
52
- await startMcpServer();
53
- });
54
-
55
- // Hidden: run daemon in foreground
56
- program
57
- .command('daemon')
58
- .description('Run daemon in foreground')
59
- .option('-c, --config <path>', 'Config file path')
60
- .action(async (opts) => {
61
- const { MarketingCore } = await import('./marketing-core.js');
62
- const core = new MarketingCore();
63
- core.start(opts.config);
64
- });
65
-
66
- program.parse();
67
-
68
- // Non-blocking update check after command finishes
69
- checkForUpdate();
package/src/ipc/client.ts DELETED
@@ -1,110 +0,0 @@
1
- import net from 'node:net';
2
- import { randomUUID } from 'node:crypto';
3
- import type { IpcMessage } from '../types/ipc.types.js';
4
- import { encodeMessage, MessageDecoder } from './protocol.js';
5
- import { getPipeName } from '../utils/paths.js';
6
-
7
- interface PendingRequest {
8
- resolve: (result: unknown) => void;
9
- reject: (err: Error) => void;
10
- timer: ReturnType<typeof setTimeout>;
11
- }
12
-
13
- export class IpcClient {
14
- private socket: net.Socket | null = null;
15
- private decoder = new MessageDecoder();
16
- private pending = new Map<string, PendingRequest>();
17
-
18
- constructor(
19
- private pipeName: string = getPipeName(),
20
- private timeout: number = 5000,
21
- ) {}
22
-
23
- connect(): Promise<void> {
24
- return new Promise((resolve, reject) => {
25
- this.socket = net.createConnection(this.pipeName, () => {
26
- resolve();
27
- });
28
-
29
- this.socket.on('data', (chunk) => {
30
- const messages = this.decoder.feed(chunk);
31
- for (const msg of messages) {
32
- this.handleMessage(msg);
33
- }
34
- });
35
-
36
- this.socket.on('error', (err) => {
37
- reject(err);
38
- for (const [id, req] of this.pending) {
39
- clearTimeout(req.timer);
40
- req.reject(new Error(`Connection error: ${err.message}`));
41
- this.pending.delete(id);
42
- }
43
- });
44
-
45
- this.socket.on('close', () => {
46
- for (const [id, req] of this.pending) {
47
- clearTimeout(req.timer);
48
- req.reject(new Error('Connection closed'));
49
- this.pending.delete(id);
50
- }
51
- this.socket = null;
52
- });
53
- });
54
- }
55
-
56
- request(method: string, params?: unknown): Promise<unknown> {
57
- return new Promise((resolve, reject) => {
58
- if (!this.socket || this.socket.destroyed) {
59
- return reject(new Error('Not connected'));
60
- }
61
-
62
- const id = randomUUID();
63
- const timer = setTimeout(() => {
64
- this.pending.delete(id);
65
- reject(new Error(`Request timeout: ${method} (${this.timeout}ms)`));
66
- }, this.timeout);
67
-
68
- this.pending.set(id, { resolve, reject, timer });
69
-
70
- const msg: IpcMessage = {
71
- id,
72
- type: 'request',
73
- method,
74
- params,
75
- };
76
- this.socket.write(encodeMessage(msg));
77
- });
78
- }
79
-
80
- disconnect(): void {
81
- for (const [id, req] of this.pending) {
82
- clearTimeout(req.timer);
83
- req.reject(new Error('Client disconnecting'));
84
- this.pending.delete(id);
85
- }
86
- this.socket?.destroy();
87
- this.socket = null;
88
- this.decoder.reset();
89
- }
90
-
91
- get connected(): boolean {
92
- return this.socket !== null && !this.socket.destroyed;
93
- }
94
-
95
- private handleMessage(msg: IpcMessage): void {
96
- if (msg.type === 'response') {
97
- const req = this.pending.get(msg.id);
98
- if (!req) return;
99
-
100
- clearTimeout(req.timer);
101
- this.pending.delete(msg.id);
102
-
103
- if (msg.error) {
104
- req.reject(new Error(msg.error.message));
105
- } else {
106
- req.resolve(msg.result);
107
- }
108
- }
109
- }
110
- }
@@ -1,35 +0,0 @@
1
- import { Buffer } from 'node:buffer';
2
- import type { IpcMessage } from '../types/ipc.types.js';
3
-
4
- export function encodeMessage(msg: IpcMessage): Buffer {
5
- const json = JSON.stringify(msg);
6
- const payload = Buffer.from(json, 'utf8');
7
- const frame = Buffer.alloc(4 + payload.length);
8
- frame.writeUInt32BE(payload.length, 0);
9
- payload.copy(frame, 4);
10
- return frame;
11
- }
12
-
13
- export class MessageDecoder {
14
- private buffer = Buffer.alloc(0);
15
-
16
- feed(chunk: Buffer): IpcMessage[] {
17
- this.buffer = Buffer.concat([this.buffer, chunk]);
18
- const messages: IpcMessage[] = [];
19
-
20
- while (this.buffer.length >= 4) {
21
- const length = this.buffer.readUInt32BE(0);
22
- if (this.buffer.length < 4 + length) break;
23
-
24
- const json = this.buffer.subarray(4, 4 + length).toString('utf8');
25
- this.buffer = this.buffer.subarray(4 + length);
26
- messages.push(JSON.parse(json) as IpcMessage);
27
- }
28
-
29
- return messages;
30
- }
31
-
32
- reset(): void {
33
- this.buffer = Buffer.alloc(0);
34
- }
35
- }
package/src/ipc/router.ts DELETED
@@ -1,126 +0,0 @@
1
- import { getLogger } from '../utils/logger.js';
2
-
3
- const logger = getLogger();
4
- import type { PostService } from '../services/post.service.js';
5
- import type { CampaignService } from '../services/campaign.service.js';
6
- import type { StrategyService } from '../services/strategy.service.js';
7
- import type { TemplateService } from '../services/template.service.js';
8
- import type { RuleService } from '../services/rule.service.js';
9
- import type { AudienceService } from '../services/audience.service.js';
10
- import type { SynapseService } from '../services/synapse.service.js';
11
- import type { AnalyticsService } from '../services/analytics.service.js';
12
- import type { InsightService } from '../services/insight.service.js';
13
- import type { LearningEngine } from '../learning/learning-engine.js';
14
-
15
- export interface Services {
16
- post: PostService;
17
- campaign: CampaignService;
18
- strategy: StrategyService;
19
- template: TemplateService;
20
- rule: RuleService;
21
- audience: AudienceService;
22
- synapse: SynapseService;
23
- analytics: AnalyticsService;
24
- insight: InsightService;
25
- learning?: LearningEngine;
26
- }
27
-
28
- type MethodHandler = (params: unknown) => unknown;
29
-
30
- export class IpcRouter {
31
- private methods: Map<string, MethodHandler>;
32
-
33
- constructor(private services: Services) {
34
- this.methods = this.buildMethodMap();
35
- }
36
-
37
- handle(method: string, params: unknown): unknown {
38
- const handler = this.methods.get(method);
39
- if (!handler) {
40
- throw new Error(`Unknown method: ${method}`);
41
- }
42
-
43
- logger.debug(`IPC: ${method}`, { params });
44
- const result = handler(params);
45
- logger.debug(`IPC: ${method} → done`);
46
- return result;
47
- }
48
-
49
- listMethods(): string[] {
50
- return [...this.methods.keys()];
51
- }
52
-
53
- private buildMethodMap(): Map<string, MethodHandler> {
54
- const s = this.services;
55
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
- const p = (params: unknown) => params as any;
57
-
58
- return new Map<string, MethodHandler>([
59
- // Posts
60
- ['post.report', (params) => s.post.report(p(params))],
61
- ['post.publish', (params) => s.post.publish(p(params).id ?? p(params).postId, p(params).url)],
62
- ['post.get', (params) => s.post.getById(p(params).id)],
63
- ['post.list', (params) => s.post.listPosts(p(params))],
64
- ['post.search', (params) => s.post.searchPosts(p(params).query, p(params).limit)],
65
- ['post.similar', (params) => s.post.findSimilar(p(params).id ?? p(params).postId)],
66
- ['post.engagement', (params) => s.post.updateEngagement(p(params))],
67
- ['post.getEngagement', (params) => s.post.getEngagement(p(params).id ?? p(params).postId)],
68
- ['post.top', (params) => s.post.getTopPosts(p(params)?.limit)],
69
- ['post.stats', () => s.post.getPostStats()],
70
- ['post.platformStats', () => s.post.getPlatformStats()],
71
-
72
- // Campaigns
73
- ['campaign.create', (params) => s.campaign.create(p(params))],
74
- ['campaign.get', (params) => s.campaign.getById(p(params).id)],
75
- ['campaign.list', () => s.campaign.listCampaigns()],
76
- ['campaign.stats', (params) => s.campaign.getStats(p(params).id ?? p(params).campaignId)],
77
- ['campaign.update', (params) => s.campaign.update(p(params).id, p(params))],
78
-
79
- // Strategies
80
- ['strategy.report', (params) => s.strategy.report(p(params))],
81
- ['strategy.suggest', (params) => s.strategy.suggest(p(params).query, p(params).limit)],
82
- ['strategy.top', (params) => s.strategy.getTopStrategies(p(params)?.minConfidence, p(params)?.limit)],
83
- ['strategy.list', (params) => s.strategy.listAll(p(params)?.limit)],
84
-
85
- // Templates
86
- ['template.find', (params) => s.template.find(p(params).query, p(params).limit)],
87
- ['template.create', (params) => s.template.create(p(params))],
88
- ['template.list', (params) => s.template.listAll(p(params)?.limit)],
89
- ['template.byPlatform', (params) => s.template.findByPlatform(p(params).platform, p(params).limit)],
90
- ['template.use', (params) => s.template.useTemplate(p(params).templateId, p(params).postId)],
91
-
92
- // Rules
93
- ['rule.check', (params) => s.rule.check(p(params).content, p(params).platform)],
94
- ['rule.list', () => s.rule.listRules()],
95
- ['rule.create', (params) => s.rule.create(p(params))],
96
-
97
- // Audiences
98
- ['audience.create', (params) => s.audience.create(p(params))],
99
- ['audience.list', () => s.audience.listAll()],
100
- ['audience.linkPost', (params) => s.audience.linkToPost(p(params).audienceId, p(params).postId)],
101
-
102
- // Insights
103
- ['insight.list', (params) => s.insight.listActive(p(params)?.limit)],
104
- ['insight.byType', (params) => s.insight.listByType(p(params).type, p(params).limit)],
105
- ['insight.byCampaign', (params) => s.insight.listByCampaign(p(params).campaignId)],
106
-
107
- // Synapses
108
- ['synapse.context', (params) => s.synapse.getPostContext(p(params).postId ?? p(params).id)],
109
- ['synapse.path', (params) => s.synapse.findPath(p(params).fromType, p(params).fromId, p(params).toType, p(params).toId)],
110
- ['synapse.related', (params) => s.synapse.getRelated(p(params))],
111
- ['synapse.stats', () => s.synapse.getNetworkStats()],
112
- ['synapse.strongest', (params) => s.synapse.getStrongest(p(params)?.limit)],
113
-
114
- // Analytics
115
- ['analytics.summary', () => s.analytics.getSummary()],
116
- ['analytics.top', (params) => s.analytics.getTopPerformers(p(params)?.limit)],
117
- ['analytics.dashboard', () => s.analytics.getDashboardData()],
118
-
119
- // Learning
120
- ['learning.run', () => {
121
- if (!s.learning) throw new Error('Learning engine not available');
122
- return s.learning.runCycle();
123
- }],
124
- ]);
125
- }
126
- }