@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.js CHANGED
@@ -3972,8 +3972,10 @@ var init_provider_cli_adapter = __esm({
3972
3972
  if (buttonIndex in this.approvalKeys) {
3973
3973
  this.ptyProcess.write(this.approvalKeys[buttonIndex]);
3974
3974
  } else {
3975
+ const buttonCount = Array.isArray(modal?.buttons) ? modal.buttons.length : 0;
3976
+ const clampedIndex = buttonCount > 0 ? Math.min(Math.max(0, buttonIndex), buttonCount - 1) : Math.max(0, buttonIndex);
3975
3977
  const DOWN = "\x1B[B";
3976
- const keys = DOWN.repeat(Math.max(0, buttonIndex)) + "\r";
3978
+ const keys = DOWN.repeat(clampedIndex) + "\r";
3977
3979
  this.ptyProcess.write(keys);
3978
3980
  }
3979
3981
  }
@@ -10361,13 +10363,40 @@ function shouldCollapseReadChatReplayDuplicate(message) {
10361
10363
  const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
10362
10364
  return role === "assistant" || role === "system";
10363
10365
  }
10366
+ function normalizeReadChatReplayText(message) {
10367
+ return flattenContent(message?.content || "").replace(/\s+/g, " ").trim();
10368
+ }
10369
+ function isStableReadChatAssistantAnswer(message) {
10370
+ if (!message) return false;
10371
+ const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
10372
+ const kind = typeof message.kind === "string" ? message.kind.trim().toLowerCase() : "standard";
10373
+ if (role !== "assistant") return false;
10374
+ if (kind && kind !== "standard") return false;
10375
+ const content = normalizeReadChatReplayText(message);
10376
+ if (content.length < 160) return false;
10377
+ if (/^(bash|shell|terminal) command\b/i.test(content)) return false;
10378
+ return true;
10379
+ }
10380
+ function isReplayedAssistantAnswerAfterStableAnswer(message, stableAnswer) {
10381
+ if (!message || !stableAnswer) return false;
10382
+ const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
10383
+ const kind = typeof message.kind === "string" ? message.kind.trim().toLowerCase() : "standard";
10384
+ if (role !== "assistant") return false;
10385
+ if (kind && kind !== "standard") return false;
10386
+ const content = normalizeReadChatReplayText(message);
10387
+ const stableContent = normalizeReadChatReplayText(stableAnswer);
10388
+ if (content.length < 80 || stableContent.length < 80) return false;
10389
+ return content === stableContent || content.startsWith(stableContent) || stableContent.startsWith(content);
10390
+ }
10364
10391
  function collapseReplayDuplicatesFromReadChat(messages) {
10365
10392
  const collapsed = [];
10366
10393
  const replaySignaturesInCurrentTurn = /* @__PURE__ */ new Set();
10394
+ let stableAssistantAnswerInCurrentTurn = null;
10367
10395
  for (const message of messages) {
10368
10396
  const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
10369
10397
  if (role === "user") {
10370
10398
  replaySignaturesInCurrentTurn.clear();
10399
+ stableAssistantAnswerInCurrentTurn = null;
10371
10400
  }
10372
10401
  const signature = buildReadChatReplayCollapseSignature(message);
10373
10402
  const previous = collapsed[collapsed.length - 1];
@@ -10375,11 +10404,15 @@ function collapseReplayDuplicatesFromReadChat(messages) {
10375
10404
  if (shouldCollapseReadChatReplayDuplicate(message) && signature) {
10376
10405
  if (previousSignature === signature) continue;
10377
10406
  if (replaySignaturesInCurrentTurn.has(signature)) continue;
10407
+ if (isReplayedAssistantAnswerAfterStableAnswer(message, stableAssistantAnswerInCurrentTurn)) continue;
10378
10408
  }
10379
10409
  collapsed.push(message);
10380
10410
  if (shouldCollapseReadChatReplayDuplicate(message) && signature) {
10381
10411
  replaySignaturesInCurrentTurn.add(signature);
10382
10412
  }
10413
+ if (isStableReadChatAssistantAnswer(message)) {
10414
+ stableAssistantAnswerInCurrentTurn = message;
10415
+ }
10383
10416
  }
10384
10417
  return collapsed;
10385
10418
  }
@@ -13139,6 +13172,12 @@ var CliProviderInstance = class {
13139
13172
  if (historyMessageCount !== null) {
13140
13173
  parsedMessages = historyMessageCount > 0 ? parsedMessages.slice(-historyMessageCount) : [];
13141
13174
  }
13175
+ const committedMessages = Array.isArray(adapterStatus.messages) ? adapterStatus.messages : [];
13176
+ const isActiveNonIdle = adapterStatus.status !== "idle";
13177
+ const shouldApplyCommittedFloor = parsedMessages.length < committedMessages.length && (adapterStatus.status === "waiting_approval" || isActiveNonIdle && historyMessageCount === null);
13178
+ if (shouldApplyCommittedFloor) {
13179
+ parsedMessages = normalizeChatMessages(committedMessages);
13180
+ }
13142
13181
  const mergedMessages = this.mergeConversationMessages(parsedMessages);
13143
13182
  const canonicalBackedHistory = this.syncCanonicalSavedHistoryIfNeeded();
13144
13183
  const dirName = this.workingDir.split("/").filter(Boolean).pop() || "session";
@@ -26288,8 +26327,8 @@ var SessionHostRuntimeTransport = class {
26288
26327
  }
26289
26328
  try {
26290
26329
  await this.client.close();
26291
- } catch {
26292
- if (destroy) throw new Error(`Failed to close session host client: ${this.options.runtimeId}`);
26330
+ } catch (err) {
26331
+ if (destroy) throw err instanceof Error ? err : new Error(`Failed to close session host client: ${this.options.runtimeId}`);
26293
26332
  }
26294
26333
  }
26295
26334
  };