@adhdev/daemon-core 0.9.38 → 0.9.40

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) => ({
@@ -2848,6 +2854,14 @@ var init_provider_cli_adapter = __esm({
2848
2854
  }
2849
2855
  this.resolveStartupState("settled");
2850
2856
  if (this.startupParseGate) return;
2857
+ if (!this.isWaitingForResponse && !this.currentTurnScope && !this.activeModal && !this.parseErrorMessage) {
2858
+ const tail = this.settledBuffer || this.recentOutputBuffer;
2859
+ const modal2 = this.runParseApproval(tail);
2860
+ const lightweightStatus = this.cliScripts?.detectStatus ? this.runDetectStatus(tail) : null;
2861
+ if (!modal2 && lightweightStatus === "idle" && this.currentStatus === "idle") {
2862
+ return;
2863
+ }
2864
+ }
2851
2865
  const session = this.runParseSession();
2852
2866
  if (!session) return;
2853
2867
  const { status, messages, modal, parsedStatus } = session;
@@ -10462,68 +10476,66 @@ function normalizeReadChatMessages(payload) {
10462
10476
  const messages = Array.isArray(payload.messages) ? payload.messages : [];
10463
10477
  return normalizeChatMessages(messages);
10464
10478
  }
10465
- function buildReadChatReplayCollapseSignature(message) {
10466
- if (!message) return "";
10479
+ function normalizeReadChatReplayTextContent(content) {
10480
+ return flattenContent(content || "").replace(/\s+/g, " ").trim();
10481
+ }
10482
+ function getReadChatReplayCollapseInfo(message) {
10483
+ if (!message) return null;
10467
10484
  const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
10468
10485
  const kind = typeof message.kind === "string" ? message.kind.trim().toLowerCase() : "standard";
10469
10486
  const senderName = typeof message.senderName === "string" ? message.senderName.trim().toLowerCase() : "";
10470
- const content = flattenContent(message.content || "").replace(/\s+/g, " ").trim();
10471
- return `${role}:${kind}:${senderName}:${content}`;
10472
- }
10473
- function shouldCollapseReadChatReplayDuplicate(message) {
10474
- if (!message) return false;
10475
- const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
10476
- return role === "assistant" || role === "system";
10477
- }
10478
- function normalizeReadChatReplayText(message) {
10479
- return flattenContent(message?.content || "").replace(/\s+/g, " ").trim();
10487
+ const collapsible = role === "assistant" || role === "system";
10488
+ if (!collapsible) return { role, kind, senderName, content: "", signature: "", collapsible };
10489
+ const content = normalizeReadChatReplayTextContent(message.content);
10490
+ return {
10491
+ role,
10492
+ kind,
10493
+ senderName,
10494
+ content,
10495
+ signature: `${role}:${kind}:${senderName}:${content}`,
10496
+ collapsible
10497
+ };
10480
10498
  }
10481
- function isStableReadChatAssistantAnswer(message) {
10482
- if (!message) return false;
10483
- const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
10484
- const kind = typeof message.kind === "string" ? message.kind.trim().toLowerCase() : "standard";
10485
- if (role !== "assistant") return false;
10486
- if (kind && kind !== "standard") return false;
10487
- const content = normalizeReadChatReplayText(message);
10488
- if (content.length < 160) return false;
10489
- if (/^(bash|shell|terminal) command\b/i.test(content)) return false;
10499
+ function isStableReadChatAssistantAnswerInfo(info) {
10500
+ if (!info) return false;
10501
+ if (info.role !== "assistant") return false;
10502
+ if (info.kind && info.kind !== "standard") return false;
10503
+ if (info.content.length < 160) return false;
10504
+ if (/^(bash|shell|terminal) command\b/i.test(info.content)) return false;
10490
10505
  return true;
10491
10506
  }
10492
- function isReplayedAssistantAnswerAfterStableAnswer(message, stableAnswer) {
10493
- if (!message || !stableAnswer) return false;
10494
- const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
10495
- const kind = typeof message.kind === "string" ? message.kind.trim().toLowerCase() : "standard";
10496
- if (role !== "assistant") return false;
10497
- if (kind && kind !== "standard") return false;
10498
- const content = normalizeReadChatReplayText(message);
10499
- const stableContent = normalizeReadChatReplayText(stableAnswer);
10507
+ function isReplayedAssistantAnswerAfterStableAnswerInfo(info, stableContent) {
10508
+ if (!info || !stableContent) return false;
10509
+ if (info.role !== "assistant") return false;
10510
+ if (info.kind && info.kind !== "standard") return false;
10511
+ const content = info.content;
10500
10512
  if (content.length < 80 || stableContent.length < 80) return false;
10501
10513
  return content === stableContent || content.startsWith(stableContent) || stableContent.startsWith(content);
10502
10514
  }
10503
10515
  function collapseReplayDuplicatesFromReadChat(messages) {
10504
10516
  const collapsed = [];
10505
10517
  const replaySignaturesInCurrentTurn = /* @__PURE__ */ new Set();
10506
- let stableAssistantAnswerInCurrentTurn = null;
10518
+ let stableAssistantAnswerContentInCurrentTurn = "";
10519
+ let previousReplaySignature = "";
10507
10520
  for (const message of messages) {
10508
- const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
10509
- if (role === "user") {
10521
+ const info = getReadChatReplayCollapseInfo(message);
10522
+ if (info?.role === "user") {
10510
10523
  replaySignaturesInCurrentTurn.clear();
10511
- stableAssistantAnswerInCurrentTurn = null;
10524
+ stableAssistantAnswerContentInCurrentTurn = "";
10525
+ previousReplaySignature = "";
10512
10526
  }
10513
- const signature = buildReadChatReplayCollapseSignature(message);
10514
- const previous = collapsed[collapsed.length - 1];
10515
- const previousSignature = buildReadChatReplayCollapseSignature(previous);
10516
- if (shouldCollapseReadChatReplayDuplicate(message) && signature) {
10517
- if (previousSignature === signature) continue;
10518
- if (replaySignaturesInCurrentTurn.has(signature)) continue;
10519
- if (isReplayedAssistantAnswerAfterStableAnswer(message, stableAssistantAnswerInCurrentTurn)) continue;
10527
+ if (info?.collapsible && info.signature) {
10528
+ if (previousReplaySignature === info.signature) continue;
10529
+ if (replaySignaturesInCurrentTurn.has(info.signature)) continue;
10530
+ if (isReplayedAssistantAnswerAfterStableAnswerInfo(info, stableAssistantAnswerContentInCurrentTurn)) continue;
10520
10531
  }
10521
10532
  collapsed.push(message);
10522
- if (shouldCollapseReadChatReplayDuplicate(message) && signature) {
10523
- replaySignaturesInCurrentTurn.add(signature);
10533
+ previousReplaySignature = info?.collapsible ? info.signature : "";
10534
+ if (info?.collapsible && info.signature) {
10535
+ replaySignaturesInCurrentTurn.add(info.signature);
10524
10536
  }
10525
- if (isStableReadChatAssistantAnswer(message)) {
10526
- stableAssistantAnswerInCurrentTurn = message;
10537
+ if (isStableReadChatAssistantAnswerInfo(info)) {
10538
+ stableAssistantAnswerContentInCurrentTurn = info?.content || "";
10527
10539
  }
10528
10540
  }
10529
10541
  return collapsed;
@@ -10603,13 +10615,17 @@ function computeReadChatSync(messages, cursor) {
10603
10615
  };
10604
10616
  }
10605
10617
  if (cursor.tailLimit > 0 && knownSignature === lastMessageSignature) {
10606
- return {
10607
- syncMode: "noop",
10608
- replaceFrom: totalMessages,
10609
- messages: [],
10610
- totalMessages,
10611
- lastMessageSignature
10612
- };
10618
+ const requestedTailCount = Math.min(totalMessages, cursor.tailLimit);
10619
+ if (knownMessageCount >= requestedTailCount) {
10620
+ return {
10621
+ syncMode: "noop",
10622
+ replaceFrom: totalMessages,
10623
+ messages: [],
10624
+ totalMessages,
10625
+ lastMessageSignature
10626
+ };
10627
+ }
10628
+ return buildBoundedTailSync(messages, cursor);
10613
10629
  }
10614
10630
  if (knownMessageCount < totalMessages) {
10615
10631
  const anchorSignature = getChatMessageSignature(messages[knownMessageCount - 1]);
@@ -13543,8 +13559,8 @@ var CliProviderInstance = class {
13543
13559
  }
13544
13560
  detectStatusTransition() {
13545
13561
  const now = Date.now();
13546
- const adapterStatus = this.adapter.getStatus();
13547
- const parsedStatus = this.adapter.getScriptParsedStatus?.() || null;
13562
+ const adapterStatus = this.adapter.getStatus({ allowParse: false });
13563
+ const parsedStatus = null;
13548
13564
  const rawStatus = adapterStatus.status;
13549
13565
  const autoApproveActive = rawStatus === "waiting_approval" && this.shouldAutoApprove();
13550
13566
  if (autoApproveActive && !this.autoApproveBusy) {
@@ -13637,7 +13653,7 @@ var CliProviderInstance = class {
13637
13653
  this.completedDebouncePending = { chatTitle, duration, timestamp: now };
13638
13654
  this.completedDebounceTimer = setTimeout(() => {
13639
13655
  if (this.completedDebouncePending) {
13640
- const latestStatus = this.adapter.getStatus();
13656
+ const latestStatus = this.adapter.getStatus({ allowParse: false });
13641
13657
  const latestAutoApproveActive = latestStatus.status === "waiting_approval" && this.shouldAutoApprove();
13642
13658
  const latestVisibleStatus = latestAutoApproveActive ? "generating" : latestStatus.status;
13643
13659
  if (latestVisibleStatus !== "idle") {