@adhdev/daemon-core 0.9.82-rc.176 → 0.9.82-rc.178

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
@@ -12715,6 +12715,12 @@ function createNativeHistoryDispatcher(reader) {
12715
12715
  const requestedProviderSid = input.providerSessionId || "";
12716
12716
  const sourcePath = resolveSourcePath(reader, workspace, sessionId);
12717
12717
  if (!sourcePath) return null;
12718
+ if (input.forceRefresh === true || input.args?.forceRefresh === true) {
12719
+ try {
12720
+ fs18.statSync(sourcePath);
12721
+ } catch {
12722
+ }
12723
+ }
12718
12724
  const session = readByReader(reader, sourcePath, sessionId, workspace);
12719
12725
  if (!session) return null;
12720
12726
  if (requestedProviderSid && session.providerSessionId && session.providerSessionId !== requestedProviderSid) {
@@ -19363,7 +19369,7 @@ function normalizeProviderNativeHistoryRecords(agentType, historySessionId, reco
19363
19369
  return sanitizeHistoryMessage(agentType, base);
19364
19370
  }).filter(Boolean);
19365
19371
  }
19366
- function callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, historySessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides) {
19372
+ function callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, historySessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides, forceRefresh) {
19367
19373
  const fn = getProviderNativeHistoryScript(scripts, canonicalHistory, "readSession");
19368
19374
  if (!fn) return null;
19369
19375
  const normalizedSessionId = normalizeSavedHistorySessionId(historySessionId || "");
@@ -19377,7 +19383,8 @@ function callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, his
19377
19383
  excludeInProgressTurn: excludeInProgressTurn === true,
19378
19384
  sessionStartedAtMs,
19379
19385
  envOverrides,
19380
- args: { sessionId: normalizedSessionId, historySessionId: normalizedSessionId, workspace, excludeInProgressTurn: excludeInProgressTurn === true, sessionStartedAtMs, envOverrides }
19386
+ forceRefresh: forceRefresh === true,
19387
+ args: { sessionId: normalizedSessionId, historySessionId: normalizedSessionId, workspace, excludeInProgressTurn: excludeInProgressTurn === true, sessionStartedAtMs, envOverrides, forceRefresh: forceRefresh === true }
19381
19388
  });
19382
19389
  if (!result || typeof result !== "object") return null;
19383
19390
  const records = normalizeProviderNativeHistoryRecords(agentType, normalizedSessionId, result.messages || result.records);
@@ -19392,11 +19399,11 @@ function callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, his
19392
19399
  unavailableReason: typeof result.unavailableReason === "string" ? result.unavailableReason.trim() : void 0
19393
19400
  };
19394
19401
  }
19395
- function buildNativeHistoryReadResult(agentType, canonicalHistory, scripts, historySessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides) {
19402
+ function buildNativeHistoryReadResult(agentType, canonicalHistory, scripts, historySessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides, forceRefresh) {
19396
19403
  const normalizedSessionId = normalizeSavedHistorySessionId(historySessionId || "");
19397
19404
  const normalizedWorkspace = typeof workspace === "string" ? workspace.trim() : "";
19398
19405
  if (!canonicalHistory || !normalizedSessionId && !normalizedWorkspace || !isNativeSourceCanonicalHistory(canonicalHistory)) return null;
19399
- return callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, normalizedSessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides);
19406
+ return callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, normalizedSessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides, forceRefresh);
19400
19407
  }
