@a-company/paradigm 3.44.0 → 3.46.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/dist/chunk-KVDYJLTC.js +121 -0
- package/dist/{chunk-SOBTKFSP.js → chunk-S2HO5MLR.js} +5 -0
- package/dist/index.js +40 -19
- package/dist/mcp.js +71 -1
- package/dist/peers-RFQCWVLV.js +82 -0
- package/dist/{platform-server-KHL6ZPPN.js → platform-server-H7Y6Q7O4.js} +1 -1
- package/dist/{serve-JVXSRSUB.js → serve-KKEHE44G.js} +1 -1
- package/dist/{symphony-EYRGGVNE.js → symphony-6K3HD7AW.js} +349 -28
- package/dist/{symphony-QWOEKZMC.js → symphony-YCHBYN3E.js} +19 -1
- package/dist/symphony-peers-APOGJPF4.js +120 -0
- package/dist/symphony-peers-HSY3RI3S.js +34 -0
- package/dist/symphony-relay-GTAJRCVF.js +683 -0
- package/dist/university-content/courses/para-501.json +84 -0
- package/package.json +1 -1
|
@@ -25,17 +25,18 @@ import {
|
|
|
25
25
|
resolveThread,
|
|
26
26
|
routeMessage,
|
|
27
27
|
unregisterAgent
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-S2HO5MLR.js";
|
|
29
29
|
import "./chunk-ZXMDA7VB.js";
|
|
30
30
|
|
|
31
31
|
// src/commands/symphony/index.ts
|
|
32
32
|
import chalk from "chalk";
|
|
33
|
-
import * as
|
|
33
|
+
import * as path from "path";
|
|
34
|
+
import * as fs from "fs";
|
|
35
|
+
import * as os from "os";
|
|
34
36
|
async function symphonyJoinCommand(options) {
|
|
35
37
|
const rootDir = process.cwd();
|
|
36
38
|
if (options.remote) {
|
|
37
|
-
|
|
38
|
-
console.log(chalk.gray("Remote linking will be available in a future Symphony phase."));
|
|
39
|
+
await symphonyJoinRemote(rootDir, options.remote);
|
|
39
40
|
return;
|
|
40
41
|
}
|
|
41
42
|
const identity = registerAgent(rootDir);
|
|
@@ -55,6 +56,88 @@ async function symphonyJoinCommand(options) {
|
|
|
55
56
|
console.log(chalk.gray(`
|
|
56
57
|
Tip: Set up polling with: /loop 10s paradigm_symphony_poll`));
|
|
57
58
|
}
|
|
59
|
+
async function symphonyJoinRemote(rootDir, remote) {
|
|
60
|
+
const { SymphonyRelay } = await import("./symphony-relay-GTAJRCVF.js");
|
|
61
|
+
let address;
|
|
62
|
+
let embeddedCode;
|
|
63
|
+
if (remote.includes("#")) {
|
|
64
|
+
const parts = remote.split("#");
|
|
65
|
+
address = parts[0];
|
|
66
|
+
embeddedCode = parts[1];
|
|
67
|
+
} else {
|
|
68
|
+
address = remote;
|
|
69
|
+
}
|
|
70
|
+
if (!address.includes(":")) {
|
|
71
|
+
address = `${address}:3939`;
|
|
72
|
+
}
|
|
73
|
+
let identity = getMyIdentity(rootDir);
|
|
74
|
+
if (!identity) {
|
|
75
|
+
identity = registerAgent(rootDir);
|
|
76
|
+
}
|
|
77
|
+
let code;
|
|
78
|
+
if (embeddedCode) {
|
|
79
|
+
code = embeddedCode;
|
|
80
|
+
console.log(chalk.cyan(`
|
|
81
|
+
Connecting to ${address} with embedded pairing code...`));
|
|
82
|
+
} else {
|
|
83
|
+
console.log(chalk.cyan(`
|
|
84
|
+
Connecting to ${address}...`));
|
|
85
|
+
console.log(chalk.white(" Enter the 6-digit pairing code shown on the host:"));
|
|
86
|
+
code = await readLineFromStdin(" Code: ");
|
|
87
|
+
code = code.trim();
|
|
88
|
+
if (!/^\d{6}$/.test(code)) {
|
|
89
|
+
console.log(chalk.red(" Invalid code. Must be 6 digits."));
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const relay = new SymphonyRelay({
|
|
94
|
+
mode: "client",
|
|
95
|
+
peerId: identity.id,
|
|
96
|
+
events: {
|
|
97
|
+
onPeerConnected: (peerId, displayName) => {
|
|
98
|
+
console.log(chalk.green(` \u2713 Connected to ${chalk.bold(displayName)} (${peerId})`));
|
|
99
|
+
},
|
|
100
|
+
onPeerDisconnected: (peerId) => {
|
|
101
|
+
console.log(chalk.yellow(` Peer ${peerId} disconnected. Reconnecting...`));
|
|
102
|
+
},
|
|
103
|
+
onMessageRelayed: (messageId, from, to) => {
|
|
104
|
+
console.log(chalk.gray(` \u2190 Message ${messageId.slice(0, 8)} from ${from} \u2192 ${to}`));
|
|
105
|
+
},
|
|
106
|
+
onError: (err) => {
|
|
107
|
+
console.log(chalk.red(` Error: ${err.message}`));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
try {
|
|
112
|
+
await relay.connectToServer(address, code);
|
|
113
|
+
console.log(chalk.green("\n \u2713 Paired and connected!"));
|
|
114
|
+
console.log(chalk.gray(" Messages from remote agents will appear in your inbox."));
|
|
115
|
+
console.log(chalk.gray(" Press Ctrl+C to disconnect.\n"));
|
|
116
|
+
process.on("SIGINT", () => {
|
|
117
|
+
console.log(chalk.yellow("\n Disconnecting..."));
|
|
118
|
+
relay.stop();
|
|
119
|
+
process.exit(0);
|
|
120
|
+
});
|
|
121
|
+
await new Promise(() => {
|
|
122
|
+
});
|
|
123
|
+
} catch (err) {
|
|
124
|
+
console.log(chalk.red(` Failed to connect: ${err.message}`));
|
|
125
|
+
relay.stop();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function readLineFromStdin(prompt) {
|
|
129
|
+
return new Promise((resolve) => {
|
|
130
|
+
process.stdout.write(prompt);
|
|
131
|
+
let data = "";
|
|
132
|
+
process.stdin.setEncoding("utf-8");
|
|
133
|
+
process.stdin.resume();
|
|
134
|
+
process.stdin.once("data", (chunk) => {
|
|
135
|
+
data = chunk.toString();
|
|
136
|
+
process.stdin.pause();
|
|
137
|
+
resolve(data);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
}
|
|
58
141
|
async function symphonyLeaveCommand() {
|
|
59
142
|
const rootDir = process.cwd();
|
|
60
143
|
const agentId = resolveAgentIdentity(rootDir);
|
|
@@ -91,16 +174,29 @@ async function symphonyWhoamiCommand() {
|
|
|
91
174
|
async function symphonyListCommand(options) {
|
|
92
175
|
cleanStaleAgents();
|
|
93
176
|
const agents = listAgents();
|
|
177
|
+
const { loadPeers } = await import("./symphony-peers-HSY3RI3S.js");
|
|
178
|
+
const peers = loadPeers();
|
|
179
|
+
const remoteAgents = [];
|
|
180
|
+
for (const peer of peers) {
|
|
181
|
+
if (peer.revoked) continue;
|
|
182
|
+
for (const agent of peer.agents || []) {
|
|
183
|
+
remoteAgents.push({ ...agent, peerId: peer.id });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const totalCount = agents.length + remoteAgents.length;
|
|
94
187
|
if (options.json) {
|
|
95
|
-
console.log(JSON.stringify(
|
|
188
|
+
console.log(JSON.stringify({
|
|
189
|
+
local: agents,
|
|
190
|
+
remote: remoteAgents
|
|
191
|
+
}, null, 2));
|
|
96
192
|
return;
|
|
97
193
|
}
|
|
98
|
-
if (
|
|
194
|
+
if (totalCount === 0) {
|
|
99
195
|
console.log(chalk.yellow('No agents joined. Run "paradigm symphony join" in each terminal.'));
|
|
100
196
|
return;
|
|
101
197
|
}
|
|
102
198
|
console.log(chalk.cyan(`
|
|
103
|
-
Symphony Agents (${
|
|
199
|
+
Symphony Agents (${totalCount})
|
|
104
200
|
`));
|
|
105
201
|
console.log(chalk.gray(` ${"AGENT ID".padEnd(30)} ${"PROJECT".padEnd(15)} ${"ROLE".padEnd(10)} STATUS`));
|
|
106
202
|
console.log(chalk.gray(` ${"\u2500".repeat(30)} ${"\u2500".repeat(15)} ${"\u2500".repeat(10)} ${"\u2500".repeat(8)}`));
|
|
@@ -111,6 +207,17 @@ async function symphonyListCommand(options) {
|
|
|
111
207
|
console.log(` ${chalk.gray(` \u2514 ${agent.statusBlurb}`)}`);
|
|
112
208
|
}
|
|
113
209
|
}
|
|
210
|
+
if (remoteAgents.length > 0) {
|
|
211
|
+
console.log(chalk.gray(`
|
|
212
|
+
${"\u2500".repeat(65)}`));
|
|
213
|
+
console.log(chalk.cyan(` Remote Agents (${remoteAgents.length})
|
|
214
|
+
`));
|
|
215
|
+
for (const agent of remoteAgents) {
|
|
216
|
+
const status = agent.status === "awake" ? chalk.green("awake") : chalk.yellow("asleep");
|
|
217
|
+
const tag = chalk.magenta(`(remote: ${agent.peerId})`);
|
|
218
|
+
console.log(` ${chalk.white(agent.id.padEnd(30))} ${agent.project.padEnd(15)} ${agent.role.padEnd(10)} ${status} ${tag}`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
114
221
|
console.log();
|
|
115
222
|
}
|
|
116
223
|
async function symphonySendCommand(messageText, options) {
|
|
@@ -291,10 +398,14 @@ async function symphonyStatusCommand(options) {
|
|
|
291
398
|
const threads = listThreads("active");
|
|
292
399
|
const pendingRequests = listFileRequests("pending");
|
|
293
400
|
const unread = identity ? readInbox(identity.id) : [];
|
|
401
|
+
const { loadPeers } = await import("./symphony-peers-HSY3RI3S.js");
|
|
402
|
+
const peers = loadPeers();
|
|
403
|
+
const activePeers = peers.filter((p) => !p.revoked);
|
|
294
404
|
if (options.json) {
|
|
295
405
|
console.log(JSON.stringify({
|
|
296
406
|
identity: identity ? { id: identity.id, project: identity.project, role: identity.role } : null,
|
|
297
407
|
agents: agents.map((a) => ({ id: a.id, status: isAgentAsleep(a) ? "asleep" : "awake", statusBlurb: a.statusBlurb })),
|
|
408
|
+
peers: activePeers.map((p) => ({ id: p.id, address: p.address, agents: p.agents?.length ?? 0, lastSeen: p.lastSeen })),
|
|
298
409
|
activeThreads: threads.length,
|
|
299
410
|
unreadMessages: unread.length,
|
|
300
411
|
pendingFileRequests: pendingRequests.length
|
|
@@ -314,6 +425,16 @@ async function symphonyStatusCommand(options) {
|
|
|
314
425
|
const blurb = a.statusBlurb ? chalk.gray(` \u2014 ${a.statusBlurb}`) : "";
|
|
315
426
|
console.log(` ${chalk.white(a.id)} [${st}]${blurb}`);
|
|
316
427
|
}
|
|
428
|
+
if (activePeers.length > 0) {
|
|
429
|
+
const totalRemoteAgents = activePeers.reduce((sum, p) => sum + (p.agents?.length ?? 0), 0);
|
|
430
|
+
console.log(` ${chalk.white("Peers:")} ${activePeers.length} connected (${totalRemoteAgents} remote agents)`);
|
|
431
|
+
for (const p of activePeers) {
|
|
432
|
+
const agentCount = p.agents?.length ?? 0;
|
|
433
|
+
console.log(` ${chalk.white(p.id)} at ${p.address} (${agentCount} agent${agentCount !== 1 ? "s" : ""})`);
|
|
434
|
+
}
|
|
435
|
+
} else {
|
|
436
|
+
console.log(` ${chalk.white("Peers:")} ${chalk.gray('none (run "paradigm symphony serve" to accept connections)')}`);
|
|
437
|
+
}
|
|
317
438
|
console.log(` ${chalk.white("Threads:")} ${threads.length} active`);
|
|
318
439
|
console.log(` ${chalk.white("Unread:")} ${unread.length} note${unread.length !== 1 ? "s" : ""}`);
|
|
319
440
|
console.log(` ${chalk.white("File Requests:")} ${pendingRequests.length} pending`);
|
|
@@ -321,31 +442,88 @@ async function symphonyStatusCommand(options) {
|
|
|
321
442
|
}
|
|
322
443
|
async function symphonyServeCommand(options) {
|
|
323
444
|
const port = parseInt(options.port || "3939", 10);
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
445
|
+
const rootDir = process.cwd();
|
|
446
|
+
const { SymphonyRelay } = await import("./symphony-relay-GTAJRCVF.js");
|
|
447
|
+
let identity = getMyIdentity(rootDir);
|
|
448
|
+
if (!identity) {
|
|
449
|
+
identity = registerAgent(rootDir);
|
|
450
|
+
}
|
|
451
|
+
console.log(chalk.cyan("\n Starting Symphony relay server...\n"));
|
|
452
|
+
const relay = new SymphonyRelay({
|
|
453
|
+
mode: "server",
|
|
454
|
+
peerId: identity.id,
|
|
455
|
+
port,
|
|
456
|
+
events: {
|
|
457
|
+
onPeerConnected: (peerId, displayName) => {
|
|
458
|
+
console.log(chalk.green(` \u2713 Peer connected: ${chalk.bold(displayName)} (${peerId})`));
|
|
459
|
+
const remoteAgents = relay.getRemoteAgents();
|
|
460
|
+
if (remoteAgents.length > 0) {
|
|
461
|
+
console.log(chalk.gray(` Remote agents: ${remoteAgents.map((a) => a.id).join(", ")}`));
|
|
462
|
+
}
|
|
463
|
+
},
|
|
464
|
+
onPeerDisconnected: (peerId) => {
|
|
465
|
+
console.log(chalk.yellow(` Peer disconnected: ${peerId}`));
|
|
466
|
+
},
|
|
467
|
+
onPeerAuthFailed: (address, reason) => {
|
|
468
|
+
console.log(chalk.red(` Auth failed from ${address}: ${reason}`));
|
|
469
|
+
},
|
|
470
|
+
onMessageRelayed: (messageId, from, to) => {
|
|
471
|
+
console.log(chalk.gray(` \u2194 Relayed ${messageId.slice(0, 8)} from ${from} to ${to}`));
|
|
472
|
+
},
|
|
473
|
+
onError: (err) => {
|
|
474
|
+
console.log(chalk.red(` Error: ${err.message}`));
|
|
335
475
|
}
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
try {
|
|
479
|
+
const pairing = await relay.startServer();
|
|
480
|
+
const localIp = getLocalIpAddress();
|
|
481
|
+
console.log(chalk.green(` \u2713 Symphony relay listening on port ${port}`));
|
|
482
|
+
console.log();
|
|
483
|
+
console.log(chalk.white(" Pairing Code:"));
|
|
484
|
+
console.log();
|
|
485
|
+
console.log(chalk.bold.cyan(` ${pairing.code.slice(0, 3)} ${pairing.code.slice(3)}`));
|
|
486
|
+
console.log();
|
|
487
|
+
console.log(chalk.gray(" Share this code with the person connecting."));
|
|
488
|
+
console.log(chalk.gray(` Code rotates every 5 minutes.
|
|
489
|
+
`));
|
|
490
|
+
console.log(chalk.white(" LAN connect:"));
|
|
491
|
+
console.log(chalk.gray(` paradigm symphony join --remote ${localIp}:${port}`));
|
|
492
|
+
if (options.public) {
|
|
493
|
+
const connectionString = `${localIp}:${port}#${pairing.code}`;
|
|
494
|
+
console.log();
|
|
495
|
+
console.log(chalk.white(" Internet connect (connection string):"));
|
|
496
|
+
console.log(chalk.cyan(` paradigm symphony join --remote ${connectionString}`));
|
|
497
|
+
console.log(chalk.gray(" (Requires port 3939 reachable: port forward, VPN, or SSH tunnel)"));
|
|
498
|
+
}
|
|
499
|
+
console.log(chalk.gray("\n Press Ctrl+C to stop.\n"));
|
|
500
|
+
const rotateInterval = setInterval(() => {
|
|
501
|
+
const newPairing = relay.rotatePairingCode();
|
|
502
|
+
console.log(chalk.cyan(` Code rotated: ${newPairing.code.slice(0, 3)} ${newPairing.code.slice(3)}`));
|
|
503
|
+
}, 5 * 60 * 1e3);
|
|
504
|
+
process.on("SIGINT", () => {
|
|
505
|
+
console.log(chalk.yellow("\n Shutting down relay..."));
|
|
506
|
+
clearInterval(rotateInterval);
|
|
507
|
+
relay.stop();
|
|
508
|
+
process.exit(0);
|
|
336
509
|
});
|
|
337
|
-
|
|
510
|
+
await new Promise(() => {
|
|
338
511
|
});
|
|
339
|
-
})
|
|
340
|
-
server.listen(port, "0.0.0.0", () => {
|
|
341
|
-
console.log(chalk.green(` \u2713 Symphony server listening on 0.0.0.0:${port}`));
|
|
342
|
-
console.log(chalk.gray(` Connect from another machine: paradigm symphony join --remote <this-ip>:${port}`));
|
|
343
|
-
});
|
|
344
|
-
server.on("error", (err) => {
|
|
512
|
+
} catch (err) {
|
|
345
513
|
console.log(chalk.red(` Failed to start server: ${err.message}`));
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
514
|
+
relay.stop();
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
function getLocalIpAddress() {
|
|
518
|
+
const interfaces = os.networkInterfaces();
|
|
519
|
+
for (const name of Object.keys(interfaces)) {
|
|
520
|
+
for (const iface of interfaces[name] || []) {
|
|
521
|
+
if (iface.family === "IPv4" && !iface.internal) {
|
|
522
|
+
return iface.address;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
return "127.0.0.1";
|
|
349
527
|
}
|
|
350
528
|
async function symphonyRequestCommand(file, options) {
|
|
351
529
|
const rootDir = process.cwd();
|
|
@@ -451,6 +629,148 @@ async function symphonyDenyCommand(requestId, options) {
|
|
|
451
629
|
console.log(chalk.red(`\u2717 File request not found or already resolved: ${requestId}`));
|
|
452
630
|
}
|
|
453
631
|
}
|
|
632
|
+
var INTENT_COLORS = {
|
|
633
|
+
question: chalk.blue,
|
|
634
|
+
context: chalk.gray,
|
|
635
|
+
clarification: chalk.blue,
|
|
636
|
+
proposal: chalk.cyan,
|
|
637
|
+
verification: chalk.blue,
|
|
638
|
+
action: chalk.cyan,
|
|
639
|
+
decision: chalk.yellow,
|
|
640
|
+
alert: chalk.red,
|
|
641
|
+
approval: chalk.green,
|
|
642
|
+
rejection: chalk.red,
|
|
643
|
+
reference: chalk.gray,
|
|
644
|
+
handoff: chalk.magenta,
|
|
645
|
+
fileRequest: chalk.green,
|
|
646
|
+
fileApproved: chalk.green,
|
|
647
|
+
fileDenied: chalk.red,
|
|
648
|
+
fileDelivery: chalk.green
|
|
649
|
+
};
|
|
650
|
+
function formatWatchMessage(msg) {
|
|
651
|
+
const time = new Date(msg.timestamp).toLocaleTimeString(void 0, {
|
|
652
|
+
hour: "numeric",
|
|
653
|
+
minute: "2-digit",
|
|
654
|
+
second: "2-digit"
|
|
655
|
+
});
|
|
656
|
+
const colorFn = INTENT_COLORS[msg.intent] || chalk.white;
|
|
657
|
+
const intentLabel = colorFn(`[${msg.intent}]`);
|
|
658
|
+
const sender = chalk.cyan(msg.sender.name);
|
|
659
|
+
const threadLabel = msg.threadRoot ? chalk.gray(` (${msg.threadRoot})`) : "";
|
|
660
|
+
const lines = [];
|
|
661
|
+
lines.push(` ${chalk.gray(time)} ${sender} ${intentLabel}${threadLabel}`);
|
|
662
|
+
const textLines = msg.content.text.split("\n");
|
|
663
|
+
for (const line of textLines) {
|
|
664
|
+
lines.push(` ${line}`);
|
|
665
|
+
}
|
|
666
|
+
if (msg.symbols.length > 0) {
|
|
667
|
+
lines.push(` ${chalk.gray(`Symbols: ${msg.symbols.join(", ")}`)}`);
|
|
668
|
+
}
|
|
669
|
+
if (msg.content.decision) {
|
|
670
|
+
lines.push(` ${chalk.yellow(`Decision: ${msg.content.decision}`)}`);
|
|
671
|
+
}
|
|
672
|
+
if (msg.content.diff) {
|
|
673
|
+
lines.push(` ${chalk.gray("[diff attached]")}`);
|
|
674
|
+
}
|
|
675
|
+
return lines.join("\n");
|
|
676
|
+
}
|
|
677
|
+
async function symphonyWatchCommand(options) {
|
|
678
|
+
const rootDir = process.cwd();
|
|
679
|
+
let identity = getMyIdentity(rootDir);
|
|
680
|
+
if (!identity) {
|
|
681
|
+
identity = registerAgent(rootDir);
|
|
682
|
+
console.log(chalk.gray(`Auto-joined as ${identity.id}`));
|
|
683
|
+
}
|
|
684
|
+
const intervalMs = parseInt(options.interval || "2000", 10);
|
|
685
|
+
const threadFilter = options.thread;
|
|
686
|
+
const quiet = options.quiet;
|
|
687
|
+
const scoreDir = path.join(os.homedir(), ".paradigm", "score");
|
|
688
|
+
const inboxPath = path.join(scoreDir, "agents", ...identity.id.split("/"), "inbox.jsonl");
|
|
689
|
+
let lastLineCount = 0;
|
|
690
|
+
let lastSize = 0;
|
|
691
|
+
if (fs.existsSync(inboxPath)) {
|
|
692
|
+
const content = fs.readFileSync(inboxPath, "utf-8");
|
|
693
|
+
lastLineCount = content.split("\n").filter((l) => l.trim().length > 0).length;
|
|
694
|
+
lastSize = fs.statSync(inboxPath).size;
|
|
695
|
+
}
|
|
696
|
+
if (!quiet) {
|
|
697
|
+
console.log(chalk.cyan("\n Symphony Watch"));
|
|
698
|
+
console.log(chalk.gray(` Agent: ${identity.id}`));
|
|
699
|
+
console.log(chalk.gray(` Inbox: ${inboxPath}`));
|
|
700
|
+
console.log(chalk.gray(` Poll: ${intervalMs}ms`));
|
|
701
|
+
if (threadFilter) {
|
|
702
|
+
console.log(chalk.gray(` Filter: thread ${threadFilter}`));
|
|
703
|
+
}
|
|
704
|
+
console.log(chalk.gray(` Press Ctrl+C to stop
|
|
705
|
+
`));
|
|
706
|
+
console.log(chalk.gray(` ${"\u2500".repeat(60)}
|
|
707
|
+
`));
|
|
708
|
+
}
|
|
709
|
+
const threadsDir = path.join(scoreDir, "threads");
|
|
710
|
+
let knownThreads = /* @__PURE__ */ new Set();
|
|
711
|
+
if (fs.existsSync(threadsDir)) {
|
|
712
|
+
for (const f of fs.readdirSync(threadsDir)) {
|
|
713
|
+
knownThreads.add(f);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
const poll = () => {
|
|
717
|
+
try {
|
|
718
|
+
if (fs.existsSync(inboxPath)) {
|
|
719
|
+
const stat = fs.statSync(inboxPath);
|
|
720
|
+
if (stat.size > lastSize) {
|
|
721
|
+
const content = fs.readFileSync(inboxPath, "utf-8");
|
|
722
|
+
const lines = content.split("\n").filter((l) => l.trim().length > 0);
|
|
723
|
+
if (lines.length > lastLineCount) {
|
|
724
|
+
const newLines = lines.slice(lastLineCount);
|
|
725
|
+
for (const line of newLines) {
|
|
726
|
+
try {
|
|
727
|
+
const msg = JSON.parse(line);
|
|
728
|
+
if (threadFilter && msg.threadRoot !== threadFilter) continue;
|
|
729
|
+
console.log(formatWatchMessage(msg));
|
|
730
|
+
console.log();
|
|
731
|
+
} catch {
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
lastLineCount = lines.length;
|
|
735
|
+
}
|
|
736
|
+
lastSize = stat.size;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
if (fs.existsSync(threadsDir)) {
|
|
740
|
+
const currentFiles = fs.readdirSync(threadsDir);
|
|
741
|
+
for (const f of currentFiles) {
|
|
742
|
+
if (!knownThreads.has(f)) {
|
|
743
|
+
knownThreads.add(f);
|
|
744
|
+
try {
|
|
745
|
+
const threadData = JSON.parse(
|
|
746
|
+
fs.readFileSync(path.join(threadsDir, f), "utf-8")
|
|
747
|
+
);
|
|
748
|
+
if (!quiet) {
|
|
749
|
+
console.log(` ${chalk.green("+")} ${chalk.white("New thread:")} ${threadData.topic || threadData.id}`);
|
|
750
|
+
console.log(` ${chalk.gray(`by ${threadData.initiator?.name || "unknown"} \u2014 ${threadData.id}`)}`);
|
|
751
|
+
console.log();
|
|
752
|
+
}
|
|
753
|
+
} catch {
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
markAgentPollTime(identity.id);
|
|
759
|
+
} catch {
|
|
760
|
+
}
|
|
761
|
+
};
|
|
762
|
+
poll();
|
|
763
|
+
const timer = setInterval(poll, intervalMs);
|
|
764
|
+
process.on("SIGINT", () => {
|
|
765
|
+
clearInterval(timer);
|
|
766
|
+
if (!quiet) {
|
|
767
|
+
console.log(chalk.gray("\n Watch stopped.\n"));
|
|
768
|
+
}
|
|
769
|
+
process.exit(0);
|
|
770
|
+
});
|
|
771
|
+
await new Promise(() => {
|
|
772
|
+
});
|
|
773
|
+
}
|
|
454
774
|
export {
|
|
455
775
|
symphonyApproveCommand,
|
|
456
776
|
symphonyDenyCommand,
|
|
@@ -466,5 +786,6 @@ export {
|
|
|
466
786
|
symphonyStatusCommand,
|
|
467
787
|
symphonyThreadCommand,
|
|
468
788
|
symphonyThreadsCommand,
|
|
789
|
+
symphonyWatchCommand,
|
|
469
790
|
symphonyWhoamiCommand
|
|
470
791
|
};
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
resolveAgentIdentity,
|
|
19
19
|
resolveThread,
|
|
20
20
|
routeMessage
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-S2HO5MLR.js";
|
|
22
22
|
import "./chunk-ZXMDA7VB.js";
|
|
23
23
|
|
|
24
24
|
// src/platform-server/routes/symphony.ts
|
|
@@ -57,6 +57,24 @@ function createSymphonyRouter(projectDir, broadcast) {
|
|
|
57
57
|
res.status(500).json({ error: "Failed to get identity", detail: String(err) });
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
|
+
router.get("/peers", async (_req, res) => {
|
|
61
|
+
try {
|
|
62
|
+
const { loadPeers } = await import("./symphony-peers-HSY3RI3S.js");
|
|
63
|
+
const peers = loadPeers();
|
|
64
|
+
const result = peers.map((p) => ({
|
|
65
|
+
id: p.id,
|
|
66
|
+
displayName: p.displayName,
|
|
67
|
+
address: p.address,
|
|
68
|
+
connectedAt: p.connectedAt,
|
|
69
|
+
lastSeen: p.lastSeen,
|
|
70
|
+
revoked: p.revoked,
|
|
71
|
+
agents: p.agents || []
|
|
72
|
+
}));
|
|
73
|
+
res.json({ peers: result });
|
|
74
|
+
} catch (err) {
|
|
75
|
+
res.status(500).json({ error: "Failed to list peers", detail: String(err) });
|
|
76
|
+
}
|
|
77
|
+
});
|
|
60
78
|
router.get("/threads", (req, res) => {
|
|
61
79
|
try {
|
|
62
80
|
const statusParam = req.query.status;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// ../paradigm-mcp/src/utils/symphony-peers.ts
|
|
4
|
+
import * as fs from "fs";
|
|
5
|
+
import * as path from "path";
|
|
6
|
+
import * as os from "os";
|
|
7
|
+
import * as crypto from "crypto";
|
|
8
|
+
var SCORE_DIR = path.join(os.homedir(), ".paradigm", "score");
|
|
9
|
+
var PEERS_FILE = path.join(SCORE_DIR, "peers.json");
|
|
10
|
+
var PAIRING_TTL_MS = 5 * 60 * 1e3;
|
|
11
|
+
function loadPeers() {
|
|
12
|
+
try {
|
|
13
|
+
if (!fs.existsSync(PEERS_FILE)) return [];
|
|
14
|
+
const content = fs.readFileSync(PEERS_FILE, "utf-8");
|
|
15
|
+
const parsed = JSON.parse(content);
|
|
16
|
+
if (!Array.isArray(parsed)) return [];
|
|
17
|
+
return parsed;
|
|
18
|
+
} catch {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function savePeers(peers) {
|
|
23
|
+
if (!fs.existsSync(SCORE_DIR)) {
|
|
24
|
+
fs.mkdirSync(SCORE_DIR, { recursive: true });
|
|
25
|
+
}
|
|
26
|
+
fs.writeFileSync(PEERS_FILE, JSON.stringify(peers, null, 2), { mode: 384 });
|
|
27
|
+
}
|
|
28
|
+
function findPeer(id) {
|
|
29
|
+
const peers = loadPeers();
|
|
30
|
+
return peers.find((p) => p.id === id) ?? null;
|
|
31
|
+
}
|
|
32
|
+
function addPeer(peer) {
|
|
33
|
+
const peers = loadPeers();
|
|
34
|
+
const idx = peers.findIndex((p) => p.id === peer.id);
|
|
35
|
+
if (idx >= 0) {
|
|
36
|
+
peers[idx] = peer;
|
|
37
|
+
} else {
|
|
38
|
+
peers.push(peer);
|
|
39
|
+
}
|
|
40
|
+
savePeers(peers);
|
|
41
|
+
}
|
|
42
|
+
function revokePeer(id) {
|
|
43
|
+
const peers = loadPeers();
|
|
44
|
+
const peer = peers.find((p) => p.id === id);
|
|
45
|
+
if (!peer) return false;
|
|
46
|
+
peer.revoked = true;
|
|
47
|
+
savePeers(peers);
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
function forgetAllPeers() {
|
|
51
|
+
const peers = loadPeers();
|
|
52
|
+
const count = peers.length;
|
|
53
|
+
if (fs.existsSync(PEERS_FILE)) {
|
|
54
|
+
fs.unlinkSync(PEERS_FILE);
|
|
55
|
+
}
|
|
56
|
+
return count;
|
|
57
|
+
}
|
|
58
|
+
function updatePeerLastSeen(id) {
|
|
59
|
+
const peers = loadPeers();
|
|
60
|
+
const peer = peers.find((p) => p.id === id);
|
|
61
|
+
if (!peer) return;
|
|
62
|
+
peer.lastSeen = (/* @__PURE__ */ new Date()).toISOString();
|
|
63
|
+
savePeers(peers);
|
|
64
|
+
}
|
|
65
|
+
function updatePeerAgents(id, agents) {
|
|
66
|
+
const peers = loadPeers();
|
|
67
|
+
const peer = peers.find((p) => p.id === id);
|
|
68
|
+
if (!peer) return;
|
|
69
|
+
peer.agents = agents;
|
|
70
|
+
savePeers(peers);
|
|
71
|
+
}
|
|
72
|
+
function generatePairing() {
|
|
73
|
+
const sharedSecret = crypto.randomBytes(32).toString("hex");
|
|
74
|
+
const code = (parseInt(crypto.randomBytes(3).toString("hex"), 16) % 1e6).toString().padStart(6, "0");
|
|
75
|
+
const codeHash = crypto.createHash("sha256").update(code).digest("hex");
|
|
76
|
+
return {
|
|
77
|
+
code,
|
|
78
|
+
codeHash,
|
|
79
|
+
sharedSecret,
|
|
80
|
+
createdAt: Date.now()
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function verifyPairingCode(state, code) {
|
|
84
|
+
if (Date.now() - state.createdAt > PAIRING_TTL_MS) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
const hash = crypto.createHash("sha256").update(code).digest("hex");
|
|
88
|
+
return hash === state.codeHash;
|
|
89
|
+
}
|
|
90
|
+
function computeHmacProof(challenge, codeHash) {
|
|
91
|
+
return crypto.createHmac("sha256", codeHash).update(challenge).digest("hex");
|
|
92
|
+
}
|
|
93
|
+
function verifyHmacProof(challenge, codeHash, proof) {
|
|
94
|
+
const expected = computeHmacProof(challenge, codeHash);
|
|
95
|
+
if (expected.length !== proof.length) return false;
|
|
96
|
+
try {
|
|
97
|
+
return crypto.timingSafeEqual(
|
|
98
|
+
Buffer.from(expected, "hex"),
|
|
99
|
+
Buffer.from(proof, "hex")
|
|
100
|
+
);
|
|
101
|
+
} catch {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export {
|
|
106
|
+
PAIRING_TTL_MS,
|
|
107
|
+
PEERS_FILE,
|
|
108
|
+
addPeer,
|
|
109
|
+
computeHmacProof,
|
|
110
|
+
findPeer,
|
|
111
|
+
forgetAllPeers,
|
|
112
|
+
generatePairing,
|
|
113
|
+
loadPeers,
|
|
114
|
+
revokePeer,
|
|
115
|
+
savePeers,
|
|
116
|
+
updatePeerAgents,
|
|
117
|
+
updatePeerLastSeen,
|
|
118
|
+
verifyHmacProof,
|
|
119
|
+
verifyPairingCode
|
|
120
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
PAIRING_TTL_MS,
|
|
4
|
+
PEERS_FILE,
|
|
5
|
+
addPeer,
|
|
6
|
+
computeHmacProof,
|
|
7
|
+
findPeer,
|
|
8
|
+
forgetAllPeers,
|
|
9
|
+
generatePairing,
|
|
10
|
+
loadPeers,
|
|
11
|
+
revokePeer,
|
|
12
|
+
savePeers,
|
|
13
|
+
updatePeerAgents,
|
|
14
|
+
updatePeerLastSeen,
|
|
15
|
+
verifyHmacProof,
|
|
16
|
+
verifyPairingCode
|
|
17
|
+
} from "./chunk-KVDYJLTC.js";
|
|
18
|
+
import "./chunk-ZXMDA7VB.js";
|
|
19
|
+
export {
|
|
20
|
+
PAIRING_TTL_MS,
|
|
21
|
+
PEERS_FILE,
|
|
22
|
+
addPeer,
|
|
23
|
+
computeHmacProof,
|
|
24
|
+
findPeer,
|
|
25
|
+
forgetAllPeers,
|
|
26
|
+
generatePairing,
|
|
27
|
+
loadPeers,
|
|
28
|
+
revokePeer,
|
|
29
|
+
savePeers,
|
|
30
|
+
updatePeerAgents,
|
|
31
|
+
updatePeerLastSeen,
|
|
32
|
+
verifyHmacProof,
|
|
33
|
+
verifyPairingCode
|
|
34
|
+
};
|