@adhdev/daemon-core 1.0.28-rc.7 → 1.0.28-rc.8

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
@@ -786,10 +786,10 @@ function readInjected(value) {
786
786
  }
787
787
  function getDaemonBuildInfo() {
788
788
  if (cached) return cached;
789
- const commit = readInjected(true ? "4d3d797d7472b72daaa82b9460f599e819ffee72" : void 0) ?? "unknown";
790
- const commitShort = readInjected(true ? "4d3d797d" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
791
- const version = readInjected(true ? "1.0.28-rc.7" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
792
- const builtAt = readInjected(true ? "2026-07-25T10:44:41.655Z" : void 0);
789
+ const commit = readInjected(true ? "cb5f0a4f64296587a261176e08731f2f3ed78766" : void 0) ?? "unknown";
790
+ const commitShort = readInjected(true ? "cb5f0a4f" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
791
+ const version = readInjected(true ? "1.0.28-rc.8" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
792
+ const builtAt = readInjected(true ? "2026-07-25T12:20:55.839Z" : void 0);
793
793
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
794
794
  return cached;
795
795
  }
@@ -7724,6 +7724,10 @@ var init_mesh_runtime_store = __esm({
7724
7724
  node_id TEXT,
7725
7725
  session_id TEXT,
7726
7726
  provider_type TEXT,
7727
+ -- LEDGER-TASK-TRACEABILITY (B): the task a lifecycle entry pertains to,
7728
+ -- promoted from payload.taskId so kind+task_id joins are index-backed
7729
+ -- (legacy DBs get this column via migrateMeshIsolationColumns' ALTER).
7730
+ task_id TEXT,
7727
7731
  payload TEXT NOT NULL DEFAULT '{}'
7728
7732
  );
7729
7733
 
@@ -7895,6 +7899,15 @@ var init_mesh_runtime_store = __esm({
7895
7899
  `);
7896
7900
  this.db.exec(`DROP TABLE IF EXISTS mesh_direct_delivered_events`);
7897
7901
  this.db.exec(`DROP TABLE IF EXISTS mesh_completion_conflicts`);
7902
+ const ledgerCols = this.tableColumns("mesh_event_ledger");
7903
+ if (!ledgerCols.has("task_id")) {
7904
+ this.db.exec(`ALTER TABLE mesh_event_ledger ADD COLUMN task_id TEXT`);
7905
+ }
7906
+ this.db.exec(`
7907
+ CREATE INDEX IF NOT EXISTS idx_mesh_event_ledger_task
7908
+ ON mesh_event_ledger(mesh_id, task_id, timestamp)
7909
+ WHERE task_id IS NOT NULL
7910
+ `);
7898
7911
  } catch (err) {
7899
7912
  if (!loggedMigrationFailure) {
7900
7913
  loggedMigrationFailure = true;
@@ -8846,8 +8859,8 @@ var init_mesh_runtime_store = __esm({
8846
8859
  }
8847
8860
  this.db.prepare(
8848
8861
  `INSERT OR IGNORE INTO mesh_event_ledger
8849
- (id, mesh_id, timestamp, kind, node_id, session_id, provider_type, payload)
8850
- VALUES (?, ?, ?, ?, ?, ?, ?, ?)`
8862
+ (id, mesh_id, timestamp, kind, node_id, session_id, provider_type, task_id, payload)
8863
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`
8851
8864
  ).run(
8852
8865
  entry.id,
8853
8866
  entry.meshId,
@@ -8856,6 +8869,7 @@ var init_mesh_runtime_store = __esm({
8856
8869
  entry.nodeId ?? null,
8857
8870
  entry.sessionId ?? null,
8858
8871
  entry.providerType ?? null,
8872
+ entry.taskId ?? null,
8859
8873
  JSON.stringify(entry.payload ?? {})
8860
8874
  );
8861
8875
  this.maybeCheckpointWal();
@@ -8886,6 +8900,7 @@ var init_mesh_runtime_store = __esm({
8886
8900
  nodeId: r.node_id,
8887
8901
  sessionId: r.session_id,
8888
8902
  providerType: r.provider_type,
8903
+ taskId: r.task_id ?? null,
8889
8904
  payload: (() => {
8890
8905
  try {
8891
8906
  return JSON.parse(r.payload);
@@ -8932,6 +8947,7 @@ var init_mesh_runtime_store = __esm({
8932
8947
  nodeId: r.node_id,
8933
8948
  sessionId: r.session_id,
8934
8949
  providerType: r.provider_type,
8950
+ taskId: r.task_id ?? null,
8935
8951
  payload: (() => {
8936
8952
  try {
8937
8953
  return JSON.parse(r.payload);
@@ -8973,8 +8989,8 @@ var init_mesh_runtime_store = __esm({
8973
8989
  let imported = 0;
8974
8990
  const stmt = this.db.prepare(
8975
8991
  `INSERT OR IGNORE INTO mesh_event_ledger
8976
- (id, mesh_id, timestamp, kind, node_id, session_id, provider_type, payload)
8977
- VALUES (?, ?, ?, ?, ?, ?, ?, ?)`
8992
+ (id, mesh_id, timestamp, kind, node_id, session_id, provider_type, task_id, payload)
8993
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`
8978
8994
  );
8979
8995
  this.db.transaction(() => {
8980
8996
  for (const e of entries) {
@@ -8987,6 +9003,7 @@ var init_mesh_runtime_store = __esm({
8987
9003
  e.nodeId ?? null,
8988
9004
  e.sessionId ?? null,
8989
9005
  e.providerType ?? null,
9006
+ e.taskId ?? null,
8990
9007
  JSON.stringify(e.payload ?? {})
8991
9008
  );
8992
9009
  if (result.changes > 0) imported++;
@@ -9366,6 +9383,7 @@ __export(mesh_ledger_exports, {
9366
9383
  isIntentionalCleanupStopEntry: () => isIntentionalCleanupStopEntry,
9367
9384
  isNoteExpired: () => isNoteExpired,
9368
9385
  isOperatingNoteTombstoned: () => isOperatingNoteTombstoned,
9386
+ ledgerEntryTaskId: () => ledgerEntryTaskId,
9369
9387
  meshLedgerEvents: () => meshLedgerEvents,
9370
9388
  normalizeMeshWorkerResult: () => normalizeMeshWorkerResult,
9371
9389
  pruneOperatingNotes: () => pruneOperatingNotes,
@@ -9379,6 +9397,11 @@ import { appendFileSync as appendFileSync2, existsSync as existsSync10, mkdirSyn
9379
9397
  import { join as join11 } from "path";
9380
9398
  import { randomUUID as randomUUID8 } from "crypto";
9381
9399
  import { EventEmitter } from "events";
9400
+ function ledgerEntryTaskId(entry) {
9401
+ if (typeof entry.taskId === "string" && entry.taskId.trim()) return entry.taskId.trim();
9402
+ const fromPayload = entry.payload && typeof entry.payload === "object" ? entry.payload.taskId : void 0;
9403
+ return typeof fromPayload === "string" && fromPayload.trim() ? fromPayload.trim() : void 0;
9404
+ }
9382
9405
  function isIntentionalCleanupStopEntry(entry) {
9383
9406
  if (entry.kind !== "session_stopped" && entry.kind !== "task_failed" && entry.kind !== "task_stalled") return false;
9384
9407
  const payload = entry.payload && typeof entry.payload === "object" && !Array.isArray(entry.payload) ? entry.payload : {};
@@ -9687,6 +9710,10 @@ function appendLedgerEntry(meshId, partial) {
9687
9710
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
9688
9711
  ...partial
9689
9712
  };
9713
+ if (!entry.taskId && TASK_LIFECYCLE_LEDGER_KINDS.has(entry.kind)) {
9714
+ const derived = ledgerEntryTaskId(entry);
9715
+ if (derived) entry.taskId = derived;
9716
+ }
9690
9717
  const filePath = getLedgerPath(meshId);
9691
9718
  if (existsSync10(filePath)) {
9692
9719
  try {
@@ -9708,6 +9735,7 @@ function appendLedgerEntry(meshId, partial) {
9708
9735
  nodeId: entry.nodeId ?? null,
9709
9736
  sessionId: entry.sessionId ?? null,
9710
9737
  providerType: entry.providerType ?? null,
9738
+ taskId: entry.taskId ?? null,
9711
9739
  payload: entry.payload
9712
9740
  });
9713
9741
  } catch {
@@ -9888,7 +9916,13 @@ function readLedgerFile(meshId) {
9888
9916
  if (!line.trim()) continue;
9889
9917
  try {
9890
9918
  const entry = JSON.parse(line);
9891
- if (entry.id && entry.kind) entries.push(entry);
9919
+ if (entry.id && entry.kind) {
9920
+ if (!entry.taskId) {
9921
+ const derived = ledgerEntryTaskId(entry);
9922
+ if (derived) entry.taskId = derived;
9923
+ }
9924
+ entries.push(entry);
9925
+ }
9892
9926
  } catch {
9893
9927
  }
9894
9928
  }
@@ -9912,6 +9946,7 @@ function ensureLedgerImported(store, meshId) {
9912
9946
  nodeId: e.nodeId ?? null,
9913
9947
  sessionId: e.sessionId ?? null,
9914
9948
  providerType: e.providerType ?? null,
9949
+ taskId: ledgerEntryTaskId(e) ?? null,
9915
9950
  payload: e.payload ?? {}
9916
9951
  })));
9917
9952
  } catch {
@@ -9920,16 +9955,21 @@ function ensureLedgerImported(store, meshId) {
9920
9955
  function readLedgerFromStore(meshId) {
9921
9956
  const store = MeshRuntimeStore.getInstance();
9922
9957
  ensureLedgerImported(store, meshId);
9923
- return store.readLedgerEntriesOrdered(meshId).map((r) => ({
9924
- id: r.id,
9925
- meshId: r.meshId,
9926
- timestamp: r.timestamp,
9927
- kind: r.kind,
9928
- ...r.nodeId ? { nodeId: r.nodeId } : {},
9929
- ...r.sessionId ? { sessionId: r.sessionId } : {},
9930
- ...r.providerType ? { providerType: r.providerType } : {},
9931
- payload: r.payload && typeof r.payload === "object" ? r.payload : {}
9932
- }));
9958
+ return store.readLedgerEntriesOrdered(meshId).map((r) => {
9959
+ const payload = r.payload && typeof r.payload === "object" ? r.payload : {};
9960
+ const taskId = ledgerEntryTaskId({ taskId: r.taskId ?? void 0, payload });
9961
+ return {
9962
+ id: r.id,
9963
+ meshId: r.meshId,
9964
+ timestamp: r.timestamp,
9965
+ kind: r.kind,
9966
+ ...r.nodeId ? { nodeId: r.nodeId } : {},
9967
+ ...r.sessionId ? { sessionId: r.sessionId } : {},
9968
+ ...r.providerType ? { providerType: r.providerType } : {},
9969
+ ...taskId ? { taskId } : {},
9970
+ payload
9971
+ };
9972
+ });
9933
9973
  }
9934
9974
  function getCachedRawEntries(meshId) {
9935
9975
  const now = Date.now();
@@ -10156,7 +10196,7 @@ function rotateLedgerFile(meshId, currentPath) {
10156
10196
  `);
10157
10197
  }
10158
10198
  }
10159
- var LEDGER_DIR_NAME, MAX_FILE_SIZE_BYTES, COMPACT_THRESHOLD_BYTES, ARCHIVE_TERMINAL_OLDER_THAN_MS, RECENT_FAILURE_WINDOW_MS, ARCHIVABLE_KINDS, DEFAULT_LEDGER_SLICE_LIMIT, MAX_LEDGER_SLICE_LIMIT, OPERATING_NOTE_KIND, OPERATING_NOTE_TOMBSTONE_KIND, OPERATING_NOTE_DEDUPE_WINDOW, OPERATING_NOTE_KEEP_LATEST, OPERATING_NOTE_CATEGORY_TTL_DAYS, MS_PER_DAY, meshLedgerEvents, ledgerReadCache, LEDGER_CACHE_TTL_MS, ledgerImportStoreRef, ledgerImportDone;
10199
+ var TASK_LIFECYCLE_LEDGER_KINDS, LEDGER_DIR_NAME, MAX_FILE_SIZE_BYTES, COMPACT_THRESHOLD_BYTES, ARCHIVE_TERMINAL_OLDER_THAN_MS, RECENT_FAILURE_WINDOW_MS, ARCHIVABLE_KINDS, DEFAULT_LEDGER_SLICE_LIMIT, MAX_LEDGER_SLICE_LIMIT, OPERATING_NOTE_KIND, OPERATING_NOTE_TOMBSTONE_KIND, OPERATING_NOTE_DEDUPE_WINDOW, OPERATING_NOTE_KEEP_LATEST, OPERATING_NOTE_CATEGORY_TTL_DAYS, MS_PER_DAY, meshLedgerEvents, ledgerReadCache, LEDGER_CACHE_TTL_MS, ledgerImportStoreRef, ledgerImportDone;
10160
10200
  var init_mesh_ledger = __esm({
10161
10201
  "src/mesh/mesh-ledger.ts"() {
10162
10202
  "use strict";
@@ -10164,6 +10204,17 @@ var init_mesh_ledger = __esm({
10164
10204
  init_dist();
10165
10205
  init_mesh_runtime_store();
10166
10206
  init_contracts();
10207
+ TASK_LIFECYCLE_LEDGER_KINDS = /* @__PURE__ */ new Set([
10208
+ "task_dispatched",
10209
+ "task_claimed",
10210
+ "task_completed",
10211
+ "task_failed",
10212
+ "task_stalled",
10213
+ "task_reclaimed",
10214
+ "task_approval_needed",
10215
+ "task_question_pending",
10216
+ "p2p_dispatch_failed"
10217
+ ]);
10167
10218
  LEDGER_DIR_NAME = "mesh-ledger";
10168
10219
  MAX_FILE_SIZE_BYTES = 10 * 1024 * 1024;
10169
10220
  COMPACT_THRESHOLD_BYTES = 2 * 1024 * 1024;
@@ -19159,6 +19210,43 @@ async function waitForLocalSessionReady(components, sessionId) {
19159
19210
  }
19160
19211
  LOG.warn("MeshQueue", `Auto-launched session ${sessionId} not interactive after ${LOCAL_LAUNCH_READY_TIMEOUT_MS}ms; dispatching anyway (adapter queue-until-ready will buffer)`);
19161
19212
  }
19213
+ function recordTaskDispatchedLedger(ctx, deliveryId) {
19214
+ const task = ctx.task;
19215
+ const routing = ctx.routingDecision;
19216
+ const routingDecision = {
19217
+ source: routing?.source ?? "queue",
19218
+ selectedNodeId: ctx.nodeId,
19219
+ ...localCoordinatorDaemonId() ? { daemonId: localCoordinatorDaemonId() } : {},
19220
+ transport: ctx.transport,
19221
+ // D: resolved execution profile — prefer the caller's resolved values, fall back
19222
+ // to what the claimed task row carries (queue/idle drains carry it on the task).
19223
+ resolvedProviderType: routing?.resolvedProviderType ?? ctx.providerType,
19224
+ ...routing?.resolvedModel ?? task.model ? { resolvedModel: routing?.resolvedModel ?? task.model } : {},
19225
+ ...routing?.resolvedThinkingLevel ?? task.thinkingLevel ? { resolvedThinkingLevel: routing?.resolvedThinkingLevel ?? task.thinkingLevel } : {},
19226
+ ...routing?.resolvedDifficulty ?? task.difficulty ? { resolvedDifficulty: routing?.resolvedDifficulty ?? task.difficulty } : {},
19227
+ ...typeof routing?.fitnessScore === "number" ? { fitnessScore: routing.fitnessScore } : {},
19228
+ ...routing?.skippedCandidates?.length ? { skippedCandidates: routing.skippedCandidates } : {},
19229
+ ...routing?.requiredTagsResult ? { requiredTagsResult: routing.requiredTagsResult } : {},
19230
+ ...routing?.reason ? { reason: routing.reason } : {}
19231
+ };
19232
+ appendLedgerEntry(ctx.meshId, {
19233
+ kind: "task_dispatched",
19234
+ nodeId: ctx.nodeId,
19235
+ sessionId: ctx.sessionId,
19236
+ providerType: ctx.providerType,
19237
+ taskId: task.id,
19238
+ payload: {
19239
+ taskId: task.id,
19240
+ ...task.missionId ? { missionId: task.missionId } : {},
19241
+ deliveryId,
19242
+ transport: ctx.transport,
19243
+ ...ctx.sourceCoordinatorSessionId ? { coordinatorSessionId: ctx.sourceCoordinatorSessionId } : {},
19244
+ ...ctx.sourceCoordinatorDaemonId ? { coordinatorDaemonId: ctx.sourceCoordinatorDaemonId } : {},
19245
+ ...Array.isArray(task.requiredTags) && task.requiredTags.length ? { requiredTags: task.requiredTags } : {},
19246
+ routingDecision
19247
+ }
19248
+ });
19249
+ }
19162
19250
  function deliverTaskToSession(dispatchThunk, ctx, warmup) {
19163
19251
  const delivery = createSessionDelivery({
19164
19252
  meshId: ctx.meshId,
@@ -19172,6 +19260,10 @@ function deliverTaskToSession(dispatchThunk, ctx, warmup) {
19172
19260
  ...ctx.sourceCoordinatorSessionId ? { sourceCoordinatorSessionId: ctx.sourceCoordinatorSessionId } : {},
19173
19261
  ...ctx.sourceCoordinatorDaemonId ? { sourceCoordinatorDaemonId: ctx.sourceCoordinatorDaemonId } : {}
19174
19262
  });
19263
+ try {
19264
+ recordTaskDispatchedLedger(ctx, delivery.id);
19265
+ } catch {
19266
+ }
19175
19267
  let dispatchPromise;
19176
19268
  try {
19177
19269
  dispatchPromise = Promise.resolve(dispatchThunk());
@@ -19235,7 +19327,7 @@ function resolveClaimingSessionTranscriptProfile(components, sessionId) {
19235
19327
  return void 0;
19236
19328
  }
19237
19329
  }
19238
- function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType) {
19330
+ function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType, routingDecision) {
19239
19331
  const mesh = getMeshWithCache(components, meshId);
19240
19332
  const node = mesh?.nodes.find((n) => meshNodeIdMatches(n, nodeId));
19241
19333
  if (isWorkspaceAutoFastForwardInFlight(readNonEmptyString(node?.workspace))) {
@@ -19312,6 +19404,24 @@ function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType)
19312
19404
  return false;
19313
19405
  }
19314
19406
  LOG.info("MeshQueue", `Node ${nodeId} (${sessionId}) pulled task ${task.id}`);
19407
+ try {
19408
+ appendLedgerEntry(meshId, {
19409
+ kind: "task_claimed",
19410
+ nodeId,
19411
+ sessionId,
19412
+ providerType,
19413
+ taskId: task.id,
19414
+ payload: {
19415
+ taskId: task.id,
19416
+ ...task.missionId ? { missionId: task.missionId } : {},
19417
+ nodeId,
19418
+ sessionId,
19419
+ providerType,
19420
+ claimedAt: (/* @__PURE__ */ new Date()).toISOString()
19421
+ }
19422
+ });
19423
+ } catch {
19424
+ }
19315
19425
  retractActionableSkipIfPreviouslyNotified(meshId, task.id);
19316
19426
  beginTaskDispatchInFlight(meshId, task.id);
19317
19427
  const silentIdlePushOnDispatch = resolveCoordinatorIdlePushPolicy(mesh?.policy) === "auto_silent_on_dispatch";
@@ -19349,7 +19459,8 @@ function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType)
19349
19459
  task,
19350
19460
  transport: "remote",
19351
19461
  ...sourceCoordinatorSessionId ? { sourceCoordinatorSessionId } : {},
19352
- ...localDaemonIdForDispatch ? { sourceCoordinatorDaemonId: localDaemonIdForDispatch } : {}
19462
+ ...localDaemonIdForDispatch ? { sourceCoordinatorDaemonId: localDaemonIdForDispatch } : {},
19463
+ ...routingDecision ? { routingDecision } : {}
19353
19464
  },
19354
19465
  // Warmup-aware deadline: this dispatch can be the FIRST command to a
19355
19466
  // peer whose mesh DataChannel is still opening — charge the cold-open
@@ -19416,7 +19527,8 @@ function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType)
19416
19527
  task,
19417
19528
  transport: "local",
19418
19529
  ...readNonEmptyString(task.sourceCoordinatorSessionId) ? { sourceCoordinatorSessionId: readNonEmptyString(task.sourceCoordinatorSessionId) } : {},
19419
- ...localCoordinatorDaemonId() ? { sourceCoordinatorDaemonId: localCoordinatorDaemonId() } : {}
19530
+ ...localCoordinatorDaemonId() ? { sourceCoordinatorDaemonId: localCoordinatorDaemonId() } : {},
19531
+ ...routingDecision ? { routingDecision } : {}
19420
19532
  }
19421
19533
  );
19422
19534
  return true;
@@ -19854,11 +19966,16 @@ function recordAutoLaunchEvent(meshId, args) {
19854
19966
  nodeId: args.nodeId,
19855
19967
  sessionId: args.sessionId,
19856
19968
  providerType: args.providerType,
19969
+ // (B) promote taskId so this entry joins the task lifecycle timeline.
19970
+ ...args.taskId ? { taskId: args.taskId } : {},
19857
19971
  payload: {
19858
19972
  phase: args.phase,
19859
19973
  taskId: args.taskId,
19860
19974
  reason: args.reason,
19861
- error: args.error
19975
+ error: args.error,
19976
+ // (D) resolved execution profile for the spawned worker.
19977
+ ...args.model ? { resolvedModel: args.model } : {},
19978
+ ...args.thinkingLevel ? { resolvedThinkingLevel: args.thinkingLevel } : {}
19862
19979
  }
19863
19980
  });
19864
19981
  } catch (e) {
@@ -19880,7 +19997,9 @@ function markAutoLaunch(meshId, taskId, args) {
19880
19997
  providerType: args.providerType,
19881
19998
  sessionId: args.sessionId,
19882
19999
  reason: args.reason,
19883
- error: args.error
20000
+ error: args.error,
20001
+ ...args.model ? { model: args.model } : {},
20002
+ ...args.thinkingLevel ? { thinkingLevel: args.thinkingLevel } : {}
19884
20003
  });
19885
20004
  if (args.status === "skipped") {
19886
20005
  if (isActionableSkipReason(args.reason)) {
@@ -20080,6 +20199,14 @@ async function maybeAutoLaunchOneQueueSession(components, meshId, mesh) {
20080
20199
  // pass it through for the 'fitness' strategy's task→slot ranking.
20081
20200
  { bumpCursor: true, task: { difficulty: task.difficulty, requiredTags: task.requiredTags } }
20082
20201
  ).map((c) => c.node);
20202
+ const skippedCandidates = [];
20203
+ const SKIPPED_CANDIDATES_MAX = 12;
20204
+ const markSkip = (nodeIdForSkip, reason, extra) => {
20205
+ markAutoLaunch(meshId, task.id, { status: "skipped", reason, nodeId: nodeIdForSkip, ...extra || {} });
20206
+ if (nodeIdForSkip && skippedCandidates.length < SKIPPED_CANDIDATES_MAX) {
20207
+ skippedCandidates.push({ nodeId: nodeIdForSkip, reason });
20208
+ }
20209
+ };
20083
20210
  for (const node of orderedCandidateNodes) {
20084
20211
  const nodeId = readMeshNodeId(node);
20085
20212
  if (!nodeId) continue;
@@ -20088,50 +20215,50 @@ async function maybeAutoLaunchOneQueueSession(components, meshId, mesh) {
20088
20215
  const cooldownUntil = autoLaunchCooldownUntil.get(launchKey) || 0;
20089
20216
  if (cooldownUntil > 0 && now >= cooldownUntil) autoLaunchCooldownUntil.delete(launchKey);
20090
20217
  if (autoLaunchInProgress.has(launchKey)) {
20091
- markAutoLaunch(meshId, task.id, { status: "skipped", reason: "auto_launch_in_progress", nodeId });
20218
+ markSkip(nodeId, "auto_launch_in_progress");
20092
20219
  continue;
20093
20220
  }
20094
20221
  if (now < cooldownUntil) {
20095
- markAutoLaunch(meshId, task.id, { status: "skipped", reason: "auto_launch_cooldown", nodeId });
20222
+ markSkip(nodeId, "auto_launch_cooldown");
20096
20223
  continue;
20097
20224
  }
20098
20225
  if (isDirtyNode(node)) {
20099
- markAutoLaunch(meshId, task.id, { status: "skipped", reason: "dirty_workspace", nodeId });
20226
+ markSkip(nodeId, "dirty_workspace");
20100
20227
  continue;
20101
20228
  }
20102
20229
  if (!isLaunchableNode(node)) {
20103
- markAutoLaunch(meshId, task.id, { status: "skipped", reason: "node_not_launch_ready", nodeId });
20230
+ markSkip(nodeId, "node_not_launch_ready");
20104
20231
  continue;
20105
20232
  }
20106
20233
  if (!isMeshNodeFreshEnoughToLaunch(node, freshnessGate)) {
20107
- markAutoLaunch(meshId, task.id, { status: "skipped", reason: "node_stale_behind_upstream", nodeId });
20234
+ markSkip(nodeId, "node_stale_behind_upstream");
20108
20235
  continue;
20109
20236
  }
20110
20237
  const launchTarget = resolveAutoLaunchTarget(components, node);
20111
20238
  if (launchTarget.mode === "skip") {
20112
- markAutoLaunch(meshId, task.id, { status: "skipped", reason: launchTarget.reason || "auto_launch_unavailable", nodeId });
20239
+ markSkip(nodeId, launchTarget.reason || "auto_launch_unavailable");
20113
20240
  autoLaunchCooldownUntil.set(launchKey, Date.now() + AUTO_LAUNCH_COOLDOWN_MS);
20114
20241
  sweepExpiredCooldowns();
20115
20242
  continue;
20116
20243
  }
20117
20244
  if (nodeHasLiveSessionPendingClaim(components, meshId, nodeId, task, node)) {
20118
- markAutoLaunch(meshId, task.id, { status: "skipped", reason: "node_has_live_session_pending_claim", nodeId });
20245
+ markSkip(nodeId, "node_has_live_session_pending_claim");
20119
20246
  continue;
20120
20247
  }
20121
20248
  if (!isTaskReadonly(task) && nodeHasActiveAssignment(meshId, nodeId)) {
20122
- markAutoLaunch(meshId, task.id, { status: "skipped", reason: "node_has_active_assignment", nodeId });
20249
+ markSkip(nodeId, "node_has_active_assignment");
20123
20250
  continue;
20124
20251
  }
20125
20252
  const maxConcurrentSessions = Number(node?.policy?.maxConcurrentSessions);
20126
20253
  if (Number.isFinite(maxConcurrentSessions) && maxConcurrentSessions >= 0 && liveSessionCountForNode(components, meshId, nodeId) >= maxConcurrentSessions) {
20127
- markAutoLaunch(meshId, task.id, { status: "skipped", reason: "max_concurrent_sessions_reached", nodeId });
20254
+ markSkip(nodeId, "max_concurrent_sessions_reached");
20128
20255
  continue;
20129
20256
  }
20130
20257
  autoLaunchInProgress.add(launchKey);
20131
20258
  try {
20132
20259
  const resolved = await resolveUsableProvider(components, nodeId, node, task.requiredTags, { difficulty: task.difficulty, requiredTags: task.requiredTags });
20133
20260
  if (!resolved.providerType) {
20134
- markAutoLaunch(meshId, task.id, { status: "skipped", reason: resolved.reason || "provider_unusable", nodeId });
20261
+ markSkip(nodeId, resolved.reason || "provider_unusable");
20135
20262
  continue;
20136
20263
  }
20137
20264
  const rawEffectiveModel = typeof task.model === "string" && task.model.trim() ? task.model.trim() : resolved.model;
@@ -20142,7 +20269,7 @@ async function maybeAutoLaunchOneQueueSession(components, meshId, mesh) {
20142
20269
  }
20143
20270
  const providerCap = resolveProviderMaxParallel(resolveNodeCapabilitySlots(node), resolved.providerType);
20144
20271
  if (providerCap !== void 0 && activeProviderAssignedCount(meshId, nodeId, resolved.providerType) >= providerCap) {
20145
- markAutoLaunch(meshId, task.id, { status: "skipped", reason: "max_provider_parallel_reached", nodeId, providerType: resolved.providerType });
20272
+ markSkip(nodeId, "max_provider_parallel_reached", { providerType: resolved.providerType });
20146
20273
  continue;
20147
20274
  }
20148
20275
  const launchSettings = {
@@ -20170,7 +20297,7 @@ async function maybeAutoLaunchOneQueueSession(components, meshId, mesh) {
20170
20297
  meshCoordinatorDaemonId: launchTarget.coordinatorDaemonId,
20171
20298
  meshCoordinatorNodeId: nodeId
20172
20299
  };
20173
- markAutoLaunch(meshId, task.id, { status: "started", nodeId, providerType: resolved.providerType });
20300
+ markAutoLaunch(meshId, task.id, { status: "started", nodeId, providerType: resolved.providerType, ...effectiveModel ? { model: effectiveModel } : {}, ...effectiveThinkingLevel ? { thinkingLevel: effectiveThinkingLevel } : {} });
20174
20301
  let launchResult2;
20175
20302
  try {
20176
20303
  launchResult2 = await components.dispatchMeshCommand(launchTarget.daemonId, "launch_cli", withStatusProbeMarker({
@@ -20199,12 +20326,12 @@ async function maybeAutoLaunchOneQueueSession(components, meshId, mesh) {
20199
20326
  return false;
20200
20327
  }
20201
20328
  const remoteSessionId = readNonEmptyString(payload.sessionId) || readNonEmptyString(payload.id) || readNonEmptyString(payload.runtimeSessionId);
20202
- markAutoLaunch(meshId, task.id, { status: "completed", nodeId, providerType: resolved.providerType, sessionId: remoteSessionId || void 0 });
20329
+ markAutoLaunch(meshId, task.id, { status: "completed", nodeId, providerType: resolved.providerType, sessionId: remoteSessionId || void 0, ...effectiveModel ? { model: effectiveModel } : {}, ...effectiveThinkingLevel ? { thinkingLevel: effectiveThinkingLevel } : {} });
20203
20330
  autoLaunchCooldownUntil.set(launchKey, Date.now() + AUTO_LAUNCH_COOLDOWN_MS);
20204
20331
  sweepExpiredCooldowns();
20205
20332
  return true;
20206
20333
  }
20207
- markAutoLaunch(meshId, task.id, { status: "started", nodeId, providerType: resolved.providerType });
20334
+ markAutoLaunch(meshId, task.id, { status: "started", nodeId, providerType: resolved.providerType, ...effectiveModel ? { model: effectiveModel } : {}, ...effectiveThinkingLevel ? { thinkingLevel: effectiveThinkingLevel } : {} });
20208
20335
  const launchResult = await components.cliManager.handleCliCommand("launch_cli", {
20209
20336
  cliType: resolved.providerType,
20210
20337
  dir: node.workspace,
@@ -20229,9 +20356,25 @@ async function maybeAutoLaunchOneQueueSession(components, meshId, mesh) {
20229
20356
  sweepExpiredCooldowns();
20230
20357
  return false;
20231
20358
  }
20232
- markAutoLaunch(meshId, task.id, { status: "completed", nodeId, providerType: resolved.providerType, sessionId });
20359
+ markAutoLaunch(meshId, task.id, { status: "completed", nodeId, providerType: resolved.providerType, sessionId, ...effectiveModel ? { model: effectiveModel } : {}, ...effectiveThinkingLevel ? { thinkingLevel: effectiveThinkingLevel } : {} });
20233
20360
  await waitForLocalSessionReady(components, sessionId);
20234
- tryAssignQueueTask(components, meshId, nodeId, sessionId, resolved.providerType);
20361
+ const requiredTags = Array.isArray(task.requiredTags) ? task.requiredTags.filter((t) => !!t) : [];
20362
+ const routingDecision = {
20363
+ source: "autoLaunch",
20364
+ fitnessScore: nodeFitnessForTask(node, { difficulty: task.difficulty, requiredTags: task.requiredTags }),
20365
+ ...skippedCandidates.length ? { skippedCandidates } : {},
20366
+ requiredTagsResult: {
20367
+ required: requiredTags,
20368
+ satisfied: !requiredTags.length || nodeSatisfiesRequiredTags(requiredTags, buildMeshNodeCapabilityTags(node, resolved.providerType)),
20369
+ missing: requiredTags.filter((t) => !buildMeshNodeCapabilityTags(node, resolved.providerType).includes(t))
20370
+ },
20371
+ resolvedProviderType: resolved.providerType,
20372
+ ...effectiveModel ? { resolvedModel: effectiveModel } : {},
20373
+ ...effectiveThinkingLevel ? { resolvedThinkingLevel: effectiveThinkingLevel } : {},
20374
+ ...task.difficulty ? { resolvedDifficulty: String(task.difficulty) } : {},
20375
+ ...resolved.reason ? { reason: resolved.reason } : {}
20376
+ };
20377
+ tryAssignQueueTask(components, meshId, nodeId, sessionId, resolved.providerType, routingDecision);
20235
20378
  return true;
20236
20379
  } catch (e) {
20237
20380
  markAutoLaunch(meshId, task.id, { status: "failed", error: e?.message || String(e), nodeId });
@@ -77488,6 +77631,7 @@ export {
77488
77631
  killIdeProcess,
77489
77632
  launchIDE,
77490
77633
  launchWithCdp,
77634
+ ledgerEntryTaskId,
77491
77635
  listCoordinatorsForWorkspace,
77492
77636
  listHostedCliRuntimes,
77493
77637
  listMagiKindPanels,