19401
19408
  function materializeNativeHistoryToMirror(agentType, canonicalHistory, historySessionId, workspace, scripts) {
19402
19409
  const normalizedSessionId = normalizeSavedHistorySessionId(historySessionId);
@@ -19425,7 +19432,7 @@ function isNativeSourceCanonicalHistory(canonicalHistory) {
19425
19432
  }
19426
19433
  function readProviderChatHistory(agentType, options = {}) {
19427
19434
  if (isNativeSourceCanonicalHistory(options.canonicalHistory) && (options.historySessionId || options.workspace)) {
19428
- const nativeResult = buildNativeHistoryReadResult(agentType, options.canonicalHistory, options.scripts, options.historySessionId, options.workspace, options.excludeInProgressTurn, options.sessionStartedAtMs, options.envOverrides);
19435
+ const nativeResult = buildNativeHistoryReadResult(agentType, options.canonicalHistory, options.scripts, options.historySessionId, options.workspace, options.excludeInProgressTurn, options.sessionStartedAtMs, options.envOverrides, options.forceRefresh);
19429
19436
  if (!nativeResult) return { messages: [], hasMore: false, source: "native-unavailable" };
19430
19437
  return {
19431
19438
  ...pageHistoryRecords(agentType, nativeResult.records, options.offset || 0, options.limit || 30, options.excludeRecentCount || 0, options.historyBehavior),
@@ -27852,7 +27859,7 @@ var SpecCliAdapter = class {
27852
27859
  activeInteractivePrompt: this.activeInteractivePrompt
27853
27860
  };
27854
27861
  }
27855
- if (/busy|generating|working|running|thinking/i.test(lc + " " + state.label)) {
27862
+ if (lc === "busy" || lc === "generating") {
27856
27863
  return { status: "generating", messages: [], activeModal: null, activeInteractivePrompt: this.activeInteractivePrompt };
27857
27864
  }
27858
27865
  return { status: "idle", messages: [], activeModal: null, activeInteractivePrompt: this.activeInteractivePrompt };
@@ -27986,13 +27993,37 @@ var SpecCliAdapter = class {
27986
27993
  return Promise.resolve({ ok: true, effects });
27987
27994
  }
27988
27995
  getDebugSnapshot() {
27996
+ let screen = "";
27997
+ let sections;
27998
+ try {
27999
+ screen = this.driver.snapshot();
28000
+ const lines = screen.split("\n");
28001
+ sections = {};
28002
+ for (const sec of this.spec.layout?.sections ?? []) {
28003
+ const from = sec.from_top;
28004
+ const fromBottom = sec.from_bottom;
28005
+ let start = 0;
28006
+ let end = lines.length;
28007
+ if (typeof from === "number") start = Math.max(0, from);
28008
+ else if (typeof fromBottom === "number") start = Math.max(0, lines.length - fromBottom);
28009
+ const until = sec.until;
28010
+ if (until && typeof until === "object" && typeof until.section === "string") {
28011
+ const ref = (this.spec.layout?.sections ?? []).find((s) => s.id === until.section);
28012
+ if (ref && typeof ref.from_bottom === "number") end = Math.max(start, lines.length - ref.from_bottom);
28013
+ }
28014
+ sections[sec.id] = lines.slice(start, end).join("\n");
28015
+ }
28016
+ } catch {
28017
+ }
27989
28018
  return {
27990
28019
  cliType: this.cliType,
27991
28020
  spec_id: this.spec.id,
27992
28021
  current_state: this.latestState,
27993
28022
  current_modal: this.latestModal,
27994
28023
  activeInteractivePrompt: this.activeInteractivePrompt,
27995
- exited: this.exited
28024
+ exited: this.exited,
28025
+ screen,
28026
+ sections
27996
28027
  };
27997
28028
  }
27998
28029
  getRuntimeMetadata() {
@@ -28758,6 +28789,7 @@ var CliProviderInstance = class {
28758
28789
  }
28759
28790
  completedDebounceTimer = null;
28760
28791
  completedDebouncePending = null;
28792
+ lastExternalCompletionProbe = null;
28761
28793
  async enforceFreshSessionLaunchIfNeeded() {
28762
28794
  const scriptName = getForcedNewSessionScriptName(this.provider, this.launchMode);
28763
28795
  if (!scriptName) return;
@@ -28790,11 +28822,44 @@ var CliProviderInstance = class {
28790
28822
  if (looksLikeActiveApprovalPromptText(content)) return false;
28791
28823
  return true;
28792
28824
  }
28825
+ buildExternalTranscriptProbe(messages, sourcePath, sourceMtimeMs) {
28826
+ const visibleMessages = messages.filter((message) => isUserFacingChatMessage(message));
28827
+ const lastVisible = visibleMessages[visibleMessages.length - 1];
28828
+ const readAt = Date.now();
28829
+ const mtimeMs = Number(sourceMtimeMs) || 0;
28830
+ return {
28831
+ readAt,
28832
+ msgCount: messages.length,
28833
+ lastRole: typeof lastVisible?.role === "string" ? lastVisible.role.trim().toLowerCase() : null,
28834
+ lastKind: typeof lastVisible?.kind === "string" ? lastVisible.kind : null,
28835
+ contentLen: lastVisible ? flattenContent(lastVisible.content).trim().length : 0,
28836
+ sourcePath: typeof sourcePath === "string" && sourcePath ? sourcePath : null,
28837
+ sourceMtimeMs: mtimeMs || null,
28838
+ mtimeAgeMs: mtimeMs ? Math.max(0, readAt - mtimeMs) : null
28839
+ };
28840
+ }
28841
+ recordPendingTranscriptProbe(pending) {
28842
+ const probe = this.lastExternalCompletionProbe;
28843
+ if (!probe) return null;
28844
+ const history = pending.transcriptProbeHistory || [];
28845
+ const last = history[history.length - 1];
28846
+ if (!last || last.readAt !== probe.readAt || last.msgCount !== probe.msgCount || last.lastRole !== probe.lastRole || last.contentLen !== probe.contentLen) {
28847
+ history.push(probe);
28848
+ pending.transcriptProbeHistory = history.slice(-5);
28849
+ }
28850
+ return probe;
28851
+ }
28793
28852
  readExternalCompletionMessages() {
28794
28853
  const adapterOwnsMessagesElsewhere = this.adapter?.chatMessagesOwnedExternally === true;
28795
28854
  if (!adapterOwnsMessagesElsewhere) return null;
28796
28855
  if (!this.providerSessionId) return null;
28797
28856
  if (!isNativeSourceCanonicalHistory(this.provider.nativeHistory)) return null;
28857
+ if (this.lastExternalCompletionProbe?.sourcePath) {
28858
+ try {
28859
+ fs12.statSync(this.lastExternalCompletionProbe.sourcePath);
28860
+ } catch {
28861
+ }
28862
+ }
28798
28863
  const restoredHistory = readProviderChatHistory(this.type, {
28799
28864
  canonicalHistory: this.provider.nativeHistory,
28800
28865
  historySessionId: this.providerSessionId,
@@ -28803,9 +28868,18 @@ var CliProviderInstance = class {
28803
28868
  limit: Number.MAX_SAFE_INTEGER,
28804
28869
  historyBehavior: this.provider.historyBehavior,
28805
28870
  scripts: this.provider.scripts,
28806
- sessionStartedAtMs: this.startedAt
28871
+ sessionStartedAtMs: this.startedAt,
28872
+ forceRefresh: true
28807
28873
  });
28808
- if (restoredHistory.source !== "provider-native") return null;
28874
+ if (restoredHistory.source !== "provider-native") {
28875
+ this.lastExternalCompletionProbe = null;
28876
+ return null;
28877
+ }
28878
+ this.lastExternalCompletionProbe = this.buildExternalTranscriptProbe(
28879
+ restoredHistory.messages,
28880
+ restoredHistory.sourcePath,
28881
+ restoredHistory.sourceMtimeMs
28882
+ );
28809
28883
  return restoredHistory.messages;
28810
28884
  }
28811
28885
  completionFinalAssistantEvidence(parsedMessages) {
@@ -28843,6 +28917,9 @@ var CliProviderInstance = class {
28843
28917
  parseError = error?.message || String(error);
28844
28918
  }
28845
28919
  const evidence = this.completionFinalAssistantEvidence(parsed?.messages);
28920
+ if (evidence.source === "external-native") {
28921
+ this.recordPendingTranscriptProbe(args.pending);
28922
+ }
28846
28923
  const visibleMessages = (Array.isArray(evidence.messages) ? evidence.messages : []).filter((message) => isUserFacingChatMessage(message));
28847
28924
  const lastVisible = visibleMessages[visibleMessages.length - 1];
28848
28925
  const lastVisibleRole = typeof lastVisible?.role === "string" ? lastVisible.role.trim().toLowerCase() : null;
@@ -28871,7 +28948,8 @@ var CliProviderInstance = class {
28871
28948
  pendingFirstObservedAt: args.pending.firstObservedAt,
28872
28949
  pendingTimestamp: args.pending.timestamp,
28873
28950
  pendingDurationSec: args.pending.duration,
28874
- previousBlockReason: args.pending.loggedBlockReason || null
28951
+ previousBlockReason: args.pending.loggedBlockReason || null,
28952
+ transcriptProbeHistory: args.pending.transcriptProbeHistory || []
28875
28953
  };
28876
28954
  }
28877
28955
  hasAdapterPendingResponse() {
@@ -28929,6 +29007,11 @@ var CliProviderInstance = class {
28929
29007
  if (!finalAssistantEvidence.present) {
28930
29008
  if (adapterOwnsMessagesElsewhere) {
28931
29009
  if (finalAssistantEvidence.source === "external-native") {
29010
+ const probe = this.recordPendingTranscriptProbe(pending);
29011
+ if (probe && !pending.loggedTranscriptProbe) {
29012
+ LOG.info("CLI", `[${this.type}] external transcript probe: msgCount=${probe.msgCount} lastRole=${probe.lastRole || "none"} lastKind=${probe.lastKind || "none"} contentLen=${probe.contentLen} sourceMtime=${probe.sourceMtimeMs ?? "unknown"} mtimeAge=${probe.mtimeAgeMs ?? "unknown"}ms`);
29013
+ pending.loggedTranscriptProbe = true;
29014
+ }
28932
29015
  return { reason: "missing_final_assistant", terminal: true };
28933
29016
  }
28934
29017
  if (this.provider.requiresFinalAssistantBeforeIdle === true) {