@adhdev/daemon-core 0.9.82-rc.414 → 0.9.82-rc.416

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
@@ -384,10 +384,10 @@ function readInjected(value) {
384
384
  }
385
385
  function getDaemonBuildInfo() {
386
386
  if (cached) return cached;
387
- const commit = readInjected(true ? "7a774e95a82354f5357197b3c84f63e68b5f7a5d" : void 0) ?? "unknown";
388
- const commitShort = readInjected(true ? "7a774e95" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
389
- const version = readInjected(true ? "0.9.82-rc.414" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
390
- const builtAt = readInjected(true ? "2026-06-28T11:50:52.585Z" : void 0);
387
+ const commit = readInjected(true ? "b1b80482f0ae678be7cd54c6861ec8134eb2ffd0" : void 0) ?? "unknown";
388
+ const commitShort = readInjected(true ? "b1b80482" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
389
+ const version = readInjected(true ? "0.9.82-rc.416" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
390
+ const builtAt = readInjected(true ? "2026-06-28T15:54:36.726Z" : void 0);
391
391
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
392
392
  return cached;
393
393
  }
@@ -2556,15 +2556,20 @@ __export(mesh_config_exports, {
2556
2556
  createMesh: () => createMesh,
2557
2557
  createMeshHostPairingToken: () => createMeshHostPairingToken,
2558
2558
  deleteMesh: () => deleteMesh,
2559
+ getMagiPanel: () => getMagiPanel,
2559
2560
  getMesh: () => getMesh,
2560
2561
  getMeshByRepo: () => getMeshByRepo,
2562
+ listMagiPanels: () => listMagiPanels,
2561
2563
  listMeshes: () => listMeshes,
2562
2564
  markMeshHostPairingJoined: () => markMeshHostPairingJoined,
2565
+ normalizeMagiPanel: () => normalizeMagiPanel,
2563
2566
  normalizeRepoIdentity: () => normalizeRepoIdentity,
2567
+ removeMagiPanel: () => removeMagiPanel,
2564
2568
  removeNode: () => removeNode,
2565
2569
  tokenIdForManualPairing: () => tokenIdForManualPairing,
2566
2570
  updateMesh: () => updateMesh,
2567
- updateNode: () => updateNode
2571
+ updateNode: () => updateNode,
2572
+ upsertMagiPanel: () => upsertMagiPanel
2568
2573
  });
2569
2574
  import { existsSync as existsSync5, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
2570
2575
  import { join as join5 } from "path";
@@ -2940,7 +2945,89 @@ function updateNode(meshId, nodeId, opts) {
2940
2945
  saveMeshConfig(config);
2941
2946
  return node;
2942
2947
  }
2943
- var mergeMeshPolicy;
2948
+ function normalizeReplicaCount(value) {
2949
+ if (typeof value !== "number" || !Number.isFinite(value)) return void 0;
2950
+ const n = Math.floor(value);
2951
+ return n >= 1 ? n : void 0;
2952
+ }
2953
+ function normalizeMagiPanel(config) {
2954
+ if (!config || typeof config !== "object" || Array.isArray(config)) {
2955
+ throw new Error("invalid_magi_panel: config must be an object");
2956
+ }
2957
+ const raw = config;
2958
+ const rawMembers = raw.members;
2959
+ if (!Array.isArray(rawMembers) || rawMembers.length === 0) {
2960
+ throw new Error("invalid_magi_panel: members must be a non-empty array");
2961
+ }
2962
+ if (rawMembers.length > MAX_MAGI_PANEL_MEMBERS) {
2963
+ throw new Error(`invalid_magi_panel: too many members (max ${MAX_MAGI_PANEL_MEMBERS})`);
2964
+ }
2965
+ const members = rawMembers.map((entry, idx) => {
2966
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
2967
+ throw new Error(`invalid_magi_panel: member[${idx}] must be an object`);
2968
+ }
2969
+ const m = entry;
2970
+ const provider = typeof m.provider === "string" ? m.provider.trim() : "";
2971
+ if (!provider) {
2972
+ throw new Error(`invalid_magi_panel: member[${idx}].provider is required`);
2973
+ }
2974
+ const nodeId = typeof m.nodeId === "string" && m.nodeId.trim() ? m.nodeId.trim() : void 0;
2975
+ const capabilityTags = normalizeCapabilityTags(m.capabilityTags);
2976
+ const n = normalizeReplicaCount(m.n);
2977
+ return {
2978
+ provider,
2979
+ ...nodeId ? { nodeId } : {},
2980
+ ...capabilityTags ? { capabilityTags } : {},
2981
+ ...n !== void 0 ? { n } : {}
2982
+ };
2983
+ });
2984
+ const description = typeof raw.description === "string" && raw.description.trim() ? raw.description.trim().slice(0, 200) : void 0;
2985
+ const defaultN = normalizeReplicaCount(raw.defaultN);
2986
+ return {
2987
+ ...description ? { description } : {},
2988
+ members,
2989
+ ...defaultN !== void 0 ? { defaultN } : {},
2990
+ // dedupExempt is always meaningful for a MAGI panel (intentional same-prompt
2991
+ // fan-out). Persist it true unless the caller explicitly disables it.
2992
+ dedupExempt: raw.dedupExempt === false ? false : true
2993
+ };
2994
+ }
2995
+ function normalizePanelName(name) {
2996
+ const trimmed = typeof name === "string" ? name.trim() : "";
2997
+ if (!trimmed) throw new Error("invalid_magi_panel: panel name is required");
2998
+ return trimmed.slice(0, 100);
2999
+ }
3000
+ function listMagiPanels() {
3001
+ return loadMeshConfig().magiPanels ?? {};
3002
+ }
3003
+ function getMagiPanel(name) {
3004
+ const key2 = typeof name === "string" ? name.trim() : "";
3005
+ if (!key2) return void 0;
3006
+ return loadMeshConfig().magiPanels?.[key2];
3007
+ }
3008
+ function upsertMagiPanel(name, config, opts = {}) {
3009
+ const key2 = normalizePanelName(name);
3010
+ const panel = normalizeMagiPanel(config);
3011
+ const stored = loadMeshConfig();
3012
+ const panels = stored.magiPanels ?? {};
3013
+ if (panels[key2] && opts.overwrite !== true) {
3014
+ throw new Error(`magi_panel_exists: panel '${key2}' already exists \u2014 pass overwrite=true to replace it`);
3015
+ }
3016
+ panels[key2] = panel;
3017
+ stored.magiPanels = panels;
3018
+ saveMeshConfig(stored);
3019
+ return panel;
3020
+ }
3021
+ function removeMagiPanel(name) {
3022
+ const key2 = typeof name === "string" ? name.trim() : "";
3023
+ if (!key2) return false;
3024
+ const stored = loadMeshConfig();
3025
+ if (!stored.magiPanels || !stored.magiPanels[key2]) return false;
3026
+ delete stored.magiPanels[key2];
3027
+ saveMeshConfig(stored);
3028
+ return true;
3029
+ }
3030
+ var mergeMeshPolicy, MAX_MAGI_PANEL_MEMBERS;
2944
3031
  var init_mesh_config = __esm({
2945
3032
  "src/config/mesh-config.ts"() {
2946
3033
  "use strict";
@@ -2949,6 +3036,7 @@ var init_mesh_config = __esm({
2949
3036
  init_repo_mesh_types();
2950
3037
  init_mesh_host_ownership();
2951
3038
  mergeMeshPolicy = mergeAndNormalizePolicy;
3039
+ MAX_MAGI_PANEL_MEMBERS = 24;
2952
3040
  }
2953
3041
  });
2954
3042
 
@@ -5136,6 +5224,7 @@ function enqueueTask(meshId, message, opts) {
5136
5224
  requiredTags: resolvedRequiredTags,
5137
5225
  ...dependsOn.length > 0 ? { dependsOn } : {},
5138
5226
  ...typeof opts?.missionId === "string" && opts.missionId.trim() ? { missionId: opts.missionId.trim() } : {},
5227
+ ...typeof opts?.consensusGroupId === "string" && opts.consensusGroupId.trim() ? { consensusGroupId: opts.consensusGroupId.trim() } : {},
5139
5228
  ...typeof opts?.sourceCoordinatorSessionId === "string" && opts.sourceCoordinatorSessionId.trim() ? { sourceCoordinatorSessionId: opts.sourceCoordinatorSessionId.trim() } : {},
5140
5229
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
5141
5230
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
@@ -8447,6 +8536,14 @@ function resolveWin32GlobalBin(trimmed) {
8447
8536
  }
8448
8537
  return null;
8449
8538
  }
8539
+ function selectWin32ExecutableMatch(matches) {
8540
+ const cleaned = matches.map((m) => m.trim()).filter(Boolean);
8541
+ const direct = cleaned.find((m) => DIRECT_EXEC_EXT.has(path10.extname(m).toLowerCase()));
8542
+ if (direct) return direct;
8543
+ const shim = cleaned.find((m) => SHIM_EXEC_EXT.has(path10.extname(m).toLowerCase()));
8544
+ if (shim) return shim;
8545
+ return null;
8546
+ }
8450
8547
  function resolveWin32Executable(command) {
8451
8548
  if (process.platform !== "win32") return command;
8452
8549
  const trimmed = (command || "").trim();
@@ -8459,8 +8556,8 @@ function resolveWin32Executable(command) {
8459
8556
  }).trim();
8460
8557
  if (out) {
8461
8558
  const matches = out.split(/\r?\n/).map((s2) => s2.trim()).filter(Boolean);
8462
- const direct = matches.find((m) => DIRECT_EXEC_EXT.has(path10.extname(m).toLowerCase()));
8463
- return direct || matches[0] || command;
8559
+ const selected = selectWin32ExecutableMatch(matches);
8560
+ if (selected) return selected;
8464
8561
  }
8465
8562
  } catch {
8466
8563
  }
@@ -8468,11 +8565,43 @@ function resolveWin32Executable(command) {
8468
8565
  if (globalBin) return globalBin;
8469
8566
  return command;
8470
8567
  }
8471
- var DIRECT_EXEC_EXT, WIN_EXEC_EXT;
8568
+ function quoteWin32CmdArg(arg) {
8569
+ if (arg.length > 0 && !/[ \t"]/.test(arg)) return arg;
8570
+ let result = '"';
8571
+ let backslashes = 0;
8572
+ for (const ch of arg) {
8573
+ if (ch === "\\") {
8574
+ backslashes += 1;
8575
+ continue;
8576
+ }
8577
+ if (ch === '"') {
8578
+ result += "\\".repeat(backslashes * 2 + 1) + '"';
8579
+ backslashes = 0;
8580
+ continue;
8581
+ }
8582
+ result += "\\".repeat(backslashes) + ch;
8583
+ backslashes = 0;
8584
+ }
8585
+ result += "\\".repeat(backslashes * 2) + '"';
8586
+ return result;
8587
+ }
8588
+ function buildWin32ExecFileSpawn(resolvedCommand, args) {
8589
+ if (process.platform !== "win32") return { file: resolvedCommand, args };
8590
+ const ext = path10.extname(resolvedCommand).toLowerCase();
8591
+ if (!SHIM_EXEC_EXT.has(ext)) return { file: resolvedCommand, args };
8592
+ const commandLine = [resolvedCommand, ...args].map(quoteWin32CmdArg).join(" ");
8593
+ return {
8594
+ file: process.env.ComSpec || "cmd.exe",
8595
+ args: ["/d", "/s", "/c", `"${commandLine}"`],
8596
+ windowsVerbatimArguments: true
8597
+ };
8598
+ }
8599
+ var DIRECT_EXEC_EXT, SHIM_EXEC_EXT, WIN_EXEC_EXT;
8472
8600
  var init_resolve_executable = __esm({
8473
8601
  "src/cli-adapters/resolve-executable.ts"() {
8474
8602
  "use strict";
8475
8603
  DIRECT_EXEC_EXT = /* @__PURE__ */ new Set([".exe", ".com"]);
8604
+ SHIM_EXEC_EXT = /* @__PURE__ */ new Set([".cmd", ".bat"]);
8476
8605
  WIN_EXEC_EXT = [".exe", ".com", ".cmd", ".bat"];
8477
8606
  }
8478
8607
  });
@@ -8663,14 +8792,16 @@ async function runMeshWorktreeBootstrap(mesh, workspace) {
8663
8792
  const startedAt = Date.now();
8664
8793
  state.lastCommand = command.displayCommand;
8665
8794
  const resolvedCommand = resolveWin32Executable(command.command);
8795
+ const spawn4 = buildWin32ExecFileSpawn(resolvedCommand, command.args);
8666
8796
  try {
8667
- const result = await execFileAsync4(resolvedCommand, command.args, {
8797
+ const result = await execFileAsync4(spawn4.file, spawn4.args, {
8668
8798
  cwd,
8669
8799
  encoding: "utf8",
8670
8800
  timeout: command.timeoutMs || DEFAULT_TIMEOUT_MS2,
8671
8801
  maxBuffer: command.outputLimitBytes || DEFAULT_OUTPUT_LIMIT_BYTES,
8672
8802
  env: { ...process.env, CI: process.env.CI || "1", ...command.env || {} },
8673
- windowsHide: true
8803
+ windowsHide: true,
8804
+ ...spawn4.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {}
8674
8805
  });
8675
8806
  state.commandsRun?.push({
8676
8807
  command: command.command,
@@ -10138,7 +10269,7 @@ var init_mesh_scheduling_runtime = __esm({
10138
10269
  function readNonEmptyString2(value) {
10139
10270
  return typeof value === "string" && value.trim() ? value.trim() : "";
10140
10271
  }
10141
- function readRecord4(value) {
10272
+ function readRecord5(value) {
10142
10273
  return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
10143
10274
  }
10144
10275
  function buildMeshWorkerRelayStamp(currentSettings, meshContext) {
@@ -10166,17 +10297,17 @@ function resolveEventSessionId(event, fallback) {
10166
10297
  return readNonEmptyString2(event.targetSessionId) || readNonEmptyString2(event.sessionId) || readNonEmptyString2(event.instanceId) || readNonEmptyString2(fallback);
10167
10298
  }
10168
10299
  function readRefineJobId(event) {
10169
- const metadata = readRecord4(event.metadataEvent) || event;
10170
- const result = readRecord4(metadata.result);
10171
- const refineJob = readRecord4(result?.refineJob);
10300
+ const metadata = readRecord5(event.metadataEvent) || event;
10301
+ const result = readRecord5(metadata.result);
10302
+ const refineJob = readRecord5(result?.refineJob);
10172
10303
  return readNonEmptyString2(metadata.jobId) || readNonEmptyString2(refineJob?.jobId);
10173
10304
  }
10174
10305
  function readWorkerResultMetadata(event) {
10175
- return readRecord4(event.workerResult) || readRecord4(event.meshWorkerResult) || readRecord4(event.structuredResult);
10306
+ return readRecord5(event.workerResult) || readRecord5(event.meshWorkerResult) || readRecord5(event.structuredResult);
10176
10307
  }
10177
10308
  function readMeshCompletionSummary(metadataEvent) {
10178
10309
  const workerResult = readWorkerResultMetadata(metadataEvent);
10179
- const resultRecord = readRecord4(metadataEvent.result);
10310
+ const resultRecord = readRecord5(metadataEvent.result);
10180
10311
  return readNonEmptyString2(metadataEvent.finalSummary) || readNonEmptyString2(workerResult?.summary) || readNonEmptyString2(workerResult?.finalSummary) || readNonEmptyString2(resultRecord?.summary) || readNonEmptyString2(resultRecord?.finalSummary);
10181
10312
  }
10182
10313
  function truncateSurfacedPreview(text) {
@@ -10214,7 +10345,7 @@ function readEventTimestampValue(value) {
10214
10345
  return 0;
10215
10346
  }
10216
10347
  function isMissingFinalAssistantDiagnostic(record) {
10217
- const diag = readRecord4(record?.completionDiagnostic);
10348
+ const diag = readRecord5(record?.completionDiagnostic);
10218
10349
  return diag?.finalAssistantPresent === false || diag?.blockReason === "missing_final_assistant";
10219
10350
  }
10220
10351
  function isFalseIdleCompletion(record) {
@@ -10323,10 +10454,10 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
10323
10454
  }
10324
10455
  if (args.event === "refine:completed") {
10325
10456
  const jobId = readRefineJobId({ metadataEvent: args.metadataEvent });
10326
- const result = readRecord4(args.metadataEvent.result);
10327
- const validationSummary = readRecord4(result?.validationSummary);
10328
- const patchEquivalence = readRecord4(result?.patchEquivalence);
10329
- const finalConvergence = readRecord4(result?.finalBranchConvergenceState);
10457
+ const result = readRecord5(args.metadataEvent.result);
10458
+ const validationSummary = readRecord5(result?.validationSummary);
10459
+ const patchEquivalence = readRecord5(result?.patchEquivalence);
10460
+ const finalConvergence = readRecord5(result?.finalBranchConvergenceState);
10330
10461
  const validationStatus = readNonEmptyString2(validationSummary?.status);
10331
10462
  const patchStatus = readNonEmptyString2(patchEquivalence?.status) || (patchEquivalence?.equivalent === true ? "passed" : "");
10332
10463
  const into = readNonEmptyString2(result?.into);
@@ -10347,10 +10478,10 @@ Next step: ${nextStep}`;
10347
10478
  }
10348
10479
  if (args.event === "refine:failed") {
10349
10480
  const jobId = readRefineJobId({ metadataEvent: args.metadataEvent });
10350
- const result = readRecord4(args.metadataEvent.result);
10351
- const validationSummary = readRecord4(result?.validationSummary);
10352
- const patchEquivalence = readRecord4(result?.patchEquivalence);
10353
- const finalConvergence = readRecord4(result?.finalBranchConvergenceState);
10481
+ const result = readRecord5(args.metadataEvent.result);
10482
+ const validationSummary = readRecord5(result?.validationSummary);
10483
+ const patchEquivalence = readRecord5(result?.patchEquivalence);
10484
+ const finalConvergence = readRecord5(result?.finalBranchConvergenceState);
10354
10485
  const code = readNonEmptyString2(result?.code);
10355
10486
  const error = readNonEmptyString2(result?.error);
10356
10487
  const validationStatus = readNonEmptyString2(validationSummary?.status);
@@ -10393,9 +10524,9 @@ function normalizeCoordinatorDaemonIds(coordinatorDaemonId) {
10393
10524
  return expandDaemonIdForms(coordinatorDaemonId);
10394
10525
  }
10395
10526
  function readRefineJobId2(event) {
10396
- const metadata = readRecord4(event.metadataEvent) || event;
10397
- const result = readRecord4(metadata.result);
10398
- const refineJob = readRecord4(result?.refineJob);
10527
+ const metadata = readRecord5(event.metadataEvent) || event;
10528
+ const result = readRecord5(metadata.result);
10529
+ const refineJob = readRecord5(result?.refineJob);
10399
10530
  return readNonEmptyString2(metadata.jobId) || readNonEmptyString2(refineJob?.jobId);
10400
10531
  }
10401
10532
  function hasPendingRefineTerminalEventDuplicate(event) {
@@ -10407,12 +10538,12 @@ function hasPendingRefineTerminalEventDuplicate(event) {
10407
10538
  );
10408
10539
  }
10409
10540
  function buildPendingEventFingerprint(event) {
10410
- const metadata = readRecord4(event.metadataEvent) || {};
10541
+ const metadata = readRecord5(event.metadataEvent) || {};
10411
10542
  if (event.event === "worktree_bootstrap_complete" || event.event === "worktree_bootstrap_failed") {
10412
10543
  return [event.meshId, event.event, event.nodeId || ""].join("::");
10413
10544
  }
10414
10545
  if (TERMINAL_COMPLETION_EVENTS.has(event.event)) {
10415
- const terminalTaskId = readNonEmptyString2(metadata.taskId) || readNonEmptyString2(readRecord4(metadata.payload)?.taskId);
10546
+ const terminalTaskId = readNonEmptyString2(metadata.taskId) || readNonEmptyString2(readRecord5(metadata.payload)?.taskId);
10416
10547
  if (terminalTaskId) {
10417
10548
  return [
10418
10549
  event.meshId,
@@ -10422,9 +10553,14 @@ function buildPendingEventFingerprint(event) {
10422
10553
  ].join("::");
10423
10554
  }
10424
10555
  }
10556
+ const consensusGroupId = readNonEmptyString2(metadata.consensusGroupId) || readNonEmptyString2(readRecord5(metadata.payload)?.consensusGroupId);
10557
+ if (consensusGroupId) {
10558
+ const groupTaskId = readNonEmptyString2(metadata.taskId) || readNonEmptyString2(readRecord5(metadata.payload)?.taskId);
10559
+ return [event.meshId, event.event, groupTaskId || "", consensusGroupId, "group"].join("::");
10560
+ }
10425
10561
  const sessionId = resolveEventSessionId(metadata);
10426
10562
  const providerSessionId = readNonEmptyString2(metadata.providerSessionId);
10427
- const taskId = readNonEmptyString2(metadata.taskId) || readNonEmptyString2(readRecord4(metadata.payload)?.taskId);
10563
+ const taskId = readNonEmptyString2(metadata.taskId) || readNonEmptyString2(readRecord5(metadata.payload)?.taskId);
10428
10564
  const jobId = readRefineJobId2(event);
10429
10565
  const timestamp = metadata.timestamp !== void 0 && metadata.timestamp !== null ? String(metadata.timestamp) : "";
10430
10566
  return [
@@ -10492,15 +10628,15 @@ function refineTerminalEventFromLedger(meshId, pending) {
10492
10628
  for (let i = entries.length - 1; i >= 0; i--) {
10493
10629
  const entry = entries[i];
10494
10630
  if (entry.kind !== "task_completed" && entry.kind !== "task_failed") continue;
10495
- const payload = readRecord4(entry.payload);
10631
+ const payload = readRecord5(entry.payload);
10496
10632
  if (payload?.source !== "refine_mesh_node_async_job") continue;
10497
- const refineJob = readRecord4(payload.refineJob);
10633
+ const refineJob = readRecord5(payload.refineJob);
10498
10634
  const jobId = readNonEmptyString2(refineJob?.jobId);
10499
10635
  if (!jobId || !acceptedJobIds.has(jobId)) continue;
10500
10636
  const eventName = entry.kind === "task_completed" ? "refine:completed" : "refine:failed";
10501
10637
  if (existingTerminalJobIds.has(`${eventName}:${jobId}`)) continue;
10502
10638
  existingTerminalJobIds.add(`${eventName}:${jobId}`);
10503
- const result = readRecord4(payload.result);
10639
+ const result = readRecord5(payload.result);
10504
10640
  const metadataEvent = {
10505
10641
  source: "refine_mesh_node_async_job",
10506
10642
  jobId,
@@ -11005,7 +11141,7 @@ function buildNoProgressCompletionReconciliation(args) {
11005
11141
  const providerType = readNonEmptyString2(args.metadataEvent.providerType);
11006
11142
  const providerSessionId = readNonEmptyString2(args.metadataEvent.providerSessionId);
11007
11143
  const workerResult = readWorkerResultMetadata(args.metadataEvent);
11008
- const completionDiagnostic = readRecord4(args.metadataEvent.completionDiagnostic);
11144
+ const completionDiagnostic = readRecord5(args.metadataEvent.completionDiagnostic);
11009
11145
  const finalSummary = readNonEmptyString2(args.metadataEvent.finalSummary);
11010
11146
  const status = readNonEmptyString2(args.metadataEvent.status).toLowerCase();
11011
11147
  const explicitCompletionEvidence = Boolean(
@@ -12248,6 +12384,12 @@ function sessionHasActiveAssignment(meshId, sessionId) {
12248
12384
  }
12249
12385
  return false;
12250
12386
  }
12387
+ function isSessionActivelyGenerating(components, sessionId) {
12388
+ if (!sessionId) return false;
12389
+ const state = components.instanceManager?.getInstance?.(sessionId)?.getState?.();
12390
+ if (!state) return false;
12391
+ return sessionStateLooksActive(state);
12392
+ }
12251
12393
  function liveSessionCountForNode(components, meshId, nodeId) {
12252
12394
  return components.instanceManager.getByCategory("cli").filter((inst) => {
12253
12395
  const state = inst.getState();
@@ -15691,13 +15833,22 @@ function injectMeshSystemMessage(components, args) {
15691
15833
  ) || readNonEmptyString2(args.metadataEvent.meshCoordinatorSessionId);
15692
15834
  const enrichedMetadataEvent = (() => {
15693
15835
  const last = sourceSession ? getLastDisplayMessage(sourceSession.getState()) : null;
15694
- if (!last || !last.preview) return args.metadataEvent;
15695
- return {
15836
+ const base = !last || !last.preview ? args.metadataEvent : {
15696
15837
  ...args.metadataEvent,
15697
15838
  lastMessagePreview: last.preview,
15698
15839
  lastMessageRole: last.role,
15699
15840
  ...last.receivedAt > 0 ? { lastMessageAt: last.receivedAt } : {}
15700
15841
  };
15842
+ if (readNonEmptyString2(base.consensusGroupId)) return base;
15843
+ const eventTaskId = readNonEmptyString2(args.metadataEvent.taskId);
15844
+ if (!eventTaskId) return base;
15845
+ try {
15846
+ const entry = MeshRuntimeStore.getInstance().findQueueEntryById(args.meshId, eventTaskId);
15847
+ const consensusGroupId = readNonEmptyString2(entry?.consensusGroupId);
15848
+ if (consensusGroupId) return { ...base, consensusGroupId };
15849
+ } catch {
15850
+ }
15851
+ return base;
15701
15852
  })();
15702
15853
  if (components.onMeshCoordinatorEventForwarded) {
15703
15854
  try {
@@ -17314,6 +17465,7 @@ __export(mesh_events_exports, {
17314
17465
  getPendingMeshCoordinatorEvents: () => getPendingMeshCoordinatorEvents,
17315
17466
  handleMeshForwardEvent: () => handleMeshForwardEvent,
17316
17467
  isMeshCoordinatorEvent: () => isMeshCoordinatorEvent,
17468
+ isSessionActivelyGenerating: () => isSessionActivelyGenerating,
17317
17469
  queuePendingMeshCoordinatorEvent: () => queuePendingMeshCoordinatorEvent,
17318
17470
  reconcileDirectDispatchCompletionFromTranscript: () => reconcileDirectDispatchCompletionFromTranscript,
17319
17471
  resolveCoordinatorDrainDeliverability: () => resolveCoordinatorDrainDeliverability,
@@ -24287,6 +24439,124 @@ function buildMeshLedgerReconciliationEvidence(meshId, replicas) {
24287
24439
  init_mesh_work_queue();
24288
24440
  init_mesh_active_work();
24289
24441
  init_mesh_refine_status();
24442
+
24443
+ // src/mesh/mesh-magi-status.ts
24444
+ function readString7(value) {
24445
+ return typeof value === "string" && value.trim() ? value.trim() : void 0;
24446
+ }
24447
+ function readRecord4(value) {
24448
+ return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
24449
+ }
24450
+ function readNumber2(value) {
24451
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
24452
+ }
24453
+ var MAGI_NEEDS_VERIFICATION_PREVIEW_CAP = 8;
24454
+ function summarizeNeedsVerification(synthesis) {
24455
+ const list = Array.isArray(synthesis?.needsVerification) ? synthesis.needsVerification : void 0;
24456
+ if (!list) return void 0;
24457
+ const items = [];
24458
+ for (const raw of list.slice(0, MAGI_NEEDS_VERIFICATION_PREVIEW_CAP)) {
24459
+ const r = readRecord4(raw);
24460
+ const claim = readString7(r?.claim);
24461
+ if (!claim) continue;
24462
+ items.push({ claim, category: readString7(r?.category) || "needs_verification" });
24463
+ }
24464
+ return items;
24465
+ }
24466
+ function mergeGroup(groups, patch) {
24467
+ const consensusGroupId = readString7(patch.consensusGroupId);
24468
+ if (!consensusGroupId) return;
24469
+ const previous = groups.get(consensusGroupId);
24470
+ const status = patch.status === "synthesized" || previous?.status === "synthesized" ? "synthesized" : "running";
24471
+ const definedPatch = Object.fromEntries(
24472
+ Object.entries(patch).filter(([, v]) => v !== void 0)
24473
+ );
24474
+ groups.set(consensusGroupId, { ...previous, ...definedPatch, consensusGroupId, status });
24475
+ }
24476
+ function buildMeshMagiActivity(args) {
24477
+ const groups = /* @__PURE__ */ new Map();
24478
+ for (const entry of args.ledgerEntries || []) {
24479
+ const payload = readRecord4(entry.payload);
24480
+ if (payload?.source !== "magi") continue;
24481
+ const consensusGroupId = readString7(payload.consensusGroupId);
24482
+ if (!consensusGroupId) continue;
24483
+ if (entry.kind === "magi_synthesis") {
24484
+ const synthesis = readRecord4(payload.synthesis);
24485
+ mergeGroup(groups, {
24486
+ consensusGroupId,
24487
+ status: "synthesized",
24488
+ missionId: readString7(payload.missionId),
24489
+ panel: readString7(payload.panel),
24490
+ question: readString7(payload.question),
24491
+ replicaCount: readNumber2(synthesis?.replicasExpected) ?? readNumber2(payload.replicaCount),
24492
+ answered: readNumber2(synthesis?.replicasAnswered),
24493
+ missing: readNumber2(synthesis?.replicasMissing),
24494
+ staleReplicas: readNumber2(payload.staleReplicas) ?? readNumber2(synthesis?.staleReplicas),
24495
+ needsVerificationCount: Array.isArray(synthesis?.needsVerification) ? synthesis.needsVerification.length : void 0,
24496
+ agreedCount: Array.isArray(synthesis?.agreed) ? synthesis.agreed.length : void 0,
24497
+ independenceBanner: synthesis && "independenceBanner" in synthesis ? synthesis.independenceBanner : void 0,
24498
+ gitSkew: readRecord4(synthesis?.gitSkew),
24499
+ needsVerification: summarizeNeedsVerification(synthesis),
24500
+ openQuestions: Array.isArray(synthesis?.openQuestions) ? synthesis.openQuestions.slice(0, 10) : void 0,
24501
+ lastLedgerKind: entry.kind,
24502
+ lastUpdatedAt: entry.timestamp
24503
+ });
24504
+ } else if (entry.kind === "magi_dispatched") {
24505
+ mergeGroup(groups, {
24506
+ consensusGroupId,
24507
+ status: "running",
24508
+ missionId: readString7(payload.missionId),
24509
+ panel: readString7(payload.panel),
24510
+ question: readString7(payload.question),
24511
+ replicaCount: readNumber2(payload.replicaCount),
24512
+ lastLedgerKind: entry.kind,
24513
+ lastUpdatedAt: entry.timestamp
24514
+ });
24515
+ }
24516
+ }
24517
+ return Array.from(groups.values()).sort((a, b) => {
24518
+ const at = new Date(a.lastUpdatedAt || "").getTime();
24519
+ const bt = new Date(b.lastUpdatedAt || "").getTime();
24520
+ return (Number.isFinite(bt) ? bt : 0) - (Number.isFinite(at) ? at : 0);
24521
+ });
24522
+ }
24523
+ var STALE_MAGI_WINDOW_MS = 6 * 60 * 60 * 1e3;
24524
+ var RECENT_MAGI_CAP = 6;
24525
+ function activityTime(g) {
24526
+ const t = new Date(g.lastUpdatedAt || "").getTime();
24527
+ return Number.isFinite(t) ? t : 0;
24528
+ }
24529
+ function summarizeMeshMagiActivity(activity) {
24530
+ const running = [];
24531
+ const synthesized = [];
24532
+ for (const g of activity) {
24533
+ if (g.status === "synthesized") synthesized.push(g);
24534
+ else running.push(g);
24535
+ }
24536
+ let newest = 0;
24537
+ for (const g of activity) newest = Math.max(newest, activityTime(g));
24538
+ const cutoff = newest - STALE_MAGI_WINDOW_MS;
24539
+ const synthesizedByRecency = [...synthesized].sort((a, b) => activityTime(b) - activityTime(a));
24540
+ const freshSynthesized = synthesizedByRecency.filter((g) => activityTime(g) >= cutoff).slice(0, RECENT_MAGI_CAP);
24541
+ const byStatus = {};
24542
+ for (const g of [...running, ...freshSynthesized]) {
24543
+ byStatus[g.status] = (byStatus[g.status] ?? 0) + 1;
24544
+ }
24545
+ const runningByRecency = [...running].sort((a, b) => activityTime(b) - activityTime(a));
24546
+ return {
24547
+ total: running.length + freshSynthesized.length,
24548
+ byStatus,
24549
+ staleSynthesized: synthesized.length - freshSynthesized.length,
24550
+ groups: [...runningByRecency, ...freshSynthesized]
24551
+ };
24552
+ }
24553
+ function getMeshMagiActivityByGroup(ledgerEntries, consensusGroupId) {
24554
+ const key2 = readString7(consensusGroupId);
24555
+ if (!key2) return void 0;
24556
+ return buildMeshMagiActivity({ ledgerEntries }).find((g) => g.consensusGroupId === key2);
24557
+ }
24558
+
24559
+ // src/index.ts
24290
24560
  init_mesh_scheduling_runtime();
24291
24561
  init_mesh_host_ownership();
24292
24562
  init_mesh_events();
@@ -49211,7 +49481,18 @@ var meshQueueHandlers = {
49211
49481
  const ownerFailure = await ctx.requireMeshHostMutationOwner(meshId, args?.inlineMesh, "queue requeue");
49212
49482
  if (ownerFailure) return ownerFailure;
49213
49483
  try {
49214
- const { requeueTask: requeueTask2 } = await Promise.resolve().then(() => (init_mesh_work_queue(), mesh_work_queue_exports));
49484
+ const { requeueTask: requeueTask2, getQueue: getQueue2 } = await Promise.resolve().then(() => (init_mesh_work_queue(), mesh_work_queue_exports));
49485
+ if (args?.force !== true) {
49486
+ const { isSessionActivelyGenerating: isSessionActivelyGenerating2 } = await Promise.resolve().then(() => (init_mesh_events(), mesh_events_exports));
49487
+ const existing = getQueue2(meshId).find((t) => t?.id === taskId);
49488
+ if (existing?.status === "assigned" && existing.assignedSessionId && isSessionActivelyGenerating2(ctx.deps, existing.assignedSessionId)) {
49489
+ return {
49490
+ success: false,
49491
+ error: `Task '${taskId}' is actively dispatched/generating (live session ${existing.assignedSessionId}); requeue refused to avoid a duplicate second dispatch. Pass force:true to override, or cancel and re-enqueue.`,
49492
+ task: existing
49493
+ };
49494
+ }
49495
+ }
49215
49496
  const task = requeueTask2(meshId, taskId, {
49216
49497
  reason: typeof args?.reason === "string" ? args.reason : void 0,
49217
49498
  targetNodeId: typeof args?.targetNodeId === "string" ? args.targetNodeId.trim() : void 0,
@@ -50188,7 +50469,7 @@ function runGit2(repoRoot, args) {
50188
50469
  return "";
50189
50470
  }
50190
50471
  }
50191
- function readRecord5(repoRoot) {
50472
+ function readRecord6(repoRoot) {
50192
50473
  const path43 = resolve19(repoRoot, PREVIEW_DEPLOY_RECORD);
50193
50474
  if (!existsSync40(path43)) return null;
50194
50475
  try {
@@ -50228,7 +50509,7 @@ function readCurrentMainCommit(repoRoot) {
50228
50509
  }
50229
50510
  function buildPreviewFreshness(repoRoot) {
50230
50511
  const current = readCurrentMainCommit(repoRoot);
50231
- const record = readRecord5(repoRoot);
50512
+ const record = readRecord6(repoRoot);
50232
50513
  const lastPreviewCommit = normalizeCommit(record?.lastPreviewCommit);
50233
50514
  const targets = readTargetFreshness(record, current.currentMainCommit);
50234
50515
  let status = "unknown";
@@ -53147,13 +53428,15 @@ async function runMeshRefineValidationGate(mesh, workspace, opts) {
53147
53428
  const cwd = candidate.cwd ? pathResolve2(workspace, candidate.cwd) : workspace;
53148
53429
  const timeout = candidate.timeoutMs || REFINE_VALIDATION_TIMEOUT_MS;
53149
53430
  const resolvedCommand = resolveWin32Executable(candidate.command);
53431
+ const spawn4 = buildWin32ExecFileSpawn(resolvedCommand, candidate.args);
53150
53432
  try {
53151
- const result = await execFileAsync4(resolvedCommand, candidate.args, {
53433
+ const result = await execFileAsync4(spawn4.file, spawn4.args, {
53152
53434
  cwd,
53153
53435
  encoding: "utf8",
53154
53436
  timeout,
53155
53437
  maxBuffer: candidate.outputLimitBytes || REFINE_VALIDATION_OUTPUT_LIMIT_BYTES,
53156
- env: { ...process.env, CI: process.env.CI || "1", ...candidate.env || {} }
53438
+ env: { ...process.env, CI: process.env.CI || "1", ...candidate.env || {} },
53439
+ ...spawn4.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {}
53157
53440
  });
53158
53441
  summary.bootstrapCommandsRun.push(commandRecord(candidate, cwd, startedAt, result, true, { exitCode: 0 }));
53159
53442
  } catch (error) {
@@ -53164,7 +53447,7 @@ async function runMeshRefineValidationGate(mesh, workspace, opts) {
53164
53447
  timedOut: error?.killed === true || /timed out/i.test(String(error?.message || "")),
53165
53448
  ...spawnResolutionFailed ? { failureKind: "spawn_resolution_failed", resolvedCommand } : { failureKind: "dependency_bootstrap_failed" }
53166
53449
  }));
53167
- summary.bootstrap = { stage: "failed", error: describeSpawnError(error, candidate.command, spawnResolutionFailed) };
53450
+ summary.bootstrap = { stage: "failed", error: describeSpawnError(error, resolvedCommand, spawnResolutionFailed) };
53168
53451
  summary.status = "failed";
53169
53452
  summary.failureKind = spawnResolutionFailed ? "spawn_resolution_failed" : "dependency_bootstrap_failed";
53170
53453
  summary.failureCode = spawnResolutionFailed ? "spawn_resolution_failed" : "dependency_bootstrap_failed";
@@ -53191,13 +53474,15 @@ async function runMeshRefineValidationGate(mesh, workspace, opts) {
53191
53474
  return summary;
53192
53475
  }
53193
53476
  const resolvedCommand = resolveWin32Executable(candidate.command);
53477
+ const spawn4 = buildWin32ExecFileSpawn(resolvedCommand, candidate.args);
53194
53478
  try {
53195
- const result = await execFileAsync4(resolvedCommand, candidate.args, {
53479
+ const result = await execFileAsync4(spawn4.file, spawn4.args, {
53196
53480
  cwd,
53197
53481
  encoding: "utf8",
53198
53482
  timeout,
53199
53483
  maxBuffer: candidate.outputLimitBytes || REFINE_VALIDATION_OUTPUT_LIMIT_BYTES,
53200
- env: { ...process.env, CI: process.env.CI || "1", ...candidate.env || {} }
53484
+ env: { ...process.env, CI: process.env.CI || "1", ...candidate.env || {} },
53485
+ ...spawn4.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {}
53201
53486
  });
53202
53487
  summary.commandsRun.push(commandRecord(candidate, cwd, startedAt, result, true, { exitCode: 0 }));
53203
53488
  } catch (error) {
@@ -53214,7 +53499,7 @@ async function runMeshRefineValidationGate(mesh, workspace, opts) {
53214
53499
  if (spawnResolutionFailed) {
53215
53500
  summary.failureKind = "spawn_resolution_failed";
53216
53501
  summary.failureCode = "spawn_resolution_failed";
53217
- summary.spawnResolutionError = describeSpawnError(error, candidate.command, true);
53502
+ summary.spawnResolutionError = describeSpawnError(error, resolvedCommand, true);
53218
53503
  } else if (missingDependencyFailure) {
53219
53504
  summary.failureKind = "missing_dependencies";
53220
53505
  summary.failureCode = "missing_dependencies";
@@ -64085,6 +64370,7 @@ export {
64085
64370
  IdeProviderInstance,
64086
64371
  InMemoryGitSnapshotStore,
64087
64372
  LOG,
64373
+ MAGI_NEEDS_VERIFICATION_PREVIEW_CAP,
64088
64374
  MAX_LEDGER_SLICE_LIMIT,
64089
64375
  MESH_CONVERGE_FAST_FORWARD_TAG,
64090
64376
  MESH_CONVERGE_REFINE_TAG,
@@ -64106,8 +64392,10 @@ export {
64106
64392
  ProviderCliAdapter,
64107
64393
  ProviderInstanceManager,
64108
64394
  ProviderLoader,
64395
+ RECENT_MAGI_CAP,
64109
64396
  RECENT_TERMINAL_REFINE_CAP,
64110
64397
  RawTerminalAttachment,
64398
+ STALE_MAGI_WINDOW_MS,
64111
64399
  STALE_TERMINAL_REFINE_WINDOW_MS,
64112
64400
  STANDALONE_CDP_SCAN_INTERVAL_MS,
64113
64401
  SessionHostPtyTransportFactory,
@@ -64137,6 +64425,7 @@ export {
64137
64425
  buildMeshHostRequiredFailure,
64138
64426
  buildMeshLedgerReconciliationEvidence,
64139
64427
  buildMeshLedgerReplicaEvidence,
64428
+ buildMeshMagiActivity,
64140
64429
  buildMeshNodeCapabilityTags,
64141
64430
  buildMeshNodeDataFreshness,
64142
64431
  buildMeshNodeProbeFreshness,
@@ -64223,8 +64512,10 @@ export {
64223
64512
  getLedgerDir,
64224
64513
  getLedgerSummary,
64225
64514
  getLogLevel,
64515
+ getMagiPanel,
64226
64516
  getMesh,
64227
64517
  getMeshByRepo,
64518
+ getMeshMagiActivityByGroup,
64228
64519
  getMeshMission,
64229
64520
  getMeshMissions,
64230
64521
  getMeshQueueRevision,
@@ -64276,6 +64567,7 @@ export {
64276
64567
  launchWithCdp,
64277
64568
  listCoordinatorsForWorkspace,
64278
64569
  listHostedCliRuntimes,
64570
+ listMagiPanels,
64279
64571
  listMeshMissionSummaries,
64280
64572
  listMeshes,
64281
64573
  listWorktrees,
@@ -64308,6 +64600,7 @@ export {
64308
64600
  normalizeInputEnvelope,
64309
64601
  normalizeInteractivePrompt,
64310
64602
  normalizeInteractivePromptResponse,
64603
+ normalizeMagiPanel,
64311
64604
  normalizeManagedStatus,
64312
64605
  normalizeMeshCapabilityTags,
64313
64606
  normalizeMeshDaemonRole,
@@ -64345,6 +64638,7 @@ export {
64345
64638
  recordMeshToolCall,
64346
64639
  registerExtensionProviders,
64347
64640
  registerMeshCoordinator,
64641
+ removeMagiPanel,
64348
64642
  removeNode,
64349
64643
  removeWorktree,
64350
64644
  requeueTask,
@@ -64388,6 +64682,7 @@ export {
64388
64682
  suggestMeshRefineConfig,
64389
64683
  summarizeGitStatus,
64390
64684
  summarizeMeshAsyncRefineJobs,
64685
+ summarizeMeshMagiActivity,
64391
64686
  summarizeMeshMission,
64392
64687
  summarizeMissionTasks,
64393
64688
  triggerMeshQueue,
@@ -64399,6 +64694,7 @@ export {
64399
64694
  updateSessionDeliveryStatus,
64400
64695
  updateSessionTaskStatus,
64401
64696
  updateTaskStatus,
64697
+ upsertMagiPanel,
64402
64698
  upsertMeshMission,
64403
64699
  upsertSavedProviderSession,
64404
64700
  validateChangeImpactConfig,