@adhdev/daemon-core 1.0.18-rc.12 → 1.0.18-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
@@ -437,10 +437,10 @@ function readInjected(value) {
437
437
  }
438
438
  function getDaemonBuildInfo() {
439
439
  if (cached) return cached;
440
- const commit = readInjected(true ? "8cce29137e6b62781be7645411736bd8d1a9e7a8" : void 0) ?? "unknown";
441
- const commitShort = readInjected(true ? "8cce2913" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
442
- const version = readInjected(true ? "1.0.18-rc.12" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
443
- const builtAt = readInjected(true ? "2026-07-22T12:25:26.100Z" : void 0);
440
+ const commit = readInjected(true ? "2a9ab536171fcf675788ac5b41596e740046bbfa" : void 0) ?? "unknown";
441
+ const commitShort = readInjected(true ? "2a9ab536" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
442
+ const version = readInjected(true ? "1.0.18-rc.13" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
443
+ const builtAt = readInjected(true ? "2026-07-22T14:01:45.066Z" : void 0);
444
444
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
445
445
  return cached;
446
446
  }
@@ -49113,6 +49113,18 @@ var CliProviderInstance = class _CliProviderInstance {
49113
49113
  // MESH_WORKER_STALL_REFIRE_COOLDOWN_MS between successive emissions across
49114
49114
  // anchor re-arms (the per-anchor guard only covers a single continuous stall).
49115
49115
  meshStallLastFiredAt = -1;
49116
+ // KIMI-MESH-COMPLETION-EMIT (axis 1): the native-source transcript progress
49117
+ // fingerprint (record count + source mtime) observed the LAST time the stall
49118
+ // watchdog checked a native-source provider (transcriptAuthority=provider — e.g.
49119
+ // kimi wire.jsonl). A pure-PTY native-source worker running a long, screen-quiet
49120
+ // tool (no viewport bytes for minutes) looks stalled by the lastOutputAt clock
49121
+ // even though its transcript file is still growing. Before firing the stall, we
49122
+ // compare the current transcript fingerprint against this snapshot; if the
49123
+ // transcript advanced, the "stall" is a false positive of PTY-render stasis, so
49124
+ // we re-arm the anchor instead of paging the coordinator (whose no_progress
49125
+ // handling can lead to the worker being stopped mid-work → completion never
49126
+ // emitted). null = not yet sampled for this session/anchor.
49127
+ meshStallNativeTranscriptSample = null;
49116
49128
  // FALSE-IDLE continuity epoch: monotonically bumped on EVERY entry into a busy
49117
49129
  // phase (→generating or →waiting_approval). The completedDebouncePending snapshots
49118
49130
  // this value at arm time (busyEpochAtArm); the flush guard requires it UNCHANGED
@@ -49922,6 +49934,14 @@ var CliProviderInstance = class _CliProviderInstance {
49922
49934
  * once at completion). Reset on the next turn's start.
49923
49935
  */
49924
49936
  lastCompletionSummary = null;
49937
+ // KIMI-MESH-COMPLETION-EMIT (axis 2, double-emit guard): the (taskId, wall-clock)
49938
+ // of the most recent agent:generating_completed this instance emitted, stamped by
49939
+ // emitGeneratingCompleted. The pre-cleanup completion flush
49940
+ // (flushMeshCompletionBeforeCleanup, driven by cli-manager's exit monitor) reads
49941
+ // this to refuse a SECOND completion for a turn whose completion already fired —
49942
+ // so a worker that finished cleanly and is simply being auto-cleaned never emits a
49943
+ // duplicate. taskId '' covers an ad-hoc (no-task) turn. null = none emitted yet.
49944
+ lastEmittedCompletion = null;
49925
49945
  async enforceFreshSessionLaunchIfNeeded() {
49926
49946
  const scriptName = getForcedNewSessionScriptName(this.provider, this.launchMode);
49927
49947
  if (!scriptName) return;
@@ -50547,6 +50567,24 @@ var CliProviderInstance = class _CliProviderInstance {
50547
50567
  const threshold = turnActive ? _CliProviderInstance.MESH_WORKER_STALL_TURN_THRESHOLD_MS : _CliProviderInstance.MESH_WORKER_STALL_IDLE_THRESHOLD_MS;
50548
50568
  const stalledMs = now - this.meshStallAnchorAt;
50549
50569
  if (stalledMs < threshold) return;
50570
+ const nativeSample = this.sampleNativeTranscriptProgress();
50571
+ if (nativeSample) {
50572
+ const prev = this.meshStallNativeTranscriptSample;
50573
+ const advanced = !prev || nativeSample.msgCount > prev.msgCount || nativeSample.sourceMtimeMs > prev.sourceMtimeMs;
50574
+ this.meshStallNativeTranscriptSample = nativeSample;
50575
+ if (advanced) {
50576
+ if (this.isMeshWorkerSession()) {
50577
+ traceMeshEventDrop(
50578
+ "mesh_worker_stall_transcript_advancing",
50579
+ this.meshTraceCtx("monitor:no_progress"),
50580
+ `msgCount=${nativeSample.msgCount} sourceMtime=${nativeSample.sourceMtimeMs} (PTY quiet ${Math.round(stalledMs / 1e3)}s but transcript advancing)`
50581
+ );
50582
+ }
50583
+ this.meshStallAnchorAt = now;
50584
+ this.meshStallEmittedForAnchor = false;
50585
+ return;
50586
+ }
50587
+ }
50550
50588
  this.meshStallEmittedForAnchor = true;
50551
50589
  if (this.meshStallLastFiredAt >= 0 && now - this.meshStallLastFiredAt < _CliProviderInstance.MESH_WORKER_STALL_REFIRE_COOLDOWN_MS) {
50552
50590
  return;
@@ -50583,6 +50621,99 @@ var CliProviderInstance = class _CliProviderInstance {
50583
50621
  this.meshStallEmittedForAnchor = false;
50584
50622
  this.meshStallTurnActiveLast = void 0;
50585
50623
  this.meshStallLastFiredAt = -1;
50624
+ this.meshStallNativeTranscriptSample = null;
50625
+ }
50626
+ /**
50627
+ * KIMI-MESH-COMPLETION-EMIT (axis 1). For a native-source provider
50628
+ * (transcriptAuthority=provider — its authoritative history is an on-disk
50629
+ * transcript file, e.g. kimi's wire.jsonl), sample the transcript's current
50630
+ * progress fingerprint (record count + source-file mtime) WITHOUT parsing the
50631
+ * PTY. Used by the stall watchdog to distinguish "PTY render is quiet but the
50632
+ * worker is still doing long tool work (transcript growing)" from a genuine
50633
+ * wedge. Returns null for a pure-PTY provider (no native source) or when the
50634
+ * source cannot be resolved this tick — the caller then falls back to the
50635
+ * unchanged lastOutputAt-only judgment.
50636
+ *
50637
+ * Generalized on the provider's native-source flag, NOT a hardcoded provider
50638
+ * type, so every current and future pure-PTY long-tool native-source provider
50639
+ * benefits. Cheap enough for the stall path: it runs only at the stall threshold
50640
+ * (≥180s of PTY stasis), never on the routine 5s tick.
50641
+ */
50642
+ sampleNativeTranscriptProgress() {
50643
+ if (!isNativeSourceCanonicalHistory(this.provider?.nativeHistory)) return null;
50644
+ let messages = null;
50645
+ try {
50646
+ messages = this.readExternalCompletionMessages();
50647
+ } catch {
50648
+ return null;
50649
+ }
50650
+ const probe = this.lastExternalCompletionProbe;
50651
+ if (!probe) return null;
50652
+ return {
50653
+ msgCount: typeof probe.msgCount === "number" ? probe.msgCount : Array.isArray(messages) ? messages.length : 0,
50654
+ sourceMtimeMs: typeof probe.sourceMtimeMs === "number" ? probe.sourceMtimeMs : 0
50655
+ };
50656
+ }
50657
+ /**
50658
+ * KIMI-MESH-COMPLETION-EMIT (axis 2). Last-chance completion emit for a mesh
50659
+ * DELEGATED worker whose PTY has already exited (e.g. killed by a false stall)
50660
+ * and is about to be auto-cleaned (cli-manager.startCliExitMonitor →
50661
+ * removeInstance closes the event-emit window forever). If the worker actually
50662
+ * FINISHED its assigned turn — its authoritative native transcript holds a final
50663
+ * assistant message for the injected task — but the completion event never fired
50664
+ * (the stall-kill happened before the FSM's idle transition), emit it now so the
50665
+ * coordinator learns the task completed instead of waiting ~180s for the reconcile
50666
+ * transcript-poll to reclaim it.
50667
+ *
50668
+ * Scope & guards (must all hold to emit):
50669
+ * • mesh worker session only — a normal standalone session's ordinary exit is
50670
+ * never synthesized (isMeshWorkerSession()).
50671
+ * • DOUBLE-EMIT guard — refuse if this turn's completion already fired
50672
+ * (lastEmittedCompletion matches the current taskId). A worker that completed
50673
+ * cleanly and is merely being cleaned up never double-emits.
50674
+ * • evidence gate — reuse the same final-assistant/turn-scoped summary machinery
50675
+ * as the normal completion path (completionFinalSummary over the native
50676
+ * transcript). No in-turn assistant summary ⇒ no proof of completion ⇒ leave
50677
+ * the reclaim path to handle a genuinely-unfinished worker.
50678
+ *
50679
+ * Returns true when a synthetic completion was emitted, false otherwise. Safe to
50680
+ * call unconditionally from the cleanup path.
50681
+ */
50682
+ flushMeshCompletionBeforeCleanup() {
50683
+ if (!this.isMeshWorkerSession()) return false;
50684
+ const taskId = this.completingTurnTaskId();
50685
+ if (this.lastEmittedCompletion && this.lastEmittedCompletion.taskId === (taskId ?? "")) {
50686
+ return false;
50687
+ }
50688
+ if (!this.injectedTaskHasStartedGenerating()) return false;
50689
+ const turnStartedAt = typeof this.adapter?.currentTurnStartedAt === "number" ? this.adapter.currentTurnStartedAt : this.meshTaskInjectedAt || void 0;
50690
+ let parsedMessages;
50691
+ try {
50692
+ parsedMessages = this.adapter?.getScriptParsedStatus?.()?.messages;
50693
+ } catch {
50694
+ parsedMessages = void 0;
50695
+ }
50696
+ let finalSummary;
50697
+ try {
50698
+ finalSummary = this.completionFinalSummary(parsedMessages, turnStartedAt);
50699
+ } catch {
50700
+ finalSummary = void 0;
50701
+ }
50702
+ if (!finalSummary) return false;
50703
+ LOG.warn("CLI", `[${this.type}] emitting pre-cleanup mesh completion for session ${this.instanceId} task=${taskId ?? "(none)"} \u2014 PTY exited before the completion event fired but the native transcript shows a finished turn; synthesizing completion so the coordinator is not left waiting for reclaim.`);
50704
+ if (this.isMeshWorkerSession()) {
50705
+ traceMeshEventStage("fired", this.meshTraceCtx(), "pre_cleanup_transcript_completion");
50706
+ }
50707
+ this.emitGeneratingCompleted({
50708
+ chatTitle: "",
50709
+ duration: void 0,
50710
+ timestamp: Date.now(),
50711
+ taskId,
50712
+ finalSummary,
50713
+ evidenceLevel: "transcript",
50714
+ completionDiagnostic: { source: "pre_cleanup_transcript_completion" }
50715
+ });
50716
+ return true;
50586
50717
  }
50587
50718
  /**
50588
50719
  * AUTOAPPROVE-FLAP-RECUR (Fix A+B): how long a busy blip / modal scroll-out may
@@ -50984,6 +51115,7 @@ var CliProviderInstance = class _CliProviderInstance {
50984
51115
  if (summary) {
50985
51116
  this.lastCompletionSummary = { content: summary, receivedAt: opts.timestamp };
50986
51117
  }
51118
+ this.lastEmittedCompletion = { taskId: typeof opts.taskId === "string" ? opts.taskId : "", at: Date.now() };
50987
51119
  this.pushEvent({
50988
51120
  event: "agent:generating_completed",
50989
51121
  chatTitle: opts.chatTitle,
@@ -53780,6 +53912,15 @@ var DaemonCliManager = class {
53780
53912
  clearInterval(checkStopped);
53781
53913
  setTimeout(() => {
53782
53914
  if (this.adapters.has(key2)) {
53915
+ try {
53916
+ const inst = instanceManager?.getInstance(key2);
53917
+ if (typeof inst?.flushMeshCompletionBeforeCleanup === "function") {
53918
+ const emitted = inst.flushMeshCompletionBeforeCleanup();
53919
+ if (emitted) LOG.info("CLI", `Emitted pre-cleanup mesh completion for ${cliType} session ${key2} before auto-clean`);
53920
+ }
53921
+ } catch (e) {
53922
+ LOG.warn("CLI", `pre-cleanup mesh completion flush failed for ${key2}: ${e?.message || e}`);
53923
+ }
53783
53924
  this.adapters.delete(key2);
53784
53925
  this.deps.removeAgentTracking(key2);
53785
53926
  sessionRegistry?.unregisterByInstanceKey(key2);