@adhdev/daemon-core 0.9.82-rc.100 → 0.9.82-rc.102

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.
@@ -174,6 +174,9 @@ export declare class ProviderCliAdapter implements CliAdapter {
174
174
  private runParseApproval;
175
175
  private hasActionableApproval;
176
176
  private parsedStatusHasFinalAssistantMessage;
177
+ private parsedStatusHasFinalStandardAssistantMessage;
178
+ private shouldKeepCodexTurnOpenForFinish;
179
+ private rescheduleCodexFinishCheck;
177
180
  private projectEffectiveStatus;
178
181
  getStatus(options?: {
179
182
  allowParse?: boolean;
@@ -116,6 +116,10 @@ export declare function readProviderChatHistory(agentType: string, options?: {
116
116
  source: 'provider-native' | 'adhdev-mirror' | 'native-unavailable';
117
117
  sourcePath?: string;
118
118
  sourceMtimeMs?: number;
119
+ providerSessionId?: string;
120
+ nativeHistoryCoverage?: string;
121
+ partialReason?: string;
122
+ unavailableReason?: string;
119
123
  };
120
124
  export declare function listProviderHistorySessions(agentType: string, options?: {
121
125
  canonicalHistory?: ProviderCanonicalHistoryConfig;
package/dist/index.js CHANGED
@@ -5615,6 +5615,11 @@ ${lastSnapshot}`;
5615
5615
  this.idleTimeout = setTimeout(() => {
5616
5616
  if (this.isWaitingForResponse && !this.hasActionableApproval()) {
5617
5617
  if (this.shouldDeferIdleTimeoutFinish()) return;
5618
+ const parsed = this.runParseSession();
5619
+ if (this.shouldKeepCodexTurnOpenForFinish(parsed)) {
5620
+ this.rescheduleCodexFinishCheck("codex_idle_timeout_not_final");
5621
+ return;
5622
+ }
5618
5623
  this.clearIdleFinishCandidate("idle_timeout_finish");
5619
5624
  this.finishResponse();
5620
5625
  }
@@ -5623,6 +5628,11 @@ ${lastSnapshot}`;
5623
5628
  finishResponse() {
5624
5629
  if (this.submitPendingUntil > Date.now()) return;
5625
5630
  if (this.responseSettleIgnoreUntil > Date.now()) return;
5631
+ const parsedBeforeFinish = this.runParseSession();
5632
+ if (this.shouldKeepCodexTurnOpenForFinish(parsedBeforeFinish)) {
5633
+ this.rescheduleCodexFinishCheck("codex_finish_not_final");
5634
+ return;
5635
+ }
5626
5636
  this.clearIdleFinishCandidate("finish_response_enter");
5627
5637
  this.recordTrace("finish_response", {
5628
5638
  ...buildCliTraceParseSnapshot({
@@ -5838,6 +5848,44 @@ ${lastSnapshot}`;
5838
5848
  });
5839
5849
  return !!lastAssistant;
5840
5850
  }
5851
+ parsedStatusHasFinalStandardAssistantMessage(parsed) {
5852
+ const messages = Array.isArray(parsed?.messages) ? parsed.messages : [];
5853
+ const lastAssistant = [...messages].reverse().find((message) => {
5854
+ if (!message || message.role !== "assistant") return false;
5855
+ return typeof message.content === "string" && message.content.trim().length > 0;
5856
+ });
5857
+ if (!lastAssistant) return false;
5858
+ const kind = typeof lastAssistant.kind === "string" && lastAssistant.kind.trim() ? lastAssistant.kind.trim() : "standard";
5859
+ return kind === "standard" && lastAssistant.meta?.streaming !== true;
5860
+ }
5861
+ shouldKeepCodexTurnOpenForFinish(parsed) {
5862
+ if (this.cliType !== "codex-cli") return false;
5863
+ if (!this.isWaitingForResponse || !this.currentTurnScope || this.hasActionableApproval()) return false;
5864
+ const parsedStatus = typeof parsed?.status === "string" ? parsed.status.trim() : "";
5865
+ if (parsedStatus !== "idle") return true;
5866
+ if (parsed?.activeModal || parsed?.modal) return true;
5867
+ return !this.parsedStatusHasFinalStandardAssistantMessage(parsed);
5868
+ }
5869
+ rescheduleCodexFinishCheck(reason) {
5870
+ this.clearIdleFinishCandidate(reason);
5871
+ this.setStatus("generating", reason);
5872
+ if (this.idleTimeout) clearTimeout(this.idleTimeout);
5873
+ this.idleTimeout = setTimeout(() => {
5874
+ if (!this.isWaitingForResponse || this.hasActionableApproval()) return;
5875
+ this.settledBuffer = this.recentOutputBuffer;
5876
+ this.evaluateSettled();
5877
+ }, this.getIdleFinishConfirmMs());
5878
+ this.recordTrace("codex_finish_deferred", {
5879
+ reason,
5880
+ ...buildCliTraceParseSnapshot({
5881
+ accumulatedBuffer: this.accumulatedBuffer,
5882
+ accumulatedRawBuffer: this.accumulatedRawBuffer,
5883
+ responseBuffer: this.responseBuffer,
5884
+ partialResponse: this.responseBuffer,
5885
+ scope: this.currentTurnScope
5886
+ })
5887
+ });
5888
+ }
5841
5889
  projectEffectiveStatus(startupModal = null) {
5842
5890
  if (this.parseErrorMessage) return "error";
5843
5891
  if (this.hasActionableApproval(startupModal)) return "waiting_approval";
@@ -5915,6 +5963,8 @@ ${lastSnapshot}`;
5915
5963
  }),
5916
5964
  activeModal,
5917
5965
  providerSessionId: typeof parsed.providerSessionId === "string" ? parsed.providerSessionId : void 0,
5966
+ errorMessage: typeof parsed.errorMessage === "string" && parsed.errorMessage.trim() ? parsed.errorMessage.trim() : void 0,
5967
+ errorReason: typeof parsed.errorReason === "string" && parsed.errorReason.trim() ? parsed.errorReason.trim() : void 0,
5918
5968
  ...bufferState ? { bufferState } : {},
5919
5969
  ...parsed.transcriptAuthority === "provider" || parsed.transcriptAuthority === "daemon" ? { transcriptAuthority: parsed.transcriptAuthority } : this.providerOwnsTranscript() ? { transcriptAuthority: "provider" } : {},
5920
5970
  ...parsed.coverage === "full" || parsed.coverage === "tail" || parsed.coverage === "current-turn" ? { coverage: parsed.coverage } : this.providerOwnsTranscript() ? { coverage: this.shouldUseFullProviderTranscriptContext() ? "full" : "tail" } : {}
@@ -6718,6 +6768,9 @@ ${lastSnapshot}`;
6718
6768
  const parsedDebugState = this.getParsedDebugState();
6719
6769
  const parsedMessages = Array.isArray(parsedDebugState?.messages) ? parsedDebugState.messages : [];
6720
6770
  let effectiveStatus = this.projectEffectiveStatus(startupModal);
6771
+ if (parsedDebugState?.status === "error") {
6772
+ effectiveStatus = "error";
6773
+ }
6721
6774
  if (startupDetectedStatus === "waiting_approval") {
6722
6775
  effectiveStatus = "waiting_approval";
6723
6776
  }
@@ -6745,6 +6798,8 @@ ${lastSnapshot}`;
6745
6798
  providerSessionId: parsedDebugState.providerSessionId,
6746
6799
  transcriptAuthority: parsedDebugState.transcriptAuthority,
6747
6800
  coverage: parsedDebugState.coverage,
6801
+ errorMessage: parsedDebugState.errorMessage,
6802
+ errorReason: parsedDebugState.errorReason,
6748
6803
  activeModal: parsedDebugState.activeModal,
6749
6804
  messageCount: parsedMessages.length
6750
6805
  } : null,
@@ -13517,7 +13572,11 @@ function callProviderNativeHistoryRead(agentType, canonicalHistory, scripts, his
13517
13572
  return {
13518
13573
  records,
13519
13574
  sourcePath: typeof result.sourcePath === "string" ? result.sourcePath : "",
13520
- sourceMtimeMs: Number(result.sourceMtimeMs) || 0
13575
+ sourceMtimeMs: Number(result.sourceMtimeMs) || 0,
13576
+ providerSessionId: typeof result.providerSessionId === "string" ? result.providerSessionId.trim() : void 0,
13577
+ nativeHistoryCoverage: typeof result.nativeHistoryCoverage === "string" ? result.nativeHistoryCoverage.trim() : void 0,
13578
+ partialReason: typeof result.partialReason === "string" ? result.partialReason.trim() : void 0,
13579
+ unavailableReason: typeof result.unavailableReason === "string" ? result.unavailableReason.trim() : void 0
13521
13580
  };
13522
13581
  }
13523
13582
  function buildNativeHistoryReadResult(agentType, canonicalHistory, scripts, historySessionId, workspace) {
@@ -13559,7 +13618,11 @@ function readProviderChatHistory(agentType, options = {}) {
13559
13618
  ...pageHistoryRecords(agentType, nativeResult.records, options.offset || 0, options.limit || 30, options.excludeRecentCount || 0, options.historyBehavior),
13560
13619
  source: "provider-native",
13561
13620
  sourcePath: nativeResult.sourcePath,
13562
- sourceMtimeMs: nativeResult.sourceMtimeMs
13621
+ sourceMtimeMs: nativeResult.sourceMtimeMs,
13622
+ providerSessionId: nativeResult.providerSessionId,
13623
+ nativeHistoryCoverage: nativeResult.nativeHistoryCoverage,
13624
+ partialReason: nativeResult.partialReason,
13625
+ unavailableReason: nativeResult.unavailableReason
13563
13626
  };
13564
13627
  }
13565
13628
  return {
@@ -16355,6 +16418,9 @@ function buildCliMessageSourceProvenance(args) {
16355
16418
  ...args.fallbackReason ? { fallbackReason: args.fallbackReason } : {},
16356
16419
  ...args.nativeSource ? { nativeSource: args.nativeSource } : {},
16357
16420
  ...args.sourcePath ? { sourcePath: args.sourcePath } : {},
16421
+ ...args.nativeHistoryCoverage ? { nativeHistoryCoverage: args.nativeHistoryCoverage } : {},
16422
+ ...args.partialReason ? { partialReason: args.partialReason } : {},
16423
+ ...args.unavailableReason ? { unavailableReason: args.unavailableReason } : {},
16358
16424
  ptyStatusApprovalOnly: args.ptyStatusApprovalOnly === true,
16359
16425
  staleness: {
16360
16426
  sourceMtimeMs: sourceMtimeMs || void 0,
@@ -16374,6 +16440,8 @@ function buildCliMessageSourceProvenance(args) {
16374
16440
  function buildNativeHistoryFallbackReason(args) {
16375
16441
  if (!supportsCliNativeTranscript(args.providerType, args.provider)) return "provider_native_transcript_not_supported";
16376
16442
  if (args.nativeSource === "native-unavailable") return "native_history_unavailable";
16443
+ if (args.nativeHistoryCoverage === "partial") return "native_history_partial";
16444
+ if (args.nativeHistoryCoverage === "unavailable") return "native_history_unavailable";
16377
16445
  if (args.nativeSource && args.nativeSource !== "provider-native") return `native_history_source_${args.nativeSource}`;
16378
16446
  if (args.nativeMessageCount <= 0) return "native_history_empty";
16379
16447
  if (!args.safeMapping) return "native_history_not_safely_mapped";
@@ -17107,6 +17175,9 @@ async function handleReadChat(h, args) {
17107
17175
  if (nativeHistory) {
17108
17176
  const nativeMessages = Array.isArray(nativeHistory.messages) ? normalizeNativeHistoryMessages(agentStr, nativeHistory.messages) : [];
17109
17177
  const historyProviderSessionId = typeof nativeHistory?.providerSessionId === "string" ? nativeHistory.providerSessionId : readHistorySessionIdFromMessages(nativeMessages) || nativeHistorySessionId || historySessionId;
17178
+ const nativeHistoryCoverage = typeof nativeHistory?.nativeHistoryCoverage === "string" ? nativeHistory.nativeHistoryCoverage : void 0;
17179
+ const partialReason = typeof nativeHistory?.partialReason === "string" ? nativeHistory.partialReason : void 0;
17180
+ const unavailableReason = typeof nativeHistory?.unavailableReason === "string" ? nativeHistory.unavailableReason : void 0;
17110
17181
  const lookup = nativeHistory.lookup === "workspace" ? "workspace" : "session";
17111
17182
  const safeMapping = hasSafeNativeHistoryMapping({
17112
17183
  historySessionId: lookup === "workspace" ? void 0 : nativeHistorySessionId,
@@ -17121,7 +17192,7 @@ async function handleReadChat(h, args) {
17121
17192
  nativeMessages,
17122
17193
  ptyMessages: returnedMessages
17123
17194
  });
17124
- if (nativeHistory.source === "provider-native" && nativeMessages.length > 0 && safeMapping && freshEnough) {
17195
+ if (nativeHistory.source === "provider-native" && nativeMessages.length > 0 && nativeHistoryCoverage !== "partial" && nativeHistoryCoverage !== "unavailable" && safeMapping && freshEnough) {
17125
17196
  selectedMessages = finalizeStreamingMessagesWhenIdle(nativeMessages, returnedStatus);
17126
17197
  selectedProviderSessionId = historyProviderSessionId || providerSessionId;
17127
17198
  selectedTranscriptAuthority = "provider";
@@ -17133,6 +17204,9 @@ async function handleReadChat(h, args) {
17133
17204
  nativeSource: nativeHistory.source,
17134
17205
  sourcePath: nativeHistory.sourcePath,
17135
17206
  sourceMtimeMs: nativeHistory.sourceMtimeMs,
17207
+ nativeHistoryCoverage,
17208
+ partialReason,
17209
+ unavailableReason,
17136
17210
  nativeMessages,
17137
17211
  ptyMessages: returnedMessages,
17138
17212
  returnedMessages: selectedMessages,
@@ -17145,6 +17219,7 @@ async function handleReadChat(h, args) {
17145
17219
  providerType,
17146
17220
  provider,
17147
17221
  nativeSource: nativeHistory.source,
17222
+ nativeHistoryCoverage,
17148
17223
  nativeMessageCount: nativeMessages.length,
17149
17224
  safeMapping,
17150
17225
  freshEnough
@@ -17157,6 +17232,9 @@ async function handleReadChat(h, args) {
17157
17232
  nativeSource: nativeHistory.source,
17158
17233
  sourcePath: nativeHistory.sourcePath,
17159
17234
  sourceMtimeMs: nativeHistory.sourceMtimeMs,
17235
+ nativeHistoryCoverage,
17236
+ partialReason,
17237
+ unavailableReason,
17160
17238
  nativeMessages,
17161
17239
  ptyMessages: returnedMessages,
17162
17240
  returnedMessages,
@@ -17222,13 +17300,16 @@ async function handleReadChat(h, args) {
17222
17300
  const lookup = history.lookup === "workspace" ? "workspace" : "session";
17223
17301
  const historyMessages = Array.isArray(history?.messages) ? normalizeNativeHistoryMessages(agentStr, history.messages) : [];
17224
17302
  const historyProviderSessionId = typeof history?.providerSessionId === "string" ? history.providerSessionId : readHistorySessionIdFromMessages(historyMessages) || historySessionId;
17303
+ const nativeHistoryCoverage = typeof history?.nativeHistoryCoverage === "string" ? history.nativeHistoryCoverage : void 0;
17304
+ const partialReason = typeof history?.partialReason === "string" ? history.partialReason : void 0;
17305
+ const unavailableReason = typeof history?.unavailableReason === "string" ? history.unavailableReason : void 0;
17225
17306
  const safeMapping = supportsCliNativeTranscript(agentStr, provider) ? hasSafeNativeHistoryMapping({
17226
17307
  historySessionId: lookup === "workspace" ? void 0 : historySessionId,
17227
17308
  providerSessionId: lookup === "workspace" ? void 0 : historyProviderSessionId,
17228
17309
  workspace,
17229
17310
  nativeMessages: historyMessages
17230
17311
  }) : false;
17231
- const nativeSelected = supportsCliNativeTranscript(agentStr, provider) && history.source === "provider-native" && historyMessages.length > 0 && safeMapping;
17312
+ const nativeSelected = supportsCliNativeTranscript(agentStr, provider) && history.source === "provider-native" && historyMessages.length > 0 && nativeHistoryCoverage !== "partial" && nativeHistoryCoverage !== "unavailable" && safeMapping;
17232
17313
  const messageSource = buildCliMessageSourceProvenance({
17233
17314
  selected: nativeSelected ? "native-history" : "pty-parser",
17234
17315
  provider: agentStr,
@@ -17237,6 +17318,7 @@ async function handleReadChat(h, args) {
17237
17318
  providerType: agentStr,
17238
17319
  provider,
17239
17320
  nativeSource: history.source,
17321
+ nativeHistoryCoverage,
17240
17322
  nativeMessageCount: historyMessages.length,
17241
17323
  safeMapping,
17242
17324
  freshEnough: true
@@ -17244,6 +17326,9 @@ async function handleReadChat(h, args) {
17244
17326
  nativeSource: history.source,
17245
17327
  sourcePath: history.sourcePath,
17246
17328
  sourceMtimeMs: history.sourceMtimeMs,
17329
+ nativeHistoryCoverage,
17330
+ partialReason,
17331
+ unavailableReason,
17247
17332
  nativeMessages: historyMessages,
17248
17333
  returnedMessages: historyMessages,
17249
17334
  safeMapping,
@@ -19949,8 +20034,10 @@ var CliProviderInstance = class {
19949
20034
  if (typeof this.adapter.getScriptParsedStatus === "function") {
19950
20035
  try {
19951
20036
  parsedStatus = this.adapter.getScriptParsedStatus() || null;
19952
- this.errorMessage = void 0;
19953
- this.errorReason = void 0;
20037
+ const parsedErrorMessage = typeof parsedStatus?.errorMessage === "string" && parsedStatus.errorMessage.trim() ? parsedStatus.errorMessage.trim() : void 0;
20038
+ const parsedErrorReason = typeof parsedStatus?.errorReason === "string" && parsedStatus.errorReason.trim() ? parsedStatus.errorReason.trim() : void 0;
20039
+ this.errorMessage = parsedErrorMessage;
20040
+ this.errorReason = parsedErrorReason;
19954
20041
  } catch (error) {
19955
20042
  parseErrorMessage = error?.message || String(error);
19956
20043
  this.errorMessage = parseErrorMessage;
@@ -19961,7 +20048,7 @@ var CliProviderInstance = class {
19961
20048
  this.errorReason = void 0;
19962
20049
  }
19963
20050
  const autoApproveActive = this.maybeAutoApproveStatus(adapterStatus, Date.now());
19964
- const visibleStatus = parseErrorMessage ? "error" : autoApproveActive ? "generating" : adapterStatus.status;
20051
+ const visibleStatus = parseErrorMessage || parsedStatus?.status === "error" ? "error" : autoApproveActive ? "generating" : adapterStatus.status;
19965
20052
  const parsedProviderSessionId = normalizeProviderSessionId(
19966
20053
  this.provider,
19967
20054
  typeof parsedStatus?.providerSessionId === "string" ? parsedStatus.providerSessionId : ""