@adhdev/daemon-standalone 0.9.76-rc.32 → 0.9.76-rc.33

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
@@ -51573,6 +51573,98 @@ Run 'adhdev doctor' for detailed diagnostics.`
51573
51573
  return null;
51574
51574
  }
51575
51575
  }
51576
+ init_mesh_config();
51577
+ init_logger();
51578
+ function readNonEmptyString(value) {
51579
+ return typeof value === "string" && value.trim() ? value.trim() : "";
51580
+ }
51581
+ function formatCompletionMetadata(event) {
51582
+ const parts = [
51583
+ readNonEmptyString(event.targetSessionId) ? `session_id=${readNonEmptyString(event.targetSessionId)}` : "",
51584
+ readNonEmptyString(event.providerType) ? `provider=${readNonEmptyString(event.providerType)}` : "",
51585
+ readNonEmptyString(event.providerSessionId) ? `provider_session_id=${readNonEmptyString(event.providerSessionId)}` : ""
51586
+ ].filter(Boolean);
51587
+ return parts.length > 0 ? ` (${parts.join("; ")})` : "";
51588
+ }
51589
+ function buildMeshSystemMessage(args) {
51590
+ const metadata = formatCompletionMetadata(args.metadataEvent);
51591
+ if (args.event === "agent:generating_completed") {
51592
+ return `[System] ${args.nodeLabel} has completed its task and is now idle${metadata}. You may use mesh_read_chat to review its progress.`;
51593
+ }
51594
+ if (args.event === "agent:waiting_approval") {
51595
+ return `[System] ${args.nodeLabel} is waiting for approval to proceed${metadata}. You may use mesh_read_chat and mesh_approve to handle it.`;
51596
+ }
51597
+ return "";
51598
+ }
51599
+ function injectMeshSystemMessage(components, args) {
51600
+ const coordinatorInstances = components.instanceManager.getByCategory("cli").filter((inst) => {
51601
+ const instState = inst.getState();
51602
+ if (instState.settings?.meshCoordinatorFor !== args.meshId) return false;
51603
+ if (args.sourceInstanceId && instState.instanceId === args.sourceInstanceId) return false;
51604
+ return true;
51605
+ });
51606
+ if (coordinatorInstances.length === 0) return { success: true, forwarded: 0 };
51607
+ const messageText = buildMeshSystemMessage({
51608
+ event: args.event,
51609
+ nodeLabel: args.nodeLabel,
51610
+ metadataEvent: args.metadataEvent
51611
+ });
51612
+ if (!messageText) return { success: false, error: "unsupported mesh event" };
51613
+ for (const coord of coordinatorInstances) {
51614
+ const coordState = coord.getState();
51615
+ LOG2.info("MeshEvents", `Forwarding mesh event to coordinator ${coordState.instanceId}`);
51616
+ coord.onEvent("send_message", { input: { text: messageText, textFallback: messageText } });
51617
+ }
51618
+ return { success: true, forwarded: coordinatorInstances.length };
51619
+ }
51620
+ function handleMeshForwardEvent(components, payload) {
51621
+ const eventName = readNonEmptyString(payload.event);
51622
+ if (eventName !== "agent:generating_completed" && eventName !== "agent:waiting_approval") {
51623
+ return { success: false, error: "unsupported mesh event" };
51624
+ }
51625
+ const meshId = readNonEmptyString(payload.meshId);
51626
+ if (!meshId) return { success: false, error: "meshId required" };
51627
+ const nodeId = readNonEmptyString(payload.nodeId);
51628
+ const workspace = readNonEmptyString(payload.workspace);
51629
+ const nodeLabel = nodeId ? `Node '${nodeId}'` : workspace ? `Agent at ${workspace}` : "Remote agent";
51630
+ return injectMeshSystemMessage(components, {
51631
+ meshId,
51632
+ nodeLabel,
51633
+ event: eventName,
51634
+ metadataEvent: {
51635
+ targetSessionId: readNonEmptyString(payload.targetSessionId) || readNonEmptyString(payload.sessionId),
51636
+ providerType: readNonEmptyString(payload.providerType),
51637
+ providerSessionId: readNonEmptyString(payload.providerSessionId)
51638
+ }
51639
+ });
51640
+ }
51641
+ function setupMeshEventForwarding(components) {
51642
+ components.instanceManager.onEvent((event) => {
51643
+ if (event.event !== "agent:generating_completed" && event.event !== "agent:waiting_approval") return;
51644
+ const instanceId = readNonEmptyString(event.instanceId);
51645
+ if (!instanceId) return;
51646
+ const sourceInstance = components.instanceManager.getInstance(instanceId);
51647
+ if (!sourceInstance || sourceInstance.category !== "cli") return;
51648
+ const state = sourceInstance.getState();
51649
+ const workspace = readNonEmptyString(state.workspace);
51650
+ if (!workspace) return;
51651
+ const settings = state.settings && typeof state.settings === "object" ? state.settings : {};
51652
+ const meshIdFromRuntime = readNonEmptyString(settings.meshNodeFor);
51653
+ const mesh = meshIdFromRuntime ? getMesh(meshIdFromRuntime) : getMeshByRepo(workspace);
51654
+ const meshId = meshIdFromRuntime || readNonEmptyString(mesh?.id);
51655
+ if (!meshId) return;
51656
+ const targetNode = mesh?.nodes?.find((n) => n.workspace === workspace);
51657
+ const runtimeNodeId = readNonEmptyString(settings.meshNodeId);
51658
+ const nodeLabel = targetNode ? `Node '${targetNode.id}'` : runtimeNodeId ? `Node '${runtimeNodeId}'` : `Agent at ${workspace}`;
51659
+ injectMeshSystemMessage(components, {
51660
+ meshId,
51661
+ sourceInstanceId: instanceId,
51662
+ nodeLabel,
51663
+ event: event.event,
51664
+ metadataEvent: event
51665
+ });
51666
+ });
51667
+ }
51576
51668
  var os18 = __toESM2(require("os"));
51577
51669
  init_config();
51578
51670
  init_terminal_screen();
@@ -52537,6 +52629,9 @@ Run 'adhdev doctor' for detailed diagnostics.`
52537
52629
  async executeDaemonCommand(cmd, args) {
52538
52630
  switch (cmd) {
52539
52631
  // ─── CLI / ACP commands ───
52632
+ case "mesh_forward_event": {
52633
+ return handleMeshForwardEvent({ instanceManager: this.deps.instanceManager }, args);
52634
+ }
52540
52635
  case "launch_cli":
52541
52636
  case "stop_cli":
52542
52637
  case "set_cli_view_mode":
@@ -61107,60 +61202,6 @@ data: ${JSON.stringify(msg.data)}
61107
61202
  };
61108
61203
  init_logger();
61109
61204
  init_config();
61110
- init_mesh_config();
61111
- init_logger();
61112
- function readNonEmptyString(value) {
61113
- return typeof value === "string" && value.trim() ? value.trim() : "";
61114
- }
61115
- function formatCompletionMetadata(event) {
61116
- const parts = [
61117
- readNonEmptyString(event.targetSessionId) ? `session_id=${readNonEmptyString(event.targetSessionId)}` : "",
61118
- readNonEmptyString(event.providerType) ? `provider=${readNonEmptyString(event.providerType)}` : "",
61119
- readNonEmptyString(event.providerSessionId) ? `provider_session_id=${readNonEmptyString(event.providerSessionId)}` : ""
61120
- ].filter(Boolean);
61121
- return parts.length > 0 ? ` (${parts.join("; ")})` : "";
61122
- }
61123
- function setupMeshEventForwarding(components) {
61124
- components.instanceManager.onEvent((event) => {
61125
- if (event.event !== "agent:generating_completed" && event.event !== "agent:waiting_approval") return;
61126
- const instanceId = readNonEmptyString(event.instanceId);
61127
- if (!instanceId) return;
61128
- const sourceInstance = components.instanceManager.getInstance(instanceId);
61129
- if (!sourceInstance || sourceInstance.category !== "cli") return;
61130
- const state = sourceInstance.getState();
61131
- const workspace = readNonEmptyString(state.workspace);
61132
- if (!workspace) return;
61133
- const settings = state.settings && typeof state.settings === "object" ? state.settings : {};
61134
- const meshIdFromRuntime = readNonEmptyString(settings.meshNodeFor);
61135
- const mesh = meshIdFromRuntime ? getMesh(meshIdFromRuntime) : getMeshByRepo(workspace);
61136
- const meshId = meshIdFromRuntime || readNonEmptyString(mesh?.id);
61137
- if (!meshId) return;
61138
- const allInstances = components.instanceManager.getByCategory("cli");
61139
- const coordinatorInstances = allInstances.filter((inst) => {
61140
- const instState = inst.getState();
61141
- if (instState.settings?.meshCoordinatorFor !== meshId) return false;
61142
- if (instState.instanceId === instanceId) return false;
61143
- return true;
61144
- });
61145
- if (coordinatorInstances.length === 0) return;
61146
- const targetNode = mesh?.nodes?.find((n) => n.workspace === workspace);
61147
- const runtimeNodeId = readNonEmptyString(settings.meshNodeId);
61148
- const nodeLabel = targetNode ? `Node '${targetNode.id}'` : runtimeNodeId ? `Node '${runtimeNodeId}'` : `Agent at ${workspace}`;
61149
- const metadata = formatCompletionMetadata(event);
61150
- let messageText = "";
61151
- if (event.event === "agent:generating_completed") {
61152
- messageText = `[System] ${nodeLabel} has completed its task and is now idle${metadata}. You may use mesh_read_chat to review its progress.`;
61153
- } else if (event.event === "agent:waiting_approval") {
61154
- messageText = `[System] ${nodeLabel} is waiting for approval to proceed${metadata}. You may use mesh_read_chat and mesh_approve to handle it.`;
61155
- }
61156
- if (!messageText) return;
61157
- for (const coord of coordinatorInstances) {
61158
- const coordState = coord.getState();
61159
- LOG2.info("MeshEvents", `Forwarding event from ${workspace} to coordinator ${coordState.instanceId}`);
61160
- coord.onEvent("send_message", { input: { text: messageText, textFallback: messageText } });
61161
- }
61162
- });
61163
- }
61164
61205
  async function initDaemonComponents2(config2) {
61165
61206
  installGlobalInterceptor();
61166
61207
  const appConfig = loadConfig2();