@adhdev/daemon-core 0.9.82-rc.267 → 0.9.82-rc.268

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
@@ -265,10 +265,10 @@ function readInjected(value) {
265
265
  }
266
266
  function getDaemonBuildInfo() {
267
267
  if (cached) return cached;
268
- const commit = readInjected(true ? "bf805cc2b4d63e722d2e330fa10a9890db3b4668" : void 0) ?? "unknown";
269
- const commitShort = readInjected(true ? "bf805cc2" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
270
- const version = readInjected(true ? "0.9.82-rc.267" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
271
- const builtAt = readInjected(true ? "2026-06-14T20:01:43.506Z" : void 0);
268
+ const commit = readInjected(true ? "9da2b92afe11e5b813734c9f389479542e25a41f" : void 0) ?? "unknown";
269
+ const commitShort = readInjected(true ? "9da2b92a" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
270
+ const version = readInjected(true ? "0.9.82-rc.268" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
271
+ const builtAt = readInjected(true ? "2026-06-14T21:47:03.827Z" : void 0);
272
272
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
273
273
  return cached;
274
274
  }
@@ -15056,11 +15056,22 @@ function buildClaudeInteractiveTuiAnswerSteps(prompt, response) {
15056
15056
  if (response.promptId !== prompt.promptId) throw new Error("Interactive prompt response does not match active prompt");
15057
15057
  const steps = [];
15058
15058
  for (const question of prompt.questions) {
15059
- if (question.multiSelect) throw new Error("Claude TUI multi-select prompts are not supported yet");
15060
15059
  const answer = response.answers[question.questionId];
15061
15060
  if (!answer) throw new Error(`Missing answer for ${question.questionId}`);
15062
15061
  const freeformText = answer.freeformText?.trim() ?? "";
15063
- if (freeformText) {
15062
+ if (question.multiSelect) {
15063
+ const labels = answer.selectedLabels;
15064
+ if (labels.length === 0) {
15065
+ throw new Error(`Expected at least one selected label for ${question.questionId}`);
15066
+ }
15067
+ for (const label of labels) {
15068
+ const selectedIndex = question.options.findIndex((option) => option.label === label);
15069
+ if (selectedIndex < 0) throw new Error(`Unknown option for ${question.questionId}: ${label}`);
15070
+ steps.push(String(selectedIndex + 1));
15071
+ steps.push(" ");
15072
+ }
15073
+ steps.push("\r");
15074
+ } else if (freeformText) {
15064
15075
  const typeOptionIndex = question.options.findIndex((o) => /^Type something\.?$/i.test(o.label));
15065
15076
  const optionNumber = typeOptionIndex >= 0 ? typeOptionIndex + 1 : question.options.length;
15066
15077
  steps.push(String(optionNumber));
@@ -20237,6 +20248,24 @@ var savedHistorySessionCache = /* @__PURE__ */ new Map();
20237
20248
  var savedHistoryFileSummaryCache = /* @__PURE__ */ new Map();
20238
20249
  var savedHistoryBackgroundRefresh = /* @__PURE__ */ new Set();
20239
20250
  var savedHistoryRollupInFlight = /* @__PURE__ */ new Set();
20251
+ var BOUNDED_TAIL_CACHE_MAX_ENTRIES = 64;
20252
+ var boundedTailReadCache = /* @__PURE__ */ new Map();
20253
+ function readBoundedTailCache(key, signature) {
20254
+ const cached2 = boundedTailReadCache.get(key);
20255
+ if (!cached2 || cached2.signature !== signature) return null;
20256
+ boundedTailReadCache.delete(key);
20257
+ boundedTailReadCache.set(key, cached2);
20258
+ return cached2.result;
20259
+ }
20260
+ function writeBoundedTailCache(key, signature, result) {
20261
+ boundedTailReadCache.delete(key);
20262
+ boundedTailReadCache.set(key, { signature, result });
20263
+ while (boundedTailReadCache.size > BOUNDED_TAIL_CACHE_MAX_ENTRIES) {
20264
+ const oldest = boundedTailReadCache.keys().next().value;
20265
+ if (oldest === void 0) break;
20266
+ boundedTailReadCache.delete(oldest);
20267
+ }
20268
+ }
20240
20269
  function normalizeHistoryComparable(text) {
20241
20270
  return String(text || "").replace(/\s+/g, " ").trim();
20242
20271
  }
@@ -21121,12 +21150,73 @@ function pageHistoryRecords(agentType, records, offset = 0, limit = 30, excludeR
21121
21150
  const sliced = collapsed.slice(startInclusive, endExclusive);
21122
21151
  return { messages: sliced, hasMore: startInclusive > 0 };
21123
21152
  }
21153
+ var BOUNDED_TAIL_MAX_LIMIT = 5e3;
21154
+ var BOUNDED_TAIL_SLACK = 50;
21155
+ function isBoundedTailRequest(limit, offset, excludeRecentCount) {
21156
+ const numericLimit = Number(limit);
21157
+ if (!Number.isFinite(numericLimit) || numericLimit <= 0) return false;
21158
+ if (numericLimit > BOUNDED_TAIL_MAX_LIMIT) return false;
21159
+ const numericOffset = Number(offset);
21160
+ const numericExclude = Number(excludeRecentCount);
21161
+ if (!Number.isFinite(numericOffset) || !Number.isFinite(numericExclude)) return false;
21162
+ return true;
21163
+ }
21164
+ function readBoundedTailRecords(agentType, dir, files, needed) {
21165
+ const collected = [];
21166
+ const seen = /* @__PURE__ */ new Set();
21167
+ let readAllFiles = true;
21168
+ for (let f = 0; f < files.length; f++) {
21169
+ const filePath = path12.join(dir, files[f]);
21170
+ let content;
21171
+ try {
21172
+ content = fs5.readFileSync(filePath, "utf-8");
21173
+ } catch {
21174
+ continue;
21175
+ }
21176
+ const lines = content.trim().split("\n").filter(Boolean);
21177
+ for (let i = lines.length - 1; i >= 0; i--) {
21178
+ try {
21179
+ const parsed = JSON.parse(lines[i]);
21180
+ const sanitizedMessage = sanitizeHistoryMessage(agentType, parsed);
21181
+ if (!sanitizedMessage) continue;
21182
+ const hash = buildHistoryMessageHash(agentType, sanitizedMessage);
21183
+ if (seen.has(hash)) continue;
21184
+ seen.add(hash);
21185
+ collected.push(sanitizedMessage);
21186
+ } catch {
21187
+ }
21188
+ }
21189
+ if (collected.length >= needed && f < files.length - 1) {
21190
+ readAllFiles = false;
21191
+ break;
21192
+ }
21193
+ }
21194
+ collected.reverse();
21195
+ return { records: collected, readAllFiles };
21196
+ }
21124
21197
  function readChatHistory(agentType, offset = 0, limit = 30, historySessionId, excludeRecentCount = 0, historyBehavior) {
21125
21198
  try {
21126
21199
  const sanitized = agentType.replace(/[^a-zA-Z0-9_-]/g, "_");
21127
21200
  const dir = path12.join(HISTORY_DIR, sanitized);
21128
21201
  if (!fs5.existsSync(dir)) return { messages: [], hasMore: false };
21129
21202
  const files = listHistoryFiles(dir, historySessionId);
21203
+ const bounded = isBoundedTailRequest(limit, offset, excludeRecentCount);
21204
+ if (bounded) {
21205
+ const fileSignatures = buildSavedHistoryFileSignatureMap(dir, files);
21206
+ const cacheKey = `${sanitized}\0${historySessionId || ""}\0${offset}\0${limit}\0${excludeRecentCount}\0${historyBehavior?.collapseConsecutiveAssistantTurns ? "1" : "0"}`;
21207
+ const signature = buildSavedHistoryCacheSignature(files, fileSignatures);
21208
+ const cached2 = readBoundedTailCache(cacheKey, signature);
21209
+ if (cached2) return cached2;
21210
+ const numericLimit = Math.max(1, Number(limit));
21211
+ const numericOffset = Math.max(0, Number(offset));
21212
+ const numericExclude = Math.max(0, Number(excludeRecentCount));
21213
+ const needed = numericLimit + numericOffset + numericExclude + Math.max(BOUNDED_TAIL_SLACK, numericLimit);
21214
+ const { records, readAllFiles } = readBoundedTailRecords(agentType, dir, files, needed);
21215
+ const result = pageHistoryRecords(agentType, records, offset, limit, excludeRecentCount, historyBehavior);
21216
+ const boundedResult = readAllFiles ? result : { messages: result.messages, hasMore: true };
21217
+ writeBoundedTailCache(cacheKey, signature, boundedResult);
21218
+ return boundedResult;
21219
+ }
21130
21220
  const allMessages = [];
21131
21221
  const seen = /* @__PURE__ */ new Set();
21132
21222
  for (const file of files) {
@@ -24336,6 +24426,7 @@ var CHAT_SOURCE_REGISTRY = new ChatSourceRegistry();
24336
24426
  // src/commands/chat-commands.ts
24337
24427
  var RECENT_SEND_WINDOW_MS = 1200;
24338
24428
  var READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS = 25e3;
24429
+ var HOT_TAIL_MIN_LIMIT = 60;
24339
24430
  var HERMES_CLI_STARTING_SEND_SETTLE_MS = 2e3;
24340
24431
  var CLI_NATIVE_TRANSCRIPT_PROVIDERS = /* @__PURE__ */ new Set(["codex-cli", "claude-cli", "hermes-cli", "antigravity-cli"]);
24341
24432
  var warnedLegacyNativeAllowlistHits = /* @__PURE__ */ new Set();
@@ -24878,7 +24969,7 @@ function readExactRuntimeMirrorMessages(args) {
24878
24969
  const history = readChatHistory(
24879
24970
  args.providerType,
24880
24971
  0,
24881
- Math.max(args.tailLimit || 0, 200),
24972
+ Math.max(args.tailLimit || 0, HOT_TAIL_MIN_LIMIT),
24882
24973
  targetSessionId,
24883
24974
  0,
24884
24975
  args.historyBehavior
@@ -25771,7 +25862,7 @@ async function handleReadChat(h, args) {
25771
25862
  const nativeHistoryLimit = Math.max(
25772
25863
  normalizeReadChatTailLimit(args) || 0,
25773
25864
  returnedMessages.length,
25774
- 200
25865
+ HOT_TAIL_MIN_LIMIT
25775
25866
  );
25776
25867
  const nativeHistorySessionId = supportsNative ? resolveCliNativeHistorySessionId(args, historySessionId, providerSessionId) : void 0;
25777
25868
  const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";