@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
|
@@ -26029,6 +26029,7 @@ function enqueueTask(meshId, message, opts) {
|
|
|
26029
26029
|
message,
|
|
26030
26030
|
status: "pending",
|
|
26031
26031
|
targetNodeId: opts?.targetNodeId,
|
|
26032
|
+
targetSessionId: opts?.targetSessionId,
|
|
26032
26033
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
26033
26034
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
26034
26035
|
};
|
|
@@ -26046,9 +26047,12 @@ function getQueue(meshId, opts) {
|
|
|
26046
26047
|
}
|
|
26047
26048
|
function claimNextTask(meshId, nodeId, sessionId) {
|
|
26048
26049
|
const queue = readQueue(meshId);
|
|
26049
|
-
let targetIdx = queue.findIndex((q) => q.status === "pending" && q.
|
|
26050
|
+
let targetIdx = queue.findIndex((q) => q.status === "pending" && q.targetSessionId === sessionId);
|
|
26050
26051
|
if (targetIdx === -1) {
|
|
26051
|
-
targetIdx = queue.findIndex((q) => q.status === "pending" && !q.
|
|
26052
|
+
targetIdx = queue.findIndex((q) => q.status === "pending" && q.targetNodeId === nodeId && !q.targetSessionId);
|
|
26053
|
+
}
|
|
26054
|
+
if (targetIdx === -1) {
|
|
26055
|
+
targetIdx = queue.findIndex((q) => q.status === "pending" && !q.targetNodeId && !q.targetSessionId);
|
|
26052
26056
|
}
|
|
26053
26057
|
if (targetIdx === -1) return null;
|
|
26054
26058
|
const entry = queue[targetIdx];
|
|
@@ -26256,22 +26260,47 @@ function formatCompletionMetadata(event) {
|
|
|
26256
26260
|
].filter(Boolean);
|
|
26257
26261
|
return parts.length > 0 ? ` (${parts.join("; ")})` : "";
|
|
26258
26262
|
}
|
|
26263
|
+
function getMeshWithCache(components, meshId) {
|
|
26264
|
+
const localMesh = getMesh(meshId);
|
|
26265
|
+
if (localMesh) return localMesh;
|
|
26266
|
+
return components.router?.getCachedInlineMesh(meshId);
|
|
26267
|
+
}
|
|
26259
26268
|
function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType) {
|
|
26260
26269
|
const task = claimNextTask(meshId, nodeId, sessionId);
|
|
26261
|
-
if (!task)
|
|
26270
|
+
if (!task) {
|
|
26271
|
+
return false;
|
|
26272
|
+
}
|
|
26262
26273
|
LOG.info("MeshQueue", `Node ${nodeId} (${sessionId}) pulled task ${task.id}`);
|
|
26274
|
+
const mesh = getMeshWithCache(components, meshId);
|
|
26275
|
+
const node = mesh?.nodes.find((n) => n.id === nodeId);
|
|
26276
|
+
if (node?.daemonId && components.dispatchMeshCommand) {
|
|
26277
|
+
const isLocalNode = components.cliManager.adapters.has(sessionId);
|
|
26278
|
+
if (!isLocalNode) {
|
|
26279
|
+
components.dispatchMeshCommand(node.daemonId, "agent_command", {
|
|
26280
|
+
targetSessionId: sessionId,
|
|
26281
|
+
cliType: providerType,
|
|
26282
|
+
action: "send_chat",
|
|
26283
|
+
message: task.message
|
|
26284
|
+
}).catch((e) => {
|
|
26285
|
+
LOG.error("MeshQueue", `Failed to dispatch task via P2P to remote node ${nodeId}: ${e?.message}`);
|
|
26286
|
+
updateTaskStatus(meshId, task.id, "failed");
|
|
26287
|
+
});
|
|
26288
|
+
return true;
|
|
26289
|
+
}
|
|
26290
|
+
}
|
|
26263
26291
|
components.cliManager.handleCliCommand("agent_command", {
|
|
26264
26292
|
targetSessionId: sessionId,
|
|
26265
26293
|
cliType: providerType,
|
|
26266
26294
|
action: "send_chat",
|
|
26267
|
-
|
|
26295
|
+
message: task.message
|
|
26268
26296
|
}).catch((e) => {
|
|
26269
|
-
LOG.error("MeshQueue", `Failed to dispatch task to node ${nodeId}: ${e?.message}`);
|
|
26297
|
+
LOG.error("MeshQueue", `Failed to dispatch task locally to node ${nodeId}: ${e?.message}`);
|
|
26298
|
+
updateTaskStatus(meshId, task.id, "failed");
|
|
26270
26299
|
});
|
|
26271
26300
|
return true;
|
|
26272
26301
|
}
|
|
26273
26302
|
function triggerMeshQueue(components, meshId) {
|
|
26274
|
-
const mesh =
|
|
26303
|
+
const mesh = getMeshWithCache(components, meshId);
|
|
26275
26304
|
if (!mesh) return;
|
|
26276
26305
|
const cliInstances = components.instanceManager.getByCategory("cli");
|
|
26277
26306
|
for (const inst of cliInstances) {
|
|
@@ -26288,6 +26317,15 @@ function triggerMeshQueue(components, meshId) {
|
|
|
26288
26317
|
tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType);
|
|
26289
26318
|
}
|
|
26290
26319
|
}
|
|
26320
|
+
for (const [key, idle] of remoteIdleSessions.entries()) {
|
|
26321
|
+
const node = mesh.nodes.find((n) => n.id === idle.nodeId);
|
|
26322
|
+
if (node) {
|
|
26323
|
+
const assigned = tryAssignQueueTask(components, meshId, idle.nodeId, idle.sessionId, idle.providerType);
|
|
26324
|
+
if (assigned) {
|
|
26325
|
+
remoteIdleSessions.delete(key);
|
|
26326
|
+
}
|
|
26327
|
+
}
|
|
26328
|
+
}
|
|
26291
26329
|
}
|
|
26292
26330
|
function buildMeshSystemMessage(args) {
|
|
26293
26331
|
const metadata = formatCompletionMetadata(args.metadataEvent);
|
|
@@ -26336,7 +26374,7 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
|
|
|
26336
26374
|
function injectMeshSystemMessage(components, args) {
|
|
26337
26375
|
if (args.event === "agent:generating_completed") {
|
|
26338
26376
|
const sessionId = readNonEmptyString(args.metadataEvent.targetSessionId);
|
|
26339
|
-
const nodeId = readNonEmptyString(args.
|
|
26377
|
+
const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
|
|
26340
26378
|
const providerType = readNonEmptyString(args.metadataEvent.providerType);
|
|
26341
26379
|
if (sessionId) {
|
|
26342
26380
|
updateSessionTaskStatus(args.meshId, sessionId, "completed");
|
|
@@ -26346,8 +26384,31 @@ function injectMeshSystemMessage(components, args) {
|
|
|
26346
26384
|
}, 500);
|
|
26347
26385
|
}
|
|
26348
26386
|
}
|
|
26387
|
+
} else if (args.event === "agent:ready") {
|
|
26388
|
+
const sessionId = readNonEmptyString(args.metadataEvent.targetSessionId);
|
|
26389
|
+
const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
|
|
26390
|
+
const providerType = readNonEmptyString(args.metadataEvent.providerType);
|
|
26391
|
+
if (sessionId && nodeId && providerType) {
|
|
26392
|
+
remoteIdleSessions.set(`${nodeId}:${sessionId}`, { nodeId, sessionId, providerType });
|
|
26393
|
+
setTimeout(() => {
|
|
26394
|
+
const assigned = tryAssignQueueTask(components, args.meshId, nodeId, sessionId, providerType);
|
|
26395
|
+
if (assigned) {
|
|
26396
|
+
remoteIdleSessions.delete(`${nodeId}:${sessionId}`);
|
|
26397
|
+
}
|
|
26398
|
+
}, 500);
|
|
26399
|
+
}
|
|
26400
|
+
} else if (args.event === "agent:generating_started") {
|
|
26401
|
+
const sessionId = readNonEmptyString(args.metadataEvent.targetSessionId);
|
|
26402
|
+
const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
|
|
26403
|
+
if (sessionId && nodeId) {
|
|
26404
|
+
remoteIdleSessions.delete(`${nodeId}:${sessionId}`);
|
|
26405
|
+
}
|
|
26349
26406
|
} else if (args.event === "agent:stopped") {
|
|
26350
26407
|
const sessionId = readNonEmptyString(args.metadataEvent.targetSessionId);
|
|
26408
|
+
const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
|
|
26409
|
+
if (sessionId && nodeId) {
|
|
26410
|
+
remoteIdleSessions.delete(`${nodeId}:${sessionId}`);
|
|
26411
|
+
}
|
|
26351
26412
|
if (sessionId) {
|
|
26352
26413
|
updateSessionTaskStatus(args.meshId, sessionId, "failed");
|
|
26353
26414
|
}
|
|
@@ -26357,7 +26418,7 @@ function injectMeshSystemMessage(components, args) {
|
|
|
26357
26418
|
try {
|
|
26358
26419
|
appendLedgerEntry(args.meshId, {
|
|
26359
26420
|
kind: ledgerKind,
|
|
26360
|
-
nodeId: readNonEmptyString(args.
|
|
26421
|
+
nodeId: readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId) || void 0,
|
|
26361
26422
|
sessionId: readNonEmptyString(args.metadataEvent.targetSessionId) || void 0,
|
|
26362
26423
|
providerType: readNonEmptyString(args.metadataEvent.providerType) || void 0,
|
|
26363
26424
|
payload: {
|
|
@@ -26377,7 +26438,7 @@ function injectMeshSystemMessage(components, args) {
|
|
|
26377
26438
|
const maxRetries = mesh?.policy?.maxTaskRetries ?? 1;
|
|
26378
26439
|
recoveryContext = getSessionRecoveryContext(args.meshId, {
|
|
26379
26440
|
sessionId: readNonEmptyString(args.metadataEvent.targetSessionId) || void 0,
|
|
26380
|
-
nodeId: readNonEmptyString(args.
|
|
26441
|
+
nodeId: readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId) || void 0,
|
|
26381
26442
|
maxRetries
|
|
26382
26443
|
});
|
|
26383
26444
|
recoveryContext.failedProviderType = readNonEmptyString(args.metadataEvent.providerType) || null;
|
|
@@ -26472,6 +26533,7 @@ function handleMeshForwardEvent(components, payload) {
|
|
|
26472
26533
|
const nodeLabel = nodeId ? `Node '${nodeId}'` : workspace ? `Agent at ${workspace}` : "Remote agent";
|
|
26473
26534
|
return injectMeshSystemMessage(components, {
|
|
26474
26535
|
meshId,
|
|
26536
|
+
nodeId,
|
|
26475
26537
|
nodeLabel,
|
|
26476
26538
|
event: eventName,
|
|
26477
26539
|
metadataEvent: {
|
|
@@ -26496,15 +26558,17 @@ function setupMeshEventForwarding(components) {
|
|
|
26496
26558
|
const meshIdFromRuntime = readNonEmptyString(settings.meshNodeFor);
|
|
26497
26559
|
const isMeshDelegate = Boolean(meshIdFromRuntime || settings.launchedByCoordinator);
|
|
26498
26560
|
if (!isMeshDelegate) return;
|
|
26499
|
-
const mesh = meshIdFromRuntime ?
|
|
26561
|
+
const mesh = meshIdFromRuntime ? getMeshWithCache(components, meshIdFromRuntime) : getMeshByRepo(workspace);
|
|
26500
26562
|
const meshId = meshIdFromRuntime || readNonEmptyString(mesh?.id);
|
|
26501
26563
|
if (!meshId) return;
|
|
26502
26564
|
const targetNode = mesh?.nodes?.find((n) => n.workspace === workspace);
|
|
26503
26565
|
const runtimeNodeId = readNonEmptyString(settings.meshNodeId);
|
|
26566
|
+
const resolvedNodeId = targetNode?.id || runtimeNodeId;
|
|
26504
26567
|
const nodeLabel = targetNode ? `Node '${targetNode.id}'` : runtimeNodeId ? `Node '${runtimeNodeId}'` : `Agent at ${workspace}`;
|
|
26505
26568
|
injectMeshSystemMessage(components, {
|
|
26506
26569
|
meshId,
|
|
26507
26570
|
sourceInstanceId: instanceId,
|
|
26571
|
+
nodeId: resolvedNodeId,
|
|
26508
26572
|
nodeLabel,
|
|
26509
26573
|
event: event.event,
|
|
26510
26574
|
metadataEvent: event
|
|
@@ -33701,11 +33765,13 @@ async function handleOpenPanel(h, args) {
|
|
|
33701
33765
|
async function handlePtyInput(h, args) {
|
|
33702
33766
|
const { cliType, data, targetSessionId } = args || {};
|
|
33703
33767
|
if (!data) return { success: false, error: "data required" };
|
|
33768
|
+
const cleanData = typeof data === "string" ? data.replace(/\x1b\[[?>][0-9;]*c/g, "") : data;
|
|
33769
|
+
if (!cleanData) return { success: true };
|
|
33704
33770
|
const adapter = h.getCliAdapter(targetSessionId || cliType);
|
|
33705
33771
|
if (!adapter || typeof adapter.writeRaw !== "function") {
|
|
33706
33772
|
return { success: false, error: `CLI adapter not found: ${targetSessionId || cliType || "unknown"}` };
|
|
33707
33773
|
}
|
|
33708
|
-
await adapter.writeRaw(
|
|
33774
|
+
await adapter.writeRaw(cleanData);
|
|
33709
33775
|
return { success: true };
|
|
33710
33776
|
}
|
|
33711
33777
|
function handlePtyResize(_h, args) {
|
|
@@ -34532,9 +34598,6 @@ function buildCoordinatorDelegatedCliLaunchOptions(input) {
|
|
|
34532
34598
|
const cliType = String(input.cliType || "").trim();
|
|
34533
34599
|
const cliArgs = Array.isArray(input.cliArgs) ? [...input.cliArgs] : [];
|
|
34534
34600
|
const env2 = { ...input.env || {}, ...COORDINATOR_DELEGATED_ENV_UNSETS };
|
|
34535
|
-
if (cliType === "hermes-cli" && !hasCliArg(cliArgs, "--ignore-user-config")) {
|
|
34536
|
-
cliArgs.unshift("--ignore-user-config");
|
|
34537
|
-
}
|
|
34538
34601
|
if (cliType === "claude-cli" && !hasCliArg(cliArgs, "--mcp-config")) {
|
|
34539
34602
|
cliArgs.unshift("--mcp-config", ensureEmptyDelegatedMcpConfig(input.workspace));
|
|
34540
34603
|
}
|
|
@@ -35567,6 +35630,22 @@ function resolveMeshCoordinatorSetup(options) {
|
|
|
35567
35630
|
if (!instructions || !template?.trim()) {
|
|
35568
35631
|
return { kind: "unsupported", reason: "Provider manual MCP setup is missing instructions or template" };
|
|
35569
35632
|
}
|
|
35633
|
+
const renderedTemplate = renderMeshCoordinatorTemplate(template, {
|
|
35634
|
+
meshId,
|
|
35635
|
+
workspace,
|
|
35636
|
+
serverName,
|
|
35637
|
+
adhdevMcpCommand: options.adhdevMcpCommand || DEFAULT_ADHDEV_MCP_COMMAND
|
|
35638
|
+
});
|
|
35639
|
+
const isCliCommand = !renderedTemplate.trim().includes("\n") && !renderedTemplate.trim().startsWith("{");
|
|
35640
|
+
if (isCliCommand) {
|
|
35641
|
+
return {
|
|
35642
|
+
kind: "cli_command",
|
|
35643
|
+
serverName,
|
|
35644
|
+
command: renderedTemplate.trim(),
|
|
35645
|
+
requiresRestart: mcpConfig.requiresRestart === true,
|
|
35646
|
+
instructions
|
|
35647
|
+
};
|
|
35648
|
+
}
|
|
35570
35649
|
return {
|
|
35571
35650
|
kind: "manual",
|
|
35572
35651
|
serverName,
|
|
@@ -35574,12 +35653,7 @@ function resolveMeshCoordinatorSetup(options) {
|
|
|
35574
35653
|
configPathCommand: mcpConfig.configPathCommand,
|
|
35575
35654
|
requiresRestart: mcpConfig.requiresRestart === true,
|
|
35576
35655
|
instructions,
|
|
35577
|
-
template:
|
|
35578
|
-
meshId,
|
|
35579
|
-
workspace,
|
|
35580
|
-
serverName,
|
|
35581
|
-
adhdevMcpCommand: options.adhdevMcpCommand || DEFAULT_ADHDEV_MCP_COMMAND
|
|
35582
|
-
})
|
|
35656
|
+
template: renderedTemplate
|
|
35583
35657
|
};
|
|
35584
35658
|
}
|
|
35585
35659
|
return {
|
|
@@ -40855,7 +40929,8 @@ async function initDaemonComponents(config2) {
|
|
|
40855
40929
|
cdpManagers,
|
|
40856
40930
|
sessionRegistry,
|
|
40857
40931
|
detectedIdes: detectedIdesRef,
|
|
40858
|
-
refreshProviderAvailability
|
|
40932
|
+
refreshProviderAvailability,
|
|
40933
|
+
dispatchMeshCommand: config2.dispatchMeshCommand
|
|
40859
40934
|
};
|
|
40860
40935
|
setupMeshEventForwarding(components);
|
|
40861
40936
|
return components;
|
|
@@ -40913,7 +40988,7 @@ async function shutdownDaemonComponents(components) {
|
|
|
40913
40988
|
}
|
|
40914
40989
|
cdpManagers.clear();
|
|
40915
40990
|
}
|
|
40916
|
-
var path4, import_promises4, import_fs3, import_child_process, import_util3, import_os2, import_path, import_fs4, import_crypto2, import_fs5, import_path2, import_crypto3, import_fs6, import_path3, import_crypto4, import_events2, import_fs7, import_path4, import_crypto5, fs2, path8, os22, os8, os9, path14, import_child_process2, os10, path15, os11, import_child_process3, import_fs8, import_promises5, path, import_util4, import_promises6, path22, path32, fs, os4, path5, import_crypto6, path6, path7, import_fs9, import_path5, import_child_process4, import_fs10, import_os3, path9, import_child_process5, os32, path10, import_fs11, os42, import_child_process6, http, crypto2, fs3, path11, os5, fs4, os6, path12, import_crypto7, fs5, path13, os7, os13, path18, crypto4, import_fs12, import_child_process7, os12, path16, crypto3, fs6, import_module, path17, import_stream2, import_child_process8, import_child_process9, net2, os15, path20, fs7, path19, os14, fs8, path21, os16, import_child_process10, import_crypto8, import_fs13, import_module2, os17, import_path6, os18, import_child_process11, import_child_process12, fs9, os19, path222, import_os4, import_path7, fs10, fs11, path23, os20, import_child_process13, import_os5, http2, fs15, path27, fs12, path24, fs13, path25, fs14, path26, os21, import_child_process14, __defProp2, __getOwnPropDesc2, __getOwnPropNames2, __hasOwnProp2, __require2, __esm2, __export2, __copyProps2, __toCommonJS2, DEFAULT_MESH_POLICY, init_repo_mesh_types, git_worktree_exports, execFileAsync2, WORKTREE_DIR_NAME, GIT_TIMEOUT_MS, GIT_MAX_BUFFER, init_git_worktree, config_exports, DEFAULT_CONFIG, MACHINE_ID_PREFIX, init_config, mesh_config_exports, SESSION_CLEANUP_MODES, SPAWNED_SESSION_VISIBILITY_MODES, init_mesh_config, coordinator_prompt_exports, TOOLS_SECTION, TOOL_EXPOSURE_PREFLIGHT_SECTION, WORKFLOW_SECTION, init_coordinator_prompt, mesh_ledger_exports, LEDGER_DIR_NAME, MAX_FILE_SIZE_BYTES, RECENT_FAILURE_WINDOW_MS, meshLedgerEvents, init_mesh_ledger, init_mesh_work_queue, LEVEL_NUM, LEVEL_LABEL, currentLevel, LOG_DIR, MAX_LOG_SIZE, MAX_LOG_DAYS, currentDate, currentLogFile, writeCount, RING_BUFFER_SIZE, ringBuffer, origConsoleLog, origConsoleError, origConsoleWarn, LOG, interceptorInstalled, LOG_PATH, init_logger, mesh_events_exports, MAX_PENDING_EVENTS, pendingMeshCoordinatorEvents, MESH_COORDINATOR_EVENTS, EVENT_TO_LEDGER_KIND, init_mesh_events, NORMAL_TRACE_BUFFER_SIZE, DEV_TRACE_BUFFER_SIZE, DEFAULT_CONFIG2, currentConfig, init_debug_config, DEFAULT_BINDING_CANDIDATES, cachedBinding, cachedBindingError, GhosttyVtTerminalBackend, init_ghostty_vt_backend, TerminalCtor, XtermTerminalBackend, init_xterm_backend, DEFAULT_SCROLLBACK, loggedTerminalBackends, TerminalScreen, init_terminal_screen, init_spawn_env, cachedPty, NodePtyRuntimeTransport, NodePtyTransportFactory, init_pty_transport, TerminalTranscriptAccumulator, buildCliSpawnEnv, init_provider_cli_shared, init_provider_cli_parse, init_provider_cli_config, init_provider_cli_runtime, provider_cli_adapter_exports, ProviderCliAdapter, init_provider_cli_adapter, execFileAsync, DEFAULT_TIMEOUT_MS, DEFAULT_MAX_BUFFER, GitCommandError, DEFAULT_MAX_FILES, DEFAULT_MAX_BYTES, summarizeGitStatus, InMemoryGitSnapshotStore, DEFAULT_GIT_WORKSPACE_POLL_INTERVAL_MS, MIN_GIT_WORKSPACE_POLL_INTERVAL_MS, GitWorkspaceMonitor, GIT_COMMAND_NAMES, SNAPSHOT_REASONS, FAILURE_REASONS, defaultSnapshotStore, defaultGitCommandServices, BUSY_STATUSES, TERMINAL_STATUSES, TurnSnapshotTracker, MAX_WORKSPACES, MAX_ACTIVITY, MAX_SAVED_SESSIONS, DEFAULT_STATE, BUILTIN_IDE_DEFINITIONS, registeredIDEs, LIVE_LIFECYCLES, DEFAULT_ACTIVE_CHAT_POLL_STATUSES, DEFAULT_CHAT_TAIL_RECENT_MESSAGE_GRACE_MS, LIVE_RUNTIME_LIFECYCLES, DaemonCdpManager, CdpDomHandlers, DEFAULT_MONITOR_CONFIG, StatusMonitor, BUILTIN_CHAT_MESSAGE_KINDS, CHAT_MESSAGE_VISIBILITIES, CHAT_MESSAGE_TRANSCRIPT_VISIBILITIES, CHAT_MESSAGE_AUDIENCES, CHAT_MESSAGE_SOURCES, CHAT_MESSAGE_ACTIVITY_SOURCES, CHAT_MESSAGE_INTERNAL_SOURCES, KNOWN_CHAT_MESSAGE_KINDS, CHAT_MESSAGE_KIND_ALIASES, EXPLICIT_HIDDEN_VISIBILITIES, EXPLICIT_VISIBLE_VISIBILITIES, HIDDEN_AUDIENCES, ACTIVITY_SOURCE_SET, INTERNAL_SOURCE_SET, HISTORY_DIR, RETAIN_DAYS, SAVED_HISTORY_INDEX_VERSION, SAVED_HISTORY_INDEX_FILE, SAVED_HISTORY_INDEX_LOCK_SUFFIX, SAVED_HISTORY_INDEX_LOCK_WAIT_MS, SAVED_HISTORY_INDEX_LOCK_STALE_MS, SAVED_HISTORY_INDEX_LOCK_POLL_MS, SAVED_HISTORY_ROLLUP_THRESHOLD_BYTES, savedHistorySessionCache, savedHistoryFileSummaryCache, savedHistoryBackgroundRefresh, savedHistoryRollupInFlight, ChatHistoryWriter, IDE_PROVIDER_SESSION_CAPABILITIES_BASE, EXTENSION_PROVIDER_SESSION_CAPABILITIES_BASE, ExtensionProviderInstance, VALID_STATUSES, VALID_ROLES, VALID_BUBBLE_STATES, VALID_TURN_STATUSES, DEFAULT_APPROVAL_POSITIVE_HINTS, IdeProviderInstance, DEFAULT_CDP_SCAN_INTERVAL_MS, DEFAULT_CDP_DISCOVERY_INTERVAL_MS, DEFAULT_STATUS_INITIAL_REPORT_DELAY_MS, DEFAULT_STATUS_SERVER_REPORT_INTERVAL_MS, DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS, MIN_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS, DEFAULT_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS, MIN_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS, DEFAULT_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS, DEFAULT_SESSION_HOST_READY_TIMEOUT_MS, STANDALONE_CDP_SCAN_INTERVAL_MS, DaemonCdpScanner, DaemonCdpInitializer, WORKING_STATUSES, FULL_STATUS_ACTIVE_CHAT_OPTIONS, LIVE_STATUS_ACTIVE_CHAT_OPTIONS, STATUS_MODAL_MESSAGE_LIMIT, STATUS_MODAL_BUTTON_LIMIT, VALID_INPUT_MEDIA_TYPES, VALID_INPUT_STRATEGIES, TEXT_ONLY_MESSAGE_INPUT_SUPPORT, IDE_SESSION_CAPABILITIES, EXTENSION_SESSION_CAPABILITIES, PTY_SESSION_CAPABILITIES, CLI_CHAT_SESSION_CAPABILITIES, ACP_SESSION_CAPABILITIES, globalStore, RECENT_SEND_WINDOW_MS, READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS, HERMES_CLI_STARTING_SEND_SETTLE_MS, recentSendByTarget, DEFAULT_DEBUG_SANITIZE_OPTIONS, SECRET_KEY_PATTERN, KEY_TO_VK, COMMAND_DEBUG_LEVELS, DaemonCommandHandler, IMAGE_MIME_EXTENSIONS, MATERIALIZED_IMAGE_MAX_AGE_MS, MATERIALIZED_IMAGE_CLEANUP_INTERVAL_MS, lastMaterializedImageCleanupAt, CachedDatabaseSync, CliProviderInstance, AcpProviderInstance, chalkModule, chalkApi, COORDINATOR_DELEGATED_ENV_UNSETS, DaemonCliManager, VALID_CAPABILITY_MEDIA_TYPES, VALID_INPUT_STRATEGIES2, KNOWN_PROVIDER_FIELDS, VALUE_CONTROL_TYPES, ProviderLoader, _providerLoader, LOG_DIR2, MAX_FILE_SIZE, MAX_DAYS, SENSITIVE_KEYS, currentDate2, currentFile, writeCount2, SKIP_COMMANDS, DEFAULT_SERVER_NAME, DEFAULT_ADHDEV_MCP_COMMAND, HERMES_CLI_TYPE, HERMES_MCP_CONFIG_PATH, READ_DEBUG_ENABLED, recentReadDebugSignatureBySession, UPGRADE_HELPER_ENV, CHANNEL_NPM_TAG, CHANNEL_SERVER_URL, CHAT_COMMANDS, READ_DEBUG_ENABLED2, DaemonCommandRouter, DaemonStatusReporter, DEFAULT_DAEMON_PORT, DAEMON_WS_PATH, ProviderStreamAdapter, DaemonAgentStreamManager, AgentStreamPoller, ProviderInstanceManager, ARCHIVE_PATH, MAX_ENTRIES_PER_PROVIDER, VersionArchive, DEV_SERVER_PORT, DevServer, SessionHostRuntimeTransport, SessionHostPtyTransportFactory, DEFAULT_SESSION_HOST_APP_NAME, DEFAULT_STANDALONE_SESSION_HOST_APP_NAME, STARTUP_TIMEOUT_MS, STARTUP_POLL_MS, SessionHostCompatibilityError, EXTENSION_CATALOG, SessionRegistry;
|
|
40991
|
+
var path4, import_promises4, import_fs3, import_child_process, import_util3, import_os2, import_path, import_fs4, import_crypto2, import_fs5, import_path2, import_crypto3, import_fs6, import_path3, import_crypto4, import_events2, import_fs7, import_path4, import_crypto5, fs2, path8, os22, os8, os9, path14, import_child_process2, os10, path15, os11, import_child_process3, import_fs8, import_promises5, path, import_util4, import_promises6, path22, path32, fs, os4, path5, import_crypto6, path6, path7, import_fs9, import_path5, import_child_process4, import_fs10, import_os3, path9, import_child_process5, os32, path10, import_fs11, os42, import_child_process6, http, crypto2, fs3, path11, os5, fs4, os6, path12, import_crypto7, fs5, path13, os7, os13, path18, crypto4, import_fs12, import_child_process7, os12, path16, crypto3, fs6, import_module, path17, import_stream2, import_child_process8, import_child_process9, net2, os15, path20, fs7, path19, os14, fs8, path21, os16, import_child_process10, import_crypto8, import_fs13, import_module2, os17, import_path6, os18, import_child_process11, import_child_process12, fs9, os19, path222, import_os4, import_path7, fs10, fs11, path23, os20, import_child_process13, import_os5, http2, fs15, path27, fs12, path24, fs13, path25, fs14, path26, os21, import_child_process14, __defProp2, __getOwnPropDesc2, __getOwnPropNames2, __hasOwnProp2, __require2, __esm2, __export2, __copyProps2, __toCommonJS2, DEFAULT_MESH_POLICY, init_repo_mesh_types, git_worktree_exports, execFileAsync2, WORKTREE_DIR_NAME, GIT_TIMEOUT_MS, GIT_MAX_BUFFER, init_git_worktree, config_exports, DEFAULT_CONFIG, MACHINE_ID_PREFIX, init_config, mesh_config_exports, SESSION_CLEANUP_MODES, SPAWNED_SESSION_VISIBILITY_MODES, init_mesh_config, coordinator_prompt_exports, TOOLS_SECTION, TOOL_EXPOSURE_PREFLIGHT_SECTION, WORKFLOW_SECTION, init_coordinator_prompt, mesh_ledger_exports, LEDGER_DIR_NAME, MAX_FILE_SIZE_BYTES, RECENT_FAILURE_WINDOW_MS, meshLedgerEvents, init_mesh_ledger, init_mesh_work_queue, LEVEL_NUM, LEVEL_LABEL, currentLevel, LOG_DIR, MAX_LOG_SIZE, MAX_LOG_DAYS, currentDate, currentLogFile, writeCount, RING_BUFFER_SIZE, ringBuffer, origConsoleLog, origConsoleError, origConsoleWarn, LOG, interceptorInstalled, LOG_PATH, init_logger, mesh_events_exports, remoteIdleSessions, MAX_PENDING_EVENTS, pendingMeshCoordinatorEvents, MESH_COORDINATOR_EVENTS, EVENT_TO_LEDGER_KIND, init_mesh_events, NORMAL_TRACE_BUFFER_SIZE, DEV_TRACE_BUFFER_SIZE, DEFAULT_CONFIG2, currentConfig, init_debug_config, DEFAULT_BINDING_CANDIDATES, cachedBinding, cachedBindingError, GhosttyVtTerminalBackend, init_ghostty_vt_backend, TerminalCtor, XtermTerminalBackend, init_xterm_backend, DEFAULT_SCROLLBACK, loggedTerminalBackends, TerminalScreen, init_terminal_screen, init_spawn_env, cachedPty, NodePtyRuntimeTransport, NodePtyTransportFactory, init_pty_transport, TerminalTranscriptAccumulator, buildCliSpawnEnv, init_provider_cli_shared, init_provider_cli_parse, init_provider_cli_config, init_provider_cli_runtime, provider_cli_adapter_exports, ProviderCliAdapter, init_provider_cli_adapter, execFileAsync, DEFAULT_TIMEOUT_MS, DEFAULT_MAX_BUFFER, GitCommandError, DEFAULT_MAX_FILES, DEFAULT_MAX_BYTES, summarizeGitStatus, InMemoryGitSnapshotStore, DEFAULT_GIT_WORKSPACE_POLL_INTERVAL_MS, MIN_GIT_WORKSPACE_POLL_INTERVAL_MS, GitWorkspaceMonitor, GIT_COMMAND_NAMES, SNAPSHOT_REASONS, FAILURE_REASONS, defaultSnapshotStore, defaultGitCommandServices, BUSY_STATUSES, TERMINAL_STATUSES, TurnSnapshotTracker, MAX_WORKSPACES, MAX_ACTIVITY, MAX_SAVED_SESSIONS, DEFAULT_STATE, BUILTIN_IDE_DEFINITIONS, registeredIDEs, LIVE_LIFECYCLES, DEFAULT_ACTIVE_CHAT_POLL_STATUSES, DEFAULT_CHAT_TAIL_RECENT_MESSAGE_GRACE_MS, LIVE_RUNTIME_LIFECYCLES, DaemonCdpManager, CdpDomHandlers, DEFAULT_MONITOR_CONFIG, StatusMonitor, BUILTIN_CHAT_MESSAGE_KINDS, CHAT_MESSAGE_VISIBILITIES, CHAT_MESSAGE_TRANSCRIPT_VISIBILITIES, CHAT_MESSAGE_AUDIENCES, CHAT_MESSAGE_SOURCES, CHAT_MESSAGE_ACTIVITY_SOURCES, CHAT_MESSAGE_INTERNAL_SOURCES, KNOWN_CHAT_MESSAGE_KINDS, CHAT_MESSAGE_KIND_ALIASES, EXPLICIT_HIDDEN_VISIBILITIES, EXPLICIT_VISIBLE_VISIBILITIES, HIDDEN_AUDIENCES, ACTIVITY_SOURCE_SET, INTERNAL_SOURCE_SET, HISTORY_DIR, RETAIN_DAYS, SAVED_HISTORY_INDEX_VERSION, SAVED_HISTORY_INDEX_FILE, SAVED_HISTORY_INDEX_LOCK_SUFFIX, SAVED_HISTORY_INDEX_LOCK_WAIT_MS, SAVED_HISTORY_INDEX_LOCK_STALE_MS, SAVED_HISTORY_INDEX_LOCK_POLL_MS, SAVED_HISTORY_ROLLUP_THRESHOLD_BYTES, savedHistorySessionCache, savedHistoryFileSummaryCache, savedHistoryBackgroundRefresh, savedHistoryRollupInFlight, ChatHistoryWriter, IDE_PROVIDER_SESSION_CAPABILITIES_BASE, EXTENSION_PROVIDER_SESSION_CAPABILITIES_BASE, ExtensionProviderInstance, VALID_STATUSES, VALID_ROLES, VALID_BUBBLE_STATES, VALID_TURN_STATUSES, DEFAULT_APPROVAL_POSITIVE_HINTS, IdeProviderInstance, DEFAULT_CDP_SCAN_INTERVAL_MS, DEFAULT_CDP_DISCOVERY_INTERVAL_MS, DEFAULT_STATUS_INITIAL_REPORT_DELAY_MS, DEFAULT_STATUS_SERVER_REPORT_INTERVAL_MS, DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS, MIN_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS, DEFAULT_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS, MIN_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS, DEFAULT_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS, DEFAULT_SESSION_HOST_READY_TIMEOUT_MS, STANDALONE_CDP_SCAN_INTERVAL_MS, DaemonCdpScanner, DaemonCdpInitializer, WORKING_STATUSES, FULL_STATUS_ACTIVE_CHAT_OPTIONS, LIVE_STATUS_ACTIVE_CHAT_OPTIONS, STATUS_MODAL_MESSAGE_LIMIT, STATUS_MODAL_BUTTON_LIMIT, VALID_INPUT_MEDIA_TYPES, VALID_INPUT_STRATEGIES, TEXT_ONLY_MESSAGE_INPUT_SUPPORT, IDE_SESSION_CAPABILITIES, EXTENSION_SESSION_CAPABILITIES, PTY_SESSION_CAPABILITIES, CLI_CHAT_SESSION_CAPABILITIES, ACP_SESSION_CAPABILITIES, globalStore, RECENT_SEND_WINDOW_MS, READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS, HERMES_CLI_STARTING_SEND_SETTLE_MS, recentSendByTarget, DEFAULT_DEBUG_SANITIZE_OPTIONS, SECRET_KEY_PATTERN, KEY_TO_VK, COMMAND_DEBUG_LEVELS, DaemonCommandHandler, IMAGE_MIME_EXTENSIONS, MATERIALIZED_IMAGE_MAX_AGE_MS, MATERIALIZED_IMAGE_CLEANUP_INTERVAL_MS, lastMaterializedImageCleanupAt, CachedDatabaseSync, CliProviderInstance, AcpProviderInstance, chalkModule, chalkApi, COORDINATOR_DELEGATED_ENV_UNSETS, DaemonCliManager, VALID_CAPABILITY_MEDIA_TYPES, VALID_INPUT_STRATEGIES2, KNOWN_PROVIDER_FIELDS, VALUE_CONTROL_TYPES, ProviderLoader, _providerLoader, LOG_DIR2, MAX_FILE_SIZE, MAX_DAYS, SENSITIVE_KEYS, currentDate2, currentFile, writeCount2, SKIP_COMMANDS, DEFAULT_SERVER_NAME, DEFAULT_ADHDEV_MCP_COMMAND, HERMES_CLI_TYPE, HERMES_MCP_CONFIG_PATH, READ_DEBUG_ENABLED, recentReadDebugSignatureBySession, UPGRADE_HELPER_ENV, CHANNEL_NPM_TAG, CHANNEL_SERVER_URL, CHAT_COMMANDS, READ_DEBUG_ENABLED2, DaemonCommandRouter, DaemonStatusReporter, DEFAULT_DAEMON_PORT, DAEMON_WS_PATH, ProviderStreamAdapter, DaemonAgentStreamManager, AgentStreamPoller, ProviderInstanceManager, ARCHIVE_PATH, MAX_ENTRIES_PER_PROVIDER, VersionArchive, DEV_SERVER_PORT, DevServer, SessionHostRuntimeTransport, SessionHostPtyTransportFactory, DEFAULT_SESSION_HOST_APP_NAME, DEFAULT_STANDALONE_SESSION_HOST_APP_NAME, STARTUP_TIMEOUT_MS, STARTUP_POLL_MS, SessionHostCompatibilityError, EXTENSION_CATALOG, SessionRegistry;
|
|
40917
40992
|
var init_dist2 = __esm({
|
|
40918
40993
|
"../daemon-core/dist/index.mjs"() {
|
|
40919
40994
|
"use strict";
|
|
@@ -41325,12 +41400,14 @@ Follow these recovery rules:
|
|
|
41325
41400
|
init_logger();
|
|
41326
41401
|
init_mesh_ledger();
|
|
41327
41402
|
init_mesh_work_queue();
|
|
41403
|
+
remoteIdleSessions = /* @__PURE__ */ new Map();
|
|
41328
41404
|
MAX_PENDING_EVENTS = 50;
|
|
41329
41405
|
pendingMeshCoordinatorEvents = [];
|
|
41330
41406
|
MESH_COORDINATOR_EVENTS = /* @__PURE__ */ new Set([
|
|
41331
41407
|
"agent:generating_completed",
|
|
41332
41408
|
"agent:waiting_approval",
|
|
41333
41409
|
"agent:stopped",
|
|
41410
|
+
"agent:ready",
|
|
41334
41411
|
"monitor:long_generating"
|
|
41335
41412
|
]);
|
|
41336
41413
|
EVENT_TO_LEDGER_KIND = {
|
|
@@ -41865,6 +41942,8 @@ Follow these recovery rules:
|
|
|
41865
41942
|
statusHistory = [];
|
|
41866
41943
|
// ─── CLI Scripts (script-based parsing) ───
|
|
41867
41944
|
cliScripts;
|
|
41945
|
+
/** Per-session opaque state object created by cliScripts.createState(), reset on stop. */
|
|
41946
|
+
scriptState = null;
|
|
41868
41947
|
runtimeSettings = {};
|
|
41869
41948
|
/** Full accumulated rendered PTY transcript for parser/readback use */
|
|
41870
41949
|
accumulatedBuffer = "";
|
|
@@ -42046,6 +42125,7 @@ ${lastSnapshot}`;
|
|
|
42046
42125
|
this.cliScripts = scripts;
|
|
42047
42126
|
this.parsedStatusCache = null;
|
|
42048
42127
|
this.parseErrorMessage = null;
|
|
42128
|
+
this.scriptState = typeof scripts.createState === "function" ? scripts.createState() : null;
|
|
42049
42129
|
const scriptNames = listCliScriptNames(scripts);
|
|
42050
42130
|
LOG.info("CLI", `[${this.cliType}] CLI scripts injected: [${scriptNames.join(", ")}]`);
|
|
42051
42131
|
}
|
|
@@ -42163,6 +42243,7 @@ ${lastSnapshot}`;
|
|
|
42163
42243
|
this.ready = false;
|
|
42164
42244
|
this.startupParseGate = false;
|
|
42165
42245
|
this.spawnAt = 0;
|
|
42246
|
+
this.scriptState = null;
|
|
42166
42247
|
this.onStatusChange?.();
|
|
42167
42248
|
});
|
|
42168
42249
|
this.spawnAt = Date.now();
|
|
@@ -42936,7 +43017,7 @@ ${lastSnapshot}`;
|
|
|
42936
43017
|
scope: this.currentTurnScope,
|
|
42937
43018
|
runtimeSettings: this.runtimeSettings
|
|
42938
43019
|
});
|
|
42939
|
-
const session = this.cliScripts.parseSession({ ...input, tail, tailScreen: buildCliScreenSnapshot(tail) });
|
|
43020
|
+
const session = this.cliScripts.parseSession(this.scriptState, { ...input, tail, tailScreen: buildCliScreenSnapshot(tail) });
|
|
42940
43021
|
this.parseErrorMessage = null;
|
|
42941
43022
|
return session && typeof session === "object" ? session : null;
|
|
42942
43023
|
} catch (e) {
|
|
@@ -42950,7 +43031,7 @@ ${lastSnapshot}`;
|
|
|
42950
43031
|
if (!this.cliScripts?.detectStatus) return null;
|
|
42951
43032
|
try {
|
|
42952
43033
|
const screenText = this.terminalScreen.getText();
|
|
42953
|
-
const status = this.cliScripts.detectStatus({
|
|
43034
|
+
const status = this.cliScripts.detectStatus(this.scriptState, {
|
|
42954
43035
|
tail: text.slice(-500),
|
|
42955
43036
|
screenText,
|
|
42956
43037
|
rawBuffer: this.accumulatedRawBuffer,
|
|
@@ -42969,7 +43050,7 @@ ${lastSnapshot}`;
|
|
|
42969
43050
|
try {
|
|
42970
43051
|
const screenText = this.terminalScreen.getText();
|
|
42971
43052
|
const buffer = screenText || this.accumulatedBuffer;
|
|
42972
|
-
return this.cliScripts.parseApproval({
|
|
43053
|
+
return this.cliScripts.parseApproval(this.scriptState, {
|
|
42973
43054
|
buffer,
|
|
42974
43055
|
screenText,
|
|
42975
43056
|
rawBuffer: this.accumulatedRawBuffer,
|
|
@@ -43077,7 +43158,7 @@ ${lastSnapshot}`;
|
|
|
43077
43158
|
scope: this.currentTurnScope,
|
|
43078
43159
|
runtimeSettings: this.runtimeSettings
|
|
43079
43160
|
});
|
|
43080
|
-
return await Promise.resolve(fn({
|
|
43161
|
+
return await Promise.resolve(fn(this.scriptState, {
|
|
43081
43162
|
...input,
|
|
43082
43163
|
args: args && typeof args === "object" ? { ...args } : {}
|
|
43083
43164
|
}));
|
|
@@ -48296,6 +48377,8 @@ ${effect.notification.body || ""}`.trim();
|
|
|
48296
48377
|
this.completedDebounceTimer = null;
|
|
48297
48378
|
}, 3e3);
|
|
48298
48379
|
}
|
|
48380
|
+
} else if (newStatus === "idle" && this.lastStatus === "starting") {
|
|
48381
|
+
this.pushEvent({ event: "agent:ready", chatTitle, timestamp: now });
|
|
48299
48382
|
} else if (newStatus === "stopped") {
|
|
48300
48383
|
if (this.generatingDebounceTimer) {
|
|
48301
48384
|
clearTimeout(this.generatingDebounceTimer);
|
|
@@ -53342,6 +53425,93 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
53342
53425
|
meshCoordinatorSetup: coordinatorSetup
|
|
53343
53426
|
};
|
|
53344
53427
|
}
|
|
53428
|
+
if (coordinatorSetup.kind === "cli_command") {
|
|
53429
|
+
let cliCmdSystemPrompt = "";
|
|
53430
|
+
try {
|
|
53431
|
+
cliCmdSystemPrompt = buildCoordinatorSystemPrompt2({ mesh, coordinatorCliType: cliType });
|
|
53432
|
+
} catch (error48) {
|
|
53433
|
+
const message = error48?.message || String(error48);
|
|
53434
|
+
LOG.error("MeshCoordinator", `Failed to build coordinator prompt: ${message}`);
|
|
53435
|
+
return {
|
|
53436
|
+
success: false,
|
|
53437
|
+
code: "mesh_coordinator_prompt_failed",
|
|
53438
|
+
error: `Failed to build Repo Mesh coordinator prompt: ${message}`,
|
|
53439
|
+
meshId,
|
|
53440
|
+
cliType,
|
|
53441
|
+
workspace
|
|
53442
|
+
};
|
|
53443
|
+
}
|
|
53444
|
+
try {
|
|
53445
|
+
const { execFileSync: execCmdSync } = await import("child_process");
|
|
53446
|
+
const cmdParts = coordinatorSetup.command.trim().split(/\s+/);
|
|
53447
|
+
const [regCmd, ...regArgs] = cmdParts;
|
|
53448
|
+
LOG.info("MeshCoordinator", `Running MCP registration: ${coordinatorSetup.command}`);
|
|
53449
|
+
execCmdSync(regCmd, regArgs, { stdio: "pipe", timeout: 15e3 });
|
|
53450
|
+
} catch (error48) {
|
|
53451
|
+
LOG.warn("MeshCoordinator", `MCP registration command failed (may be pre-registered): ${error48?.message || error48}`);
|
|
53452
|
+
}
|
|
53453
|
+
const cliCmdArgs = [];
|
|
53454
|
+
const cliCmdEnv = {};
|
|
53455
|
+
if (cliCmdSystemPrompt) {
|
|
53456
|
+
if (cliType === "codex-cli") {
|
|
53457
|
+
cliCmdArgs.push("-c", `developer_instructions=${JSON.stringify(cliCmdSystemPrompt)}`);
|
|
53458
|
+
} else if (cliType === "gemini-cli") {
|
|
53459
|
+
try {
|
|
53460
|
+
const { writeFileSync: wfs, existsSync: efs, readFileSync: rfs } = await import("fs");
|
|
53461
|
+
const geminiMdPath = `${workspace}/GEMINI.md`;
|
|
53462
|
+
const marker = "<!-- adhdev-mesh-coordinator-prompt -->";
|
|
53463
|
+
const markerEnd = "<!-- /adhdev-mesh-coordinator-prompt -->";
|
|
53464
|
+
const block = `${marker}
|
|
53465
|
+
${cliCmdSystemPrompt}
|
|
53466
|
+
${markerEnd}`;
|
|
53467
|
+
if (efs(geminiMdPath)) {
|
|
53468
|
+
const existing = rfs(geminiMdPath, "utf-8");
|
|
53469
|
+
const replaced = existing.replace(
|
|
53470
|
+
new RegExp(`${marker}[\\s\\S]*?${markerEnd}`, "g"),
|
|
53471
|
+
block
|
|
53472
|
+
);
|
|
53473
|
+
wfs(geminiMdPath, replaced.includes(marker) ? replaced : `${existing}
|
|
53474
|
+
|
|
53475
|
+
${block}`);
|
|
53476
|
+
} else {
|
|
53477
|
+
wfs(geminiMdPath, block);
|
|
53478
|
+
}
|
|
53479
|
+
LOG.info("MeshCoordinator", `Wrote coordinator prompt to ${workspace}/GEMINI.md`);
|
|
53480
|
+
} catch (e) {
|
|
53481
|
+
LOG.warn("MeshCoordinator", `Could not write GEMINI.md: ${e?.message || e}`);
|
|
53482
|
+
}
|
|
53483
|
+
}
|
|
53484
|
+
}
|
|
53485
|
+
const cliCmdLaunch = await this.deps.cliManager.handleCliCommand("launch_cli", {
|
|
53486
|
+
cliType,
|
|
53487
|
+
dir: workspace,
|
|
53488
|
+
cliArgs: cliCmdArgs.length > 0 ? cliCmdArgs : void 0,
|
|
53489
|
+
env: Object.keys(cliCmdEnv).length > 0 ? cliCmdEnv : void 0,
|
|
53490
|
+
settings: { meshCoordinatorFor: meshId }
|
|
53491
|
+
});
|
|
53492
|
+
if (!cliCmdLaunch?.success) {
|
|
53493
|
+
return { success: false, error: cliCmdLaunch?.error || "Failed to launch CLI session" };
|
|
53494
|
+
}
|
|
53495
|
+
LOG.info("MeshCoordinator", `Launched ${cliType} coordinator (cli_command) for mesh ${meshId}`);
|
|
53496
|
+
try {
|
|
53497
|
+
const { appendLedgerEntry: appendLedgerEntry2 } = await Promise.resolve().then(() => (init_mesh_ledger(), mesh_ledger_exports));
|
|
53498
|
+
appendLedgerEntry2(meshId, {
|
|
53499
|
+
kind: "coordinator_started",
|
|
53500
|
+
sessionId: cliCmdLaunch.sessionId || cliCmdLaunch.id,
|
|
53501
|
+
providerType: cliType,
|
|
53502
|
+
payload: { workspace }
|
|
53503
|
+
});
|
|
53504
|
+
} catch {
|
|
53505
|
+
}
|
|
53506
|
+
return {
|
|
53507
|
+
success: true,
|
|
53508
|
+
meshId,
|
|
53509
|
+
cliType,
|
|
53510
|
+
workspace,
|
|
53511
|
+
sessionId: cliCmdLaunch.sessionId || cliCmdLaunch.id,
|
|
53512
|
+
mcpRegistered: true
|
|
53513
|
+
};
|
|
53514
|
+
}
|
|
53345
53515
|
const configFormat = coordinatorSetup.configFormat;
|
|
53346
53516
|
if (configFormat !== "claude_mcp_json" && configFormat !== "hermes_config_yaml") {
|
|
53347
53517
|
return {
|
|
@@ -57300,12 +57470,60 @@ function extractGitDiff(value) {
|
|
|
57300
57470
|
function extractLaunchPayload(value) {
|
|
57301
57471
|
return findNestedPayload(value, (payload) => Boolean(payload?.sessionId || payload?.id || payload?.runtimeSessionId));
|
|
57302
57472
|
}
|
|
57473
|
+
async function ipcDispatchToRemoteAgent(ctx, node, args) {
|
|
57474
|
+
const transport = ctx.transport;
|
|
57475
|
+
const daemonId = node.daemonId;
|
|
57476
|
+
let sessionId = args.session_id?.trim() || "";
|
|
57477
|
+
const providerPriorityList = Array.isArray(node.policy?.providerPriority) ? node.policy.providerPriority : [];
|
|
57478
|
+
let resolvedProviderType = args.providerType?.trim() || providerPriorityList[0] || "";
|
|
57479
|
+
if (!sessionId) {
|
|
57480
|
+
try {
|
|
57481
|
+
const relayResult = await transport.meshCommand(daemonId, "get_status_metadata", {});
|
|
57482
|
+
const innerResult = relayResult?.result ?? relayResult;
|
|
57483
|
+
const statusObj = innerResult?.status ?? innerResult;
|
|
57484
|
+
const sessions = Array.isArray(statusObj?.sessions) ? statusObj.sessions : [];
|
|
57485
|
+
const meshSessions = sessions.filter(
|
|
57486
|
+
(s) => s?.settings?.meshNodeFor === ctx.mesh.id || s?.settings?.meshNodeId === node.id || s?.settings?.launchedByCoordinator === true
|
|
57487
|
+
);
|
|
57488
|
+
const targetSession = meshSessions[0] || sessions.find(
|
|
57489
|
+
(s) => !resolvedProviderType || s?.providerType === resolvedProviderType || s?.cliType === resolvedProviderType
|
|
57490
|
+
) || sessions[0];
|
|
57491
|
+
if (targetSession?.id || targetSession?.sessionId) {
|
|
57492
|
+
sessionId = targetSession.id || targetSession.sessionId;
|
|
57493
|
+
if (!resolvedProviderType) {
|
|
57494
|
+
resolvedProviderType = targetSession.providerType || targetSession.cliType || "";
|
|
57495
|
+
}
|
|
57496
|
+
} else {
|
|
57497
|
+
}
|
|
57498
|
+
} catch (e) {
|
|
57499
|
+
}
|
|
57500
|
+
}
|
|
57501
|
+
if (!resolvedProviderType) {
|
|
57502
|
+
return { success: false, error: `Cannot dispatch to remote node '${node.id}': providerType unknown. Set providerPriority on the node policy or call mesh_launch_session first.` };
|
|
57503
|
+
}
|
|
57504
|
+
try {
|
|
57505
|
+
await transport.meshCommand(daemonId, "agent_command", {
|
|
57506
|
+
...sessionId ? { targetSessionId: sessionId } : {},
|
|
57507
|
+
agentType: resolvedProviderType,
|
|
57508
|
+
cliType: resolvedProviderType,
|
|
57509
|
+
action: "send_chat",
|
|
57510
|
+
message: args.message
|
|
57511
|
+
});
|
|
57512
|
+
return { success: true, dispatched: true, sessionId: sessionId || resolvedProviderType };
|
|
57513
|
+
} catch (e) {
|
|
57514
|
+
return { success: false, error: `P2P dispatch failed: ${e?.message || String(e)}` };
|
|
57515
|
+
}
|
|
57516
|
+
}
|
|
57303
57517
|
function resolveCoordinatorNode(ctx) {
|
|
57304
57518
|
const preferredNodeId = typeof ctx.mesh.coordinator?.preferredNodeId === "string" ? ctx.mesh.coordinator.preferredNodeId.trim() : "";
|
|
57305
57519
|
if (preferredNodeId) {
|
|
57306
57520
|
const preferred = ctx.mesh.nodes.find((n) => n.id === preferredNodeId && typeof n.daemonId === "string" && n.daemonId.trim());
|
|
57307
57521
|
if (preferred) return preferred;
|
|
57308
57522
|
}
|
|
57523
|
+
if (ctx.localMachineId) {
|
|
57524
|
+
const byMachine = ctx.mesh.nodes.find((n) => n.machineId === ctx.localMachineId);
|
|
57525
|
+
if (byMachine) return byMachine;
|
|
57526
|
+
}
|
|
57309
57527
|
if (ctx.localDaemonId) {
|
|
57310
57528
|
return ctx.mesh.nodes.find((n) => n.daemonId === ctx.localDaemonId);
|
|
57311
57529
|
}
|
|
@@ -57395,7 +57613,8 @@ function getNodeLaunchReadiness(node) {
|
|
|
57395
57613
|
};
|
|
57396
57614
|
}
|
|
57397
57615
|
async function commandForNode(ctx, node, command, args = {}) {
|
|
57398
|
-
|
|
57616
|
+
const isLocalNode = ctx.localMachineId && node.machineId === ctx.localMachineId || ctx.localDaemonId && node.daemonId === ctx.localDaemonId;
|
|
57617
|
+
if (ctx.transport instanceof IpcTransport && node.daemonId && !isLocalNode) {
|
|
57399
57618
|
return ctx.transport.meshCommand(node.daemonId, command, args);
|
|
57400
57619
|
}
|
|
57401
57620
|
if (isLocalTransport(ctx.transport)) {
|
|
@@ -57405,10 +57624,12 @@ async function commandForNode(ctx, node, command, args = {}) {
|
|
|
57405
57624
|
}
|
|
57406
57625
|
var MESH_STATUS_TOOL = {
|
|
57407
57626
|
name: "mesh_status",
|
|
57408
|
-
description: "Get the current status of all nodes in the repo mesh \u2014 health, git state, active sessions. Use this to decide which node to send work to.",
|
|
57627
|
+
description: "Get the current status of all nodes in the repo mesh \u2014 health, git state, active sessions, recovery hints, and recommended next steps. Use this to decide which node to send work to or how to recover from failures.",
|
|
57409
57628
|
inputSchema: {
|
|
57410
57629
|
type: "object",
|
|
57411
|
-
properties: {
|
|
57630
|
+
properties: {
|
|
57631
|
+
_gemini_compat: { type: "string", description: "Dummy property for Gemini compatibility. Ignore this." }
|
|
57632
|
+
}
|
|
57412
57633
|
}
|
|
57413
57634
|
};
|
|
57414
57635
|
var MESH_LIST_NODES_TOOL = {
|
|
@@ -57416,7 +57637,9 @@ var MESH_LIST_NODES_TOOL = {
|
|
|
57416
57637
|
description: "List all nodes in the mesh with their capabilities, platform, and workspace paths.",
|
|
57417
57638
|
inputSchema: {
|
|
57418
57639
|
type: "object",
|
|
57419
|
-
properties: {
|
|
57640
|
+
properties: {
|
|
57641
|
+
_gemini_compat: { type: "string", description: "Dummy property for Gemini compatibility. Ignore this." }
|
|
57642
|
+
}
|
|
57420
57643
|
}
|
|
57421
57644
|
};
|
|
57422
57645
|
var MESH_ENQUEUE_TASK_TOOL = {
|
|
@@ -57630,6 +57853,7 @@ async function meshStatus(ctx) {
|
|
|
57630
57853
|
await refreshMeshFromDaemon(ctx);
|
|
57631
57854
|
const { mesh, transport } = ctx;
|
|
57632
57855
|
const results = [];
|
|
57856
|
+
const ledgerSummary = getLedgerSummary(mesh.id);
|
|
57633
57857
|
for (const node of mesh.nodes) {
|
|
57634
57858
|
const entry = {
|
|
57635
57859
|
nodeId: node.id,
|
|
@@ -57663,6 +57887,33 @@ async function meshStatus(ctx) {
|
|
|
57663
57887
|
entry.health = "degraded";
|
|
57664
57888
|
entry.error = e.message;
|
|
57665
57889
|
}
|
|
57890
|
+
const recoveryContext = getSessionRecoveryContext(mesh.id, { nodeId: node.id });
|
|
57891
|
+
if (recoveryContext.consecutiveNodeFailures > 0) {
|
|
57892
|
+
entry.recoveryHints = {
|
|
57893
|
+
consecutiveFailures: recoveryContext.consecutiveNodeFailures,
|
|
57894
|
+
lastTaskMessage: recoveryContext.lastTaskMessage,
|
|
57895
|
+
advice: recoveryContext.advice,
|
|
57896
|
+
retryRecommended: recoveryContext.retryRecommended
|
|
57897
|
+
};
|
|
57898
|
+
}
|
|
57899
|
+
const nextStepHints = [];
|
|
57900
|
+
if (entry.health === "online" && node.isLocalWorktree) {
|
|
57901
|
+
nextStepHints.push(`Merge worktree to base via mesh_refine_node(node_id: "${node.id}")`);
|
|
57902
|
+
} else if (entry.health === "dirty") {
|
|
57903
|
+
nextStepHints.push(`Commit changes via mesh_checkpoint(node_id: "${node.id}", message: "...")`);
|
|
57904
|
+
} else if (entry.health === "degraded" && entry.error?.includes("git")) {
|
|
57905
|
+
nextStepHints.push("Initialize git repository or check workspace path.");
|
|
57906
|
+
}
|
|
57907
|
+
if (recoveryContext.consecutiveNodeFailures > 0) {
|
|
57908
|
+
if (recoveryContext.retryRecommended) {
|
|
57909
|
+
nextStepHints.push(`Retry task on this node or launch a fresh session.`);
|
|
57910
|
+
} else {
|
|
57911
|
+
nextStepHints.push(`Consider reassigning work to a different node.`);
|
|
57912
|
+
}
|
|
57913
|
+
}
|
|
57914
|
+
if (nextStepHints.length > 0) {
|
|
57915
|
+
entry.nextStepHints = nextStepHints;
|
|
57916
|
+
}
|
|
57666
57917
|
const relatedRepos = await collectRelatedRepoStatuses(ctx, node);
|
|
57667
57918
|
if (relatedRepos.length) entry.relatedRepos = relatedRepos;
|
|
57668
57919
|
results.push(entry);
|
|
@@ -57676,7 +57927,7 @@ async function meshStatus(ctx) {
|
|
|
57676
57927
|
nodes: results
|
|
57677
57928
|
};
|
|
57678
57929
|
try {
|
|
57679
|
-
response.ledgerSummary =
|
|
57930
|
+
response.ledgerSummary = ledgerSummary;
|
|
57680
57931
|
} catch {
|
|
57681
57932
|
}
|
|
57682
57933
|
if (ctx.transport instanceof IpcTransport) {
|
|
@@ -57720,12 +57971,38 @@ async function meshListNodes(ctx) {
|
|
|
57720
57971
|
async function meshEnqueueTask(ctx, args) {
|
|
57721
57972
|
try {
|
|
57722
57973
|
const task = enqueueTask(ctx.mesh.id, args.message);
|
|
57723
|
-
if (ctx.transport
|
|
57724
|
-
ctx.transport.
|
|
57974
|
+
if (isLocalTransport(ctx.transport) && !(ctx.transport instanceof IpcTransport)) {
|
|
57975
|
+
ctx.transport.command("trigger_mesh_queue", { meshId: ctx.mesh.id }).catch(() => {
|
|
57725
57976
|
});
|
|
57726
|
-
|
|
57977
|
+
return JSON.stringify({ success: true, taskId: task.id, status: task.status });
|
|
57978
|
+
}
|
|
57979
|
+
if (ctx.transport instanceof IpcTransport) {
|
|
57727
57980
|
ctx.transport.command("trigger_mesh_queue", { meshId: ctx.mesh.id }).catch(() => {
|
|
57728
57981
|
});
|
|
57982
|
+
const dispatchPromises = [];
|
|
57983
|
+
for (const node of ctx.mesh.nodes) {
|
|
57984
|
+
const isLocalNode = ctx.localMachineId && node.machineId === ctx.localMachineId || ctx.localDaemonId && node.daemonId === ctx.localDaemonId;
|
|
57985
|
+
if (isLocalNode || !node.daemonId) continue;
|
|
57986
|
+
dispatchPromises.push(
|
|
57987
|
+
ipcDispatchToRemoteAgent(ctx, node, { message: args.message }).then((result) => {
|
|
57988
|
+
if (result.success) {
|
|
57989
|
+
try {
|
|
57990
|
+
appendLedgerEntry(ctx.mesh.id, {
|
|
57991
|
+
kind: "task_dispatched",
|
|
57992
|
+
nodeId: node.id,
|
|
57993
|
+
sessionId: result.sessionId,
|
|
57994
|
+
payload: { message: args.message, via: "p2p_direct", taskId: task.id }
|
|
57995
|
+
});
|
|
57996
|
+
} catch {
|
|
57997
|
+
}
|
|
57998
|
+
}
|
|
57999
|
+
}).catch(() => {
|
|
58000
|
+
})
|
|
58001
|
+
);
|
|
58002
|
+
}
|
|
58003
|
+
Promise.all(dispatchPromises).catch(() => {
|
|
58004
|
+
});
|
|
58005
|
+
return JSON.stringify({ success: true, taskId: task.id, status: task.status });
|
|
57729
58006
|
}
|
|
57730
58007
|
return JSON.stringify({ success: true, taskId: task.id, status: task.status });
|
|
57731
58008
|
} catch (e) {
|
|
@@ -57754,11 +58031,32 @@ async function meshSendTask(ctx, args) {
|
|
|
57754
58031
|
});
|
|
57755
58032
|
return JSON.stringify(res);
|
|
57756
58033
|
}
|
|
57757
|
-
const
|
|
57758
|
-
if (ctx.transport instanceof IpcTransport && node.daemonId &&
|
|
57759
|
-
|
|
58034
|
+
const isLocalNode = ctx.localMachineId && node.machineId === ctx.localMachineId || ctx.localDaemonId && node.daemonId === ctx.localDaemonId;
|
|
58035
|
+
if (ctx.transport instanceof IpcTransport && node.daemonId && !isLocalNode) {
|
|
58036
|
+
const cached2 = meshSessionProviderMetadata.get(meshSessionCacheKey(args.node_id, args.session_id || ""));
|
|
58037
|
+
const result = await ipcDispatchToRemoteAgent(ctx, node, {
|
|
58038
|
+
session_id: args.session_id,
|
|
58039
|
+
message: args.message,
|
|
58040
|
+
providerType: cached2?.providerType
|
|
57760
58041
|
});
|
|
57761
|
-
|
|
58042
|
+
if (result.success) {
|
|
58043
|
+
try {
|
|
58044
|
+
appendLedgerEntry(ctx.mesh.id, {
|
|
58045
|
+
kind: "task_dispatched",
|
|
58046
|
+
nodeId: args.node_id,
|
|
58047
|
+
sessionId: result.sessionId,
|
|
58048
|
+
payload: { message: args.message, via: "p2p_direct" }
|
|
58049
|
+
});
|
|
58050
|
+
} catch {
|
|
58051
|
+
}
|
|
58052
|
+
}
|
|
58053
|
+
return JSON.stringify({ ...result, nodeId: args.node_id });
|
|
58054
|
+
}
|
|
58055
|
+
const task = enqueueTask(ctx.mesh.id, args.message, {
|
|
58056
|
+
targetNodeId: args.node_id,
|
|
58057
|
+
targetSessionId: args.session_id
|
|
58058
|
+
});
|
|
58059
|
+
if (isLocalTransport(ctx.transport) || ctx.transport instanceof IpcTransport) {
|
|
57762
58060
|
ctx.transport.command("trigger_mesh_queue", { meshId: ctx.mesh.id }).catch(() => {
|
|
57763
58061
|
});
|
|
57764
58062
|
}
|
|
@@ -57902,7 +58200,8 @@ async function meshLaunchSession(ctx, args) {
|
|
|
57902
58200
|
});
|
|
57903
58201
|
} catch {
|
|
57904
58202
|
}
|
|
57905
|
-
|
|
58203
|
+
const isLocalNode = ctx.localMachineId && node.machineId === ctx.localMachineId || ctx.localDaemonId && node.daemonId === ctx.localDaemonId;
|
|
58204
|
+
if (ctx.transport instanceof IpcTransport && node.daemonId && !isLocalNode) {
|
|
57906
58205
|
ctx.transport.meshCommand(node.daemonId, "trigger_mesh_queue", { meshId: ctx.mesh.id }).catch(() => {
|
|
57907
58206
|
});
|
|
57908
58207
|
} else if (isLocalTransport(ctx.transport)) {
|
|
@@ -59840,6 +60139,15 @@ async function startMcpServer(opts) {
|
|
|
59840
60139
|
process.exit(1);
|
|
59841
60140
|
}
|
|
59842
60141
|
let localDaemonId;
|
|
60142
|
+
let localMachineId;
|
|
60143
|
+
if (transport instanceof LocalTransport || transport instanceof IpcTransport) {
|
|
60144
|
+
try {
|
|
60145
|
+
const { loadConfig: loadConfig2 } = await Promise.resolve().then(() => (init_dist2(), dist_exports));
|
|
60146
|
+
const cfg = loadConfig2();
|
|
60147
|
+
if (cfg.registeredMachineId) localMachineId = cfg.registeredMachineId;
|
|
60148
|
+
} catch {
|
|
60149
|
+
}
|
|
60150
|
+
}
|
|
59843
60151
|
if (transport instanceof IpcTransport) {
|
|
59844
60152
|
try {
|
|
59845
60153
|
const statusResult = await transport.getStatus();
|
|
@@ -59848,7 +60156,7 @@ async function startMcpServer(opts) {
|
|
|
59848
60156
|
} catch {
|
|
59849
60157
|
}
|
|
59850
60158
|
}
|
|
59851
|
-
const meshCtx = { mesh, transport, ...localDaemonId ? { localDaemonId } : {} };
|
|
60159
|
+
const meshCtx = { mesh, transport, ...localDaemonId ? { localDaemonId } : {}, ...localMachineId ? { localMachineId } : {} };
|
|
59852
60160
|
const coordinatorPrompt = await buildMeshModeCoordinatorPrompt(mesh);
|
|
59853
60161
|
const server2 = new import_server.Server(
|
|
59854
60162
|
{ name: "adhdev-mcp-server", version: "0.9.76" },
|