@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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adhdev/session-host-core",
3
- "version": "0.9.51",
3
+ "version": "0.9.53",
4
4
  "description": "ADHDev local session host core \u2014 session registry, protocol, buffers",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adhdev/daemon-core",
3
- "version": "0.9.51",
3
+ "version": "0.9.53",
4
4
  "description": "ADHDev daemon core \u2014 CDP, IDE detection, providers, command execution",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -869,6 +869,33 @@ function getStateLastSignature(state: any): string {
869
869
  return `${last.role || ''}:${String(last.content || '').replace(/\s+/g, ' ').trim()}`;
870
870
  }
871
871
 
872
+ function toNonNegativeNumber(value: any): number {
873
+ const numeric = Number(value ?? 0);
874
+ return Number.isFinite(numeric) ? Math.max(0, numeric) : 0;
875
+ }
876
+
877
+ function getCliVisibleTranscriptCount(adapter: any): number {
878
+ const adapterStatus = adapter?.getStatus?.() || {};
879
+ const adapterMessages = Array.isArray(adapterStatus.messages) ? adapterStatus.messages : [];
880
+ let parsedRecord: Record<string, any> | null = null;
881
+ if (typeof adapter?.getScriptParsedStatus === 'function') {
882
+ try {
883
+ const parsed = parseMaybeJson(adapter.getScriptParsedStatus());
884
+ parsedRecord = parsed && typeof parsed === 'object' ? parsed as Record<string, any> : null;
885
+ } catch {
886
+ parsedRecord = null;
887
+ }
888
+ }
889
+ const parsedMessages = Array.isArray(parsedRecord?.messages) ? parsedRecord.messages : [];
890
+ if (!parsedRecord) return adapterMessages.length;
891
+ const parsedIsProviderAuthoritative = parsedRecord.transcriptAuthority === 'provider'
892
+ || parsedRecord.coverage === 'full';
893
+ const shouldPreferAdapterMessages = !parsedIsProviderAuthoritative
894
+ && adapterMessages.length > 0
895
+ && adapterMessages.length > parsedMessages.length;
896
+ return shouldPreferAdapterMessages ? adapterMessages.length : parsedMessages.length;
897
+ }
898
+
872
899
  async function getStableExtensionBaseline(h: CommandHelpers): Promise<any | null> {
873
900
  const first = await readExtensionChatState(h);
874
901
  if (getStateMessageCount(first) > 0 || getStateLastSignature(first)) return first;
@@ -899,11 +926,11 @@ export async function handleChatHistory(h: CommandHelpers, args: any): Promise<C
899
926
  const provider = h.getProvider(agentType);
900
927
  const agentStr = provider?.type || agentType || getCurrentProviderType(h);
901
928
  const transport = getTargetTransport(h, provider);
902
- let excludeRecentCount = Math.max(0, Number(args?.excludeRecentCount || 0));
903
- if (isCliLikeTransport(transport)) {
929
+ const hasExplicitExcludeRecentCount = args?.excludeRecentCount !== undefined && args?.excludeRecentCount !== null;
930
+ let excludeRecentCount = toNonNegativeNumber(args?.excludeRecentCount);
931
+ if (!hasExplicitExcludeRecentCount && isCliLikeTransport(transport)) {
904
932
  const adapter = getTargetedCliAdapter(h, args, provider?.type);
905
- const status = adapter?.getStatus?.();
906
- const visibleCount = Array.isArray(status?.messages) ? status.messages.length : 0;
933
+ const visibleCount = getCliVisibleTranscriptCount(adapter);
907
934
  if (visibleCount > excludeRecentCount) excludeRecentCount = visibleCount;
908
935
  }
909
936
  const workspace = typeof args?.workspace === 'string'
@@ -193,6 +193,9 @@ export async function handleSetProviderSourceConfig(h: CommandHelpers, args: any
193
193
  });
194
194
  loader.reload();
195
195
  loader.registerToDetector();
196
+ const refreshedInstances = h.ctx.instanceManager
197
+ ? h.ctx.instanceManager.refreshProviderDefinitions((providerType) => loader.resolve(providerType))
198
+ : 0;
196
199
  await h.ctx.onProviderSourceConfigChanged?.();
197
200
 
198
201
  LOG.info(
@@ -200,7 +203,7 @@ export async function handleSetProviderSourceConfig(h: CommandHelpers, args: any
200
203
  `[set_provider_source_config] mode=${sourceConfig.sourceMode} explicitProviderDir=${sourceConfig.explicitProviderDir || '-'} userDir=${sourceConfig.userDir}`,
201
204
  );
202
205
 
203
- return { success: true, reloaded: true, ...sourceConfig };
206
+ return { success: true, reloaded: true, refreshedInstances, ...sourceConfig };
204
207
  }
205
208
 
206
209
  // ─── Extension Script Execution (Model/Mode) ─────
@@ -1141,6 +1141,11 @@ export class ChatHistoryWriter {
1141
1141
  * the newest N messages are skipped so older-history pagination can avoid
1142
1142
  * duplicating the live transcript tail already shown in the UI.
1143
1143
  */
1144
+ function normalizePaginationNumber(value: number, fallback: number, min: number): number {
1145
+ const numeric = Number(value);
1146
+ return Number.isFinite(numeric) ? Math.max(min, numeric) : fallback;
1147
+ }
1148
+
1144
1149
  function pageHistoryRecords(
1145
1150
  agentType: string,
1146
1151
  records: HistoryMessage[],
@@ -1163,9 +1168,12 @@ function pageHistoryRecords(
1163
1168
  if (message.role !== 'system') lastTurn = message;
1164
1169
  }
1165
1170
  const collapsed = collapseReplayAssistantTurns(chronological, historyBehavior);
1166
- const boundedLimit = Math.max(1, limit);
1167
- const boundedOffset = Math.max(0, offset);
1168
- const boundedExclude = Math.max(0, Math.min(excludeRecentCount, collapsed.length));
1171
+ const boundedLimit = normalizePaginationNumber(limit, 30, 1);
1172
+ const boundedOffset = normalizePaginationNumber(offset, 0, 0);
1173
+ const boundedExclude = Math.min(
1174
+ normalizePaginationNumber(excludeRecentCount, 0, 0),
1175
+ collapsed.length,
1176
+ );
1169
1177
  const endExclusive = Math.max(0, collapsed.length - boundedExclude - boundedOffset);
1170
1178
  const startInclusive = Math.max(0, endExclusive - boundedLimit);
1171
1179
  const sliced = collapsed.slice(startInclusive, endExclusive);