@adhdev/daemon-core 0.9.76-rc.32 → 0.9.76-rc.34

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 CHANGED
@@ -12245,6 +12245,14 @@ function buildChatDebugBundleSummary(bundle) {
12245
12245
  const readChat = bundle.readChat && typeof bundle.readChat === "object" ? bundle.readChat : {};
12246
12246
  const cli = bundle.cli && typeof bundle.cli === "object" ? bundle.cli : null;
12247
12247
  const frontend = bundle.frontend && typeof bundle.frontend === "object" ? bundle.frontend : null;
12248
+ const debugReadChat = readChat.debugReadChat && typeof readChat.debugReadChat === "object" ? readChat.debugReadChat : {};
12249
+ const parsedStatus = cli?.parsedStatus && typeof cli.parsedStatus === "object" ? cli.parsedStatus : null;
12250
+ const cliParsedMessageCount = Array.isArray(parsedStatus?.messages) ? parsedStatus.messages.length : void 0;
12251
+ const readChatReturnedMessages = Array.isArray(readChat.messagesTail) ? readChat.messagesTail.length : void 0;
12252
+ const cliPartialResponse = typeof cli?.partialResponse === "string" ? cli.partialResponse : "";
12253
+ const readChatStatus = typeof readChat.status === "string" ? readChat.status : "";
12254
+ const cliStatus = typeof cli?.status === "string" ? cli.status : "";
12255
+ const cliParsedStatus = typeof parsedStatus?.status === "string" ? parsedStatus.status : "";
12248
12256
  return {
12249
12257
  createdAt: bundle.createdAt,
12250
12258
  targetSessionId: target.targetSessionId,
@@ -12253,8 +12261,22 @@ function buildChatDebugBundleSummary(bundle) {
12253
12261
  readChatSuccess: readChat.success,
12254
12262
  readChatStatus: readChat.status,
12255
12263
  readChatTotalMessages: readChat.totalMessages,
12264
+ readChatReturnedMessages,
12256
12265
  cliStatus: cli?.status,
12266
+ cliParsedStatus: cliParsedStatus || void 0,
12257
12267
  cliMessageCount: cli?.messageCount,
12268
+ cliParsedMessageCount,
12269
+ cliPartialResponseChars: cliPartialResponse.length,
12270
+ parserAdapterStatusMismatch: Boolean(cliStatus && cliParsedStatus && cliStatus !== cliParsedStatus),
12271
+ parserReadChatStatusMismatch: Boolean(readChatStatus && cliParsedStatus && readChatStatus !== cliParsedStatus),
12272
+ readChatDebug: Object.keys(debugReadChat).length ? {
12273
+ adapterStatus: debugReadChat.adapterStatus,
12274
+ parsedStatus: debugReadChat.parsedStatus,
12275
+ returnedStatus: debugReadChat.returnedStatus,
12276
+ parsedMsgCount: debugReadChat.parsedMsgCount,
12277
+ returnedMsgCount: debugReadChat.returnedMsgCount,
12278
+ shouldPreferAdapterMessages: debugReadChat.shouldPreferAdapterMessages
12279
+ } : void 0,
12258
12280
  hasFrontendSnapshot: !!frontend
12259
12281
  };
12260
12282
  }
@@ -20525,6 +20547,100 @@ function normalizeExistingPath(filePath) {
20525
20547
  }
20526
20548
  }
20527
20549
 
