@a-company/paradigm 3.43.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.
Files changed (37) hide show
  1. package/dist/{chunk-YW5OCVKB.js → chunk-FKJUBQU3.js} +14 -1
  2. package/dist/chunk-KVDYJLTC.js +121 -0
  3. package/dist/{symphony-ROEKK7VD.js → chunk-S2HO5MLR.js} +53 -431
  4. package/dist/{chunk-RGFANZ4Q.js → chunk-ZDHLG5VP.js} +14 -1
  5. package/dist/{chunk-CZEIK3Y2.js → chunk-ZMQA6SCO.js} +1 -1
  6. package/dist/{chunk-7WEKMZ46.js → chunk-ZSYVKSY6.js} +1 -1
  7. package/dist/{commands-LEPFD7S5.js → commands-5N4ILTPH.js} +13 -0
  8. package/dist/{dist-RVKYUCRU.js → dist-CM3MVWWW.js} +1 -1
  9. package/dist/{dist-Y7I3CFY5.js → dist-POMVY6WP.js} +2 -2
  10. package/dist/{habits-O37HTUKE.js → habits-RG5SVKXP.js} +2 -2
  11. package/dist/index.js +69 -48
  12. package/dist/mcp.js +89 -9
  13. package/dist/peers-RFQCWVLV.js +82 -0
  14. package/dist/{platform-server-KK4OCRTV.js → platform-server-H7Y6Q7O4.js} +10 -1
  15. package/dist/{reindex-NZQRGKPN.js → reindex-WIJMCJ4A.js} +1 -1
  16. package/dist/{sentinel-BKYTBT7M.js → sentinel-UOIGJWHH.js} +1 -1
  17. package/dist/{sentinel-bridge-IZTXYS5M.js → sentinel-bridge-APDXYAZS.js} +1 -1
  18. package/dist/sentinel-mcp.js +13 -0
  19. package/dist/sentinel.js +6 -6
  20. package/dist/{serve-3V2WXLGM.js → serve-KKEHE44G.js} +1 -1
  21. package/dist/{server-OFEJ2HJP.js → server-JV6UFGWZ.js} +1 -1
  22. package/dist/symphony-6K3HD7AW.js +791 -0
  23. package/dist/symphony-YCHBYN3E.js +326 -0
  24. package/dist/symphony-peers-APOGJPF4.js +120 -0
  25. package/dist/symphony-peers-HSY3RI3S.js +34 -0
  26. package/dist/symphony-relay-GTAJRCVF.js +683 -0
  27. package/dist/{triage-POXJ2TIX.js → triage-IZ4MDYNB.js} +2 -2
  28. package/dist/university-content/courses/para-501.json +84 -0
  29. package/package.json +1 -1
  30. package/platform-ui/dist/assets/{GitSection-DvyJBF_-.js → GitSection-BD3Ze06e.js} +1 -1
  31. package/platform-ui/dist/assets/{GraphSection-BiQrXqfs.js → GraphSection-SglITfSs.js} +1 -1
  32. package/platform-ui/dist/assets/{LoreSection-BaH1FaRb.js → LoreSection-bR5Km4Fd.js} +1 -1
  33. package/platform-ui/dist/assets/{SentinelSection-DemAznjI.js → SentinelSection-QSpAZArG.js} +1 -1
  34. package/platform-ui/dist/assets/SymphonySection-CobYJgvg.js +1 -0
  35. package/platform-ui/dist/assets/SymphonySection-zY0C5tFl.css +1 -0
  36. package/platform-ui/dist/assets/{index-DDKhCt-w.js → index-DbxeSMkV.js} +11 -11
  37. package/platform-ui/dist/index.html +1 -1
