@adhdev/daemon-core 0.9.51 → 0.9.53

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
@@ -8135,6 +8135,10 @@ var ChatHistoryWriter = class {
8135
8135
  return name.replace(/[^a-zA-Z0-9_-]/g, "_");
8136
8136
  }
8137
8137
  };
8138
+ function normalizePaginationNumber(value, fallback, min) {
8139
+ const numeric = Number(value);
8140
+ return Number.isFinite(numeric) ? Math.max(min, numeric) : fallback;
8141
+ }
8138
8142
  function pageHistoryRecords(agentType, records, offset = 0, limit = 30, excludeRecentCount = 0, historyBehavior) {
8139
8143
  const allMessages = records.map((message) => sanitizeHistoryMessage(agentType, message)).filter(Boolean);
8140
8144
  allMessages.sort((a, b) => a.receivedAt - b.receivedAt);
@@ -8148,9 +8152,12 @@ function pageHistoryRecords(agentType, records, offset = 0, limit = 30, excludeR
8148
8152
  if (message.role !== "system") lastTurn = message;
8149
8153
  }
8150
8154
  const collapsed = collapseReplayAssistantTurns(chronological, historyBehavior);
8151
- const boundedLimit = Math.max(1, limit);
8152
- const boundedOffset = Math.max(0, offset);
8153
- const boundedExclude = Math.max(0, Math.min(excludeRecentCount, collapsed.length));
8155
+ const boundedLimit = normalizePaginationNumber(limit, 30, 1);
8156
+ const boundedOffset = normalizePaginationNumber(offset, 0, 0);
8157
+ const boundedExclude = Math.min(
8158
+ normalizePaginationNumber(excludeRecentCount, 0, 0),
8159
+ collapsed.length
8160
+ );
8154
8161
  const endExclusive = Math.max(0, collapsed.length - boundedExclude - boundedOffset);
8155
8162
  const startInclusive = Math.max(0, endExclusive - boundedLimit);
8156
8163
  const sliced = collapsed.slice(startInclusive, endExclusive);
@@ -11363,6 +11370,28 @@ function getStateLastSignature(state) {
11363
11370
  if (!last) return "";
11364
11371
  return `${last.role || ""}:${String(last.content || "").replace(/\s+/g, " ").trim()}`;
11365
11372
  }
11373
+ function toNonNegativeNumber(value) {
11374
+ const numeric = Number(value ?? 0);
11375
+ return Number.isFinite(numeric) ? Math.max(0, numeric) : 0;
11376
+ }
11377
+ function getCliVisibleTranscriptCount(adapter) {
11378
+ const adapterStatus = adapter?.getStatus?.() || {};
11379
+ const adapterMessages = Array.isArray(adapterStatus.messages) ? adapterStatus.messages : [];
11380
+ let parsedRecord = null;
11381
+ if (typeof adapter?.getScriptParsedStatus === "function") {
11382
+ try {
11383
+ const parsed = parseMaybeJson(adapter.getScriptParsedStatus());
11384
+ parsedRecord = parsed && typeof parsed === "object" ? parsed : null;
11385
+ } catch {
11386
+ parsedRecord = null;
11387
+ }
11388
+ }
11389
+ const parsedMessages = Array.isArray(parsedRecord?.messages) ? parsedRecord.messages : [];
11390
+ if (!parsedRecord) return adapterMessages.length;
11391
+ const parsedIsProviderAuthoritative = parsedRecord.transcriptAuthority === "provider" || parsedRecord.coverage === "full";
11392
+ const shouldPreferAdapterMessages = !parsedIsProviderAuthoritative && adapterMessages.length > 0 && adapterMessages.length > parsedMessages.length;
11393
+ return shouldPreferAdapterMessages ? adapterMessages.length : parsedMessages.length;
11394
+ }
11366
11395
  async function getStableExtensionBaseline(h) {
11367
11396
  const first = await readExtensionChatState(h);
11368
11397
  if (getStateMessageCount(first) > 0 || getStateLastSignature(first)) return first;
@@ -11391,11 +11420,11 @@ async function handleChatHistory(h, args) {
11391
11420
  const provider = h.getProvider(agentType);
11392
11421
  const agentStr = provider?.type || agentType || getCurrentProviderType(h);
11393
11422
  const transport = getTargetTransport(h, provider);
11394
- let excludeRecentCount = Math.max(0, Number(args?.excludeRecentCount || 0));
11395
- if (isCliLikeTransport(transport)) {
11423
+ const hasExplicitExcludeRecentCount = args?.excludeRecentCount !== void 0 && args?.excludeRecentCount !== null;
11424
+ let excludeRecentCount = toNonNegativeNumber(args?.excludeRecentCount);
11425
+ if (!hasExplicitExcludeRecentCount && isCliLikeTransport(transport)) {
11396
11426
  const adapter = getTargetedCliAdapter(h, args, provider?.type);
11397
- const status = adapter?.getStatus?.();
11398
- const visibleCount = Array.isArray(status?.messages) ? status.messages.length : 0;
11427
+ const visibleCount = getCliVisibleTranscriptCount(adapter);
11399
11428
  if (visibleCount > excludeRecentCount) excludeRecentCount = visibleCount;
11400
11429
  }
11401
11430
  const workspace = typeof args?.workspace === "string" ? args.workspace : typeof h.currentSession?.workspace === "string" ? h.currentSession.workspace : void 0;
@@ -12873,12 +12902,13 @@ async function handleSetProviderSourceConfig(h, args) {
12873
12902
  });
12874
12903
  loader.reload();
12875
12904
  loader.registerToDetector();
12905
+ const refreshedInstances = h.ctx.instanceManager ? h.ctx.instanceManager.refreshProviderDefinitions((providerType) => loader.resolve(providerType)) : 0;
12876
12906
  await h.ctx.onProviderSourceConfigChanged?.();
12877
12907
  LOG.info(
12878
12908
  "Command",
12879
12909
  `[set_provider_source_config] mode=${sourceConfig.sourceMode} explicitProviderDir=${sourceConfig.explicitProviderDir || "-"} userDir=${sourceConfig.userDir}`
12880
12910
  );
12881
- return { success: true, reloaded: true, ...sourceConfig };
12911
+ return { success: true, reloaded: true, refreshedInstances, ...sourceConfig };
12882
12912
  }
12883
12913
  function normalizeProviderScriptArgs(args, scriptName) {
12884
12914
  const normalizedArgs = { ...args || {} };