@adhdev/daemon-core 0.9.82-rc.454 → 0.9.82-rc.456

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.
@@ -25,7 +25,7 @@ import { LOG } from '../logging/logger.js';
25
25
  import { traceMeshEventStage, traceMeshEventDrop } from '../mesh/mesh-event-trace.js';
26
26
  import type { ChatMessage } from '../types.js';
27
27
  import { buildPersistedProviderEffectMessage, normalizeProviderEffects } from './control-effects.js';
28
- import { formatAutoApprovalMessage, pickApprovalButton, hasNegativeApprovalOption, looksLikeActiveApprovalPromptText } from './approval-utils.js';
28
+ import { formatAutoApprovalMessage, pickApprovalButton, hasNegativeApprovalOption, hasReliableApprovalAffirmative, looksLikeActiveApprovalPromptText } from './approval-utils.js';
29
29
  import { getCliScriptCommand, parseCliScriptResult } from './cli-script-results.js';
30
30
  import { mergeProviderPatchState, resolveProviderStateSurface } from './provider-patch-state.js';
31
31
  import { normalizeProviderSessionId } from './provider-session-id.js';
@@ -572,6 +572,13 @@ export class CliProviderInstance implements ProviderInstance {
572
572
  // mask is dropped so the real waiting_approval surfaces. Cleared when the episode ends
573
573
  // (modal genuinely gone, manual attendance takes over, or auto-approve fires).
574
574
  private autoApproveMaskSince = 0;
575
+ // NOTIF-APPROVAL-MASKED (Q1b): the autoApproveMaskSince episode value for which a
576
+ // stalled-approval coordinator nudge has already been emitted, so the nudge fires
577
+ // exactly once per stalled auto-approve episode (0 = none emitted). Reusing the
578
+ // per-episode mask-clock value as the key makes it provider-agnostic (no reliance on
579
+ // approvalEntrySeq) and self-resetting: each new episode gets a fresh
580
+ // autoApproveMaskSince timestamp, and the episode-end reset zeroes it.
581
+ private stalledApprovalNudgeEpisode = 0;
575
582
  // Provider-common manual-attendance signal: while a human is actively driving
576
583
  // this session from the dashboard, auto-approve holds so they can take manual
577
584
  // control. Background mesh workers are never attended → delegated auto-approve
@@ -2056,6 +2063,7 @@ export class CliProviderInstance implements ProviderInstance {
2056
2063
  // Manual attendance takes over — the modal stays surfaced (maybeAutoApproveStatus
2057
2064
  // returns false), so end the mask episode.
2058
2065
  this.autoApproveMaskSince = 0;
2066
+ this.stalledApprovalNudgeEpisode = 0;
2059
2067
  if (this.autoApproveSettleTimer) clearTimeout(this.autoApproveSettleTimer);
2060
2068
  this.autoApproveSettleTimer = setTimeout(() => {
2061
2069
  this.autoApproveSettleTimer = null;
@@ -2100,6 +2108,7 @@ export class CliProviderInstance implements ProviderInstance {
2100
2108
  // Modal has genuinely been gone past the hysteresis window → the episode ended;
2101
2109
  // end the mask episode too (a later approval starts a fresh stall clock).
2102
2110
  this.autoApproveMaskSince = 0;
2111
+ this.stalledApprovalNudgeEpisode = 0;
2103
2112
  if (this.autoApproveSettleTimer) { clearTimeout(this.autoApproveSettleTimer); this.autoApproveSettleTimer = null; }
2104
2113
  return autoApproveActive;
2105
2114
  }
@@ -2110,6 +2119,12 @@ export class CliProviderInstance implements ProviderInstance {
2110
2119
  // when zero so it survives modal-signature changes and hysteresis blips — it measures
2111
2120
  // the true age of the unresolved auto-approve, not the per-signature settle window.
2112
2121
  if (!this.autoApproveMaskSince) this.autoApproveMaskSince = now;
2122
+ // NOTIF-APPROVAL-MASKED (Q1b): once this episode has stalled past the mask threshold,
2123
+ // surface the raw waiting_approval to the mesh coordinator (decoupled from the dashboard
2124
+ // mask). Placed on the active-approval path here — the single choke point that owns the
2125
+ // mask-stall clock and is re-driven throughout a silent stall (getState heartbeat,
2126
+ // detectStatusTransition, recheckAutoApproveSettled). No-op until the stall threshold trips.
2127
+ this.maybeEmitStalledApprovalNudge(adapterStatus, now);
2113
2128
  const modal = adapterStatus.activeModal;
2114
2129
  // (fix) Do not auto-approve when no concrete modal/buttons are present.
2115
2130
  // Claude TUI flaps between paints; without this guard adapterStatus
@@ -2147,10 +2162,22 @@ export class CliProviderInstance implements ProviderInstance {
2147
2162
  return autoApproveActive;
2148
2163
  }
2149
2164
  const { index: buttonIndex, label: buttonLabel } = pickApprovalButton(buttons, this.provider);
2150
- if (buttonIndex < 0 || !hasNegativeApprovalOption(buttons)) {
2151
- // No affirmative matched, or no decline option present (→ not a real
2152
- // consent prompt, e.g. a picker that slipped past the kind gate).
2153
- // Surface the modal so the user decides; never pick blindly.
2165
+ // Structural decline anchor. A real approval offers BOTH an affirmative
2166
+ // and a decline but on a TALL Write/Edit diff the trailing "3. No"
2167
+ // scrolls off the captured frame, leaving only "1. Yes" + "2. Yes, allow
2168
+ // this session" so hasNegativeApprovalOption reads false (#137). A
2169
+ // scoped grant-affirmative ("Yes, allow … during this session" / "…don't
2170
+ // ask again") ONLY appears in a genuine consent modal (never a picker),
2171
+ // so it stands in for the off-frame decline as a reliable second anchor.
2172
+ // Conservative by construction: a picker without a grant-scope option
2173
+ // still bails here, and the fire below still picks the plain allow-once
2174
+ // "Yes" via pickApprovalButton, not the broader grant.
2175
+ const hasReliableConsentAnchor = hasNegativeApprovalOption(buttons)
2176
+ || hasReliableApprovalAffirmative(buttons);
2177
+ if (buttonIndex < 0 || !hasReliableConsentAnchor) {
2178
+ // No affirmative matched, or no decline / reliable grant option present
2179
+ // (→ not a real consent prompt, e.g. a picker that slipped past the
2180
+ // kind gate). Surface the modal so the user decides; never pick blindly.
2154
2181
  return autoApproveActive;
2155
2182
  }
2156
2183
  // Modal *identity* signature — the question/button set only, NO volatile
@@ -2215,6 +2242,7 @@ export class CliProviderInstance implements ProviderInstance {
2215
2242
  this.autoApproveInactiveSince = 0;
2216
2243
  // Fired (resolveModal in flight) — the episode resolved; end the mask-stall clock.
2217
2244
  this.autoApproveMaskSince = 0;
2245
+ this.stalledApprovalNudgeEpisode = 0;
2218
2246
  if (this.autoApproveBusyTimer) clearTimeout(this.autoApproveBusyTimer);
2219
2247
  this.autoApproveBusyTimer = setTimeout(() => {
2220
2248
  this.autoApproveBusy = false;
@@ -3124,7 +3152,16 @@ export class CliProviderInstance implements ProviderInstance {
3124
3152
  }
3125
3153
 
3126
3154
  /** @see ProviderInstance.noteManualInteraction */
3127
- noteManualInteraction(now = Date.now()): void {
3155
+ noteManualInteraction(now = Date.now(), opts?: { passive?: boolean }): void {
3156
+ // P1b (#137 secondary): a DELEGATED worker session must not treat a
3157
+ // passive dashboard view (foreground tab selection / panel open) as
3158
+ // manual attendance. A coordinator merely peeking at a worker's panel
3159
+ // would otherwise suppress that worker's delegated auto-approve for the
3160
+ // whole 60s window. Only explicit input/intervention (controlbar,
3161
+ // resolve_action, pty_input) attends a worker. Non-worker (foreground)
3162
+ // sessions keep noting on passive views so a user foregrounding their own
3163
+ // session still holds auto-approve to act on the modal themselves.
3164
+ if (opts?.passive && this.isMeshWorkerSession()) return;
3128
3165
  this.manualAttendance.note(now);
3129
3166
  }
3130
3167
 
@@ -3154,6 +3191,50 @@ export class CliProviderInstance implements ProviderInstance {
3154
3191
  && now - this.autoApproveMaskSince > CliProviderInstance.AUTO_APPROVE_MASK_STALL_MS;
3155
3192
  }
3156
3193
 
3194
+ /**
3195
+ * NOTIF-APPROVAL-MASKED (Q1b): surface a delegated worker's STALLED auto-approve modal
3196
+ * to the mesh COORDINATOR, decoupled from the dashboard visible-status mask.
3197
+ *
3198
+ * When auto-approve is configured but the episode never settles (modal parse miss / the
3199
+ * settle gate never satisfied), getState()/detectStatusTransition() fold the raw
3200
+ * `waiting_approval` into `generating` to suppress dashboard flicker — so
3201
+ * detectStatusTransition()'s `waiting_approval` arm never runs and NO agent:waiting_approval
3202
+ * event is emitted. The coordinator's real-time approval-nudge delivery then has no input and
3203
+ * the worker's stuck modal is never surfaced (the live ~25s stall). The dashboard mask is
3204
+ * intentional and stays; this emits the coordinator nudge exactly ONCE, gated on the SAME
3205
+ * raw-waiting_approval + mask-stalled signal resolveModalParkStatus() distinguishes, the
3206
+ * instant the mask-stall threshold trips (the same moment getState un-folds the mask).
3207
+ *
3208
+ * Only delegated worker sessions qualify: a foreground session has no coordinator to notify,
3209
+ * and its own dashboard mask already reveals the modal on stall. A normally-resolving
3210
+ * auto-approve never reaches AUTO_APPROVE_MASK_STALL_MS, so it emits nothing here; and if a
3211
+ * masked approval clears just as this fires, rc.455's isApprovalNudgeResolved stale-drop
3212
+ * discards the nudge coordinator-side without noise. Dedup is per-episode (keyed on the
3213
+ * mask-clock value) so a modal that flaps between parsed/unparsed states is announced once.
3214
+ */
3215
+ private maybeEmitStalledApprovalNudge(adapterStatus: any, now: number): void {
3216
+ if (!this.isMeshWorkerSession()) return;
3217
+ if (adapterStatus?.status !== 'waiting_approval') return;
3218
+ if (!this.autoApproveMaskStalled(now)) return;
3219
+ // Exactly once per stalled episode (autoApproveMaskSince uniquely identifies it).
3220
+ if (this.stalledApprovalNudgeEpisode === this.autoApproveMaskSince) return;
3221
+ this.stalledApprovalNudgeEpisode = this.autoApproveMaskSince;
3222
+ const modal = adapterStatus.activeModal;
3223
+ const dirName = workingDirBasename(this.workingDir);
3224
+ const chatTitle = `${this.provider.name} · ${dirName}`;
3225
+ this.appendRuntimeSystemMessage(
3226
+ this.formatApprovalRequestMessage(modal?.message, modal?.buttons),
3227
+ `approval_request:${now}`,
3228
+ now,
3229
+ );
3230
+ this.pushEvent({
3231
+ event: 'agent:waiting_approval', chatTitle, timestamp: now,
3232
+ modalMessage: modal?.message,
3233
+ modalButtons: modal?.buttons,
3234
+ });
3235
+ LOG.info('CLI', `[${this.type}] stalled auto-approve nudge → coordinator (masked ${Math.round((now - this.autoApproveMaskSince) / 1000)}s)`);
3236
+ }
3237
+
3157
3238
  private recordAutoApproval(modalMessage?: string, buttonLabel?: string, now = Date.now()): void {
3158
3239
  this.appendRuntimeSystemMessage(
3159
3240
  formatAutoApprovalMessage(modalMessage, buttonLabel),
@@ -83,3 +83,23 @@ export const MANUAL_ATTENDANCE_COMMANDS: ReadonlySet<string> = new Set([
83
83
  'resolve_action',
84
84
  'pty_input',
85
85
  ]);
86
+
87
+ /**
88
+ * The subset of {@link MANUAL_ATTENDANCE_COMMANDS} that are PASSIVE view-only
89
+ * actions — foregrounding a session's tab / opening its panel. They convey "I am
90
+ * looking at this session", not "I am driving it", and carry no user input.
91
+ *
92
+ * For a foreground (base-node) session these still attend: a user who
93
+ * foregrounds their own session should get the quiet window so an incoming
94
+ * approval stays visible for them to act on. But for a DELEGATED worker session
95
+ * a passive peek must NOT attend — a coordinator merely opening a worker's panel
96
+ * to watch progress would otherwise suppress that worker's delegated
97
+ * auto-approve for the whole window (secondary cause, #137). The per-instance
98
+ * hook decides: it drops a passive stamp only when the session is a delegated
99
+ * worker, so explicit input (controlbar / resolve_action / pty_input) still
100
+ * attends a worker and a foreground session is unaffected.
101
+ */
102
+ export const MANUAL_ATTENDANCE_PASSIVE_VIEW_COMMANDS: ReadonlySet<string> = new Set([
103
+ 'select_session',
104
+ 'open_panel',
105
+ ]);
@@ -232,8 +232,13 @@ export interface ProviderInstance {
232
232
  * input). Provider-common signal that suppresses auto-approve for a short
233
233
  * window so the user can drive the session manually; background mesh worker
234
234
  * sessions never receive it, so their delegated auto-approve is unaffected.
235
+ *
236
+ * `opts.passive` marks a view-only action (select_session / open_panel). A
237
+ * delegated worker session ignores passive stamps so a coordinator merely
238
+ * watching its panel does not suppress its delegated auto-approve; explicit
239
+ * input still attends. Foreground sessions attend on passive views too.
235
240
  */
236
- noteManualInteraction?(now?: number): void;
241
+ noteManualInteraction?(now?: number, opts?: { passive?: boolean }): void;
237
242
 
238
243
  /** cleanup */
239
244
  dispose(): void;
@@ -63,7 +63,12 @@ export interface ModalTuiSpec {
63
63
 
64
64
  // ─── Helpers ───────────────────────────────────────────────────────────
65
65
 
66
- const SEPARATOR_RE = /^(?:─|━|═|━){10,}\s*$/;
66
+ // A horizontal rule line. Covers solid box-drawing rules (─ ━ ═) AND the dashed
67
+ // variants (╌ ╍ ┄ ┅ ┈ ┉) that Claude Code draws as the INNER separators around a
68
+ // Write/Edit diff body. This matches the coverage of the claude-cli v4 FSM spec
69
+ // anchor `^[─╌]+$` (issue #137) so the SDK-v1 parser recognizes the same modal
70
+ // frames the FSM does — a dashed rule is a separator, not modal content.
71
+ const SEPARATOR_RE = /^[─━═╌╍┄┅┈┉]{10,}\s*$/;
67
72
 
68
73
  function compile(re: string, flags?: string): RegExp {
69
74
  try {
@@ -119,7 +124,13 @@ function scopeLines(
119
124
  }
120
125
  }
121
126
  }
122
- if (lastSep >= 0 && prevSep >= 0) {
127
+ // Only scope to the separator frame when it actually BRACKETS the question
128
+ // line. Claude Write/Edit modals draw dashed (╌) inner rules around the diff
129
+ // body, so the last two separators can enclose the file diff while the
130
+ // question + button block sit BELOW the lower dashed rule. Scoping to that
131
+ // inner frame would drop every button (→ null → missed auto-approve, #137).
132
+ // When the question is outside the frame, fall through to a window around it.
133
+ if (lastSep >= 0 && prevSep >= 0 && questionIndex >= prevSep && questionIndex < lastSep + 1) {
123
134
  return { start: prevSep, end: lastSep + 1 };
124
135
  }
125
136
  // Fallback: window around question line.