@adhdev/daemon-core 0.9.70 → 0.9.71

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
@@ -3525,11 +3525,22 @@ var init_provider_cli_adapter = __esm({
3525
3525
  }
3526
3526
  }
3527
3527
  }
3528
+ getParsedDebugState() {
3529
+ if (this.startupParseGate || typeof this.cliScripts?.parseSession !== "function") return null;
3530
+ try {
3531
+ const parsed = this.getScriptParsedStatus();
3532
+ return parsed && typeof parsed === "object" ? parsed : null;
3533
+ } catch {
3534
+ return null;
3535
+ }
3536
+ }
3528
3537
  getDebugState() {
3529
3538
  const screenText = sanitizeTerminalText(this.terminalScreen.getText());
3530
3539
  const startupModal = this.startupParseGate ? this.runParseApproval(this.recentOutputBuffer) : null;
3531
3540
  const effectiveStatus = this.projectEffectiveStatus(startupModal);
3532
3541
  const effectiveReady = this.ready || !!startupModal;
3542
+ const parsedDebugState = this.getParsedDebugState();
3543
+ const parsedMessages = Array.isArray(parsedDebugState?.messages) ? parsedDebugState.messages : [];
3533
3544
  return {
3534
3545
  type: this.cliType,
3535
3546
  name: this.cliName,
@@ -3542,8 +3553,18 @@ var init_provider_cli_adapter = __esm({
3542
3553
  startupParseGate: this.startupParseGate,
3543
3554
  spawnAt: this.spawnAt,
3544
3555
  workingDir: this.workingDir,
3545
- messages: [],
3546
- messageCount: 0,
3556
+ messages: parsedMessages,
3557
+ messageCount: parsedMessages.length,
3558
+ parsedStatus: parsedDebugState ? {
3559
+ id: parsedDebugState.id,
3560
+ status: parsedDebugState.status,
3561
+ title: parsedDebugState.title,
3562
+ providerSessionId: parsedDebugState.providerSessionId,
3563
+ transcriptAuthority: parsedDebugState.transcriptAuthority,
3564
+ coverage: parsedDebugState.coverage,
3565
+ activeModal: parsedDebugState.activeModal,
3566
+ messageCount: parsedMessages.length
3567
+ } : null,
3547
3568
  screenText: screenText.slice(-4e3),
3548
3569
  currentTurnScope: this.currentTurnScope,
3549
3570
  startupBuffer: this.startupBuffer.slice(-4e3),
@@ -11055,7 +11076,8 @@ function buildIdeWorkspaceSession(state, cdpManagers, options) {
11055
11076
  },
11056
11077
  errorMessage: state.errorMessage,
11057
11078
  errorReason: state.errorReason,
11058
- lastUpdated: state.lastUpdated
11079
+ lastUpdated: state.lastUpdated,
11080
+ settings: state.settings
11059
11081
  };
11060
11082
  }
11061
11083
  function buildExtensionAgentSession(parent, ext, options) {
@@ -11090,7 +11112,8 @@ function buildExtensionAgentSession(parent, ext, options) {
11090
11112
  },
11091
11113
  errorMessage: ext.errorMessage,
11092
11114
  errorReason: ext.errorReason,
11093
- lastUpdated: ext.lastUpdated
11115
+ lastUpdated: ext.lastUpdated,
11116
+ settings: ext.settings
11094
11117
  };
11095
11118
  }
11096
11119
  function shouldIncludeExtensionSession(ext) {
@@ -11156,7 +11179,8 @@ function buildCliSession(state, options) {
11156
11179
  },
11157
11180
  errorMessage: state.errorMessage,
11158
11181
  errorReason: state.errorReason,
11159
- lastUpdated: state.lastUpdated
11182
+ lastUpdated: state.lastUpdated,
11183
+ settings: state.settings
11160
11184
  };
11161
11185
  }
11162
11186
  function buildAcpSession(state, options) {
@@ -11190,7 +11214,8 @@ function buildAcpSession(state, options) {
11190
11214
  },
11191
11215
  errorMessage: state.errorMessage,
11192
11216
  errorReason: state.errorReason,
11193
- lastUpdated: state.lastUpdated
11217
+ lastUpdated: state.lastUpdated,
11218
+ settings: state.settings
11194
11219
  };
11195
11220
  }
