@adhdev/daemon-standalone 0.9.77-rc.2 → 0.9.77-rc.20

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/public/index.html CHANGED
@@ -7,7 +7,7 @@
7
7
  <meta name="description" content="ADHDev self-hosted dashboard for controlling AI agents" />
8
8
  <link rel="icon" href="/otter-logo.png" />
9
9
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet" />
10
- <script type="module" crossorigin src="/assets/index-6WEc6L46.js"></script>
10
+ <script type="module" crossorigin src="/assets/index-CWWeDAva.js"></script>
11
11
  <link rel="modulepreload" crossorigin href="/assets/vendor-CLec0455.js">
12
12
  <link rel="stylesheet" crossorigin href="/assets/index-DftJ2WZr.css">
13
13
  </head>
@@ -26264,7 +26264,7 @@ function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType)
26264
26264
  targetSessionId: sessionId,
26265
26265
  cliType: providerType,
26266
26266
  action: "send_chat",
26267
- input: task.message
26267
+ message: task.message
26268
26268
  }).catch((e) => {
26269
26269
  LOG.error("MeshQueue", `Failed to dispatch task to node ${nodeId}: ${e?.message}`);
26270
26270
  });
@@ -26346,6 +26346,15 @@ function injectMeshSystemMessage(components, args) {
26346
26346
  }, 500);
26347
26347
  }
26348
26348
  }
