@adhdev/daemon-core 0.9.70 → 0.9.72

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
@@ -2222,7 +2222,7 @@ var init_provider_cli_adapter = __esm({
2222
2222
  `[${this.cliType}] Waiting for interactive prompt: status=${status} stableMs=${stableMs} recentOutputMs=${recentlyOutput} screen=${JSON.stringify(summarizeCliTraceText(screenText, 220)).slice(0, 260)}`
2223
2223
  );
2224
2224
  }
2225
- await new Promise((resolve15) => setTimeout(resolve15, 50));
2225
+ await new Promise((resolve16) => setTimeout(resolve16, 50));
2226
2226
  }
2227
2227
  const finalScreenText = this.terminalScreen.getText() || "";
2228
2228
  LOG.warn(
@@ -3132,7 +3132,7 @@ var init_provider_cli_adapter = __esm({
3132
3132
  const deadline = Date.now() + 1e4;
3133
3133
  while (this.startupParseGate && Date.now() < deadline) {
3134
3134
  this.resolveStartupState("send_wait");
3135
- await new Promise((resolve15) => setTimeout(resolve15, 50));
3135
+ await new Promise((resolve16) => setTimeout(resolve16, 50));
3136
3136
  }
3137
3137
  }
3138
3138
  if (!allowInterventionPrompt) {
@@ -3208,13 +3208,13 @@ var init_provider_cli_adapter = __esm({
3208
3208
  }
3209
3209
  this.responseEpoch += 1;
3210
3210
  this.responseSettleIgnoreUntil = Date.now() + submitDelayMs + this.timeouts.outputSettle + 250;
3211
- await new Promise((resolve15, reject) => {
3211
+ await new Promise((resolve16, reject) => {
3212
3212
  let resolved = false;
3213
3213
  const completion = {
3214
3214
  resolveOnce: () => {
3215
3215
  if (resolved) return;
3216
3216
  resolved = true;
3217
- resolve15();
3217
+ resolve16();
3218
3218
  },
3219
3219
  rejectOnce: (error) => {
3220
3220
  if (resolved) return;
@@ -3372,17 +3372,17 @@ var init_provider_cli_adapter = __esm({
3372
3372
  }
3373
3373
  }
3374
3374
  waitForStopped(timeoutMs) {
3375
- return new Promise((resolve15) => {
3375
+ return new Promise((resolve16) => {
3376
3376
  const startedAt = Date.now();
3377
3377
  const timer = setInterval(() => {
3378
3378
  if (!this.ptyProcess || this.currentStatus === "stopped") {
3379
3379
  clearInterval(timer);
3380
- resolve15(true);
3380
+ resolve16(true);
3381
3381
  return;
3382
3382
  }
3383
3383
  if (Date.now() - startedAt >= timeoutMs) {
3384
3384
  clearInterval(timer);
3385
- resolve15(false);
3385
+ resolve16(false);
3386
3386
  }
3387
3387
  }, 100);
3388
3388
  });
@@ -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),
@@ -5612,8 +5633,8 @@ async function detectIDEs(providerLoader) {
5612
5633
  if (existsSync5(bundledCli)) resolvedCli = bundledCli;
5613
5634
  }
5614
5635
  if (!resolvedCli && appPath && os21 === "win32") {
5615
- const { dirname: dirname7 } = await import("path");
5616
- const appDir = dirname7(appPath);
5636
+ const { dirname: dirname8 } = await import("path");
5637
+ const appDir = dirname8(appPath);
5617
5638
  const candidates = [
5618
5639
  `${appDir}\\\\bin\\\\${def.cli}.cmd`,
5619
5640
  `${appDir}\\\\bin\\\\${def.cli}`,
@@ -5677,19 +5698,19 @@ function resolveCommandPath(command) {
5677
5698
  return null;
5678
5699
  }
5679
5700
  function execAsync(cmd, timeoutMs = 5e3) {
5680
- return new Promise((resolve15) => {
5701
+ return new Promise((resolve16) => {
5681
5702
  const child = exec(cmd, {
5682
5703
  encoding: "utf-8",
5683
5704
  timeout: timeoutMs,
5684
5705
  ...process.platform === "win32" ? { windowsHide: true } : {}
5685
5706
  }, (err, stdout) => {
5686
5707
  if (err || !stdout?.trim()) {
5687
- resolve15(null);
5708
+ resolve16(null);
5688
5709
  } else {
5689
- resolve15(stdout.trim());
5710
+ resolve16(stdout.trim());
5690
5711
  }
5691
5712
  });
5692
- child.on("error", () => resolve15(null));
5713
+ child.on("error", () => resolve16(null));
5693
5714
  });
5694
5715
  }
5695
5716
  async function detectCLIs(providerLoader, options) {
@@ -6054,7 +6075,7 @@ var DaemonCdpManager = class {
6054
6075
  * Returns multiple entries if multiple IDE windows are open on same port
6055
6076
  */
6056
6077
  static listAllTargets(port) {
6057
- return new Promise((resolve15) => {
6078
+ return new Promise((resolve16) => {
6058
6079
  const req = http.get(`http://127.0.0.1:${port}/json`, (res) => {
6059
6080
  let data = "";
6060
6081
  res.on("data", (chunk) => data += chunk.toString());
@@ -6070,16 +6091,16 @@ var DaemonCdpManager = class {
6070
6091
  (t) => !isNonMain(t.title || "") && t.url?.includes("workbench.html") && !t.url?.includes("agent")
6071
6092
  );
6072
6093
  const fallbackPages = pages.filter((t) => !isNonMain(t.title || ""));
6073
- resolve15(mainPages.length > 0 ? mainPages : fallbackPages);
6094
+ resolve16(mainPages.length > 0 ? mainPages : fallbackPages);
6074
6095
  } catch {
6075
- resolve15([]);
6096
+ resolve16([]);
6076
6097
  }
6077
6098
  });
6078
6099
  });
6079
- req.on("error", () => resolve15([]));
6100
+ req.on("error", () => resolve16([]));
6080
6101
  req.setTimeout(2e3, () => {
6081
6102
  req.destroy();
6082
- resolve15([]);
6103
+ resolve16([]);
6083
6104
  });
6084
6105
  });
6085
6106
  }
@@ -6119,7 +6140,7 @@ var DaemonCdpManager = class {
6119
6140
  }
6120
6141
  }
6121
6142
  findTargetOnPort(port) {
6122
- return new Promise((resolve15) => {
6143
+ return new Promise((resolve16) => {
6123
6144
  const req = http.get(`http://127.0.0.1:${port}/json`, (res) => {
6124
6145
  let data = "";
6125
6146
  res.on("data", (chunk) => data += chunk.toString());
@@ -6130,7 +6151,7 @@ var DaemonCdpManager = class {
6130
6151
  (t) => (t.type === "page" || t.type === "browser" || t.type === "Page") && t.webSocketDebuggerUrl
6131
6152
  );
6132
6153
  if (pages.length === 0) {
6133
- resolve15(targets.find((t) => t.webSocketDebuggerUrl) || null);
6154
+ resolve16(targets.find((t) => t.webSocketDebuggerUrl) || null);
6134
6155
  return;
6135
6156
  }
6136
6157
  const titleFilteredPages = pages.filter((t) => !this.isNonMainTitle(t.title || ""));
@@ -6149,25 +6170,25 @@ var DaemonCdpManager = class {
6149
6170
  this._targetId = selected.target.id;
6150
6171
  }
6151
6172
  this._pageTitle = selected.target.title || "";
6152
- resolve15(selected.target);
6173
+ resolve16(selected.target);
6153
6174
  return;
6154
6175
  }
6155
6176
  if (previousTargetId) {
6156
6177
  this.log(`[CDP] Target ${previousTargetId} not found in page list`);
6157
- resolve15(null);
6178
+ resolve16(null);
6158
6179
  return;
6159
6180
  }
6160
6181
  this._pageTitle = list[0]?.title || "";
6161
- resolve15(list[0]);
6182
+ resolve16(list[0]);
6162
6183
  } catch {
6163
- resolve15(null);
6184
+ resolve16(null);
6164
6185
  }
6165
6186
  });
6166
6187
  });
6167
- req.on("error", () => resolve15(null));
6188
+ req.on("error", () => resolve16(null));
6168
6189
  req.setTimeout(2e3, () => {
6169
6190
  req.destroy();
6170
- resolve15(null);
6191
+ resolve16(null);
6171
6192
  });
6172
6193
  });
6173
6194
  }
@@ -6178,7 +6199,7 @@ var DaemonCdpManager = class {
6178
6199
  this.extensionProviders = providers;
6179
6200
  }
6180
6201
  connectToTarget(wsUrl) {
6181
- return new Promise((resolve15) => {
6202
+ return new Promise((resolve16) => {
6182
6203
  this.ws = new WebSocket(wsUrl);
6183
6204
  this.ws.on("open", async () => {
6184
6205
  this._connected = true;
@@ -6188,17 +6209,17 @@ var DaemonCdpManager = class {
6188
6209
  }
6189
6210
  this.connectBrowserWs().catch(() => {
6190
6211
  });
6191
- resolve15(true);
6212
+ resolve16(true);
6192
6213
  });
6193
6214
  this.ws.on("message", (data) => {
6194
6215
  try {
6195
6216
  const msg = JSON.parse(data.toString());
6196
6217
  if (msg.id && this.pending.has(msg.id)) {
6197
- const { resolve: resolve16, reject } = this.pending.get(msg.id);
6218
+ const { resolve: resolve17, reject } = this.pending.get(msg.id);
6198
6219
  this.pending.delete(msg.id);
6199
6220
  this.failureCount = 0;
6200
6221
  if (msg.error) reject(new Error(msg.error.message));
6201
- else resolve16(msg.result);
6222
+ else resolve17(msg.result);
6202
6223
  } else if (msg.method === "Runtime.executionContextCreated") {
6203
6224
  this.contexts.add(msg.params.context.id);
6204
6225
  } else if (msg.method === "Runtime.executionContextDestroyed") {
@@ -6221,7 +6242,7 @@ var DaemonCdpManager = class {
6221
6242
  this.ws.on("error", (err) => {
6222
6243
  this.log(`[CDP] WebSocket error: ${err.message}`);
6223
6244
  this._connected = false;
6224
- resolve15(false);
6245
+ resolve16(false);
6225
6246
  });
6226
6247
  });
6227
6248
  }
@@ -6235,7 +6256,7 @@ var DaemonCdpManager = class {
6235
6256
  return;
6236
6257
  }
6237
6258
  this.log(`[CDP] Connecting browser WS for target discovery...`);
6238
- await new Promise((resolve15, reject) => {
6259
+ await new Promise((resolve16, reject) => {
6239
6260
  this.browserWs = new WebSocket(browserWsUrl);
6240
6261
  this.browserWs.on("open", async () => {
6241
6262
  this._browserConnected = true;
@@ -6245,16 +6266,16 @@ var DaemonCdpManager = class {
6245
6266
  } catch (e) {
6246
6267
  this.log(`[CDP] setDiscoverTargets failed: ${e.message}`);
6247
6268
  }
6248
- resolve15();
6269
+ resolve16();
6249
6270
  });
6250
6271
  this.browserWs.on("message", (data) => {
6251
6272
  try {
6252
6273
  const msg = JSON.parse(data.toString());
6253
6274
  if (msg.id && this.browserPending.has(msg.id)) {
6254
- const { resolve: resolve16, reject: reject2 } = this.browserPending.get(msg.id);
6275
+ const { resolve: resolve17, reject: reject2 } = this.browserPending.get(msg.id);
6255
6276
  this.browserPending.delete(msg.id);
6256
6277
  if (msg.error) reject2(new Error(msg.error.message));
6257
- else resolve16(msg.result);
6278
+ else resolve17(msg.result);
6258
6279
  }
6259
6280
  } catch {
6260
6281
  }
@@ -6274,31 +6295,31 @@ var DaemonCdpManager = class {
6274
6295
  }
6275
6296
  }
6276
6297
  getBrowserWsUrl() {
6277
- return new Promise((resolve15) => {
6298
+ return new Promise((resolve16) => {
6278
6299
  const req = http.get(`http://127.0.0.1:${this.port}/json/version`, (res) => {
6279
6300
  let data = "";
6280
6301
  res.on("data", (chunk) => data += chunk.toString());
6281
6302
  res.on("end", () => {
6282
6303
  try {
6283
6304
  const info = JSON.parse(data);
6284
- resolve15(info.webSocketDebuggerUrl || null);
6305
+ resolve16(info.webSocketDebuggerUrl || null);
6285
6306
  } catch {
6286
- resolve15(null);
6307
+ resolve16(null);
6287
6308
  }
6288
6309
  });
6289
6310
  });
6290
- req.on("error", () => resolve15(null));
6311
+ req.on("error", () => resolve16(null));
6291
6312
  req.setTimeout(3e3, () => {
6292
6313
  req.destroy();
6293
- resolve15(null);
6314
+ resolve16(null);
6294
6315
  });
6295
6316
  });
6296
6317
  }
6297
6318
  sendBrowser(method, params = {}, timeoutMs = 15e3) {
6298
- return new Promise((resolve15, reject) => {
6319
+ return new Promise((resolve16, reject) => {
6299
6320
  if (!this.browserWs || !this._browserConnected) return reject(new Error("Browser WS not connected"));
6300
6321
  const id = this.browserMsgId++;
6301
- this.browserPending.set(id, { resolve: resolve15, reject });
6322
+ this.browserPending.set(id, { resolve: resolve16, reject });
6302
6323
  this.browserWs.send(JSON.stringify({ id, method, params }));
6303
6324
  setTimeout(() => {
6304
6325
  if (this.browserPending.has(id)) {
@@ -6338,11 +6359,11 @@ var DaemonCdpManager = class {
6338
6359
  }
6339
6360
  // ─── CDP Protocol ────────────────────────────────────────
6340
6361
  sendInternal(method, params = {}, timeoutMs = 15e3) {
6341
- return new Promise((resolve15, reject) => {
6362
+ return new Promise((resolve16, reject) => {
6342
6363
  if (!this.ws || !this._connected) return reject(new Error("CDP not connected"));
6343
6364
  if (this.ws.readyState !== WebSocket.OPEN) return reject(new Error("WebSocket not open"));
6344
6365
  const id = this.msgId++;
6345
- this.pending.set(id, { resolve: resolve15, reject });
6366
+ this.pending.set(id, { resolve: resolve16, reject });
6346
6367
  this.ws.send(JSON.stringify({ id, method, params }));
6347
6368
  setTimeout(() => {
6348
6369
  if (this.pending.has(id)) {
@@ -6591,7 +6612,7 @@ var DaemonCdpManager = class {
6591
6612
  const browserWs = this.browserWs;
6592
6613
  let msgId = this.browserMsgId;
6593
6614
  const sendWs = (method, params = {}, sessionId) => {
6594
- return new Promise((resolve15, reject) => {
6615
+ return new Promise((resolve16, reject) => {
6595
6616
  const mid = msgId++;
6596
6617
  this.browserMsgId = msgId;
6597
6618
  const handler = (raw) => {
@@ -6600,7 +6621,7 @@ var DaemonCdpManager = class {
6600
6621
  if (msg.id === mid) {
6601
6622
  browserWs.removeListener("message", handler);
6602
6623
  if (msg.error) reject(new Error(msg.error.message || JSON.stringify(msg.error)));
6603
- else resolve15(msg.result);
6624
+ else resolve16(msg.result);
6604
6625
  }
6605
6626
  } catch {
6606
6627
  }
@@ -6801,14 +6822,14 @@ var DaemonCdpManager = class {
6801
6822
  if (!ws || ws.readyState !== WebSocket.OPEN) {
6802
6823
  throw new Error("CDP not connected");
6803
6824
  }
6804
- return new Promise((resolve15, reject) => {
6825
+ return new Promise((resolve16, reject) => {
6805
6826
  const id = getNextId();
6806
6827
  pendingMap.set(id, {
6807
6828
  resolve: (result) => {
6808
6829
  if (result?.result?.subtype === "error") {
6809
6830
  reject(new Error(result.result.description));
6810
6831
  } else {
6811
- resolve15(result?.result?.value);
6832
+ resolve16(result?.result?.value);
6812
6833
  }
6813
6834
  },
6814
6835
  reject
@@ -6840,10 +6861,10 @@ var DaemonCdpManager = class {
6840
6861
  throw new Error("CDP not connected");
6841
6862
  }
6842
6863
  const sendViaSession = (method, params = {}) => {
6843
- return new Promise((resolve15, reject) => {
6864
+ return new Promise((resolve16, reject) => {
6844
6865
  const pendingMap = this._browserConnected ? this.browserPending : this.pending;
6845
6866
  const id = this._browserConnected ? this.browserMsgId++ : this.msgId++;
6846
- pendingMap.set(id, { resolve: resolve15, reject });
6867
+ pendingMap.set(id, { resolve: resolve16, reject });
6847
6868
  ws.send(JSON.stringify({ id, sessionId, method, params }));
6848
6869
  setTimeout(() => {
6849
6870
  if (pendingMap.has(id)) {
@@ -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);
@@ -12022,7 +12049,7 @@ function getCliVisibleTranscriptCount(adapter) {
12022
12049
  async function getStableExtensionBaseline(h) {
12023
12050
  const first = await readExtensionChatState(h);
12024
12051
  if (getStateMessageCount(first) > 0 || getStateLastSignature(first)) return first;
12025
- await new Promise((resolve15) => setTimeout(resolve15, 150));
12052
+ await new Promise((resolve16) => setTimeout(resolve16, 150));
12026
12053
  const second = await readExtensionChatState(h);
12027
12054
  return getStateMessageCount(second) >= getStateMessageCount(first) ? second : first;
12028
12055
  }
@@ -12030,7 +12057,7 @@ async function verifyExtensionSendObserved(h, before) {
12030
12057
  const beforeCount = getStateMessageCount(before);
12031
12058
  const beforeSignature = getStateLastSignature(before);
12032
12059
  for (let attempt = 0; attempt < 12; attempt += 1) {
12033
- await new Promise((resolve15) => setTimeout(resolve15, 250));
12060
+ await new Promise((resolve16) => setTimeout(resolve16, 250));
12034
12061
  const state = await readExtensionChatState(h);
12035
12062
  if (state?.status === "waiting_approval") return true;
12036
12063
  const afterCount = getStateMessageCount(state);
@@ -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 = "";
@@ -13638,7 +13690,7 @@ async function executeProviderScript(h, args, scriptName) {
13638
13690
  const enterCount = cliCommand.enterCount || 1;
13639
13691
  await adapter.writeRaw(cliCommand.text + "\r");
13640
13692
  for (let i = 1; i < enterCount; i += 1) {
13641
- await new Promise((resolve15) => setTimeout(resolve15, 50));
13693
+ await new Promise((resolve16) => setTimeout(resolve16, 50));
13642
13694
  await adapter.writeRaw("\r");
13643
13695
  }
13644
13696
  }
@@ -14323,7 +14375,7 @@ var DaemonCommandHandler = class {
14323
14375
  try {
14324
14376
  const http3 = await import("http");
14325
14377
  const postData = JSON.stringify(body);
14326
- const result = await new Promise((resolve15, reject) => {
14378
+ const result = await new Promise((resolve16, reject) => {
14327
14379
  const req = http3.request({
14328
14380
  hostname: "127.0.0.1",
14329
14381
  port: 19280,
@@ -14335,9 +14387,9 @@ var DaemonCommandHandler = class {
14335
14387
  res.on("data", (chunk) => data += chunk);
14336
14388
  res.on("end", () => {
14337
14389
  try {
14338
- resolve15(JSON.parse(data));
14390
+ resolve16(JSON.parse(data));
14339
14391
  } catch {
14340
- resolve15({ raw: data });
14392
+ resolve16({ raw: data });
14341
14393
  }
14342
14394
  });
14343
14395
  });
@@ -14355,15 +14407,15 @@ var DaemonCommandHandler = class {
14355
14407
  if (!providerType) return { success: false, error: "providerType required" };
14356
14408
  try {
14357
14409
  const http3 = await import("http");
14358
- const result = await new Promise((resolve15, reject) => {
14410
+ const result = await new Promise((resolve16, reject) => {
14359
14411
  http3.get(`http://127.0.0.1:19280/api/providers/${providerType}/${endpoint}`, (res) => {
14360
14412
  let data = "";
14361
14413
  res.on("data", (chunk) => data += chunk);
14362
14414
  res.on("end", () => {
14363
14415
  try {
14364
- resolve15(JSON.parse(data));
14416
+ resolve16(JSON.parse(data));
14365
14417
  } catch {
14366
- resolve15({ raw: data });
14418
+ resolve16({ raw: data });
14367
14419
  }
14368
14420
  });
14369
14421
  }).on("error", reject);
@@ -14377,7 +14429,7 @@ var DaemonCommandHandler = class {
14377
14429
  try {
14378
14430
  const http3 = await import("http");
14379
14431
  const postData = JSON.stringify(args || {});
14380
- const result = await new Promise((resolve15, reject) => {
14432
+ const result = await new Promise((resolve16, reject) => {
14381
14433
  const req = http3.request({
14382
14434
  hostname: "127.0.0.1",
14383
14435
  port: 19280,
@@ -14389,9 +14441,9 @@ var DaemonCommandHandler = class {
14389
14441
  res.on("data", (chunk) => data += chunk);
14390
14442
  res.on("end", () => {
14391
14443
  try {
14392
- resolve15(JSON.parse(data));
14444
+ resolve16(JSON.parse(data));
14393
14445
  } catch {
14394
- resolve15({ raw: data });
14446
+ resolve16({ raw: data });
14395
14447
  }
14396
14448
  });
14397
14449
  });
@@ -14515,7 +14567,7 @@ async function waitForCliAdapterReady(adapter, options) {
14515
14567
  if (status === "stopped") {
14516
14568
  throw new Error("CLI runtime stopped before it became ready");
14517
14569
  }
14518
- await new Promise((resolve15) => setTimeout(resolve15, pollMs));
14570
+ await new Promise((resolve16) => setTimeout(resolve16, pollMs));
14519
14571
  }
14520
14572
  throw new Error(`CLI runtime did not become ready within ${timeoutMs}ms`);
14521
14573
  }
@@ -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,
@@ -14858,18 +14910,14 @@ var CliProviderInstance = class {
14858
14910
  const enterCount = cliCommand.enterCount || 1;
14859
14911
  await this.adapter.writeRaw(cliCommand.text + "\r");
14860
14912
  for (let i = 1; i < enterCount; i += 1) {
14861
- await new Promise((resolve15) => setTimeout(resolve15, 50));
14913
+ await new Promise((resolve16) => setTimeout(resolve16, 50));
14862
14914
  await this.adapter.writeRaw("\r");
14863
14915
  }
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}`;
@@ -15963,13 +16020,13 @@ var AcpProviderInstance = class {
15963
16020
  }
15964
16021
  this.currentStatus = "waiting_approval";
15965
16022
  this.detectStatusTransition();
15966
- const approved = await new Promise((resolve15) => {
15967
- this.permissionResolvers.push(resolve15);
16023
+ const approved = await new Promise((resolve16) => {
16024
+ this.permissionResolvers.push(resolve16);
15968
16025
  setTimeout(() => {
15969
- const idx = this.permissionResolvers.indexOf(resolve15);
16026
+ const idx = this.permissionResolvers.indexOf(resolve16);
15970
16027
  if (idx >= 0) {
15971
16028
  this.permissionResolvers.splice(idx, 1);
15972
- resolve15(false);
16029
+ resolve16(false);
15973
16030
  }
15974
16031
  }, 3e5);
15975
16032
  });
@@ -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,
@@ -18555,7 +18612,7 @@ var ProviderLoader = class _ProviderLoader {
18555
18612
  return { updated: false };
18556
18613
  }
18557
18614
  try {
18558
- const etag = await new Promise((resolve15, reject) => {
18615
+ const etag = await new Promise((resolve16, reject) => {
18559
18616
  const options = {
18560
18617
  method: "HEAD",
18561
18618
  hostname: "github.com",
@@ -18573,7 +18630,7 @@ var ProviderLoader = class _ProviderLoader {
18573
18630
  headers: { "User-Agent": "adhdev-launcher" },
18574
18631
  timeout: 1e4
18575
18632
  }, (res2) => {
18576
- resolve15(res2.headers.etag || res2.headers["last-modified"] || "");
18633
+ resolve16(res2.headers.etag || res2.headers["last-modified"] || "");
18577
18634
  });
18578
18635
  req2.on("error", reject);
18579
18636
  req2.on("timeout", () => {
@@ -18582,7 +18639,7 @@ var ProviderLoader = class _ProviderLoader {
18582
18639
  });
18583
18640
  req2.end();
18584
18641
  } else {
18585
- resolve15(res.headers.etag || res.headers["last-modified"] || "");
18642
+ resolve16(res.headers.etag || res.headers["last-modified"] || "");
18586
18643
  }
18587
18644
  });
18588
18645
  req.on("error", reject);
@@ -18646,7 +18703,7 @@ var ProviderLoader = class _ProviderLoader {
18646
18703
  downloadFile(url, destPath) {
18647
18704
  const https = __require("https");
18648
18705
  const http3 = __require("http");
18649
- return new Promise((resolve15, reject) => {
18706
+ return new Promise((resolve16, reject) => {
18650
18707
  const doRequest = (reqUrl, redirectCount = 0) => {
18651
18708
  if (redirectCount > 5) {
18652
18709
  reject(new Error("Too many redirects"));
@@ -18666,7 +18723,7 @@ var ProviderLoader = class _ProviderLoader {
18666
18723
  res.pipe(ws);
18667
18724
  ws.on("finish", () => {
18668
18725
  ws.close();
18669
- resolve15();
18726
+ resolve16();
18670
18727
  });
18671
18728
  ws.on("error", reject);
18672
18729
  });
@@ -19245,17 +19302,17 @@ async function findFreePort(ports) {
19245
19302
  throw new Error("No free port found");
19246
19303
  }
19247
19304
  function checkPortFree(port) {
19248
- return new Promise((resolve15) => {
19305
+ return new Promise((resolve16) => {
19249
19306
  const server = net.createServer();
19250
19307
  server.unref();
19251
- server.on("error", () => resolve15(false));
19308
+ server.on("error", () => resolve16(false));
19252
19309
  server.listen(port, "127.0.0.1", () => {
19253
- server.close(() => resolve15(true));
19310
+ server.close(() => resolve16(true));
19254
19311
  });
19255
19312
  });
19256
19313
  }
19257
19314
  async function isCdpActive(port) {
19258
- return new Promise((resolve15) => {
19315
+ return new Promise((resolve16) => {
19259
19316
  const req = __require("http").get(`http://127.0.0.1:${port}/json/version`, {
19260
19317
  timeout: 2e3
19261
19318
  }, (res) => {
@@ -19264,16 +19321,16 @@ async function isCdpActive(port) {
19264
19321
  res.on("end", () => {
19265
19322
  try {
19266
19323
  const info = JSON.parse(data);
19267
- resolve15(!!info["WebKit-Version"] || !!info["Browser"]);
19324
+ resolve16(!!info["WebKit-Version"] || !!info["Browser"]);
19268
19325
  } catch {
19269
- resolve15(false);
19326
+ resolve16(false);
19270
19327
  }
19271
19328
  });
19272
19329
  });
19273
- req.on("error", () => resolve15(false));
19330
+ req.on("error", () => resolve16(false));
19274
19331
  req.on("timeout", () => {
19275
19332
  req.destroy();
19276
- resolve15(false);
19333
+ resolve16(false);
19277
19334
  });
19278
19335
  });
19279
19336
  }
@@ -19749,7 +19806,9 @@ cleanOldFiles();
19749
19806
  init_logger();
19750
19807
 
19751
19808
  // src/commands/mesh-coordinator.ts
19752
- import { join as join17 } from "path";
19809
+ import { existsSync as existsSync14, realpathSync as realpathSync2 } from "fs";
19810
+ import { createRequire as createRequire2 } from "module";
19811
+ import { dirname as dirname3, join as join17, resolve as resolve13 } from "path";
19753
19812
  var DEFAULT_SERVER_NAME = "adhdev-mesh";
19754
19813
  var DEFAULT_ADHDEV_MCP_COMMAND = "adhdev-mcp";
19755
19814
  function resolveMeshCoordinatorSetup(options) {
@@ -19774,11 +19833,23 @@ function resolveMeshCoordinatorSetup(options) {
19774
19833
  if (!path26) {
19775
19834
  return { kind: "unsupported", reason: "Provider auto-import MCP config is missing a config path" };
19776
19835
  }
19836
+ const mcpServer = resolveAdhdevMcpServerLaunch({
19837
+ meshId,
19838
+ nodeExecutable: options.nodeExecutable,
19839
+ adhdevMcpEntryPath: options.adhdevMcpEntryPath
19840
+ });
19841
+ if (!mcpServer) {
19842
+ return {
19843
+ kind: "unsupported",
19844
+ reason: "Could not resolve the ADHDev MCP server entrypoint without relying on a PATH bin shim"
19845
+ };
19846
+ }
19777
19847
  return {
19778
19848
  kind: "auto_import",
19779
19849
  serverName,
19780
19850
  configPath: join17(workspace, path26),
19781
- configFormat: mcpConfig.format
19851
+ configFormat: mcpConfig.format,
19852
+ mcpServer
19782
19853
  };
19783
19854
  }
19784
19855
  if (mcpConfig.mode === "manual") {
@@ -19810,6 +19881,53 @@ function resolveMeshCoordinatorSetup(options) {
19810
19881
  function renderMeshCoordinatorTemplate(template, values) {
19811
19882
  return template.replace(/\{\{\s*(meshId|workspace|serverName|adhdevMcpCommand)\s*\}\}/g, (_, key) => values[key] || "");
19812
19883
  }
19884
+ function resolveAdhdevMcpServerLaunch(options) {
19885
+ const entryPath = resolveAdhdevMcpEntryPath(options.adhdevMcpEntryPath);
19886
+ if (!entryPath) return null;
19887
+ return {
19888
+ command: options.nodeExecutable?.trim() || process.execPath,
19889
+ args: [entryPath, "--repo-mesh", options.meshId]
19890
+ };
19891
+ }
19892
+ function resolveAdhdevMcpEntryPath(explicitPath) {
19893
+ const explicit = explicitPath?.trim();
19894
+ if (explicit) return normalizeExistingPath(explicit) || explicit;
19895
+ const envPath = process.env.ADHDEV_MCP_SERVER_PATH?.trim();
19896
+ if (envPath) return normalizeExistingPath(envPath) || envPath;
19897
+ const candidates = [];
19898
+ const addCandidate = (candidate) => {
19899
+ if (!candidates.includes(candidate)) candidates.push(candidate);
19900
+ };
19901
+ const addPackagedCandidates = (baseFile) => {
19902
+ if (!baseFile) return;
19903
+ const realBase = normalizeExistingPath(baseFile) || baseFile;
19904
+ const dir = dirname3(realBase);
19905
+ addCandidate(resolve13(dir, "../vendor/mcp-server/index.js"));
19906
+ addCandidate(resolve13(dir, "../../vendor/mcp-server/index.js"));
19907
+ addCandidate(resolve13(dir, "../../../vendor/mcp-server/index.js"));
19908
+ };
19909
+ addPackagedCandidates(process.argv[1]);
19910
+ for (const candidate of candidates) {
19911
+ const normalized = normalizeExistingPath(candidate);
19912
+ if (normalized) return normalized;
19913
+ }
19914
+ try {
19915
+ const requireBase = process.argv[1] ? normalizeExistingPath(process.argv[1]) || process.argv[1] : join17(process.cwd(), "adhdev-daemon.js");
19916
+ const req = createRequire2(requireBase);
19917
+ const resolvedModule = req.resolve("@adhdev/mcp-server");
19918
+ return normalizeExistingPath(resolvedModule) || resolvedModule;
19919
+ } catch {
19920
+ return null;
19921
+ }
19922
+ }
19923
+ function normalizeExistingPath(filePath) {
19924
+ try {
19925
+ if (!existsSync14(filePath)) return null;
19926
+ return realpathSync2.native(filePath);
19927
+ } catch {
19928
+ return null;
19929
+ }
19930
+ }
19813
19931
 
19814
19932
  // src/status/snapshot.ts
19815
19933
  init_config();
@@ -20317,7 +20435,7 @@ async function waitForPidExit(pid, timeoutMs) {
20317
20435
  while (Date.now() - start < timeoutMs) {
20318
20436
  try {
20319
20437
  process.kill(pid, 0);
20320
- await new Promise((resolve15) => setTimeout(resolve15, 250));
20438
+ await new Promise((resolve16) => setTimeout(resolve16, 250));
20321
20439
  } catch {
20322
20440
  return;
20323
20441
  }
@@ -20428,7 +20546,7 @@ async function runDaemonUpgradeHelper(payload) {
20428
20546
  appendUpgradeLog(installOutput.trim());
20429
20547
  }
20430
20548
  if (process.platform === "win32") {
20431
- await new Promise((resolve15) => setTimeout(resolve15, 500));
20549
+ await new Promise((resolve16) => setTimeout(resolve16, 500));
20432
20550
  cleanupStaleGlobalInstallDirs(payload.packageName, installCommand.surface);
20433
20551
  appendUpgradeLog("Post-install staging cleanup complete");
20434
20552
  }
@@ -21266,11 +21384,16 @@ var DaemonCommandRouter = class {
21266
21384
  const cliType = typeof args?.cliType === "string" ? args.cliType.trim() : "claude-cli";
21267
21385
  if (!meshId) return { success: false, error: "meshId required" };
21268
21386
  try {
21269
- const { getMesh: getMesh3 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
21270
21387
  const { buildCoordinatorSystemPrompt: buildCoordinatorSystemPrompt2 } = await Promise.resolve().then(() => (init_coordinator_prompt(), coordinator_prompt_exports));
21271
- const mesh = getMesh3(meshId);
21388
+ let mesh;
21389
+ if (args?.inlineMesh && typeof args.inlineMesh === "object") {
21390
+ mesh = args.inlineMesh;
21391
+ } else {
21392
+ const { getMesh: getMesh3 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
21393
+ mesh = getMesh3(meshId);
21394
+ }
21272
21395
  if (!mesh) return { success: false, error: "Mesh not found" };
21273
- if (mesh.nodes.length === 0) return { success: false, error: "No nodes in mesh" };
21396
+ if (!Array.isArray(mesh.nodes) || mesh.nodes.length === 0) return { success: false, error: "No nodes in mesh" };
21274
21397
  const workspace = mesh.nodes[0].workspace;
21275
21398
  const providerMeta = this.deps.providerLoader.resolve?.(cliType) || this.deps.providerLoader.getMeta(cliType);
21276
21399
  const coordinatorSetup = resolveMeshCoordinatorSetup({
@@ -21309,9 +21432,9 @@ var DaemonCommandRouter = class {
21309
21432
  workspace
21310
21433
  };
21311
21434
  }
21312
- const { existsSync: existsSync21, readFileSync: readFileSync15, writeFileSync: writeFileSync12, copyFileSync: copyFileSync3 } = await import("fs");
21435
+ const { existsSync: existsSync22, readFileSync: readFileSync15, writeFileSync: writeFileSync12, copyFileSync: copyFileSync3 } = await import("fs");
21313
21436
  const mcpConfigPath = coordinatorSetup.configPath;
21314
- const hadExistingMcpConfig = existsSync21(mcpConfigPath);
21437
+ const hadExistingMcpConfig = existsSync22(mcpConfigPath);
21315
21438
  let existingMcpConfig = {};
21316
21439
  if (hadExistingMcpConfig) {
21317
21440
  try {
@@ -21325,8 +21448,8 @@ var DaemonCommandRouter = class {
21325
21448
  mcpServers: {
21326
21449
  ...existingMcpConfig.mcpServers || {},
21327
21450
  [coordinatorSetup.serverName]: {
21328
- command: "adhdev-mcp",
21329
- args: ["--repo-mesh", meshId]
21451
+ command: coordinatorSetup.mcpServer.command,
21452
+ args: coordinatorSetup.mcpServer.args
21330
21453
  }
21331
21454
  }
21332
21455
  };
@@ -21338,10 +21461,20 @@ var DaemonCommandRouter = class {
21338
21461
  } catch {
21339
21462
  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
21463
  }
21464
+ const cliArgs = [];
21465
+ if (systemPrompt) {
21466
+ cliArgs.push("--append-system-prompt", systemPrompt);
21467
+ }
21468
+ if (cliType === "claude-cli") {
21469
+ cliArgs.push("--mcp-config", coordinatorSetup.configPath);
21470
+ }
21341
21471
  const launchResult = await this.deps.cliManager.handleCliCommand("launch_cli", {
21342
21472
  cliType,
21343
21473
  dir: workspace,
21344
- initialPrompt: systemPrompt
21474
+ cliArgs: cliArgs.length > 0 ? cliArgs : void 0,
21475
+ settings: {
21476
+ meshCoordinatorFor: meshId
21477
+ }
21345
21478
  });
21346
21479
  if (!launchResult?.success) {
21347
21480
  return { success: false, error: launchResult?.error || "Failed to launch CLI session" };
@@ -21644,7 +21777,8 @@ var DaemonStatusReporter = class {
21644
21777
  workspace: session.workspace ?? null,
21645
21778
  title: session.title,
21646
21779
  cdpConnected: session.cdpConnected,
21647
- summaryMetadata: session.summaryMetadata
21780
+ summaryMetadata: session.summaryMetadata,
21781
+ settings: session.settings
21648
21782
  })),
21649
21783
  p2p: payload.p2p,
21650
21784
  timestamp: now
@@ -21969,7 +22103,7 @@ var ProviderStreamAdapter = class {
21969
22103
  const beforeCount = this.messageCount(before);
21970
22104
  const beforeSignature = this.lastMessageSignature(before);
21971
22105
  for (let attempt = 0; attempt < 12; attempt += 1) {
21972
- await new Promise((resolve15) => setTimeout(resolve15, 250));
22106
+ await new Promise((resolve16) => setTimeout(resolve16, 250));
21973
22107
  let state;
21974
22108
  try {
21975
22109
  state = await this.readChat(evaluate);
@@ -21991,7 +22125,7 @@ var ProviderStreamAdapter = class {
21991
22125
  if (this.messageCount(first) > 0 || this.lastMessageSignature(first)) {
21992
22126
  return first;
21993
22127
  }
21994
- await new Promise((resolve15) => setTimeout(resolve15, 150));
22128
+ await new Promise((resolve16) => setTimeout(resolve16, 150));
21995
22129
  const second = await this.readChat(evaluate);
21996
22130
  return this.messageCount(second) >= this.messageCount(first) ? second : first;
21997
22131
  }
@@ -22142,7 +22276,7 @@ var ProviderStreamAdapter = class {
22142
22276
  if (typeof data.error === "string" && data.error.trim()) return false;
22143
22277
  }
22144
22278
  for (let attempt = 0; attempt < 6; attempt += 1) {
22145
- await new Promise((resolve15) => setTimeout(resolve15, 250));
22279
+ await new Promise((resolve16) => setTimeout(resolve16, 250));
22146
22280
  const state = await this.readChat(evaluate);
22147
22281
  const title = this.getStateTitle(state);
22148
22282
  if (this.titlesMatch(title, sessionId)) return true;
@@ -24735,7 +24869,7 @@ function getCliTargetBundle(ctx, type, instanceId) {
24735
24869
  return { target, instance, adapter };
24736
24870
  }
24737
24871
  function sleep(ms) {
24738
- return new Promise((resolve15) => setTimeout(resolve15, ms));
24872
+ return new Promise((resolve16) => setTimeout(resolve16, ms));
24739
24873
  }
24740
24874
  async function waitForCliReady(ctx, type, instanceId, timeoutMs) {
24741
24875
  const startedAt = Date.now();
@@ -26981,15 +27115,15 @@ var DevServer = class _DevServer {
26981
27115
  this.json(res, 500, { error: e.message });
26982
27116
  }
26983
27117
  });
26984
- return new Promise((resolve15, reject) => {
27118
+ return new Promise((resolve16, reject) => {
26985
27119
  this.server.listen(port, "127.0.0.1", () => {
26986
27120
  this.log(`Dev server listening on http://127.0.0.1:${port}`);
26987
- resolve15();
27121
+ resolve16();
26988
27122
  });
26989
27123
  this.server.on("error", (e) => {
26990
27124
  if (e.code === "EADDRINUSE") {
26991
27125
  this.log(`Port ${port} in use, skipping dev server`);
26992
- resolve15();
27126
+ resolve16();
26993
27127
  } else {
26994
27128
  reject(e);
26995
27129
  }
@@ -27071,20 +27205,20 @@ var DevServer = class _DevServer {
27071
27205
  child.stderr?.on("data", (d) => {
27072
27206
  stderr += d.toString().slice(0, 2e3);
27073
27207
  });
27074
- await new Promise((resolve15) => {
27208
+ await new Promise((resolve16) => {
27075
27209
  const timer = setTimeout(() => {
27076
27210
  child.kill();
27077
- resolve15();
27211
+ resolve16();
27078
27212
  }, 3e3);
27079
27213
  child.on("exit", () => {
27080
27214
  clearTimeout(timer);
27081
- resolve15();
27215
+ resolve16();
27082
27216
  });
27083
27217
  child.stdout?.once("data", () => {
27084
27218
  setTimeout(() => {
27085
27219
  child.kill();
27086
27220
  clearTimeout(timer);
27087
- resolve15();
27221
+ resolve16();
27088
27222
  }, 500);
27089
27223
  });
27090
27224
  });
@@ -27587,14 +27721,14 @@ var DevServer = class _DevServer {
27587
27721
  child.stderr?.on("data", (d) => {
27588
27722
  stderr += d.toString();
27589
27723
  });
27590
- await new Promise((resolve15) => {
27724
+ await new Promise((resolve16) => {
27591
27725
  const timer = setTimeout(() => {
27592
27726
  child.kill();
27593
- resolve15();
27727
+ resolve16();
27594
27728
  }, timeout);
27595
27729
  child.on("exit", () => {
27596
27730
  clearTimeout(timer);
27597
- resolve15();
27731
+ resolve16();
27598
27732
  });
27599
27733
  });
27600
27734
  const elapsed = Date.now() - start;
@@ -28264,14 +28398,14 @@ data: ${JSON.stringify(msg.data)}
28264
28398
  res.end(JSON.stringify(data, null, 2));
28265
28399
  }
28266
28400
  async readBody(req) {
28267
- return new Promise((resolve15) => {
28401
+ return new Promise((resolve16) => {
28268
28402
  let body = "";
28269
28403
  req.on("data", (chunk) => body += chunk);
28270
28404
  req.on("end", () => {
28271
28405
  try {
28272
- resolve15(JSON.parse(body));
28406
+ resolve16(JSON.parse(body));
28273
28407
  } catch {
28274
- resolve15({});
28408
+ resolve16({});
28275
28409
  }
28276
28410
  });
28277
28411
  });
@@ -28786,7 +28920,7 @@ async function waitForReady(endpoint, timeoutMs = STARTUP_TIMEOUT_MS) {
28786
28920
  const deadline = Date.now() + timeoutMs;
28787
28921
  while (Date.now() < deadline) {
28788
28922
  if (await canConnect(endpoint)) return;
28789
- await new Promise((resolve15) => setTimeout(resolve15, STARTUP_POLL_MS));
28923
+ await new Promise((resolve16) => setTimeout(resolve16, STARTUP_POLL_MS));
28790
28924
  }
28791
28925
  throw new Error(`Session host did not become ready within ${timeoutMs}ms`);
28792
28926
  }
@@ -28964,10 +29098,10 @@ async function installExtension(ide, extension) {
28964
29098
  const buffer = Buffer.from(await res.arrayBuffer());
28965
29099
  const fs16 = await import("fs");
28966
29100
  fs16.writeFileSync(vsixPath, buffer);
28967
- return new Promise((resolve15) => {
29101
+ return new Promise((resolve16) => {
28968
29102
  const cmd = `"${ide.cliCommand}" --install-extension "${vsixPath}" --force`;
28969
29103
  exec2(cmd, { timeout: 6e4 }, (error, _stdout, stderr) => {
28970
- resolve15({
29104
+ resolve16({
28971
29105
  extensionId: extension.id,
28972
29106
  marketplaceId: extension.marketplaceId,
28973
29107
  success: !error,
@@ -28980,11 +29114,11 @@ async function installExtension(ide, extension) {
28980
29114
  } catch (e) {
28981
29115
  }
28982
29116
  }
28983
- return new Promise((resolve15) => {
29117
+ return new Promise((resolve16) => {
28984
29118
  const cmd = `"${ide.cliCommand}" --install-extension ${extension.marketplaceId} --force`;
28985
29119
  exec2(cmd, { timeout: 6e4 }, (error, stdout, stderr) => {
28986
29120
  if (error) {
28987
- resolve15({
29121
+ resolve16({
28988
29122
  extensionId: extension.id,
28989
29123
  marketplaceId: extension.marketplaceId,
28990
29124
  success: false,
@@ -28992,7 +29126,7 @@ async function installExtension(ide, extension) {
28992
29126
  error: stderr || error.message
28993
29127
  });
28994
29128
  } else {
28995
- resolve15({
29129
+ resolve16({
28996
29130
  extensionId: extension.id,
28997
29131
  marketplaceId: extension.marketplaceId,
28998
29132
  success: true,
@@ -29086,6 +29220,48 @@ var SessionRegistry = class {
29086
29220
  // src/boot/daemon-lifecycle.ts
29087
29221
  init_logger();
29088
29222
  init_config();
29223
+
29224
+ // src/mesh/mesh-events.ts
29225
+ init_mesh_config();
29226
+ init_logger();
29227
+ function setupMeshEventForwarding(components) {
29228
+ components.instanceManager.onEvent((event) => {
29229
+ if (event.event !== "agent:generating_completed" && event.event !== "agent:waiting_approval") return;
29230
+ const instanceId = event.instanceId;
29231
+ if (!instanceId) return;
29232
+ const sourceInstance = components.instanceManager.getInstance(instanceId);
29233
+ if (!sourceInstance || sourceInstance.category !== "cli") return;
29234
+ const state = sourceInstance.getState();
29235
+ const workspace = state.workspace;
29236
+ if (!workspace) return;
29237
+ const mesh = getMeshByRepo(workspace);
29238
+ if (!mesh) return;
29239
+ const allInstances = components.instanceManager.getByCategory("cli");
29240
+ const coordinatorInstances = allInstances.filter((inst) => {
29241
+ const instState = inst.getState();
29242
+ if (instState.settings?.meshCoordinatorFor !== mesh.id) return false;
29243
+ if (instState.instanceId === instanceId) return false;
29244
+ return true;
29245
+ });
29246
+ if (coordinatorInstances.length === 0) return;
29247
+ const targetNode = mesh.nodes.find((n) => n.workspace === workspace);
29248
+ const nodeLabel = targetNode ? `Node '${targetNode.id}'` : `Agent at ${workspace}`;
29249
+ let messageText = "";
29250
+ if (event.event === "agent:generating_completed") {
29251
+ messageText = `[System] ${nodeLabel} has completed its task and is now idle. You may use mesh_read_chat to review its progress.`;
29252
+ } else if (event.event === "agent:waiting_approval") {
29253
+ messageText = `[System] ${nodeLabel} is waiting for approval to proceed. You may use mesh_read_chat and mesh_approve to handle it.`;
29254
+ }
29255
+ if (!messageText) return;
29256
+ for (const coord of coordinatorInstances) {
29257
+ const coordState = coord.getState();
29258
+ LOG.info("MeshEvents", `Forwarding event from ${workspace} to coordinator ${coordState.instanceId}`);
29259
+ coord.onEvent("send_message", { input: { text: messageText, textFallback: messageText } });
29260
+ }
29261
+ });
29262
+ }
29263
+
29264
+ // src/boot/daemon-lifecycle.ts
29089
29265
  async function initDaemonComponents(config) {
29090
29266
  installGlobalInterceptor();
29091
29267
  const appConfig = loadConfig();
@@ -29243,7 +29419,7 @@ async function initDaemonComponents(config) {
29243
29419
  });
29244
29420
  poller.start();
29245
29421
  instanceManager.startTicking(config.tickIntervalMs ?? 5e3);
29246
- return {
29422
+ const components = {
29247
29423
  providerLoader,
29248
29424
  instanceManager,
29249
29425
  cliManager,
@@ -29257,6 +29433,8 @@ async function initDaemonComponents(config) {
29257
29433
  detectedIdes: detectedIdesRef,
29258
29434
  refreshProviderAvailability
29259
29435
  };
29436
+ setupMeshEventForwarding(components);
29437
+ return components;
29260
29438
  }
29261
29439
  async function startDaemonDevSupport(options) {
29262
29440
  const devServer = new DevServer({