@adhdev/daemon-standalone 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.js CHANGED
@@ -29662,9 +29662,7 @@ var require_dist2 = __commonJS({
29662
29662
  };
29663
29663
  });
29664
29664
  }
29665
- function chooseMoreComparableCliMessage(left, right) {
29666
- const leftComparable = normalizeComparableMessageContent(left.content || "");
29667
- const rightComparable = normalizeComparableMessageContent(right.content || "");
29665
+ function chooseMoreComparableCliMessage(left, right, leftComparable = normalizeComparableMessageContent(left.content || ""), rightComparable = normalizeComparableMessageContent(right.content || "")) {
29668
29666
  if (leftComparable && leftComparable === rightComparable) {
29669
29667
  const leftNewlines = String(left.content || "").split(/\r\n|\n|\r/g).length - 1;
29670
29668
  const rightNewlines = String(right.content || "").split(/\r\n|\n|\r/g).length - 1;
@@ -29679,24 +29677,32 @@ var require_dist2 = __commonJS({
29679
29677
  ...message,
29680
29678
  content: typeof message.content === "string" ? message.content : String(message.content || "")
29681
29679
  };
29680
+ const currentComparable = normalizeComparableMessageContent(current.content || "");
29682
29681
  const previous = deduped[deduped.length - 1];
29683
29682
  if (!previous) {
29684
- deduped.push(current);
29683
+ deduped.push({ message: current, comparable: currentComparable });
29685
29684
  continue;
29686
29685
  }
29687
- const previousComparable = normalizeComparableMessageContent(previous.content || "");
29688
- const currentComparable = normalizeComparableMessageContent(current.content || "");
29689
- const sameRole = previous.role === current.role;
29690
- const sameKind = (previous.kind || "standard") === (current.kind || "standard");
29691
- const sameSender = (previous.senderName || "") === (current.senderName || "");
29692
- const comparableMatch = previousComparable && previousComparable === currentComparable;
29686
+ const sameRole = previous.message.role === current.role;
29687
+ const sameKind = (previous.message.kind || "standard") === (current.kind || "standard");
29688
+ const sameSender = (previous.message.senderName || "") === (current.senderName || "");
29689
+ const comparableMatch = previous.comparable && previous.comparable === currentComparable;
29693
29690
  if (sameRole && sameKind && sameSender && comparableMatch) {
29694
- deduped[deduped.length - 1] = chooseMoreComparableCliMessage(previous, current);
29691
+ const selected = chooseMoreComparableCliMessage(
29692
+ previous.message,
29693
+ current,
29694
+ previous.comparable,
29695
+ currentComparable
29696
+ );
29697
+ deduped[deduped.length - 1] = {
29698
+ message: selected,
29699
+ comparable: selected === current ? currentComparable : previous.comparable
29700
+ };
29695
29701
  continue;
29696
29702
  }
29697
- deduped.push(current);
29703
+ deduped.push({ message: current, comparable: currentComparable });
29698
29704
  }
29699
- return deduped;
29705
+ return deduped.map((entry) => entry.message);
29700
29706
  }
29701
29707
  function normalizeCliParsedMessages(parsedMessages, options) {
29702
29708
  return dedupeConsecutiveComparableCliMessages(hydrateCliParsedMessages(parsedMessages, options).map((message) => ({
@@ -30144,7 +30150,7 @@ var require_dist2 = __commonJS({
30144
30150
  }
30145
30151
  getFreshParsedStatusCache() {
30146
30152
  const cached2 = this.parsedStatusCache;
30147
- if (cached2 && cached2.committedMessagesRef === this.committedMessages && cached2.responseBuffer === this.responseBuffer && cached2.currentTurnScope === this.currentTurnScope && cached2.recentOutputBuffer === this.recentOutputBuffer && cached2.accumulatedBuffer === this.accumulatedBuffer && cached2.accumulatedRawBuffer === this.accumulatedRawBuffer && cached2.screenText === this.lastScreenText && cached2.currentStatus === this.currentStatus && cached2.activeModal === this.activeModal && cached2.cliName === this.cliName && cached2.lastOutputAt === this.lastOutputAt) {
30153
+ if (cached2 && cached2.committedMessagesRef === this.committedMessages && cached2.responseBuffer === this.responseBuffer && cached2.currentTurnScope === this.currentTurnScope && cached2.recentOutputBuffer === this.recentOutputBuffer && cached2.accumulatedBuffer === this.accumulatedBuffer && cached2.screenText === this.lastScreenText && cached2.currentStatus === this.currentStatus && cached2.activeModal === this.activeModal && cached2.cliName === this.cliName) {
30148
30154
  return cached2.result;
30149
30155
  }
30150
30156
  return null;
@@ -31392,7 +31398,7 @@ var require_dist2 = __commonJS({
31392
31398
  getScriptParsedStatus() {
31393
31399
  const screenText = this.readTerminalScreenText();
31394
31400
  const cached2 = this.parsedStatusCache;
31395
- if (cached2 && cached2.committedMessagesRef === this.committedMessages && cached2.responseBuffer === this.responseBuffer && cached2.currentTurnScope === this.currentTurnScope && cached2.recentOutputBuffer === this.recentOutputBuffer && cached2.accumulatedBuffer === this.accumulatedBuffer && cached2.accumulatedRawBuffer === this.accumulatedRawBuffer && cached2.screenText === screenText && cached2.currentStatus === this.currentStatus && cached2.activeModal === this.activeModal && cached2.cliName === this.cliName && cached2.lastOutputAt === this.lastOutputAt) {
31401
+ if (cached2 && cached2.committedMessagesRef === this.committedMessages && cached2.responseBuffer === this.responseBuffer && cached2.currentTurnScope === this.currentTurnScope && cached2.recentOutputBuffer === this.recentOutputBuffer && cached2.accumulatedBuffer === this.accumulatedBuffer && cached2.screenText === screenText && cached2.currentStatus === this.currentStatus && cached2.activeModal === this.activeModal && cached2.cliName === this.cliName) {
31396
31402
  return cached2.result;
31397
31403
  }
31398
31404
  const parsed = this.parseCurrentTranscript(
@@ -31511,12 +31517,10 @@ var require_dist2 = __commonJS({
31511
31517
  currentTurnScope: this.currentTurnScope,
31512
31518
  recentOutputBuffer: this.recentOutputBuffer,
31513
31519
  accumulatedBuffer: this.accumulatedBuffer,
31514
- accumulatedRawBuffer: this.accumulatedRawBuffer,
31515
31520
  screenText,
31516
31521
  currentStatus: this.currentStatus,
31517
31522
  activeModal: this.activeModal,
31518
31523
  cliName: this.cliName,
31519
- lastOutputAt: this.lastOutputAt,
31520
31524
  result
31521
31525
  };
31522
31526
  return result;
@@ -36336,6 +36340,15 @@ ${cleanBody}`;
36336
36340
  pendingEvents: this.flushEvents()
36337
36341
  };
36338
36342
  }
36343
+ getSessionModalState(sessionId) {
36344
+ if (sessionId && sessionId !== this.instanceId) return null;
36345
+ return {
36346
+ id: this.instanceId,
36347
+ status: this.currentStatus,
36348
+ title: this.chatTitle || this.agentName || this.provider.name,
36349
+ activeModal: this.activeModal
36350
+ };
36351
+ }
36339
36352
  onEvent(event, data) {
36340
36353
  if (event === "stream_update") {
36341
36354
  if (data?.streams) this.agentStreams = data.streams;
@@ -36796,6 +36809,23 @@ ${effect.notification.body || ""}`.trim();
36796
36809
  pendingEvents: this.flushEvents()
36797
36810
  };
36798
36811
  }
36812
+ getSessionModalState(sessionId) {
36813
+ if (sessionId && sessionId !== this.instanceId) {
36814
+ for (const ext of this.extensions.values()) {
36815
+ const projected = ext.getSessionModalState?.(sessionId);
36816
+ if (projected?.id === sessionId) return projected;
36817
+ }
36818
+ return null;
36819
+ }
36820
+ const autoApproveActive = (this.currentStatus === "waiting_approval" || this.cachedChat?.status === "waiting_approval") && this.canAutoApprove();
36821
+ const visibleStatus = autoApproveActive ? "generating" : this.currentStatus;
36822
+ return {
36823
+ id: this.instanceId,
36824
+ status: autoApproveActive && this.cachedChat?.status === "waiting_approval" ? "generating" : this.cachedChat?.status || visibleStatus,
36825
+ title: this.cachedChat?.title || this.type,
36826
+ activeModal: autoApproveActive ? null : this.cachedChat?.activeModal || null
36827
+ };
36828
+ }
36799
36829
  onEvent(event, data) {
36800
36830
  if (event === "cdp_connected") {
36801
36831
  } else if (event === "cdp_disconnected") {
@@ -38406,68 +38436,66 @@ ${effect.notification.body || ""}`.trim();
38406
38436
  const messages = Array.isArray(payload.messages) ? payload.messages : [];
38407
38437
  return normalizeChatMessages(messages);
38408
38438
  }
38409
- function buildReadChatReplayCollapseSignature(message) {
38410
- if (!message) return "";
38411
- const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
38412
- const kind = typeof message.kind === "string" ? message.kind.trim().toLowerCase() : "standard";
38413
- const senderName = typeof message.senderName === "string" ? message.senderName.trim().toLowerCase() : "";
38414
- const content = flattenContent(message.content || "").replace(/\s+/g, " ").trim();
38415
- return `${role}:${kind}:${senderName}:${content}`;
38416
- }
38417
- function shouldCollapseReadChatReplayDuplicate(message) {
38418
- if (!message) return false;
38419
- const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
38420
- return role === "assistant" || role === "system";
38439
+ function normalizeReadChatReplayTextContent(content) {
38440
+ return flattenContent(content || "").replace(/\s+/g, " ").trim();
38421
38441
  }
38422
- function normalizeReadChatReplayText(message) {
38423
- return flattenContent(message?.content || "").replace(/\s+/g, " ").trim();
38424
- }
38425
- function isStableReadChatAssistantAnswer(message) {
38426
- if (!message) return false;
38442
+ function getReadChatReplayCollapseInfo(message) {
38443
+ if (!message) return null;
38427
38444
  const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
38428
38445
  const kind = typeof message.kind === "string" ? message.kind.trim().toLowerCase() : "standard";
38429
- if (role !== "assistant") return false;
38430
- if (kind && kind !== "standard") return false;
38431
- const content = normalizeReadChatReplayText(message);
38432
- if (content.length < 160) return false;
38433
- if (/^(bash|shell|terminal) command\b/i.test(content)) return false;
38446
+ const senderName = typeof message.senderName === "string" ? message.senderName.trim().toLowerCase() : "";
38447
+ const collapsible = role === "assistant" || role === "system";
38448
+ if (!collapsible) return { role, kind, senderName, content: "", signature: "", collapsible };
38449
+ const content = normalizeReadChatReplayTextContent(message.content);
38450
+ return {
38451
+ role,
38452
+ kind,
38453
+ senderName,
38454
+ content,
38455
+ signature: `${role}:${kind}:${senderName}:${content}`,
38456
+ collapsible
38457
+ };
38458
+ }
38459
+ function isStableReadChatAssistantAnswerInfo(info) {
38460
+ if (!info) return false;
38461
+ if (info.role !== "assistant") return false;
38462
+ if (info.kind && info.kind !== "standard") return false;
38463
+ if (info.content.length < 160) return false;
38464
+ if (/^(bash|shell|terminal) command\b/i.test(info.content)) return false;
38434
38465
  return true;
38435
38466
  }
38436
- function isReplayedAssistantAnswerAfterStableAnswer(message, stableAnswer) {
38437
- if (!message || !stableAnswer) return false;
38438
- const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
38439
- const kind = typeof message.kind === "string" ? message.kind.trim().toLowerCase() : "standard";
38440
- if (role !== "assistant") return false;
38441
- if (kind && kind !== "standard") return false;
38442
- const content = normalizeReadChatReplayText(message);
38443
- const stableContent = normalizeReadChatReplayText(stableAnswer);
38467
+ function isReplayedAssistantAnswerAfterStableAnswerInfo(info, stableContent) {
38468
+ if (!info || !stableContent) return false;
38469
+ if (info.role !== "assistant") return false;
38470
+ if (info.kind && info.kind !== "standard") return false;
38471
+ const content = info.content;
38444
38472
  if (content.length < 80 || stableContent.length < 80) return false;
38445
38473
  return content === stableContent || content.startsWith(stableContent) || stableContent.startsWith(content);
38446
38474
  }
38447
38475
  function collapseReplayDuplicatesFromReadChat(messages) {
38448
38476
  const collapsed = [];
38449
38477
  const replaySignaturesInCurrentTurn = /* @__PURE__ */ new Set();
38450
- let stableAssistantAnswerInCurrentTurn = null;
38478
+ let stableAssistantAnswerContentInCurrentTurn = "";
38479
+ let previousReplaySignature = "";
38451
38480
  for (const message of messages) {
38452
- const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
38453
- if (role === "user") {
38481
+ const info = getReadChatReplayCollapseInfo(message);
38482
+ if (info?.role === "user") {
38454
38483
  replaySignaturesInCurrentTurn.clear();
38455
- stableAssistantAnswerInCurrentTurn = null;
38484
+ stableAssistantAnswerContentInCurrentTurn = "";
38485
+ previousReplaySignature = "";
38456
38486
  }
38457
- const signature = buildReadChatReplayCollapseSignature(message);
38458
- const previous = collapsed[collapsed.length - 1];
38459
- const previousSignature = buildReadChatReplayCollapseSignature(previous);
38460
- if (shouldCollapseReadChatReplayDuplicate(message) && signature) {
38461
- if (previousSignature === signature) continue;
38462
- if (replaySignaturesInCurrentTurn.has(signature)) continue;
38463
- if (isReplayedAssistantAnswerAfterStableAnswer(message, stableAssistantAnswerInCurrentTurn)) continue;
38487
+ if (info?.collapsible && info.signature) {
38488
+ if (previousReplaySignature === info.signature) continue;
38489
+ if (replaySignaturesInCurrentTurn.has(info.signature)) continue;
38490
+ if (isReplayedAssistantAnswerAfterStableAnswerInfo(info, stableAssistantAnswerContentInCurrentTurn)) continue;
38464
38491
  }
38465
38492
  collapsed.push(message);
38466
- if (shouldCollapseReadChatReplayDuplicate(message) && signature) {
38467
- replaySignaturesInCurrentTurn.add(signature);
38493
+ previousReplaySignature = info?.collapsible ? info.signature : "";
38494
+ if (info?.collapsible && info.signature) {
38495
+ replaySignaturesInCurrentTurn.add(info.signature);
38468
38496
  }
38469
- if (isStableReadChatAssistantAnswer(message)) {
38470
- stableAssistantAnswerInCurrentTurn = message;
38497
+ if (isStableReadChatAssistantAnswerInfo(info)) {
38498
+ stableAssistantAnswerContentInCurrentTurn = info?.content || "";
38471
38499
  }
38472
38500
  }
38473
38501
  return collapsed;
@@ -38547,13 +38575,17 @@ ${effect.notification.body || ""}`.trim();
38547
38575
  };
38548
38576
  }
38549
38577
  if (cursor.tailLimit > 0 && knownSignature === lastMessageSignature) {
38550
- return {
38551
- syncMode: "noop",
38552
- replaceFrom: totalMessages,
38553
- messages: [],
38554
- totalMessages,
38555
- lastMessageSignature
38556
- };
38578
+ const requestedTailCount = Math.min(totalMessages, cursor.tailLimit);
38579
+ if (knownMessageCount >= requestedTailCount) {
38580
+ return {
38581
+ syncMode: "noop",
38582
+ replaceFrom: totalMessages,
38583
+ messages: [],
38584
+ totalMessages,
38585
+ lastMessageSignature
38586
+ };
38587
+ }
38588
+ return buildBoundedTailSync(messages, cursor);
38557
38589
  }
38558
38590
  if (knownMessageCount < totalMessages) {
38559
38591
  const anchorSignature = getChatMessageSignature(messages[knownMessageCount - 1]);
@@ -41404,6 +41436,18 @@ ${effect.notification.body || ""}`.trim();
41404
41436
  runtimeRecoveryState: runtime?.recoveryState ?? null
41405
41437
  };
41406
41438
  }
41439
+ getSessionModalState() {
41440
+ const adapterStatus = this.adapter.getStatus({ allowParse: false });
41441
+ const autoApproveActive = adapterStatus.status === "waiting_approval" && this.shouldAutoApprove();
41442
+ const visibleStatus = autoApproveActive ? "generating" : adapterStatus.status;
41443
+ const dirName = this.workingDir.split("/").filter(Boolean).pop() || "session";
41444
+ return {
41445
+ id: this.instanceId,
41446
+ status: visibleStatus,
41447
+ title: dirName,
41448
+ activeModal: autoApproveActive ? null : adapterStatus.activeModal
41449
+ };
41450
+ }
41407
41451
  updateSettings(newSettings) {
41408
41452
  this.settings = { ...newSettings };
41409
41453
  this.adapter.updateRuntimeSettings?.(this.settings);
@@ -42129,6 +42173,18 @@ ${effect.notification.body || ""}`.trim();
42129
42173
  this.detectStatusTransition();
42130
42174
  }
42131
42175
  }
42176
+ getSessionModalState() {
42177
+ const dirName = this.workingDir.split("/").filter(Boolean).pop() || "session";
42178
+ return {
42179
+ id: this.instanceId,
42180
+ status: this.currentStatus,
42181
+ title: `${this.provider.name} \xB7 ${dirName}`,
42182
+ activeModal: this.currentStatus === "waiting_approval" ? {
42183
+ message: this.activeToolCalls.find((t) => t.status === "running")?.name || "Permission requested",
42184
+ buttons: ["Approve", "Reject"]
42185
+ } : null
42186
+ };
42187
+ }
42132
42188
  getState() {
42133
42189
  const dirName = this.workingDir.split("/").filter(Boolean).pop() || "session";
42134
42190
  const recentMessages = normalizeChatMessages(this.messages.map((m) => {
@@ -48963,6 +49019,29 @@ Run 'adhdev doctor' for detailed diagnostics.`
48963
49019
  }
48964
49020
  return sessions;
48965
49021
  }
49022
+ getSessionModalState(sessionId, options = {}) {
49023
+ if (!sessionId) return null;
49024
+ const candidates = [sessionId];
49025
+ if (options.instanceKey && options.instanceKey !== sessionId) {
49026
+ candidates.push(options.instanceKey);
49027
+ }
49028
+ for (const id of candidates) {
49029
+ const instance = this.instances.get(id);
49030
+ if (!instance?.getSessionModalState) continue;
49031
+ try {
49032
+ const projected = instance.getSessionModalState(sessionId);
49033
+ if (!projected?.id) continue;
49034
+ if (projected.id !== sessionId) {
49035
+ LOG2.warn("InstanceMgr", `[InstanceManager] Ignoring mismatched session modal projection from ${id}: requested=${sessionId} projected=${projected.id}`);
49036
+ continue;
49037
+ }
49038
+ return projected;
49039
+ } catch (e) {
49040
+ LOG2.warn("InstanceMgr", `[InstanceManager] Failed to project session modal metadata from ${id}: ${e.message}`);
49041
+ }
49042
+ }
49043
+ return null;
49044
+ }
48966
49045
  /**
48967
49046
  * Per-category status collect
48968
49047
  */
@@ -57211,25 +57290,20 @@ var StandaloneServer = class {
57211
57290
  }
57212
57291
  }
57213
57292
  }
57214
- findProviderStateBySessionId(sessionId) {
57293
+ findSessionModalStateBySessionId(sessionId) {
57215
57294
  if (!this.components || !sessionId) return null;
57216
- const states = this.components.instanceManager.collectAllStates();
57217
- for (const state of states) {
57218
- if (state.instanceId === sessionId) return state;
57219
- if (state.category === "ide") {
57220
- const child = state.extensions.find((entry) => entry.instanceId === sessionId);
57221
- if (child) return child;
57222
- }
57223
- }
57224
- return null;
57295
+ const target = this.components.sessionRegistry.get(sessionId);
57296
+ return this.components.instanceManager.getSessionModalState(sessionId, {
57297
+ instanceKey: target?.instanceKey
57298
+ });
57225
57299
  }
57226
57300
  buildSessionModalUpdate(state, key) {
57227
- const providerState = this.findProviderStateBySessionId(state.request.params.targetSessionId);
57228
- if (!providerState) return null;
57301
+ const modalState = this.findSessionModalStateBySessionId(state.request.params.targetSessionId);
57302
+ if (!modalState) return null;
57229
57303
  const now = Date.now();
57230
- const activeModal = providerState.activeChat?.activeModal;
57231
- const status = String(providerState.activeChat?.status || providerState.status || "idle");
57232
- const title = typeof providerState.activeChat?.title === "string" ? providerState.activeChat.title : void 0;
57304
+ const activeModal = modalState.activeModal;
57305
+ const status = String(modalState.status || "idle");
57306
+ const title = typeof modalState.title === "string" ? modalState.title : void 0;
57233
57307
  const prepared = (0, import_daemon_core2.prepareSessionModalUpdate)({
57234
57308
  key,
57235
57309
  sessionId: state.request.params.targetSessionId,