@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.
@@ -113,6 +113,7 @@ export declare function readProviderChatHistory(agentType: string, options?: {
113
113
  excludeInProgressTurn?: boolean;
114
114
  sessionStartedAtMs?: number;
115
115
  envOverrides?: Record<string, string>;
116
+ forceRefresh?: boolean;
116
117
  }): {
117
118
  messages: HistoryMessage[];
118
119
  hasMore: boolean;
package/dist/index.js CHANGED
@@ -12719,6 +12719,12 @@ function createNativeHistoryDispatcher(reader) {
12719
12719
  const requestedProviderSid = input.providerSessionId || "";
12720
12720
  const sourcePath = resolveSourcePath(reader, workspace, sessionId);
12721
12721
  if (!sourcePath) return null;
12722
+ if (input.forceRefresh === true || input.args?.forceRefresh === true) {
12723
+ try {
12724
+ fs18.statSync(sourcePath);
12725
+ } catch {
12726
+ }
12727
+ }
12722
12728
  const session = readByReader(reader, sourcePath, sessionId, workspace);
12723
12729
  if (!session) return null;
12724
12730
  if (requestedProviderSid && session.providerSessionId && session.providerSessionId !== requestedProviderSid) {
@@ -19673,7 +19679,7 @@ function normalizeProviderNativeHistoryRecords(agentType, historySessionId, reco
19673
19679
  return sanitizeHistoryMessage(agentType, base);
19674
19680
  }).filter(Boolean);
19675
19681
  }
19676
- function callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, historySessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides) {
19682
+ function callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, historySessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides, forceRefresh) {
19677
19683
  const fn = getProviderNativeHistoryScript(scripts, canonicalHistory, "readSession");
19678
19684
  if (!fn) return null;
19679
19685
  const normalizedSessionId = normalizeSavedHistorySessionId(historySessionId || "");
@@ -19687,7 +19693,8 @@ function callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, his
19687
19693
  excludeInProgressTurn: excludeInProgressTurn === true,
19688
19694
  sessionStartedAtMs,
19689
19695
  envOverrides,
19690
- args: { sessionId: normalizedSessionId, historySessionId: normalizedSessionId, workspace, excludeInProgressTurn: excludeInProgressTurn === true, sessionStartedAtMs, envOverrides }
19696
+ forceRefresh: forceRefresh === true,
19697
+ args: { sessionId: normalizedSessionId, historySessionId: normalizedSessionId, workspace, excludeInProgressTurn: excludeInProgressTurn === true, sessionStartedAtMs, envOverrides, forceRefresh: forceRefresh === true }
19691
19698
  });
19692
19699
  if (!result || typeof result !== "object") return null;
19693
19700
  const records = normalizeProviderNativeHistoryRecords(agentType, normalizedSessionId, result.messages || result.records);
@@ -19702,11 +19709,11 @@ function callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, his
19702
19709
  unavailableReason: typeof result.unavailableReason === "string" ? result.unavailableReason.trim() : void 0
19703
19710
  };
19704
19711
  }
19705
- function buildNativeHistoryReadResult(agentType, canonicalHistory, scripts, historySessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides) {
19712
+ function buildNativeHistoryReadResult(agentType, canonicalHistory, scripts, historySessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides, forceRefresh) {
19706
19713
  const normalizedSessionId = normalizeSavedHistorySessionId(historySessionId || "");
19707
19714
  const normalizedWorkspace = typeof workspace === "string" ? workspace.trim() : "";
19708
19715
  if (!canonicalHistory || !normalizedSessionId && !normalizedWorkspace || !isNativeSourceCanonicalHistory(canonicalHistory)) return null;
19709
- return callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, normalizedSessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides);
19716
+ return callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, normalizedSessionId, workspace, excludeInProgressTurn, sessionStartedAtMs, envOverrides, forceRefresh);
19710
19717
  }
