@adhdev/daemon-core 0.9.82-rc.109 → 0.9.82-rc.110

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adhdev/daemon-core",
3
- "version": "0.9.82-rc.109",
3
+ "version": "0.9.82-rc.110",
4
4
  "description": "ADHDev daemon core — CDP, IDE detection, providers, command execution",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -145,6 +145,9 @@ export class ProviderCliAdapter implements CliAdapter {
145
145
  private isWaitingForResponse = false;
146
146
  private activeModal: { message: string; buttons: string[] } | null = null;
147
147
  private parseErrorMessage: string | null = null;
148
+ private providerSessionId: string | null = null;
149
+ private providerErrorMessage: string | null = null;
150
+ private providerErrorReason: string | null = null;
148
151
  private responseTimeout: NodeJS.Timeout | null = null;
149
152
  private idleTimeout: NodeJS.Timeout | null = null;
150
153
  private ready = false;
@@ -1151,6 +1154,7 @@ export class ProviderCliAdapter implements CliAdapter {
1151
1154
  && !(parsedStatus === 'idle' && !!lastParsedAssistant);
1152
1155
 
1153
1156
  if (shouldHoldGenerating) { this.applyHoldGenerating(ctx, recentInteractiveActivity); return; }
1157
+ if (status === 'error') { this.applyError(ctx, session); return; }
1154
1158
  if (status === 'waiting_approval') { this.applyWaitingApproval(ctx); return; }
1155
1159
  if (status === 'generating') { this.applyGenerating(ctx); return; }
1156
1160
  if (status === 'idle') { this.applyIdle(ctx, now); }
@@ -1294,6 +1298,41 @@ export class ProviderCliAdapter implements CliAdapter {
1294
1298
  this.onStatusChange?.();
1295
1299
  }
1296
1300
 
1301
+ private applyError(ctx: SettledEvalContext, session: ParsedSession): void {
1302
+ this.clearIdleFinishCandidate('provider_error');
1303
+ if (this.responseTimeout) { clearTimeout(this.responseTimeout); this.responseTimeout = null; }
1304
+ if (this.idleTimeout) { clearTimeout(this.idleTimeout); this.idleTimeout = null; }
1305
+ if (this.approvalExitTimeout) { clearTimeout(this.approvalExitTimeout); this.approvalExitTimeout = null; }
1306
+ this.isWaitingForResponse = false;
1307
+ this.responseSettleIgnoreUntil = 0;
1308
+ this.submitRetryUsed = false;
1309
+ this.submitRetryPromptSnippet = '';
1310
+ this.finishRetryCount = 0;
1311
+ this.currentTurnScope = null;
1312
+ this.activeModal = null;
1313
+ this.providerErrorMessage = typeof session.errorMessage === 'string' && session.errorMessage.trim()
1314
+ ? session.errorMessage.trim()
1315
+ : 'Provider reported an error';
1316
+ this.providerErrorReason = typeof session.errorReason === 'string' && session.errorReason.trim()
1317
+ ? session.errorReason.trim()
1318
+ : 'provider_error';
1319
+ this.setStatus('error', this.providerErrorReason);
1320
+ this.recordTrace('provider_error', {
1321
+ errorMessage: this.providerErrorMessage,
1322
+ errorReason: this.providerErrorReason,
1323
+ parsedStatus: ctx.parsedStatus || ctx.status,
1324
+ messageCount: ctx.parsedMessages.length,
1325
+ ...buildCliTraceParseSnapshot({
1326
+ accumulatedBuffer: this.accumulatedBuffer,
1327
+ accumulatedRawBuffer: this.accumulatedRawBuffer,
1328
+ responseBuffer: this.responseBuffer,
1329
+ partialResponse: this.responseBuffer,
1330
+ scope: this.currentTurnScope,
1331
+ }),
1332
+ });
1333
+ this.onStatusChange?.();
1334
+ }
1335
+
1297
1336
  private applyIdle(ctx: SettledEvalContext, now: number): void {
1298
1337
  const { modal, lastParsedAssistant, prevStatus } = ctx;
1299
1338
  if (prevStatus === 'waiting_approval') {
@@ -1567,6 +1606,7 @@ export class ProviderCliAdapter implements CliAdapter {
1567
1606
  { ...input, tail, tailScreen: buildCliScreenSnapshot(tail) },
1568
1607
  );
1569
1608
  this.parseErrorMessage = null;
1609
+ if (session && typeof session === 'object') this.applyParsedSessionMetadata(session);
1570
1610
  return session && typeof session === 'object' ? session : null;
1571
1611
  } catch (e: any) {
1572
1612
  const message = e?.message || String(e);
@@ -1628,6 +1668,22 @@ export class ProviderCliAdapter implements CliAdapter {
1628
1668
  return !!lastAssistant;
1629
1669
  }
1630
1670
 
1671
+ private applyParsedSessionMetadata(parsed: any): void {
1672
+ const providerSessionId = typeof parsed?.providerSessionId === 'string' && parsed.providerSessionId.trim()
1673
+ ? parsed.providerSessionId.trim()
1674
+ : '';
1675
+ if (providerSessionId) {
1676
+ this.providerSessionId = providerSessionId;
1677
+ this.updateRuntimeMeta({ providerSessionId });
1678
+ }
1679
+ this.providerErrorMessage = typeof parsed?.errorMessage === 'string' && parsed.errorMessage.trim()
1680
+ ? parsed.errorMessage.trim()
1681
+ : null;
1682
+ this.providerErrorReason = typeof parsed?.errorReason === 'string' && parsed.errorReason.trim()
1683
+ ? parsed.errorReason.trim()
1684
+ : null;
1685
+ }
1686
+
1631
1687
  private parsedStatusHasFinalStandardAssistantMessage(parsed: any): boolean {
1632
1688
  const messages = Array.isArray(parsed?.messages) ? parsed.messages : [];
1633
1689
  const lastAssistant = [...messages].reverse().find((message: any) => {
@@ -1730,8 +1786,9 @@ export class ProviderCliAdapter implements CliAdapter {
1730
1786
  queuedAt: message.queuedAt,
1731
1787
  source: message.source,
1732
1788
  })),
1733
- errorMessage: this.parseErrorMessage || undefined,
1734
- errorReason: this.parseErrorMessage ? 'parse_error' : undefined,
1789
+ errorMessage: this.parseErrorMessage || this.providerErrorMessage || undefined,
1790
+ errorReason: this.parseErrorMessage ? 'parse_error' : (this.providerErrorReason || undefined),
1791
+ providerSessionId: this.providerSessionId || undefined,
1735
1792
  ...(bufferState ? { bufferState } : {}),
1736
1793
  };
1737
1794
  }
@@ -1778,7 +1835,7 @@ export class ProviderCliAdapter implements CliAdapter {
1778
1835
  lastOutputAt: this.lastOutputAt,
1779
1836
  }),
1780
1837
  activeModal,
1781
- providerSessionId: typeof (parsed as any).providerSessionId === 'string' ? (parsed as any).providerSessionId : undefined,
1838
+ providerSessionId: this.providerSessionId || (typeof (parsed as any).providerSessionId === 'string' ? (parsed as any).providerSessionId : undefined),
1782
1839
  errorMessage: typeof (parsed as any).errorMessage === 'string' && (parsed as any).errorMessage.trim()
1783
1840
  ? (parsed as any).errorMessage.trim()
1784
1841
  : undefined,
@@ -38,6 +38,7 @@ export interface CliSessionStatus {
38
38
  }>;
39
39
  errorMessage?: string;
40
40
  errorReason?: string;
41
+ providerSessionId?: string;
41
42
  bufferState?: {
42
43
  responseBuffer?: { truncated: boolean; droppedChars: number; maxChars: number };
43
44
  recentOutputBuffer?: { truncated: boolean; droppedChars: number; maxChars: number };
@@ -51,6 +52,9 @@ export interface ParsedSession {
51
52
  messages: any[];
52
53
  modal: { message: string; buttons: string[] } | null;
53
54
  parsedStatus: string | null;
55
+ errorMessage?: string;
56
+ errorReason?: string;
57
+ providerSessionId?: string;
54
58
  transcriptAuthority?: 'provider' | 'daemon';
55
59
  coverage?: 'full' | 'tail' | 'current-turn';
56
60
  }
@@ -514,6 +514,13 @@ export class CliProviderInstance implements ProviderInstance {
514
514
  this.errorMessage = undefined;
515
515
  this.errorReason = undefined;
516
516
  }
517
+ const adapterProviderSessionId = normalizeProviderSessionId(
518
+ this.provider,
519
+ typeof adapterStatus?.providerSessionId === 'string' ? adapterStatus.providerSessionId : '',
520
+ );
521
+ if (adapterProviderSessionId) {
522
+ this.promoteProviderSessionId(adapterProviderSessionId);
523
+ }
517
524
  const autoApproveActive = this.maybeAutoApproveStatus(adapterStatus, Date.now());
518
525
  const visibleStatus = parseErrorMessage || parsedStatus?.status === 'error'
519
526
  ? 'error'
@@ -970,6 +977,13 @@ export class CliProviderInstance implements ProviderInstance {
970
977
  // during long-running CLI sessions. Keep this path on adapter-owned light
971
978
  // state only; rich provider parsing is reserved for getState/read_chat.
972
979
  const adapterStatus = this.adapter.getStatus({ allowParse: false });
980
+ const adapterProviderSessionId = normalizeProviderSessionId(
981
+ this.provider,
982
+ typeof adapterStatus?.providerSessionId === 'string' ? adapterStatus.providerSessionId : '',
983
+ );
984
+ if (adapterProviderSessionId) {
985
+ this.promoteProviderSessionId(adapterProviderSessionId);
986
+ }
973
987
  const parsedStatus = null;
974
988
  const rawStatus = adapterStatus.status;
975
989
  const autoApproveActive = this.maybeAutoApproveStatus(adapterStatus, now);
@@ -1051,6 +1065,23 @@ export class CliProviderInstance implements ProviderInstance {
1051
1065
  }
1052
1066
  } else if (newStatus === 'idle' && this.lastStatus === 'starting') {
1053
1067
  this.pushEvent({ event: 'agent:ready', chatTitle, timestamp: now });
1068
+ } else if (newStatus === 'error') {
1069
+ if (this.generatingDebounceTimer) { clearTimeout(this.generatingDebounceTimer); this.generatingDebounceTimer = null; }
1070
+ this.generatingDebouncePending = null;
1071
+ if (this.completedDebounceTimer) { clearTimeout(this.completedDebounceTimer); this.completedDebounceTimer = null; }
1072
+ this.completedDebouncePending = null;
1073
+ this.errorMessage = adapterStatus.errorMessage || this.errorMessage;
1074
+ this.errorReason = (adapterStatus.errorReason as ProviderErrorReason) || this.errorReason;
1075
+ this.pushEvent({
1076
+ event: 'agent:stopped',
1077
+ chatTitle,
1078
+ timestamp: now,
1079
+ finalSummary: adapterStatus.errorMessage || adapterStatus.errorReason || 'Provider reported an error',
1080
+ completionDiagnostic: {
1081
+ reason: adapterStatus.errorReason || 'provider_error',
1082
+ errorMessage: adapterStatus.errorMessage || undefined,
1083
+ },
1084
+ });
1054
1085
  } else if (newStatus === 'stopped') {
1055
1086
  // Cancel any pending debounce
1056
1087
  if (this.generatingDebounceTimer) { clearTimeout(this.generatingDebounceTimer); this.generatingDebounceTimer = null; }