@adhdev/daemon-core 1.0.28-rc.11 → 1.0.28-rc.13

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.mjs CHANGED
@@ -786,10 +786,10 @@ function readInjected(value) {
786
786
  }
787
787
  function getDaemonBuildInfo() {
788
788
  if (cached) return cached;
789
- const commit = readInjected(true ? "5cd04eec1e043188c3ef97821372ad5ff615cd04" : void 0) ?? "unknown";
790
- const commitShort = readInjected(true ? "5cd04eec" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
791
- const version = readInjected(true ? "1.0.28-rc.11" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
792
- const builtAt = readInjected(true ? "2026-07-26T07:08:19.328Z" : void 0);
789
+ const commit = readInjected(true ? "200c050e12084938c52f329a7531fd59a7cf5064" : void 0) ?? "unknown";
790
+ const commitShort = readInjected(true ? "200c050e" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
791
+ const version = readInjected(true ? "1.0.28-rc.13" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
792
+ const builtAt = readInjected(true ? "2026-07-26T08:47:54.956Z" : void 0);
793
793
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
794
794
  return cached;
795
795
  }
@@ -50437,18 +50437,20 @@ var CliProviderInstance = class _CliProviderInstance {
50437
50437
  // MESH_WORKER_STALL_REFIRE_COOLDOWN_MS between successive emissions across
50438
50438
  // anchor re-arms (the per-anchor guard only covers a single continuous stall).
50439
50439
  meshStallLastFiredAt = -1;
50440
- // KIMI-MESH-COMPLETION-EMIT (axis 1): the native-source transcript progress
50441
- // fingerprint (record count + source mtime) observed the LAST time the stall
50442
- // watchdog checked a native-source provider (transcriptAuthority=provider e.g.
50443
- // kimi wire.jsonl). A pure-PTY native-source worker running a long, screen-quiet
50444
- // tool (no viewport bytes for minutes) looks stalled by the lastOutputAt clock
50445
- // even though its transcript file is still growing. Before firing the stall, we
50446
- // compare the current transcript fingerprint against this snapshot; if the
50447
- // transcript advanced, the "stall" is a false positive of PTY-render stasis, so
50448
- // we re-arm the anchor instead of paging the coordinator (whose no_progress
50449
- // handling can lead to the worker being stopped mid-work → completion never
50450
- // emitted). null = not yet sampled for this session/anchor.
50451
- meshStallNativeTranscriptSample = null;
50440
+ // KIMI-MESH-COMPLETION-EMIT (axis 1) TX-FSM Stage 1: whether the stall
50441
+ // watchdog has consumed a usable native-transcript SIGNAL SNAPSHOT for the
50442
+ // current stall episode. A pure-PTY native-source worker running a long,
50443
+ // screen-quiet tool (no viewport bytes for minutes) looks stalled by the
50444
+ // lastOutputAt clock even though its transcript file is still growing.
50445
+ // Before firing the stall, the watchdog consults the shared
50446
+ // TranscriptSignalSource's in_turn_progress signal; if the transcript is
50447
+ // advancing, the "stall" is a false positive of PTY-render stasis, so we
50448
+ // re-arm the anchor instead of paging the coordinator (whose no_progress
50449
+ // handling can lead to the worker being stopped mid-work → completion
50450
+ // never emitted). The FIRST usable sample of an episode still re-arms
50451
+ // unconditionally (no episode-scoped baseline exists yet to prove stasis
50452
+ // against) — the historical `!prev → advanced` semantics, preserved.
50453
+ meshStallTranscriptSignalSampled = false;
50452
50454
  // FALSE-IDLE continuity epoch: monotonically bumped on EVERY entry into a busy
50453
50455
  // phase (→generating or →waiting_approval). The completedDebouncePending snapshots
50454
50456
  // this value at arm time (busyEpochAtArm); the flush guard requires it UNCHANGED
@@ -51246,10 +51248,17 @@ var CliProviderInstance = class _CliProviderInstance {
51246
51248
  completedDebounceTimer = null;
51247
51249
  completedDebouncePending = null;
51248
51250
  lastExternalCompletionProbe = null;
51249
- /** TX-FSM Stage 0 (shadow): lazily-created transcript signal normalizer.
51250
- * Fed ONLY by transcript reads this instance already performs — it adds
51251
- * zero I/O and its output never feeds back into any verdict. */
51251
+ /** TX-FSM: lazily-created transcript signal normalizer. Fed ONLY by
51252
+ * transcript reads this instance already performs — it adds zero I/O.
51253
+ * Stage 0: its output was a pure shadow observation for the FSM driver.
51254
+ * Stage 1: the instance's own stall/growth-hold judgments consume the
51255
+ * normalized snapshot too (single source of truth). */
51252
51256
  transcriptSignalSource = null;
51257
+ /** TX-FSM Stage 1: the latest snapshot the source produced (set inside
51258
+ * publishTranscriptSignalObservation). Consumed the same tick by the
51259
+ * stall-path / growth-hold judgments via probeNativeTranscriptSignals —
51260
+ * never treated as fresh across ticks. */
51261
+ lastTranscriptSignalSnapshot = null;
51253
51262
  /**
51254
51263
  * The final assistant summary of the last completed turn, cached at
51255
51264
  * completion-emit time. For a native-source provider (antigravity) whose
@@ -51427,19 +51436,21 @@ var CliProviderInstance = class _CliProviderInstance {
51427
51436
  return restoredHistory.messages;
51428
51437
  }
51429
51438
  /**
51430
- * TX-FSM Stage 0 (shadow): normalize the transcript read that JUST
51431
- * happened into a SignalSnapshot and inject it into the FSM driver as a
51432
- * pure observation (daemon → SpecCliAdapter → FsmDriver). Fed ONLY by
51433
- * reads this method's caller already performs — it adds zero I/O, so the
51434
- * getState() zero-native-read invariant and the stall-path read cadence
51435
- * are untouched. The snapshot is shadow data: nothing on this path feeds
51436
- * back into completion/stall/redrive verdicts. Fail-open end to end a
51437
- * missing adapter hook (non-spec providers), an unresolved transcript, or
51438
- * any throw degrades to "no observation", never to a wedge.
51439
+ * TX-FSM: normalize the transcript read that JUST happened into a
51440
+ * SignalSnapshot. Stage 0 injected it into the FSM driver as a pure
51441
+ * shadow observation (daemon → SpecCliAdapter → FsmDriver); Stage 1
51442
+ * additionally caches it (lastTranscriptSignalSnapshot) so the instance's
51443
+ * OWN stall/growth-hold judgments consume the SAME normalized snapshot
51444
+ * instead of re-running private transcript scans. Fed ONLY by reads this
51445
+ * method's caller already performs it adds zero I/O, so the getState()
51446
+ * zero-native-read invariant and the stall-path read cadence are
51447
+ * untouched. The source update runs regardless of the adapter hook so a
51448
+ * non-spec provider still produces the instance-side snapshot (the FSM
51449
+ * injection is simply skipped there). Fail-open end to end — an
51450
+ * unresolved transcript or any throw degrades to "no observation", never
51451
+ * to a wedge.
51439
51452
  */
51440
51453
  publishTranscriptSignalObservation(messages, error = false) {
51441
- const adapter = this.adapter;
51442
- if (typeof adapter?.setSignalObservation !== "function") return;
51443
51454
  try {
51444
51455
  if (!this.transcriptSignalSource) {
51445
51456
  this.transcriptSignalSource = new TranscriptSignalSource({
@@ -51449,7 +51460,8 @@ var CliProviderInstance = class _CliProviderInstance {
51449
51460
  profile: resolveTranscriptAuthorityProfile(this.provider),
51450
51461
  turnStartedAt: () => {
51451
51462
  const t = this.adapter?.currentTurnStartedAt;
51452
- return typeof t === "number" && Number.isFinite(t) ? t : void 0;
51463
+ if (typeof t === "number" && Number.isFinite(t)) return t;
51464
+ return this.meshTaskInjectedAt > 0 ? this.meshTaskInjectedAt : void 0;
51453
51465
  },
51454
51466
  // Reuse the exact completion machinery (I1) for the
51455
51467
  // final_assistant_present signal rather than duplicating
@@ -51461,7 +51473,11 @@ var CliProviderInstance = class _CliProviderInstance {
51461
51473
  const snapshot = this.transcriptSignalSource.update(
51462
51474
  { messages, probe: this.lastExternalCompletionProbe, error }
51463
51475
  );
51464
- adapter.setSignalObservation(snapshot);
51476
+ this.lastTranscriptSignalSnapshot = snapshot;
51477
+ const adapter = this.adapter;
51478
+ if (typeof adapter?.setSignalObservation === "function") {
51479
+ adapter.setSignalObservation(snapshot);
51480
+ }
51465
51481
  } catch {
51466
51482
  }
51467
51483
  }
@@ -51954,17 +51970,17 @@ var CliProviderInstance = class _CliProviderInstance {
51954
51970
  const threshold = turnActive ? _CliProviderInstance.MESH_WORKER_STALL_TURN_THRESHOLD_MS : _CliProviderInstance.MESH_WORKER_STALL_IDLE_THRESHOLD_MS;
51955
51971
  const stalledMs = now - this.meshStallAnchorAt;
51956
51972
  if (stalledMs < threshold) return;
51957
- const nativeSample = this.sampleNativeTranscriptProgress();
51958
- if (nativeSample) {
51959
- const prev = this.meshStallNativeTranscriptSample;
51960
- const advanced = !prev || nativeSample.msgCount > prev.msgCount || nativeSample.sourceMtimeMs > prev.sourceMtimeMs;
51961
- this.meshStallNativeTranscriptSample = nativeSample;
51962
- if (advanced) {
51973
+ const transcriptSignals = this.probeNativeTranscriptSignals();
51974
+ if (transcriptSignals?.snapshot?.available === true) {
51975
+ const firstSampleThisEpisode = !this.meshStallTranscriptSignalSampled;
51976
+ this.meshStallTranscriptSignalSampled = true;
51977
+ const signalDetail = transcriptSignals.snapshot.detail;
51978
+ if (firstSampleThisEpisode || transcriptSignals.snapshot.signals.in_turn_progress === true) {
51963
51979
  if (this.isMeshWorkerSession()) {
51964
51980
  traceMeshEventDrop(
51965
51981
  "mesh_worker_stall_transcript_advancing",
51966
51982
  this.meshTraceCtx("monitor:no_progress"),
51967
- `msgCount=${nativeSample.msgCount} sourceMtime=${nativeSample.sourceMtimeMs} (PTY quiet ${Math.round(stalledMs / 1e3)}s but transcript advancing)`
51983
+ `msgCount=${signalDetail.msgCount} sourceMtime=${signalDetail.sourceMtimeMs} (PTY quiet ${Math.round(stalledMs / 1e3)}s but transcript advancing)`
51968
51984
  );
51969
51985
  }
51970
51986
  this.meshStallAnchorAt = now;
@@ -51972,7 +51988,7 @@ var CliProviderInstance = class _CliProviderInstance {
51972
51988
  return;
51973
51989
  }
51974
51990
  }
51975
- if (this.tryReconcileTranscriptCompletionForStall(observedStatus)) {
51991
+ if (this.tryReconcileTranscriptCompletionForStall(observedStatus, transcriptSignals)) {
51976
51992
  this.meshStallEmittedForAnchor = true;
51977
51993
  return;
51978
51994
  }
@@ -52012,38 +52028,45 @@ var CliProviderInstance = class _CliProviderInstance {
52012
52028
  this.meshStallEmittedForAnchor = false;
52013
52029
  this.meshStallTurnActiveLast = void 0;
52014
52030
  this.meshStallLastFiredAt = -1;
52015
- this.meshStallNativeTranscriptSample = null;
52031
+ this.meshStallTranscriptSignalSampled = false;
52016
52032
  }
52033
+ /** The result of one native-transcript signal probe: the normalized
52034
+ * snapshot the shared TranscriptSignalSource produced from the read, and
52035
+ * the very messages it was normalized from (so a judgment site can pull
52036
+ * a payload — e.g. the final summary — from the SAME read with zero
52037
+ * added I/O). */
52017
52038
  /**
52018
- * KIMI-MESH-COMPLETION-EMIT (axis 1). For a native-source provider
52019
- * (transcriptAuthority=provider its authoritative history is an on-disk
52020
- * transcript file, e.g. kimi's wire.jsonl), sample the transcript's current
52021
- * progress fingerprint (record count + source-file mtime) WITHOUT parsing the
52022
- * PTY. Used by the stall watchdog to distinguish "PTY render is quiet but the
52023
- * worker is still doing long tool work (transcript growing)" from a genuine
52024
- * wedge. Returns null for a pure-PTY provider (no native source) or when the
52025
- * source cannot be resolved this tick — the caller then falls back to the
52026
- * unchanged lastOutputAt-only judgment.
52039
+ * TX-FSM Stage 1 the single native-transcript signal probe (replaces
52040
+ * the Stage-0 sampleNativeTranscriptProgress fingerprint sampler). For a
52041
+ * native-source provider (its authoritative history is an on-disk
52042
+ * transcript file, e.g. kimi's wire.jsonl), perform the read this
52043
+ * judgment point already owns SAME cadence as before, one
52044
+ * readExternalCompletionMessages() per call, never more and return the
52045
+ * NORMALIZED SignalSnapshot the shared TranscriptSignalSource produced
52046
+ * from it (publishTranscriptSignalObservation runs inside the read), plus
52047
+ * the messages that read returned. Judgment sites (the stall watchdog's
52048
+ * transcript-advancing axis, the completion growth-hold, the stall-path
52049
+ * completion rescue) consume the snapshot's SIGNALS instead of running
52050
+ * their own fingerprint/freshness/final-assistant scans — one source of
52051
+ * truth for "what does the transcript say right now".
52027
52052
  *
52028
- * Generalized on the provider's native-source flag, NOT a hardcoded provider
52029
- * type, so every current and future pure-PTY long-tool native-source provider
52030
- * benefits. Cheap enough for the stall path: it runs only at the stall threshold
52031
- * (≥180s of PTY stasis), never on the routine 5s tick.
52053
+ * Class gating goes through resolveTranscriptAuthorityProfile ONLY.
52054
+ * Returns null for a non-native-source class (nothing to signal from) and
52055
+ * a null snapshot when the read threw callers keep their fail-open
52056
+ * fallbacks ("couldn't tell" never blocks an idle verdict and never
52057
+ * fabricates a completion). Cheap enough for the stall path: it runs
52058
+ * only at the stall threshold (≥180s of PTY stasis) or during an armed
52059
+ * completion-debounce retry, never on the routine 5s tick.
52032
52060
  */
52033
- sampleNativeTranscriptProgress() {
52034
- if (!isNativeSourceCanonicalHistory(this.provider?.nativeHistory)) return null;
52061
+ probeNativeTranscriptSignals() {
52062
+ if (resolveTranscriptAuthorityProfile(this.provider).class !== "native-source") return null;
52035
52063
  let messages = null;
52036
52064
  try {
52037
52065
  messages = this.readExternalCompletionMessages();
52038
52066
  } catch {
52039
- return null;
52067
+ return { snapshot: null, messages: null };
52040
52068
  }
52041
- const probe = this.lastExternalCompletionProbe;
52042
- if (!probe) return null;
52043
- return {
52044
- msgCount: typeof probe.msgCount === "number" ? probe.msgCount : Array.isArray(messages) ? messages.length : 0,
52045
- sourceMtimeMs: typeof probe.sourceMtimeMs === "number" ? probe.sourceMtimeMs : 0
52046
- };
52069
+ return { snapshot: this.lastTranscriptSignalSnapshot, messages };
52047
52070
  }
52048
52071
  /**
52049
52072
  * KIMI-MESH-COMPLETION-EMIT (axis 2). Last-chance completion emit for a mesh
@@ -52132,8 +52155,22 @@ var CliProviderInstance = class _CliProviderInstance {
52132
52155
  * false for a daemon-owned provider and for a genuinely mid-turn / wedged
52133
52156
  * worker with no in-turn final assistant, so a real stall still fires
52134
52157
  * unchanged. Evidence bar is identical to flushMeshCompletionBeforeCleanup.
52158
+ *
52159
+ * TX-FSM Stage 1 (FIX 3 probe delegation): for a native-source class the
52160
+ * completion VERDICT is the shared TranscriptSignalSource's
52161
+ * final_assistant_present signal, normalized from the ONE transcript read
52162
+ * the stall watchdog already performed this tick (passed in as
52163
+ * `transcriptSignals`) — not a second private read + scan. The emit
52164
+ * payload (finalSummary) is extracted from the SAME messages the signal
52165
+ * was normalized from, with the SAME turn boundary the legacy path used,
52166
+ * so the extraction re-proves the turn scope the signal checked. Fail-open
52167
+ * both ways: no usable snapshot (read failed / unresolved / a pure-PTY
52168
+ * class, which has no native signal by construction) → the legacy
52169
+ * class-appropriate evidence path (completionFinalSummary), unchanged; and
52170
+ * a present-but-unextractable signal yields false rather than a
52171
+ * payload-less emit.
52135
52172
  */
52136
- tryReconcileTranscriptCompletionForStall(observedStatus) {
52173
+ tryReconcileTranscriptCompletionForStall(observedStatus, transcriptSignals) {
52137
52174
  const profile = resolveTranscriptAuthorityProfile(this.provider);
52138
52175
  if (profile.class === "daemon-owned") return false;
52139
52176
  if (observedStatus !== "idle") return false;
@@ -52151,10 +52188,19 @@ var CliProviderInstance = class _CliProviderInstance {
52151
52188
  parsedMessages = void 0;
52152
52189
  }
52153
52190
  let finalSummary;
52154
- try {
52155
- finalSummary = this.completionFinalSummary(parsedMessages, turnStartedAt);
52156
- } catch {
52157
- finalSummary = void 0;
52191
+ const signalSnapshot = transcriptSignals?.snapshot;
52192
+ if (profile.class === "native-source" && signalSnapshot?.available === true) {
52193
+ if (signalSnapshot.signals.final_assistant_present !== true) return false;
52194
+ finalSummary = extractFinalSummaryFromMessagesAfter(
52195
+ Array.isArray(transcriptSignals?.messages) ? transcriptSignals.messages : [],
52196
+ turnStartedAt
52197
+ ) || void 0;
52198
+ } else {
52199
+ try {
52200
+ finalSummary = this.completionFinalSummary(parsedMessages, turnStartedAt);
52201
+ } catch {
52202
+ finalSummary = void 0;
52203
+ }
52158
52204
  }
52159
52205
  if (!finalSummary) return false;
52160
52206
  const diagnosticSource = profile.class === "pure-pty" ? "stall_pure_pty_transcript_completion" : "stall_native_source_transcript_completion";
@@ -52421,24 +52467,25 @@ var CliProviderInstance = class _CliProviderInstance {
52421
52467
  const isTranscriptEvidenceGate = block2.allowTimeout === true;
52422
52468
  LOG.debug("CLI", `[${this.type}] finalization block: reason=${blockReason} terminal=${block2.terminal} allowTimeout=${isTranscriptEvidenceGate} waitedMs=${waitedMs} maxWait=${COMPLETED_FINALIZATION_MAX_WAIT_MS}`);
52423
52469
  if (blockReason === "missing_final_assistant" && block2.noExternalTranscriptSource === true) {
52424
- let nativeSample = null;
52470
+ let growthSnapshot = null;
52425
52471
  try {
52426
- nativeSample = this.sampleNativeTranscriptProgress();
52472
+ growthSnapshot = this.probeNativeTranscriptSignals()?.snapshot ?? null;
52427
52473
  } catch {
52428
- nativeSample = null;
52474
+ growthSnapshot = null;
52429
52475
  }
52430
- const sourceMtimeMs = nativeSample?.sourceMtimeMs ?? 0;
52431
- if (nativeSample && sourceMtimeMs > 0 && Date.now() - sourceMtimeMs < MISSING_ASSISTANT_TRANSCRIPT_GROWTH_QUIET_MS) {
52476
+ if (growthSnapshot?.available === true && growthSnapshot.signals.transcript_growing === true) {
52477
+ const growthDetail = growthSnapshot.detail;
52478
+ const mtimeAgeMs = growthDetail.ageMs ?? 0;
52432
52479
  if (pending.loggedBlockReason !== "native_transcript_advancing") {
52433
- LOG.info("CLI", `[${this.type}] holding pending completed (native_transcript_advancing: msgCount=${nativeSample.msgCount} mtimeAge=${Date.now() - sourceMtimeMs}ms < ${MISSING_ASSISTANT_TRANSCRIPT_GROWTH_QUIET_MS}ms) \u2014 transcript still growing, screen-idle verdict not trusted`);
52480
+ LOG.info("CLI", `[${this.type}] holding pending completed (native_transcript_advancing: msgCount=${growthDetail.msgCount} mtimeAge=${mtimeAgeMs}ms < ${MISSING_ASSISTANT_TRANSCRIPT_GROWTH_QUIET_MS}ms) \u2014 transcript still growing, screen-idle verdict not trusted`);
52434
52481
  if (this.isMeshWorkerSession()) {
52435
- traceMeshEventDrop("completion_gate_hold", this.meshTraceCtx(), `native_transcript_advancing msgCount=${nativeSample.msgCount} mtimeAge=${Date.now() - sourceMtimeMs}ms`);
52482
+ traceMeshEventDrop("completion_gate_hold", this.meshTraceCtx(), `native_transcript_advancing msgCount=${growthDetail.msgCount} mtimeAge=${mtimeAgeMs}ms`);
52436
52483
  }
52437
52484
  if (this.completionTraceOn()) this.recordCompletionGateTrace("hold", {
52438
52485
  blockReason: "native_transcript_advancing",
52439
52486
  latestVisibleStatus,
52440
- msgCount: nativeSample.msgCount,
52441
- sourceMtimeAgeMs: Date.now() - sourceMtimeMs,
52487
+ msgCount: growthDetail.msgCount,
52488
+ sourceMtimeAgeMs: mtimeAgeMs,
52442
52489
  growthQuietMs: MISSING_ASSISTANT_TRANSCRIPT_GROWTH_QUIET_MS,
52443
52490
  waitedMs
52444
52491
  });