@adhdev/daemon-core 0.9.69 → 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.
@@ -206,6 +206,7 @@ export declare class ProviderCliAdapter implements CliAdapter {
206
206
  writeRaw(data: string): Promise<void>;
207
207
  resolveModal(buttonIndex: number): void;
208
208
  resize(cols: number, rows: number): void;
209
+ private getParsedDebugState;
209
210
  getDebugState(): Record<string, any>;
210
211
  getTraceState(limit?: number): Record<string, any>;
211
212
  getProviderResolutionMeta(): ProviderResolutionMeta;
@@ -75,6 +75,7 @@ export declare class DaemonCliManager {
75
75
  private registerCliInstance;
76
76
  startSession(cliType: string, workingDir: string, cliArgs?: string[], initialModel?: string, options?: {
77
77
  resumeSessionId?: string;
78
+ settingsOverride?: Record<string, any>;
78
79
  }): Promise<{
79
80
  runtimeSessionId: string;
80
81
  providerSessionId?: string;
package/dist/index.js CHANGED
@@ -3529,11 +3529,22 @@ var init_provider_cli_adapter = __esm({
3529
3529
  }
3530
3530
  }
3531
3531
  }
3532
+ getParsedDebugState() {
3533
+ if (this.startupParseGate || typeof this.cliScripts?.parseSession !== "function") return null;
3534
+ try {
3535
+ const parsed = this.getScriptParsedStatus();
3536
+ return parsed && typeof parsed === "object" ? parsed : null;
3537
+ } catch {
3538
+ return null;
3539
+ }
3540
+ }
3532
3541
  getDebugState() {
3533
3542
  const screenText = sanitizeTerminalText(this.terminalScreen.getText());
3534
3543
  const startupModal = this.startupParseGate ? this.runParseApproval(this.recentOutputBuffer) : null;
3535
3544
  const effectiveStatus = this.projectEffectiveStatus(startupModal);
3536
3545
  const effectiveReady = this.ready || !!startupModal;
3546
+ const parsedDebugState = this.getParsedDebugState();
3547
+ const parsedMessages = Array.isArray(parsedDebugState?.messages) ? parsedDebugState.messages : [];
3537
3548
  return {
3538
3549
  type: this.cliType,
3539
3550
  name: this.cliName,
@@ -3546,8 +3557,18 @@ var init_provider_cli_adapter = __esm({
3546
3557
  startupParseGate: this.startupParseGate,
3547
3558
  spawnAt: this.spawnAt,
3548
3559
  workingDir: this.workingDir,
3549
- messages: [],
3550
- messageCount: 0,
3560
+ messages: parsedMessages,
3561
+ messageCount: parsedMessages.length,
3562
+ parsedStatus: parsedDebugState ? {
3563
+ id: parsedDebugState.id,
3564
+ status: parsedDebugState.status,
3565
+ title: parsedDebugState.title,
3566
+ providerSessionId: parsedDebugState.providerSessionId,
3567
+ transcriptAuthority: parsedDebugState.transcriptAuthority,
3568
+ coverage: parsedDebugState.coverage,
3569
+ activeModal: parsedDebugState.activeModal,
3570
+ messageCount: parsedMessages.length
3571
+ } : null,
3551
3572
  screenText: screenText.slice(-4e3),
3552
3573
  currentTurnScope: this.currentTurnScope,
3553
3574
  startupBuffer: this.startupBuffer.slice(-4e3),
@@ -11247,7 +11268,8 @@ function buildIdeWorkspaceSession(state, cdpManagers, options) {
11247
11268
  },
11248
11269
  errorMessage: state.errorMessage,
11249
11270
  errorReason: state.errorReason,
11250
- lastUpdated: state.lastUpdated
11271
+ lastUpdated: state.lastUpdated,
11272
+ settings: state.settings
11251
11273
  };
11252
11274
  }
11253
11275
  function buildExtensionAgentSession(parent, ext, options) {
@@ -11282,7 +11304,8 @@ function buildExtensionAgentSession(parent, ext, options) {
11282
11304
  },
11283
11305
  errorMessage: ext.errorMessage,
11284
11306
  errorReason: ext.errorReason,
11285
- lastUpdated: ext.lastUpdated
11307
+ lastUpdated: ext.lastUpdated,
11308
+ settings: ext.settings
11286
11309
  };
11287
11310
  }
11288
11311
  function shouldIncludeExtensionSession(ext) {
@@ -11348,7 +11371,8 @@ function buildCliSession(state, options) {
11348
11371
  },
11349
11372
  errorMessage: state.errorMessage,
11350
11373
  errorReason: state.errorReason,
11351
- lastUpdated: state.lastUpdated
11374
+ lastUpdated: state.lastUpdated,
11375
+ settings: state.settings
11352
11376
  };
11353
11377
  }
11354
11378
  function buildAcpSession(state, options) {
@@ -11382,7 +11406,8 @@ function buildAcpSession(state, options) {
11382
11406
  },
11383
11407
  errorMessage: state.errorMessage,
11384
11408
  errorReason: state.errorReason,
11385
- lastUpdated: state.lastUpdated
11409
+ lastUpdated: state.lastUpdated,
11410
+ settings: state.settings
11386
11411
  };
11387
11412
  }
11388
11413
  function buildSessionEntries(allStates, cdpManagers, options = {}) {
@@ -11749,6 +11774,8 @@ function getSendChatInputEnvelope(args) {
11749
11774
  function getHistorySessionId(h, args) {
11750
11775
  const explicit = typeof args?.historySessionId === "string" ? args.historySessionId.trim() : "";
11751
11776
  if (explicit) return explicit;
11777
+ const explicitProviderSessionId = typeof args?.providerSessionId === "string" ? args.providerSessionId.trim() : "";
11778
+ if (explicitProviderSessionId) return explicitProviderSessionId;
11752
11779
  const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
11753
11780
  if (!targetSessionId) return void 0;
11754
11781
  const instance = h.ctx.instanceManager?.getInstance(targetSessionId);
@@ -12312,7 +12339,32 @@ async function handleReadChat(h, args) {
12312
12339
  ...coverage ? { coverage } : {}
12313
12340
  }, args);
12314
12341
  }
12315
- return { success: false, error: `${transport} adapter not found` };
12342
+ const historyLimit = normalizeReadChatTailLimit(args);
12343
+ try {
12344
+ const agentStr = provider?.type || args?.agentType || getCurrentProviderType(h);
12345
+ const workspace = typeof args?.workspace === "string" ? args.workspace : typeof h.currentSession?.workspace === "string" ? h.currentSession.workspace : void 0;
12346
+ const history = readProviderChatHistory(agentStr, {
12347
+ canonicalHistory: provider?.canonicalHistory,
12348
+ historySessionId,
12349
+ workspace,
12350
+ offset: 0,
12351
+ limit: historyLimit,
12352
+ excludeRecentCount: 0,
12353
+ historyBehavior: provider?.historyBehavior,
12354
+ scripts: provider?.scripts
12355
+ });
12356
+ const historyProviderSessionId = typeof history?.providerSessionId === "string" ? history.providerSessionId : historySessionId;
12357
+ return buildReadChatCommandResult({
12358
+ messages: Array.isArray(history?.messages) ? history.messages : [],
12359
+ status: "idle",
12360
+ ...typeof history?.title === "string" ? { title: history.title } : {},
12361
+ ...historyProviderSessionId ? { providerSessionId: historyProviderSessionId } : {},
12362
+ ...provider?.historyBehavior?.transcriptAuthority === "provider" || provider?.historyBehavior?.transcriptAuthority === "daemon" ? { transcriptAuthority: (provider?.historyBehavior).transcriptAuthority } : {},
12363
+ coverage: "tail"
12364
+ }, args);
12365
+ } catch (error) {
12366
+ return { success: false, error: error?.message || `${transport} adapter not found` };
12367
+ }
12316
12368
  }
12317
12369
  if (isExtensionTransport(transport)) {
12318
12370
  let extensionReadChatError = "";
@@ -14863,7 +14915,7 @@ var CliProviderInstance = class {
14863
14915
  this.errorMessage = void 0;
14864
14916
  this.errorReason = void 0;
14865
14917
  }
14866
- const autoApproveActive = adapterStatus.status === "waiting_approval" && this.shouldAutoApprove();
14918
+ const autoApproveActive = this.maybeAutoApproveStatus(adapterStatus, Date.now());
14867
14919
  const visibleStatus = parseErrorMessage ? "error" : autoApproveActive ? "generating" : adapterStatus.status;
14868
14920
  const parsedProviderSessionId = normalizeProviderSessionId(
14869
14921
  this.provider,
@@ -15056,12 +15108,8 @@ var CliProviderInstance = class {
15056
15108
  }
15057
15109
  this.applyProviderResponse(parsed.payload, { phase: "immediate" });
15058
15110
  }
15059
- detectStatusTransition() {
15060
- const now = Date.now();
15061
- const adapterStatus = this.adapter.getStatus({ allowParse: false });
15062
- const parsedStatus = null;
15063
- const rawStatus = adapterStatus.status;
15064
- const autoApproveActive = rawStatus === "waiting_approval" && this.shouldAutoApprove();
15111
+ maybeAutoApproveStatus(adapterStatus, now = Date.now()) {
15112
+ const autoApproveActive = adapterStatus?.status === "waiting_approval" && this.shouldAutoApprove();
15065
15113
  if (autoApproveActive && !this.autoApproveBusy) {
15066
15114
  this.autoApproveBusy = true;
15067
15115
  if (this.autoApproveBusyTimer) clearTimeout(this.autoApproveBusyTimer);
@@ -15069,12 +15117,21 @@ var CliProviderInstance = class {
15069
15117
  this.autoApproveBusy = false;
15070
15118
  this.autoApproveBusyTimer = null;
15071
15119
  }, 2e3);
15072
- const { index: buttonIndex, label: buttonLabel } = pickApprovalButton(adapterStatus.activeModal?.buttons, this.provider);
15073
- this.recordAutoApproval(adapterStatus.activeModal?.message, buttonLabel, now);
15120
+ const modal = adapterStatus.activeModal;
15121
+ const { index: buttonIndex, label: buttonLabel } = pickApprovalButton(modal?.buttons, this.provider);
15122
+ this.recordAutoApproval(modal?.message, buttonLabel, now);
15074
15123
  setTimeout(() => {
15075
15124
  this.adapter.resolveModal(buttonIndex);
15076
15125
  }, 0);
15077
15126
  }
15127
+ return autoApproveActive;
15128
+ }
15129
+ detectStatusTransition() {
15130
+ const now = Date.now();
15131
+ const adapterStatus = this.adapter.getStatus({ allowParse: false });
15132
+ const parsedStatus = null;
15133
+ const rawStatus = adapterStatus.status;
15134
+ const autoApproveActive = this.maybeAutoApproveStatus(adapterStatus, now);
15078
15135
  const newStatus = autoApproveActive ? "generating" : rawStatus;
15079
15136
  const dirName = this.workingDir.split("/").filter(Boolean).pop() || "session";
15080
15137
  const chatTitle = `${this.provider.name} \xB7 ${dirName}`;
@@ -17140,7 +17197,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
17140
17197
  resolvedDir,
17141
17198
  resolvedCliArgs,
17142
17199
  resolvedProvider,
17143
- this.providerLoader.getSettings(normalizedType),
17200
+ { ...this.providerLoader.getSettings(normalizedType), ...options?.settingsOverride || {} },
17144
17201
  false,
17145
17202
  {
17146
17203
  providerSessionId: sessionBinding.providerSessionId,
@@ -17394,7 +17451,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
17394
17451
  dir,
17395
17452
  args?.cliArgs,
17396
17453
  args?.initialModel,
17397
- { resumeSessionId: args?.resumeSessionId }
17454
+ { resumeSessionId: args?.resumeSessionId, settingsOverride: args?.settings }
17398
17455
  );
17399
17456
  return {
17400
17457
  success: true,
@@ -21453,11 +21510,16 @@ var DaemonCommandRouter = class {
21453
21510
  const cliType = typeof args?.cliType === "string" ? args.cliType.trim() : "claude-cli";
21454
21511
  if (!meshId) return { success: false, error: "meshId required" };
21455
21512
  try {
21456
- const { getMesh: getMesh3 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
21457
21513
  const { buildCoordinatorSystemPrompt: buildCoordinatorSystemPrompt2 } = await Promise.resolve().then(() => (init_coordinator_prompt(), coordinator_prompt_exports));
21458
- const mesh = getMesh3(meshId);
21514
+ let mesh;
21515
+ if (args?.inlineMesh && typeof args.inlineMesh === "object") {
21516
+ mesh = args.inlineMesh;
21517
+ } else {
21518
+ const { getMesh: getMesh3 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
21519
+ mesh = getMesh3(meshId);
21520
+ }
21459
21521
  if (!mesh) return { success: false, error: "Mesh not found" };
21460
- if (mesh.nodes.length === 0) return { success: false, error: "No nodes in mesh" };
21522
+ if (!Array.isArray(mesh.nodes) || mesh.nodes.length === 0) return { success: false, error: "No nodes in mesh" };
21461
21523
  const workspace = mesh.nodes[0].workspace;
21462
21524
  const providerMeta = this.deps.providerLoader.resolve?.(cliType) || this.deps.providerLoader.getMeta(cliType);
21463
21525
  const coordinatorSetup = resolveMeshCoordinatorSetup({
@@ -21525,10 +21587,20 @@ var DaemonCommandRouter = class {
21525
21587
  } catch {
21526
21588
  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).`;
21527
21589
  }
21590
+ const cliArgs = [];
21591
+ if (systemPrompt) {
21592
+ cliArgs.push("--append-system-prompt", systemPrompt);
21593
+ }
21594
+ if (cliType === "claude-cli") {
21595
+ cliArgs.push("--mcp-config", coordinatorSetup.configPath);
21596
+ }
21528
21597
  const launchResult = await this.deps.cliManager.handleCliCommand("launch_cli", {
21529
21598
  cliType,
21530
21599
  dir: workspace,
21531
- initialPrompt: systemPrompt
21600
+ cliArgs: cliArgs.length > 0 ? cliArgs : void 0,
21601
+ settings: {
21602
+ meshCoordinatorFor: meshId
21603
+ }
21532
21604
  });
21533
21605
  if (!launchResult?.success) {
21534
21606
  return { success: false, error: launchResult?.error || "Failed to launch CLI session" };
@@ -21831,7 +21903,8 @@ var DaemonStatusReporter = class {
21831
21903
  workspace: session.workspace ?? null,
21832
21904
  title: session.title,
21833
21905
  cdpConnected: session.cdpConnected,
21834
- summaryMetadata: session.summaryMetadata
21906
+ summaryMetadata: session.summaryMetadata,
21907
+ settings: session.settings
21835
21908
  })),
21836
21909
  p2p: payload.p2p,
21837
21910
  timestamp: now
@@ -29268,6 +29341,48 @@ var SessionRegistry = class {
29268
29341
  // src/boot/daemon-lifecycle.ts
29269
29342
  init_logger();
29270
29343
  init_config();
29344
+
29345
+ // src/mesh/mesh-events.ts
29346
+ init_mesh_config();
29347
+ init_logger();
29348
+ function setupMeshEventForwarding(components) {
29349
+ components.instanceManager.onEvent((event) => {
29350
+ if (event.event !== "agent:generating_completed" && event.event !== "agent:waiting_approval") return;
29351
+ const instanceId = event.instanceId;
29352
+ if (!instanceId) return;
29353
+ const sourceInstance = components.instanceManager.getInstance(instanceId);
29354
+ if (!sourceInstance || sourceInstance.category !== "cli") return;
29355
+ const state = sourceInstance.getState();
29356
+ const workspace = state.workspace;
29357
+ if (!workspace) return;
29358
+ const mesh = getMeshByRepo(workspace);
29359
+ if (!mesh) return;
29360
+ const allInstances = components.instanceManager.getByCategory("cli");
29361
+ const coordinatorInstances = allInstances.filter((inst) => {
29362
+ const instState = inst.getState();
29363
+ if (instState.settings?.meshCoordinatorFor !== mesh.id) return false;
29364
+ if (instState.instanceId === instanceId) return false;
29365
+ return true;
29366
+ });
29367
+ if (coordinatorInstances.length === 0) return;
29368
+ const targetNode = mesh.nodes.find((n) => n.workspace === workspace);
29369
+ const nodeLabel = targetNode ? `Node '${targetNode.id}'` : `Agent at ${workspace}`;
29370
+ let messageText = "";
29371
+ if (event.event === "agent:generating_completed") {
29372
+ messageText = `[System] ${nodeLabel} has completed its task and is now idle. You may use mesh_read_chat to review its progress.`;
29373
+ } else if (event.event === "agent:waiting_approval") {
29374
+ messageText = `[System] ${nodeLabel} is waiting for approval to proceed. You may use mesh_read_chat and mesh_approve to handle it.`;
29375
+ }
29376
+ if (!messageText) return;
29377
+ for (const coord of coordinatorInstances) {
29378
+ const coordState = coord.getState();
29379
+ LOG.info("MeshEvents", `Forwarding event from ${workspace} to coordinator ${coordState.instanceId}`);
29380
+ coord.onEvent("send_message", { input: { text: messageText, textFallback: messageText } });
29381
+ }
29382
+ });
29383
+ }
29384
+
29385
+ // src/boot/daemon-lifecycle.ts
29271
29386
  async function initDaemonComponents(config) {
29272
29387
  installGlobalInterceptor();
29273
29388
  const appConfig = loadConfig();
@@ -29425,7 +29540,7 @@ async function initDaemonComponents(config) {
29425
29540
  });
29426
29541
  poller.start();
29427
29542
  instanceManager.startTicking(config.tickIntervalMs ?? 5e3);
29428
- return {
29543
+ const components = {
29429
29544
  providerLoader,
29430
29545
  instanceManager,
29431
29546
  cliManager,
@@ -29439,6 +29554,8 @@ async function initDaemonComponents(config) {
29439
29554
  detectedIdes: detectedIdesRef,
29440
29555
  refreshProviderAvailability
29441
29556
  };
29557
+ setupMeshEventForwarding(components);
29558
+ return components;
29442
29559
  }
29443
29560
  async function startDaemonDevSupport(options) {
29444
29561
  const devServer = new DevServer({