@adhdev/daemon-core 0.9.39 → 0.9.41

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
@@ -1790,9 +1790,7 @@ function hydrateCliParsedMessages(parsedMessages, options) {
1790
1790
  };
1791
1791
  });
1792
1792
  }
1793
- function chooseMoreComparableCliMessage(left, right) {
1794
- const leftComparable = normalizeComparableMessageContent(left.content || "");
1795
- const rightComparable = normalizeComparableMessageContent(right.content || "");
1793
+ function chooseMoreComparableCliMessage(left, right, leftComparable = normalizeComparableMessageContent(left.content || ""), rightComparable = normalizeComparableMessageContent(right.content || "")) {
1796
1794
  if (leftComparable && leftComparable === rightComparable) {
1797
1795
  const leftNewlines = String(left.content || "").split(/\r\n|\n|\r/g).length - 1;
1798
1796
  const rightNewlines = String(right.content || "").split(/\r\n|\n|\r/g).length - 1;
@@ -1807,24 +1805,32 @@ function dedupeConsecutiveComparableCliMessages(messages) {
1807
1805
  ...message,
1808
1806
  content: typeof message.content === "string" ? message.content : String(message.content || "")
1809
1807
  };
1808
+ const currentComparable = normalizeComparableMessageContent(current.content || "");
1810
1809
  const previous = deduped[deduped.length - 1];
1811
1810
  if (!previous) {
1812
- deduped.push(current);
1811
+ deduped.push({ message: current, comparable: currentComparable });
1813
1812
  continue;
1814
1813
  }
1815
- const previousComparable = normalizeComparableMessageContent(previous.content || "");
1816
- const currentComparable = normalizeComparableMessageContent(current.content || "");
1817
- const sameRole = previous.role === current.role;
1818
- const sameKind = (previous.kind || "standard") === (current.kind || "standard");
1819
- const sameSender = (previous.senderName || "") === (current.senderName || "");
1820
- const comparableMatch = previousComparable && previousComparable === currentComparable;
1814
+ const sameRole = previous.message.role === current.role;
1815
+ const sameKind = (previous.message.kind || "standard") === (current.kind || "standard");
1816
+ const sameSender = (previous.message.senderName || "") === (current.senderName || "");
1817
+ const comparableMatch = previous.comparable && previous.comparable === currentComparable;
1821
1818
  if (sameRole && sameKind && sameSender && comparableMatch) {
1822
- deduped[deduped.length - 1] = chooseMoreComparableCliMessage(previous, current);
1819
+ const selected = chooseMoreComparableCliMessage(
1820
+ previous.message,
1821
+ current,
1822
+ previous.comparable,
1823
+ currentComparable
1824
+ );
1825
+ deduped[deduped.length - 1] = {
1826
+ message: selected,
1827
+ comparable: selected === current ? currentComparable : previous.comparable
1828
+ };
1823
1829
  continue;
1824
1830
  }
1825
- deduped.push(current);
1831
+ deduped.push({ message: current, comparable: currentComparable });
1826
1832
  }
1827
- return deduped;
1833
+ return deduped.map((entry) => entry.message);
1828
1834
  }
1829
1835
  function normalizeCliParsedMessages(parsedMessages, options) {
1830
1836
  return dedupeConsecutiveComparableCliMessages(hydrateCliParsedMessages(parsedMessages, options).map((message) => ({
@@ -2274,7 +2280,7 @@ var init_provider_cli_adapter = __esm({
2274
2280
  }
2275
2281
  getFreshParsedStatusCache() {
2276
2282
  const cached = this.parsedStatusCache;
2277
- if (cached && cached.committedMessagesRef === this.committedMessages && cached.responseBuffer === this.responseBuffer && cached.currentTurnScope === this.currentTurnScope && cached.recentOutputBuffer === this.recentOutputBuffer && cached.accumulatedBuffer === this.accumulatedBuffer && cached.accumulatedRawBuffer === this.accumulatedRawBuffer && cached.screenText === this.lastScreenText && cached.currentStatus === this.currentStatus && cached.activeModal === this.activeModal && cached.cliName === this.cliName && cached.lastOutputAt === this.lastOutputAt) {
2283
+ if (cached && cached.committedMessagesRef === this.committedMessages && cached.responseBuffer === this.responseBuffer && cached.currentTurnScope === this.currentTurnScope && cached.recentOutputBuffer === this.recentOutputBuffer && cached.accumulatedBuffer === this.accumulatedBuffer && cached.screenText === this.lastScreenText && cached.currentStatus === this.currentStatus && cached.activeModal === this.activeModal && cached.cliName === this.cliName) {
2278
2284
  return cached.result;
2279
2285
  }
2280
2286
  return null;
@@ -3522,7 +3528,7 @@ var init_provider_cli_adapter = __esm({
3522
3528
  getScriptParsedStatus() {
3523
3529
  const screenText = this.readTerminalScreenText();
3524
3530
  const cached = this.parsedStatusCache;
3525
- if (cached && cached.committedMessagesRef === this.committedMessages && cached.responseBuffer === this.responseBuffer && cached.currentTurnScope === this.currentTurnScope && cached.recentOutputBuffer === this.recentOutputBuffer && cached.accumulatedBuffer === this.accumulatedBuffer && cached.accumulatedRawBuffer === this.accumulatedRawBuffer && cached.screenText === screenText && cached.currentStatus === this.currentStatus && cached.activeModal === this.activeModal && cached.cliName === this.cliName && cached.lastOutputAt === this.lastOutputAt) {
3531
+ if (cached && cached.committedMessagesRef === this.committedMessages && cached.responseBuffer === this.responseBuffer && cached.currentTurnScope === this.currentTurnScope && cached.recentOutputBuffer === this.recentOutputBuffer && cached.accumulatedBuffer === this.accumulatedBuffer && cached.screenText === screenText && cached.currentStatus === this.currentStatus && cached.activeModal === this.activeModal && cached.cliName === this.cliName) {
3526
3532
  return cached.result;
3527
3533
  }
3528
3534
  const parsed = this.parseCurrentTranscript(
@@ -3641,12 +3647,10 @@ var init_provider_cli_adapter = __esm({
3641
3647
  currentTurnScope: this.currentTurnScope,
3642
3648
  recentOutputBuffer: this.recentOutputBuffer,
3643
3649
  accumulatedBuffer: this.accumulatedBuffer,
3644
- accumulatedRawBuffer: this.accumulatedRawBuffer,
3645
3650
  screenText,
3646
3651
  currentStatus: this.currentStatus,
3647
3652
  activeModal: this.activeModal,
3648
3653
  cliName: this.cliName,
3649
- lastOutputAt: this.lastOutputAt,
3650
3654
  result
3651
3655
  };
3652
3656
  return result;
@@ -8362,6 +8366,15 @@ var ExtensionProviderInstance = class {
8362
8366
  pendingEvents: this.flushEvents()
8363
8367
  };
8364
8368
  }
8369
+ getSessionModalState(sessionId) {
8370
+ if (sessionId && sessionId !== this.instanceId) return null;
8371
+ return {
8372
+ id: this.instanceId,
8373
+ status: this.currentStatus,
8374
+ title: this.chatTitle || this.agentName || this.provider.name,
8375
+ activeModal: this.activeModal
8376
+ };
8377
+ }
8365
8378
  onEvent(event, data) {
8366
8379
  if (event === "stream_update") {
8367
8380
  if (data?.streams) this.agentStreams = data.streams;
@@ -8828,6 +8841,23 @@ var IdeProviderInstance = class {
8828
8841
  pendingEvents: this.flushEvents()
8829
8842
  };
8830
8843
  }
8844
+ getSessionModalState(sessionId) {
8845
+ if (sessionId && sessionId !== this.instanceId) {
8846
+ for (const ext of this.extensions.values()) {
8847
+ const projected = ext.getSessionModalState?.(sessionId);
8848
+ if (projected?.id === sessionId) return projected;
8849
+ }
8850
+ return null;
8851
+ }
8852
+ const autoApproveActive = (this.currentStatus === "waiting_approval" || this.cachedChat?.status === "waiting_approval") && this.canAutoApprove();
8853
+ const visibleStatus = autoApproveActive ? "generating" : this.currentStatus;
8854
+ return {
8855
+ id: this.instanceId,
8856
+ status: autoApproveActive && this.cachedChat?.status === "waiting_approval" ? "generating" : this.cachedChat?.status || visibleStatus,
8857
+ title: this.cachedChat?.title || this.type,
8858
+ activeModal: autoApproveActive ? null : this.cachedChat?.activeModal || null
8859
+ };
8860
+ }
8831
8861
  onEvent(event, data) {
8832
8862
  if (event === "cdp_connected") {
8833
8863
  } else if (event === "cdp_disconnected") {
@@ -10470,68 +10500,66 @@ function normalizeReadChatMessages(payload) {
10470
10500
  const messages = Array.isArray(payload.messages) ? payload.messages : [];
10471
10501
  return normalizeChatMessages(messages);
10472
10502
  }
10473
- function buildReadChatReplayCollapseSignature(message) {
10474
- if (!message) return "";
10503
+ function normalizeReadChatReplayTextContent(content) {
10504
+ return flattenContent(content || "").replace(/\s+/g, " ").trim();
10505
+ }
10506
+ function getReadChatReplayCollapseInfo(message) {
10507
+ if (!message) return null;
10475
10508
  const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
10476
10509
  const kind = typeof message.kind === "string" ? message.kind.trim().toLowerCase() : "standard";
10477
10510
  const senderName = typeof message.senderName === "string" ? message.senderName.trim().toLowerCase() : "";
10478
- const content = flattenContent(message.content || "").replace(/\s+/g, " ").trim();
10479
- return `${role}:${kind}:${senderName}:${content}`;
10480
- }
10481
- function shouldCollapseReadChatReplayDuplicate(message) {
10482
- if (!message) return false;
10483
- const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
10484
- return role === "assistant" || role === "system";
10485
- }
10486
- function normalizeReadChatReplayText(message) {
10487
- return flattenContent(message?.content || "").replace(/\s+/g, " ").trim();
10511
+ const collapsible = role === "assistant" || role === "system";
10512
+ if (!collapsible) return { role, kind, senderName, content: "", signature: "", collapsible };
10513
+ const content = normalizeReadChatReplayTextContent(message.content);
10514
+ return {
10515
+ role,
10516
+ kind,
10517
+ senderName,
10518
+ content,
10519
+ signature: `${role}:${kind}:${senderName}:${content}`,
10520
+ collapsible
10521
+ };
10488
10522
  }
10489
- function isStableReadChatAssistantAnswer(message) {
10490
- if (!message) return false;
10491
- const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
10492
- const kind = typeof message.kind === "string" ? message.kind.trim().toLowerCase() : "standard";
10493
- if (role !== "assistant") return false;
10494
- if (kind && kind !== "standard") return false;
10495
- const content = normalizeReadChatReplayText(message);
10496
- if (content.length < 160) return false;
10497
- if (/^(bash|shell|terminal) command\b/i.test(content)) return false;
10523
+ function isStableReadChatAssistantAnswerInfo(info) {
10524
+ if (!info) return false;
10525
+ if (info.role !== "assistant") return false;
10526
+ if (info.kind && info.kind !== "standard") return false;
10527
+ if (info.content.length < 160) return false;
10528
+ if (/^(bash|shell|terminal) command\b/i.test(info.content)) return false;
10498
10529
  return true;
10499
10530
  }
10500
- function isReplayedAssistantAnswerAfterStableAnswer(message, stableAnswer) {
10501
- if (!message || !stableAnswer) return false;
10502
- const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
10503
- const kind = typeof message.kind === "string" ? message.kind.trim().toLowerCase() : "standard";
10504
- if (role !== "assistant") return false;
10505
- if (kind && kind !== "standard") return false;
10506
- const content = normalizeReadChatReplayText(message);
10507
- const stableContent = normalizeReadChatReplayText(stableAnswer);
10531
+ function isReplayedAssistantAnswerAfterStableAnswerInfo(info, stableContent) {
10532
+ if (!info || !stableContent) return false;
10533
+ if (info.role !== "assistant") return false;
10534
+ if (info.kind && info.kind !== "standard") return false;
10535
+ const content = info.content;
10508
10536
  if (content.length < 80 || stableContent.length < 80) return false;
10509
10537
  return content === stableContent || content.startsWith(stableContent) || stableContent.startsWith(content);
10510
10538
  }
10511
10539
  function collapseReplayDuplicatesFromReadChat(messages) {
10512
10540
  const collapsed = [];
10513
10541
  const replaySignaturesInCurrentTurn = /* @__PURE__ */ new Set();
10514
- let stableAssistantAnswerInCurrentTurn = null;
10542
+ let stableAssistantAnswerContentInCurrentTurn = "";
10543
+ let previousReplaySignature = "";
10515
10544
  for (const message of messages) {
10516
- const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
10517
- if (role === "user") {
10545
+ const info = getReadChatReplayCollapseInfo(message);
10546
+ if (info?.role === "user") {
10518
10547
  replaySignaturesInCurrentTurn.clear();
10519
- stableAssistantAnswerInCurrentTurn = null;
10548
+ stableAssistantAnswerContentInCurrentTurn = "";
10549
+ previousReplaySignature = "";
10520
10550
  }
10521
- const signature = buildReadChatReplayCollapseSignature(message);
10522
- const previous = collapsed[collapsed.length - 1];
10523
- const previousSignature = buildReadChatReplayCollapseSignature(previous);
10524
- if (shouldCollapseReadChatReplayDuplicate(message) && signature) {
10525
- if (previousSignature === signature) continue;
10526
- if (replaySignaturesInCurrentTurn.has(signature)) continue;
10527
- if (isReplayedAssistantAnswerAfterStableAnswer(message, stableAssistantAnswerInCurrentTurn)) continue;
10551
+ if (info?.collapsible && info.signature) {
10552
+ if (previousReplaySignature === info.signature) continue;
10553
+ if (replaySignaturesInCurrentTurn.has(info.signature)) continue;
10554
+ if (isReplayedAssistantAnswerAfterStableAnswerInfo(info, stableAssistantAnswerContentInCurrentTurn)) continue;
10528
10555
  }
10529
10556
  collapsed.push(message);
10530
- if (shouldCollapseReadChatReplayDuplicate(message) && signature) {
10531
- replaySignaturesInCurrentTurn.add(signature);
10557
+ previousReplaySignature = info?.collapsible ? info.signature : "";
10558
+ if (info?.collapsible && info.signature) {
10559
+ replaySignaturesInCurrentTurn.add(info.signature);
10532
10560
  }
10533
- if (isStableReadChatAssistantAnswer(message)) {
10534
- stableAssistantAnswerInCurrentTurn = message;
10561
+ if (isStableReadChatAssistantAnswerInfo(info)) {
10562
+ stableAssistantAnswerContentInCurrentTurn = info?.content || "";
10535
10563
  }
10536
10564
  }
10537
10565
  return collapsed;
@@ -10611,13 +10639,17 @@ function computeReadChatSync(messages, cursor) {
10611
10639
  };
10612
10640
  }
10613
10641
  if (cursor.tailLimit > 0 && knownSignature === lastMessageSignature) {
10614
- return {
10615
- syncMode: "noop",
10616
- replaceFrom: totalMessages,
10617
- messages: [],
10618
- totalMessages,
10619
- lastMessageSignature
10620
- };
10642
+ const requestedTailCount = Math.min(totalMessages, cursor.tailLimit);
10643
+ if (knownMessageCount >= requestedTailCount) {
10644
+ return {
10645
+ syncMode: "noop",
10646
+ replaceFrom: totalMessages,
10647
+ messages: [],
10648
+ totalMessages,
10649
+ lastMessageSignature
10650
+ };
10651
+ }
10652
+ return buildBoundedTailSync(messages, cursor);
10621
10653
  }
10622
10654
  if (knownMessageCount < totalMessages) {
10623
10655
  const anchorSignature = getChatMessageSignature(messages[knownMessageCount - 1]);
@@ -13490,6 +13522,18 @@ var CliProviderInstance = class {
13490
13522
  runtimeRecoveryState: runtime?.recoveryState ?? null
13491
13523
  };
13492
13524
  }
13525
+ getSessionModalState() {
13526
+ const adapterStatus = this.adapter.getStatus({ allowParse: false });
13527
+ const autoApproveActive = adapterStatus.status === "waiting_approval" && this.shouldAutoApprove();
13528
+ const visibleStatus = autoApproveActive ? "generating" : adapterStatus.status;
13529
+ const dirName = this.workingDir.split("/").filter(Boolean).pop() || "session";
13530
+ return {
13531
+ id: this.instanceId,
13532
+ status: visibleStatus,
13533
+ title: dirName,
13534
+ activeModal: autoApproveActive ? null : adapterStatus.activeModal
13535
+ };
13536
+ }
13493
13537
  updateSettings(newSettings) {
13494
13538
  this.settings = { ...newSettings };
13495
13539
  this.adapter.updateRuntimeSettings?.(this.settings);
@@ -14222,6 +14266,18 @@ var AcpProviderInstance = class {
14222
14266
  this.detectStatusTransition();
14223
14267
  }
14224
14268
  }
14269
+ getSessionModalState() {
14270
+ const dirName = this.workingDir.split("/").filter(Boolean).pop() || "session";
14271
+ return {
14272
+ id: this.instanceId,
14273
+ status: this.currentStatus,
14274
+ title: `${this.provider.name} \xB7 ${dirName}`,
14275
+ activeModal: this.currentStatus === "waiting_approval" ? {
14276
+ message: this.activeToolCalls.find((t) => t.status === "running")?.name || "Permission requested",
14277
+ buttons: ["Approve", "Reject"]
14278
+ } : null
14279
+ };
14280
+ }
14225
14281
  getState() {
14226
14282
  const dirName = this.workingDir.split("/").filter(Boolean).pop() || "session";
14227
14283
  const recentMessages = normalizeChatMessages(this.messages.map((m) => {
@@ -21104,6 +21160,29 @@ var ProviderInstanceManager = class {
21104
21160
  }
21105
21161
  return sessions;
21106
21162
  }
21163
+ getSessionModalState(sessionId, options = {}) {
21164
+ if (!sessionId) return null;
21165
+ const candidates = [sessionId];
21166
+ if (options.instanceKey && options.instanceKey !== sessionId) {
21167
+ candidates.push(options.instanceKey);
21168
+ }
21169
+ for (const id of candidates) {
21170
+ const instance = this.instances.get(id);
21171
+ if (!instance?.getSessionModalState) continue;
21172
+ try {
21173
+ const projected = instance.getSessionModalState(sessionId);
21174
+ if (!projected?.id) continue;
21175
+ if (projected.id !== sessionId) {
21176
+ LOG.warn("InstanceMgr", `[InstanceManager] Ignoring mismatched session modal projection from ${id}: requested=${sessionId} projected=${projected.id}`);
21177
+ continue;
21178
+ }
21179
+ return projected;
21180
+ } catch (e) {
21181
+ LOG.warn("InstanceMgr", `[InstanceManager] Failed to project session modal metadata from ${id}: ${e.message}`);
21182
+ }
21183
+ }
21184
+ return null;
21185
+ }
21107
21186
  /**
21108
21187
  * Per-category status collect
21109
21188
  */