adhdev 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/cli/index.js CHANGED
@@ -7892,68 +7892,66 @@ function normalizeReadChatMessages(payload) {
7892
7892
  const messages = Array.isArray(payload.messages) ? payload.messages : [];
7893
7893
  return normalizeChatMessages(messages);
7894
7894
  }
7895
- function buildReadChatReplayCollapseSignature(message) {
7896
- if (!message) return "";
7895
+ function normalizeReadChatReplayTextContent(content) {
7896
+ return flattenContent(content || "").replace(/\s+/g, " ").trim();
7897
+ }
7898
+ function getReadChatReplayCollapseInfo(message) {
7899
+ if (!message) return null;
7897
7900
  const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
7898
7901
  const kind = typeof message.kind === "string" ? message.kind.trim().toLowerCase() : "standard";
7899
7902
  const senderName = typeof message.senderName === "string" ? message.senderName.trim().toLowerCase() : "";
7900
- const content = flattenContent(message.content || "").replace(/\s+/g, " ").trim();
7901
- return `${role}:${kind}:${senderName}:${content}`;
7902
- }
7903
- function shouldCollapseReadChatReplayDuplicate(message) {
7904
- if (!message) return false;
7905
- const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
7906
- return role === "assistant" || role === "system";
7907
- }
7908
- function normalizeReadChatReplayText(message) {
7909
- return flattenContent(message?.content || "").replace(/\s+/g, " ").trim();
7903
+ const collapsible = role === "assistant" || role === "system";
7904
+ if (!collapsible) return { role, kind, senderName, content: "", signature: "", collapsible };
7905
+ const content = normalizeReadChatReplayTextContent(message.content);
7906
+ return {
7907
+ role,
7908
+ kind,
7909
+ senderName,
7910
+ content,
7911
+ signature: `${role}:${kind}:${senderName}:${content}`,
7912
+ collapsible
7913
+ };
7910
7914
  }
7911
- function isStableReadChatAssistantAnswer(message) {
7912
- if (!message) return false;
7913
- const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
7914
- const kind = typeof message.kind === "string" ? message.kind.trim().toLowerCase() : "standard";
7915
- if (role !== "assistant") return false;
7916
- if (kind && kind !== "standard") return false;
7917
- const content = normalizeReadChatReplayText(message);
7918
- if (content.length < 160) return false;
7919
- if (/^(bash|shell|terminal) command\b/i.test(content)) return false;
7915
+ function isStableReadChatAssistantAnswerInfo(info) {
7916
+ if (!info) return false;
7917
+ if (info.role !== "assistant") return false;
7918
+ if (info.kind && info.kind !== "standard") return false;
7919
+ if (info.content.length < 160) return false;
7920
+ if (/^(bash|shell|terminal) command\b/i.test(info.content)) return false;
7920
7921
  return true;
7921
7922
  }
7922
- function isReplayedAssistantAnswerAfterStableAnswer(message, stableAnswer) {
7923
- if (!message || !stableAnswer) return false;
7924
- const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
7925
- const kind = typeof message.kind === "string" ? message.kind.trim().toLowerCase() : "standard";
7926
- if (role !== "assistant") return false;
7927
- if (kind && kind !== "standard") return false;
7928
- const content = normalizeReadChatReplayText(message);
7929
- const stableContent = normalizeReadChatReplayText(stableAnswer);
7923
+ function isReplayedAssistantAnswerAfterStableAnswerInfo(info, stableContent) {
7924
+ if (!info || !stableContent) return false;
7925
+ if (info.role !== "assistant") return false;
7926
+ if (info.kind && info.kind !== "standard") return false;
7927
+ const content = info.content;
7930
7928
  if (content.length < 80 || stableContent.length < 80) return false;
7931
7929
  return content === stableContent || content.startsWith(stableContent) || stableContent.startsWith(content);
7932
7930
  }
7933
7931
  function collapseReplayDuplicatesFromReadChat(messages) {
7934
7932
  const collapsed = [];
7935
7933
  const replaySignaturesInCurrentTurn = /* @__PURE__ */ new Set();
7936
- let stableAssistantAnswerInCurrentTurn = null;
7934
+ let stableAssistantAnswerContentInCurrentTurn = "";
7935
+ let previousReplaySignature = "";
7937
7936
  for (const message of messages) {
7938
- const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
7939
- if (role === "user") {
7937
+ const info = getReadChatReplayCollapseInfo(message);
7938
+ if (info?.role === "user") {
7940
7939
  replaySignaturesInCurrentTurn.clear();
7941
- stableAssistantAnswerInCurrentTurn = null;
7940
+ stableAssistantAnswerContentInCurrentTurn = "";
7941
+ previousReplaySignature = "";
7942
7942
  }
7943
- const signature = buildReadChatReplayCollapseSignature(message);
7944
- const previous = collapsed[collapsed.length - 1];
7945
- const previousSignature = buildReadChatReplayCollapseSignature(previous);
7946
- if (shouldCollapseReadChatReplayDuplicate(message) && signature) {
7947
- if (previousSignature === signature) continue;
7948
- if (replaySignaturesInCurrentTurn.has(signature)) continue;
7949
- if (isReplayedAssistantAnswerAfterStableAnswer(message, stableAssistantAnswerInCurrentTurn)) continue;
7943
+ if (info?.collapsible && info.signature) {
7944
+ if (previousReplaySignature === info.signature) continue;
7945
+ if (replaySignaturesInCurrentTurn.has(info.signature)) continue;
7946
+ if (isReplayedAssistantAnswerAfterStableAnswerInfo(info, stableAssistantAnswerContentInCurrentTurn)) continue;
7950
7947
  }
7951
7948
  collapsed.push(message);
7952
- if (shouldCollapseReadChatReplayDuplicate(message) && signature) {
7953
- replaySignaturesInCurrentTurn.add(signature);
7949
+ previousReplaySignature = info?.collapsible ? info.signature : "";
7950
+ if (info?.collapsible && info.signature) {
7951
+ replaySignaturesInCurrentTurn.add(info.signature);
7954
7952
  }
7955
- if (isStableReadChatAssistantAnswer(message)) {
7956
- stableAssistantAnswerInCurrentTurn = message;
7953
+ if (isStableReadChatAssistantAnswerInfo(info)) {
7954
+ stableAssistantAnswerContentInCurrentTurn = info?.content || "";
7957
7955
  }
7958
7956
  }
7959
7957
  return collapsed;
@@ -8033,13 +8031,17 @@ function computeReadChatSync(messages, cursor) {
8033
8031
  };
8034
8032
  }
8035
8033
  if (cursor.tailLimit > 0 && knownSignature === lastMessageSignature) {
8036
- return {
8037
- syncMode: "noop",
8038
- replaceFrom: totalMessages,
8039
- messages: [],
8040
- totalMessages,
8041
- lastMessageSignature
8042
- };
8034
+ const requestedTailCount = Math.min(totalMessages, cursor.tailLimit);
8035
+ if (knownMessageCount >= requestedTailCount) {
8036
+ return {
8037
+ syncMode: "noop",
8038
+ replaceFrom: totalMessages,
8039
+ messages: [],
8040
+ totalMessages,
8041
+ lastMessageSignature
8042
+ };
8043
+ }
8044
+ return buildBoundedTailSync(messages, cursor);
8043
8045
  }
8044
8046
  if (knownMessageCount < totalMessages) {
8045
8047
  const anchorSignature = getChatMessageSignature(messages[knownMessageCount - 1]);
@@ -12478,9 +12480,7 @@ function hydrateCliParsedMessages(parsedMessages, options) {
12478
12480
  };
12479
12481
  });
12480
12482
  }
12481
- function chooseMoreComparableCliMessage(left2, right2) {
12482
- const leftComparable = normalizeComparableMessageContent(left2.content || "");
12483
- const rightComparable = normalizeComparableMessageContent(right2.content || "");
12483
+ function chooseMoreComparableCliMessage(left2, right2, leftComparable = normalizeComparableMessageContent(left2.content || ""), rightComparable = normalizeComparableMessageContent(right2.content || "")) {
12484
12484
  if (leftComparable && leftComparable === rightComparable) {
12485
12485
  const leftNewlines = String(left2.content || "").split(/\r\n|\n|\r/g).length - 1;
12486
12486
  const rightNewlines = String(right2.content || "").split(/\r\n|\n|\r/g).length - 1;
@@ -12495,24 +12495,32 @@ function dedupeConsecutiveComparableCliMessages(messages) {
12495
12495
  ...message,
12496
12496
  content: typeof message.content === "string" ? message.content : String(message.content || "")
12497
12497
  };
12498
+ const currentComparable = normalizeComparableMessageContent(current.content || "");
12498
12499
  const previous = deduped[deduped.length - 1];
12499
12500
  if (!previous) {
12500
- deduped.push(current);
12501
+ deduped.push({ message: current, comparable: currentComparable });
12501
12502
  continue;
12502
12503
  }
12503
- const previousComparable = normalizeComparableMessageContent(previous.content || "");
12504
- const currentComparable = normalizeComparableMessageContent(current.content || "");
12505
- const sameRole = previous.role === current.role;
12506
- const sameKind = (previous.kind || "standard") === (current.kind || "standard");
12507
- const sameSender = (previous.senderName || "") === (current.senderName || "");
12508
- const comparableMatch = previousComparable && previousComparable === currentComparable;
12504
+ const sameRole = previous.message.role === current.role;
12505
+ const sameKind = (previous.message.kind || "standard") === (current.kind || "standard");
12506
+ const sameSender = (previous.message.senderName || "") === (current.senderName || "");
12507
+ const comparableMatch = previous.comparable && previous.comparable === currentComparable;
12509
12508
  if (sameRole && sameKind && sameSender && comparableMatch) {
12510
- deduped[deduped.length - 1] = chooseMoreComparableCliMessage(previous, current);
12509
+ const selected = chooseMoreComparableCliMessage(
12510
+ previous.message,
12511
+ current,
12512
+ previous.comparable,
12513
+ currentComparable
12514
+ );
12515
+ deduped[deduped.length - 1] = {
12516
+ message: selected,
12517
+ comparable: selected === current ? currentComparable : previous.comparable
12518
+ };
12511
12519
  continue;
12512
12520
  }
12513
- deduped.push(current);
12521
+ deduped.push({ message: current, comparable: currentComparable });
12514
12522
  }
12515
- return deduped;
12523
+ return deduped.map((entry) => entry.message);
12516
12524
  }
12517
12525
  function normalizeCliParsedMessages(parsedMessages, options) {
12518
12526
  return dedupeConsecutiveComparableCliMessages(hydrateCliParsedMessages(parsedMessages, options).map((message) => ({
@@ -13537,6 +13545,14 @@ var init_provider_cli_adapter = __esm({
13537
13545
  }
13538
13546
  this.resolveStartupState("settled");
13539
13547
  if (this.startupParseGate) return;
13548
+ if (!this.isWaitingForResponse && !this.currentTurnScope && !this.activeModal && !this.parseErrorMessage) {
13549
+ const tail = this.settledBuffer || this.recentOutputBuffer;
13550
+ const modal2 = this.runParseApproval(tail);
13551
+ const lightweightStatus = this.cliScripts?.detectStatus ? this.runDetectStatus(tail) : null;
13552
+ if (!modal2 && lightweightStatus === "idle" && this.currentStatus === "idle") {
13553
+ return;
13554
+ }
13555
+ }
13540
13556
  const session = this.runParseSession();
13541
13557
  if (!session) return;
13542
13558
  const { status, messages, modal, parsedStatus } = session;
@@ -15477,8 +15493,8 @@ var init_cli_provider_instance = __esm({
15477
15493
  }
15478
15494
  detectStatusTransition() {
15479
15495
  const now = Date.now();
15480
- const adapterStatus = this.adapter.getStatus();
15481
- const parsedStatus = this.adapter.getScriptParsedStatus?.() || null;
15496
+ const adapterStatus = this.adapter.getStatus({ allowParse: false });
15497
+ const parsedStatus = null;
15482
15498
  const rawStatus = adapterStatus.status;
15483
15499
  const autoApproveActive = rawStatus === "waiting_approval" && this.shouldAutoApprove();
15484
15500
  if (autoApproveActive && !this.autoApproveBusy) {
@@ -15571,7 +15587,7 @@ var init_cli_provider_instance = __esm({
15571
15587
  this.completedDebouncePending = { chatTitle, duration: duration3, timestamp: now };
15572
15588
  this.completedDebounceTimer = setTimeout(() => {
15573
15589
  if (this.completedDebouncePending) {
15574
- const latestStatus = this.adapter.getStatus();
15590
+ const latestStatus = this.adapter.getStatus({ allowParse: false });
15575
15591
  const latestAutoApproveActive = latestStatus.status === "waiting_approval" && this.shouldAutoApprove();
15576
15592
  const latestVisibleStatus = latestAutoApproveActive ? "generating" : latestStatus.status;
15577
15593
  if (latestVisibleStatus !== "idle") {
@@ -88304,7 +88320,7 @@ var init_adhdev_daemon = __esm({
88304
88320
  init_version();
88305
88321
  init_src();
88306
88322
  init_runtime_defaults();
88307
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.38" });
88323
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.40" });
88308
88324
  AdhdevDaemon = class _AdhdevDaemon {
88309
88325
  localHttpServer = null;
88310
88326
  localWss = null;
@@ -88622,12 +88638,24 @@ var init_adhdev_daemon = __esm({
88622
88638
  }
88623
88639
  findProviderStateBySessionId(sessionId) {
88624
88640
  if (!this.components || !sessionId) return null;
88625
- const states = this.components.instanceManager.collectAllStates();
88626
- for (const state of states) {
88627
- if (state.instanceId === sessionId) return state;
88628
- if (state.category === "ide") {
88641
+ const directInstance = this.components.instanceManager.getInstance(sessionId);
88642
+ if (directInstance) {
88643
+ try {
88644
+ return directInstance.getState();
88645
+ } catch (error48) {
88646
+ LOG.warn("P2P", `Failed to collect subscribed session state for ${sessionId}: ${error48?.message || String(error48)}`);
88647
+ return null;
88648
+ }
88649
+ }
88650
+ for (const instance of this.components.instanceManager.getByCategory("ide")) {
88651
+ try {
88652
+ const state = instance.getState();
88653
+ if (state.instanceId === sessionId) return state;
88654
+ if (state.category !== "ide") continue;
88629
88655
  const child = state.extensions.find((entry) => entry.instanceId === sessionId);
88630
88656
  if (child) return child;
88657
+ } catch (error48) {
88658
+ LOG.warn("P2P", `Failed to collect IDE child state for ${sessionId}: ${error48?.message || String(error48)}`);
88631
88659
  }
88632
88660
  }
88633
88661
  return null;