11196
11221
  function buildSessionEntries(allStates, cdpManagers, options = {}) {
@@ -11557,6 +11582,8 @@ function getSendChatInputEnvelope(args) {
11557
11582
  function getHistorySessionId(h, args) {
11558
11583
  const explicit = typeof args?.historySessionId === "string" ? args.historySessionId.trim() : "";
11559
11584
  if (explicit) return explicit;
11585
+ const explicitProviderSessionId = typeof args?.providerSessionId === "string" ? args.providerSessionId.trim() : "";
11586
+ if (explicitProviderSessionId) return explicitProviderSessionId;
11560
11587
  const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
11561
11588
  if (!targetSessionId) return void 0;
11562
11589
  const instance = h.ctx.instanceManager?.getInstance(targetSessionId);
@@ -12120,7 +12147,32 @@ async function handleReadChat(h, args) {
12120
12147
  ...coverage ? { coverage } : {}
12121
12148
  }, args);
12122
12149
  }
12123
- return { success: false, error: `${transport} adapter not found` };
12150
+ const historyLimit = normalizeReadChatTailLimit(args);
12151
+ try {
12152
+ const agentStr = provider?.type || args?.agentType || getCurrentProviderType(h);
12153
+ const workspace = typeof args?.workspace === "string" ? args.workspace : typeof h.currentSession?.workspace === "string" ? h.currentSession.workspace : void 0;
12154
+ const history = readProviderChatHistory(agentStr, {
12155
+ canonicalHistory: provider?.canonicalHistory,
12156
+ historySessionId,
12157
+ workspace,
12158
+ offset: 0,
12159
+ limit: historyLimit,
12160
+ excludeRecentCount: 0,
12161
+ historyBehavior: provider?.historyBehavior,
12162
+ scripts: provider?.scripts
12163
+ });
12164
+ const historyProviderSessionId = typeof history?.providerSessionId === "string" ? history.providerSessionId : historySessionId;
12165
+ return buildReadChatCommandResult({
12166
+ messages: Array.isArray(history?.messages) ? history.messages : [],
12167
+ status: "idle",
12168
+ ...typeof history?.title === "string" ? { title: history.title } : {},
12169
+ ...historyProviderSessionId ? { providerSessionId: historyProviderSessionId } : {},
12170
+ ...provider?.historyBehavior?.transcriptAuthority === "provider" || provider?.historyBehavior?.transcriptAuthority === "daemon" ? { transcriptAuthority: (provider?.historyBehavior).transcriptAuthority } : {},
12171
+ coverage: "tail"
12172
+ }, args);
12173
+ } catch (error) {
12174
+ return { success: false, error: error?.message || `${transport} adapter not found` };
12175
+ }
12124
12176
  }