20550
+ // src/mesh/mesh-events.ts
20551
+ init_mesh_config();
20552
+ init_logger();
20553
+ function readNonEmptyString(value) {
20554
+ return typeof value === "string" && value.trim() ? value.trim() : "";
20555
+ }
20556
+ function formatCompletionMetadata(event) {
20557
+ const parts = [
20558
+ readNonEmptyString(event.targetSessionId) ? `session_id=${readNonEmptyString(event.targetSessionId)}` : "",
20559
+ readNonEmptyString(event.providerType) ? `provider=${readNonEmptyString(event.providerType)}` : "",
20560
+ readNonEmptyString(event.providerSessionId) ? `provider_session_id=${readNonEmptyString(event.providerSessionId)}` : ""
20561
+ ].filter(Boolean);
20562
+ return parts.length > 0 ? ` (${parts.join("; ")})` : "";
20563
+ }
20564
+ function buildMeshSystemMessage(args) {
20565
+ const metadata = formatCompletionMetadata(args.metadataEvent);
20566
+ if (args.event === "agent:generating_completed") {
20567
+ return `[System] ${args.nodeLabel} has completed its task and is now idle${metadata}. You may use mesh_read_chat to review its progress.`;
20568
+ }
20569
+ if (args.event === "agent:waiting_approval") {
20570
+ return `[System] ${args.nodeLabel} is waiting for approval to proceed${metadata}. You may use mesh_read_chat and mesh_approve to handle it.`;
20571
+ }
20572
+ return "";
20573
+ }
20574
+ function injectMeshSystemMessage(components, args) {
20575
+ const coordinatorInstances = components.instanceManager.getByCategory("cli").filter((inst) => {
20576
+ const instState = inst.getState();
20577
+ if (instState.settings?.meshCoordinatorFor !== args.meshId) return false;
20578
+ if (args.sourceInstanceId && instState.instanceId === args.sourceInstanceId) return false;
20579
+ return true;
20580
+ });
20581
+ if (coordinatorInstances.length === 0) return { success: true, forwarded: 0 };
20582
+ const messageText = buildMeshSystemMessage({
20583
+ event: args.event,
20584
+ nodeLabel: args.nodeLabel,
20585
+ metadataEvent: args.metadataEvent
20586
+ });
20587
+ if (!messageText) return { success: false, error: "unsupported mesh event" };
20588
+ for (const coord of coordinatorInstances) {
20589
+ const coordState = coord.getState();
20590
+ LOG.info("MeshEvents", `Forwarding mesh event to coordinator ${coordState.instanceId}`);
20591
+ coord.onEvent("send_message", { input: { text: messageText, textFallback: messageText } });
20592
+ }
20593
+ return { success: true, forwarded: coordinatorInstances.length };
20594
+ }
20595
+ function handleMeshForwardEvent(components, payload) {
20596
+ const eventName = readNonEmptyString(payload.event);
20597
+ if (eventName !== "agent:generating_completed" && eventName !== "agent:waiting_approval") {
20598
+ return { success: false, error: "unsupported mesh event" };
20599
+ }
20600
+ const meshId = readNonEmptyString(payload.meshId);
20601
+ if (!meshId) return { success: false, error: "meshId required" };
20602
+ const nodeId = readNonEmptyString(payload.nodeId);
20603
+ const workspace = readNonEmptyString(payload.workspace);
20604
+ const nodeLabel = nodeId ? `Node '${nodeId}'` : workspace ? `Agent at ${workspace}` : "Remote agent";
20605
+ return injectMeshSystemMessage(components, {
20606
+ meshId,
20607
+ nodeLabel,
20608
+ event: eventName,
20609
+ metadataEvent: {
20610
+ targetSessionId: readNonEmptyString(payload.targetSessionId) || readNonEmptyString(payload.sessionId),
20611
+ providerType: readNonEmptyString(payload.providerType),
20612
+ providerSessionId: readNonEmptyString(payload.providerSessionId)
20613
+ }
20614
+ });
20615
+ }
20616
+ function setupMeshEventForwarding(components) {
20617
+ components.instanceManager.onEvent((event) => {
20618
+ if (event.event !== "agent:generating_completed" && event.event !== "agent:waiting_approval") return;
20619
+ const instanceId = readNonEmptyString(event.instanceId);
20620
+ if (!instanceId) return;
20621
+ const sourceInstance = components.instanceManager.getInstance(instanceId);
20622
+ if (!sourceInstance || sourceInstance.category !== "cli") return;
20623
+ const state = sourceInstance.getState();
20624
+ const workspace = readNonEmptyString(state.workspace);
20625
+ if (!workspace) return;
20626
+ const settings = state.settings && typeof state.settings === "object" ? state.settings : {};
20627
+ const meshIdFromRuntime = readNonEmptyString(settings.meshNodeFor);
20628
+ const mesh = meshIdFromRuntime ? getMesh(meshIdFromRuntime) : getMeshByRepo(workspace);
20629
+ const meshId = meshIdFromRuntime || readNonEmptyString(mesh?.id);
20630
+ if (!meshId) return;
20631
+ const targetNode = mesh?.nodes?.find((n) => n.workspace === workspace);
20632
+ const runtimeNodeId = readNonEmptyString(settings.meshNodeId);
20633
+ const nodeLabel = targetNode ? `Node '${targetNode.id}'` : runtimeNodeId ? `Node '${runtimeNodeId}'` : `Agent at ${workspace}`;
20634
+ injectMeshSystemMessage(components, {
20635
+ meshId,
20636
+ sourceInstanceId: instanceId,
20637
+ nodeLabel,
20638
+ event: event.event,
20639
+ metadataEvent: event
20640
+ });
20641
+ });
20642
+ }
20643
+
20528
20644
  // src/status/snapshot.ts
20529
20645
  var os18 = __toESM(require("os"));
