@adhdev/daemon-core 0.9.82-rc.567 → 0.9.82-rc.568

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.
@@ -452,6 +452,7 @@ export declare class CliProviderInstance implements ProviderInstance {
452
452
  * the dashboard tail-repair cache — a display value, not a completion decision.
453
453
  */
454
454
  private lastVisibleAssistantSummary;
455
+ private lastVisibleAssistantSummaryDetail;
455
456
  /**
456
457
  * NOTIF Defect-B: the final assistant summary this instance ALREADY parsed and
457
458
  * cached for the current turn (lastCompletionSummary), if any. The evidence
@@ -467,6 +468,7 @@ export declare class CliProviderInstance implements ProviderInstance {
467
468
  * next turn (see lastCompletionSummary = null on onTurnStarted).
468
469
  */
469
470
  private cachedCompletionSummaryContent;
471
+ private cachedInTurnCompletionSummaryContent;
470
472
  private completionFinalAssistantEvidence;
471
473
  private completionFinalSummary;
472
474
  private buildCompletedFinalizationDiagnostic;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adhdev/daemon-core",
3
- "version": "0.9.82-rc.567",
3
+ "version": "0.9.82-rc.568",
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",
@@ -47,8 +47,8 @@
47
47
  "author": "vilmire",
48
48
  "license": "AGPL-3.0-or-later",
49
49
  "dependencies": {
50
- "@adhdev/mesh-shared": "0.9.82-rc.567",
51
- "@adhdev/session-host-core": "0.9.82-rc.567",
50
+ "@adhdev/mesh-shared": "0.9.82-rc.568",
51
+ "@adhdev/session-host-core": "0.9.82-rc.568",
52
52
  "@agentclientprotocol/sdk": "^0.16.1",
53
53
  "ajv": "^8.20.0",
54
54
  "ajv-formats": "^3.0.1",
@@ -1392,7 +1392,7 @@ export class CliProviderInstance implements ProviderInstance {
1392
1392
  * real last answer with ZERO per-tick native reads (the native read already ran
1393
1393
  * once at completion). Reset on the next turn's start.
1394
1394
  */
1395
- private lastCompletionSummary: { content: string; receivedAt: number } | null = null;
1395
+ private lastCompletionSummary: { content: string; receivedAt: number; sourceTimestampMs?: number } | null = null;
1396
1396
 
1397
1397
  private async enforceFreshSessionLaunchIfNeeded(): Promise<void> {
1398
1398
  const scriptName = getForcedNewSessionScriptName(this.provider, this.launchMode);
@@ -1594,18 +1594,31 @@ export class CliProviderInstance implements ProviderInstance {
1594
1594
  * the dashboard tail-repair cache — a display value, not a completion decision.
1595
1595
  */
1596
1596
  private lastVisibleAssistantSummary(messages: unknown): string {
1597
- if (!Array.isArray(messages)) return '';
1597
+ return this.lastVisibleAssistantSummaryDetail(messages).content;
1598
+ }
1599
+
1600
+ // Like lastVisibleAssistantSummary but also returns the source bubble's own
1601
+ // timestamp (ms), so a cached summary can later be turn-scoped: the display
1602
+ // cache is populated from an UNSCOPED tail read (it must show the answer as
1603
+ // soon as native-history has it), so it can hold a bubble that predates the
1604
+ // current turn. Recording the bubble's timestamp lets the weak-completion
1605
+ // fallback reject a turn-stale cached summary instead of re-leaking the exact
1606
+ // stale bubble the turn-boundary gate already rejected (FALSE-IDLE Defect 1c).
1607
+ private lastVisibleAssistantSummaryDetail(messages: unknown): { content: string; timestampMs?: number } {
1608
+ if (!Array.isArray(messages)) return { content: '' };
1598
1609
  for (let i = messages.length - 1; i >= 0; i -= 1) {
1599
1610
  const m = messages[i] as { role?: string; kind?: string; content?: unknown };
1600
1611
  const role = typeof m?.role === 'string' ? m.role : '';
1601
1612
  const kind = typeof m?.kind === 'string' ? m.kind : '';
1602
1613
  if (role === 'system') continue;
1603
1614
  if (kind === 'tool' || kind === 'activity') continue;
1604
- if (role === 'user' || role === 'human') return '';
1605
- if (role === 'assistant') return flattenContent(m.content as any).trim();
1606
- return '';
1615
+ if (role === 'user' || role === 'human') return { content: '' };
1616
+ if (role === 'assistant') {
1617
+ return { content: flattenContent(m.content as any).trim(), timestampMs: readChatMessageTimestampMs(m as any) };
1618
+ }
1619
+ return { content: '' };
1607
1620
  }
1608
- return '';
1621
+ return { content: '' };
1609
1622
  }
1610
1623
 
1611
1624
  /**
@@ -1628,6 +1641,29 @@ export class CliProviderInstance implements ProviderInstance {
1628
1641
  return content;
1629
1642
  }
1630
1643
 
1644
+ // FALSE-IDLE Defect 1c: turn-scoped view of the cached completion summary.
1645
+ // The cache is populated from an UNSCOPED tail read (lastVisibleAssistant‑
1646
+ // SummaryDetail) so the dashboard can show the answer the instant native-history
1647
+ // has it — which means it can hold a bubble that PREDATES the producing turn.
1648
+ // The weak-completion (missing_final_assistant) emit path falls back to the cache
1649
+ // for finalSummary; without turn-scoping it would re-surface the exact stale
1650
+ // mid-turn bubble the turn-boundary gate already rejected as evidence, freezing
1651
+ // that stale text as the completion's finalSummary. Consult the cache only when
1652
+ // its source bubble is proven in-turn (timestamp at/after turnStartedAt). When no
1653
+ // boundary is known (turnStartedAt falsy) or the cache carries no source timestamp
1654
+ // (legacy writes), behaviour is identical to the unscoped read.
1655
+ private cachedInTurnCompletionSummaryContent(turnStartedAt?: number): string {
1656
+ const cached = this.lastCompletionSummary;
1657
+ const content = typeof cached?.content === 'string' ? cached.content.trim() : '';
1658
+ if (!content) return '';
1659
+ const hasBoundary = typeof turnStartedAt === 'number' && Number.isFinite(turnStartedAt) && turnStartedAt > 0;
1660
+ const ts = cached?.sourceTimestampMs;
1661
+ if (hasBoundary && typeof ts === 'number' && Number.isFinite(ts) && ts < (turnStartedAt as number)) {
1662
+ return '';
1663
+ }
1664
+ return content;
1665
+ }
1666
+
1631
1667
  private completionFinalAssistantEvidence(parsedMessages: unknown, turnStartedAt?: number): CompletionFinalAssistantEvidence {
1632
1668
  // (FALSEIDLE FixB) UPPER-BOUND turn-end evidence. completionHasFinalAssistantMessage is a
1633
1669
  // pure message-content check ("does the last visible bubble read as a finalized assistant
@@ -1681,9 +1717,9 @@ export class CliProviderInstance implements ProviderInstance {
1681
1717
  // (which also requires turnClosed and turn-scoping): the dashboard should
1682
1718
  // show the answer as soon as native-history has it, even if the FSM has
1683
1719
  // not yet ratified the turn end. getState() replaces it on the next turn.
1684
- const lastVisibleAssistant = this.lastVisibleAssistantSummary(externalMessages);
1685
- if (lastVisibleAssistant) {
1686
- this.lastCompletionSummary = { content: lastVisibleAssistant, receivedAt: Date.now() };
1720
+ const lastVisibleAssistant = this.lastVisibleAssistantSummaryDetail(externalMessages);
1721
+ if (lastVisibleAssistant.content) {
1722
+ this.lastCompletionSummary = { content: lastVisibleAssistant.content, receivedAt: Date.now(), sourceTimestampMs: lastVisibleAssistant.timestampMs };
1687
1723
  }
1688
1724
  return {
1689
1725
  present,
@@ -1745,7 +1781,11 @@ export class CliProviderInstance implements ProviderInstance {
1745
1781
  // sessions whose generating_completed is suppressed, and short-gen
1746
1782
  // settle paths), so the dashboard sees the answer even when no
1747
1783
  // agent:generating_completed is ever emitted. Native read already ran.
1748
- this.lastCompletionSummary = { content: externalSummary, receivedAt: Date.now() };
1784
+ // externalSummary is already turn-scoped (extractFinalSummaryFromMessagesAfter
1785
+ // dropped any bubble predating turnStartedAt), so it is in-turn by construction.
1786
+ // Record the turn boundary as its source timestamp so the weak-completion
1787
+ // fallback (cachedInTurnCompletionSummaryContent) accepts it.
1788
+ this.lastCompletionSummary = { content: externalSummary, receivedAt: Date.now(), sourceTimestampMs: typeof turnStartedAt === 'number' ? turnStartedAt : undefined };
1749
1789
  return externalSummary;
1750
1790
  }
1751
1791
  return parsedSummary || undefined;
@@ -1769,7 +1809,12 @@ export class CliProviderInstance implements ProviderInstance {
1769
1809
  parseError = error?.message || String(error);
1770
1810
  }
1771
1811
 
1772
- const evidence = this.completionFinalAssistantEvidence(parsed?.messages);
1812
+ // FALSE-IDLE Defect 1c: turn-scope the diagnostic's evidence probe too. Passing
1813
+ // pending.turnStartedAt makes completionHasFinalAssistantMessage reject a stale
1814
+ // mid-turn bubble (predating the turn) just as the finalization gate did, so the
1815
+ // diagnostic cannot credit finalAssistantPresent (or clear missing_final_assistant)
1816
+ // off a bubble the gate already rejected. With no boundary this is unchanged.
1817
+ const evidence = this.completionFinalAssistantEvidence(parsed?.messages, args.pending.turnStartedAt);
1773
1818
  if (evidence.source === 'external-native') {
1774
1819
  this.recordPendingTranscriptProbe(args.pending);
1775
1820
  }
@@ -1790,7 +1835,7 @@ export class CliProviderInstance implements ProviderInstance {
1790
1835
  // missing_final_assistant with an empty payload. Only ever UPGRADES a
1791
1836
  // point-sample miss — a genuine present=true is unchanged, and an empty cache
1792
1837
  // leaves the missing-evidence diagnostic exactly as before.
1793
- const cachedSummary = evidence.present ? '' : this.cachedCompletionSummaryContent();
1838
+ const cachedSummary = evidence.present ? '' : this.cachedInTurnCompletionSummaryContent(args.pending.turnStartedAt);
1794
1839
  const creditedFromCache = !evidence.present && cachedSummary.length > 0;
1795
1840
  const finalAssistantPresent = evidence.present || creditedFromCache;
1796
1841
  const finalAssistantEvidenceSource = evidence.present
@@ -2755,7 +2800,7 @@ export class CliProviderInstance implements ProviderInstance {
2755
2800
  // carries the summary that mesh_read_chat.summary already shows — consistent with
2756
2801
  // completionDiagnostic.finalAssistantPresent being credited from the same cache.
2757
2802
  finalSummary: (this.completionFinalSummary(this.adapter?.getScriptParsedStatus()?.messages, pending.turnStartedAt)
2758
- || this.cachedCompletionSummaryContent()
2803
+ || this.cachedInTurnCompletionSummaryContent(pending.turnStartedAt)
2759
2804
  || (blockReason.startsWith('parsed_status:') ? '' : undefined)),
2760
2805
  completionDiagnostic,
2761
2806
  });