@adhdev/daemon-core 0.9.82-rc.461 → 0.9.82-rc.462

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
@@ -409,10 +409,10 @@ function readInjected(value) {
409
409
  }
410
410
  function getDaemonBuildInfo() {
411
411
  if (cached) return cached;
412
- const commit = readInjected(true ? "ed8842e811aa362a2b4cc530498bc1fc7e1a7e4a" : void 0) ?? "unknown";
413
- const commitShort = readInjected(true ? "ed8842e8" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
414
- const version = readInjected(true ? "0.9.82-rc.461" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
415
- const builtAt = readInjected(true ? "2026-07-04T15:00:03.344Z" : void 0);
412
+ const commit = readInjected(true ? "1481e2078cc0eceea283a2370cccb4cd9102e4ff" : void 0) ?? "unknown";
413
+ const commitShort = readInjected(true ? "1481e207" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
414
+ const version = readInjected(true ? "0.9.82-rc.462" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
415
+ const builtAt = readInjected(true ? "2026-07-04T16:50:21.874Z" : void 0);
416
416
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
417
417
  return cached;
418
418
  }
@@ -11479,6 +11479,37 @@ var init_mesh_events_utils = __esm({
11479
11479
  function normalizeCoordinatorDaemonIds(coordinatorDaemonId) {
11480
11480
  return expandDaemonIdForms(coordinatorDaemonId);
11481
11481
  }
11482
+ function isMeshProtocolV2EnforceEnabled() {
11483
+ const raw = readNonEmptyString2(process.env.MESH_PROTOCOL_V2_ENFORCE);
11484
+ if (!raw) return false;
11485
+ const v = raw.trim().toLowerCase();
11486
+ return v === "1" || v === "true" || v === "on" || v === "yes";
11487
+ }
11488
+ function ledgerRecordQuarantinedEvent(event, reason) {
11489
+ try {
11490
+ const finalSummary = readMeshCompletionSummary(event.metadataEvent || {});
11491
+ appendLedgerEntry(event.meshId, {
11492
+ kind: "event_held",
11493
+ ...event.nodeId ? { nodeId: event.nodeId } : {},
11494
+ payload: {
11495
+ event: event.event,
11496
+ reason,
11497
+ recoverable: true,
11498
+ nodeLabel: event.nodeLabel,
11499
+ ...event.workspace ? { workspace: event.workspace } : {},
11500
+ targetCoordinatorDaemonId: event.targetCoordinatorDaemonId ?? null,
11501
+ ...readNonEmptyString2(event.eventId) ? { eventId: event.eventId } : {},
11502
+ queuedAt: event.queuedAt,
11503
+ ...finalSummary ? { finalSummary } : {}
11504
+ }
11505
+ });
11506
+ } catch (e) {
11507
+ LOG.warn("MeshEventsV2", `Failed to ledger-record v2-quarantined ${event.event} for mesh ${event.meshId}: ${e?.message || e}`);
11508
+ }
11509
+ }
11510
+ function getMeshV2DrainCounters() {
11511
+ return { ...meshV2DrainCounters };
11512
+ }
11482
11513
  function warnV2Once(key2, message) {
11483
11514
  if (warnedV2Violations.has(key2)) return;
11484
11515
  warnedV2Violations.add(key2);
@@ -11510,12 +11541,22 @@ function identityDeliversTo(intendedFor, drainer) {
11510
11541
  }
11511
11542
  function routeV2EventsForDrainer(events, drainer, ctx) {
11512
11543
  if (!drainer) return events;
11544
+ const enforce = isMeshProtocolV2EnforceEnabled();
11513
11545
  const bump = (k) => {
11514
11546
  if (ctx.countMetrics) meshV2DrainCounters[k]++;
11515
11547
  };
11516
11548
  const kept = [];
11517
11549
  for (const event of events) {
11518
11550
  if (!isV2Event(event)) {
11551
+ if (enforce) {
11552
+ bump("v1UnversionedQuarantined");
11553
+ if (ctx.countMetrics) ledgerRecordQuarantinedEvent(event, "v2_enforce_unversioned_quarantined");
11554
+ warnV2Once(
11555
+ `${event.meshId}::${event.eventId ?? event.event}::v1-quarantined`,
11556
+ `v2 ENFORCE: unversioned ${event.event} on mesh ${event.meshId} QUARANTINED (no v2 envelope \u2014 held back, not delivered; ledger-recorded recoverable). A producer path still emits v1.`
11557
+ );
11558
+ continue;
11559
+ }
11519
11560
  bump("v1BroadcastAccepted");
11520
11561
  kept.push(event);
11521
11562
  continue;
@@ -11524,6 +11565,15 @@ function routeV2EventsForDrainer(events, drainer, ctx) {
11524
11565
  try {
11525
11566
  validated = assertPendingMeshCoordinatorEventV2(event);
11526
11567
  } catch (e) {
11568
+ if (enforce) {
11569
+ bump("v2ValidationFailedQuarantined");
11570
+ if (ctx.countMetrics) ledgerRecordQuarantinedEvent(event, "v2_enforce_validation_failed_quarantined");
11571
+ warnV2Once(
11572
+ `${event.meshId}::${event.eventId ?? event.event}::invalid-quarantined`,
11573
+ `v2 ENFORCE: envelope validation failed for ${event.event} on mesh ${event.meshId} \u2014 QUARANTINED (held back, not delivered; ledger-recorded recoverable): ${e?.message || e}`
11574
+ );
11575
+ continue;
11576
+ }
11527
11577
  bump("v2ValidationFailedAccepted");
11528
11578
  warnV2Once(
11529
11579
  `${event.meshId}::${event.eventId ?? event.event}::invalid`,
@@ -12108,7 +12158,15 @@ var init_mesh_events_pending = __esm({
12108
12158
  * coordinatorRunId change orphaned them). */
12109
12159
  v2ReattributedToDrainer: 0,
12110
12160
  /** v1 (unversioned) events passed through as broadcast (rollout baseline). */
12111
- v1BroadcastAccepted: 0
12161
+ v1BroadcastAccepted: 0,
12162
+ /** T6 enforce: v2 events that FAILED validation and were QUARANTINED (held back
12163
+ * from delivery, not dropped). Non-zero here means a producer is still emitting a
12164
+ * malformed envelope after enforce was turned on. */
12165
+ v2ValidationFailedQuarantined: 0,
12166
+ /** T6 enforce: v1 (unversioned) events QUARANTINED because no v2 envelope could be
12167
+ * derived at emit time. Non-zero here means a producer path still emits v1 after
12168
+ * enforce — it should reach 0 once every node is on a v2-stamping build. */
12169
+ v1UnversionedQuarantined: 0
12112
12170
  };
12113
12171
  warnedV2Violations = /* @__PURE__ */ new Set();
12114
12172
  TERMINAL_COMPLETION_EVENTS = /* @__PURE__ */ new Set(["agent:generating_completed", "agent:stopped"]);
@@ -18312,6 +18370,21 @@ function resolveAckedDeathDeadlineMs() {
18312
18370
  function resolveAckedTranscriptFastTrackGraceMs() {
18313
18371
  return resolveTunedReconcileMs("MESH_INFLIGHT_ACKED_TRANSCRIPT_FASTTRACK_GRACE_MS", 4e4, 0, 5 * 6e4);
18314
18372
  }
18373
+ function getMeshV2BackstopCounters() {
18374
+ return { ...meshV2BackstopCounters };
18375
+ }
18376
+ function meshProtocolV2EnforceOn() {
18377
+ const raw = process.env.MESH_PROTOCOL_V2_ENFORCE;
18378
+ if (typeof raw !== "string") return false;
18379
+ const v = raw.trim().toLowerCase();
18380
+ return v === "1" || v === "true" || v === "on" || v === "yes";
18381
+ }
18382
+ function recordBackstopFire(kind, detail) {
18383
+ meshV2BackstopCounters[kind]++;
18384
+ if (meshProtocolV2EnforceOn()) {
18385
+ LOG.warn("MeshReconcileV2", `v2 ENFORCE last-resort backstop fired (${kind}): ${detail}. Under a healthy v2 completion contract this should be 0 \u2014 a worker's real terminal emit was lost/late.`);
18386
+ }
18387
+ }
18315
18388
  function inFlightSynthKey(meshId, taskId) {
18316
18389
  return `${meshId}::${taskId}`;
18317
18390
  }
@@ -19226,6 +19299,7 @@ async function reconcileUnterminatedDirectDispatches(components, mesh, selfIds,
19226
19299
  };
19227
19300
  const synthKey = inFlightSynthKey(mesh.id, taskId);
19228
19301
  const isAcked = dispatch.status === "acked";
19302
+ let backstopKind;
19229
19303
  let payload = null;
19230
19304
  let readFailed = false;
19231
19305
  try {
@@ -19290,6 +19364,7 @@ async function reconcileUnterminatedDirectDispatches(components, mesh, selfIds,
19290
19364
  const idleHeldMs = nowMs - idleSinceMs;
19291
19365
  if (idleHeldMs >= fastTrackGraceMs) {
19292
19366
  fastTrackReady = true;
19367
+ backstopKind = "ackedHoldFastTrackFired";
19293
19368
  LOG.info("MeshReconcile", `Acked-hold transcript fast-track: task ${taskId} on node ${nodeId} (mesh ${mesh.id}) read idle WITH a final assistant message for ${Math.round(idleHeldMs / 1e3)}s continuous (grace ${Math.round(fastTrackGraceMs / 1e3)}s) \u2014 promoting the synth ahead of the ${Math.round(deathDeadlineMs / 1e3)}s death backstop; the worker's real emit was lost/late and a later one no-ops idempotently.`);
19294
19369
  }
19295
19370
  } else if (holdState?.transcriptIdleSinceMs !== void 0) {
@@ -19300,6 +19375,7 @@ async function reconcileUnterminatedDirectDispatches(components, mesh, selfIds,
19300
19375
  continue;
19301
19376
  }
19302
19377
  if (!fastTrackReady) {
19378
+ backstopKind = "ackedHoldDeathDeadlineFired";
19303
19379
  LOG.warn("MeshReconcile", `Acked-hold death deadline reached: task ${taskId} on node ${nodeId} (mesh ${mesh.id}) still idle ${Math.round(sinceAckMs / 1e3)}s after the ack (deadline ${Math.round(deathDeadlineMs / 1e3)}s) \u2014 synthesizing the missing completion as a notification-loss net (a real emit, if it ever lands, no-ops idempotently).`);
19304
19380
  }
19305
19381
  }
@@ -19344,6 +19420,7 @@ async function reconcileUnterminatedDirectDispatches(components, mesh, selfIds,
19344
19420
  source: "daemon_reconcile_transcript_completion"
19345
19421
  });
19346
19422
  if (result.reconciled) {
19423
+ recordBackstopFire(backstopKind ?? "phase4SynthesisFired", `task ${taskId} on node ${nodeId} (mesh ${mesh.id}), kind=${result.kind}`);
19347
19424
  LOG.info("MeshReconcile", `Synthesized missing completion (${result.kind}) for task ${taskId} on node ${nodeId} (mesh ${mesh.id})`);
19348
19425
  }
19349
19426
  } catch (e) {
@@ -19473,7 +19550,7 @@ function setupMeshReconcileLoop(components) {
19473
19550
  }
19474
19551
  };
19475
19552
  }
19476
- var DEFAULT_RECONCILE_INTERVAL_MS, DEFAULT_AUTO_PRUNE_MIN_AGE_MS, DEFAULT_PENDING_HELD_DRAIN_ESCALATE_MS, ACKED_DEATH_CONSECUTIVE_READ_FAILURES, inFlightAckedHoldState, rehydratedHoldMeshes, coordinatorModalParkState, heldEventLedgerRecorded, ASSIGNED_STRANDED_DEADLINE_MS, DELIVERED_NO_TURN_DEADLINE_MS, RECLAIM_UNKNOWN_GRACE_TICKS, deliveredNoTurnUnknownStreak, STRICT_SESSION_MATCH_TTL_MS, unresolvedForwardRejectionCounts, MAX_FORWARD_REJECTIONS;
19553
+ var DEFAULT_RECONCILE_INTERVAL_MS, DEFAULT_AUTO_PRUNE_MIN_AGE_MS, DEFAULT_PENDING_HELD_DRAIN_ESCALATE_MS, ACKED_DEATH_CONSECUTIVE_READ_FAILURES, inFlightAckedHoldState, rehydratedHoldMeshes, meshV2BackstopCounters, coordinatorModalParkState, heldEventLedgerRecorded, ASSIGNED_STRANDED_DEADLINE_MS, DELIVERED_NO_TURN_DEADLINE_MS, RECLAIM_UNKNOWN_GRACE_TICKS, deliveredNoTurnUnknownStreak, STRICT_SESSION_MATCH_TTL_MS, unresolvedForwardRejectionCounts, MAX_FORWARD_REJECTIONS;
19477
19554
  var init_mesh_reconcile_loop = __esm({
19478
19555
  "src/mesh/mesh-reconcile-loop.ts"() {
19479
19556
  "use strict";
@@ -19501,6 +19578,14 @@ var init_mesh_reconcile_loop = __esm({
19501
19578
  ACKED_DEATH_CONSECUTIVE_READ_FAILURES = 3;
19502
19579
  inFlightAckedHoldState = /* @__PURE__ */ new Map();
19503
19580
  rehydratedHoldMeshes = /* @__PURE__ */ new Set();
19581
+ meshV2BackstopCounters = {
19582
+ /** PHASE-4 transcript synthesis actually reconciled a missing completion. */
19583
+ phase4SynthesisFired: 0,
19584
+ /** Acked-hold transcript fast-track promoted a synth ahead of the death deadline. */
19585
+ ackedHoldFastTrackFired: 0,
19586
+ /** Acked-hold death-deadline backstop released a held synth (the 8-min net). */
19587
+ ackedHoldDeathDeadlineFired: 0
19588
+ };
19504
19589
  coordinatorModalParkState = /* @__PURE__ */ new Map();
19505
19590
  heldEventLedgerRecorded = /* @__PURE__ */ new Set();
19506
19591
  ASSIGNED_STRANDED_DEADLINE_MS = 5 * 6e4;
@@ -19520,9 +19605,12 @@ __export(mesh_events_exports, {
19520
19605
  __resetMeshWorkspaceCacheForTests: () => __resetMeshWorkspaceCacheForTests,
19521
19606
  clearPendingMeshCoordinatorEvents: () => clearPendingMeshCoordinatorEvents,
19522
19607
  drainPendingMeshCoordinatorEvents: () => drainPendingMeshCoordinatorEvents,
19608
+ getMeshV2BackstopCounters: () => getMeshV2BackstopCounters,
19609
+ getMeshV2DrainCounters: () => getMeshV2DrainCounters,
19523
19610
  getPendingMeshCoordinatorEvents: () => getPendingMeshCoordinatorEvents,
19524
19611
  handleMeshForwardEvent: () => handleMeshForwardEvent,
19525
19612
  isMeshCoordinatorEvent: () => isMeshCoordinatorEvent,
19613
+ isMeshProtocolV2EnforceEnabled: () => isMeshProtocolV2EnforceEnabled,
19526
19614
  isSessionActivelyGenerating: () => isSessionActivelyGenerating,
19527
19615
  queuePendingMeshCoordinatorEvent: () => queuePendingMeshCoordinatorEvent,
19528
19616
  readV2EnvelopeFromWire: () => readV2EnvelopeFromWire,
@@ -43835,10 +43923,10 @@ var CliProviderInstance = class _CliProviderInstance {
43835
43923
  if (buttonIndex < 0 || !hasReliableConsentAnchor) {
43836
43924
  return autoApproveActive;
43837
43925
  }
43926
+ const affirmativeAnchor = normalizeApprovalLabel(buttonLabel);
43838
43927
  const modalSignature = [
43839
43928
  typeof modal?.message === "string" ? modal.message.trim() : "",
43840
- buttons.join("|"),
43841
- buttonIndex
43929
+ affirmativeAnchor
43842
43930
  ].join("::");
43843
43931
  const approvalEntrySeq = typeof adapterStatus?.approvalEntrySeq === "number" ? adapterStatus.approvalEntrySeq : 0;
43844
43932
  const busySignature = `${approvalEntrySeq}::${modalSignature}`;
@@ -53445,7 +53533,12 @@ var meshEventsHandlers = {
53445
53533
  return { success: true, events: [], heldForBusyLocalCoordinator: true, hasLiveCliCoordinator };
53446
53534
  }
53447
53535
  const events = drainPendingMeshCoordinatorEvents(meshId || void 0, coordinatorDaemonId);
53448
- return { success: true, events, hasLiveCliCoordinator, ...selfCoordinatorInboxRead ? { surfacedForSelfCoordinator: true } : {} };
53536
+ const meshProtocolV2Counters = {
53537
+ enforce: isMeshProtocolV2EnforceEnabled(),
53538
+ drain: { ...getMeshV2DrainCounters() },
53539
+ backstop: { ...getMeshV2BackstopCounters() }
53540
+ };
53541
+ return { success: true, events, hasLiveCliCoordinator, meshProtocolV2Counters, ...selfCoordinatorInboxRead ? { surfacedForSelfCoordinator: true } : {} };
53449
53542
  },
53450
53543
  interactive_prompt_response: async (ctx, args) => {
53451
53544
  const sessionId = typeof args?.targetSessionId === "string" && args.targetSessionId.trim() ? args.targetSessionId.trim() : typeof args?.sessionId === "string" && args.sessionId.trim() ? args.sessionId.trim() : "";
@@ -54471,6 +54564,11 @@ var meshStatusHandlers = {
54471
54564
  const callerCoordinatorDaemonId = typeof args?.coordinatorDaemonId === "string" && args.coordinatorDaemonId.trim() ? args.coordinatorDaemonId.trim() : ctx.deps.statusInstanceId || void 0;
54472
54565
  const pendingCoordinatorEvents = getPendingMeshCoordinatorEvents(meshId, callerCoordinatorDaemonId);
54473
54566
  const unroutableDeliveries = getRecentUnroutableDeliveries();
54567
+ const meshProtocolV2Counters = {
54568
+ enforce: isMeshProtocolV2EnforceEnabled(),
54569
+ drain: { ...getMeshV2DrainCounters() },
54570
+ backstop: { ...getMeshV2BackstopCounters() }
54571
+ };
54474
54572
  const previewFreshness = (() => {
54475
54573
  const localRepoRoot = nodeStatuses.map((node) => readStringValue(node?.git?.repoRoot, node?.repoRoot, node?.workspace)).find((candidate) => !!candidate && fs27.existsSync(candidate));
54476
54574
  return localRepoRoot ? buildPreviewFreshness(localRepoRoot) : void 0;
@@ -54560,6 +54658,7 @@ var meshStatusHandlers = {
54560
54658
  ...historicalSessions ? { historicalSessions } : {},
54561
54659
  ...pendingCoordinatorEvents.length > 0 ? { pendingCoordinatorEvents } : {},
54562
54660
  ...unroutableDeliveries.length > 0 ? { unroutableDeliveries } : {},
54661
+ meshProtocolV2Counters,
54563
54662
  activeRefineJobs: Array.from(ctx.runningRefineJobs.values()).filter((job) => job.meshId === meshId).map((job) => ({
54564
54663
  jobId: job.jobId,
54565
54664
  nodeId: job.targetNodeId,
@@ -54569,12 +54668,13 @@ var meshStatusHandlers = {
54569
54668
  targetCoordinatorDaemonId: job.targetCoordinatorDaemonId
54570
54669
  }))
54571
54670
  };
54572
- const { pendingCoordinatorEvents: _pendingCoordinatorEvents, unroutableDeliveries: _unroutableDeliveries, ...cacheableStatusResult } = statusResult;
54671
+ const { pendingCoordinatorEvents: _pendingCoordinatorEvents, unroutableDeliveries: _unroutableDeliveries, meshProtocolV2Counters: _meshProtocolV2Counters, ...cacheableStatusResult } = statusResult;
54573
54672
  const rememberedStatus = verboseMissions ? cacheableStatusResult : ctx.rememberAggregateMeshStatus(meshId, cacheableStatusResult, refreshReason);
54574
54673
  const returnedStatus = {
54575
54674
  ...rememberedStatus,
54576
54675
  ...pendingCoordinatorEvents.length > 0 ? { pendingCoordinatorEvents } : {},
54577
- ...unroutableDeliveries.length > 0 ? { unroutableDeliveries } : {}
54676
+ ...unroutableDeliveries.length > 0 ? { unroutableDeliveries } : {},
54677
+ meshProtocolV2Counters
54578
54678
  };
54579
54679
  logRepoMeshStatusDebug("return_live", {
54580
54680
  meshId,