@adhdev/daemon-core 1.0.18-rc.11 → 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.js CHANGED
@@ -442,10 +442,10 @@ function readInjected(value) {
442
442
  }
443
443
  function getDaemonBuildInfo() {
444
444
  if (cached) return cached;
445
- const commit = readInjected(true ? "99f9c20bcf4ceec1e7ab2bfe6c8f641ca88da360" : void 0) ?? "unknown";
446
- const commitShort = readInjected(true ? "99f9c20b" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
447
- const version = readInjected(true ? "1.0.18-rc.11" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
448
- const builtAt = readInjected(true ? "2026-07-22T10:18:44.739Z" : void 0);
445
+ const commit = readInjected(true ? "2a9ab536171fcf675788ac5b41596e740046bbfa" : void 0) ?? "unknown";
446
+ const commitShort = readInjected(true ? "2a9ab536" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
447
+ const version = readInjected(true ? "1.0.18-rc.13" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
448
+ const builtAt = readInjected(true ? "2026-07-22T14:01:45.066Z" : void 0);
449
449
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
450
450
  return cached;
451
451
  }
@@ -49540,6 +49540,18 @@ var CliProviderInstance = class _CliProviderInstance {
49540
49540
  // MESH_WORKER_STALL_REFIRE_COOLDOWN_MS between successive emissions across
49541
49541
  // anchor re-arms (the per-anchor guard only covers a single continuous stall).
49542
49542
  meshStallLastFiredAt = -1;
49543
+ // KIMI-MESH-COMPLETION-EMIT (axis 1): the native-source transcript progress
49544
+ // fingerprint (record count + source mtime) observed the LAST time the stall
49545
+ // watchdog checked a native-source provider (transcriptAuthority=provider — e.g.
49546
+ // kimi wire.jsonl). A pure-PTY native-source worker running a long, screen-quiet
49547
+ // tool (no viewport bytes for minutes) looks stalled by the lastOutputAt clock
49548
+ // even though its transcript file is still growing. Before firing the stall, we
49549
+ // compare the current transcript fingerprint against this snapshot; if the
49550
+ // transcript advanced, the "stall" is a false positive of PTY-render stasis, so
49551
+ // we re-arm the anchor instead of paging the coordinator (whose no_progress
49552
+ // handling can lead to the worker being stopped mid-work → completion never
49553
+ // emitted). null = not yet sampled for this session/anchor.
49554
+ meshStallNativeTranscriptSample = null;
49543
49555
  // FALSE-IDLE continuity epoch: monotonically bumped on EVERY entry into a busy
49544
49556
  // phase (→generating or →waiting_approval). The completedDebouncePending snapshots
49545
49557
  // this value at arm time (busyEpochAtArm); the flush guard requires it UNCHANGED
@@ -50349,6 +50361,14 @@ var CliProviderInstance = class _CliProviderInstance {
50349
50361
  * once at completion). Reset on the next turn's start.
50350
50362
  */
50351
50363
  lastCompletionSummary = null;
50364
+ // KIMI-MESH-COMPLETION-EMIT (axis 2, double-emit guard): the (taskId, wall-clock)
50365
+ // of the most recent agent:generating_completed this instance emitted, stamped by
50366
+ // emitGeneratingCompleted. The pre-cleanup completion flush
50367
+ // (flushMeshCompletionBeforeCleanup, driven by cli-manager's exit monitor) reads
50368
+ // this to refuse a SECOND completion for a turn whose completion already fired —
50369
+ // so a worker that finished cleanly and is simply being auto-cleaned never emits a
50370
+ // duplicate. taskId '' covers an ad-hoc (no-task) turn. null = none emitted yet.
50371
+ lastEmittedCompletion = null;
50352
50372
  async enforceFreshSessionLaunchIfNeeded() {
50353
50373
  const scriptName = getForcedNewSessionScriptName(this.provider, this.launchMode);
50354
50374
  if (!scriptName) return;
@@ -50974,6 +50994,24 @@ var CliProviderInstance = class _CliProviderInstance {
50974
50994
  const threshold = turnActive ? _CliProviderInstance.MESH_WORKER_STALL_TURN_THRESHOLD_MS : _CliProviderInstance.MESH_WORKER_STALL_IDLE_THRESHOLD_MS;
50975
50995
  const stalledMs = now - this.meshStallAnchorAt;
50976
50996
  if (stalledMs < threshold) return;
50997
+ const nativeSample = this.sampleNativeTranscriptProgress();
50998
+ if (nativeSample) {
50999
+ const prev = this.meshStallNativeTranscriptSample;
51000
+ const advanced = !prev || nativeSample.msgCount > prev.msgCount || nativeSample.sourceMtimeMs > prev.sourceMtimeMs;
51001
+ this.meshStallNativeTranscriptSample = nativeSample;
51002
+ if (advanced) {
51003
+ if (this.isMeshWorkerSession()) {
51004
+ traceMeshEventDrop(
51005
+ "mesh_worker_stall_transcript_advancing",
51006
+ this.meshTraceCtx("monitor:no_progress"),
51007
+ `msgCount=${nativeSample.msgCount} sourceMtime=${nativeSample.sourceMtimeMs} (PTY quiet ${Math.round(stalledMs / 1e3)}s but transcript advancing)`
51008
+ );
51009
+ }
51010
+ this.meshStallAnchorAt = now;
51011
+ this.meshStallEmittedForAnchor = false;
51012
+ return;
51013
+ }
51014
+ }
50977
51015
  this.meshStallEmittedForAnchor = true;
50978
51016
  if (this.meshStallLastFiredAt >= 0 && now - this.meshStallLastFiredAt < _CliProviderInstance.MESH_WORKER_STALL_REFIRE_COOLDOWN_MS) {
50979
51017
  return;
@@ -51010,6 +51048,99 @@ var CliProviderInstance = class _CliProviderInstance {
51010
51048
  this.meshStallEmittedForAnchor = false;
51011
51049
  this.meshStallTurnActiveLast = void 0;
51012
51050
  this.meshStallLastFiredAt = -1;
51051
+ this.meshStallNativeTranscriptSample = null;
51052
+ }
51053
+ /**
51054
+ * KIMI-MESH-COMPLETION-EMIT (axis 1). For a native-source provider
51055
+ * (transcriptAuthority=provider — its authoritative history is an on-disk
51056
+ * transcript file, e.g. kimi's wire.jsonl), sample the transcript's current
51057
+ * progress fingerprint (record count + source-file mtime) WITHOUT parsing the
51058
+ * PTY. Used by the stall watchdog to distinguish "PTY render is quiet but the
51059
+ * worker is still doing long tool work (transcript growing)" from a genuine
51060
+ * wedge. Returns null for a pure-PTY provider (no native source) or when the
51061
+ * source cannot be resolved this tick — the caller then falls back to the
51062
+ * unchanged lastOutputAt-only judgment.
51063
+ *
51064
+ * Generalized on the provider's native-source flag, NOT a hardcoded provider
51065
+ * type, so every current and future pure-PTY long-tool native-source provider
51066
+ * benefits. Cheap enough for the stall path: it runs only at the stall threshold
51067
+ * (≥180s of PTY stasis), never on the routine 5s tick.
51068
+ */
51069
+ sampleNativeTranscriptProgress() {
51070
+ if (!isNativeSourceCanonicalHistory(this.provider?.nativeHistory)) return null;
51071
+ let messages = null;
51072
+ try {
51073
+ messages = this.readExternalCompletionMessages();
51074
+ } catch {
51075
+ return null;
51076
+ }
51077
+ const probe = this.lastExternalCompletionProbe;
51078
+ if (!probe) return null;
51079
+ return {
51080
+ msgCount: typeof probe.msgCount === "number" ? probe.msgCount : Array.isArray(messages) ? messages.length : 0,
51081
+ sourceMtimeMs: typeof probe.sourceMtimeMs === "number" ? probe.sourceMtimeMs : 0
51082
+ };
51083
+ }
51084
+ /**
51085
+ * KIMI-MESH-COMPLETION-EMIT (axis 2). Last-chance completion emit for a mesh
51086
+ * DELEGATED worker whose PTY has already exited (e.g. killed by a false stall)
51087
+ * and is about to be auto-cleaned (cli-manager.startCliExitMonitor →
51088
+ * removeInstance closes the event-emit window forever). If the worker actually
51089
+ * FINISHED its assigned turn — its authoritative native transcript holds a final
51090
+ * assistant message for the injected task — but the completion event never fired
51091
+ * (the stall-kill happened before the FSM's idle transition), emit it now so the
51092
+ * coordinator learns the task completed instead of waiting ~180s for the reconcile
51093
+ * transcript-poll to reclaim it.
51094
+ *
51095
+ * Scope & guards (must all hold to emit):
51096
+ * • mesh worker session only — a normal standalone session's ordinary exit is
51097
+ * never synthesized (isMeshWorkerSession()).
51098
+ * • DOUBLE-EMIT guard — refuse if this turn's completion already fired
51099
+ * (lastEmittedCompletion matches the current taskId). A worker that completed
51100
+ * cleanly and is merely being cleaned up never double-emits.
51101
+ * • evidence gate — reuse the same final-assistant/turn-scoped summary machinery
51102
+ * as the normal completion path (completionFinalSummary over the native
51103
+ * transcript). No in-turn assistant summary ⇒ no proof of completion ⇒ leave
51104
+ * the reclaim path to handle a genuinely-unfinished worker.
51105
+ *
51106
+ * Returns true when a synthetic completion was emitted, false otherwise. Safe to
51107
+ * call unconditionally from the cleanup path.
51108
+ */
51109
+ flushMeshCompletionBeforeCleanup() {
51110
+ if (!this.isMeshWorkerSession()) return false;
51111
+ const taskId = this.completingTurnTaskId();
51112
+ if (this.lastEmittedCompletion && this.lastEmittedCompletion.taskId === (taskId ?? "")) {
51113
+ return false;
51114
+ }
51115
+ if (!this.injectedTaskHasStartedGenerating()) return false;
51116
+ const turnStartedAt = typeof this.adapter?.currentTurnStartedAt === "number" ? this.adapter.currentTurnStartedAt : this.meshTaskInjectedAt || void 0;
51117
+ let parsedMessages;
51118
+ try {
51119
+ parsedMessages = this.adapter?.getScriptParsedStatus?.()?.messages;
51120
+ } catch {
51121
+ parsedMessages = void 0;
51122
+ }
51123
+ let finalSummary;
51124
+ try {
51125
+ finalSummary = this.completionFinalSummary(parsedMessages, turnStartedAt);
51126
+ } catch {
51127
+ finalSummary = void 0;
51128
+ }
51129
+ if (!finalSummary) return false;
51130
+ 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.`);
51131
+ if (this.isMeshWorkerSession()) {
51132
+ traceMeshEventStage("fired", this.meshTraceCtx(), "pre_cleanup_transcript_completion");
51133
+ }
51134
+ this.emitGeneratingCompleted({
51135
+ chatTitle: "",
51136
+ duration: void 0,
51137
+ timestamp: Date.now(),
51138
+ taskId,
51139
+ finalSummary,
51140
+ evidenceLevel: "transcript",
51141
+ completionDiagnostic: { source: "pre_cleanup_transcript_completion" }
51142
+ });
51143
+ return true;
51013
51144
  }
51014
51145
  /**
51015
51146
  * AUTOAPPROVE-FLAP-RECUR (Fix A+B): how long a busy blip / modal scroll-out may
@@ -51411,6 +51542,7 @@ var CliProviderInstance = class _CliProviderInstance {
51411
51542
  if (summary) {
51412
51543
  this.lastCompletionSummary = { content: summary, receivedAt: opts.timestamp };
51413
51544
  }
51545
+ this.lastEmittedCompletion = { taskId: typeof opts.taskId === "string" ? opts.taskId : "", at: Date.now() };
51414
51546
  this.pushEvent({
51415
51547
  event: "agent:generating_completed",
51416
51548
  chatTitle: opts.chatTitle,
@@ -54202,6 +54334,15 @@ var DaemonCliManager = class {
54202
54334
  clearInterval(checkStopped);
54203
54335
  setTimeout(() => {
54204
54336
  if (this.adapters.has(key2)) {
54337
+ try {
54338
+ const inst = instanceManager?.getInstance(key2);
54339
+ if (typeof inst?.flushMeshCompletionBeforeCleanup === "function") {
54340
+ const emitted = inst.flushMeshCompletionBeforeCleanup();
54341
+ if (emitted) LOG.info("CLI", `Emitted pre-cleanup mesh completion for ${cliType} session ${key2} before auto-clean`);
54342
+ }
54343
+ } catch (e) {
54344
+ LOG.warn("CLI", `pre-cleanup mesh completion flush failed for ${key2}: ${e?.message || e}`);
54345
+ }
54205
54346
  this.adapters.delete(key2);
54206
54347
  this.deps.removeAgentTracking(key2);
54207
54348
  sessionRegistry?.unregisterByInstanceKey(key2);
@@ -67832,6 +67973,7 @@ var DaemonStatusReporter = class {
67832
67973
  switch (value) {
67833
67974
  case "agent:generating_started":
67834
67975
  case "agent:waiting_approval":
67976
+ case "agent:waiting_choice":
67835
67977
  case "agent:generating_completed":
67836
67978
  case "agent:stopped":
67837
67979
  case "monitor:no_progress":