@adhdev/daemon-core 0.9.82-rc.403 → 0.9.82-rc.405

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/dist/index.js CHANGED
@@ -399,10 +399,10 @@ function readInjected(value) {
399
399
  }
400
400
  function getDaemonBuildInfo() {
401
401
  if (cached) return cached;
402
- const commit = readInjected(true ? "9522954406c86758c979231d4f96b280d09efd7a" : void 0) ?? "unknown";
403
- const commitShort = readInjected(true ? "95229544" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
404
- const version = readInjected(true ? "0.9.82-rc.403" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
405
- const builtAt = readInjected(true ? "2026-06-27T17:53:59.574Z" : void 0);
402
+ const commit = readInjected(true ? "4e4b5f468d194f630073a66359898bce97fadf4b" : void 0) ?? "unknown";
403
+ const commitShort = readInjected(true ? "4e4b5f46" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
404
+ const version = readInjected(true ? "0.9.82-rc.405" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
405
+ const builtAt = readInjected(true ? "2026-06-28T03:54:34.483Z" : void 0);
406
406
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
407
407
  return cached;
408
408
  }
@@ -39691,6 +39691,7 @@ var COMPLETED_FINALIZATION_RETRY_MS = 1e3;
39691
39691
  var COMPLETED_FINALIZATION_MAX_WAIT_MS = 3e4;
39692
39692
  var NATIVE_HISTORY_MESH_IDLE_SETTLE_MS = 4e3;
39693
39693
  var USER_INPUT_ACK_DEDUP_WINDOW_MS = 6e4;
39694
+ var STARTUP_GRACE_IDLE_COLLAPSE_WINDOW_MS = 12e3;
39694
39695
  var TERMINAL_MESH_EVENTS = /* @__PURE__ */ new Set([
39695
39696
  "agent:generating_completed",
39696
39697
  "agent:stopped",
@@ -39956,6 +39957,23 @@ var CliProviderInstance = class _CliProviderInstance {
39956
39957
  // first sets it; the other becomes a no-op.
39957
39958
  agentReadyEmitted = false;
39958
39959
  generatingStartedAt = 0;
39960
+ // GENERATING-BOUNDARY (R4b): the per-turn taskId for which a startup-grace
39961
+ // started+completed pair was already synthesized. Both fast-collapse callers
39962
+ // (starting→idle transition AND the idle-stayed no-status-change poll) route
39963
+ // through maybeSynthesizeStartupGraceCollapse; the idle-stayed caller re-polls
39964
+ // steadily while the session sits idle, so this guard makes the synthesis fire
39965
+ // AT MOST ONCE per collapsed turn.
39966
+ fastCollapseSynthesizedTaskId = null;
39967
+ // GENERATING-BOUNDARY (R4c): the wall-clock moment the FSM's starting→idle
39968
+ // startup-grace collapse was observed (set ONCE, on the first starting→idle
39969
+ // transition this boot). The idle-stayed collapse window is anchored on THIS,
39970
+ // not on instance/boot time (this.startedAt): the FSM spends the full 8s
39971
+ // startup-grace sitting in 'starting' before collapsing, and a turn can be
39972
+ // dispatched a few seconds AFTER the collapse — measuring the window from boot
39973
+ // would have it already closed by the time that turn lands+completes (the live
39974
+ // R4b miss: collapse at boot+8s, dispatch at boot+12.4s > the 12s boot window).
39975
+ // Anchoring on the collapse moment makes the window cover dispatch-delay+turn.
39976
+ startupGraceCollapseAt = null;
39959
39977
  settings = {};
39960
39978
  monitor;
39961
39979
  generatingDebounceTimer = null;
@@ -41082,6 +41100,73 @@ var CliProviderInstance = class _CliProviderInstance {
41082
41100
  this.agentReadyEmitted = true;
41083
41101
  this.pushEvent({ event: "agent:ready", chatTitle, timestamp: now });
41084
41102
  }
41103
+ /**
41104
+ * GENERATING-BOUNDARY synthetic emit for a first turn that started AND finished
41105
+ * inside the startup-grace window without the FSM ever observing a 'generating'
41106
+ * frame (an unobservably-fast turn). Synthesizes the agent:generating_started +
41107
+ * agent:generating_completed pair so the mesh coordinator learns the worker went
41108
+ * idle. Returns true iff it synthesized.
41109
+ *
41110
+ * Two callers share this defense line:
41111
+ * - 'startup_grace_fast_collapse' — the starting→idle transition (the FSM whose
41112
+ * spec lacks/hadn't-synced the starting→busy edge collapses starting→idle
41113
+ * directly, with no intervening 'generating' frame).
41114
+ * - 'startup_grace_idle_turn_collapse' — the idle→idle no-status-change poll
41115
+ * (the launch settle already drained starting→idle BEFORE the first turn, so
41116
+ * the turn runs+completes while status stays 'idle' the whole time and
41117
+ * detectStatusTransition never re-enters its change block — the live rc.403
41118
+ * Probe1 miss).
41119
+ *
41120
+ * False-positive safety (must NOT fire on a benign boot): currentTurnTaskId is
41121
+ * set ONLY by onTurnStarted (a real turn STARTED this boot) and persists past
41122
+ * completion, so it excludes a true idle boot (null) and a queued-pending first
41123
+ * turn that only runs after grace (onTurnStarted not yet called → null).
41124
+ * !hasAdapterPendingResponse() excludes a turn still mid-flight. generating
41125
+ * never armed (generatingStartedAt===0 && !generatingDebouncePending) means the
41126
+ * whole idle→busy→idle never happened for this turn. The once-per-turn guard
41127
+ * (fastCollapseSynthesizedTaskId) keeps the re-polled idle-stayed caller from
41128
+ * re-emitting every poll.
41129
+ */
41130
+ maybeSynthesizeStartupGraceCollapse(chatTitle, now, reason) {
41131
+ const startedTurnTaskId = typeof this.adapter?.currentTurnTaskId === "string" && this.adapter.currentTurnTaskId.trim() ? this.adapter.currentTurnTaskId : void 0;
41132
+ const fastCollapsed = !!startedTurnTaskId && !this.hasAdapterPendingResponse() && !this.generatingStartedAt && !this.generatingDebouncePending;
41133
+ if (!fastCollapsed) return false;
41134
+ if (this.fastCollapseSynthesizedTaskId === startedTurnTaskId) return false;
41135
+ let fcFinalSummary;
41136
+ let fcEvidenceSource = "unavailable";
41137
+ try {
41138
+ const parsedMessages = this.adapter?.getScriptParsedStatus()?.messages;
41139
+ const evidence = this.completionFinalAssistantEvidence(parsedMessages);
41140
+ fcEvidenceSource = evidence.source;
41141
+ fcFinalSummary = extractFinalSummaryFromMessages(evidence.messages);
41142
+ } catch {
41143
+ }
41144
+ const missingEvidence = (this.provider.requiresFinalAssistantBeforeIdle === true || fcEvidenceSource === "external-native") && !fcFinalSummary;
41145
+ const hasMeshContext = !!(this.settings.meshNodeFor || this.settings.meshActiveTaskId || this.settings.launchedByCoordinator);
41146
+ if (missingEvidence && !hasMeshContext) {
41147
+ LOG.info("CLI", `[${this.type}] ${reason} suppressed: missing final assistant evidence, no mesh context (source=${fcEvidenceSource})`);
41148
+ return false;
41149
+ }
41150
+ this.fastCollapseSynthesizedTaskId = startedTurnTaskId;
41151
+ LOG.info("CLI", `[${this.type}] ${reason}: synthesizing started+completed (taskId=${startedTurnTaskId} source=${fcEvidenceSource} hadFinalSummary=${!!fcFinalSummary})`);
41152
+ this.pushEvent({ event: "agent:generating_started", chatTitle, timestamp: now });
41153
+ if (this.isMeshWorkerSession()) {
41154
+ traceMeshEventStage("fired", this.meshTraceCtx(), `${reason} (source=${fcEvidenceSource})`);
41155
+ }
41156
+ this.pushEvent({
41157
+ event: "agent:generating_completed",
41158
+ chatTitle,
41159
+ duration: 0,
41160
+ timestamp: now,
41161
+ finalSummary: fcFinalSummary,
41162
+ completionDiagnostic: {
41163
+ reason,
41164
+ finalAssistantEvidenceSource: fcEvidenceSource,
41165
+ ...missingEvidence ? { blockReason: "missing_final_assistant" } : {}
41166
+ }
41167
+ });
41168
+ return true;
41169
+ }
41085
41170
  detectStatusTransition() {
41086
41171
  const now = Date.now();
41087
41172
  const adapterStatus = this.adapter.getStatus({ allowParse: false });
@@ -41240,42 +41325,8 @@ var CliProviderInstance = class _CliProviderInstance {
41240
41325
  }
41241
41326
  } else if (newStatus === "idle" && this.lastStatus === "starting") {
41242
41327
  this.emitAgentReadyOnce(chatTitle, now);
41243
- const startedTurnTaskId = typeof this.adapter?.currentTurnTaskId === "string" && this.adapter.currentTurnTaskId.trim() ? this.adapter.currentTurnTaskId : void 0;
41244
- const fastCollapsed = !!startedTurnTaskId && !this.hasAdapterPendingResponse() && !this.generatingStartedAt && !this.generatingDebouncePending;
41245
- if (fastCollapsed) {
41246
- let fcFinalSummary;
41247
- let fcEvidenceSource = "unavailable";
41248
- try {
41249
- const parsedMessages = this.adapter?.getScriptParsedStatus()?.messages;
41250
- const evidence = this.completionFinalAssistantEvidence(parsedMessages);
41251
- fcEvidenceSource = evidence.source;
41252
- fcFinalSummary = extractFinalSummaryFromMessages(evidence.messages);
41253
- } catch {
41254
- }
41255
- const missingEvidence = (this.provider.requiresFinalAssistantBeforeIdle === true || fcEvidenceSource === "external-native") && !fcFinalSummary;
41256
- const hasMeshContext = !!(this.settings.meshNodeFor || this.settings.meshActiveTaskId || this.settings.launchedByCoordinator);
41257
- if (missingEvidence && !hasMeshContext) {
41258
- LOG.info("CLI", `[${this.type}] startup-grace fast-collapse suppressed: missing final assistant evidence, no mesh context (source=${fcEvidenceSource})`);
41259
- } else {
41260
- LOG.info("CLI", `[${this.type}] startup-grace fast-collapse: synthesizing started+completed (taskId=${startedTurnTaskId} source=${fcEvidenceSource} hadFinalSummary=${!!fcFinalSummary})`);
41261
- this.pushEvent({ event: "agent:generating_started", chatTitle, timestamp: now });
41262
- if (this.isMeshWorkerSession()) {
41263
- traceMeshEventStage("fired", this.meshTraceCtx(), `startup-grace fast-collapse (source=${fcEvidenceSource})`);
41264
- }
41265
- this.pushEvent({
41266
- event: "agent:generating_completed",
41267
- chatTitle,
41268
- duration: 0,
41269
- timestamp: now,
41270
- finalSummary: fcFinalSummary,
41271
- completionDiagnostic: {
41272
- reason: "startup_grace_fast_collapse",
41273
- finalAssistantEvidenceSource: fcEvidenceSource,
41274
- ...missingEvidence ? { blockReason: "missing_final_assistant" } : {}
41275
- }
41276
- });
41277
- }
41278
- }
41328
+ if (this.startupGraceCollapseAt === null) this.startupGraceCollapseAt = now;
41329
+ this.maybeSynthesizeStartupGraceCollapse(chatTitle, now, "startup_grace_fast_collapse");
41279
41330
  } else if (newStatus === "error") {
41280
41331
  if (this.generatingDebounceTimer) {
41281
41332
  clearTimeout(this.generatingDebounceTimer);
@@ -41314,6 +41365,9 @@ var CliProviderInstance = class _CliProviderInstance {
41314
41365
  }
41315
41366
  this.lastStatus = newStatus;
41316
41367
  }
41368
+ if (newStatus === "idle" && previousStatus === "idle" && this.startupGraceCollapseAt !== null && now - this.startupGraceCollapseAt < STARTUP_GRACE_IDLE_COLLAPSE_WINDOW_MS) {
41369
+ this.maybeSynthesizeStartupGraceCollapse(chatTitle, now, "startup_grace_idle_turn_collapse");
41370
+ }
41317
41371
  if (newStatus === "idle" && adapterStatus.fsmReadySeen === true && !this.agentReadyEmitted) {
41318
41372
  this.emitAgentReadyOnce(chatTitle, now);
41319
41373
  }