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/index.js CHANGED
@@ -7372,68 +7372,66 @@ function normalizeReadChatMessages(payload) {
7372
7372
  const messages = Array.isArray(payload.messages) ? payload.messages : [];
7373
7373
  return normalizeChatMessages(messages);
7374
7374
  }
7375
- function buildReadChatReplayCollapseSignature(message) {
7376
- if (!message) return "";
7375
+ function normalizeReadChatReplayTextContent(content) {
7376
+ return flattenContent(content || "").replace(/\s+/g, " ").trim();
7377
+ }
7378
+ function getReadChatReplayCollapseInfo(message) {
7379
+ if (!message) return null;
7377
7380
  const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
7378
7381
  const kind = typeof message.kind === "string" ? message.kind.trim().toLowerCase() : "standard";
7379
7382
  const senderName = typeof message.senderName === "string" ? message.senderName.trim().toLowerCase() : "";
7380
- const content = flattenContent(message.content || "").replace(/\s+/g, " ").trim();
7381
- return `${role}:${kind}:${senderName}:${content}`;
7382
- }
7383
- function shouldCollapseReadChatReplayDuplicate(message) {
7384
- if (!message) return false;
7385
- const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
7386
- return role === "assistant" || role === "system";
7387
- }
7388
- function normalizeReadChatReplayText(message) {
7389
- return flattenContent(message?.content || "").replace(/\s+/g, " ").trim();
7383
+ const collapsible = role === "assistant" || role === "system";
7384
+ if (!collapsible) return { role, kind, senderName, content: "", signature: "", collapsible };
7385
+ const content = normalizeReadChatReplayTextContent(message.content);
7386
+ return {
7387
+ role,
7388
+ kind,
7389
+ senderName,
7390
+ content,
7391
+ signature: `${role}:${kind}:${senderName}:${content}`,
7392
+ collapsible
7393
+ };
7390
7394
  }
7391
- function isStableReadChatAssistantAnswer(message) {
7392
- if (!message) return false;
7393
- const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
7394
- const kind = typeof message.kind === "string" ? message.kind.trim().toLowerCase() : "standard";
7395
- if (role !== "assistant") return false;
7396
- if (kind && kind !== "standard") return false;
7397
- const content = normalizeReadChatReplayText(message);
7398
- if (content.length < 160) return false;
7399
- if (/^(bash|shell|terminal) command\b/i.test(content)) return false;
7395
+ function isStableReadChatAssistantAnswerInfo(info) {
7396
+ if (!info) return false;
7397
+ if (info.role !== "assistant") return false;
7398
+ if (info.kind && info.kind !== "standard") return false;
7399
+ if (info.content.length < 160) return false;
7400
+ if (/^(bash|shell|terminal) command\b/i.test(info.content)) return false;
7400
7401
  return true;
7401
7402
  }
7402
- function isReplayedAssistantAnswerAfterStableAnswer(message, stableAnswer) {
7403
- if (!message || !stableAnswer) return false;
7404
- const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
7405
- const kind = typeof message.kind === "string" ? message.kind.trim().toLowerCase() : "standard";
7406
- if (role !== "assistant") return false;
7407
- if (kind && kind !== "standard") return false;
7408
- const content = normalizeReadChatReplayText(message);
7409
- const stableContent = normalizeReadChatReplayText(stableAnswer);
7403
+ function isReplayedAssistantAnswerAfterStableAnswerInfo(info, stableContent) {
7404
+ if (!info || !stableContent) return false;
7405
+ if (info.role !== "assistant") return false;
7406
+ if (info.kind && info.kind !== "standard") return false;
7407
+ const content = info.content;
7410
7408
  if (content.length < 80 || stableContent.length < 80) return false;
7411
7409
  return content === stableContent || content.startsWith(stableContent) || stableContent.startsWith(content);
7412
7410
  }
7413
7411
  function collapseReplayDuplicatesFromReadChat(messages) {
7414
7412
  const collapsed = [];
7415
7413
  const replaySignaturesInCurrentTurn = /* @__PURE__ */ new Set();
7416
- let stableAssistantAnswerInCurrentTurn = null;
7414
+ let stableAssistantAnswerContentInCurrentTurn = "";
7415
+ let previousReplaySignature = "";
7417
7416
  for (const message of messages) {
7418
- const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
7419
- if (role === "user") {
7417
+ const info = getReadChatReplayCollapseInfo(message);
7418
+ if (info?.role === "user") {
7420
7419
  replaySignaturesInCurrentTurn.clear();
7421
- stableAssistantAnswerInCurrentTurn = null;
7420
+ stableAssistantAnswerContentInCurrentTurn = "";
7421
+ previousReplaySignature = "";
7422
7422
  }
7423
- const signature = buildReadChatReplayCollapseSignature(message);
7424
- const previous = collapsed[collapsed.length - 1];
7425
- const previousSignature = buildReadChatReplayCollapseSignature(previous);
7426
- if (shouldCollapseReadChatReplayDuplicate(message) && signature) {
7427
- if (previousSignature === signature) continue;
7428
- if (replaySignaturesInCurrentTurn.has(signature)) continue;
7429
- if (isReplayedAssistantAnswerAfterStableAnswer(message, stableAssistantAnswerInCurrentTurn)) continue;
7423
+ if (info?.collapsible && info.signature) {
7424
+ if (previousReplaySignature === info.signature) continue;
7425
+ if (replaySignaturesInCurrentTurn.has(info.signature)) continue;
7426
+ if (isReplayedAssistantAnswerAfterStableAnswerInfo(info, stableAssistantAnswerContentInCurrentTurn)) continue;
7430
7427
  }
7431
7428
  collapsed.push(message);
7432
- if (shouldCollapseReadChatReplayDuplicate(message) && signature) {
7433
- replaySignaturesInCurrentTurn.add(signature);
7429
+ previousReplaySignature = info?.collapsible ? info.signature : "";
7430
+ if (info?.collapsible && info.signature) {
7431
+ replaySignaturesInCurrentTurn.add(info.signature);
7434
7432
  }
7435
- if (isStableReadChatAssistantAnswer(message)) {
7436
- stableAssistantAnswerInCurrentTurn = message;
7433
+ if (isStableReadChatAssistantAnswerInfo(info)) {
7434
+ stableAssistantAnswerContentInCurrentTurn = info?.content || "";
7437
7435
  }
7438
7436
  }
7439
7437
  return collapsed;
@@ -7513,13 +7511,17 @@ function computeReadChatSync(messages, cursor) {
7513
7511
  };
7514
7512
  }
7515
7513
  if (cursor.tailLimit > 0 && knownSignature === lastMessageSignature) {
7516
- return {
7517
- syncMode: "noop",
7518
- replaceFrom: totalMessages,
7519
- messages: [],
7520
- totalMessages,
7521
- lastMessageSignature
7522
- };
7514
+ const requestedTailCount = Math.min(totalMessages, cursor.tailLimit);
7515
+ if (knownMessageCount >= requestedTailCount) {
7516
+ return {
7517
+ syncMode: "noop",
7518
+ replaceFrom: totalMessages,
7519
+ messages: [],
7520
+ totalMessages,
7521
+ lastMessageSignature
7522
+ };
7523
+ }
7524
+ return buildBoundedTailSync(messages, cursor);
7523
7525
  }
7524
7526
  if (knownMessageCount < totalMessages) {
7525
7527
  const anchorSignature = getChatMessageSignature(messages[knownMessageCount - 1]);
@@ -11522,9 +11524,7 @@ function hydrateCliParsedMessages(parsedMessages, options) {
11522
11524
  };
11523
11525
  });
11524
11526
  }
11525
- function chooseMoreComparableCliMessage(left2, right2) {
11526
- const leftComparable = normalizeComparableMessageContent(left2.content || "");
11527
- const rightComparable = normalizeComparableMessageContent(right2.content || "");
11527
+ function chooseMoreComparableCliMessage(left2, right2, leftComparable = normalizeComparableMessageContent(left2.content || ""), rightComparable = normalizeComparableMessageContent(right2.content || "")) {
11528
11528
  if (leftComparable && leftComparable === rightComparable) {
11529
11529
  const leftNewlines = String(left2.content || "").split(/\r\n|\n|\r/g).length - 1;
11530
11530
  const rightNewlines = String(right2.content || "").split(/\r\n|\n|\r/g).length - 1;
@@ -11539,24 +11539,32 @@ function dedupeConsecutiveComparableCliMessages(messages) {
11539
11539
  ...message,
11540
11540
  content: typeof message.content === "string" ? message.content : String(message.content || "")
11541
11541
  };
11542
+ const currentComparable = normalizeComparableMessageContent(current.content || "");
11542
11543
  const previous = deduped[deduped.length - 1];
11543
11544
  if (!previous) {
11544
- deduped.push(current);
11545
+ deduped.push({ message: current, comparable: currentComparable });
11545
11546
  continue;
11546
11547
  }
11547
- const previousComparable = normalizeComparableMessageContent(previous.content || "");
11548
- const currentComparable = normalizeComparableMessageContent(current.content || "");
11549
- const sameRole = previous.role === current.role;
11550
- const sameKind = (previous.kind || "standard") === (current.kind || "standard");
11551
- const sameSender = (previous.senderName || "") === (current.senderName || "");
11552
- const comparableMatch = previousComparable && previousComparable === currentComparable;
11548
+ const sameRole = previous.message.role === current.role;
11549
+ const sameKind = (previous.message.kind || "standard") === (current.kind || "standard");
11550
+ const sameSender = (previous.message.senderName || "") === (current.senderName || "");
11551
+ const comparableMatch = previous.comparable && previous.comparable === currentComparable;
11553
11552
  if (sameRole && sameKind && sameSender && comparableMatch) {
11554
- deduped[deduped.length - 1] = chooseMoreComparableCliMessage(previous, current);
11553
+ const selected = chooseMoreComparableCliMessage(
11554
+ previous.message,
11555
+ current,
11556
+ previous.comparable,
11557
+ currentComparable
11558
+ );
11559
+ deduped[deduped.length - 1] = {
11560
+ message: selected,
11561
+ comparable: selected === current ? currentComparable : previous.comparable
11562
+ };
11555
11563
  continue;
11556
11564
  }
11557
- deduped.push(current);
11565
+ deduped.push({ message: current, comparable: currentComparable });
11558
11566
  }
11559
- return deduped;
11567
+ return deduped.map((entry) => entry.message);
11560
11568
  }
11561
11569
  function normalizeCliParsedMessages(parsedMessages, options) {
11562
11570
  return dedupeConsecutiveComparableCliMessages(hydrateCliParsedMessages(parsedMessages, options).map((message) => ({
@@ -12581,6 +12589,14 @@ var init_provider_cli_adapter = __esm({
12581
12589
  }
12582
12590
  this.resolveStartupState("settled");
12583
12591
  if (this.startupParseGate) return;
12592
+ if (!this.isWaitingForResponse && !this.currentTurnScope && !this.activeModal && !this.parseErrorMessage) {
12593
+ const tail = this.settledBuffer || this.recentOutputBuffer;
12594
+ const modal2 = this.runParseApproval(tail);
12595
+ const lightweightStatus = this.cliScripts?.detectStatus ? this.runDetectStatus(tail) : null;
12596
+ if (!modal2 && lightweightStatus === "idle" && this.currentStatus === "idle") {
12597
+ return;
12598
+ }
12599
+ }
12584
12600
  const session = this.runParseSession();
12585
12601
  if (!session) return;
12586
12602
  const { status, messages, modal, parsedStatus } = session;
@@ -14521,8 +14537,8 @@ var init_cli_provider_instance = __esm({
14521
14537
  }
14522
14538
  detectStatusTransition() {
14523
14539
  const now = Date.now();
14524
- const adapterStatus = this.adapter.getStatus();
14525
- const parsedStatus = this.adapter.getScriptParsedStatus?.() || null;
14540
+ const adapterStatus = this.adapter.getStatus({ allowParse: false });
14541
+ const parsedStatus = null;
14526
14542
  const rawStatus = adapterStatus.status;
14527
14543
  const autoApproveActive = rawStatus === "waiting_approval" && this.shouldAutoApprove();
14528
14544
  if (autoApproveActive && !this.autoApproveBusy) {
@@ -14615,7 +14631,7 @@ var init_cli_provider_instance = __esm({
14615
14631
  this.completedDebouncePending = { chatTitle, duration: duration3, timestamp: now };
14616
14632
  this.completedDebounceTimer = setTimeout(() => {
14617
14633
  if (this.completedDebouncePending) {
14618
- const latestStatus = this.adapter.getStatus();
14634
+ const latestStatus = this.adapter.getStatus({ allowParse: false });
14619
14635
  const latestAutoApproveActive = latestStatus.status === "waiting_approval" && this.shouldAutoApprove();
14620
14636
  const latestVisibleStatus = latestAutoApproveActive ? "generating" : latestStatus.status;
14621
14637
  if (latestVisibleStatus !== "idle") {
@@ -56584,7 +56600,7 @@ var init_adhdev_daemon = __esm({
56584
56600
  init_version();
56585
56601
  init_src();
56586
56602
  init_runtime_defaults();
56587
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.38" });
56603
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.40" });
56588
56604
  AdhdevDaemon = class _AdhdevDaemon {
56589
56605
  localHttpServer = null;
56590
56606
  localWss = null;
@@ -56902,12 +56918,24 @@ var init_adhdev_daemon = __esm({
56902
56918
  }
56903
56919
  findProviderStateBySessionId(sessionId) {
56904
56920
  if (!this.components || !sessionId) return null;
56905
- const states = this.components.instanceManager.collectAllStates();
56906
- for (const state of states) {
56907
- if (state.instanceId === sessionId) return state;
56908
- if (state.category === "ide") {
56921
+ const directInstance = this.components.instanceManager.getInstance(sessionId);
56922
+ if (directInstance) {
56923
+ try {
56924
+ return directInstance.getState();
56925
+ } catch (error48) {
56926
+ LOG.warn("P2P", `Failed to collect subscribed session state for ${sessionId}: ${error48?.message || String(error48)}`);
56927
+ return null;
56928
+ }
56929
+ }
56930
+ for (const instance of this.components.instanceManager.getByCategory("ide")) {
56931
+ try {
56932
+ const state = instance.getState();
56933
+ if (state.instanceId === sessionId) return state;
56934
+ if (state.category !== "ide") continue;
56909
56935
  const child = state.extensions.find((entry) => entry.instanceId === sessionId);
56910
56936
  if (child) return child;
56937
+ } catch (error48) {
56938
+ LOG.warn("P2P", `Failed to collect IDE child state for ${sessionId}: ${error48?.message || String(error48)}`);
56911
56939
  }
56912
56940
  }
56913
56941
  return null;