@adhdev/daemon-standalone 0.9.77-rc.3 → 0.9.77-rc.31
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/index.js +196 -25
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/public/assets/{index-6WEc6L46.js → index-CWWeDAva.js} +2 -2
- package/public/assets/{terminal-BeBmUW3m.js → terminal-B-dmfv31.js} +11 -11
- package/public/index.html +1 -1
- package/vendor/mcp-server/index.js +348 -40
- package/vendor/mcp-server/index.js.map +1 -1
package/dist/index.js
CHANGED
|
@@ -32202,6 +32202,7 @@ Follow these recovery rules:
|
|
|
32202
32202
|
message,
|
|
32203
32203
|
status: "pending",
|
|
32204
32204
|
targetNodeId: opts?.targetNodeId,
|
|
32205
|
+
targetSessionId: opts?.targetSessionId,
|
|
32205
32206
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
32206
32207
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
32207
32208
|
};
|
|
@@ -32219,9 +32220,12 @@ Follow these recovery rules:
|
|
|
32219
32220
|
}
|
|
32220
32221
|
function claimNextTask(meshId, nodeId, sessionId) {
|
|
32221
32222
|
const queue = readQueue(meshId);
|
|
32222
|
-
let targetIdx = queue.findIndex((q2) => q2.status === "pending" && q2.
|
|
32223
|
+
let targetIdx = queue.findIndex((q2) => q2.status === "pending" && q2.targetSessionId === sessionId);
|
|
32223
32224
|
if (targetIdx === -1) {
|
|
32224
|
-
targetIdx = queue.findIndex((q2) => q2.status === "pending" && !q2.
|
|
32225
|
+
targetIdx = queue.findIndex((q2) => q2.status === "pending" && q2.targetNodeId === nodeId && !q2.targetSessionId);
|
|
32226
|
+
}
|
|
32227
|
+
if (targetIdx === -1) {
|
|
32228
|
+
targetIdx = queue.findIndex((q2) => q2.status === "pending" && !q2.targetNodeId && !q2.targetSessionId);
|
|
32225
32229
|
}
|
|
32226
32230
|
if (targetIdx === -1) return null;
|
|
32227
32231
|
const entry = queue[targetIdx];
|
|
@@ -32530,22 +32534,47 @@ Follow these recovery rules:
|
|
|
32530
32534
|
].filter(Boolean);
|
|
32531
32535
|
return parts.length > 0 ? ` (${parts.join("; ")})` : "";
|
|
32532
32536
|
}
|
|
32537
|
+
function getMeshWithCache(components, meshId) {
|
|
32538
|
+
const localMesh = getMesh(meshId);
|
|
32539
|
+
if (localMesh) return localMesh;
|
|
32540
|
+
return components.router?.getCachedInlineMesh(meshId);
|
|
32541
|
+
}
|
|
32533
32542
|
function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType) {
|
|
32534
32543
|
const task = claimNextTask(meshId, nodeId, sessionId);
|
|
32535
|
-
if (!task)
|
|
32544
|
+
if (!task) {
|
|
32545
|
+
return false;
|
|
32546
|
+
}
|
|
32536
32547
|
LOG2.info("MeshQueue", `Node ${nodeId} (${sessionId}) pulled task ${task.id}`);
|
|
32548
|
+
const mesh = getMeshWithCache(components, meshId);
|
|
32549
|
+
const node = mesh?.nodes.find((n) => n.id === nodeId);
|
|
32550
|
+
if (node?.daemonId && components.dispatchMeshCommand) {
|
|
32551
|
+
const isLocalNode = components.cliManager.adapters.has(sessionId);
|
|
32552
|
+
if (!isLocalNode) {
|
|
32553
|
+
components.dispatchMeshCommand(node.daemonId, "agent_command", {
|
|
32554
|
+
targetSessionId: sessionId,
|
|
32555
|
+
cliType: providerType,
|
|
32556
|
+
action: "send_chat",
|
|
32557
|
+
message: task.message
|
|
32558
|
+
}).catch((e) => {
|
|
32559
|
+
LOG2.error("MeshQueue", `Failed to dispatch task via P2P to remote node ${nodeId}: ${e?.message}`);
|
|
32560
|
+
updateTaskStatus(meshId, task.id, "failed");
|
|
32561
|
+
});
|
|
32562
|
+
return true;
|
|
32563
|
+
}
|
|
32564
|
+
}
|
|
32537
32565
|
components.cliManager.handleCliCommand("agent_command", {
|
|
32538
32566
|
targetSessionId: sessionId,
|
|
32539
32567
|
cliType: providerType,
|
|
32540
32568
|
action: "send_chat",
|
|
32541
|
-
|
|
32569
|
+
message: task.message
|
|
32542
32570
|
}).catch((e) => {
|
|
32543
|
-
LOG2.error("MeshQueue", `Failed to dispatch task to node ${nodeId}: ${e?.message}`);
|
|
32571
|
+
LOG2.error("MeshQueue", `Failed to dispatch task locally to node ${nodeId}: ${e?.message}`);
|
|
32572
|
+
updateTaskStatus(meshId, task.id, "failed");
|
|
32544
32573
|
});
|
|
32545
32574
|
return true;
|
|
32546
32575
|
}
|
|
32547
32576
|
function triggerMeshQueue(components, meshId) {
|
|
32548
|
-
const mesh =
|
|
32577
|
+
const mesh = getMeshWithCache(components, meshId);
|
|
32549
32578
|
if (!mesh) return;
|
|
32550
32579
|
const cliInstances = components.instanceManager.getByCategory("cli");
|
|
32551
32580
|
for (const inst of cliInstances) {
|
|
@@ -32562,6 +32591,15 @@ Follow these recovery rules:
|
|
|
32562
32591
|
tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType);
|
|
32563
32592
|
}
|
|
32564
32593
|
}
|
|
32594
|
+
for (const [key, idle] of remoteIdleSessions.entries()) {
|
|
32595
|
+
const node = mesh.nodes.find((n) => n.id === idle.nodeId);
|
|
32596
|
+
if (node) {
|
|
32597
|
+
const assigned = tryAssignQueueTask(components, meshId, idle.nodeId, idle.sessionId, idle.providerType);
|
|
32598
|
+
if (assigned) {
|
|
32599
|
+
remoteIdleSessions.delete(key);
|
|
32600
|
+
}
|
|
32601
|
+
}
|
|
32602
|
+
}
|
|
32565
32603
|
}
|
|
32566
32604
|
function buildMeshSystemMessage(args) {
|
|
32567
32605
|
const metadata = formatCompletionMetadata(args.metadataEvent);
|
|
@@ -32610,7 +32648,7 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
|
|
|
32610
32648
|
function injectMeshSystemMessage(components, args) {
|
|
32611
32649
|
if (args.event === "agent:generating_completed") {
|
|
32612
32650
|
const sessionId = readNonEmptyString(args.metadataEvent.targetSessionId);
|
|
32613
|
-
const nodeId = readNonEmptyString(args.
|
|
32651
|
+
const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
|
|
32614
32652
|
const providerType = readNonEmptyString(args.metadataEvent.providerType);
|
|
32615
32653
|
if (sessionId) {
|
|
32616
32654
|
updateSessionTaskStatus(args.meshId, sessionId, "completed");
|
|
@@ -32620,8 +32658,31 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
|
|
|
32620
32658
|
}, 500);
|
|
32621
32659
|
}
|
|
32622
32660
|
}
|
|
32661
|
+
} else if (args.event === "agent:ready") {
|
|
32662
|
+
const sessionId = readNonEmptyString(args.metadataEvent.targetSessionId);
|
|
32663
|
+
const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
|
|
32664
|
+
const providerType = readNonEmptyString(args.metadataEvent.providerType);
|
|
32665
|
+
if (sessionId && nodeId && providerType) {
|
|
32666
|
+
remoteIdleSessions.set(`${nodeId}:${sessionId}`, { nodeId, sessionId, providerType });
|
|
32667
|
+
setTimeout(() => {
|
|
32668
|
+
const assigned = tryAssignQueueTask(components, args.meshId, nodeId, sessionId, providerType);
|
|
32669
|
+
if (assigned) {
|
|
32670
|
+
remoteIdleSessions.delete(`${nodeId}:${sessionId}`);
|
|
32671
|
+
}
|
|
32672
|
+
}, 500);
|
|
32673
|
+
}
|
|
32674
|
+
} else if (args.event === "agent:generating_started") {
|
|
32675
|
+
const sessionId = readNonEmptyString(args.metadataEvent.targetSessionId);
|
|
32676
|
+
const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
|
|
32677
|
+
if (sessionId && nodeId) {
|
|
32678
|
+
remoteIdleSessions.delete(`${nodeId}:${sessionId}`);
|
|
32679
|
+
}
|
|
32623
32680
|
} else if (args.event === "agent:stopped") {
|
|
32624
32681
|
const sessionId = readNonEmptyString(args.metadataEvent.targetSessionId);
|
|
32682
|
+
const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
|
|
32683
|
+
if (sessionId && nodeId) {
|
|
32684
|
+
remoteIdleSessions.delete(`${nodeId}:${sessionId}`);
|
|
32685
|
+
}
|
|
32625
32686
|
if (sessionId) {
|
|
32626
32687
|
updateSessionTaskStatus(args.meshId, sessionId, "failed");
|
|
32627
32688
|
}
|
|
@@ -32631,7 +32692,7 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
|
|
|
32631
32692
|
try {
|
|
32632
32693
|
appendLedgerEntry(args.meshId, {
|
|
32633
32694
|
kind: ledgerKind,
|
|
32634
|
-
nodeId: readNonEmptyString(args.
|
|
32695
|
+
nodeId: readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId) || void 0,
|
|
32635
32696
|
sessionId: readNonEmptyString(args.metadataEvent.targetSessionId) || void 0,
|
|
32636
32697
|
providerType: readNonEmptyString(args.metadataEvent.providerType) || void 0,
|
|
32637
32698
|
payload: {
|
|
@@ -32651,7 +32712,7 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
|
|
|
32651
32712
|
const maxRetries = mesh?.policy?.maxTaskRetries ?? 1;
|
|
32652
32713
|
recoveryContext = getSessionRecoveryContext(args.meshId, {
|
|
32653
32714
|
sessionId: readNonEmptyString(args.metadataEvent.targetSessionId) || void 0,
|
|
32654
|
-
nodeId: readNonEmptyString(args.
|
|
32715
|
+
nodeId: readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId) || void 0,
|
|
32655
32716
|
maxRetries
|
|
32656
32717
|
});
|
|
32657
32718
|
recoveryContext.failedProviderType = readNonEmptyString(args.metadataEvent.providerType) || null;
|
|
@@ -32746,6 +32807,7 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
|
|
|
32746
32807
|
const nodeLabel = nodeId ? `Node '${nodeId}'` : workspace ? `Agent at ${workspace}` : "Remote agent";
|
|
32747
32808
|
return injectMeshSystemMessage(components, {
|
|
32748
32809
|
meshId,
|
|
32810
|
+
nodeId,
|
|
32749
32811
|
nodeLabel,
|
|
32750
32812
|
event: eventName,
|
|
32751
32813
|
metadataEvent: {
|
|
@@ -32770,21 +32832,24 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
|
|
|
32770
32832
|
const meshIdFromRuntime = readNonEmptyString(settings.meshNodeFor);
|
|
32771
32833
|
const isMeshDelegate = Boolean(meshIdFromRuntime || settings.launchedByCoordinator);
|
|
32772
32834
|
if (!isMeshDelegate) return;
|
|
32773
|
-
const mesh = meshIdFromRuntime ?
|
|
32835
|
+
const mesh = meshIdFromRuntime ? getMeshWithCache(components, meshIdFromRuntime) : getMeshByRepo(workspace);
|
|
32774
32836
|
const meshId = meshIdFromRuntime || readNonEmptyString(mesh?.id);
|
|
32775
32837
|
if (!meshId) return;
|
|
32776
32838
|
const targetNode = mesh?.nodes?.find((n) => n.workspace === workspace);
|
|
32777
32839
|
const runtimeNodeId = readNonEmptyString(settings.meshNodeId);
|
|
32840
|
+
const resolvedNodeId = targetNode?.id || runtimeNodeId;
|
|
32778
32841
|
const nodeLabel = targetNode ? `Node '${targetNode.id}'` : runtimeNodeId ? `Node '${runtimeNodeId}'` : `Agent at ${workspace}`;
|
|
32779
32842
|
injectMeshSystemMessage(components, {
|
|
32780
32843
|
meshId,
|
|
32781
32844
|
sourceInstanceId: instanceId,
|
|
32845
|
+
nodeId: resolvedNodeId,
|
|
32782
32846
|
nodeLabel,
|
|
32783
32847
|
event: event.event,
|
|
32784
32848
|
metadataEvent: event
|
|
32785
32849
|
});
|
|
32786
32850
|
});
|
|
32787
32851
|
}
|
|
32852
|
+
var remoteIdleSessions;
|
|
32788
32853
|
var MAX_PENDING_EVENTS;
|
|
32789
32854
|
var pendingMeshCoordinatorEvents;
|
|
32790
32855
|
var MESH_COORDINATOR_EVENTS;
|
|
@@ -32796,12 +32861,14 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
|
|
|
32796
32861
|
init_logger();
|
|
32797
32862
|
init_mesh_ledger();
|
|
32798
32863
|
init_mesh_work_queue();
|
|
32864
|
+
remoteIdleSessions = /* @__PURE__ */ new Map();
|
|
32799
32865
|
MAX_PENDING_EVENTS = 50;
|
|
32800
32866
|
pendingMeshCoordinatorEvents = [];
|
|
32801
32867
|
MESH_COORDINATOR_EVENTS = /* @__PURE__ */ new Set([
|
|
32802
32868
|
"agent:generating_completed",
|
|
32803
32869
|
"agent:waiting_approval",
|
|
32804
32870
|
"agent:stopped",
|
|
32871
|
+
"agent:ready",
|
|
32805
32872
|
"monitor:long_generating"
|
|
32806
32873
|
]);
|
|
32807
32874
|
EVENT_TO_LEDGER_KIND = {
|
|
@@ -33914,6 +33981,8 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
|
|
|
33914
33981
|
statusHistory = [];
|
|
33915
33982
|
// ─── CLI Scripts (script-based parsing) ───
|
|
33916
33983
|
cliScripts;
|
|
33984
|
+
/** Per-session opaque state object created by cliScripts.createState(), reset on stop. */
|
|
33985
|
+
scriptState = null;
|
|
33917
33986
|
runtimeSettings = {};
|
|
33918
33987
|
/** Full accumulated rendered PTY transcript for parser/readback use */
|
|
33919
33988
|
accumulatedBuffer = "";
|
|
@@ -34095,6 +34164,7 @@ ${lastSnapshot}`;
|
|
|
34095
34164
|
this.cliScripts = scripts;
|
|
34096
34165
|
this.parsedStatusCache = null;
|
|
34097
34166
|
this.parseErrorMessage = null;
|
|
34167
|
+
this.scriptState = typeof scripts.createState === "function" ? scripts.createState() : null;
|
|
34098
34168
|
const scriptNames = listCliScriptNames(scripts);
|
|
34099
34169
|
LOG2.info("CLI", `[${this.cliType}] CLI scripts injected: [${scriptNames.join(", ")}]`);
|
|
34100
34170
|
}
|
|
@@ -34212,6 +34282,7 @@ ${lastSnapshot}`;
|
|
|
34212
34282
|
this.ready = false;
|
|
34213
34283
|
this.startupParseGate = false;
|
|
34214
34284
|
this.spawnAt = 0;
|
|
34285
|
+
this.scriptState = null;
|
|
34215
34286
|
this.onStatusChange?.();
|
|
34216
34287
|
});
|
|
34217
34288
|
this.spawnAt = Date.now();
|
|
@@ -34985,7 +35056,7 @@ ${lastSnapshot}`;
|
|
|
34985
35056
|
scope: this.currentTurnScope,
|
|
34986
35057
|
runtimeSettings: this.runtimeSettings
|
|
34987
35058
|
});
|
|
34988
|
-
const session = this.cliScripts.parseSession({ ...input, tail, tailScreen: buildCliScreenSnapshot(tail) });
|
|
35059
|
+
const session = this.cliScripts.parseSession(this.scriptState, { ...input, tail, tailScreen: buildCliScreenSnapshot(tail) });
|
|
34989
35060
|
this.parseErrorMessage = null;
|
|
34990
35061
|
return session && typeof session === "object" ? session : null;
|
|
34991
35062
|
} catch (e) {
|
|
@@ -34999,7 +35070,7 @@ ${lastSnapshot}`;
|
|
|
34999
35070
|
if (!this.cliScripts?.detectStatus) return null;
|
|
35000
35071
|
try {
|
|
35001
35072
|
const screenText = this.terminalScreen.getText();
|
|
35002
|
-
const status = this.cliScripts.detectStatus({
|
|
35073
|
+
const status = this.cliScripts.detectStatus(this.scriptState, {
|
|
35003
35074
|
tail: text.slice(-500),
|
|
35004
35075
|
screenText,
|
|
35005
35076
|
rawBuffer: this.accumulatedRawBuffer,
|
|
@@ -35018,7 +35089,7 @@ ${lastSnapshot}`;
|
|
|
35018
35089
|
try {
|
|
35019
35090
|
const screenText = this.terminalScreen.getText();
|
|
35020
35091
|
const buffer = screenText || this.accumulatedBuffer;
|
|
35021
|
-
return this.cliScripts.parseApproval({
|
|
35092
|
+
return this.cliScripts.parseApproval(this.scriptState, {
|
|
35022
35093
|
buffer,
|
|
35023
35094
|
screenText,
|
|
35024
35095
|
rawBuffer: this.accumulatedRawBuffer,
|
|
@@ -35126,7 +35197,7 @@ ${lastSnapshot}`;
|
|
|
35126
35197
|
scope: this.currentTurnScope,
|
|
35127
35198
|
runtimeSettings: this.runtimeSettings
|
|
35128
35199
|
});
|
|
35129
|
-
return await Promise.resolve(fn2({
|
|
35200
|
+
return await Promise.resolve(fn2(this.scriptState, {
|
|
35130
35201
|
...input,
|
|
35131
35202
|
args: args && typeof args === "object" ? { ...args } : {}
|
|
35132
35203
|
}));
|
|
@@ -46296,11 +46367,13 @@ ${effect.notification.body || ""}`.trim();
|
|
|
46296
46367
|
async function handlePtyInput(h, args) {
|
|
46297
46368
|
const { cliType, data, targetSessionId } = args || {};
|
|
46298
46369
|
if (!data) return { success: false, error: "data required" };
|
|
46370
|
+
const cleanData = typeof data === "string" ? data.replace(/\x1b\[[?>][0-9;]*c/g, "") : data;
|
|
46371
|
+
if (!cleanData) return { success: true };
|
|
46299
46372
|
const adapter = h.getCliAdapter(targetSessionId || cliType);
|
|
46300
46373
|
if (!adapter || typeof adapter.writeRaw !== "function") {
|
|
46301
46374
|
return { success: false, error: `CLI adapter not found: ${targetSessionId || cliType || "unknown"}` };
|
|
46302
46375
|
}
|
|
46303
|
-
await adapter.writeRaw(
|
|
46376
|
+
await adapter.writeRaw(cleanData);
|
|
46304
46377
|
return { success: true };
|
|
46305
46378
|
}
|
|
46306
46379
|
function handlePtyResize(_h, args) {
|
|
@@ -47918,6 +47991,8 @@ ${effect.notification.body || ""}`.trim();
|
|
|
47918
47991
|
this.completedDebounceTimer = null;
|
|
47919
47992
|
}, 3e3);
|
|
47920
47993
|
}
|
|
47994
|
+
} else if (newStatus === "idle" && this.lastStatus === "starting") {
|
|
47995
|
+
this.pushEvent({ event: "agent:ready", chatTitle, timestamp: now });
|
|
47921
47996
|
} else if (newStatus === "stopped") {
|
|
47922
47997
|
if (this.generatingDebounceTimer) {
|
|
47923
47998
|
clearTimeout(this.generatingDebounceTimer);
|
|
@@ -49653,9 +49728,6 @@ ${rawInput}` : rawInput;
|
|
|
49653
49728
|
const cliType = String(input.cliType || "").trim();
|
|
49654
49729
|
const cliArgs = Array.isArray(input.cliArgs) ? [...input.cliArgs] : [];
|
|
49655
49730
|
const env2 = { ...input.env || {}, ...COORDINATOR_DELEGATED_ENV_UNSETS };
|
|
49656
|
-
if (cliType === "hermes-cli" && !hasCliArg(cliArgs, "--ignore-user-config")) {
|
|
49657
|
-
cliArgs.unshift("--ignore-user-config");
|
|
49658
|
-
}
|
|
49659
49731
|
if (cliType === "claude-cli" && !hasCliArg(cliArgs, "--mcp-config")) {
|
|
49660
49732
|
cliArgs.unshift("--mcp-config", ensureEmptyDelegatedMcpConfig(input.workspace));
|
|
49661
49733
|
}
|
|
@@ -52970,6 +53042,22 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
52970
53042
|
if (!instructions || !template?.trim()) {
|
|
52971
53043
|
return { kind: "unsupported", reason: "Provider manual MCP setup is missing instructions or template" };
|
|
52972
53044
|
}
|
|
53045
|
+
const renderedTemplate = renderMeshCoordinatorTemplate(template, {
|
|
53046
|
+
meshId,
|
|
53047
|
+
workspace,
|
|
53048
|
+
serverName,
|
|
53049
|
+
adhdevMcpCommand: options.adhdevMcpCommand || DEFAULT_ADHDEV_MCP_COMMAND
|
|
53050
|
+
});
|
|
53051
|
+
const isCliCommand = !renderedTemplate.trim().includes("\n") && !renderedTemplate.trim().startsWith("{");
|
|
53052
|
+
if (isCliCommand) {
|
|
53053
|
+
return {
|
|
53054
|
+
kind: "cli_command",
|
|
53055
|
+
serverName,
|
|
53056
|
+
command: renderedTemplate.trim(),
|
|
53057
|
+
requiresRestart: mcpConfig.requiresRestart === true,
|
|
53058
|
+
instructions
|
|
53059
|
+
};
|
|
53060
|
+
}
|
|
52973
53061
|
return {
|
|
52974
53062
|
kind: "manual",
|
|
52975
53063
|
serverName,
|
|
@@ -52977,12 +53065,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
52977
53065
|
configPathCommand: mcpConfig.configPathCommand,
|
|
52978
53066
|
requiresRestart: mcpConfig.requiresRestart === true,
|
|
52979
53067
|
instructions,
|
|
52980
|
-
template:
|
|
52981
|
-
meshId,
|
|
52982
|
-
workspace,
|
|
52983
|
-
serverName,
|
|
52984
|
-
adhdevMcpCommand: options.adhdevMcpCommand || DEFAULT_ADHDEV_MCP_COMMAND
|
|
52985
|
-
})
|
|
53068
|
+
template: renderedTemplate
|
|
52986
53069
|
};
|
|
52987
53070
|
}
|
|
52988
53071
|
return {
|
|
@@ -55156,6 +55239,93 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
|
|
|
55156
55239
|
meshCoordinatorSetup: coordinatorSetup
|
|
55157
55240
|
};
|
|
55158
55241
|
}
|
|
55242
|
+
if (coordinatorSetup.kind === "cli_command") {
|
|
55243
|
+
let cliCmdSystemPrompt = "";
|
|
55244
|
+
try {
|
|
55245
|
+
cliCmdSystemPrompt = buildCoordinatorSystemPrompt2({ mesh, coordinatorCliType: cliType });
|
|
55246
|
+
} catch (error48) {
|
|
55247
|
+
const message = error48?.message || String(error48);
|
|
55248
|
+
LOG2.error("MeshCoordinator", `Failed to build coordinator prompt: ${message}`);
|
|
55249
|
+
return {
|
|
55250
|
+
success: false,
|
|
55251
|
+
code: "mesh_coordinator_prompt_failed",
|
|
55252
|
+
error: `Failed to build Repo Mesh coordinator prompt: ${message}`,
|
|
55253
|
+
meshId,
|
|
55254
|
+
cliType,
|
|
55255
|
+
workspace
|
|
55256
|
+
};
|
|
55257
|
+
}
|
|
55258
|
+
try {
|
|
55259
|
+
const { execFileSync: execCmdSync } = await import("child_process");
|
|
55260
|
+
const cmdParts = coordinatorSetup.command.trim().split(/\s+/);
|
|
55261
|
+
const [regCmd, ...regArgs] = cmdParts;
|
|
55262
|
+
LOG2.info("MeshCoordinator", `Running MCP registration: ${coordinatorSetup.command}`);
|
|
55263
|
+
execCmdSync(regCmd, regArgs, { stdio: "pipe", timeout: 15e3 });
|
|
55264
|
+
} catch (error48) {
|
|
55265
|
+
LOG2.warn("MeshCoordinator", `MCP registration command failed (may be pre-registered): ${error48?.message || error48}`);
|
|
55266
|
+
}
|
|
55267
|
+
const cliCmdArgs = [];
|
|
55268
|
+
const cliCmdEnv = {};
|
|
55269
|
+
if (cliCmdSystemPrompt) {
|
|
55270
|
+
if (cliType === "codex-cli") {
|
|
55271
|
+
cliCmdArgs.push("-c", `developer_instructions=${JSON.stringify(cliCmdSystemPrompt)}`);
|
|
55272
|
+
} else if (cliType === "gemini-cli") {
|
|
55273
|
+
try {
|
|
55274
|
+
const { writeFileSync: wfs, existsSync: efs, readFileSync: rfs } = await import("fs");
|
|
55275
|
+
const geminiMdPath = `${workspace}/GEMINI.md`;
|
|
55276
|
+
const marker = "<!-- adhdev-mesh-coordinator-prompt -->";
|
|
55277
|
+
const markerEnd = "<!-- /adhdev-mesh-coordinator-prompt -->";
|
|
55278
|
+
const block = `${marker}
|
|
55279
|
+
${cliCmdSystemPrompt}
|
|
55280
|
+
${markerEnd}`;
|
|
55281
|
+
if (efs(geminiMdPath)) {
|
|
55282
|
+
const existing = rfs(geminiMdPath, "utf-8");
|
|
55283
|
+
const replaced = existing.replace(
|
|
55284
|
+
new RegExp(`${marker}[\\s\\S]*?${markerEnd}`, "g"),
|
|
55285
|
+
block
|
|
55286
|
+
);
|
|
55287
|
+
wfs(geminiMdPath, replaced.includes(marker) ? replaced : `${existing}
|
|
55288
|
+
|
|
55289
|
+
${block}`);
|
|
55290
|
+
} else {
|
|
55291
|
+
wfs(geminiMdPath, block);
|
|
55292
|
+
}
|
|
55293
|
+
LOG2.info("MeshCoordinator", `Wrote coordinator prompt to ${workspace}/GEMINI.md`);
|
|
55294
|
+
} catch (e) {
|
|
55295
|
+
LOG2.warn("MeshCoordinator", `Could not write GEMINI.md: ${e?.message || e}`);
|
|
55296
|
+
}
|
|
55297
|
+
}
|
|
55298
|
+
}
|
|
55299
|
+
const cliCmdLaunch = await this.deps.cliManager.handleCliCommand("launch_cli", {
|
|
55300
|
+
cliType,
|
|
55301
|
+
dir: workspace,
|
|
55302
|
+
cliArgs: cliCmdArgs.length > 0 ? cliCmdArgs : void 0,
|
|
55303
|
+
env: Object.keys(cliCmdEnv).length > 0 ? cliCmdEnv : void 0,
|
|
55304
|
+
settings: { meshCoordinatorFor: meshId }
|
|
55305
|
+
});
|
|
55306
|
+
if (!cliCmdLaunch?.success) {
|
|
55307
|
+
return { success: false, error: cliCmdLaunch?.error || "Failed to launch CLI session" };
|
|
55308
|
+
}
|
|
55309
|
+
LOG2.info("MeshCoordinator", `Launched ${cliType} coordinator (cli_command) for mesh ${meshId}`);
|
|
55310
|
+
try {
|
|
55311
|
+
const { appendLedgerEntry: appendLedgerEntry2 } = await Promise.resolve().then(() => (init_mesh_ledger(), mesh_ledger_exports));
|
|
55312
|
+
appendLedgerEntry2(meshId, {
|
|
55313
|
+
kind: "coordinator_started",
|
|
55314
|
+
sessionId: cliCmdLaunch.sessionId || cliCmdLaunch.id,
|
|
55315
|
+
providerType: cliType,
|
|
55316
|
+
payload: { workspace }
|
|
55317
|
+
});
|
|
55318
|
+
} catch {
|
|
55319
|
+
}
|
|
55320
|
+
return {
|
|
55321
|
+
success: true,
|
|
55322
|
+
meshId,
|
|
55323
|
+
cliType,
|
|
55324
|
+
workspace,
|
|
55325
|
+
sessionId: cliCmdLaunch.sessionId || cliCmdLaunch.id,
|
|
55326
|
+
mcpRegistered: true
|
|
55327
|
+
};
|
|
55328
|
+
}
|
|
55159
55329
|
const configFormat = coordinatorSetup.configFormat;
|
|
55160
55330
|
if (configFormat !== "claude_mcp_json" && configFormat !== "hermes_config_yaml") {
|
|
55161
55331
|
return {
|
|
@@ -63202,7 +63372,8 @@ data: ${JSON.stringify(msg.data)}
|
|
|
63202
63372
|
cdpManagers,
|
|
63203
63373
|
sessionRegistry,
|
|
63204
63374
|
detectedIdes: detectedIdesRef,
|
|
63205
|
-
refreshProviderAvailability
|
|
63375
|
+
refreshProviderAvailability,
|
|
63376
|
+
dispatchMeshCommand: config2.dispatchMeshCommand
|
|
63206
63377
|
};
|
|
63207
63378
|
setupMeshEventForwarding(components);
|
|
63208
63379
|
return components;
|