@adhdev/daemon-standalone 1.0.28-rc.22 → 1.0.28-rc.24

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
@@ -33311,10 +33311,10 @@ var require_dist3 = __commonJS({
33311
33311
  }
33312
33312
  function getDaemonBuildInfo() {
33313
33313
  if (cached2) return cached2;
33314
- const commit = readInjected(true ? "dc10211420f1723bac639bd4dc2cfc2dd3fe0c81" : void 0) ?? "unknown";
33315
- const commitShort = readInjected(true ? "dc102114" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
33316
- const version2 = readInjected(true ? "1.0.28-rc.22" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
33317
- const builtAt = readInjected(true ? "2026-07-29T00:52:17.964Z" : void 0);
33314
+ const commit = readInjected(true ? "6abc12466a3077bd6bc096332ce9073ff8d4d975" : void 0) ?? "unknown";
33315
+ const commitShort = readInjected(true ? "6abc1246" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
33316
+ const version2 = readInjected(true ? "1.0.28-rc.24" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
33317
+ const builtAt = readInjected(true ? "2026-07-29T05:49:00.948Z" : void 0);
33318
33318
  cached2 = builtAt ? { commit, commitShort, version: version2, builtAt } : { commit, commitShort, version: version2 };
33319
33319
  return cached2;
33320
33320
  }
@@ -37556,6 +37556,21 @@ ${error48.message || ""}`;
37556
37556
  }
37557
37557
  return { attemptId: attempt.attemptId, stage: attempt.stage, applied: false, staleAttempt: false };
37558
37558
  }
37559
+ if (args.sessionId && attempt.sessionId && !sessionIdsEquivalent(args.sessionId, attempt.sessionId)) {
37560
+ metrics.staleAttemptEvents += 1;
37561
+ store.insertTurnEvent({
37562
+ eventId: (0, import_crypto5.randomUUID)(),
37563
+ meshId: args.meshId,
37564
+ attemptId: attempt.attemptId,
37565
+ taskId: args.taskId,
37566
+ kind: `stale_${args.stage}`,
37567
+ dedupeKey: args.sessionId,
37568
+ occurredAtMs: args.occurredAtMs ?? nowMs,
37569
+ recordedAt: nowIso
37570
+ });
37571
+ LOG2.info("TurnLedger", `Ignored ${args.stage} for task ${args.taskId} attempt ${attempt.attemptId}: event session ${args.sessionId} \u2260 attempt session ${attempt.sessionId} \u2014 no state change`);
37572
+ return { attemptId: attempt.attemptId, stage: attempt.stage, applied: false, staleAttempt: true };
37573
+ }
37559
37574
  const inserted = store.insertTurnEvent({
37560
37575
  eventId: (0, import_crypto5.randomUUID)(),
37561
37576
  meshId: args.meshId,
@@ -49992,6 +50007,15 @@ ${rendered}`, "utf-8");
49992
50007
  const via = readString6(payload.via);
49993
50008
  return Boolean(via && DIRECT_DISPATCH_VIA.has(via) && payload.source !== "queue");
49994
50009
  }
50010
+ function hasTerminalLedgerAuthorityForTask(ledgerEntries, taskId) {
50011
+ for (const entry of ledgerEntries || []) {
50012
+ if (entry.kind !== "task_completed" && entry.kind !== "task_failed") continue;
50013
+ if (readString6(entry.payload?.taskId) !== taskId) continue;
50014
+ if (entry.kind === "task_completed" && isWeakCompletionEvidence(entry.payload || {})) continue;
50015
+ return true;
50016
+ }
50017
+ return false;
50018
+ }
49995
50019
  function directDispatchTaskId(entry) {
49996
50020
  return readString6(entry.payload?.taskId) || entry.id;
49997
50021
  }
@@ -50129,7 +50153,8 @@ ${rendered}`, "utf-8");
50129
50153
  const queueNodeId = task.assignedNodeId || task.targetNodeId;
50130
50154
  const queueSessionId = task.assignedSessionId || task.targetSessionId;
50131
50155
  const queueLive = task.status === "assigned" ? sessionStatusFromNodes(opts.nodes, queueNodeId ?? void 0, queueSessionId ?? void 0) : {};
50132
- let queueStatus = queueLive.status === "awaiting_approval" || queueLive.status === "awaiting_choice" || queueLive.status === "generating" ? queueLive.status : task.status;
50156
+ const queueTerminalAuthority = task.status === "assigned" && hasTerminalLedgerAuthorityForTask(opts.ledgerEntries, task.id);
50157
+ let queueStatus = !queueTerminalAuthority && (queueLive.status === "awaiting_approval" || queueLive.status === "awaiting_choice" || queueLive.status === "generating") ? queueLive.status : task.status;
50133
50158
  const turnOverlay = task.status === "assigned" ? turnProjectionActiveWorkStatus(opts.meshId, task.id) : null;
50134
50159
  if (turnOverlay) queueStatus = turnOverlay.status;
50135
50160
  records.push({
@@ -50156,7 +50181,9 @@ ${rendered}`, "utf-8");
50156
50181
  const dbStatus = dispatch.status;
50157
50182
  const isTerminal = dbStatus === "completed" || dbStatus === "failed" || dbStatus === "stale";
50158
50183
  const turnOverlay = isTerminal ? null : turnProjectionActiveWorkStatus(opts.meshId, dispatch.taskId);
50159
- const status = isTerminal ? dbStatus === "completed" ? "idle" : "failed" : turnOverlay?.status || live.status || (dbStatus === "acked" ? "generating" : "assigned");
50184
+ const directTerminalAuthority = !isTerminal && hasTerminalLedgerAuthorityForTask(opts.ledgerEntries, dispatch.taskId);
50185
+ const liveStatus = directTerminalAuthority ? void 0 : live.status;
50186
+ const status = isTerminal ? dbStatus === "completed" ? "idle" : "failed" : turnOverlay?.status || liveStatus || (dbStatus === "acked" ? "generating" : "assigned");
50160
50187
  const { ledgerOnlyStaleReason, isFreshUnacknowledged } = classifyDirectDispatch({
50161
50188
  status,
50162
50189
  isTerminalRow: isTerminal,
@@ -50358,6 +50385,7 @@ ${rendered}`, "utf-8");
50358
50385
  init_mesh_work_queue();
50359
50386
  init_dist();
50360
50387
  init_mesh_turn_presentation();
50388
+ init_mesh_events_utils();
50361
50389
  DIRECT_DISPATCH_VIA = /* @__PURE__ */ new Set(["p2p_direct", "local_direct", "mesh_send_task"]);
50362
50390
  TERMINAL_LEDGER_KINDS = /* @__PURE__ */ new Set(["task_completed", "task_failed", "task_stalled"]);
50363
50391
  LEDGER_ONLY_STALE_REASON = "direct task dispatch has no provider acknowledgement, transcript append, or active runtime transition";
@@ -57760,6 +57788,24 @@ ${cleanBody}`;
57760
57788
  }, `${row.requeueReason} ${Math.round((Date.now() - requeuedAtMs) / 1e3)}s \u2192 ${outcome}`);
57761
57789
  return true;
57762
57790
  }
57791
+ function hasTerminalAuthorityForTask(meshId, taskId) {
57792
+ try {
57793
+ const row = resolveTurnAttemptRow({ meshId, taskId });
57794
+ if (row && (row.terminalOutcome || isTerminalTurnStage(row.stage))) return true;
57795
+ } catch {
57796
+ }
57797
+ try {
57798
+ const entry = MeshRuntimeStore.getInstance().findQueueEntryById(meshId, taskId);
57799
+ if (entry && (entry.status === "completed" || entry.status === "failed" || entry.status === "cancelled")) return true;
57800
+ } catch {
57801
+ }
57802
+ try {
57803
+ const evidence = findTerminalLedgerEvidenceForTask({ meshId, taskId });
57804
+ if (evidence && evidence.kind !== "task_stalled") return true;
57805
+ } catch {
57806
+ }
57807
+ return false;
57808
+ }
57763
57809
  function injectMeshSystemMessage(components, args) {
57764
57810
  const eventSessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
57765
57811
  const eventNodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
@@ -57770,6 +57816,14 @@ ${cleanBody}`;
57770
57816
  meshId: args.meshId,
57771
57817
  event: args.event
57772
57818
  };
57819
+ if ((args.event === "agent:waiting_approval" || args.event === "agent:waiting_choice") && eventSessionId) {
57820
+ const approvalTaskId = readNonEmptyString(args.metadataEvent.taskId);
57821
+ if (approvalTaskId && hasTerminalAuthorityForTask(args.meshId, approvalTaskId)) {
57822
+ LOG2.info("MeshEvents", `Suppressed ${args.event} for session ${eventSessionId} (mesh ${args.meshId}, task ${approvalTaskId}) \u2014 terminal authority already exists for the task; the approval/choice is stale (no current actionable modal)`);
57823
+ traceMeshEventDrop("stale_approval_after_terminal", traceCtx);
57824
+ return { success: true, forwarded: 0, suppressed: true, staleApprovalAfterTerminal: true };
57825
+ }
57826
+ }
57773
57827
  const sourceSession = args.sourceInstanceId ? components.instanceManager.getInstance(args.sourceInstanceId) : void 0;
57774
57828
  const workerCoordinatorDaemonId = readNonEmptyString(
57775
57829
  sourceSession?.getState()?.settings?.meshCoordinatorDaemonId
@@ -58737,6 +58791,7 @@ ${cleanBody}`;
58737
58791
  init_mesh_events_utils();
58738
58792
  init_mesh_event_classify();
58739
58793
  init_mesh_turn_ledger();
58794
+ init_mesh_turn_presentation();
58740
58795
  init_mesh_queue_assignment();
58741
58796
  REMOTE_IDLE_SESSION_TTL_MS = 5 * 60 * 1e3;
58742
58797
  meshByWorkspaceCache = /* @__PURE__ */ new Map();
@@ -87465,6 +87520,11 @@ ${body}
87465
87520
  const finalAssistantEvidence = this.completionFinalAssistantEvidence(parsed?.messages, pending.turnStartedAt);
87466
87521
  const allowMissingAssistantTimeout = !!(this.settings.meshNodeFor || this.settings.meshActiveTaskId || this.settings.launchedByCoordinator);
87467
87522
  LOG2.debug("CLI", `[${this.type}] finalAssistantEvidence: present=${finalAssistantEvidence.present} source=${finalAssistantEvidence.source} adapterOwnsMessagesElsewhere=${adapterOwnsMessagesElsewhere} parsedStatus=${parsedStatus}`);
87523
+ if (finalAssistantEvidence.present && finalAssistantEvidence.source !== "unavailable") {
87524
+ pending.resolvedFinalMessages = Array.isArray(finalAssistantEvidence.messages) ? finalAssistantEvidence.messages : void 0;
87525
+ } else {
87526
+ pending.resolvedFinalMessages = void 0;
87527
+ }
87468
87528
  if (!finalAssistantEvidence.present) {
87469
87529
  if (adapterOwnsMessagesElsewhere) {
87470
87530
  if (finalAssistantEvidence.source === "external-native") {
@@ -88424,13 +88484,35 @@ ${body}
88424
88484
  duration: pending.duration,
88425
88485
  timestamp: pending.timestamp,
88426
88486
  taskId: pending.taskId,
88427
- finalSummary: this.completionFinalSummary(this.adapter?.getScriptParsedStatus()?.messages, pending.turnStartedAt)
88487
+ finalSummary: this.cleanCompletionFinalSummary(pending)
88428
88488
  });
88429
88489
  this.completedDebouncePending = null;
88430
88490
  this.completedDebounceTimer = null;
88431
88491
  this.generatingStartedAt = 0;
88432
88492
  this.lastApprovalEventFingerprint = "";
88433
88493
  }
88494
+ /**
88495
+ * EMPTY-FINAL-CONTENT (kimi native-source TOCTOU): finalSummary for the CLEAN
88496
+ * finalization path (getCompletedFinalizationBlock returned null — the turn is already
88497
+ * proven done). Prefer extracting the summary from pending.resolvedFinalMessages, the
88498
+ * EXACT message snapshot completionFinalAssistantEvidence just proved `present:true`
88499
+ * from, instead of taking a brand-new independent read
88500
+ * (adapter.getScriptParsedStatus() / a fresh readExternalCompletionMessages() inside
88501
+ * completionFinalSummary). A native-source provider's on-disk transcript can be
88502
+ * rewritten/truncated between the two reads, and a PTY-buffer scrape can lose the
88503
+ * matched bubble to a repaint/scroll — either race can turn a proven-present turn into
88504
+ * an emitted completion with an empty assistant bubble. Falls back to the live
88505
+ * (pre-fix) read when no snapshot was cached (e.g. a code path that reaches the clean
88506
+ * emit without going through getCompletedFinalizationBlock first), so no other provider
88507
+ * class's behavior changes.
88508
+ */
88509
+ cleanCompletionFinalSummary(pending) {
88510
+ if (Array.isArray(pending.resolvedFinalMessages)) {
88511
+ const fromSnapshot = extractFinalSummaryFromMessagesAfter(pending.resolvedFinalMessages, pending.turnStartedAt);
88512
+ if (fromSnapshot) return fromSnapshot;
88513
+ }
88514
+ return this.completionFinalSummary(this.adapter?.getScriptParsedStatus()?.messages, pending.turnStartedAt);
88515
+ }
88434
88516
  /**
88435
88517
  * A-3 (CLI 완료판정 통합): single authoritative emit for a CLI turn's
88436
88518
  * `agent:generating_completed` event. The completion JUDGMENT — WHETHER and
@@ -88522,6 +88604,20 @@ ${body}
88522
88604
  * window, and scoped to autonomous mesh sessions (a foreground/attended or non-mesh
88523
88605
  * session, where a human answers the prompt, is returned untouched).
88524
88606
  */
88607
+ /**
88608
+ * TERMINAL-STALE-APPROVAL (provider side): true once a GENUINE (non-weak) completion
88609
+ * has been emitted for the CURRENT busy epoch — the turn is over and no new generating
88610
+ * phase has opened since the emit (busyEpoch has not advanced past the latch). A stale
88611
+ * cached/sticky modal frame must not re-synthesize waiting_approval for such an
88612
+ * already-completed turn. A weak/false-idle emit does NOT count (the turn may
88613
+ * genuinely still be in flight), and any new busy phase (busyEpoch advanced past the
88614
+ * emit) re-enables approval surfacing for the new turn.
88615
+ */
88616
+ hasEmittedGenuineCompletionForCurrentEpoch() {
88617
+ const latch = this.lastEmittedCompletion;
88618
+ if (!latch || latch.weak) return false;
88619
+ return this.busyEpoch <= latch.emittedAtEpoch;
88620
+ }
88525
88621
  stabilizeFlappingApprovalStatus(adapterStatus, now = Date.now()) {
88526
88622
  if (!this.isAutonomousMeshSession() || !this.shouldUsePtyAutoApprove()) return adapterStatus;
88527
88623
  const rawStatus = adapterStatus?.status;
@@ -88534,6 +88630,11 @@ ${body}
88534
88630
  }
88535
88631
  return adapterStatus;
88536
88632
  }
88633
+ if (this.approvalStickyLastConcreteAt > 0 && this.hasEmittedGenuineCompletionForCurrentEpoch()) {
88634
+ this.approvalStickyLastConcreteAt = 0;
88635
+ this.approvalStickyModal = null;
88636
+ this.approvalStickyEntrySeq = 0;
88637
+ }
88537
88638
  if (this.approvalStickyLastConcreteAt > 0 && this.approvalStickyModal) {
88538
88639
  const withinWindow = now - this.approvalStickyLastConcreteAt < _CliProviderInstance.APPROVAL_STICKY_FLAP_MS;
88539
88640
  const resolvedSinceAnchor = resolvedAt >= this.approvalStickyLastConcreteAt;