@adhdev/daemon-core 0.9.82-rc.491 → 0.9.82-rc.492

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.
@@ -48,6 +48,16 @@ export interface CliStateEngineCallbacks {
48
48
  onStatusChange(): void;
49
49
  onApplyParsedSession(session: ParsedSession): void;
50
50
  onTurnCompleted(): void;
51
+ /**
52
+ * FALSE-IDLE (Fix 2): true when the owning session is inside the post-approval
53
+ * resume grace — an autonomous auto-approving mesh session that resolved a modal
54
+ * within the resume-grace window. The engine cannot decide this on its own (it has
55
+ * no mesh/auto-approve awareness); the instance answers using the SAME
56
+ * `inApprovalResumeGrace` judgment Fix 1 uses, so the two fixes stay in lockstep.
57
+ * Optional: absent ⇒ treated as false (no hysteresis) so any non-instance embedder
58
+ * keeps the pre-fix behavior.
59
+ */
60
+ isInApprovalResumeGrace?(): boolean;
51
61
  }
52
62
  export declare class CliStateEngine {
53
63
  private readonly provider;
@@ -113,6 +123,8 @@ export declare class CliStateEngine {
113
123
  pendingScriptStatusSince: number;
114
124
  private pendingScriptStatusTimer;
115
125
  private idleFinishCandidate;
126
+ private approvalResumeDeferSince;
127
+ private approvalResumeDeferEpoch;
116
128
  /**
117
129
  * `finishResponse` produces the `generating → idle` transition that
118
130
  * coordinators interpret as "task complete". Some providers (antigravity-
@@ -201,6 +213,20 @@ export declare class CliStateEngine {
201
213
  private applyError;
202
214
  private maybeScheduleProviderErrorRetry;
203
215
  private applyIdle;
216
+ /**
217
+ * FALSE-IDLE (Fix 2): should applyIdle suppress the idle/finish for the current
218
+ * turn because we are inside the post-approval resume grace?
219
+ *
220
+ * True only when: (a) the owning instance reports it is an autonomous auto-approving
221
+ * mesh session that resolved a modal within the resume-grace window
222
+ * (isInApprovalResumeGrace callback — the SAME judgment Fix 1 uses), AND (b) the defer
223
+ * for THIS response epoch has not yet exceeded APPROVAL_RESUME_IDLE_DEFER_CAP_MS.
224
+ * The cap guarantees no infinite defer: a turn that genuinely ended right after an
225
+ * approval and stays silent past the cap stops being suppressed and finishes normally.
226
+ * The per-epoch anchor means a fresh turn/response restarts the clock.
227
+ */
228
+ private shouldDeferIdleForApprovalResume;
229
+ private clearApprovalResumeDefer;
204
230
  finishResponse(): void;
205
231
  private scheduleIdleFinish;
206
232
  private cancelPendingIdleFinish;
@@ -32,6 +32,7 @@ export declare class ProviderCliAdapter implements CliAdapter {
32
32
  private ptyProcess;
33
33
  private transportFactory;
34
34
  private onStatusChange;
35
+ private inApprovalResumeGraceProbe;
35
36
  readonly engine: CliStateEngine;
36
37
  private responseBuffer;
37
38
  private recentOutputBuffer;
@@ -137,6 +138,7 @@ export declare class ProviderCliAdapter implements CliAdapter {
137
138
  updateRuntimeSettings(settings: Record<string, any>): void;
138
139
  setServerConn(serverConn: any): void;
139
140
  setOnStatusChange(callback: () => void): void;
141
+ setInApprovalResumeGraceProbe(probe: () => boolean): void;
140
142
  setOnPtyData(callback: (data: string) => void): void;
141
143
  private flushPendingOutputParse;
142
144
  spawn(): Promise<void>;
package/dist/index.js CHANGED
@@ -414,10 +414,10 @@ function readInjected(value) {
414
414
  }
415
415
  function getDaemonBuildInfo() {
416
416
  if (cached) return cached;
417
- const commit = readInjected(true ? "5b9e1774e6eb6318b6484d9adc6c510e9d96ea8a" : void 0) ?? "unknown";
418
- const commitShort = readInjected(true ? "5b9e1774" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
419
- const version = readInjected(true ? "0.9.82-rc.491" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
420
- const builtAt = readInjected(true ? "2026-07-10T06:22:30.442Z" : void 0);
417
+ const commit = readInjected(true ? "d3ef86c2b3332b1ce289eb8d4193c7c945d39401" : void 0) ?? "unknown";
418
+ const commitShort = readInjected(true ? "d3ef86c2" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
419
+ const version = readInjected(true ? "0.9.82-rc.492" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
420
+ const builtAt = readInjected(true ? "2026-07-10T07:51:20.549Z" : void 0);
421
421
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
422
422
  return cached;
423
423
  }
@@ -24501,7 +24501,7 @@ var init_provider_cli_parse = __esm({
24501
24501
  });
24502
24502
 
24503
24503
  // src/cli-adapters/cli-state-engine.ts
24504
- var SCRIPT_STATUS_DEBOUNCE_MS, MAX_FINISH_RETRIES, FINISH_RETRY_DELAY_MS, MAX_TRACE_ENTRIES, APPROVAL_EXIT_TIMEOUT_MS, IDLE_CONFIRMATION_GRACE_MS, CliStateEngine;
24504
+ var SCRIPT_STATUS_DEBOUNCE_MS, MAX_FINISH_RETRIES, FINISH_RETRY_DELAY_MS, MAX_TRACE_ENTRIES, APPROVAL_EXIT_TIMEOUT_MS, IDLE_CONFIRMATION_GRACE_MS, APPROVAL_RESUME_IDLE_DEFER_CAP_MS, CliStateEngine;
24505
24505
  var init_cli_state_engine = __esm({
24506
24506
  "src/cli-adapters/cli-state-engine.ts"() {
24507
24507
  "use strict";
@@ -24514,6 +24514,7 @@ var init_cli_state_engine = __esm({
24514
24514
  MAX_TRACE_ENTRIES = 250;
24515
24515
  APPROVAL_EXIT_TIMEOUT_MS = 6e4;
24516
24516
  IDLE_CONFIRMATION_GRACE_MS = 2e3;
24517
+ APPROVAL_RESUME_IDLE_DEFER_CAP_MS = 18e3;
24517
24518
  CliStateEngine = class {
24518
24519
  constructor(provider, runner, transport, callbacks, timeouts) {
24519
24520
  this.provider = provider;
@@ -24603,6 +24604,12 @@ var init_cli_state_engine = __esm({
24603
24604
  pendingScriptStatusTimer = null;
24604
24605
  // ── Idle candidate ───────────────────────────────
24605
24606
  idleFinishCandidate = null;
24607
+ // FALSE-IDLE (Fix 2): wall-clock when the current post-approval resume-grace idle
24608
+ // defer began, scoped to a responseEpoch. Zero when not deferring. Bounds the defer
24609
+ // to APPROVAL_RESUME_IDLE_DEFER_CAP_MS so a turn that genuinely ended right after an
24610
+ // approval eventually finishes. Reset whenever a new turn/response starts or completes.
24611
+ approvalResumeDeferSince = 0;
24612
+ approvalResumeDeferEpoch = -1;
24606
24613
  // ── Idle confirmation grace ──────────────────────
24607
24614
  /**
24608
24615
  * `finishResponse` produces the `generating → idle` transition that
@@ -24816,6 +24823,8 @@ var init_cli_state_engine = __esm({
24816
24823
  this.activeModal = null;
24817
24824
  this.pendingScriptStatus = null;
24818
24825
  this.pendingScriptStatusSince = 0;
24826
+ this.approvalResumeDeferSince = 0;
24827
+ this.approvalResumeDeferEpoch = -1;
24819
24828
  }
24820
24829
  clearIdleFinishCandidate(reason) {
24821
24830
  if (!this.idleFinishCandidate) return;
@@ -25237,6 +25246,14 @@ var init_cli_state_engine = __esm({
25237
25246
  const idleReady = !modal && hasAssistantTurn && quietForMs >= idleQuietThresholdMs && screenStableMs >= idleFinishConfirmMs;
25238
25247
  const candidate = this.idleFinishCandidate;
25239
25248
  const candidateQuiet = !!candidate && candidate.responseEpoch === this.responseEpoch && candidate.lastOutputAt === snap.lastOutputAt && candidate.lastScreenChangeAt === snap.lastScreenChangeAt && assistantLength >= candidate.assistantLength && now - candidate.armedAt >= idleFinishConfirmMs;
25249
+ if (this.shouldDeferIdleForApprovalResume(now)) {
25250
+ this.clearIdleFinishCandidate("approval_resume_grace_defer");
25251
+ if (this.idleTimeout) clearTimeout(this.idleTimeout);
25252
+ this.idleTimeout = setTimeout(() => {
25253
+ if (this.isWaitingForResponse) this.evaluateSettled(this.transport.getSnapshot());
25254
+ }, this.timeouts.idleFinish);
25255
+ return;
25256
+ }
25240
25257
  if (idleReady && candidateQuiet) {
25241
25258
  this.clearIdleFinishCandidate("finish_response");
25242
25259
  if (this.idleTimeout) clearTimeout(this.idleTimeout);
@@ -25254,6 +25271,12 @@ var init_cli_state_engine = __esm({
25254
25271
  if (this.idleTimeout) clearTimeout(this.idleTimeout);
25255
25272
  this.idleTimeout = setTimeout(() => {
25256
25273
  if (this.isWaitingForResponse && !this.hasActionableApproval()) {
25274
+ if (this.shouldDeferIdleForApprovalResume(Date.now())) {
25275
+ this.idleTimeout = setTimeout(() => {
25276
+ if (this.isWaitingForResponse) this.evaluateSettled(this.transport.getSnapshot());
25277
+ }, this.timeouts.idleFinish);
25278
+ return;
25279
+ }
25257
25280
  if (this.shouldDeferIdleTimeoutFinish()) return;
25258
25281
  const parsed = this.runParseSession(this.transport.getSnapshot());
25259
25282
  if (this.shouldDeferFinishForTranscript(parsed)) {
@@ -25265,6 +25288,47 @@ var init_cli_state_engine = __esm({
25265
25288
  }
25266
25289
  }, this.timeouts.idleFinish);
25267
25290
  }
25291
+ /**
25292
+ * FALSE-IDLE (Fix 2): should applyIdle suppress the idle/finish for the current
25293
+ * turn because we are inside the post-approval resume grace?
25294
+ *
25295
+ * True only when: (a) the owning instance reports it is an autonomous auto-approving
25296
+ * mesh session that resolved a modal within the resume-grace window
25297
+ * (isInApprovalResumeGrace callback — the SAME judgment Fix 1 uses), AND (b) the defer
25298
+ * for THIS response epoch has not yet exceeded APPROVAL_RESUME_IDLE_DEFER_CAP_MS.
25299
+ * The cap guarantees no infinite defer: a turn that genuinely ended right after an
25300
+ * approval and stays silent past the cap stops being suppressed and finishes normally.
25301
+ * The per-epoch anchor means a fresh turn/response restarts the clock.
25302
+ */
25303
+ shouldDeferIdleForApprovalResume(now) {
25304
+ if (typeof this.callbacks.isInApprovalResumeGrace !== "function") {
25305
+ this.clearApprovalResumeDefer();
25306
+ return false;
25307
+ }
25308
+ let inGrace = false;
25309
+ try {
25310
+ inGrace = this.callbacks.isInApprovalResumeGrace() === true;
25311
+ } catch {
25312
+ inGrace = false;
25313
+ }
25314
+ if (!inGrace) {
25315
+ this.clearApprovalResumeDefer();
25316
+ return false;
25317
+ }
25318
+ if (this.approvalResumeDeferEpoch !== this.responseEpoch || this.approvalResumeDeferSince === 0) {
25319
+ this.approvalResumeDeferEpoch = this.responseEpoch;
25320
+ this.approvalResumeDeferSince = now;
25321
+ return true;
25322
+ }
25323
+ if (now - this.approvalResumeDeferSince >= APPROVAL_RESUME_IDLE_DEFER_CAP_MS) {
25324
+ return false;
25325
+ }
25326
+ return true;
25327
+ }
25328
+ clearApprovalResumeDefer() {
25329
+ this.approvalResumeDeferSince = 0;
25330
+ this.approvalResumeDeferEpoch = -1;
25331
+ }
25268
25332
  finishResponse() {
25269
25333
  if (this.submitPendingUntil > Date.now()) return;
25270
25334
  if (this.responseSettleIgnoreUntil > Date.now()) return;
@@ -25707,7 +25771,8 @@ var init_provider_cli_adapter = __esm({
25707
25771
  },
25708
25772
  onTurnCompleted: () => {
25709
25773
  this.responseBuffer = "";
25710
- }
25774
+ },
25775
+ isInApprovalResumeGrace: () => this.inApprovalResumeGraceProbe?.() === true
25711
25776
  },
25712
25777
  resolvedConfig.timeouts
25713
25778
  );
@@ -25739,6 +25804,9 @@ var init_provider_cli_adapter = __esm({
25739
25804
  ptyProcess = null;
25740
25805
  transportFactory;
25741
25806
  onStatusChange = null;
25807
+ // FALSE-IDLE (Fix 2): probe the owning instance for the post-approval resume grace.
25808
+ // Null until the instance registers it; the engine treats absence as "not in grace".
25809
+ inApprovalResumeGraceProbe = null;
25742
25810
  // ─── State machine engine ─────────────────────────
25743
25811
  engine;
25744
25812
  responseBuffer = "";
@@ -25982,6 +26050,12 @@ ${lastSnapshot}`;
25982
26050
  setOnStatusChange(callback) {
25983
26051
  this.onStatusChange = callback;
25984
26052
  }
26053
+ // FALSE-IDLE (Fix 2): the instance registers its inApprovalResumeGrace judgment so the
26054
+ // engine's applyIdle hysteresis can scope itself to autonomous auto-approving sessions
26055
+ // without the engine needing any mesh/auto-approve awareness of its own.
26056
+ setInApprovalResumeGraceProbe(probe) {
26057
+ this.inApprovalResumeGraceProbe = probe;
26058
+ }
25985
26059
  setOnPtyData(callback) {
25986
26060
  this.onPtyDataCallback = callback;
25987
26061
  }
@@ -45618,6 +45692,28 @@ var CliProviderInstance = class _CliProviderInstance {
45618
45692
  * the nudge was NOT deferred) and leaked to the coordinator.
45619
45693
  */
45620
45694
  static AUTO_APPROVE_MASK_STALL_MS = 10500;
45695
+ /**
45696
+ * FALSE-IDLE (inter-approval quiet valley): grace window after an auto-approve
45697
+ * (or mesh_approve) RESOLVES a modal during which a subsequent generating→idle
45698
+ * quiet valley must NOT be treated as turn completion.
45699
+ *
45700
+ * The RCA: auto-approve resolves a modal → the agent resumes the same turn →
45701
+ * between resolving that approval and preparing the next tool/approval the agent
45702
+ * falls briefly silent. The FSM sees idle + a recorded mid-turn assistant bubble
45703
+ * and fires an early agent:generating_completed even though the turn is still in
45704
+ * flight. Live evidence showed the same session resuming waiting_approval ~13s
45705
+ * after a "clean" completion emit.
45706
+ *
45707
+ * The window must be comfortably larger than the observed resume gap (~13s) so
45708
+ * the valley is bridged, but not so large that a turn that genuinely ended right
45709
+ * after an approval is held for an annoying stretch. 18s clears 13s with margin
45710
+ * while capping the worst-case extra hold on a truly-finished turn at 18s (still
45711
+ * well under COMPLETED_FINALIZATION_MAX_WAIT_MS's 30s hard bound). The recency is
45712
+ * measured from the engine's lastApprovalResolvedAt, which is stamped ONLY by
45713
+ * resolveModal (auto-approve fire / dashboard / mesh_approve) — so a plain turn
45714
+ * with no approval never carries recency and is never held (no regression).
45715
+ */
45716
+ static APPROVAL_RESUME_GRACE_MS = 18e3;
45621
45717
  adapter;
45622
45718
  context = null;
45623
45719
  events = [];
@@ -45765,6 +45861,9 @@ var CliProviderInstance = class _CliProviderInstance {
45765
45861
  this.adapter.setOnStatusChange(() => {
45766
45862
  this.detectStatusTransition();
45767
45863
  });
45864
+ if (typeof this.adapter.setInApprovalResumeGraceProbe === "function") {
45865
+ this.adapter.setInApprovalResumeGraceProbe(() => this.inApprovalResumeGrace());
45866
+ }
45768
45867
  await this.adapter.spawn();
45769
45868
  await this.enforceFreshSessionLaunchIfNeeded();
45770
45869
  await this.applyInitialThinkingLevelViaControl();
@@ -46653,6 +46752,9 @@ var CliProviderInstance = class _CliProviderInstance {
46653
46752
  if (adapterAny?.isWaitingForResponse === true) return { reason: "adapter_waiting_for_response", terminal: !approvalResolvedIdle };
46654
46753
  if (adapterAny?.currentTurnScope) return { reason: "adapter_turn_scope_active", terminal: !approvalResolvedIdle };
46655
46754
  if (this.hasAdapterPendingResponse()) return { reason: "adapter_pending_response", terminal: !approvalResolvedIdle };
46755
+ if (!approvalResolvedIdle && this.inApprovalResumeGrace()) {
46756
+ return { reason: "approval_resume_grace", terminal: false };
46757
+ }
46656
46758
  const partial = typeof this.adapter.getPartialResponse === "function" ? this.adapter.getPartialResponse() : "";
46657
46759
  if (typeof partial === "string" && partial.trim()) return { reason: "partial_response_pending", terminal: true };
46658
46760
  let parsed;
@@ -46814,6 +46916,24 @@ var CliProviderInstance = class _CliProviderInstance {
46814
46916
  isAutonomousMeshSession() {
46815
46917
  return this.isMeshWorkerSession() || !!this.settings.meshCoordinatorFor;
46816
46918
  }
46919
+ /**
46920
+ * FALSE-IDLE: are we inside the post-approval resume grace window? True when this
46921
+ * is an autonomous auto-approving mesh session AND the engine resolved a modal
46922
+ * (auto-approve / mesh_approve) within APPROVAL_RESUME_GRACE_MS. This is the single
46923
+ * "auto-approve recency" judgment shared by Fix 1 (the SETTLE-VALLEY completion
46924
+ * hold below) and Fix 2 (the FSM-level applyIdle hysteresis in cli-state-engine).
46925
+ *
46926
+ * Scoped to autonomous auto-approving sessions so a foreground/attended session,
46927
+ * or a session with auto-approve off (whose approvals a human answers), is never
46928
+ * held. The recency clock (adapter.lastApprovalResolvedAt) is 0 until the first
46929
+ * resolveModal, so a plain turn that never saw an approval always returns false.
46930
+ */
46931
+ inApprovalResumeGrace(now = Date.now()) {
46932
+ if (!this.isAutonomousMeshSession() || !this.shouldAutoApprove()) return false;
46933
+ const resolvedAt = typeof this.adapter?.lastApprovalResolvedAt === "number" ? this.adapter.lastApprovalResolvedAt : 0;
46934
+ if (resolvedAt <= 0) return false;
46935
+ return now - resolvedAt < _CliProviderInstance.APPROVAL_RESUME_GRACE_MS;
46936
+ }
46817
46937
  /**
46818
46938
  * ARCH-REFACTOR R1: the taskId to attribute the CURRENTLY-completing turn to.
46819
46939
  * Prefers the per-turn binding (engine.currentTurnTaskId, set when the turn was
@@ -47125,7 +47245,14 @@ var CliProviderInstance = class _CliProviderInstance {
47125
47245
  this.autoApproveLastModalSeenAt = now;
47126
47246
  const modalKind = typeof modal?.kind === "string" ? modal.kind : "approval";
47127
47247
  if (modalKind !== "approval") {
47128
- return autoApproveActive;
47248
+ const modalText = `${String(modal?.title || "")}
47249
+ ${String(modal?.message || "")}
47250
+ ${buttons.join("\n")}`;
47251
+ const looksLikeSelectionPicker = /Select (?:a |an )?(?:model|mode|option)\b|Switch between/i.test(modalText);
47252
+ const looksLikeConsent = looksLikeActiveApprovalPromptText(modalText) || /Do you want to (?:proceed|create|make|edit|apply|run|delete|modify|allow)\b|allow all edits\b|don'?t ask again\b/i.test(modalText) || hasNegativeApprovalOption(buttons) || hasReliableApprovalAffirmative(buttons);
47253
+ if (looksLikeSelectionPicker && !looksLikeConsent) {
47254
+ return autoApproveActive;
47255
+ }
47129
47256
  }
47130
47257
  const { index: buttonIndex, label: buttonLabel } = pickApprovalButton(buttons, this.provider);
47131
47258
  const hasReliableConsentAnchor = hasNegativeApprovalOption(buttons) || hasReliableApprovalAffirmative(buttons);