@adhdev/daemon-core 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.mjs CHANGED
@@ -3969,8 +3969,10 @@ var init_provider_cli_adapter = __esm({
3969
3969
  if (buttonIndex in this.approvalKeys) {
3970
3970
  this.ptyProcess.write(this.approvalKeys[buttonIndex]);
3971
3971
  } else {
3972
+ const buttonCount = Array.isArray(modal?.buttons) ? modal.buttons.length : 0;
3973
+ const clampedIndex = buttonCount > 0 ? Math.min(Math.max(0, buttonIndex), buttonCount - 1) : Math.max(0, buttonIndex);
3972
3974
  const DOWN = "\x1B[B";
3973
- const keys = DOWN.repeat(Math.max(0, buttonIndex)) + "\r";
3975
+ const keys = DOWN.repeat(clampedIndex) + "\r";
3974
3976
  this.ptyProcess.write(keys);
3975
3977
  }
3976
3978
  }
@@ -10208,13 +10210,40 @@ function shouldCollapseReadChatReplayDuplicate(message) {
10208
10210
  const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
10209
10211
  return role === "assistant" || role === "system";
10210
10212
  }
10213
+ function normalizeReadChatReplayText(message) {
10214
+ return flattenContent(message?.content || "").replace(/\s+/g, " ").trim();
10215
+ }
10216
+ function isStableReadChatAssistantAnswer(message) {
10217
+ if (!message) return false;
10218
+ const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
10219
+ const kind = typeof message.kind === "string" ? message.kind.trim().toLowerCase() : "standard";
10220
+ if (role !== "assistant") return false;
10221
+ if (kind && kind !== "standard") return false;
10222
+ const content = normalizeReadChatReplayText(message);
10223
+ if (content.length < 160) return false;
10224
+ if (/^(bash|shell|terminal) command\b/i.test(content)) return false;
10225
+ return true;
10226
+ }
10227
+ function isReplayedAssistantAnswerAfterStableAnswer(message, stableAnswer) {
10228
+ if (!message || !stableAnswer) return false;
10229
+ const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
10230
+ const kind = typeof message.kind === "string" ? message.kind.trim().toLowerCase() : "standard";
10231
+ if (role !== "assistant") return false;
10232
+ if (kind && kind !== "standard") return false;
10233
+ const content = normalizeReadChatReplayText(message);
10234
+ const stableContent = normalizeReadChatReplayText(stableAnswer);
10235
+ if (content.length < 80 || stableContent.length < 80) return false;
10236
+ return content === stableContent || content.startsWith(stableContent) || stableContent.startsWith(content);
10237
+ }
10211
10238
  function collapseReplayDuplicatesFromReadChat(messages) {
10212
10239
  const collapsed = [];
10213
10240
  const replaySignaturesInCurrentTurn = /* @__PURE__ */ new Set();
10241
+ let stableAssistantAnswerInCurrentTurn = null;
10214
10242
  for (const message of messages) {
10215
10243
  const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
10216
10244
  if (role === "user") {
10217
10245
  replaySignaturesInCurrentTurn.clear();
10246
+ stableAssistantAnswerInCurrentTurn = null;
10218
10247
  }
10219
10248
  const signature = buildReadChatReplayCollapseSignature(message);
10220
10249
  const previous = collapsed[collapsed.length - 1];
@@ -10222,11 +10251,15 @@ function collapseReplayDuplicatesFromReadChat(messages) {
10222
10251
  if (shouldCollapseReadChatReplayDuplicate(message) && signature) {
10223
10252
  if (previousSignature === signature) continue;
10224
10253
  if (replaySignaturesInCurrentTurn.has(signature)) continue;
10254
+ if (isReplayedAssistantAnswerAfterStableAnswer(message, stableAssistantAnswerInCurrentTurn)) continue;
10225
10255
  }
10226
10256
  collapsed.push(message);
10227
10257
  if (shouldCollapseReadChatReplayDuplicate(message) && signature) {
10228
10258
  replaySignaturesInCurrentTurn.add(signature);
10229
10259
  }
10260
+ if (isStableReadChatAssistantAnswer(message)) {
10261
+ stableAssistantAnswerInCurrentTurn = message;
10262
+ }
10230
10263
  }
10231
10264
  return collapsed;
10232
10265
  }
@@ -12986,6 +13019,12 @@ var CliProviderInstance = class {
12986
13019
  if (historyMessageCount !== null) {
12987
13020
  parsedMessages = historyMessageCount > 0 ? parsedMessages.slice(-historyMessageCount) : [];
12988
13021
  }
13022
+ const committedMessages = Array.isArray(adapterStatus.messages) ? adapterStatus.messages : [];
13023
+ const isActiveNonIdle = adapterStatus.status !== "idle";
13024
+ const shouldApplyCommittedFloor = parsedMessages.length < committedMessages.length && (adapterStatus.status === "waiting_approval" || isActiveNonIdle && historyMessageCount === null);
13025
+ if (shouldApplyCommittedFloor) {
13026
+ parsedMessages = normalizeChatMessages(committedMessages);
13027
+ }
12989
13028
  const mergedMessages = this.mergeConversationMessages(parsedMessages);
12990
13029
  const canonicalBackedHistory = this.syncCanonicalSavedHistoryIfNeeded();
12991
13030
  const dirName = this.workingDir.split("/").filter(Boolean).pop() || "session";
@@ -26142,8 +26181,8 @@ var SessionHostRuntimeTransport = class {
26142
26181
  }
26143
26182
  try {
26144
26183
  await this.client.close();
26145
- } catch {
26146
- if (destroy) throw new Error(`Failed to close session host client: ${this.options.runtimeId}`);
26184
+ } catch (err) {
26185
+ if (destroy) throw err instanceof Error ? err : new Error(`Failed to close session host client: ${this.options.runtimeId}`);
26147
26186
  }
26148
26187
  }
26149
26188
  };