@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.mjs CHANGED
@@ -404,10 +404,10 @@ function readInjected(value) {
404
404
  }
405
405
  function getDaemonBuildInfo() {
406
406
  if (cached) return cached;
407
- const commit = readInjected(true ? "ed8842e811aa362a2b4cc530498bc1fc7e1a7e4a" : void 0) ?? "unknown";
408
- const commitShort = readInjected(true ? "ed8842e8" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
409
- const version = readInjected(true ? "0.9.82-rc.461" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
410
- const builtAt = readInjected(true ? "2026-07-04T15:00:03.344Z" : void 0);
407
+ const commit = readInjected(true ? "1481e2078cc0eceea283a2370cccb4cd9102e4ff" : void 0) ?? "unknown";
408
+ const commitShort = readInjected(true ? "1481e207" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
409
+ const version = readInjected(true ? "0.9.82-rc.462" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
410
+ const builtAt = readInjected(true ? "2026-07-04T16:50:21.874Z" : void 0);
411
411
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
412
412
  return cached;
413
413
  }
@@ -11475,6 +11475,37 @@ import { randomUUID as randomUUID8 } from "crypto";
11475
11475
  function normalizeCoordinatorDaemonIds(coordinatorDaemonId) {
11476
11476
  return expandDaemonIdForms(coordinatorDaemonId);
11477
11477
  }
11478
+ function isMeshProtocolV2EnforceEnabled() {
11479
+ const raw = readNonEmptyString2(process.env.MESH_PROTOCOL_V2_ENFORCE);
11480
+ if (!raw) return false;
11481
+ const v = raw.trim().toLowerCase();
11482
+ return v === "1" || v === "true" || v === "on" || v === "yes";
11483
+ }
11484
+ function ledgerRecordQuarantinedEvent(event, reason) {
11485
+ try {
11486
+ const finalSummary = readMeshCompletionSummary(event.metadataEvent || {});
11487
+ appendLedgerEntry(event.meshId, {
11488
+ kind: "event_held",
11489
+ ...event.nodeId ? { nodeId: event.nodeId } : {},
11490
+ payload: {
11491
+ event: event.event,
11492
+ reason,
11493
+ recoverable: true,
11494
+ nodeLabel: event.nodeLabel,
11495
+ ...event.workspace ? { workspace: event.workspace } : {},
11496
+ targetCoordinatorDaemonId: event.targetCoordinatorDaemonId ?? null,
11497
+ ...readNonEmptyString2(event.eventId) ? { eventId: event.eventId } : {},
11498
+ queuedAt: event.queuedAt,
11499
+ ...finalSummary ? { finalSummary } : {}
11500
+ }
11501
+ });
11502
+ } catch (e) {
11503
+ LOG.warn("MeshEventsV2", `Failed to ledger-record v2-quarantined ${event.event} for mesh ${event.meshId}: ${e?.message || e}`);
11504
+ }
11505
+ }
11506
+ function getMeshV2DrainCounters() {
11507
+ return { ...meshV2DrainCounters };
11508
+ }
11478
11509
  function warnV2Once(key2, message) {
11479
11510
  if (warnedV2Violations.has(key2)) return;
11480
11511
  warnedV2Violations.add(key2);
@@ -11506,12 +11537,22 @@ function identityDeliversTo(intendedFor, drainer) {
11506
11537
  }
11507
11538
  function routeV2EventsForDrainer(events, drainer, ctx) {
11508
11539
  if (!drainer) return events;
11540
+ const enforce = isMeshProtocolV2EnforceEnabled();
11509
11541
  const bump = (k) => {
11510
11542
  if (ctx.countMetrics) meshV2DrainCounters[k]++;
11511
11543
  };
11512
11544
  const kept = [];
11513
11545
  for (const event of events) {
11514
11546
  if (!isV2Event(event)) {
11547
+ if (enforce) {
11548
+ bump("v1UnversionedQuarantined");
11549
+ if (ctx.countMetrics) ledgerRecordQuarantinedEvent(event, "v2_enforce_unversioned_quarantined");
11550
+ warnV2Once(
11551
+ `${event.meshId}::${event.eventId ?? event.event}::v1-quarantined`,
11552
+ `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.`
11553
+ );
11554
+ continue;
11555
+ }
11515
11556
  bump("v1BroadcastAccepted");
11516
11557
  kept.push(event);
11517
11558
  continue;
@@ -11520,6 +11561,15 @@ function routeV2EventsForDrainer(events, drainer, ctx) {
11520
11561
  try {
11521
11562
  validated = assertPendingMeshCoordinatorEventV2(event);
11522
11563
  } catch (e) {
11564
+ if (enforce) {
11565
+ bump("v2ValidationFailedQuarantined");
11566
+ if (ctx.countMetrics) ledgerRecordQuarantinedEvent(event, "v2_enforce_validation_failed_quarantined");
11567
+ warnV2Once(
11568
+ `${event.meshId}::${event.eventId ?? event.event}::invalid-quarantined`,
11569
+ `v2 ENFORCE: envelope validation failed for ${event.event} on mesh ${event.meshId} \u2014 QUARANTINED (held back, not delivered; ledger-recorded recoverable): ${e?.message || e}`
11570
+ );
11571
+ continue;
11572
+ }
11523
11573
  bump("v2ValidationFailedAccepted");
11524
11574
  warnV2Once(
11525
11575
  `${event.meshId}::${event.eventId ?? event.event}::invalid`,
@@ -12101,7 +12151,15 @@ var init_mesh_events_pending = __esm({
12101
12151
  * coordinatorRunId change orphaned them). */
12102
12152
  v2ReattributedToDrainer: 0,
12103
12153
  /** v1 (unversioned) events passed through as broadcast (rollout baseline). */
12104
- v1BroadcastAccepted: 0
12154
+ v1BroadcastAccepted: 0,
12155
+ /** T6 enforce: v2 events that FAILED validation and were QUARANTINED (held back
12156
+ * from delivery, not dropped). Non-zero here means a producer is still emitting a
12157
+ * malformed envelope after enforce was turned on. */
12158
+ v2ValidationFailedQuarantined: 0,
12159
+ /** T6 enforce: v1 (unversioned) events QUARANTINED because no v2 envelope could be
12160
+ * derived at emit time. Non-zero here means a producer path still emits v1 after
12161
+ * enforce — it should reach 0 once every node is on a v2-stamping build. */
12162
+ v1UnversionedQuarantined: 0
12105
12163
  };
12106
12164
  warnedV2Violations = /* @__PURE__ */ new Set();
12107
12165
  TERMINAL_COMPLETION_EVENTS = /* @__PURE__ */ new Set(["agent:generating_completed", "agent:stopped"]);
@@ -18308,6 +18366,21 @@ function resolveAckedDeathDeadlineMs() {
18308
18366
  function resolveAckedTranscriptFastTrackGraceMs() {
18309
18367
  return resolveTunedReconcileMs("MESH_INFLIGHT_ACKED_TRANSCRIPT_FASTTRACK_GRACE_MS", 4e4, 0, 5 * 6e4);
18310
18368
  }
18369
+ function getMeshV2BackstopCounters() {
18370
+ return { ...meshV2BackstopCounters };
18371
+ }
18372
+ function meshProtocolV2EnforceOn() {
18373
+ const raw = process.env.MESH_PROTOCOL_V2_ENFORCE;
18374
+ if (typeof raw !== "string") return false;
18375
+ const v = raw.trim().toLowerCase();
18376
+ return v === "1" || v === "true" || v === "on" || v === "yes";
18377
+ }
18378
+ function recordBackstopFire(kind, detail) {
18379
+ meshV2BackstopCounters[kind]++;
18380
+ if (meshProtocolV2EnforceOn()) {
18381
+ 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.`);
18382
+ }
18383
+ }
18311
18384
  function inFlightSynthKey(meshId, taskId) {
18312
18385
  return `${meshId}::${taskId}`;
18313
18386
  }
@@ -19222,6 +19295,7 @@ async function reconcileUnterminatedDirectDispatches(components, mesh, selfIds,
19222
19295
  };
19223
19296
  const synthKey = inFlightSynthKey(mesh.id, taskId);
19224
19297
  const isAcked = dispatch.status === "acked";
19298
+ let backstopKind;
19225
19299
  let payload = null;
19226
19300
  let readFailed = false;
19227
19301
  try {
@@ -19286,6 +19360,7 @@ async function reconcileUnterminatedDirectDispatches(components, mesh, selfIds,
19286
19360
  const idleHeldMs = nowMs - idleSinceMs;
19287
19361
  if (idleHeldMs >= fastTrackGraceMs) {
19288
19362
  fastTrackReady = true;
19363
+ backstopKind = "ackedHoldFastTrackFired";
19289
19364
  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.`);
19290
19365
  }
19291
19366
  } else if (holdState?.transcriptIdleSinceMs !== void 0) {
@@ -19296,6 +19371,7 @@ async function reconcileUnterminatedDirectDispatches(components, mesh, selfIds,
19296
19371
  continue;
19297
19372
  }
19298
19373
  if (!fastTrackReady) {
19374
+ backstopKind = "ackedHoldDeathDeadlineFired";
19299
19375
  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).`);
19300
19376
  }
19301
19377
  }
@@ -19340,6 +19416,7 @@ async function reconcileUnterminatedDirectDispatches(components, mesh, selfIds,
19340
19416
  source: "daemon_reconcile_transcript_completion"
19341
19417
  });
19342
19418
  if (result.reconciled) {
19419
+ recordBackstopFire(backstopKind ?? "phase4SynthesisFired", `task ${taskId} on node ${nodeId} (mesh ${mesh.id}), kind=${result.kind}`);
19343
19420
  LOG.info("MeshReconcile", `Synthesized missing completion (${result.kind}) for task ${taskId} on node ${nodeId} (mesh ${mesh.id})`);
19344
19421
  }
19345
19422
  } catch (e) {
@@ -19469,7 +19546,7 @@ function setupMeshReconcileLoop(components) {
19469
19546
  }
19470
19547
  };
19471
19548
  }
19472
- 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;
19549
+ 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;
19473
19550
  var init_mesh_reconcile_loop = __esm({
19474
19551
  "src/mesh/mesh-reconcile-loop.ts"() {
19475
19552
  "use strict";
@@ -19497,6 +19574,14 @@ var init_mesh_reconcile_loop = __esm({
19497
19574
  ACKED_DEATH_CONSECUTIVE_READ_FAILURES = 3;
19498
19575
  inFlightAckedHoldState = /* @__PURE__ */ new Map();
19499
19576
  rehydratedHoldMeshes = /* @__PURE__ */ new Set();
19577
+ meshV2BackstopCounters = {
19578
+ /** PHASE-4 transcript synthesis actually reconciled a missing completion. */
19579
+ phase4SynthesisFired: 0,
19580
+ /** Acked-hold transcript fast-track promoted a synth ahead of the death deadline. */
19581
+ ackedHoldFastTrackFired: 0,
19582
+ /** Acked-hold death-deadline backstop released a held synth (the 8-min net). */
19583
+ ackedHoldDeathDeadlineFired: 0
19584
+ };
19500
19585
  coordinatorModalParkState = /* @__PURE__ */ new Map();
19501
19586
  heldEventLedgerRecorded = /* @__PURE__ */ new Set();
19502
19587
  ASSIGNED_STRANDED_DEADLINE_MS = 5 * 6e4;
@@ -19516,9 +19601,12 @@ __export(mesh_events_exports, {
19516
19601
  __resetMeshWorkspaceCacheForTests: () => __resetMeshWorkspaceCacheForTests,
19517
19602
  clearPendingMeshCoordinatorEvents: () => clearPendingMeshCoordinatorEvents,
19518
19603
  drainPendingMeshCoordinatorEvents: () => drainPendingMeshCoordinatorEvents,
19604
+ getMeshV2BackstopCounters: () => getMeshV2BackstopCounters,
19605
+ getMeshV2DrainCounters: () => getMeshV2DrainCounters,
19519
19606
  getPendingMeshCoordinatorEvents: () => getPendingMeshCoordinatorEvents,
19520
19607
  handleMeshForwardEvent: () => handleMeshForwardEvent,
19521
19608
  isMeshCoordinatorEvent: () => isMeshCoordinatorEvent,
19609
+ isMeshProtocolV2EnforceEnabled: () => isMeshProtocolV2EnforceEnabled,
19522
19610
  isSessionActivelyGenerating: () => isSessionActivelyGenerating,
19523
19611
  queuePendingMeshCoordinatorEvent: () => queuePendingMeshCoordinatorEvent,
19524
19612
  readV2EnvelopeFromWire: () => readV2EnvelopeFromWire,
@@ -43425,10 +43513,10 @@ var CliProviderInstance = class _CliProviderInstance {
43425
43513
  if (buttonIndex < 0 || !hasReliableConsentAnchor) {
43426
43514
  return autoApproveActive;
43427
43515
  }
43516
+ const affirmativeAnchor = normalizeApprovalLabel(buttonLabel);
43428
43517
  const modalSignature = [
43429
43518
  typeof modal?.message === "string" ? modal.message.trim() : "",
43430
- buttons.join("|"),
43431
- buttonIndex
43519
+ affirmativeAnchor
43432
43520
  ].join("::");
43433
43521
  const approvalEntrySeq = typeof adapterStatus?.approvalEntrySeq === "number" ? adapterStatus.approvalEntrySeq : 0;
43434
43522
  const busySignature = `${approvalEntrySeq}::${modalSignature}`;
@@ -53040,7 +53128,12 @@ var meshEventsHandlers = {
53040
53128
  return { success: true, events: [], heldForBusyLocalCoordinator: true, hasLiveCliCoordinator };
53041
53129
  }
53042
53130
  const events = drainPendingMeshCoordinatorEvents(meshId || void 0, coordinatorDaemonId);
53043
- return { success: true, events, hasLiveCliCoordinator, ...selfCoordinatorInboxRead ? { surfacedForSelfCoordinator: true } : {} };
53131
+ const meshProtocolV2Counters = {
53132
+ enforce: isMeshProtocolV2EnforceEnabled(),
53133
+ drain: { ...getMeshV2DrainCounters() },
53134
+ backstop: { ...getMeshV2BackstopCounters() }
53135
+ };
53136
+ return { success: true, events, hasLiveCliCoordinator, meshProtocolV2Counters, ...selfCoordinatorInboxRead ? { surfacedForSelfCoordinator: true } : {} };
53044
53137
  },
53045
53138
  interactive_prompt_response: async (ctx, args) => {
53046
53139
  const sessionId = typeof args?.targetSessionId === "string" && args.targetSessionId.trim() ? args.targetSessionId.trim() : typeof args?.sessionId === "string" && args.sessionId.trim() ? args.sessionId.trim() : "";
@@ -54066,6 +54159,11 @@ var meshStatusHandlers = {
54066
54159
  const callerCoordinatorDaemonId = typeof args?.coordinatorDaemonId === "string" && args.coordinatorDaemonId.trim() ? args.coordinatorDaemonId.trim() : ctx.deps.statusInstanceId || void 0;
54067
54160
  const pendingCoordinatorEvents = getPendingMeshCoordinatorEvents(meshId, callerCoordinatorDaemonId);
54068
54161
  const unroutableDeliveries = getRecentUnroutableDeliveries();
54162
+ const meshProtocolV2Counters = {
54163
+ enforce: isMeshProtocolV2EnforceEnabled(),
54164
+ drain: { ...getMeshV2DrainCounters() },
54165
+ backstop: { ...getMeshV2BackstopCounters() }
54166
+ };
54069
54167
  const previewFreshness = (() => {
54070
54168
  const localRepoRoot = nodeStatuses.map((node) => readStringValue(node?.git?.repoRoot, node?.repoRoot, node?.workspace)).find((candidate) => !!candidate && fs27.existsSync(candidate));
54071
54169
  return localRepoRoot ? buildPreviewFreshness(localRepoRoot) : void 0;
@@ -54155,6 +54253,7 @@ var meshStatusHandlers = {
54155
54253
  ...historicalSessions ? { historicalSessions } : {},
54156
54254
  ...pendingCoordinatorEvents.length > 0 ? { pendingCoordinatorEvents } : {},
54157
54255
  ...unroutableDeliveries.length > 0 ? { unroutableDeliveries } : {},
54256
+ meshProtocolV2Counters,
54158
54257
  activeRefineJobs: Array.from(ctx.runningRefineJobs.values()).filter((job) => job.meshId === meshId).map((job) => ({
54159
54258
  jobId: job.jobId,
54160
54259
  nodeId: job.targetNodeId,
@@ -54164,12 +54263,13 @@ var meshStatusHandlers = {
54164
54263
  targetCoordinatorDaemonId: job.targetCoordinatorDaemonId
54165
54264
  }))
54166
54265
  };
54167
- const { pendingCoordinatorEvents: _pendingCoordinatorEvents, unroutableDeliveries: _unroutableDeliveries, ...cacheableStatusResult } = statusResult;
54266
+ const { pendingCoordinatorEvents: _pendingCoordinatorEvents, unroutableDeliveries: _unroutableDeliveries, meshProtocolV2Counters: _meshProtocolV2Counters, ...cacheableStatusResult } = statusResult;
54168
54267
  const rememberedStatus = verboseMissions ? cacheableStatusResult : ctx.rememberAggregateMeshStatus(meshId, cacheableStatusResult, refreshReason);
54169
54268
  const returnedStatus = {
54170
54269
  ...rememberedStatus,
54171
54270
  ...pendingCoordinatorEvents.length > 0 ? { pendingCoordinatorEvents } : {},
54172
- ...unroutableDeliveries.length > 0 ? { unroutableDeliveries } : {}
54271
+ ...unroutableDeliveries.length > 0 ? { unroutableDeliveries } : {},
54272
+ meshProtocolV2Counters
54173
54273
  };
54174
54274
  logRepoMeshStatusDebug("return_live", {
54175
54275
  meshId,