20530
20646
  init_config();
@@ -21494,6 +21610,9 @@ var DaemonCommandRouter = class {
21494
21610
  async executeDaemonCommand(cmd, args) {
21495
21611
  switch (cmd) {
21496
21612
  // ─── CLI / ACP commands ───
21613
+ case "mesh_forward_event": {
21614
+ return handleMeshForwardEvent({ instanceManager: this.deps.instanceManager }, args);
21615
+ }
21497
21616
  case "launch_cli":
21498
21617
  case "stop_cli":
21499
21618
  case "set_cli_view_mode":
@@ -30116,64 +30235,6 @@ var SessionRegistry = class {
30116
30235
  // src/boot/daemon-lifecycle.ts
30117
30236
  init_logger();
30118
30237
  init_config();
30119
-
30120
- // src/mesh/mesh-events.ts
30121
- init_mesh_config();
30122
- init_logger();
30123
- function readNonEmptyString(value) {
30124
- return typeof value === "string" && value.trim() ? value.trim() : "";
30125
- }
30126
- function formatCompletionMetadata(event) {
30127
- const parts = [
30128
- readNonEmptyString(event.targetSessionId) ? `session_id=${readNonEmptyString(event.targetSessionId)}` : "",
30129
- readNonEmptyString(event.providerType) ? `provider=${readNonEmptyString(event.providerType)}` : "",
30130
- readNonEmptyString(event.providerSessionId) ? `provider_session_id=${readNonEmptyString(event.providerSessionId)}` : ""
30131
- ].filter(Boolean);
30132
- return parts.length > 0 ? ` (${parts.join("; ")})` : "";
30133
- }
30134
- function setupMeshEventForwarding(components) {
30135
- components.instanceManager.onEvent((event) => {
30136
- if (event.event !== "agent:generating_completed" && event.event !== "agent:waiting_approval") return;
30137
- const instanceId = readNonEmptyString(event.instanceId);
30138
- if (!instanceId) return;
30139
- const sourceInstance = components.instanceManager.getInstance(instanceId);
30140
- if (!sourceInstance || sourceInstance.category !== "cli") return;
30141
- const state = sourceInstance.getState();
30142
- const workspace = readNonEmptyString(state.workspace);
30143
- if (!workspace) return;
30144
- const settings = state.settings && typeof state.settings === "object" ? state.settings : {};
30145
- const meshIdFromRuntime = readNonEmptyString(settings.meshNodeFor);
30146
- const mesh = meshIdFromRuntime ? getMesh(meshIdFromRuntime) : getMeshByRepo(workspace);
30147
- const meshId = meshIdFromRuntime || readNonEmptyString(mesh?.id);
30148
- if (!meshId) return;
30149
- const allInstances = components.instanceManager.getByCategory("cli");
30150
- const coordinatorInstances = allInstances.filter((inst) => {
30151
- const instState = inst.getState();
30152
- if (instState.settings?.meshCoordinatorFor !== meshId) return false;
30153
- if (instState.instanceId === instanceId) return false;
30154
- return true;
30155
- });
30156
- if (coordinatorInstances.length === 0) return;
30157
- const targetNode = mesh?.nodes?.find((n) => n.workspace === workspace);
30158
- const runtimeNodeId = readNonEmptyString(settings.meshNodeId);
30159
- const nodeLabel = targetNode ? `Node '${targetNode.id}'` : runtimeNodeId ? `Node '${runtimeNodeId}'` : `Agent at ${workspace}`;
30160
- const metadata = formatCompletionMetadata(event);
30161
- let messageText = "";
30162
- if (event.event === "agent:generating_completed") {
30163
- messageText = `[System] ${nodeLabel} has completed its task and is now idle${metadata}. You may use mesh_read_chat to review its progress.`;
30164
- } else if (event.event === "agent:waiting_approval") {
30165
- messageText = `[System] ${nodeLabel} is waiting for approval to proceed${metadata}. You may use mesh_read_chat and mesh_approve to handle it.`;
30166
- }
30167
- if (!messageText) return;
30168
- for (const coord of coordinatorInstances) {
30169
- const coordState = coord.getState();
30170
- LOG.info("MeshEvents", `Forwarding event from ${workspace} to coordinator ${coordState.instanceId}`);
30171
- coord.onEvent("send_message", { input: { text: messageText, textFallback: messageText } });
30172
- }
30173
- });
30174
- }
30175
-
30176
- // src/boot/daemon-lifecycle.ts
30177
30238
  async function initDaemonComponents(config) {
30178
30239
  installGlobalInterceptor();
30179
30240
  const appConfig = loadConfig();