@adhdev/daemon-standalone 0.9.22 → 0.9.24

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
@@ -31839,8 +31839,10 @@ var require_dist2 = __commonJS({
31839
31839
  if (buttonIndex in this.approvalKeys) {
31840
31840
  this.ptyProcess.write(this.approvalKeys[buttonIndex]);
31841
31841
  } else {
31842
+ const buttonCount = Array.isArray(modal?.buttons) ? modal.buttons.length : 0;
31843
+ const clampedIndex = buttonCount > 0 ? Math.min(Math.max(0, buttonIndex), buttonCount - 1) : Math.max(0, buttonIndex);
31842
31844
  const DOWN = "\x1B[B";
31843
- const keys = DOWN.repeat(Math.max(0, buttonIndex)) + "\r";
31845
+ const keys = DOWN.repeat(clampedIndex) + "\r";
31844
31846
  this.ptyProcess.write(keys);
31845
31847
  }
31846
31848
  }
@@ -38144,13 +38146,40 @@ ${effect.notification.body || ""}`.trim();
38144
38146
  const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
38145
38147
  return role === "assistant" || role === "system";
38146
38148
  }
38149
+ function normalizeReadChatReplayText(message) {
38150
+ return flattenContent(message?.content || "").replace(/\s+/g, " ").trim();
38151
+ }
38152
+ function isStableReadChatAssistantAnswer(message) {
38153
+ if (!message) return false;
38154
+ const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
38155
+ const kind = typeof message.kind === "string" ? message.kind.trim().toLowerCase() : "standard";
38156
+ if (role !== "assistant") return false;
38157
+ if (kind && kind !== "standard") return false;
38158
+ const content = normalizeReadChatReplayText(message);
38159
+ if (content.length < 160) return false;
38160
+ if (/^(bash|shell|terminal) command\b/i.test(content)) return false;
38161
+ return true;
38162
+ }
38163
+ function isReplayedAssistantAnswerAfterStableAnswer(message, stableAnswer) {
38164
+ if (!message || !stableAnswer) return false;
38165
+ const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
38166
+ const kind = typeof message.kind === "string" ? message.kind.trim().toLowerCase() : "standard";
38167
+ if (role !== "assistant") return false;
38168
+ if (kind && kind !== "standard") return false;
38169
+ const content = normalizeReadChatReplayText(message);
38170
+ const stableContent = normalizeReadChatReplayText(stableAnswer);
38171
+ if (content.length < 80 || stableContent.length < 80) return false;
38172
+ return content === stableContent || content.startsWith(stableContent) || stableContent.startsWith(content);
38173
+ }
38147
38174
  function collapseReplayDuplicatesFromReadChat(messages) {
38148
38175
  const collapsed = [];
38149
38176
  const replaySignaturesInCurrentTurn = /* @__PURE__ */ new Set();
38177
+ let stableAssistantAnswerInCurrentTurn = null;
38150
38178
  for (const message of messages) {
38151
38179
  const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
38152
38180
  if (role === "user") {
38153
38181
  replaySignaturesInCurrentTurn.clear();
38182
+ stableAssistantAnswerInCurrentTurn = null;
38154
38183
  }
38155
38184
  const signature = buildReadChatReplayCollapseSignature(message);
38156
38185
  const previous = collapsed[collapsed.length - 1];
@@ -38158,11 +38187,15 @@ ${effect.notification.body || ""}`.trim();
38158
38187
  if (shouldCollapseReadChatReplayDuplicate(message) && signature) {
38159
38188
  if (previousSignature === signature) continue;
38160
38189
  if (replaySignaturesInCurrentTurn.has(signature)) continue;
38190
+ if (isReplayedAssistantAnswerAfterStableAnswer(message, stableAssistantAnswerInCurrentTurn)) continue;
38161
38191
  }
38162
38192
  collapsed.push(message);
38163
38193
  if (shouldCollapseReadChatReplayDuplicate(message) && signature) {
38164
38194
  replaySignaturesInCurrentTurn.add(signature);
38165
38195
  }
38196
+ if (isStableReadChatAssistantAnswer(message)) {
38197
+ stableAssistantAnswerInCurrentTurn = message;
38198
+ }
38166
38199
  }
38167
38200
  return collapsed;
38168
38201
  }
@@ -40900,6 +40933,12 @@ ${effect.notification.body || ""}`.trim();
40900
40933
  if (historyMessageCount !== null) {
40901
40934
  parsedMessages = historyMessageCount > 0 ? parsedMessages.slice(-historyMessageCount) : [];
40902
40935
  }
40936
+ const committedMessages = Array.isArray(adapterStatus.messages) ? adapterStatus.messages : [];
40937
+ const isActiveNonIdle = adapterStatus.status !== "idle";
40938
+ const shouldApplyCommittedFloor = parsedMessages.length < committedMessages.length && (adapterStatus.status === "waiting_approval" || isActiveNonIdle && historyMessageCount === null);
40939
+ if (shouldApplyCommittedFloor) {
40940
+ parsedMessages = normalizeChatMessages(committedMessages);
40941
+ }
40903
40942
  const mergedMessages = this.mergeConversationMessages(parsedMessages);
40904
40943
  const canonicalBackedHistory = this.syncCanonicalSavedHistoryIfNeeded();
40905
40944
  const dirName = this.workingDir.split("/").filter(Boolean).pop() || "session";
@@ -53977,8 +54016,8 @@ data: ${JSON.stringify(msg.data)}
53977
54016
  }
53978
54017
  try {
53979
54018
  await this.client.close();
53980
- } catch {
53981
- if (destroy) throw new Error(`Failed to close session host client: ${this.options.runtimeId}`);
54019
+ } catch (err) {
54020
+ if (destroy) throw err instanceof Error ? err : new Error(`Failed to close session host client: ${this.options.runtimeId}`);
53982
54021
  }
53983
54022
  }
53984
54023
  };