19711
19718
  function materializeNativeHistoryToMirror(agentType, canonicalHistory, historySessionId, workspace, scripts) {
19712
19719
  const normalizedSessionId = normalizeSavedHistorySessionId(historySessionId);
@@ -19735,7 +19742,7 @@ function isNativeSourceCanonicalHistory(canonicalHistory) {
19735
19742
  }
19736
19743
  function readProviderChatHistory(agentType, options = {}) {
19737
19744
  if (isNativeSourceCanonicalHistory(options.canonicalHistory) && (options.historySessionId || options.workspace)) {
19738
- const nativeResult = buildNativeHistoryReadResult(agentType, options.canonicalHistory, options.scripts, options.historySessionId, options.workspace, options.excludeInProgressTurn, options.sessionStartedAtMs, options.envOverrides);
19745
+ const nativeResult = buildNativeHistoryReadResult(agentType, options.canonicalHistory, options.scripts, options.historySessionId, options.workspace, options.excludeInProgressTurn, options.sessionStartedAtMs, options.envOverrides, options.forceRefresh);
19739
19746
  if (!nativeResult) return { messages: [], hasMore: false, source: "native-unavailable" };
19740
19747
  return {
19741
19748
  ...pageHistoryRecords(agentType, nativeResult.records, options.offset || 0, options.limit || 30, options.excludeRecentCount || 0, options.historyBehavior),
@@ -28162,7 +28169,7 @@ var SpecCliAdapter = class {
28162
28169
  activeInteractivePrompt: this.activeInteractivePrompt
28163
28170
  };
28164
28171
  }
28165
- if (/busy|generating|working|running|thinking/i.test(lc + " " + state.label)) {
28172
+ if (lc === "busy" || lc === "generating") {
28166
28173
  return { status: "generating", messages: [], activeModal: null, activeInteractivePrompt: this.activeInteractivePrompt };
28167
28174
  }
28168
28175
  return { status: "idle", messages: [], activeModal: null, activeInteractivePrompt: this.activeInteractivePrompt };
@@ -28296,13 +28303,37 @@ var SpecCliAdapter = class {
28296
28303
  return Promise.resolve({ ok: true, effects });
28297
28304
  }
28298
28305
  getDebugSnapshot() {
28306
+ let screen = "";
28307
+ let sections;
28308
+ try {
28309
+ screen = this.driver.snapshot();
28310
+ const lines = screen.split("\n");
28311
+ sections = {};
28312
+ for (const sec of this.spec.layout?.sections ?? []) {
28313
+ const from = sec.from_top;
28314
+ const fromBottom = sec.from_bottom;
28315
+ let start = 0;
28316
+ let end = lines.length;
28317
+ if (typeof from === "number") start = Math.max(0, from);
28318
+ else if (typeof fromBottom === "number") start = Math.max(0, lines.length - fromBottom);
28319
+ const until = sec.until;
28320
+ if (until && typeof until === "object" && typeof until.section === "string") {
28321
+ const ref = (this.spec.layout?.sections ?? []).find((s) => s.id === until.section);
28322
+ if (ref && typeof ref.from_bottom === "number") end = Math.max(start, lines.length - ref.from_bottom);
28323
+ }
28324
+ sections[sec.id] = lines.slice(start, end).join("\n");
28325
+ }
28326
+ } catch {
28327
+ }
28299
28328
  return {
28300
28329
  cliType: this.cliType,
28301
28330
  spec_id: this.spec.id,
28302
28331
  current_state: this.latestState,
28303
28332
  current_modal: this.latestModal,
28304
28333
  activeInteractivePrompt: this.activeInteractivePrompt,
28305
- exited: this.exited
28334
+ exited: this.exited,
28335
+ screen,
28336
+ sections
28306
28337
  };
28307
28338
  }
28308
28339
  getRuntimeMetadata() {
@@ -29068,6 +29099,7 @@ var CliProviderInstance = class {
29068
29099
  }
29069
29100
  completedDebounceTimer = null;
29070
29101
  completedDebouncePending = null;
29102
+ lastExternalCompletionProbe = null;
29071
29103
  async enforceFreshSessionLaunchIfNeeded() {
29072
29104
  const scriptName = getForcedNewSessionScriptName(this.provider, this.launchMode);
29073
29105
  if (!scriptName) return;
@@ -29100,11 +29132,44 @@ var CliProviderInstance = class {
29100
29132
  if (looksLikeActiveApprovalPromptText(content)) return false;
29101
29133
  return true;
29102
29134
  }
29135
+ buildExternalTranscriptProbe(messages, sourcePath, sourceMtimeMs) {
29136
+ const visibleMessages = messages.filter((message) => isUserFacingChatMessage(message));
29137
+ const lastVisible = visibleMessages[visibleMessages.length - 1];
29138
+ const readAt = Date.now();
29139
+ const mtimeMs = Number(sourceMtimeMs) || 0;
29140
+ return {
29141
+ readAt,
29142
+ msgCount: messages.length,
29143
+ lastRole: typeof lastVisible?.role === "string" ? lastVisible.role.trim().toLowerCase() : null,
29144
+ lastKind: typeof lastVisible?.kind === "string" ? lastVisible.kind : null,
29145
+ contentLen: lastVisible ? flattenContent(lastVisible.content).trim().length : 0,
29146
+ sourcePath: typeof sourcePath === "string" && sourcePath ? sourcePath : null,
29147
+ sourceMtimeMs: mtimeMs || null,
29148
+ mtimeAgeMs: mtimeMs ? Math.max(0, readAt - mtimeMs) : null
29149
+ };
29150
+ }
29151
+ recordPendingTranscriptProbe(pending) {
29152
+ const probe = this.lastExternalCompletionProbe;
29153
+ if (!probe) return null;
29154
+ const history = pending.transcriptProbeHistory || [];
29155
+ const last = history[history.length - 1];
29156
+ if (!last || last.readAt !== probe.readAt || last.msgCount !== probe.msgCount || last.lastRole !== probe.lastRole || last.contentLen !== probe.contentLen) {
29157
+ history.push(probe);
29158
+ pending.transcriptProbeHistory = history.slice(-5);
29159
+ }
29160
+ return probe;
29161
+ }
29103
29162
  readExternalCompletionMessages() {
29104
29163
  const adapterOwnsMessagesElsewhere = this.adapter?.chatMessagesOwnedExternally === true;
29105
29164
  if (!adapterOwnsMessagesElsewhere) return null;
29106
29165
  if (!this.providerSessionId) return null;
29107
29166
  if (!isNativeSourceCanonicalHistory(this.provider.nativeHistory)) return null;
29167
+ if (this.lastExternalCompletionProbe?.sourcePath) {
29168
+ try {
29169
+ fs12.statSync(this.lastExternalCompletionProbe.sourcePath);
29170
+ } catch {
29171
+ }
29172
+ }
29108
29173
  const restoredHistory = readProviderChatHistory(this.type, {
29109
29174
  canonicalHistory: this.provider.nativeHistory,
29110
29175
  historySessionId: this.providerSessionId,
@@ -29113,9 +29178,18 @@ var CliProviderInstance = class {
29113
29178
  limit: Number.MAX_SAFE_INTEGER,
29114
29179
  historyBehavior: this.provider.historyBehavior,
29115
29180
  scripts: this.provider.scripts,
29116
- sessionStartedAtMs: this.startedAt
29181
+ sessionStartedAtMs: this.startedAt,
29182
+ forceRefresh: true
29117
29183
  });
29118
- if (restoredHistory.source !== "provider-native") return null;
29184
+ if (restoredHistory.source !== "provider-native") {
29185
+ this.lastExternalCompletionProbe = null;
29186
+ return null;
29187
+ }
29188
+ this.lastExternalCompletionProbe = this.buildExternalTranscriptProbe(
29189
+ restoredHistory.messages,
29190
+ restoredHistory.sourcePath,
29191
+ restoredHistory.sourceMtimeMs
29192
+ );
29119
29193
  return restoredHistory.messages;
29120
29194
  }
29121
29195
  completionFinalAssistantEvidence(parsedMessages) {
@@ -29153,6 +29227,9 @@ var CliProviderInstance = class {
29153
29227
  parseError = error?.message || String(error);
29154
29228
  }
29155
29229
  const evidence = this.completionFinalAssistantEvidence(parsed?.messages);
29230
+ if (evidence.source === "external-native") {
29231
+ this.recordPendingTranscriptProbe(args.pending);
29232
+ }
29156
29233
  const visibleMessages = (Array.isArray(evidence.messages) ? evidence.messages : []).filter((message) => isUserFacingChatMessage(message));
29157
29234
  const lastVisible = visibleMessages[visibleMessages.length - 1];
29158
29235
  const lastVisibleRole = typeof lastVisible?.role === "string" ? lastVisible.role.trim().toLowerCase() : null;
@@ -29181,7 +29258,8 @@ var CliProviderInstance = class {
29181
29258
  pendingFirstObservedAt: args.pending.firstObservedAt,
29182
29259
  pendingTimestamp: args.pending.timestamp,
29183
29260
  pendingDurationSec: args.pending.duration,
29184
- previousBlockReason: args.pending.loggedBlockReason || null
29261
+ previousBlockReason: args.pending.loggedBlockReason || null,
29262
+ transcriptProbeHistory: args.pending.transcriptProbeHistory || []
29185
29263
  };
29186
29264
  }
29187
29265
  hasAdapterPendingResponse() {
@@ -29239,6 +29317,11 @@ var CliProviderInstance = class {
29239
29317
  if (!finalAssistantEvidence.present) {
29240
29318
  if (adapterOwnsMessagesElsewhere) {
29241
29319
  if (finalAssistantEvidence.source === "external-native") {
29320
+ const probe = this.recordPendingTranscriptProbe(pending);
29321
+ if (probe && !pending.loggedTranscriptProbe) {
29322
+ 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`);
29323
+ pending.loggedTranscriptProbe = true;
29324
+ }
29242
29325
  return { reason: "missing_final_assistant", terminal: true };
29243
29326
  }
29244
29327
  if (this.provider.requiresFinalAssistantBeforeIdle === true) {