@a-company/paradigm 3.28.0 → 3.43.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/{accept-orchestration-6EM5EHXA.js → accept-orchestration-ZUWQUHSK.js} +6 -6
- package/dist/add-VSPZ6FM4.js +81 -0
- package/dist/{aggregate-M5WMUI6B.js → aggregate-SV3VGEIL.js} +2 -2
- package/dist/assess-UHBDYIK7.js +68 -0
- package/dist/{beacon-XL2ALH5O.js → beacon-3SJV4DAP.js} +2 -2
- package/dist/calibration-WWHK73WU.js +135 -0
- package/dist/{chunk-C5ZE6WEX.js → chunk-2SKXFXIT.js} +91 -1
- package/dist/{chunk-AK5M6KJB.js → chunk-36TKPM5Z.js} +20 -2
- package/dist/{chunk-W4VFKZVF.js → chunk-7COU5S2Z.js} +3 -3
- package/dist/{chunk-3BAMPB6I.js → chunk-7WEKMZ46.js} +2 -147
- package/dist/{chunk-SCC77UUP.js → chunk-AKIMFN6I.js} +3 -3
- package/dist/{chunk-3DYYXGDC.js → chunk-CDMAMDSG.js} +33 -0
- package/dist/{chunk-7IJ5JVKT.js → chunk-CZEIK3Y2.js} +913 -40
- package/dist/{chunk-MRENOFTR.js → chunk-EDOAWN7J.js} +6 -1
- package/dist/chunk-F3BCHPYT.js +143 -0
- package/dist/chunk-GT5QGC2H.js +253 -0
- package/dist/{chunk-N6RNYCZD.js → chunk-HIKKOCXY.js} +1 -1
- package/dist/{chunk-J26YQVAK.js → chunk-J4E6K5MG.js} +1 -1
- package/dist/chunk-L27I3CPZ.js +357 -0
- package/dist/{chunk-KWDTBXP2.js → chunk-LHLIAYQ3.js} +1 -1
- package/dist/{chunk-OXG5GVDJ.js → chunk-P7XSBJE3.js} +1 -1
- package/dist/{chunk-Z7W7HNRG.js → chunk-QDXI2DHR.js} +1 -1
- package/dist/{chunk-BRILIG7Z.js → chunk-QIOCFXDQ.js} +42 -0
- package/dist/{chunk-ZOH24ZPF.js → chunk-QWA26UNO.js} +7 -7
- package/dist/{lore-server-ILPHKWLK.js → chunk-RAB5IKPR.js} +77 -112
- package/dist/{chunk-BKMNLROM.js → chunk-RGFANZ4Q.js} +448 -147
- package/dist/{chunk-R2SGQ22F.js → chunk-YW5OCVKB.js} +448 -2
- package/dist/{chunk-6P4IFIK2.js → chunk-ZGUAAVMA.js} +53 -4
- package/dist/{commands-6ZVTD74M.js → commands-LEPFD7S5.js} +452 -1
- package/dist/config-schema-3YNIFJCJ.js +152 -0
- package/dist/{constellation-NXU6Q2HM.js → constellation-FAGT45TU.js} +2 -2
- package/dist/{context-audit-RI4R2WRH.js → context-audit-557EO6PK.js} +138 -8
- package/dist/{cost-CTGSLSOC.js → cost-UD3WPEKZ.js} +1 -1
- package/dist/{cursorrules-XBWFX66V.js → cursorrules-3TKZ4E4R.js} +2 -2
- package/dist/{delete-YTASL4SM.js → delete-RRK4RL6Y.js} +1 -1
- package/dist/{diff-AH7L4PRQ.js → diff-IP5CIARP.js} +6 -6
- package/dist/{dist-AG5JNIZU-HW2FWNTZ.js → dist-5QE2BB2B-X6DYVSUL.js} +59 -5
- package/dist/{dist-KY5HGDDL.js → dist-OGTSAZ55.js} +58 -4
- package/dist/{dist-IKBGY7FQ.js → dist-RVKYUCRU.js} +3 -1
- package/dist/{dist-7U64HDSC.js → dist-UXWV4OKX.js} +8 -2
- package/dist/{dist-RMAIFRTW.js → dist-Y7I3CFY5.js} +5 -3
- package/dist/{doctor-INBOLZC7.js → doctor-GKZJU7QG.js} +1 -1
- package/dist/{edit-S7NZD7H7.js → edit-4CLNN5JG.js} +1 -1
- package/dist/{graph-ERNQQQ7C.js → graph-YYUXI3F7.js} +1 -1
- package/dist/graph-server-ZPXRSGCW.js +116 -0
- package/dist/{habits-7BORPC2F.js → habits-O37HTUKE.js} +2 -2
- package/dist/index.js +207 -89
- package/dist/integrity-MK2OP5TA.js +194 -0
- package/dist/integrity-checker-J7YXRTBT.js +11 -0
- package/dist/{lint-53GPXKKI.js → lint-HYWGS3JJ.js} +1 -1
- package/dist/{list-QTFWN35D.js → list-BTLFHSRC.js} +1 -1
- package/dist/list-IUCYPGMK.js +57 -0
- package/dist/{lore-loader-S5BXMH27.js → lore-loader-VTEEZDX3.js} +3 -1
- package/dist/lore-server-NOOAHKJX.js +118 -0
- package/dist/mcp.js +2616 -112
- package/dist/migrate-FQVGQNXZ.js +889 -0
- package/dist/{migrate-assessments-FPR6C35Z.js → migrate-assessments-JP6Q5KME.js} +1 -1
- package/dist/{orchestrate-HMSQ2CED.js → orchestrate-A226N6FC.js} +6 -6
- package/dist/platform-server-KK4OCRTV.js +891 -0
- package/dist/{probe-SN4BNXOC.js → probe-7JK7IDNI.js} +5 -5
- package/dist/{providers-YW3FG6DA.js → providers-YNFSL6HK.js} +1 -1
- package/dist/quiz-I75NU2QQ.js +99 -0
- package/dist/{record-UGN75GTB.js → record-46CLR4OG.js} +11 -2
- package/dist/{reindex-YG3KIXAK.js → reindex-NZQRGKPN.js} +3 -2
- package/dist/{remember-IEBQHXHZ.js → remember-4EUZKIIB.js} +1 -1
- package/dist/{retag-URLJLMSK.js → retag-KC4JVRLE.js} +1 -1
- package/dist/{review-725ZKA7U.js → review-Q7M4CRB5.js} +1 -1
- package/dist/{ripple-DFMXLFWI.js → ripple-RI3LOT6R.js} +2 -2
- package/dist/{sentinel-FUR3QKCJ.js → sentinel-BKYTBT7M.js} +1 -1
- package/dist/sentinel-bridge-IZTXYS5M.js +109 -0
- package/dist/sentinel-ui/assets/{index-Zh1YM0C9.css → index-CJ1Wx083.css} +1 -1
- package/dist/sentinel-ui/assets/index-S1VJ67dT.js +62 -0
- package/dist/sentinel-ui/assets/index-S1VJ67dT.js.map +1 -0
- package/dist/sentinel-ui/index.html +2 -2
- package/dist/sentinel.js +6 -6
- package/dist/{serve-DIALBCTU.js → serve-22A4XOIG.js} +1 -1
- package/dist/{university-A66BMZ4Z.js → serve-2YJ6D2Y6.js} +9 -8
- package/dist/serve-3V2WXLGM.js +33 -0
- package/dist/{server-2VICPDUR.js → server-OFEJ2HJP.js} +25 -2
- package/dist/{server-OWBK2WFS.js → server-RDLQ3DK7.js} +49 -4
- package/dist/{setup-HOI52TN3.js → setup-M2ZKLKNN.js} +4 -4
- package/dist/{shift-DRF5M3G6.js → shift-LNMKFYLR.js} +73 -14
- package/dist/{show-GEVVQWWG.js → show-P7GYO43X.js} +1 -1
- package/dist/show-PKZMYKRN.js +82 -0
- package/dist/{snapshot-XHINQBZS.js → snapshot-Y3COXK4T.js} +2 -2
- package/dist/{spawn-DIY7T4QW.js → spawn-SSXZX45U.js} +2 -2
- package/dist/status-KLHALGW4.js +71 -0
- package/dist/{summary-NV7SBV5O.js → summary-5NQNOD3F.js} +2 -2
- package/dist/{sweep-5POCF2E4.js → sweep-EZU3GU6S.js} +1 -1
- package/dist/symphony-ROEKK7VD.js +999 -0
- package/dist/{team-YOGT2Q2X.js → team-HGLJXWQG.js} +7 -7
- package/dist/{timeline-RKXNRMKF.js → timeline-ANC7LVDL.js} +1 -1
- package/dist/{triage-GJ6GK647.js → triage-POXJ2TIX.js} +2 -2
- package/dist/university-content/courses/.purpose +7 -1
- package/dist/university-content/courses/para-101.json +53 -0
- package/dist/university-content/courses/para-501.json +166 -0
- package/dist/university-content/plsat/.purpose +6 -0
- package/dist/university-content/plsat/v3.0.json +400 -1
- package/dist/university-content/reference.json +48 -0
- package/dist/university-ui/assets/{index-TcsCEBMo.js → index-tfi5xN4Q.js} +2 -2
- package/dist/university-ui/assets/{index-TcsCEBMo.js.map → index-tfi5xN4Q.js.map} +1 -1
- package/dist/university-ui/index.html +1 -1
- package/dist/{upgrade-65QOQXRC.js → upgrade-ANX3LVSA.js} +1 -0
- package/dist/validate-GD5XWILV.js +134 -0
- package/dist/{validate-TKKRGJKC.js → validate-ZVPNN4FL.js} +1 -1
- package/dist/{workspace-L27RR5MF.js → workspace-UIUTHZTD.js} +6 -6
- package/package.json +4 -2
- package/platform-ui/dist/assets/GitSection-C-GQWHcu.css +1 -0
- package/platform-ui/dist/assets/GitSection-DvyJBF_-.js +4 -0
- package/platform-ui/dist/assets/GraphSection-BiQrXqfs.js +8 -0
- package/platform-ui/dist/assets/GraphSection-BlgXTl53.css +1 -0
- package/platform-ui/dist/assets/LoreSection-BaH1FaRb.js +1 -0
- package/platform-ui/dist/assets/LoreSection-C3EixkjW.css +1 -0
- package/platform-ui/dist/assets/SentinelSection-BI-aIYKL.css +1 -0
- package/platform-ui/dist/assets/SentinelSection-DemAznjI.js +1 -0
- package/platform-ui/dist/assets/index-CfpZFjea.css +1 -0
- package/platform-ui/dist/assets/index-DDKhCt-w.js +57 -0
- package/platform-ui/dist/index.html +14 -0
- package/dist/graph-server-BZ73HTAT.js +0 -251
- package/dist/sentinel-ui/assets/index-C_Wstm64.js +0 -62
- package/dist/sentinel-ui/assets/index-C_Wstm64.js.map +0 -1
- /package/dist/{chunk-5SXMV4SP.js → chunk-FS3WTUHY.js} +0 -0
|
@@ -0,0 +1,999 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "./chunk-ZXMDA7VB.js";
|
|
3
|
+
|
|
4
|
+
// src/commands/symphony/index.ts
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
import * as net from "net";
|
|
7
|
+
|
|
8
|
+
// ../paradigm-mcp/src/utils/symphony-loader.ts
|
|
9
|
+
import * as fs from "fs";
|
|
10
|
+
import * as path from "path";
|
|
11
|
+
import * as os from "os";
|
|
12
|
+
import * as crypto from "crypto";
|
|
13
|
+
var SCORE_DIR = path.join(os.homedir(), ".paradigm", "score");
|
|
14
|
+
var LEGACY_MAIL_DIR = path.join(os.homedir(), ".paradigm", "mail");
|
|
15
|
+
var AGENTS_DIR = path.join(SCORE_DIR, "agents");
|
|
16
|
+
var THREADS_DIR = path.join(SCORE_DIR, "threads");
|
|
17
|
+
var FILE_REQUESTS_DIR = path.join(SCORE_DIR, "file-requests");
|
|
18
|
+
var TRUST_CONFIG_PATH = path.join(SCORE_DIR, "trust.yaml");
|
|
19
|
+
var FILE_REQUEST_TTL_MS = 60 * 60 * 1e3;
|
|
20
|
+
var DEFAULT_TRUST = {
|
|
21
|
+
users: {},
|
|
22
|
+
defaults: {
|
|
23
|
+
level: "restricted",
|
|
24
|
+
autoApprove: [],
|
|
25
|
+
neverApprove: [
|
|
26
|
+
".env*",
|
|
27
|
+
"**/*.key",
|
|
28
|
+
"**/*.pem",
|
|
29
|
+
"**/credentials*",
|
|
30
|
+
"**/secrets/**"
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
function migrateFromLegacyMail() {
|
|
35
|
+
if (fs.existsSync(LEGACY_MAIL_DIR) && !fs.existsSync(SCORE_DIR)) {
|
|
36
|
+
try {
|
|
37
|
+
fs.renameSync(LEGACY_MAIL_DIR, SCORE_DIR);
|
|
38
|
+
} catch {
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function ensureScoreDirs() {
|
|
43
|
+
migrateFromLegacyMail();
|
|
44
|
+
for (const dir of [AGENTS_DIR, THREADS_DIR, FILE_REQUESTS_DIR]) {
|
|
45
|
+
if (!fs.existsSync(dir)) {
|
|
46
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function getAgentDir(agentId) {
|
|
51
|
+
return path.join(AGENTS_DIR, agentId);
|
|
52
|
+
}
|
|
53
|
+
function ensureAgentDir(agentId) {
|
|
54
|
+
const dir = getAgentDir(agentId);
|
|
55
|
+
if (!fs.existsSync(dir)) {
|
|
56
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
57
|
+
}
|
|
58
|
+
return dir;
|
|
59
|
+
}
|
|
60
|
+
function readJsonlFile(filePath) {
|
|
61
|
+
if (!fs.existsSync(filePath)) return [];
|
|
62
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
63
|
+
const lines = content.split("\n").filter((line) => line.trim().length > 0);
|
|
64
|
+
const items = [];
|
|
65
|
+
for (const line of lines) {
|
|
66
|
+
try {
|
|
67
|
+
items.push(JSON.parse(line));
|
|
68
|
+
} catch {
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return items;
|
|
72
|
+
}
|
|
73
|
+
function appendJsonlLine(filePath, item) {
|
|
74
|
+
const dir = path.dirname(filePath);
|
|
75
|
+
if (!fs.existsSync(dir)) {
|
|
76
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
77
|
+
}
|
|
78
|
+
fs.appendFileSync(filePath, JSON.stringify(item) + "\n", "utf-8");
|
|
79
|
+
}
|
|
80
|
+
function sanitizeId(name) {
|
|
81
|
+
return name.toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "").slice(0, 40) || "unknown";
|
|
82
|
+
}
|
|
83
|
+
function resolveProjectName(projectDir) {
|
|
84
|
+
try {
|
|
85
|
+
const configPath = path.join(projectDir, ".paradigm", "config.yaml");
|
|
86
|
+
if (fs.existsSync(configPath)) {
|
|
87
|
+
const content = fs.readFileSync(configPath, "utf-8");
|
|
88
|
+
const match = content.match(/^project:\s*(.+)$/m);
|
|
89
|
+
if (match) return sanitizeId(match[1].trim().replace(/["']/g, ""));
|
|
90
|
+
}
|
|
91
|
+
} catch {
|
|
92
|
+
}
|
|
93
|
+
return sanitizeId(path.basename(projectDir));
|
|
94
|
+
}
|
|
95
|
+
function resolveAgentIdentity(projectDir, role) {
|
|
96
|
+
const project = resolveProjectName(projectDir);
|
|
97
|
+
const agentRole = role || "core";
|
|
98
|
+
return `${project}/${agentRole}`;
|
|
99
|
+
}
|
|
100
|
+
function registerAgent(projectDir, role, label) {
|
|
101
|
+
ensureScoreDirs();
|
|
102
|
+
const agentId = resolveAgentIdentity(projectDir, role);
|
|
103
|
+
const agentDir = ensureAgentDir(agentId);
|
|
104
|
+
const project = resolveProjectName(projectDir);
|
|
105
|
+
const identity = {
|
|
106
|
+
id: agentId,
|
|
107
|
+
name: label || `${project} (${role || "core"})`,
|
|
108
|
+
type: "agent",
|
|
109
|
+
project,
|
|
110
|
+
role: role || "core",
|
|
111
|
+
pid: process.pid,
|
|
112
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
113
|
+
label
|
|
114
|
+
};
|
|
115
|
+
fs.writeFileSync(
|
|
116
|
+
path.join(agentDir, "identity.json"),
|
|
117
|
+
JSON.stringify(identity, null, 2),
|
|
118
|
+
"utf-8"
|
|
119
|
+
);
|
|
120
|
+
return identity;
|
|
121
|
+
}
|
|
122
|
+
function unregisterAgent(agentId) {
|
|
123
|
+
const agentDir = getAgentDir(agentId);
|
|
124
|
+
if (!fs.existsSync(agentDir)) return false;
|
|
125
|
+
try {
|
|
126
|
+
fs.rmSync(agentDir, { recursive: true, force: true });
|
|
127
|
+
return true;
|
|
128
|
+
} catch {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function listAgents() {
|
|
133
|
+
ensureScoreDirs();
|
|
134
|
+
if (!fs.existsSync(AGENTS_DIR)) return [];
|
|
135
|
+
const agents = [];
|
|
136
|
+
const projectDirs = fs.readdirSync(AGENTS_DIR, { withFileTypes: true }).filter((d) => d.isDirectory());
|
|
137
|
+
for (const projectDir of projectDirs) {
|
|
138
|
+
const projectPath = path.join(AGENTS_DIR, projectDir.name);
|
|
139
|
+
const roleDirs = fs.readdirSync(projectPath, { withFileTypes: true }).filter((d) => d.isDirectory());
|
|
140
|
+
for (const roleDir of roleDirs) {
|
|
141
|
+
const identityPath = path.join(projectPath, roleDir.name, "identity.json");
|
|
142
|
+
if (!fs.existsSync(identityPath)) continue;
|
|
143
|
+
try {
|
|
144
|
+
const content = fs.readFileSync(identityPath, "utf-8");
|
|
145
|
+
const identity = JSON.parse(content);
|
|
146
|
+
agents.push(identity);
|
|
147
|
+
} catch {
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return agents;
|
|
152
|
+
}
|
|
153
|
+
function cleanStaleAgents() {
|
|
154
|
+
const agents = listAgents();
|
|
155
|
+
let cleaned = 0;
|
|
156
|
+
for (const agent of agents) {
|
|
157
|
+
if (!isProcessAlive(agent.pid)) {
|
|
158
|
+
unregisterAgent(agent.id);
|
|
159
|
+
cleaned++;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return cleaned;
|
|
163
|
+
}
|
|
164
|
+
function getMyIdentity(projectDir) {
|
|
165
|
+
const agentId = resolveAgentIdentity(projectDir);
|
|
166
|
+
const identityPath = path.join(getAgentDir(agentId), "identity.json");
|
|
167
|
+
if (!fs.existsSync(identityPath)) return null;
|
|
168
|
+
try {
|
|
169
|
+
return JSON.parse(fs.readFileSync(identityPath, "utf-8"));
|
|
170
|
+
} catch {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function markAgentPollTime(agentId) {
|
|
175
|
+
const identityPath = path.join(getAgentDir(agentId), "identity.json");
|
|
176
|
+
if (!fs.existsSync(identityPath)) return;
|
|
177
|
+
try {
|
|
178
|
+
const identity = JSON.parse(fs.readFileSync(identityPath, "utf-8"));
|
|
179
|
+
identity.lastPoll = (/* @__PURE__ */ new Date()).toISOString();
|
|
180
|
+
fs.writeFileSync(identityPath, JSON.stringify(identity, null, 2), "utf-8");
|
|
181
|
+
} catch {
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function isAgentAsleep(identity, thresholdMs = 6e4) {
|
|
185
|
+
if (!identity.lastPoll) return true;
|
|
186
|
+
const lastPoll = new Date(identity.lastPoll).getTime();
|
|
187
|
+
return Date.now() - lastPoll > thresholdMs;
|
|
188
|
+
}
|
|
189
|
+
function discoverClaudeCodeSessions() {
|
|
190
|
+
const agents = listAgents();
|
|
191
|
+
const alive = agents.filter((a) => isProcessAlive(a.pid));
|
|
192
|
+
try {
|
|
193
|
+
const conductorSessionsDir = path.join(os.homedir(), ".conductor", "sessions");
|
|
194
|
+
if (fs.existsSync(conductorSessionsDir)) {
|
|
195
|
+
const files = fs.readdirSync(conductorSessionsDir).filter((f) => f.endsWith(".json"));
|
|
196
|
+
for (const file of files) {
|
|
197
|
+
try {
|
|
198
|
+
const content = fs.readFileSync(path.join(conductorSessionsDir, file), "utf-8");
|
|
199
|
+
const session = JSON.parse(content);
|
|
200
|
+
const pid = parseInt(path.basename(file, ".json"), 10);
|
|
201
|
+
if (!alive.some((a) => a.pid === pid) && isProcessAlive(pid)) {
|
|
202
|
+
alive.push({
|
|
203
|
+
id: `conductor/${pid}`,
|
|
204
|
+
name: session.label || `Session ${pid}`,
|
|
205
|
+
type: "agent",
|
|
206
|
+
project: session.projectDir ? path.basename(session.projectDir) : "unknown",
|
|
207
|
+
role: "conductor",
|
|
208
|
+
pid,
|
|
209
|
+
startedAt: session.registeredAt || (/* @__PURE__ */ new Date()).toISOString()
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
} catch {
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
} catch {
|
|
217
|
+
}
|
|
218
|
+
return alive;
|
|
219
|
+
}
|
|
220
|
+
function inboxPath(agentId) {
|
|
221
|
+
return path.join(getAgentDir(agentId), "inbox.jsonl");
|
|
222
|
+
}
|
|
223
|
+
function outboxPath(agentId) {
|
|
224
|
+
return path.join(getAgentDir(agentId), "outbox.jsonl");
|
|
225
|
+
}
|
|
226
|
+
function ackPath(agentId) {
|
|
227
|
+
return path.join(getAgentDir(agentId), "ack.json");
|
|
228
|
+
}
|
|
229
|
+
function appendToInbox(agentId, message) {
|
|
230
|
+
ensureAgentDir(agentId);
|
|
231
|
+
appendJsonlLine(inboxPath(agentId), message);
|
|
232
|
+
}
|
|
233
|
+
function readInbox(agentId, afterAck) {
|
|
234
|
+
const messages = readJsonlFile(inboxPath(agentId));
|
|
235
|
+
if (!afterAck) {
|
|
236
|
+
const ack = readAck(agentId);
|
|
237
|
+
if (ack) {
|
|
238
|
+
const ackIndex2 = messages.findIndex((m) => m.id === ack);
|
|
239
|
+
if (ackIndex2 >= 0) return messages.slice(ackIndex2 + 1);
|
|
240
|
+
}
|
|
241
|
+
return messages;
|
|
242
|
+
}
|
|
243
|
+
const ackIndex = messages.findIndex((m) => m.id === afterAck);
|
|
244
|
+
if (ackIndex >= 0) return messages.slice(ackIndex + 1);
|
|
245
|
+
return messages;
|
|
246
|
+
}
|
|
247
|
+
function appendToOutbox(agentId, message) {
|
|
248
|
+
ensureAgentDir(agentId);
|
|
249
|
+
appendJsonlLine(outboxPath(agentId), message);
|
|
250
|
+
}
|
|
251
|
+
function acknowledgeMessages(agentId, lastMessageId) {
|
|
252
|
+
const filePath = ackPath(agentId);
|
|
253
|
+
ensureAgentDir(agentId);
|
|
254
|
+
fs.writeFileSync(filePath, JSON.stringify({ lastAck: lastMessageId }), "utf-8");
|
|
255
|
+
}
|
|
256
|
+
function readAck(agentId) {
|
|
257
|
+
const filePath = ackPath(agentId);
|
|
258
|
+
if (!fs.existsSync(filePath)) return null;
|
|
259
|
+
try {
|
|
260
|
+
const content = JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
261
|
+
return content.lastAck || null;
|
|
262
|
+
} catch {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
function garbageCollect(agentId) {
|
|
267
|
+
const ack = readAck(agentId);
|
|
268
|
+
if (!ack) return 0;
|
|
269
|
+
const filePath = inboxPath(agentId);
|
|
270
|
+
const messages = readJsonlFile(filePath);
|
|
271
|
+
const ackIndex = messages.findIndex((m) => m.id === ack);
|
|
272
|
+
if (ackIndex < 0) return 0;
|
|
273
|
+
const kept = messages.slice(ackIndex + 1);
|
|
274
|
+
const removed = messages.length - kept.length;
|
|
275
|
+
if (kept.length === 0) {
|
|
276
|
+
if (fs.existsSync(filePath)) fs.writeFileSync(filePath, "", "utf-8");
|
|
277
|
+
} else {
|
|
278
|
+
fs.writeFileSync(filePath, kept.map((m) => JSON.stringify(m)).join("\n") + "\n", "utf-8");
|
|
279
|
+
}
|
|
280
|
+
return removed;
|
|
281
|
+
}
|
|
282
|
+
function threadPath(threadId) {
|
|
283
|
+
return path.join(THREADS_DIR, `${threadId}.json`);
|
|
284
|
+
}
|
|
285
|
+
function createThread(topic, initiator) {
|
|
286
|
+
ensureScoreDirs();
|
|
287
|
+
const id = "thr-" + crypto.randomBytes(4).toString("hex");
|
|
288
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
289
|
+
const thread = {
|
|
290
|
+
id,
|
|
291
|
+
topic,
|
|
292
|
+
initiator,
|
|
293
|
+
participants: [initiator],
|
|
294
|
+
status: "active",
|
|
295
|
+
createdAt: now,
|
|
296
|
+
lastActivity: now,
|
|
297
|
+
messageCount: 0
|
|
298
|
+
};
|
|
299
|
+
fs.writeFileSync(threadPath(id), JSON.stringify(thread, null, 2), "utf-8");
|
|
300
|
+
return thread;
|
|
301
|
+
}
|
|
302
|
+
function loadThread(threadId) {
|
|
303
|
+
const filePath = threadPath(threadId);
|
|
304
|
+
if (!fs.existsSync(filePath)) return null;
|
|
305
|
+
try {
|
|
306
|
+
return JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
307
|
+
} catch {
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
function listThreads(status) {
|
|
312
|
+
ensureScoreDirs();
|
|
313
|
+
if (!fs.existsSync(THREADS_DIR)) return [];
|
|
314
|
+
const files = fs.readdirSync(THREADS_DIR).filter((f) => f.endsWith(".json"));
|
|
315
|
+
const threads = [];
|
|
316
|
+
for (const file of files) {
|
|
317
|
+
try {
|
|
318
|
+
const content = fs.readFileSync(path.join(THREADS_DIR, file), "utf-8");
|
|
319
|
+
const thread = JSON.parse(content);
|
|
320
|
+
if (!status || thread.status === status) {
|
|
321
|
+
threads.push(thread);
|
|
322
|
+
}
|
|
323
|
+
} catch {
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return threads.sort((a, b) => b.lastActivity.localeCompare(a.lastActivity));
|
|
327
|
+
}
|
|
328
|
+
function updateThread(threadId, partial) {
|
|
329
|
+
const thread = loadThread(threadId);
|
|
330
|
+
if (!thread) return false;
|
|
331
|
+
const updated = { ...thread, ...partial };
|
|
332
|
+
fs.writeFileSync(threadPath(threadId), JSON.stringify(updated, null, 2), "utf-8");
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
function resolveThread(threadId, decision) {
|
|
336
|
+
return updateThread(threadId, {
|
|
337
|
+
status: "resolved",
|
|
338
|
+
resolvedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
339
|
+
decision
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
function getThreadMessages(threadId) {
|
|
343
|
+
const agents = listAgents();
|
|
344
|
+
const messages = [];
|
|
345
|
+
for (const agent of agents) {
|
|
346
|
+
const inbox = readJsonlFile(inboxPath(agent.id));
|
|
347
|
+
const outbox = readJsonlFile(outboxPath(agent.id));
|
|
348
|
+
for (const msg of [...inbox, ...outbox]) {
|
|
349
|
+
if (msg.threadRoot === threadId || msg.id === threadId) {
|
|
350
|
+
if (!messages.some((m) => m.id === msg.id)) {
|
|
351
|
+
messages.push(msg);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return messages.sort((a, b) => a.timestamp.localeCompare(b.timestamp));
|
|
357
|
+
}
|
|
358
|
+
function buildMessage(params) {
|
|
359
|
+
return {
|
|
360
|
+
id: crypto.randomUUID(),
|
|
361
|
+
parentId: params.parentId,
|
|
362
|
+
threadRoot: params.threadRoot,
|
|
363
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
364
|
+
sender: params.sender,
|
|
365
|
+
recipients: params.recipients,
|
|
366
|
+
intent: params.intent,
|
|
367
|
+
content: {
|
|
368
|
+
text: params.text,
|
|
369
|
+
diff: params.diff,
|
|
370
|
+
decision: params.decision
|
|
371
|
+
},
|
|
372
|
+
symbols: params.symbols || [],
|
|
373
|
+
attachments: params.attachments,
|
|
374
|
+
metadata: params.metadata
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
function routeMessage(message) {
|
|
378
|
+
ensureScoreDirs();
|
|
379
|
+
appendToOutbox(message.sender.id, message);
|
|
380
|
+
let deliveryCount = 0;
|
|
381
|
+
if (message.recipients && message.recipients.length > 0) {
|
|
382
|
+
for (const recipient of message.recipients) {
|
|
383
|
+
appendToInbox(recipient.id, message);
|
|
384
|
+
deliveryCount++;
|
|
385
|
+
}
|
|
386
|
+
} else {
|
|
387
|
+
const agents = listAgents();
|
|
388
|
+
for (const agent of agents) {
|
|
389
|
+
if (agent.id !== message.sender.id) {
|
|
390
|
+
appendToInbox(agent.id, message);
|
|
391
|
+
deliveryCount++;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
if (message.threadRoot) {
|
|
396
|
+
const thread = loadThread(message.threadRoot);
|
|
397
|
+
if (thread) {
|
|
398
|
+
const isParticipant = thread.participants.some((p) => p.id === message.sender.id);
|
|
399
|
+
const updatedParticipants = isParticipant ? thread.participants : [...thread.participants, message.sender];
|
|
400
|
+
updateThread(message.threadRoot, {
|
|
401
|
+
participants: updatedParticipants,
|
|
402
|
+
lastActivity: message.timestamp,
|
|
403
|
+
messageCount: thread.messageCount + 1
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return deliveryCount;
|
|
408
|
+
}
|
|
409
|
+
function fileRequestPath(requestId) {
|
|
410
|
+
return path.join(FILE_REQUESTS_DIR, `${requestId}.json`);
|
|
411
|
+
}
|
|
412
|
+
function loadTrustConfig() {
|
|
413
|
+
if (!fs.existsSync(TRUST_CONFIG_PATH)) return DEFAULT_TRUST;
|
|
414
|
+
try {
|
|
415
|
+
const content = fs.readFileSync(TRUST_CONFIG_PATH, "utf-8");
|
|
416
|
+
try {
|
|
417
|
+
return JSON.parse(content);
|
|
418
|
+
} catch {
|
|
419
|
+
return DEFAULT_TRUST;
|
|
420
|
+
}
|
|
421
|
+
} catch {
|
|
422
|
+
return DEFAULT_TRUST;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
function createFileRequest(params) {
|
|
426
|
+
ensureScoreDirs();
|
|
427
|
+
const requestId = "freq-" + crypto.randomBytes(4).toString("hex");
|
|
428
|
+
const record = {
|
|
429
|
+
request: {
|
|
430
|
+
requestId,
|
|
431
|
+
filePath: params.filePath,
|
|
432
|
+
reason: params.reason,
|
|
433
|
+
requester: params.requester,
|
|
434
|
+
urgency: params.urgency || "normal",
|
|
435
|
+
snippet: params.snippet,
|
|
436
|
+
threadRoot: params.threadRoot
|
|
437
|
+
},
|
|
438
|
+
status: "pending",
|
|
439
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
440
|
+
};
|
|
441
|
+
fs.writeFileSync(fileRequestPath(requestId), JSON.stringify(record, null, 2), "utf-8");
|
|
442
|
+
return record;
|
|
443
|
+
}
|
|
444
|
+
function loadFileRequest(requestId) {
|
|
445
|
+
const filePath = fileRequestPath(requestId);
|
|
446
|
+
if (!fs.existsSync(filePath)) return null;
|
|
447
|
+
try {
|
|
448
|
+
return JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
449
|
+
} catch {
|
|
450
|
+
return null;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
function listFileRequests(status) {
|
|
454
|
+
ensureScoreDirs();
|
|
455
|
+
if (!fs.existsSync(FILE_REQUESTS_DIR)) return [];
|
|
456
|
+
const files = fs.readdirSync(FILE_REQUESTS_DIR).filter((f) => f.endsWith(".json"));
|
|
457
|
+
const requests = [];
|
|
458
|
+
for (const file of files) {
|
|
459
|
+
try {
|
|
460
|
+
const content = fs.readFileSync(path.join(FILE_REQUESTS_DIR, file), "utf-8");
|
|
461
|
+
const record = JSON.parse(content);
|
|
462
|
+
if (!status || record.status === status) {
|
|
463
|
+
requests.push(record);
|
|
464
|
+
}
|
|
465
|
+
} catch {
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return requests.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
|
|
469
|
+
}
|
|
470
|
+
function approveFileRequest(requestId, projectDir, redact) {
|
|
471
|
+
const record = loadFileRequest(requestId);
|
|
472
|
+
if (!record) return { success: false, error: `File request not found: ${requestId}` };
|
|
473
|
+
if (record.status !== "pending") return { success: false, error: `Request already ${record.status}` };
|
|
474
|
+
const absolutePath = path.resolve(projectDir, record.request.filePath);
|
|
475
|
+
if (!absolutePath.startsWith(path.resolve(projectDir))) {
|
|
476
|
+
return { success: false, error: "File path escapes project directory" };
|
|
477
|
+
}
|
|
478
|
+
if (!fs.existsSync(absolutePath)) {
|
|
479
|
+
return { success: false, error: `File not found: ${record.request.filePath}` };
|
|
480
|
+
}
|
|
481
|
+
try {
|
|
482
|
+
let content = fs.readFileSync(absolutePath, "utf-8");
|
|
483
|
+
let encoding = "utf8";
|
|
484
|
+
if (redact) {
|
|
485
|
+
const secretPatterns = [
|
|
486
|
+
/(?:api[_-]?key|secret|token|password|credential|auth)\s*[:=]/i,
|
|
487
|
+
/(?:^|\s)(?:export\s+)?[A-Z_]+(?:KEY|SECRET|TOKEN|PASSWORD|CREDENTIAL)\s*=/,
|
|
488
|
+
/-----BEGIN (?:RSA |EC )?PRIVATE KEY-----/
|
|
489
|
+
];
|
|
490
|
+
content = content.split("\n").map((line) => {
|
|
491
|
+
for (const pattern of secretPatterns) {
|
|
492
|
+
if (pattern.test(line)) return "[REDACTED]";
|
|
493
|
+
}
|
|
494
|
+
return line;
|
|
495
|
+
}).join("\n");
|
|
496
|
+
}
|
|
497
|
+
const hash = crypto.createHash("sha256").update(content).digest("hex");
|
|
498
|
+
const delivery = {
|
|
499
|
+
requestId,
|
|
500
|
+
filePath: record.request.filePath,
|
|
501
|
+
content,
|
|
502
|
+
encoding,
|
|
503
|
+
size: Buffer.byteLength(content),
|
|
504
|
+
hash
|
|
505
|
+
};
|
|
506
|
+
record.status = "approved";
|
|
507
|
+
record.resolvedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
508
|
+
record.delivery = delivery;
|
|
509
|
+
fs.writeFileSync(fileRequestPath(requestId), JSON.stringify(record, null, 2), "utf-8");
|
|
510
|
+
const deliveryMessage = buildMessage({
|
|
511
|
+
sender: { id: "system", name: "File Transfer", type: "human" },
|
|
512
|
+
recipients: [record.request.requester],
|
|
513
|
+
intent: "fileDelivery",
|
|
514
|
+
text: `File delivered: ${record.request.filePath} (${delivery.size} bytes, SHA-256: ${hash.slice(0, 12)}...)`,
|
|
515
|
+
threadRoot: record.request.threadRoot,
|
|
516
|
+
symbols: []
|
|
517
|
+
});
|
|
518
|
+
deliveryMessage.attachments = [{
|
|
519
|
+
name: path.basename(record.request.filePath),
|
|
520
|
+
type: "file",
|
|
521
|
+
content: delivery.content,
|
|
522
|
+
encoding: delivery.encoding
|
|
523
|
+
}];
|
|
524
|
+
routeMessage(deliveryMessage);
|
|
525
|
+
return { success: true, delivery };
|
|
526
|
+
} catch (err) {
|
|
527
|
+
return { success: false, error: `Failed to read file: ${err.message}` };
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
function denyFileRequest(requestId, reason) {
|
|
531
|
+
const record = loadFileRequest(requestId);
|
|
532
|
+
if (!record || record.status !== "pending") return false;
|
|
533
|
+
record.status = "denied";
|
|
534
|
+
record.resolvedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
535
|
+
record.denyReason = reason;
|
|
536
|
+
fs.writeFileSync(fileRequestPath(requestId), JSON.stringify(record, null, 2), "utf-8");
|
|
537
|
+
const denialMessage = buildMessage({
|
|
538
|
+
sender: { id: "system", name: "File Transfer", type: "human" },
|
|
539
|
+
recipients: [record.request.requester],
|
|
540
|
+
intent: "fileDenied",
|
|
541
|
+
text: `File request denied: ${record.request.filePath}${reason ? ` \u2014 ${reason}` : ""}`,
|
|
542
|
+
threadRoot: record.request.threadRoot,
|
|
543
|
+
symbols: []
|
|
544
|
+
});
|
|
545
|
+
routeMessage(denialMessage);
|
|
546
|
+
return true;
|
|
547
|
+
}
|
|
548
|
+
function matchesGlob(filePath, pattern) {
|
|
549
|
+
let regex = pattern.replace(/\./g, "\\.").replace(/\*\*/g, "{{GLOBSTAR}}").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]").replace(/\{\{GLOBSTAR\}\}/g, ".*");
|
|
550
|
+
return new RegExp(`^${regex}$`).test(filePath);
|
|
551
|
+
}
|
|
552
|
+
function isPathDenied(filePath, config, user) {
|
|
553
|
+
const trust = config || loadTrustConfig();
|
|
554
|
+
if (user && trust.users[user]) {
|
|
555
|
+
for (const pattern of trust.users[user].neverApprove) {
|
|
556
|
+
if (matchesGlob(filePath, pattern)) return true;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
for (const pattern of trust.defaults.neverApprove) {
|
|
560
|
+
if (matchesGlob(filePath, pattern)) return true;
|
|
561
|
+
}
|
|
562
|
+
return false;
|
|
563
|
+
}
|
|
564
|
+
function isProcessAlive(pid) {
|
|
565
|
+
try {
|
|
566
|
+
process.kill(pid, 0);
|
|
567
|
+
return true;
|
|
568
|
+
} catch {
|
|
569
|
+
return false;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
// src/commands/symphony/index.ts
|
|
574
|
+
async function symphonyJoinCommand(options) {
|
|
575
|
+
const rootDir = process.cwd();
|
|
576
|
+
if (options.remote) {
|
|
577
|
+
console.log(chalk.yellow(`Remote linking to ${options.remote} \u2014 not yet implemented in Phase 0.`));
|
|
578
|
+
console.log(chalk.gray("Remote linking will be available in a future Symphony phase."));
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
const identity = registerAgent(rootDir);
|
|
582
|
+
console.log(chalk.green(`\u2713 Joined as ${chalk.bold(identity.id)}`));
|
|
583
|
+
const sessions = discoverClaudeCodeSessions();
|
|
584
|
+
const others = sessions.filter((s) => s.id !== identity.id);
|
|
585
|
+
if (others.length > 0) {
|
|
586
|
+
console.log(chalk.cyan(`
|
|
587
|
+
Found ${others.length} other session${others.length !== 1 ? "s" : ""}:`));
|
|
588
|
+
for (const s of others) {
|
|
589
|
+
const status = isAgentAsleep(s) ? chalk.yellow("asleep") : chalk.green("awake");
|
|
590
|
+
console.log(` ${chalk.white(s.id)} \u2014 ${s.name} [${status}]`);
|
|
591
|
+
}
|
|
592
|
+
} else {
|
|
593
|
+
console.log(chalk.gray('\n No other sessions found. Open another terminal and run "paradigm symphony join".'));
|
|
594
|
+
}
|
|
595
|
+
console.log(chalk.gray(`
|
|
596
|
+
Tip: Set up polling with: /loop 10s paradigm_symphony_poll`));
|
|
597
|
+
}
|
|
598
|
+
async function symphonyLeaveCommand() {
|
|
599
|
+
const rootDir = process.cwd();
|
|
600
|
+
const agentId = resolveAgentIdentity(rootDir);
|
|
601
|
+
const success = unregisterAgent(agentId);
|
|
602
|
+
if (success) {
|
|
603
|
+
console.log(chalk.green(`\u2713 Left the score: ${agentId}`));
|
|
604
|
+
} else {
|
|
605
|
+
console.log(chalk.yellow(`No active part found for this project.`));
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
async function symphonyWhoamiCommand() {
|
|
609
|
+
const rootDir = process.cwd();
|
|
610
|
+
const identity = getMyIdentity(rootDir);
|
|
611
|
+
if (!identity) {
|
|
612
|
+
console.log(chalk.yellow('Not joined. Run "paradigm symphony join" first.'));
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
const agents = listAgents();
|
|
616
|
+
const others = agents.filter((a) => a.id !== identity.id);
|
|
617
|
+
const threads = listThreads("active");
|
|
618
|
+
const unread = readInbox(identity.id);
|
|
619
|
+
console.log(chalk.cyan(`
|
|
620
|
+
${chalk.bold(identity.id)}`));
|
|
621
|
+
console.log(chalk.gray(` Project: ${identity.project}`));
|
|
622
|
+
console.log(chalk.gray(` Role: ${identity.role}`));
|
|
623
|
+
console.log(chalk.gray(` PID: ${identity.pid}`));
|
|
624
|
+
console.log(chalk.gray(` Started: ${identity.startedAt}`));
|
|
625
|
+
console.log(`
|
|
626
|
+
${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`)}`);
|
|
627
|
+
}
|
|
628
|
+
async function symphonyListCommand(options) {
|
|
629
|
+
cleanStaleAgents();
|
|
630
|
+
const agents = listAgents();
|
|
631
|
+
if (options.json) {
|
|
632
|
+
console.log(JSON.stringify(agents, null, 2));
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
if (agents.length === 0) {
|
|
636
|
+
console.log(chalk.yellow('No agents joined. Run "paradigm symphony join" in each terminal.'));
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
console.log(chalk.cyan(`
|
|
640
|
+
Symphony Agents (${agents.length})
|
|
641
|
+
`));
|
|
642
|
+
console.log(chalk.gray(` ${"AGENT ID".padEnd(30)} ${"PROJECT".padEnd(15)} ${"ROLE".padEnd(10)} STATUS`));
|
|
643
|
+
console.log(chalk.gray(` ${"\u2500".repeat(30)} ${"\u2500".repeat(15)} ${"\u2500".repeat(10)} ${"\u2500".repeat(8)}`));
|
|
644
|
+
for (const agent of agents) {
|
|
645
|
+
const status = isAgentAsleep(agent) ? chalk.yellow("asleep") : chalk.green("awake");
|
|
646
|
+
console.log(` ${chalk.white(agent.id.padEnd(30))} ${agent.project.padEnd(15)} ${agent.role.padEnd(10)} ${status}`);
|
|
647
|
+
}
|
|
648
|
+
console.log();
|
|
649
|
+
}
|
|
650
|
+
async function symphonySendCommand(messageText, options) {
|
|
651
|
+
const rootDir = process.cwd();
|
|
652
|
+
let identity = getMyIdentity(rootDir);
|
|
653
|
+
if (!identity) {
|
|
654
|
+
identity = registerAgent(rootDir);
|
|
655
|
+
console.log(chalk.gray(`Auto-joined as ${identity.id}`));
|
|
656
|
+
}
|
|
657
|
+
const sender = {
|
|
658
|
+
id: identity.id,
|
|
659
|
+
name: identity.name,
|
|
660
|
+
type: "human",
|
|
661
|
+
// CLI notes come from the human
|
|
662
|
+
project: identity.project,
|
|
663
|
+
role: identity.role
|
|
664
|
+
};
|
|
665
|
+
let recipients;
|
|
666
|
+
if (options.to) {
|
|
667
|
+
recipients = [{ id: options.to, name: options.to, type: "agent" }];
|
|
668
|
+
}
|
|
669
|
+
let threadRoot = options.thread;
|
|
670
|
+
if (!threadRoot) {
|
|
671
|
+
const topic = messageText.length > 60 ? messageText.slice(0, 60) + "..." : messageText;
|
|
672
|
+
const thread = createThread(topic, sender);
|
|
673
|
+
threadRoot = thread.id;
|
|
674
|
+
}
|
|
675
|
+
const message = buildMessage({
|
|
676
|
+
sender,
|
|
677
|
+
recipients,
|
|
678
|
+
intent: "context",
|
|
679
|
+
text: messageText,
|
|
680
|
+
threadRoot
|
|
681
|
+
});
|
|
682
|
+
const deliveryCount = routeMessage(message);
|
|
683
|
+
console.log(chalk.green(`\u2713 Sent to ${deliveryCount} agent${deliveryCount !== 1 ? "s" : ""}`));
|
|
684
|
+
console.log(chalk.gray(` Thread: ${threadRoot}`));
|
|
685
|
+
console.log(chalk.gray(` Note: ${message.id}`));
|
|
686
|
+
}
|
|
687
|
+
async function symphonyReadCommand() {
|
|
688
|
+
const rootDir = process.cwd();
|
|
689
|
+
const identity = getMyIdentity(rootDir);
|
|
690
|
+
if (!identity) {
|
|
691
|
+
console.log(chalk.yellow('Not joined. Run "paradigm symphony join" first.'));
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
markAgentPollTime(identity.id);
|
|
695
|
+
const messages = readInbox(identity.id);
|
|
696
|
+
if (messages.length === 0) {
|
|
697
|
+
console.log(chalk.gray("\n No unread notes.\n"));
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
const byThread = /* @__PURE__ */ new Map();
|
|
701
|
+
for (const msg of messages) {
|
|
702
|
+
const tid = msg.threadRoot || "direct";
|
|
703
|
+
if (!byThread.has(tid)) byThread.set(tid, []);
|
|
704
|
+
byThread.get(tid).push(msg);
|
|
705
|
+
}
|
|
706
|
+
console.log(chalk.cyan(`
|
|
707
|
+
${messages.length} unread note${messages.length !== 1 ? "s" : ""}
|
|
708
|
+
`));
|
|
709
|
+
for (const [threadId, msgs] of byThread) {
|
|
710
|
+
let threadLabel = threadId;
|
|
711
|
+
if (threadId !== "direct") {
|
|
712
|
+
const thread = loadThread(threadId);
|
|
713
|
+
if (thread) threadLabel = `${thread.topic} (${threadId})`;
|
|
714
|
+
}
|
|
715
|
+
console.log(chalk.white(` \u250C\u2500 ${threadLabel}`));
|
|
716
|
+
for (let i = 0; i < msgs.length; i++) {
|
|
717
|
+
const msg = msgs[i];
|
|
718
|
+
const isLast = i === msgs.length - 1;
|
|
719
|
+
const prefix = isLast ? " \u2514\u2500" : " \u251C\u2500";
|
|
720
|
+
const time = new Date(msg.timestamp).toLocaleTimeString(void 0, { hour: "numeric", minute: "2-digit" });
|
|
721
|
+
console.log(`${prefix} ${chalk.cyan(msg.sender.name)} ${chalk.gray(`[${msg.intent}]`)} ${chalk.gray(time)}`);
|
|
722
|
+
const textLines = msg.content.text.split("\n");
|
|
723
|
+
const indent = isLast ? " " : " \u2502 ";
|
|
724
|
+
for (const line of textLines) {
|
|
725
|
+
console.log(`${indent}${line}`);
|
|
726
|
+
}
|
|
727
|
+
if (msg.symbols.length > 0) {
|
|
728
|
+
console.log(`${indent}${chalk.gray(`Symbols: ${msg.symbols.join(", ")}`)}`);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
console.log();
|
|
732
|
+
}
|
|
733
|
+
const lastId = messages[messages.length - 1].id;
|
|
734
|
+
acknowledgeMessages(identity.id, lastId);
|
|
735
|
+
garbageCollect(identity.id);
|
|
736
|
+
}
|
|
737
|
+
async function symphonyThreadsCommand(options) {
|
|
738
|
+
const threads = listThreads();
|
|
739
|
+
if (options.json) {
|
|
740
|
+
console.log(JSON.stringify(threads, null, 2));
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
if (threads.length === 0) {
|
|
744
|
+
console.log(chalk.gray("\n No threads.\n"));
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
console.log(chalk.cyan(`
|
|
748
|
+
Threads (${threads.length})
|
|
749
|
+
`));
|
|
750
|
+
console.log(chalk.gray(` ${"ID".padEnd(14)} ${"TOPIC".padEnd(35)} ${"MSGS".padEnd(6)} ${"STATUS".padEnd(10)} LAST ACTIVITY`));
|
|
751
|
+
console.log(chalk.gray(` ${"\u2500".repeat(14)} ${"\u2500".repeat(35)} ${"\u2500".repeat(6)} ${"\u2500".repeat(10)} ${"\u2500".repeat(20)}`));
|
|
752
|
+
for (const thread of threads) {
|
|
753
|
+
const topic = thread.topic.length > 33 ? thread.topic.slice(0, 33) + ".." : thread.topic;
|
|
754
|
+
const status = thread.status === "active" ? chalk.green("active") : chalk.gray("resolved");
|
|
755
|
+
const lastAct = new Date(thread.lastActivity).toLocaleString(void 0, {
|
|
756
|
+
month: "short",
|
|
757
|
+
day: "numeric",
|
|
758
|
+
hour: "numeric",
|
|
759
|
+
minute: "2-digit"
|
|
760
|
+
});
|
|
761
|
+
console.log(` ${chalk.white(thread.id.padEnd(14))} ${topic.padEnd(35)} ${String(thread.messageCount).padEnd(6)} ${status.padEnd(10)} ${chalk.gray(lastAct)}`);
|
|
762
|
+
}
|
|
763
|
+
console.log();
|
|
764
|
+
}
|
|
765
|
+
async function symphonyThreadCommand(threadId) {
|
|
766
|
+
const thread = loadThread(threadId);
|
|
767
|
+
if (!thread) {
|
|
768
|
+
console.log(chalk.red(`Thread not found: ${threadId}`));
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
const messages = getThreadMessages(threadId);
|
|
772
|
+
console.log(chalk.cyan(`
|
|
773
|
+
Thread: ${thread.topic}`));
|
|
774
|
+
console.log(chalk.gray(` ID: ${thread.id} | Status: ${thread.status} | Notes: ${thread.messageCount}`));
|
|
775
|
+
console.log(chalk.gray(` Participants: ${thread.participants.map((p) => p.name).join(", ")}`));
|
|
776
|
+
if (thread.decision) {
|
|
777
|
+
console.log(chalk.green(` Decision: ${thread.decision}`));
|
|
778
|
+
}
|
|
779
|
+
console.log(chalk.gray(`
|
|
780
|
+
${"\u2500".repeat(60)}
|
|
781
|
+
`));
|
|
782
|
+
for (const msg of messages) {
|
|
783
|
+
const time = new Date(msg.timestamp).toLocaleString(void 0, {
|
|
784
|
+
month: "short",
|
|
785
|
+
day: "numeric",
|
|
786
|
+
hour: "numeric",
|
|
787
|
+
minute: "2-digit"
|
|
788
|
+
});
|
|
789
|
+
console.log(` ${chalk.cyan(msg.sender.name)} ${chalk.gray(`[${msg.intent}]`)} ${chalk.gray(time)}`);
|
|
790
|
+
const textLines = msg.content.text.split("\n");
|
|
791
|
+
for (const line of textLines) {
|
|
792
|
+
console.log(` ${line}`);
|
|
793
|
+
}
|
|
794
|
+
if (msg.symbols.length > 0) {
|
|
795
|
+
console.log(` ${chalk.gray(`Symbols: ${msg.symbols.join(", ")}`)}`);
|
|
796
|
+
}
|
|
797
|
+
if (msg.content.decision) {
|
|
798
|
+
console.log(` ${chalk.green(`Decision: ${msg.content.decision}`)}`);
|
|
799
|
+
}
|
|
800
|
+
console.log();
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
async function symphonyResolveCommand(threadId, options) {
|
|
804
|
+
const thread = loadThread(threadId);
|
|
805
|
+
if (!thread) {
|
|
806
|
+
console.log(chalk.red(`Thread not found: ${threadId}`));
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
const success = resolveThread(threadId, options.decision);
|
|
810
|
+
if (success) {
|
|
811
|
+
console.log(chalk.green(`\u2713 Thread resolved: ${thread.topic}`));
|
|
812
|
+
if (options.decision) {
|
|
813
|
+
console.log(chalk.gray(` Decision: ${options.decision}`));
|
|
814
|
+
}
|
|
815
|
+
console.log(chalk.gray(` Tip: Record this as lore with "paradigm lore record --title 'Thread: ${thread.topic}'"`));
|
|
816
|
+
} else {
|
|
817
|
+
console.log(chalk.red("Failed to resolve thread."));
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
async function symphonyStatusCommand(options) {
|
|
821
|
+
cleanStaleAgents();
|
|
822
|
+
const rootDir = process.cwd();
|
|
823
|
+
const identity = getMyIdentity(rootDir);
|
|
824
|
+
const agents = listAgents();
|
|
825
|
+
const threads = listThreads("active");
|
|
826
|
+
const pendingRequests = listFileRequests("pending");
|
|
827
|
+
const unread = identity ? readInbox(identity.id) : [];
|
|
828
|
+
if (options.json) {
|
|
829
|
+
console.log(JSON.stringify({
|
|
830
|
+
identity: identity ? { id: identity.id, project: identity.project, role: identity.role } : null,
|
|
831
|
+
agents: agents.map((a) => ({ id: a.id, status: isAgentAsleep(a) ? "asleep" : "awake" })),
|
|
832
|
+
activeThreads: threads.length,
|
|
833
|
+
unreadMessages: unread.length,
|
|
834
|
+
pendingFileRequests: pendingRequests.length
|
|
835
|
+
}, null, 2));
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
console.log(chalk.cyan("\n Symphony Status\n"));
|
|
839
|
+
if (identity) {
|
|
840
|
+
console.log(` ${chalk.white("Identity:")} ${identity.id}`);
|
|
841
|
+
} else {
|
|
842
|
+
console.log(` ${chalk.yellow("Not joined.")} Run "paradigm symphony join" to join.`);
|
|
843
|
+
}
|
|
844
|
+
const awake = agents.filter((a) => !isAgentAsleep(a)).length;
|
|
845
|
+
console.log(` ${chalk.white("Agents:")} ${agents.length} joined (${awake} awake)`);
|
|
846
|
+
console.log(` ${chalk.white("Threads:")} ${threads.length} active`);
|
|
847
|
+
console.log(` ${chalk.white("Unread:")} ${unread.length} note${unread.length !== 1 ? "s" : ""}`);
|
|
848
|
+
console.log(` ${chalk.white("File Requests:")} ${pendingRequests.length} pending`);
|
|
849
|
+
console.log();
|
|
850
|
+
}
|
|
851
|
+
async function symphonyServeCommand(options) {
|
|
852
|
+
const port = parseInt(options.port || "3939", 10);
|
|
853
|
+
console.log(chalk.cyan(`
|
|
854
|
+
Starting Symphony TCP server on port ${port}...`));
|
|
855
|
+
console.log(chalk.gray(" Phase 0 stub \u2014 remote linking protocol not yet implemented.\n"));
|
|
856
|
+
const server = net.createServer((socket) => {
|
|
857
|
+
socket.write(JSON.stringify({ type: "hello", version: "0.1.0" }) + "\n");
|
|
858
|
+
socket.on("data", (data) => {
|
|
859
|
+
try {
|
|
860
|
+
const msg = JSON.parse(data.toString().trim());
|
|
861
|
+
socket.write(JSON.stringify({ type: "ack", received: msg.type }) + "\n");
|
|
862
|
+
} catch {
|
|
863
|
+
socket.write(JSON.stringify({ type: "error", message: "Invalid JSON" }) + "\n");
|
|
864
|
+
}
|
|
865
|
+
});
|
|
866
|
+
socket.on("error", () => {
|
|
867
|
+
});
|
|
868
|
+
});
|
|
869
|
+
server.listen(port, "0.0.0.0", () => {
|
|
870
|
+
console.log(chalk.green(` \u2713 Symphony server listening on 0.0.0.0:${port}`));
|
|
871
|
+
console.log(chalk.gray(` Connect from another machine: paradigm symphony join --remote <this-ip>:${port}`));
|
|
872
|
+
});
|
|
873
|
+
server.on("error", (err) => {
|
|
874
|
+
console.log(chalk.red(` Failed to start server: ${err.message}`));
|
|
875
|
+
});
|
|
876
|
+
await new Promise(() => {
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
async function symphonyRequestCommand(file, options) {
|
|
880
|
+
const rootDir = process.cwd();
|
|
881
|
+
let identity = getMyIdentity(rootDir);
|
|
882
|
+
if (!identity) {
|
|
883
|
+
identity = registerAgent(rootDir);
|
|
884
|
+
}
|
|
885
|
+
const from = options.from;
|
|
886
|
+
const reason = options.reason || "Needed for current task";
|
|
887
|
+
if (!from) {
|
|
888
|
+
console.log(chalk.red("--from is required. Specify which agent to request from."));
|
|
889
|
+
const agents = listAgents().filter((a) => a.id !== identity.id);
|
|
890
|
+
if (agents.length > 0) {
|
|
891
|
+
console.log(chalk.gray("\nAvailable agents:"));
|
|
892
|
+
for (const a of agents) {
|
|
893
|
+
console.log(chalk.gray(` ${a.id}`));
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
898
|
+
const trust = loadTrustConfig();
|
|
899
|
+
if (isPathDenied(file, trust)) {
|
|
900
|
+
console.log(chalk.red(`\u2717 "${file}" is on the hard-deny list and cannot be requested.`));
|
|
901
|
+
return;
|
|
902
|
+
}
|
|
903
|
+
const record = createFileRequest({
|
|
904
|
+
filePath: file,
|
|
905
|
+
requester: {
|
|
906
|
+
id: identity.id,
|
|
907
|
+
name: identity.name,
|
|
908
|
+
type: "agent",
|
|
909
|
+
project: identity.project,
|
|
910
|
+
role: identity.role
|
|
911
|
+
},
|
|
912
|
+
reason
|
|
913
|
+
});
|
|
914
|
+
const msg = buildMessage({
|
|
915
|
+
sender: {
|
|
916
|
+
id: identity.id,
|
|
917
|
+
name: identity.name,
|
|
918
|
+
type: "agent",
|
|
919
|
+
project: identity.project,
|
|
920
|
+
role: identity.role
|
|
921
|
+
},
|
|
922
|
+
recipients: [{ id: from, name: from, type: "agent" }],
|
|
923
|
+
intent: "fileRequest",
|
|
924
|
+
text: `File request: ${file}
|
|
925
|
+
Reason: ${reason}`,
|
|
926
|
+
symbols: []
|
|
927
|
+
});
|
|
928
|
+
routeMessage(msg);
|
|
929
|
+
console.log(chalk.green(`\u2713 File request created: ${record.request.requestId}`));
|
|
930
|
+
console.log(chalk.gray(` File: ${file}`));
|
|
931
|
+
console.log(chalk.gray(` From: ${from}`));
|
|
932
|
+
console.log(chalk.gray(` Reason: ${reason}`));
|
|
933
|
+
console.log(chalk.gray(`
|
|
934
|
+
The owning agent's human must approve with:`));
|
|
935
|
+
console.log(chalk.white(` paradigm symphony approve ${record.request.requestId}`));
|
|
936
|
+
}
|
|
937
|
+
async function symphonyRequestsCommand() {
|
|
938
|
+
const requests = listFileRequests("pending");
|
|
939
|
+
if (requests.length === 0) {
|
|
940
|
+
console.log(chalk.gray("\n No pending file requests.\n"));
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
console.log(chalk.cyan(`
|
|
944
|
+
Pending File Requests (${requests.length})
|
|
945
|
+
`));
|
|
946
|
+
for (const req of requests) {
|
|
947
|
+
const age = Date.now() - new Date(req.createdAt).getTime();
|
|
948
|
+
const ageMin = Math.round(age / 6e4);
|
|
949
|
+
console.log(` ${chalk.white(req.request.requestId)}`);
|
|
950
|
+
console.log(` File: ${req.request.filePath}`);
|
|
951
|
+
console.log(` From: ${req.request.requester.name} (${req.request.requester.id})`);
|
|
952
|
+
console.log(` Reason: ${req.request.reason}`);
|
|
953
|
+
console.log(chalk.gray(` ${ageMin}m ago`));
|
|
954
|
+
console.log(chalk.gray(` \u2192 paradigm symphony approve ${req.request.requestId}`));
|
|
955
|
+
console.log(chalk.gray(` \u2192 paradigm symphony deny ${req.request.requestId}`));
|
|
956
|
+
console.log();
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
async function symphonyApproveCommand(requestId, options) {
|
|
960
|
+
const rootDir = process.cwd();
|
|
961
|
+
const result = approveFileRequest(requestId, rootDir, options.redact);
|
|
962
|
+
if (!result.success) {
|
|
963
|
+
console.log(chalk.red(`\u2717 ${result.error}`));
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
966
|
+
const label = options.redact ? "approved (redacted)" : "approved";
|
|
967
|
+
console.log(chalk.green(`\u2713 File request ${label}`));
|
|
968
|
+
console.log(chalk.gray(` File: ${result.delivery?.filePath}`));
|
|
969
|
+
console.log(chalk.gray(` Size: ${result.delivery?.size} bytes`));
|
|
970
|
+
console.log(chalk.gray(` SHA-256: ${result.delivery?.hash?.slice(0, 16)}...`));
|
|
971
|
+
}
|
|
972
|
+
async function symphonyDenyCommand(requestId, options) {
|
|
973
|
+
const success = denyFileRequest(requestId, options.reason);
|
|
974
|
+
if (success) {
|
|
975
|
+
console.log(chalk.green(`\u2713 File request denied: ${requestId}`));
|
|
976
|
+
if (options.reason) {
|
|
977
|
+
console.log(chalk.gray(` Reason: ${options.reason}`));
|
|
978
|
+
}
|
|
979
|
+
} else {
|
|
980
|
+
console.log(chalk.red(`\u2717 File request not found or already resolved: ${requestId}`));
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
export {
|
|
984
|
+
symphonyApproveCommand,
|
|
985
|
+
symphonyDenyCommand,
|
|
986
|
+
symphonyJoinCommand,
|
|
987
|
+
symphonyLeaveCommand,
|
|
988
|
+
symphonyListCommand,
|
|
989
|
+
symphonyReadCommand,
|
|
990
|
+
symphonyRequestCommand,
|
|
991
|
+
symphonyRequestsCommand,
|
|
992
|
+
symphonyResolveCommand,
|
|
993
|
+
symphonySendCommand,
|
|
994
|
+
symphonyServeCommand,
|
|
995
|
+
symphonyStatusCommand,
|
|
996
|
+
symphonyThreadCommand,
|
|
997
|
+
symphonyThreadsCommand,
|
|
998
|
+
symphonyWhoamiCommand
|
|
999
|
+
};
|