@adhdev/daemon-core 0.9.77-rc.10 → 0.9.77-rc.11

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.mjs CHANGED
@@ -1317,7 +1317,7 @@ function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType)
1317
1317
  targetSessionId: sessionId,
1318
1318
  cliType: providerType,
1319
1319
  action: "send_chat",
1320
- input: task.message
1320
+ message: task.message
1321
1321
  }).catch((e) => {
1322
1322
  LOG.error("MeshQueue", `Failed to dispatch task to node ${nodeId}: ${e?.message}`);
1323
1323
  });
@@ -14987,11 +14987,13 @@ async function handleOpenPanel(h, args) {
14987
14987
  async function handlePtyInput(h, args) {
14988
14988
  const { cliType, data, targetSessionId } = args || {};
14989
14989
  if (!data) return { success: false, error: "data required" };
14990
+ const cleanData = typeof data === "string" ? data.replace(/\x1b\[\?[0-9;]*c/g, "") : data;
14991
+ if (!cleanData) return { success: true };
14990
14992
  const adapter = h.getCliAdapter(targetSessionId || cliType);
14991
14993
  if (!adapter || typeof adapter.writeRaw !== "function") {
14992
14994
  return { success: false, error: `CLI adapter not found: ${targetSessionId || cliType || "unknown"}` };
14993
14995
  }
14994
- await adapter.writeRaw(data);
14996
+ await adapter.writeRaw(cleanData);
14995
14997
  return { success: true };
14996
14998
  }
14997
14999
  function handlePtyResize(_h, args) {
@@ -21706,6 +21708,22 @@ function resolveMeshCoordinatorSetup(options) {
21706
21708
  if (!instructions || !template?.trim()) {
21707
21709
  return { kind: "unsupported", reason: "Provider manual MCP setup is missing instructions or template" };
21708
21710
  }
21711
+ const renderedTemplate = renderMeshCoordinatorTemplate(template, {
21712
+ meshId,
21713
+ workspace,
21714
+ serverName,
21715
+ adhdevMcpCommand: options.adhdevMcpCommand || DEFAULT_ADHDEV_MCP_COMMAND
21716
+ });
21717
+ const isCliCommand = !renderedTemplate.trim().includes("\n") && !renderedTemplate.trim().startsWith("{");
21718
+ if (isCliCommand) {
21719
+ return {
21720
+ kind: "cli_command",
21721
+ serverName,
21722
+ command: renderedTemplate.trim(),
21723
+ requiresRestart: mcpConfig.requiresRestart === true,
21724
+ instructions
21725
+ };
21726
+ }
21709
21727
  return {
21710
21728
  kind: "manual",
21711
21729
  serverName,
@@ -21713,12 +21731,7 @@ function resolveMeshCoordinatorSetup(options) {
21713
21731
  configPathCommand: mcpConfig.configPathCommand,
21714
21732
  requiresRestart: mcpConfig.requiresRestart === true,
21715
21733
  instructions,
21716
- template: renderMeshCoordinatorTemplate(template, {
21717
- meshId,
21718
- workspace,
21719
- serverName,
21720
- adhdevMcpCommand: options.adhdevMcpCommand || DEFAULT_ADHDEV_MCP_COMMAND
21721
- })
21734
+ template: renderedTemplate
21722
21735
  };
21723
21736
  }
21724
21737
  return {
@@ -23900,6 +23913,93 @@ var DaemonCommandRouter = class {
23900
23913
  meshCoordinatorSetup: coordinatorSetup
23901
23914
  };
23902
23915
  }
23916
+ if (coordinatorSetup.kind === "cli_command") {
23917
+ let cliCmdSystemPrompt = "";
23918
+ try {
23919
+ cliCmdSystemPrompt = buildCoordinatorSystemPrompt2({ mesh, coordinatorCliType: cliType });
23920
+ } catch (error) {
23921
+ const message = error?.message || String(error);
23922
+ LOG.error("MeshCoordinator", `Failed to build coordinator prompt: ${message}`);
23923
+ return {
23924
+ success: false,
23925
+ code: "mesh_coordinator_prompt_failed",
23926
+ error: `Failed to build Repo Mesh coordinator prompt: ${message}`,
23927
+ meshId,
23928
+ cliType,
23929
+ workspace
23930
+ };
23931
+ }
23932
+ try {
23933
+ const { execFileSync: execCmdSync } = await import("child_process");
23934
+ const cmdParts = coordinatorSetup.command.trim().split(/\s+/);
23935
+ const [regCmd, ...regArgs] = cmdParts;
23936
+ LOG.info("MeshCoordinator", `Running MCP registration: ${coordinatorSetup.command}`);
23937
+ execCmdSync(regCmd, regArgs, { stdio: "pipe", timeout: 15e3 });
23938
+ } catch (error) {
23939
+ LOG.warn("MeshCoordinator", `MCP registration command failed (may be pre-registered): ${error?.message || error}`);
23940
+ }
23941
+ const cliCmdArgs = [];
23942
+ const cliCmdEnv = {};
23943
+ if (cliCmdSystemPrompt) {
23944
+ if (cliType === "codex-cli") {
23945
+ cliCmdArgs.push("-c", `developer_instructions=${JSON.stringify(cliCmdSystemPrompt)}`);
23946
+ } else if (cliType === "gemini-cli") {
23947
+ try {
23948
+ const { writeFileSync: wfs, existsSync: efs, readFileSync: rfs } = await import("fs");
23949
+ const geminiMdPath = `${workspace}/GEMINI.md`;
23950
+ const marker = "<!-- adhdev-mesh-coordinator-prompt -->";
23951
+ const markerEnd = "<!-- /adhdev-mesh-coordinator-prompt -->";
23952
+ const block = `${marker}
23953
+ ${cliCmdSystemPrompt}
23954
+ ${markerEnd}`;
23955
+ if (efs(geminiMdPath)) {
23956
+ const existing = rfs(geminiMdPath, "utf-8");
23957
+ const replaced = existing.replace(
23958
+ new RegExp(`${marker}[\\s\\S]*?${markerEnd}`, "g"),
23959
+ block
23960
+ );
23961
+ wfs(geminiMdPath, replaced.includes(marker) ? replaced : `${existing}
23962
+
23963
+ ${block}`);
23964
+ } else {
23965
+ wfs(geminiMdPath, block);
23966
+ }
23967
+ LOG.info("MeshCoordinator", `Wrote coordinator prompt to ${workspace}/GEMINI.md`);
23968
+ } catch (e) {
23969
+ LOG.warn("MeshCoordinator", `Could not write GEMINI.md: ${e?.message || e}`);
23970
+ }
23971
+ }
23972
+ }
23973
+ const cliCmdLaunch = await this.deps.cliManager.handleCliCommand("launch_cli", {
23974
+ cliType,
23975
+ dir: workspace,
23976
+ cliArgs: cliCmdArgs.length > 0 ? cliCmdArgs : void 0,
23977
+ env: Object.keys(cliCmdEnv).length > 0 ? cliCmdEnv : void 0,
23978
+ settings: { meshCoordinatorFor: meshId }
23979
+ });
23980
+ if (!cliCmdLaunch?.success) {
23981
+ return { success: false, error: cliCmdLaunch?.error || "Failed to launch CLI session" };
23982
+ }
23983
+ LOG.info("MeshCoordinator", `Launched ${cliType} coordinator (cli_command) for mesh ${meshId}`);
23984
+ try {
23985
+ const { appendLedgerEntry: appendLedgerEntry2 } = await Promise.resolve().then(() => (init_mesh_ledger(), mesh_ledger_exports));
23986
+ appendLedgerEntry2(meshId, {
23987
+ kind: "coordinator_started",
23988
+ sessionId: cliCmdLaunch.sessionId || cliCmdLaunch.id,
23989
+ providerType: cliType,
23990
+ payload: { workspace }
23991
+ });
23992
+ } catch {
23993
+ }
23994
+ return {
23995
+ success: true,
23996
+ meshId,
23997
+ cliType,
23998
+ workspace,
23999
+ sessionId: cliCmdLaunch.sessionId || cliCmdLaunch.id,
24000
+ mcpRegistered: true
24001
+ };
24002
+ }
23903
24003
  const configFormat = coordinatorSetup.configFormat;
23904
24004
  if (configFormat !== "claude_mcp_json" && configFormat !== "hermes_config_yaml") {
23905
24005
  return {