26349
+ } else if (args.event === "agent:ready") {
26350
+ const sessionId = readNonEmptyString(args.metadataEvent.targetSessionId);
26351
+ const nodeId = readNonEmptyString(args.metadataEvent.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
26352
+ const providerType = readNonEmptyString(args.metadataEvent.providerType);
26353
+ if (sessionId && nodeId && providerType) {
26354
+ setTimeout(() => {
26355
+ tryAssignQueueTask(components, args.meshId, nodeId, sessionId, providerType);
26356
+ }, 500);
26357
+ }
26349
26358
  } else if (args.event === "agent:stopped") {
26350
26359
  const sessionId = readNonEmptyString(args.metadataEvent.targetSessionId);
26351
26360
  if (sessionId) {
@@ -33701,11 +33710,13 @@ async function handleOpenPanel(h, args) {
33701
33710
  async function handlePtyInput(h, args) {
33702
33711
  const { cliType, data, targetSessionId } = args || {};
33703
33712
  if (!data) return { success: false, error: "data required" };
33713
+ const cleanData = typeof data === "string" ? data.replace(/\x1b\[[?>][0-9;]*c/g, "") : data;
33714
+ if (!cleanData) return { success: true };
33704
33715
  const adapter = h.getCliAdapter(targetSessionId || cliType);
33705
33716
  if (!adapter || typeof adapter.writeRaw !== "function") {
33706
33717
  return { success: false, error: `CLI adapter not found: ${targetSessionId || cliType || "unknown"}` };
33707
33718
  }
33708
- await adapter.writeRaw(data);
33719
+ await adapter.writeRaw(cleanData);
33709
33720
  return { success: true };
33710
33721
  }
33711
33722
  function handlePtyResize(_h, args) {
@@ -34532,9 +34543,6 @@ function buildCoordinatorDelegatedCliLaunchOptions(input) {
34532
34543
  const cliType = String(input.cliType || "").trim();
34533
34544
  const cliArgs = Array.isArray(input.cliArgs) ? [...input.cliArgs] : [];
34534
34545
  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
34546
  if (cliType === "claude-cli" && !hasCliArg(cliArgs, "--mcp-config")) {
34539
34547
  cliArgs.unshift("--mcp-config", ensureEmptyDelegatedMcpConfig(input.workspace));
34540
34548
  }
@@ -35567,6 +35575,22 @@ function resolveMeshCoordinatorSetup(options) {
35567
35575
  if (!instructions || !template?.trim()) {
35568
35576
  return { kind: "unsupported", reason: "Provider manual MCP setup is missing instructions or template" };
35569
35577
  }
35578
+ const renderedTemplate = renderMeshCoordinatorTemplate(template, {
35579
+ meshId,
35580
+ workspace,
35581
+ serverName,
35582
+ adhdevMcpCommand: options.adhdevMcpCommand || DEFAULT_ADHDEV_MCP_COMMAND
35583
+ });
35584
+ const isCliCommand = !renderedTemplate.trim().includes("\n") && !renderedTemplate.trim().startsWith("{");
35585
+ if (isCliCommand) {
35586
+ return {
35587
+ kind: "cli_command",
35588
+ serverName,
35589
+ command: renderedTemplate.trim(),
35590
+ requiresRestart: mcpConfig.requiresRestart === true,
35591
+ instructions
35592
+ };
35593
+ }
35570
35594
  return {
35571
35595
  kind: "manual",
35572
35596
  serverName,
@@ -35574,12 +35598,7 @@ function resolveMeshCoordinatorSetup(options) {
35574
35598
  configPathCommand: mcpConfig.configPathCommand,
35575
35599
  requiresRestart: mcpConfig.requiresRestart === true,
35576
35600
  instructions,
35577
- template: renderMeshCoordinatorTemplate(template, {
35578
- meshId,
35579
- workspace,
35580
- serverName,
35581
- adhdevMcpCommand: options.adhdevMcpCommand || DEFAULT_ADHDEV_MCP_COMMAND
35582
- })
35601
+ template: renderedTemplate
35583
35602
  };
35584
35603
  }
35585
35604
  return {
@@ -41331,6 +41350,7 @@ Follow these recovery rules:
41331
41350
  "agent:generating_completed",
41332
41351
  "agent:waiting_approval",
41333
41352
  "agent:stopped",
41353
+ "agent:ready",
41334
41354
  "monitor:long_generating"
41335
41355
  ]);
41336
41356
  EVENT_TO_LEDGER_KIND = {
@@ -41865,6 +41885,8 @@ Follow these recovery rules:
41865
41885
  statusHistory = [];
41866
41886
  // ─── CLI Scripts (script-based parsing) ───
41867
41887
  cliScripts;
41888
+ /** Per-session opaque state object created by cliScripts.createState(), reset on stop. */
41889
+ scriptState = null;
41868
41890
  runtimeSettings = {};
41869
41891
  /** Full accumulated rendered PTY transcript for parser/readback use */
41870
41892
  accumulatedBuffer = "";
@@ -42046,6 +42068,7 @@ ${lastSnapshot}`;
42046
42068
  this.cliScripts = scripts;
42047
42069
  this.parsedStatusCache = null;
42048
42070
  this.parseErrorMessage = null;
42071
+ this.scriptState = typeof scripts.createState === "function" ? scripts.createState() : null;
42049
42072
  const scriptNames = listCliScriptNames(scripts);
42050
42073
  LOG.info("CLI", `[${this.cliType}] CLI scripts injected: [${scriptNames.join(", ")}]`);
42051
42074
  }
@@ -42163,6 +42186,7 @@ ${lastSnapshot}`;
42163
42186
  this.ready = false;
42164
42187
  this.startupParseGate = false;
42165
42188
  this.spawnAt = 0;
42189
+ this.scriptState = null;
42166
42190
  this.onStatusChange?.();
42167
42191
  });
42168
42192
  this.spawnAt = Date.now();
@@ -42936,7 +42960,7 @@ ${lastSnapshot}`;
42936
42960
  scope: this.currentTurnScope,
42937
42961
  runtimeSettings: this.runtimeSettings
42938
42962
  });
42939
- const session = this.cliScripts.parseSession({ ...input, tail, tailScreen: buildCliScreenSnapshot(tail) });
42963
+ const session = this.cliScripts.parseSession(this.scriptState, { ...input, tail, tailScreen: buildCliScreenSnapshot(tail) });
42940
42964
  this.parseErrorMessage = null;
42941
42965
  return session && typeof session === "object" ? session : null;
42942
42966
  } catch (e) {
@@ -42950,7 +42974,7 @@ ${lastSnapshot}`;
42950
42974
  if (!this.cliScripts?.detectStatus) return null;
42951
42975
  try {
42952
42976
  const screenText = this.terminalScreen.getText();
42953
- const status = this.cliScripts.detectStatus({
42977
+ const status = this.cliScripts.detectStatus(this.scriptState, {
42954
42978
  tail: text.slice(-500),
42955
42979
  screenText,
42956
42980
  rawBuffer: this.accumulatedRawBuffer,
@@ -42969,7 +42993,7 @@ ${lastSnapshot}`;
42969
42993
  try {
42970
42994
  const screenText = this.terminalScreen.getText();
42971
42995
  const buffer = screenText || this.accumulatedBuffer;
42972
- return this.cliScripts.parseApproval({
42996
+ return this.cliScripts.parseApproval(this.scriptState, {
42973
42997
  buffer,
42974
42998
  screenText,
42975
42999
  rawBuffer: this.accumulatedRawBuffer,
@@ -43077,7 +43101,7 @@ ${lastSnapshot}`;
43077
43101
  scope: this.currentTurnScope,
43078
43102
  runtimeSettings: this.runtimeSettings
43079
43103
  });
43080
- return await Promise.resolve(fn({
43104
+ return await Promise.resolve(fn(this.scriptState, {
43081
43105
  ...input,
43082
43106
  args: args && typeof args === "object" ? { ...args } : {}
43083
43107
  }));
@@ -48296,6 +48320,8 @@ ${effect.notification.body || ""}`.trim();
48296
48320
  this.completedDebounceTimer = null;
48297
48321
  }, 3e3);
48298
48322
  }
48323
+ } else if (newStatus === "idle" && this.lastStatus === "starting") {
48324
+ this.pushEvent({ event: "agent:ready", chatTitle, timestamp: now });
48299
48325
  } else if (newStatus === "stopped") {
48300
48326
  if (this.generatingDebounceTimer) {
48301
48327
  clearTimeout(this.generatingDebounceTimer);
@@ -53342,6 +53368,93 @@ Run 'adhdev doctor' for detailed diagnostics.`
53342
53368
  meshCoordinatorSetup: coordinatorSetup
53343
53369
  };
53344
53370
  }
53371
+ if (coordinatorSetup.kind === "cli_command") {
53372
+ let cliCmdSystemPrompt = "";
53373
+ try {
53374
+ cliCmdSystemPrompt = buildCoordinatorSystemPrompt2({ mesh, coordinatorCliType: cliType });
53375
+ } catch (error48) {
53376
+ const message = error48?.message || String(error48);
53377
+ LOG.error("MeshCoordinator", `Failed to build coordinator prompt: ${message}`);
53378
+ return {
53379
+ success: false,
53380
+ code: "mesh_coordinator_prompt_failed",
53381
+ error: `Failed to build Repo Mesh coordinator prompt: ${message}`,
53382
+ meshId,
53383
+ cliType,
53384
+ workspace
53385
+ };
53386
+ }
53387
+ try {
53388
+ const { execFileSync: execCmdSync } = await import("child_process");
53389
+ const cmdParts = coordinatorSetup.command.trim().split(/\s+/);
53390
+ const [regCmd, ...regArgs] = cmdParts;
53391
+ LOG.info("MeshCoordinator", `Running MCP registration: ${coordinatorSetup.command}`);
53392
+ execCmdSync(regCmd, regArgs, { stdio: "pipe", timeout: 15e3 });
53393
+ } catch (error48) {
53394
+ LOG.warn("MeshCoordinator", `MCP registration command failed (may be pre-registered): ${error48?.message || error48}`);
53395
+ }
53396
+ const cliCmdArgs = [];
53397
+ const cliCmdEnv = {};
53398
+ if (cliCmdSystemPrompt) {
53399
+ if (cliType === "codex-cli") {
53400
+ cliCmdArgs.push("-c", `developer_instructions=${JSON.stringify(cliCmdSystemPrompt)}`);
53401
+ } else if (cliType === "gemini-cli") {
53402
+ try {
53403
+ const { writeFileSync: wfs, existsSync: efs, readFileSync: rfs } = await import("fs");
53404
+ const geminiMdPath = `${workspace}/GEMINI.md`;
53405
+ const marker = "<!-- adhdev-mesh-coordinator-prompt -->";
53406
+ const markerEnd = "<!-- /adhdev-mesh-coordinator-prompt -->";
53407
+ const block = `${marker}
53408
+ ${cliCmdSystemPrompt}
53409
+ ${markerEnd}`;
53410
+ if (efs(geminiMdPath)) {
53411
+ const existing = rfs(geminiMdPath, "utf-8");
53412
+ const replaced = existing.replace(
53413
+ new RegExp(`${marker}[\\s\\S]*?${markerEnd}`, "g"),
53414
+ block
53415
+ );
53416
+ wfs(geminiMdPath, replaced.includes(marker) ? replaced : `${existing}
53417
+
53418
+ ${block}`);
53419
+ } else {
53420
+ wfs(geminiMdPath, block);
53421
+ }
53422
+ LOG.info("MeshCoordinator", `Wrote coordinator prompt to ${workspace}/GEMINI.md`);
53423
+ } catch (e) {
53424
+ LOG.warn("MeshCoordinator", `Could not write GEMINI.md: ${e?.message || e}`);
53425
+ }
53426
+ }
53427
+ }
53428
+ const cliCmdLaunch = await this.deps.cliManager.handleCliCommand("launch_cli", {
53429
+ cliType,
53430
+ dir: workspace,
53431
+ cliArgs: cliCmdArgs.length > 0 ? cliCmdArgs : void 0,
53432
+ env: Object.keys(cliCmdEnv).length > 0 ? cliCmdEnv : void 0,
53433
+ settings: { meshCoordinatorFor: meshId }
53434
+ });
53435
+ if (!cliCmdLaunch?.success) {
53436
+ return { success: false, error: cliCmdLaunch?.error || "Failed to launch CLI session" };
53437
+ }
53438
+ LOG.info("MeshCoordinator", `Launched ${cliType} coordinator (cli_command) for mesh ${meshId}`);
53439
+ try {
53440
+ const { appendLedgerEntry: appendLedgerEntry2 } = await Promise.resolve().then(() => (init_mesh_ledger(), mesh_ledger_exports));
53441
+ appendLedgerEntry2(meshId, {
53442
+ kind: "coordinator_started",
53443
+ sessionId: cliCmdLaunch.sessionId || cliCmdLaunch.id,
53444
+ providerType: cliType,
53445
+ payload: { workspace }
53446
+ });
53447
+ } catch {
53448
+ }
53449
+ return {
53450
+ success: true,
53451
+ meshId,
53452
+ cliType,
53453
+ workspace,
53454
+ sessionId: cliCmdLaunch.sessionId || cliCmdLaunch.id,
53455
+ mcpRegistered: true
53456
+ };
53457
+ }
53345
53458
  const configFormat = coordinatorSetup.configFormat;
53346
53459
  if (configFormat !== "claude_mcp_json" && configFormat !== "hermes_config_yaml") {
53347
53460
  return {
@@ -57306,6 +57419,10 @@ function resolveCoordinatorNode(ctx) {
57306
57419
  const preferred = ctx.mesh.nodes.find((n) => n.id === preferredNodeId && typeof n.daemonId === "string" && n.daemonId.trim());
57307
57420
  if (preferred) return preferred;
57308
57421
  }
57422
+ if (ctx.localMachineId) {
57423
+ const byMachine = ctx.mesh.nodes.find((n) => n.machineId === ctx.localMachineId);
57424
+ if (byMachine) return byMachine;
57425
+ }
57309
57426
  if (ctx.localDaemonId) {
57310
57427
  return ctx.mesh.nodes.find((n) => n.daemonId === ctx.localDaemonId);
57311
57428
  }
@@ -57395,7 +57512,8 @@ function getNodeLaunchReadiness(node) {
57395
57512
  };
57396
57513
  }
57397
57514
  async function commandForNode(ctx, node, command, args = {}) {
57398
- if (ctx.transport instanceof IpcTransport && node.daemonId && node.daemonId !== ctx.localDaemonId) {
57515
+ const isLocalNode = ctx.localMachineId && node.machineId === ctx.localMachineId || ctx.localDaemonId && node.daemonId === ctx.localDaemonId;
57516
+ if (ctx.transport instanceof IpcTransport && node.daemonId && !isLocalNode) {
57399
57517
  return ctx.transport.meshCommand(node.daemonId, command, args);
57400
57518
  }
57401
57519
  if (isLocalTransport(ctx.transport)) {
@@ -57408,7 +57526,9 @@ var MESH_STATUS_TOOL = {
57408
57526
  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.",
57409
57527
  inputSchema: {
57410
57528
  type: "object",
57411
- properties: {}
57529
+ properties: {
57530
+ _gemini_compat: { type: "string", description: "Dummy property for Gemini compatibility. Ignore this." }
57531
+ }
57412
57532
  }
57413
57533
  };
57414
57534
  var MESH_LIST_NODES_TOOL = {
@@ -57416,7 +57536,9 @@ var MESH_LIST_NODES_TOOL = {
57416
57536
  description: "List all nodes in the mesh with their capabilities, platform, and workspace paths.",
57417
57537
  inputSchema: {
57418
57538
  type: "object",
57419
- properties: {}
57539
+ properties: {
57540
+ _gemini_compat: { type: "string", description: "Dummy property for Gemini compatibility. Ignore this." }
57541
+ }
57420
57542
  }
57421
57543
  };
57422
57544
  var MESH_ENQUEUE_TASK_TOOL = {
@@ -57720,10 +57842,7 @@ async function meshListNodes(ctx) {
57720
57842
  async function meshEnqueueTask(ctx, args) {
57721
57843
  try {
57722
57844
  const task = enqueueTask(ctx.mesh.id, args.message);
57723
- if (ctx.transport instanceof IpcTransport && ctx.localDaemonId) {
57724
- ctx.transport.meshCommand(ctx.localDaemonId, "trigger_mesh_queue", { meshId: ctx.mesh.id }).catch(() => {
57725
- });
57726
- } else if (isLocalTransport(ctx.transport)) {
57845
+ if (isLocalTransport(ctx.transport)) {
57727
57846
  ctx.transport.command("trigger_mesh_queue", { meshId: ctx.mesh.id }).catch(() => {
57728
57847
  });
57729
57848
  }
@@ -57755,7 +57874,8 @@ async function meshSendTask(ctx, args) {
57755
57874
  return JSON.stringify(res);
57756
57875
  }
57757
57876
  const task = enqueueTask(ctx.mesh.id, args.message, { targetNodeId: args.node_id });
57758
- if (ctx.transport instanceof IpcTransport && node.daemonId && node.daemonId !== ctx.localDaemonId) {
57877
+ const isLocalNode = ctx.localMachineId && node.machineId === ctx.localMachineId || ctx.localDaemonId && node.daemonId === ctx.localDaemonId;
57878
+ if (ctx.transport instanceof IpcTransport && node.daemonId && !isLocalNode) {
57759
57879
  ctx.transport.meshCommand(node.daemonId, "trigger_mesh_queue", { meshId: ctx.mesh.id }).catch(() => {
57760
57880
  });
57761
57881
  } else if (isLocalTransport(ctx.transport)) {
@@ -57902,7 +58022,8 @@ async function meshLaunchSession(ctx, args) {
57902
58022
  });
57903
58023
  } catch {
57904
58024
  }
57905
- if (ctx.transport instanceof IpcTransport && node.daemonId && node.daemonId !== ctx.localDaemonId) {
58025
+ const isLocalNode = ctx.localMachineId && node.machineId === ctx.localMachineId || ctx.localDaemonId && node.daemonId === ctx.localDaemonId;
58026
+ if (ctx.transport instanceof IpcTransport && node.daemonId && !isLocalNode) {
57906
58027
  ctx.transport.meshCommand(node.daemonId, "trigger_mesh_queue", { meshId: ctx.mesh.id }).catch(() => {
57907
58028
  });
57908
58029
  } else if (isLocalTransport(ctx.transport)) {
@@ -59840,6 +59961,15 @@ async function startMcpServer(opts) {
59840
59961
  process.exit(1);
59841
59962
  }
59842
59963
  let localDaemonId;
59964
+ let localMachineId;
59965
+ if (transport instanceof LocalTransport || transport instanceof IpcTransport) {
59966
+ try {
59967
+ const { loadConfig: loadConfig2 } = await Promise.resolve().then(() => (init_dist2(), dist_exports));
59968
+ const cfg = loadConfig2();
59969
+ if (cfg.registeredMachineId) localMachineId = cfg.registeredMachineId;
59970
+ } catch {
59971
+ }
59972
+ }
59843
59973
  if (transport instanceof IpcTransport) {
59844
59974
  try {
59845
59975
  const statusResult = await transport.getStatus();
@@ -59848,7 +59978,7 @@ async function startMcpServer(opts) {
59848
59978
  } catch {
59849
59979
  }
59850
59980
  }
59851
- const meshCtx = { mesh, transport, ...localDaemonId ? { localDaemonId } : {} };
59981
+ const meshCtx = { mesh, transport, ...localDaemonId ? { localDaemonId } : {}, ...localMachineId ? { localMachineId } : {} };
59852
59982
  const coordinatorPrompt = await buildMeshModeCoordinatorPrompt(mesh);
59853
59983
  const server2 = new import_server.Server(
59854
59984
  { name: "adhdev-mcp-server", version: "0.9.76" },