@adhdev/daemon-standalone 1.0.28-rc.13 → 1.0.28-rc.14

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
@@ -33262,10 +33262,10 @@ var require_dist3 = __commonJS({
33262
33262
  }
33263
33263
  function getDaemonBuildInfo() {
33264
33264
  if (cached2) return cached2;
33265
- const commit = readInjected(true ? "200c050e12084938c52f329a7531fd59a7cf5064" : void 0) ?? "unknown";
33266
- const commitShort = readInjected(true ? "200c050e" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
33267
- const version2 = readInjected(true ? "1.0.28-rc.13" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
33268
- const builtAt = readInjected(true ? "2026-07-26T08:48:28.825Z" : void 0);
33265
+ const commit = readInjected(true ? "a13de2dc4d24bfeb8d0e512a76f5e50d5e7cb05d" : void 0) ?? "unknown";
33266
+ const commitShort = readInjected(true ? "a13de2dc" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
33267
+ const version2 = readInjected(true ? "1.0.28-rc.14" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
33268
+ const builtAt = readInjected(true ? "2026-07-26T10:04:56.445Z" : void 0);
33269
33269
  cached2 = builtAt ? { commit, commitShort, version: version2, builtAt } : { commit, commitShort, version: version2 };
33270
33270
  return cached2;
33271
33271
  }
@@ -57603,7 +57603,7 @@ ${cleanBody}`;
57603
57603
  return ts2 >= dispatchedAtMs;
57604
57604
  });
57605
57605
  }
57606
- async function pollAssignedTaskTerminalEvidence(components, mesh, row) {
57606
+ async function pollAssignedTaskTerminalEvidence(components, mesh, row, opts) {
57607
57607
  const sessionId = readNonEmptyString(row.assignedSessionId);
57608
57608
  const nodeId = readNonEmptyString(row.assignedNodeId);
57609
57609
  if (!sessionId || !nodeId) return null;
@@ -57620,6 +57620,9 @@ ${cleanBody}`;
57620
57620
  if (!(Number.isFinite(dispatchedAtMs) && Number.isFinite(transcriptAtMs) && transcriptAtMs >= dispatchedAtMs)) {
57621
57621
  return null;
57622
57622
  }
57623
+ if (typeof opts?.minFinalAssistantAgeMs === "number" && opts.minFinalAssistantAgeMs > 0 && Date.now() - transcriptAtMs < opts.minFinalAssistantAgeMs) {
57624
+ return null;
57625
+ }
57623
57626
  return {
57624
57627
  outcome: "completed",
57625
57628
  finalSummary: evidence.finalSummary,
@@ -58017,7 +58020,9 @@ ${cleanBody}`;
58017
58020
  if (since === void 0) {
58018
58021
  assignedIdleFinalAssistantSince.set(idleTranscriptStreakKey, nowMs);
58019
58022
  } else if (nowMs - since >= ASSIGNED_IDLE_TRANSCRIPT_COMPLETE_MS) {
58020
- const terminalEvidence = await pollAssignedTaskTerminalEvidence(components, mesh, row);
58023
+ const terminalEvidence = await pollAssignedTaskTerminalEvidence(components, mesh, row, {
58024
+ minFinalAssistantAgeMs: ASSIGNED_IDLE_TRANSCRIPT_COMPLETE_MS
58025
+ });
58021
58026
  if (terminalEvidence) {
58022
58027
  assignedIdleFinalAssistantSince.delete(idleTranscriptStreakKey);
58023
58028
  updateTaskStatus(meshId, row.id, terminalEvidence.outcome);
@@ -78909,6 +78914,16 @@ ${body}
78909
78914
  init_hash();
78910
78915
  init_transcript_evidence();
78911
78916
  init_logger();
78917
+ var BUSY_LEASE_BOUND_MS = 18e4;
78918
+ var DEFAULT_CANARY_PROVIDERS = ["kimi", "codex-cli"];
78919
+ function resolveBusyLeaseGate(providerType, env2 = process.env) {
78920
+ const boundRaw = Number(env2.ADHDEV_TX_BUSY_LEASE_BOUND_MS);
78921
+ const boundMs = Number.isFinite(boundRaw) && boundRaw > 0 ? Math.floor(boundRaw) : BUSY_LEASE_BOUND_MS;
78922
+ const listRaw = env2.ADHDEV_TX_BUSY_LEASE_PROVIDERS;
78923
+ const list = (typeof listRaw === "string" ? listRaw : DEFAULT_CANARY_PROVIDERS.join(",")).split(",").map((s2) => s2.trim()).filter(Boolean);
78924
+ const type2 = (providerType ?? "").trim();
78925
+ return { enabled: type2.length > 0 && list.includes(type2), boundMs };
78926
+ }
78912
78927
  init_signal_envelope();
78913
78928
  var TranscriptSignalSource = class {
78914
78929
  constructor(opts) {
@@ -78916,6 +78931,10 @@ ${body}
78916
78931
  }
78917
78932
  /** msgCount seen at the previous update — drives in_turn_progress. */
78918
78933
  prevMsgCount = -1;
78934
+ /** TX-FSM Stage 2: wall-clock of the most recent sample that proved the
78935
+ * transcript live (in_turn_progress === true — a count advance OR mtime
78936
+ * inside the growth-quiet window). -1 = the lease was never issued. */
78937
+ lastLiveSampleAt = -1;
78919
78938
  /** Fingerprint of the last LOGGED snapshot, so the shadow log fires on
78920
78939
  * change only (a quiet session must not spam one line per read). */
78921
78940
  lastLoggedFingerprint = "";
@@ -78964,6 +78983,7 @@ ${body}
78964
78983
  const inTurnProgress = countAdvanced || fresh;
78965
78984
  const transcriptGrowing = ageMs === null ? null : fresh;
78966
78985
  this.prevMsgCount = msgCount;
78986
+ if (inTurnProgress) this.lastLiveSampleAt = now;
78967
78987
  return {
78968
78988
  kind: SIGNAL_SNAPSHOT_KIND,
78969
78989
  sampledAt: now,
@@ -78977,6 +78997,33 @@ ${body}
78977
78997
  detail: { msgCount, sourceMtimeMs, ageMs }
78978
78998
  };
78979
78999
  }
79000
+ /**
79001
+ * TX-FSM Stage 2 — the bounded busy lease, derived from the SAME sample
79002
+ * stream that produces the envelope (zero added I/O, pure memory read).
79003
+ *
79004
+ * Semantics: every sample whose in_turn_progress is true (re)issues the
79005
+ * lease at that sample's wall-clock; the lease stays ACTIVE for
79006
+ * leaseBoundMs after the LAST such sample and then EXPIRES. The bound is
79007
+ * the whole point: the lease extends busy across PTY-quiet stretches while
79008
+ * the transcript is demonstrably alive, but it can never hold busy
79009
+ * indefinitely — after expiry the consumer must resume its normal
79010
+ * (pre-lease) judgment, so a finished-but-wedged session escapes on the
79011
+ * bound, not on a transcript event that may never come.
79012
+ *
79013
+ * Fail-open by construction: a non-native-source class, an unresolved
79014
+ * transcript, or a read error never reaches the issuance line, so the
79015
+ * lease is simply never issued (active:false, lastLiveAt:null) — a
79016
+ * missing lease must never wedge a session or fabricate one.
79017
+ */
79018
+ busyLease(now = Date.now()) {
79019
+ if (this.lastLiveSampleAt < 0) {
79020
+ return { active: false, lastLiveAt: null, expiresAt: null, remainingMs: 0 };
79021
+ }
79022
+ const bound = this.opts.leaseBoundMs ?? BUSY_LEASE_BOUND_MS;
79023
+ const expiresAt = this.lastLiveSampleAt + bound;
79024
+ const remainingMs = Math.max(0, expiresAt - now);
79025
+ return { active: remainingMs > 0, lastLiveAt: this.lastLiveSampleAt, expiresAt, remainingMs };
79026
+ }
78980
79027
  /** Stage-0 shadow log: emit one line when the normalized observation
78981
79028
  * CHANGES. This log is the Stage 1-3 judgment input ("which signals were
78982
79029
  * actually observable, and when"), so it carries the full signal set —
@@ -84366,7 +84413,11 @@ ${body}
84366
84413
  // final_assistant_present signal rather than duplicating
84367
84414
  // the message scan.
84368
84415
  finalAssistantPresent: (msgs, ts2) => this.completionHasFinalAssistantMessage(msgs, ts2),
84369
- growthQuietMs: MISSING_ASSISTANT_TRANSCRIPT_GROWTH_QUIET_MS
84416
+ growthQuietMs: MISSING_ASSISTANT_TRANSCRIPT_GROWTH_QUIET_MS,
84417
+ // TX-FSM Stage 2: the lease bound follows the rollout gate's
84418
+ // (possibly env-overridden) value; the gate's enabled flag is
84419
+ // consulted per judgment, not here.
84420
+ leaseBoundMs: resolveBusyLeaseGate(this.type).boundMs
84370
84421
  });
84371
84422
  }
84372
84423
  const snapshot = this.transcriptSignalSource.update(
@@ -84967,6 +85018,21 @@ ${body}
84967
85018
  }
84968
85019
  return { snapshot: this.lastTranscriptSignalSnapshot, messages };
84969
85020
  }
85021
+ /**
85022
+ * TX-FSM Stage 2: is the bounded busy lease enabled for THIS provider?
85023
+ * This is the canary rollout gate (busy-lease-gate.ts) — a per-provider
85024
+ * feature switch, NOT a classification (transcript class/timing still come
85025
+ * from resolveTranscriptAuthorityProfile only). Resolved per call so an
85026
+ * env-driven rollout change takes effect without rebuilding the instance;
85027
+ * any resolver error fails closed (lease disabled → pre-Stage-2 behavior).
85028
+ */
85029
+ busyLeaseGateEnabled() {
85030
+ try {
85031
+ return resolveBusyLeaseGate(this.type).enabled;
85032
+ } catch {
85033
+ return false;
85034
+ }
85035
+ }
84970
85036
  /**
84971
85037
  * KIMI-MESH-COMPLETION-EMIT (axis 2). Last-chance completion emit for a mesh
84972
85038
  * DELEGATED worker whose PTY has already exited (e.g. killed by a false stall)
@@ -85393,6 +85459,28 @@ ${body}
85393
85459
  this.scheduleCompletedDebounceFlush(COMPLETED_FINALIZATION_RETRY_MS);
85394
85460
  return;
85395
85461
  }
85462
+ if (growthSnapshot?.available === true && this.busyLeaseGateEnabled()) {
85463
+ const lease = this.transcriptSignalSource?.busyLease() ?? null;
85464
+ if (lease?.active === true) {
85465
+ if (pending.loggedBlockReason !== "busy_lease_active") {
85466
+ LOG2.info("CLI", `[${this.type}] holding pending completed (busy_lease_active: lastLiveAt=${lease.lastLiveAt} expiresIn=${lease.remainingMs}ms) \u2014 transcript live within the lease bound, screen-idle verdict not trusted`);
85467
+ if (this.isMeshWorkerSession()) {
85468
+ traceMeshEventDrop("completion_gate_hold", this.meshTraceCtx(), `busy_lease_active lastLiveAt=${lease.lastLiveAt} expiresIn=${lease.remainingMs}ms`);
85469
+ }
85470
+ if (this.completionTraceOn()) this.recordCompletionGateTrace("hold", {
85471
+ blockReason: "busy_lease_active",
85472
+ latestVisibleStatus,
85473
+ leaseLastLiveAt: lease.lastLiveAt,
85474
+ leaseExpiresAt: lease.expiresAt,
85475
+ leaseRemainingMs: lease.remainingMs,
85476
+ waitedMs
85477
+ });
85478
+ pending.loggedBlockReason = "busy_lease_active";
85479
+ }
85480
+ this.scheduleCompletedDebounceFlush(COMPLETED_FINALIZATION_RETRY_MS);
85481
+ return;
85482
+ }
85483
+ }
85396
85484
  }
85397
85485
  if (!isTranscriptEvidenceGate && (block2.terminal || waitedMs < COMPLETED_FINALIZATION_MAX_WAIT_MS)) {
85398
85486
  if (pending.loggedBlockReason !== blockReason) {