@adhdev/daemon-standalone 0.9.76-rc.31 → 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
@@ -34485,9 +34485,8 @@ ${lastSnapshot}`;
34485
34485
  };
34486
34486
  this.recordTrace("submit_echo_missing", diagnostic);
34487
34487
  if (this.requirePromptEchoBeforeSubmit) {
34488
- const message = `${this.cliName} prompt echo was not observed on the PTY screen before submit`;
34489
- LOG2.warn("CLI", `[${this.cliType}] ${message} elapsed=${elapsed}ms maxEchoWaitMs=${state.maxEchoWaitMs} screen=${JSON.stringify(diagnostic.screenText).slice(0, 240)}`);
34490
- completion.rejectOnce(new Error(message));
34488
+ LOG2.warn("CLI", `[${this.cliType}] prompt echo was not observed before submit; sending guarded submit key anyway elapsed=${elapsed}ms maxEchoWaitMs=${state.maxEchoWaitMs} screen=${JSON.stringify(diagnostic.screenText).slice(0, 240)}`);
34489
+ this.submitSendKey(state, completion);
34491
34490
  return;
34492
34491
  }
34493
34492
  LOG2.warn("CLI", `[${this.cliType}] prompt echo was not observed before submit; sending submit key anyway elapsed=${elapsed}ms maxEchoWaitMs=${state.maxEchoWaitMs}`);
@@ -51574,6 +51573,98 @@ Run 'adhdev doctor' for detailed diagnostics.`
51574
51573
  return null;
51575
51574
  }
51576
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
+ }
51577
51668
  var os18 = __toESM2(require("os"));
51578
51669
  init_config();
51579
51670
  init_terminal_screen();
@@ -52538,6 +52629,9 @@ Run 'adhdev doctor' for detailed diagnostics.`
52538
52629
  async executeDaemonCommand(cmd, args) {
52539
52630
  switch (cmd) {
52540
52631
  // ─── CLI / ACP commands ───
52632
+ case "mesh_forward_event": {
52633
+ return handleMeshForwardEvent({ instanceManager: this.deps.instanceManager }, args);
52634
+ }
52541
52635
  case "launch_cli":
52542
52636
  case "stop_cli":
52543
52637
  case "set_cli_view_mode":
@@ -61108,60 +61202,6 @@ data: ${JSON.stringify(msg.data)}
61108
61202
  };
61109
61203
  init_logger();
61110
61204
  init_config();
61111
- init_mesh_config();
61112
- init_logger();
61113
- function readNonEmptyString(value) {
61114
- return typeof value === "string" && value.trim() ? value.trim() : "";
61115
- }
61116
- function formatCompletionMetadata(event) {
61117
- const parts = [
61118
- readNonEmptyString(event.targetSessionId) ? `session_id=${readNonEmptyString(event.targetSessionId)}` : "",
61119
- readNonEmptyString(event.providerType) ? `provider=${readNonEmptyString(event.providerType)}` : "",
61120
- readNonEmptyString(event.providerSessionId) ? `provider_session_id=${readNonEmptyString(event.providerSessionId)}` : ""
61121
- ].filter(Boolean);
61122
- return parts.length > 0 ? ` (${parts.join("; ")})` : "";
61123
- }
61124
- function setupMeshEventForwarding(components) {
61125
- components.instanceManager.onEvent((event) => {
61126
- if (event.event !== "agent:generating_completed" && event.event !== "agent:waiting_approval") return;
61127
- const instanceId = readNonEmptyString(event.instanceId);
61128
- if (!instanceId) return;
61129
- const sourceInstance = components.instanceManager.getInstance(instanceId);
61130
- if (!sourceInstance || sourceInstance.category !== "cli") return;
61131
- const state = sourceInstance.getState();
61132
- const workspace = readNonEmptyString(state.workspace);
61133
- if (!workspace) return;
61134
- const settings = state.settings && typeof state.settings === "object" ? state.settings : {};
61135
- const meshIdFromRuntime = readNonEmptyString(settings.meshNodeFor);
61136
- const mesh = meshIdFromRuntime ? getMesh(meshIdFromRuntime) : getMeshByRepo(workspace);
61137
- const meshId = meshIdFromRuntime || readNonEmptyString(mesh?.id);
61138
- if (!meshId) return;
61139
- const allInstances = components.instanceManager.getByCategory("cli");
61140
- const coordinatorInstances = allInstances.filter((inst) => {
61141
- const instState = inst.getState();
61142
- if (instState.settings?.meshCoordinatorFor !== meshId) return false;
61143
- if (instState.instanceId === instanceId) return false;
61144
- return true;
61145
- });
61146
- if (coordinatorInstances.length === 0) return;
61147
- const targetNode = mesh?.nodes?.find((n) => n.workspace === workspace);
61148
- const runtimeNodeId = readNonEmptyString(settings.meshNodeId);
61149
- const nodeLabel = targetNode ? `Node '${targetNode.id}'` : runtimeNodeId ? `Node '${runtimeNodeId}'` : `Agent at ${workspace}`;
61150
- const metadata = formatCompletionMetadata(event);
61151
- let messageText = "";
61152
- if (event.event === "agent:generating_completed") {
61153
- messageText = `[System] ${nodeLabel} has completed its task and is now idle${metadata}. You may use mesh_read_chat to review its progress.`;
61154
- } else if (event.event === "agent:waiting_approval") {
61155
- messageText = `[System] ${nodeLabel} is waiting for approval to proceed${metadata}. You may use mesh_read_chat and mesh_approve to handle it.`;
61156
- }
61157
- if (!messageText) return;
61158
- for (const coord of coordinatorInstances) {
61159
- const coordState = coord.getState();
61160
- LOG2.info("MeshEvents", `Forwarding event from ${workspace} to coordinator ${coordState.instanceId}`);
61161
- coord.onEvent("send_message", { input: { text: messageText, textFallback: messageText } });
61162
- }
61163
- });
61164
- }
61165
61205
  async function initDaemonComponents2(config2) {
61166
61206
  installGlobalInterceptor();
61167
61207
  const appConfig = loadConfig2();