12125
12177
  if (isExtensionTransport(transport)) {
12126
12178
  let extensionReadChatError = "";
@@ -14671,7 +14723,7 @@ var CliProviderInstance = class {
14671
14723
  this.errorMessage = void 0;
14672
14724
  this.errorReason = void 0;
14673
14725
  }
14674
- const autoApproveActive = adapterStatus.status === "waiting_approval" && this.shouldAutoApprove();
14726
+ const autoApproveActive = this.maybeAutoApproveStatus(adapterStatus, Date.now());
14675
14727
  const visibleStatus = parseErrorMessage ? "error" : autoApproveActive ? "generating" : adapterStatus.status;
14676
14728
  const parsedProviderSessionId = normalizeProviderSessionId(
14677
14729
  this.provider,
@@ -14864,12 +14916,8 @@ var CliProviderInstance = class {
14864
14916
  }
14865
14917
  this.applyProviderResponse(parsed.payload, { phase: "immediate" });
14866
14918
  }
14867
- detectStatusTransition() {
14868
- const now = Date.now();
14869
- const adapterStatus = this.adapter.getStatus({ allowParse: false });
14870
- const parsedStatus = null;
14871
- const rawStatus = adapterStatus.status;
14872
- const autoApproveActive = rawStatus === "waiting_approval" && this.shouldAutoApprove();
14919
+ maybeAutoApproveStatus(adapterStatus, now = Date.now()) {
14920
+ const autoApproveActive = adapterStatus?.status === "waiting_approval" && this.shouldAutoApprove();
14873
14921
  if (autoApproveActive && !this.autoApproveBusy) {
14874
14922
  this.autoApproveBusy = true;
14875
14923
  if (this.autoApproveBusyTimer) clearTimeout(this.autoApproveBusyTimer);
@@ -14877,12 +14925,21 @@ var CliProviderInstance = class {
14877
14925
  this.autoApproveBusy = false;
14878
14926
  this.autoApproveBusyTimer = null;
14879
14927
  }, 2e3);
14880
- const { index: buttonIndex, label: buttonLabel } = pickApprovalButton(adapterStatus.activeModal?.buttons, this.provider);
14881
- this.recordAutoApproval(adapterStatus.activeModal?.message, buttonLabel, now);
14928
+ const modal = adapterStatus.activeModal;
14929
+ const { index: buttonIndex, label: buttonLabel } = pickApprovalButton(modal?.buttons, this.provider);
14930
+ this.recordAutoApproval(modal?.message, buttonLabel, now);
14882
14931
  setTimeout(() => {
14883
14932
  this.adapter.resolveModal(buttonIndex);
14884
14933
  }, 0);
14885
14934
  }
14935
+ return autoApproveActive;
14936
+ }
14937
+ detectStatusTransition() {
14938
+ const now = Date.now();
14939
+ const adapterStatus = this.adapter.getStatus({ allowParse: false });
14940
+ const parsedStatus = null;
14941
+ const rawStatus = adapterStatus.status;
14942
+ const autoApproveActive = this.maybeAutoApproveStatus(adapterStatus, now);
14886
14943
  const newStatus = autoApproveActive ? "generating" : rawStatus;
14887
14944
  const dirName = this.workingDir.split("/").filter(Boolean).pop() || "session";
14888
14945
  const chatTitle = `${this.provider.name} \xB7 ${dirName}`;
@@ -16953,7 +17010,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
16953
17010
  resolvedDir,
16954
17011
  resolvedCliArgs,
16955
17012
  resolvedProvider,
16956
- this.providerLoader.getSettings(normalizedType),
17013
+ { ...this.providerLoader.getSettings(normalizedType), ...options?.settingsOverride || {} },
16957
17014
  false,
16958
17015
  {
16959
17016
  providerSessionId: sessionBinding.providerSessionId,
@@ -17207,7 +17264,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
17207
17264
  dir,
17208
17265
  args?.cliArgs,
17209
17266
  args?.initialModel,
17210
- { resumeSessionId: args?.resumeSessionId }
17267
+ { resumeSessionId: args?.resumeSessionId, settingsOverride: args?.settings }
17211
17268
  );
17212
17269
  return {
17213
17270
  success: true,
@@ -21266,11 +21323,16 @@ var DaemonCommandRouter = class {
21266
21323
  const cliType = typeof args?.cliType === "string" ? args.cliType.trim() : "claude-cli";
21267
21324
  if (!meshId) return { success: false, error: "meshId required" };
21268
21325
  try {
21269
- const { getMesh: getMesh3 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
21270
21326
  const { buildCoordinatorSystemPrompt: buildCoordinatorSystemPrompt2 } = await Promise.resolve().then(() => (init_coordinator_prompt(), coordinator_prompt_exports));
21271
- const mesh = getMesh3(meshId);
21327
+ let mesh;
21328
+ if (args?.inlineMesh && typeof args.inlineMesh === "object") {
21329
+ mesh = args.inlineMesh;
21330
+ } else {
21331
+ const { getMesh: getMesh3 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
21332
+ mesh = getMesh3(meshId);
21333
+ }
21272
21334
  if (!mesh) return { success: false, error: "Mesh not found" };
21273
- if (mesh.nodes.length === 0) return { success: false, error: "No nodes in mesh" };
21335
+ if (!Array.isArray(mesh.nodes) || mesh.nodes.length === 0) return { success: false, error: "No nodes in mesh" };
21274
21336
  const workspace = mesh.nodes[0].workspace;
21275
21337
  const providerMeta = this.deps.providerLoader.resolve?.(cliType) || this.deps.providerLoader.getMeta(cliType);
21276
21338
  const coordinatorSetup = resolveMeshCoordinatorSetup({
@@ -21338,10 +21400,20 @@ var DaemonCommandRouter = class {
21338
21400
  } catch {
21339
21401
  systemPrompt = `You are a Repo Mesh Coordinator for "${mesh.name}". Use the adhdev-mesh MCP tools (mesh_status, mesh_list_nodes, mesh_send_task, mesh_read_chat, mesh_launch_session, etc.) to orchestrate work across ${mesh.nodes.length} node(s).`;
21340
21402
  }
21403
+ const cliArgs = [];
21404
+ if (systemPrompt) {
21405
+ cliArgs.push("--append-system-prompt", systemPrompt);
21406
+ }
21407
+ if (cliType === "claude-cli") {
21408
+ cliArgs.push("--mcp-config", coordinatorSetup.configPath);
21409
+ }
21341
21410
  const launchResult = await this.deps.cliManager.handleCliCommand("launch_cli", {
21342
21411
  cliType,
21343
21412
  dir: workspace,
21344
- initialPrompt: systemPrompt
21413
+ cliArgs: cliArgs.length > 0 ? cliArgs : void 0,
21414
+ settings: {
21415
+ meshCoordinatorFor: meshId
21416
+ }
21345
21417
  });
21346
21418
  if (!launchResult?.success) {
21347
21419
  return { success: false, error: launchResult?.error || "Failed to launch CLI session" };
@@ -21644,7 +21716,8 @@ var DaemonStatusReporter = class {
21644
21716
  workspace: session.workspace ?? null,
21645
21717
  title: session.title,
21646
21718
  cdpConnected: session.cdpConnected,
21647
- summaryMetadata: session.summaryMetadata
21719
+ summaryMetadata: session.summaryMetadata,
21720
+ settings: session.settings
21648
21721
  })),
21649
21722
  p2p: payload.p2p,
21650
21723
  timestamp: now
@@ -29086,6 +29159,48 @@ var SessionRegistry = class {
29086
29159
  // src/boot/daemon-lifecycle.ts
29087
29160
  init_logger();
29088
29161
  init_config();
29162
+
29163
+ // src/mesh/mesh-events.ts
29164
+ init_mesh_config();
29165
+ init_logger();
29166
+ function setupMeshEventForwarding(components) {
29167
+ components.instanceManager.onEvent((event) => {
29168
+ if (event.event !== "agent:generating_completed" && event.event !== "agent:waiting_approval") return;
29169
+ const instanceId = event.instanceId;
29170
+ if (!instanceId) return;
29171
+ const sourceInstance = components.instanceManager.getInstance(instanceId);
29172
+ if (!sourceInstance || sourceInstance.category !== "cli") return;
29173
+ const state = sourceInstance.getState();
29174
+ const workspace = state.workspace;
29175
+ if (!workspace) return;
29176
+ const mesh = getMeshByRepo(workspace);
29177
+ if (!mesh) return;
29178
+ const allInstances = components.instanceManager.getByCategory("cli");
29179
+ const coordinatorInstances = allInstances.filter((inst) => {
29180
+ const instState = inst.getState();
29181
+ if (instState.settings?.meshCoordinatorFor !== mesh.id) return false;
29182
+ if (instState.instanceId === instanceId) return false;
29183
+ return true;
29184
+ });
29185
+ if (coordinatorInstances.length === 0) return;
29186
+ const targetNode = mesh.nodes.find((n) => n.workspace === workspace);
29187
+ const nodeLabel = targetNode ? `Node '${targetNode.id}'` : `Agent at ${workspace}`;
29188
+ let messageText = "";
29189
+ if (event.event === "agent:generating_completed") {
29190
+ messageText = `[System] ${nodeLabel} has completed its task and is now idle. You may use mesh_read_chat to review its progress.`;
29191
+ } else if (event.event === "agent:waiting_approval") {
29192
+ messageText = `[System] ${nodeLabel} is waiting for approval to proceed. You may use mesh_read_chat and mesh_approve to handle it.`;
29193
+ }
29194
+ if (!messageText) return;
29195
+ for (const coord of coordinatorInstances) {
29196
+ const coordState = coord.getState();
29197
+ LOG.info("MeshEvents", `Forwarding event from ${workspace} to coordinator ${coordState.instanceId}`);
29198
+ coord.onEvent("send_message", { input: { text: messageText, textFallback: messageText } });
29199
+ }
29200
+ });
29201
+ }
29202
+
29203
+ // src/boot/daemon-lifecycle.ts
29089
29204
  async function initDaemonComponents(config) {
29090
29205
  installGlobalInterceptor();
29091
29206
  const appConfig = loadConfig();
@@ -29243,7 +29358,7 @@ async function initDaemonComponents(config) {
29243
29358
  });
29244
29359
  poller.start();
29245
29360
  instanceManager.startTicking(config.tickIntervalMs ?? 5e3);
29246
- return {
29361
+ const components = {
29247
29362
  providerLoader,
29248
29363
  instanceManager,
29249
29364
  cliManager,
@@ -29257,6 +29372,8 @@ async function initDaemonComponents(config) {
29257
29372
  detectedIdes: detectedIdesRef,
29258
29373
  refreshProviderAvailability
29259
29374
  };
29375
+ setupMeshEventForwarding(components);
29376
+ return components;
29260
29377
  }
29261
29378
  async function startDaemonDevSupport(options) {
29262
29379
  const devServer = new DevServer({