@@ -0,0 +1,791 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ acknowledgeMessages,
4
+ approveFileRequest,
5
+ buildMessage,
6
+ cleanStaleAgents,
7
+ createFileRequest,
8
+ createThread,
9
+ denyFileRequest,
10
+ discoverClaudeCodeSessions,
11
+ garbageCollect,
12
+ getMyIdentity,
13
+ getThreadMessages,
14
+ isAgentAsleep,
15
+ isPathDenied,
16
+ listAgents,
17
+ listFileRequests,
18
+ listThreads,
19
+ loadThread,
20
+ loadTrustConfig,
21
+ markAgentPollTime,
22
+ readInbox,
23
+ registerAgent,
24
+ resolveAgentIdentity,
25
+ resolveThread,
26
+ routeMessage,
27
+ unregisterAgent
28
+ } from "./chunk-S2HO5MLR.js";
29
+ import "./chunk-ZXMDA7VB.js";
30
+
31
+ // src/commands/symphony/index.ts
32
+ import chalk from "chalk";
33
+ import * as path from "path";
34
+ import * as fs from "fs";
35
+ import * as os from "os";
36
+ async function symphonyJoinCommand(options) {
37
+ const rootDir = process.cwd();
38
+ if (options.remote) {
39
+ await symphonyJoinRemote(rootDir, options.remote);
40
+ return;
41
+ }
42
+ const identity = registerAgent(rootDir);
43
+ console.log(chalk.green(`\u2713 Joined as ${chalk.bold(identity.id)}`));
44
+ const sessions = discoverClaudeCodeSessions();
45
+ const others = sessions.filter((s) => s.id !== identity.id);
46
+ if (others.length > 0) {
47
+ console.log(chalk.cyan(`
48
+ Found ${others.length} other session${others.length !== 1 ? "s" : ""}:`));
49
+ for (const s of others) {
50
+ const status = isAgentAsleep(s) ? chalk.yellow("asleep") : chalk.green("awake");
51
+ console.log(` ${chalk.white(s.id)} \u2014 ${s.name} [${status}]`);
52
+ }
53
+ } else {
54
+ console.log(chalk.gray('\n No other sessions found. Open another terminal and run "paradigm symphony join".'));
55
+ }
56
+ console.log(chalk.gray(`
57
+ Tip: Set up polling with: /loop 10s paradigm_symphony_poll`));
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
+ }
141
+ async function symphonyLeaveCommand() {
142
+ const rootDir = process.cwd();
143
+ const agentId = resolveAgentIdentity(rootDir);
144
+ const success = unregisterAgent(agentId);
145
+ if (success) {
146
+ console.log(chalk.green(`\u2713 Left the score: ${agentId}`));
147
+ } else {
148
+ console.log(chalk.yellow(`No active part found for this project.`));
149
+ }
150
+ }
151
+ async function symphonyWhoamiCommand() {
152
+ const rootDir = process.cwd();
153
+ const identity = getMyIdentity(rootDir);
154
+ if (!identity) {
155
+ console.log(chalk.yellow('Not joined. Run "paradigm symphony join" first.'));
156
+ return;
157
+ }
158
+ const agents = listAgents();
159
+ const others = agents.filter((a) => a.id !== identity.id);
160
+ const threads = listThreads("active");
161
+ const unread = readInbox(identity.id);
162
+ console.log(chalk.cyan(`
163
+ ${chalk.bold(identity.id)}`));
164
+ console.log(chalk.gray(` Project: ${identity.project}`));
165
+ console.log(chalk.gray(` Role: ${identity.role}`));
166
+ console.log(chalk.gray(` PID: ${identity.pid}`));
167
+ console.log(chalk.gray(` Started: ${identity.startedAt}`));
168
+ if (identity.statusBlurb) {
169
+ console.log(chalk.white(` Status: ${identity.statusBlurb}`));
170
+ }
171
+ console.log(`
172
+ ${chalk.white(`${others.length} linked peer${others.length !== 1 ? "s" : ""}`)} \u2014 ${chalk.white(`${threads.length} active thread${threads.length !== 1 ? "s" : ""}`)} \u2014 ${chalk.white(`${unread.length} unread`)}`);
173
+ }
174
+ async function symphonyListCommand(options) {
175
+ cleanStaleAgents();
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;
187
+ if (options.json) {
188
+ console.log(JSON.stringify({
189
+ local: agents,
190
+ remote: remoteAgents
191
+ }, null, 2));
192
+ return;
193
+ }
194
+ if (totalCount === 0) {
195
+ console.log(chalk.yellow('No agents joined. Run "paradigm symphony join" in each terminal.'));
196
+ return;
197
+ }
198
+ console.log(chalk.cyan(`
199
+ Symphony Agents (${totalCount})
200
+ `));
201
+ console.log(chalk.gray(` ${"AGENT ID".padEnd(30)} ${"PROJECT".padEnd(15)} ${"ROLE".padEnd(10)} STATUS`));
202
+ console.log(chalk.gray(` ${"\u2500".repeat(30)} ${"\u2500".repeat(15)} ${"\u2500".repeat(10)} ${"\u2500".repeat(8)}`));
203
+ for (const agent of agents) {
204
+ const status = isAgentAsleep(agent) ? chalk.yellow("asleep") : chalk.green("awake");
205
+ console.log(` ${chalk.white(agent.id.padEnd(30))} ${agent.project.padEnd(15)} ${agent.role.padEnd(10)} ${status}`);
206
+ if (agent.statusBlurb) {
207
+ console.log(` ${chalk.gray(` \u2514 ${agent.statusBlurb}`)}`);
208
+ }
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
+ }
221
+ console.log();
222
+ }
223
+ async function symphonySendCommand(messageText, options) {
224
+ const rootDir = process.cwd();
225
+ let identity = getMyIdentity(rootDir);
226
+ if (!identity) {
227
+ identity = registerAgent(rootDir);
228
+ console.log(chalk.gray(`Auto-joined as ${identity.id}`));
229
+ }
230
+ const sender = {
231
+ id: identity.id,
232
+ name: identity.name,
233
+ type: "human",
234
+ // CLI notes come from the human
235
+ project: identity.project,
236
+ role: identity.role
237
+ };
238
+ let recipients;
239
+ if (options.to) {
240
+ recipients = [{ id: options.to, name: options.to, type: "agent" }];
241
+ }
242
+ let threadRoot = options.thread;
243
+ if (!threadRoot) {
244
+ const topic = messageText.length > 60 ? messageText.slice(0, 60) + "..." : messageText;
245
+ const thread = createThread(topic, sender);
246
+ threadRoot = thread.id;
247
+ }
248
+ const message = buildMessage({
249
+ sender,
250
+ recipients,
251
+ intent: "context",
252
+ text: messageText,
253
+ threadRoot
254
+ });
255
+ const deliveryCount = routeMessage(message);
256
+ console.log(chalk.green(`\u2713 Sent to ${deliveryCount} agent${deliveryCount !== 1 ? "s" : ""}`));
257
+ console.log(chalk.gray(` Thread: ${threadRoot}`));
258
+ console.log(chalk.gray(` Note: ${message.id}`));
259
+ }
260
+ async function symphonyReadCommand() {
261
+ const rootDir = process.cwd();
262
+ const identity = getMyIdentity(rootDir);
263
+ if (!identity) {
264
+ console.log(chalk.yellow('Not joined. Run "paradigm symphony join" first.'));
265
+ return;
266
+ }
267
+ markAgentPollTime(identity.id);
268
+ const messages = readInbox(identity.id);
269
+ if (messages.length === 0) {
270
+ console.log(chalk.gray("\n No unread notes.\n"));
271
+ return;
272
+ }
273
+ const byThread = /* @__PURE__ */ new Map();
274
+ for (const msg of messages) {
275
+ const tid = msg.threadRoot || "direct";
276
+ if (!byThread.has(tid)) byThread.set(tid, []);
277
+ byThread.get(tid).push(msg);
278
+ }
279
+ console.log(chalk.cyan(`
280
+ ${messages.length} unread note${messages.length !== 1 ? "s" : ""}
281
+ `));
282
+ for (const [threadId, msgs] of byThread) {
283
+ let threadLabel = threadId;
284
+ if (threadId !== "direct") {
285
+ const thread = loadThread(threadId);
286
+ if (thread) threadLabel = `${thread.topic} (${threadId})`;
287
+ }
288
+ console.log(chalk.white(` \u250C\u2500 ${threadLabel}`));
289
+ for (let i = 0; i < msgs.length; i++) {
290
+ const msg = msgs[i];
291
+ const isLast = i === msgs.length - 1;
292
+ const prefix = isLast ? " \u2514\u2500" : " \u251C\u2500";
293
+ const time = new Date(msg.timestamp).toLocaleTimeString(void 0, { hour: "numeric", minute: "2-digit" });
294
+ console.log(`${prefix} ${chalk.cyan(msg.sender.name)} ${chalk.gray(`[${msg.intent}]`)} ${chalk.gray(time)}`);
295
+ const textLines = msg.content.text.split("\n");
296
+ const indent = isLast ? " " : " \u2502 ";
297
+ for (const line of textLines) {
298
+ console.log(`${indent}${line}`);
299
+ }
300
+ if (msg.symbols.length > 0) {
301
+ console.log(`${indent}${chalk.gray(`Symbols: ${msg.symbols.join(", ")}`)}`);
302
+ }
303
+ }
304
+ console.log();
305
+ }
306
+ const lastId = messages[messages.length - 1].id;
307
+ acknowledgeMessages(identity.id, lastId);
308
+ garbageCollect(identity.id);
309
+ }
310
+ async function symphonyThreadsCommand(options) {
311
+ const threads = listThreads();
312
+ if (options.json) {
313
+ console.log(JSON.stringify(threads, null, 2));
314
+ return;
315
+ }
316
+ if (threads.length === 0) {
317
+ console.log(chalk.gray("\n No threads.\n"));
318
+ return;
319
+ }
320
+ console.log(chalk.cyan(`
321
+ Threads (${threads.length})
322
+ `));
323
+ console.log(chalk.gray(` ${"ID".padEnd(14)} ${"TOPIC".padEnd(35)} ${"MSGS".padEnd(6)} ${"STATUS".padEnd(10)} LAST ACTIVITY`));
324
+ console.log(chalk.gray(` ${"\u2500".repeat(14)} ${"\u2500".repeat(35)} ${"\u2500".repeat(6)} ${"\u2500".repeat(10)} ${"\u2500".repeat(20)}`));
325
+ for (const thread of threads) {
326
+ const topic = thread.topic.length > 33 ? thread.topic.slice(0, 33) + ".." : thread.topic;
327
+ const status = thread.status === "active" ? chalk.green("active") : chalk.gray("resolved");
328
+ const lastAct = new Date(thread.lastActivity).toLocaleString(void 0, {
329
+ month: "short",
330
+ day: "numeric",
331
+ hour: "numeric",
332
+ minute: "2-digit"
333
+ });
334
+ console.log(` ${chalk.white(thread.id.padEnd(14))} ${topic.padEnd(35)} ${String(thread.messageCount).padEnd(6)} ${status.padEnd(10)} ${chalk.gray(lastAct)}`);
335
+ }
336
+ console.log();
337
+ }
338
+ async function symphonyThreadCommand(threadId) {
339
+ const thread = loadThread(threadId);
340
+ if (!thread) {
341
+ console.log(chalk.red(`Thread not found: ${threadId}`));
342
+ return;
343
+ }
344
+ const messages = getThreadMessages(threadId);
345
+ console.log(chalk.cyan(`
346
+ Thread: ${thread.topic}`));
347
+ console.log(chalk.gray(` ID: ${thread.id} | Status: ${thread.status} | Notes: ${thread.messageCount}`));
348
+ console.log(chalk.gray(` Participants: ${thread.participants.map((p) => p.name).join(", ")}`));
349
+ if (thread.decision) {
350
+ console.log(chalk.green(` Decision: ${thread.decision}`));
351
+ }
352
+ console.log(chalk.gray(`
353
+ ${"\u2500".repeat(60)}
354
+ `));
355
+ for (const msg of messages) {
356
+ const time = new Date(msg.timestamp).toLocaleString(void 0, {
357
+ month: "short",
358
+ day: "numeric",
359
+ hour: "numeric",
360
+ minute: "2-digit"
361
+ });
362
+ console.log(` ${chalk.cyan(msg.sender.name)} ${chalk.gray(`[${msg.intent}]`)} ${chalk.gray(time)}`);
363
+ const textLines = msg.content.text.split("\n");
364
+ for (const line of textLines) {
365
+ console.log(` ${line}`);
366
+ }
367
+ if (msg.symbols.length > 0) {
368
+ console.log(` ${chalk.gray(`Symbols: ${msg.symbols.join(", ")}`)}`);
369
+ }
370
+ if (msg.content.decision) {
371
+ console.log(` ${chalk.green(`Decision: ${msg.content.decision}`)}`);
372
+ }
373
+ console.log();
374
+ }
375
+ }
376
+ async function symphonyResolveCommand(threadId, options) {
377
+ const thread = loadThread(threadId);
378
+ if (!thread) {
379
+ console.log(chalk.red(`Thread not found: ${threadId}`));
380
+ return;
381
+ }
382
+ const success = resolveThread(threadId, options.decision);
383
+ if (success) {
384
+ console.log(chalk.green(`\u2713 Thread resolved: ${thread.topic}`));
385
+ if (options.decision) {
386
+ console.log(chalk.gray(` Decision: ${options.decision}`));
387
+ }
388
+ console.log(chalk.gray(` Tip: Record this as lore with "paradigm lore record --title 'Thread: ${thread.topic}'"`));
389
+ } else {
390
+ console.log(chalk.red("Failed to resolve thread."));
391
+ }
392
+ }
393
+ async function symphonyStatusCommand(options) {
394
+ cleanStaleAgents();
395
+ const rootDir = process.cwd();
396
+ const identity = getMyIdentity(rootDir);
397
+ const agents = listAgents();
398
+ const threads = listThreads("active");
399
+ const pendingRequests = listFileRequests("pending");
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);
404
+ if (options.json) {
405
+ console.log(JSON.stringify({
406
+ identity: identity ? { id: identity.id, project: identity.project, role: identity.role } : null,
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 })),
409
+ activeThreads: threads.length,
410
+ unreadMessages: unread.length,
411
+ pendingFileRequests: pendingRequests.length
412
+ }, null, 2));
413
+ return;
414
+ }
415
+ console.log(chalk.cyan("\n Symphony Status\n"));
416
+ if (identity) {
417
+ console.log(` ${chalk.white("Identity:")} ${identity.id}`);
418
+ } else {
419
+ console.log(` ${chalk.yellow("Not joined.")} Run "paradigm symphony join" to join.`);
420
+ }
421
+ const awake = agents.filter((a) => !isAgentAsleep(a)).length;
422
+ console.log(` ${chalk.white("Agents:")} ${agents.length} joined (${awake} awake)`);
423
+ for (const a of agents) {
424
+ const st = isAgentAsleep(a) ? chalk.yellow("asleep") : chalk.green("awake");
425
+ const blurb = a.statusBlurb ? chalk.gray(` \u2014 ${a.statusBlurb}`) : "";
426
+ console.log(` ${chalk.white(a.id)} [${st}]${blurb}`);
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
+ }
438
+ console.log(` ${chalk.white("Threads:")} ${threads.length} active`);
439
+ console.log(` ${chalk.white("Unread:")} ${unread.length} note${unread.length !== 1 ? "s" : ""}`);
440
+ console.log(` ${chalk.white("File Requests:")} ${pendingRequests.length} pending`);
441
+ console.log();
442
+ }
443
+ async function symphonyServeCommand(options) {
444
+ const port = parseInt(options.port || "3939", 10);
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}`));
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);
509
+ });
510
+ await new Promise(() => {
511
+ });
512
+ } catch (err) {
513
+ console.log(chalk.red(` Failed to start server: ${err.message}`));
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";
527
+ }
528
+ async function symphonyRequestCommand(file, options) {
529
+ const rootDir = process.cwd();
530
+ let identity = getMyIdentity(rootDir);
531
+ if (!identity) {
532
+ identity = registerAgent(rootDir);
533
+ }
534
+ const from = options.from;
535
+ const reason = options.reason || "Needed for current task";
536
+ if (!from) {
537
+ console.log(chalk.red("--from is required. Specify which agent to request from."));
538
+ const agents = listAgents().filter((a) => a.id !== identity.id);
539
+ if (agents.length > 0) {
540
+ console.log(chalk.gray("\nAvailable agents:"));
541
+ for (const a of agents) {
542
+ console.log(chalk.gray(` ${a.id}`));
543
+ }
544
+ }
545
+ return;
546
+ }
547
+ const trust = loadTrustConfig();
548
+ if (isPathDenied(file, trust)) {
549
+ console.log(chalk.red(`\u2717 "${file}" is on the hard-deny list and cannot be requested.`));
550
+ return;
551
+ }
552
+ const record = createFileRequest({
553
+ filePath: file,
554
+ requester: {
555
+ id: identity.id,
556
+ name: identity.name,
557
+ type: "agent",
558
+ project: identity.project,
559
+ role: identity.role
560
+ },
561
+ reason
562
+ });
563
+ const msg = buildMessage({
564
+ sender: {
565
+ id: identity.id,
566
+ name: identity.name,
567
+ type: "agent",
568
+ project: identity.project,
569
+ role: identity.role
570
+ },
571
+ recipients: [{ id: from, name: from, type: "agent" }],
572
+ intent: "fileRequest",
573
+ text: `File request: ${file}
574
+ Reason: ${reason}`,
575
+ symbols: []
576
+ });
577
+ routeMessage(msg);
578
+ console.log(chalk.green(`\u2713 File request created: ${record.request.requestId}`));
579
+ console.log(chalk.gray(` File: ${file}`));
580
+ console.log(chalk.gray(` From: ${from}`));
581
+ console.log(chalk.gray(` Reason: ${reason}`));
582
+ console.log(chalk.gray(`
583
+ The owning agent's human must approve with:`));
584
+ console.log(chalk.white(` paradigm symphony approve ${record.request.requestId}`));
585
+ }
586
+ async function symphonyRequestsCommand() {
587
+ const requests = listFileRequests("pending");
588
+ if (requests.length === 0) {
589
+ console.log(chalk.gray("\n No pending file requests.\n"));
590
+ return;
591
+ }
592
+ console.log(chalk.cyan(`
593
+ Pending File Requests (${requests.length})
594
+ `));
595
+ for (const req of requests) {
596
+ const age = Date.now() - new Date(req.createdAt).getTime();
597
+ const ageMin = Math.round(age / 6e4);
598
+ console.log(` ${chalk.white(req.request.requestId)}`);
599
+ console.log(` File: ${req.request.filePath}`);
600
+ console.log(` From: ${req.request.requester.name} (${req.request.requester.id})`);
601
+ console.log(` Reason: ${req.request.reason}`);
602
+ console.log(chalk.gray(` ${ageMin}m ago`));
603
+ console.log(chalk.gray(` \u2192 paradigm symphony approve ${req.request.requestId}`));
604
+ console.log(chalk.gray(` \u2192 paradigm symphony deny ${req.request.requestId}`));
605
+ console.log();
606
+ }
607
+ }
608
+ async function symphonyApproveCommand(requestId, options) {
609
+ const rootDir = process.cwd();
610
+ const result = approveFileRequest(requestId, rootDir, options.redact);
611
+ if (!result.success) {
612
+ console.log(chalk.red(`\u2717 ${result.error}`));
613
+ return;
614
+ }
615
+ const label = options.redact ? "approved (redacted)" : "approved";
616
+ console.log(chalk.green(`\u2713 File request ${label}`));
617
+ console.log(chalk.gray(` File: ${result.delivery?.filePath}`));
618
+ console.log(chalk.gray(` Size: ${result.delivery?.size} bytes`));
619
+ console.log(chalk.gray(` SHA-256: ${result.delivery?.hash?.slice(0, 16)}...`));
620
+ }
621
+ async function symphonyDenyCommand(requestId, options) {
622
+ const success = denyFileRequest(requestId, options.reason);
623
+ if (success) {
624
+ console.log(chalk.green(`\u2713 File request denied: ${requestId}`));
625
+ if (options.reason) {
626
+ console.log(chalk.gray(` Reason: ${options.reason}`));
627
+ }
628
+ } else {
629
+ console.log(chalk.red(`\u2717 File request not found or already resolved: ${requestId}`));
630
+ }
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
+ }
774
+ export {
775
+ symphonyApproveCommand,
776
+ symphonyDenyCommand,
777
+ symphonyJoinCommand,
778
+ symphonyLeaveCommand,
779
+ symphonyListCommand,
780
+ symphonyReadCommand,
781
+ symphonyRequestCommand,
782
+ symphonyRequestsCommand,
783
+ symphonyResolveCommand,
784
+ symphonySendCommand,
785
+ symphonyServeCommand,
786
+ symphonyStatusCommand,
787
+ symphonyThreadCommand,
788
+ symphonyThreadsCommand,
789
+ symphonyWatchCommand,
790
+ symphonyWhoamiCommand
791
+ };