@adhdev/daemon-core 0.9.82-rc.481 → 0.9.82-rc.482

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 ? "0d212674453127562e4c5827f5515163ea29f072" : void 0) ?? "unknown";
413
- const commitShort = readInjected(true ? "0d212674" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
414
- const version = readInjected(true ? "0.9.82-rc.481" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
415
- const builtAt = readInjected(true ? "2026-07-07T20:14:39.096Z" : void 0);
412
+ const commit = readInjected(true ? "5c311ee659d4fe9b1638a1bb325b681ef6ecc24e" : void 0) ?? "unknown";
413
+ const commitShort = readInjected(true ? "5c311ee6" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
414
+ const version = readInjected(true ? "0.9.82-rc.482" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
415
+ const builtAt = readInjected(true ? "2026-07-08T00:15:56.441Z" : void 0);
416
416
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
417
417
  return cached;
418
418
  }
@@ -2819,8 +2819,6 @@ var init_dist = __esm({
2819
2819
  "mesh_review_inbox",
2820
2820
  "mesh_magi_review",
2821
2821
  "mesh_magi_collect",
2822
- "mesh_magi_panel_set",
2823
- "mesh_magi_panel_list",
2824
2822
  "mesh_magi_kind_panel_set",
2825
2823
  "mesh_magi_kind_panel_list"
2826
2824
  ];
@@ -2920,24 +2918,19 @@ __export(mesh_config_exports, {
2920
2918
  createMeshHostPairingToken: () => createMeshHostPairingToken,
2921
2919
  deleteMesh: () => deleteMesh,
2922
2920
  getMagiKindPanel: () => getMagiKindPanel,
2923
- getMagiPanel: () => getMagiPanel,
2924
2921
  getMesh: () => getMesh,
2925
2922
  getMeshByRepo: () => getMeshByRepo,
2926
2923
  listMagiKindPanels: () => listMagiKindPanels,
2927
- listMagiPanels: () => listMagiPanels,
2928
2924
  listMeshes: () => listMeshes,
2929
2925
  markMeshHostPairingJoined: () => markMeshHostPairingJoined,
2930
- normalizeMagiPanel: () => normalizeMagiPanel,
2931
2926
  normalizeMagiSlots: () => normalizeMagiSlots,
2932
2927
  normalizeRepoIdentity: () => normalizeRepoIdentity,
2933
2928
  removeMagiKindPanel: () => removeMagiKindPanel,
2934
- removeMagiPanel: () => removeMagiPanel,
2935
2929
  removeNode: () => removeNode,
2936
2930
  setMagiKindPanel: () => setMagiKindPanel,
2937
2931
  tokenIdForManualPairing: () => tokenIdForManualPairing,
2938
2932
  updateMesh: () => updateMesh,
2939
- updateNode: () => updateNode,
2940
- upsertMagiPanel: () => upsertMagiPanel
2933
+ updateNode: () => updateNode
2941
2934
  });
2942
2935
  function getMeshConfigPath() {
2943
2936
  return (0, import_path3.join)(getConfigDir(), "meshes.json");
@@ -3333,99 +3326,6 @@ function normalizeReplicaCount(value) {
3333
3326
  const n = Math.floor(value);
3334
3327
  return n >= 1 ? n : void 0;
3335
3328
  }
3336
- function normalizeMagiPanelDefaultKind(raw) {
3337
- if (raw == null) return void 0;
3338
- const s2 = typeof raw === "string" ? raw.trim().toLowerCase() : "";
3339
- if (s2 === "claim_audit" || s2 === "rca" || s2 === "design") return s2;
3340
- if (s2 === "freeform") {
3341
- console.warn(
3342
- "[magi] panel defaultKind='freeform' rejected \u2014 freeform contributes no structured claims to cross-verification; dropping (use claim_audit / rca / design, or omit)."
3343
- );
3344
- return void 0;
3345
- }
3346
- return void 0;
3347
- }
3348
- function normalizeMagiPanel(config) {
3349
- if (!config || typeof config !== "object" || Array.isArray(config)) {
3350
- throw new Error("invalid_magi_panel: config must be an object");
3351
- }
3352
- const raw = config;
3353
- const rawMembers = raw.members;
3354
- if (!Array.isArray(rawMembers) || rawMembers.length === 0) {
3355
- throw new Error("invalid_magi_panel: members must be a non-empty array");
3356
- }
3357
- if (rawMembers.length > MAX_MAGI_PANEL_MEMBERS) {
3358
- throw new Error(`invalid_magi_panel: too many members (max ${MAX_MAGI_PANEL_MEMBERS})`);
3359
- }
3360
- const members = rawMembers.map((entry, idx) => {
3361
- if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
3362
- throw new Error(`invalid_magi_panel: member[${idx}] must be an object`);
3363
- }
3364
- const m = entry;
3365
- const provider = typeof m.provider === "string" ? m.provider.trim() : "";
3366
- if (!provider) {
3367
- throw new Error(`invalid_magi_panel: member[${idx}].provider is required`);
3368
- }
3369
- const nodeId = typeof m.nodeId === "string" && m.nodeId.trim() ? m.nodeId.trim() : void 0;
3370
- const model = typeof m.model === "string" && m.model.trim() ? m.model.trim() : void 0;
3371
- const capabilityTags = normalizeCapabilityTags(m.capabilityTags);
3372
- const n = normalizeReplicaCount(m.n);
3373
- return {
3374
- provider,
3375
- ...nodeId ? { nodeId } : {},
3376
- ...model ? { model } : {},
3377
- ...capabilityTags ? { capabilityTags } : {},
3378
- ...n !== void 0 ? { n } : {}
3379
- };
3380
- });
3381
- const description = typeof raw.description === "string" && raw.description.trim() ? raw.description.trim().slice(0, 200) : void 0;
3382
- const defaultN = normalizeReplicaCount(raw.defaultN);
3383
- const defaultKind = normalizeMagiPanelDefaultKind(raw.defaultKind);
3384
- return {
3385
- ...description ? { description } : {},
3386
- members,
3387
- ...defaultN !== void 0 ? { defaultN } : {},
3388
- ...defaultKind !== void 0 ? { defaultKind } : {},
3389
- // dedupExempt is always meaningful for a MAGI panel (intentional same-prompt
3390
- // fan-out). Persist it true unless the caller explicitly disables it.
3391
- dedupExempt: raw.dedupExempt === false ? false : true
3392
- };
3393
- }
3394
- function normalizePanelName(name) {
3395
- const trimmed = typeof name === "string" ? name.trim() : "";
3396
- if (!trimmed) throw new Error("invalid_magi_panel: panel name is required");
3397
- return trimmed.slice(0, 100);
3398
- }
3399
- function listMagiPanels() {
3400
- return loadMeshConfig().magiPanels ?? {};
3401
- }
3402
- function getMagiPanel(name) {
3403
- const key2 = typeof name === "string" ? name.trim() : "";
3404
- if (!key2) return void 0;
3405
- return loadMeshConfig().magiPanels?.[key2];
3406
- }
3407
- function upsertMagiPanel(name, config, opts = {}) {
3408
- const key2 = normalizePanelName(name);
3409
- const panel = normalizeMagiPanel(config);
3410
- const stored = loadMeshConfig();
3411
- const panels = stored.magiPanels ?? {};
3412
- if (panels[key2] && opts.overwrite !== true) {
3413
- throw new Error(`magi_panel_exists: panel '${key2}' already exists \u2014 pass overwrite=true to replace it`);
3414
- }
3415
- panels[key2] = panel;
3416
- stored.magiPanels = panels;
3417
- saveMeshConfig(stored);
3418
- return panel;
3419
- }
3420
- function removeMagiPanel(name) {
3421
- const key2 = typeof name === "string" ? name.trim() : "";
3422
- if (!key2) return false;
3423
- const stored = loadMeshConfig();
3424
- if (!stored.magiPanels || !stored.magiPanels[key2]) return false;
3425
- delete stored.magiPanels[key2];
3426
- saveMeshConfig(stored);
3427
- return true;
3428
- }
3429
3329
  function normalizeMagiTaskKindKey(raw) {
3430
3330
  const s2 = typeof raw === "string" ? raw.trim().toLowerCase() : "";
3431
3331
  if (!MAGI_KIND_PANEL_KINDS.includes(s2)) {
@@ -3497,7 +3397,7 @@ function removeMagiKindPanel(kind) {
3497
3397
  saveMeshConfig(stored);
3498
3398
  return true;
3499
3399
  }
3500
- var import_fs3, import_path3, import_crypto3, mergeMeshPolicy, MAX_MAGI_PANEL_MEMBERS, MAGI_KIND_PANEL_KINDS, MAX_MAGI_KIND_SLOTS;
3400
+ var import_fs3, import_path3, import_crypto3, mergeMeshPolicy, MAGI_KIND_PANEL_KINDS, MAX_MAGI_KIND_SLOTS;
3501
3401
  var init_mesh_config = __esm({
3502
3402
  "src/config/mesh-config.ts"() {
3503
3403
  "use strict";
@@ -3509,7 +3409,6 @@ var init_mesh_config = __esm({
3509
3409
  init_repo_mesh_types();
3510
3410
  init_mesh_host_ownership();
3511
3411
  mergeMeshPolicy = mergeAndNormalizePolicy;
3512
- MAX_MAGI_PANEL_MEMBERS = 24;
3513
3412
  MAGI_KIND_PANEL_KINDS = ["claim_audit", "rca", "design", "freeform"];
3514
3413
  MAX_MAGI_KIND_SLOTS = 24;
3515
3414
  }
@@ -3880,9 +3779,7 @@ var init_coordinator_prompt = __esm({
3880
3779
  | \`mesh_write_mesh_json_config\` | Gated write of \`.adhdev/mesh.json\` (repo coordinator-prompt config) from the mesh entry \u2014 dry-run/overwrite like mesh_init |
3881
3780
  | \`mesh_magi_review\` | Cross-verify a read-only investigation across a standing panel of independent mesh agents (different machines/providers) instead of a single worker |
3882
3781
  | \`mesh_magi_collect\` | Collect + synthesize a previously dispatched MAGI fan-out by its consensus group id (async companion to mesh_magi_review wait:false) |
3883
- | \`mesh_magi_panel_set\` | Upsert a named MAGI panel (standing set of independent node\xD7provider members) into machine-local config |
3884
- | \`mesh_magi_panel_list\` | List configured MAGI panels and resolve each member's availability against the current mesh (read-only) |
3885
- | \`mesh_magi_kind_panel_set\` | Bind a task_kind \u2192 MAGI kind-panel slots (machine-local, wholesale replacement \u2014 approve current-vs-new first) |
3782
+ | \`mesh_magi_kind_panel_set\` | Bind a task_kind \u2192 MAGI kind-panel slots (the SOLE MAGI panel-resolution surface; machine-local, wholesale replacement \u2014 approve current-vs-new first) |
3886
3783
  | \`mesh_magi_kind_panel_list\` | List configured task_kind \u2192 MAGI kind-panel slot bindings (machine-local, read-only) |`;
3887
3784
  TOOL_EXPOSURE_PREFLIGHT_SECTION = `## Tool Exposure Preflight
3888
3785
 
@@ -3922,7 +3819,7 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
3922
3819
 
3923
3820
  **Save scopes \u2014 label every draft with its scope before asking for approval:**
3924
3821
  - **repo-file (commit target)** \u2014 \`.adhdev/refine.json\`, \`.adhdev/worktree_bootstrap.json\`, \`.adhdev/change-impact.json\`, \`.adhdev/mesh.json\`. These are committed to the repository and shared with every machine/contributor.
3925
- - **machine-local** \u2014 MAGI kind\u2192panel bindings and named MAGI panels, node providerPriority (\`~/.adhdev/meshes.json\`). These stay on this machine and are NOT committed.
3822
+ - **machine-local** \u2014 MAGI kind\u2192panel bindings, node providerPriority (\`~/.adhdev/meshes.json\`). These stay on this machine and are NOT committed.
3926
3823
 
3927
3824
  **Guided sequence:**
3928
3825
  1. **Scan (dry-run)** \u2014 Call \`mesh_init\` (write=false, the default). It returns per-domain suggested configs for refine / worktree_bootstrap / change-impact, a recommended providerPriority, AND \`currentConfig\` \u2014 the currently-saved config per domain (repo files + machine-local \`magiKindPanels\`). Nothing is written.
@@ -3930,8 +3827,7 @@ When the user asks to **set up / configure / onboard** this repo for Repo Mesh (
3930
3827
  3. **Approve \u2192 gated write** \u2014 Only after the user approves, call the matching gated-write tool:
3931
3828
  - repo \`.adhdev/*\` config files \u2192 \`mesh_init\` with \`write=true\` (and \`overwrite=true\` ONLY for domains the user approved replacing).
3932
3829
  - \`.adhdev/mesh.json\` (coordinator prompt / operating notes) \u2192 \`mesh_write_mesh_json_config\` (write=true, overwrite only if approved).
3933
- - machine-local MAGI kind\u2192panel slots \u2192 \`mesh_magi_kind_panel_set\` (write=true). NOTE: a kind binding is a **wholesale replacement** of that kind's slot list \u2014 present the current-vs-new slots first.
3934
- - machine-local named MAGI panels \u2192 \`mesh_magi_panel_set\`. providerPriority \u2192 apply via node policy update.
3830
+ - machine-local MAGI kind\u2192panel slots \u2192 \`mesh_magi_kind_panel_set\` (write=true). NOTE: a kind binding is a **wholesale replacement** of that kind's slot list \u2014 present the current-vs-new slots first. providerPriority \u2192 apply via node policy update.
3935
3831
 
3936
3832
  **init vs reinit:**
3937
3833
  - **\`mesh_init\`** \u2014 for a fresh, never-onboarded repo. Existing config files are kept (existing-wins) unless the user explicitly approves overwrite. Use for first-time setup.
@@ -4346,8 +4242,7 @@ function shouldDeliverPendingEventToCoordinator(event, drainer) {
4346
4242
  return coordinatorIdentityEquals(event.intendedFor, drainer);
4347
4243
  }
4348
4244
  function defaultScopeForEvent(eventName) {
4349
- if (SYSTEM_EVENTS.has(eventName)) return "system";
4350
- if (TERMINAL_TASK_EVENTS.has(eventName)) return "unicast";
4245
+ if (TERMINAL_TASK_EVENTS.has(eventName) || COORDINATOR_ALERT_EVENTS.has(eventName)) return "unicast";
4351
4246
  return "broadcast";
4352
4247
  }
4353
4248
  function coordinatorIdentityFromEmitFields(fields) {
@@ -4373,7 +4268,7 @@ function buildPendingEventEmitStamp(opts) {
4373
4268
  ...intendedFor ? { intendedFor } : {}
4374
4269
  };
4375
4270
  }
4376
- var MESH_PROTOCOL_VERSION_V1, MESH_PROTOCOL_VERSION_V2, SUPPORTED_MESH_PROTOCOL_VERSIONS, MESH_EVENT_SCOPES, MeshContractViolationError, TERMINAL_TASK_EVENTS, SYSTEM_EVENTS;
4271
+ var MESH_PROTOCOL_VERSION_V1, MESH_PROTOCOL_VERSION_V2, SUPPORTED_MESH_PROTOCOL_VERSIONS, MESH_EVENT_SCOPES, MeshContractViolationError, TERMINAL_TASK_EVENTS, COORDINATOR_ALERT_EVENTS;
4377
4272
  var init_contracts = __esm({
4378
4273
  "src/mesh/contracts.ts"() {
4379
4274
  "use strict";
@@ -4402,7 +4297,7 @@ var init_contracts = __esm({
4402
4297
  "refine:failed",
4403
4298
  "refine:accepted"
4404
4299
  ]);
4405
- SYSTEM_EVENTS = /* @__PURE__ */ new Set([
4300
+ COORDINATOR_ALERT_EVENTS = /* @__PURE__ */ new Set([
4406
4301
  "mesh:dispatch_blocked"
4407
4302
  ]);
4408
4303
  }
@@ -6354,7 +6249,22 @@ function meshRuntimeStorePath() {
6354
6249
  }
6355
6250
  return nextPath;
6356
6251
  }
6357
- var import_fs5, import_path5, DatabaseCtor, loggedMigrationFailure, loggedStrayCleanup, MeshRuntimeStore;
6252
+ function pruneMeshRuntimeRetention() {
6253
+ try {
6254
+ const store = MeshRuntimeStore.getInstance();
6255
+ const ledger = store.pruneEventLedger(MESH_EVENT_LEDGER_RETENTION_MS);
6256
+ const toolCalls = store.pruneToolCallLog(MESH_TOOL_CALL_LOG_RETENTION_MS);
6257
+ const terminalQueue = store.pruneTerminalQueueEntries(MESH_TERMINAL_QUEUE_RETENTION_MS);
6258
+ if (ledger + toolCalls + terminalQueue > 0) {
6259
+ LOG.info("MeshRuntimeStore", `Retention prune removed ${ledger} ledger / ${toolCalls} tool-call / ${terminalQueue} terminal-queue row(s)`);
6260
+ }
6261
+ return { ledger, toolCalls, terminalQueue };
6262
+ } catch (e) {
6263
+ LOG.warn("MeshRuntimeStore", `Runtime retention prune failed: ${e?.message || e}`);
6264
+ return { ledger: 0, toolCalls: 0, terminalQueue: 0 };
6265
+ }
6266
+ }
6267
+ var import_fs5, import_path5, DatabaseCtor, loggedMigrationFailure, loggedStrayCleanup, MeshRuntimeStore, MESH_EVENT_LEDGER_RETENTION_MS, MESH_TOOL_CALL_LOG_RETENTION_MS, MESH_TERMINAL_QUEUE_RETENTION_MS;
6358
6268
  var init_mesh_runtime_store = __esm({
6359
6269
  "src/mesh/mesh-runtime-store.ts"() {
6360
6270
  "use strict";
@@ -7466,10 +7376,79 @@ var init_mesh_runtime_store = __esm({
7466
7376
  }
7467
7377
  /**
7468
7378
  * Prune tool call log entries older than the given age in ms.
7469
- * Exposed for testing.
7379
+ * Returns the number of rows deleted. Also used by the periodic retention
7380
+ * sweep (pruneMeshRuntimeRetention) — the in-write sweep in recordMeshToolCall
7381
+ * only fires every 200 calls and only covers the rate-limit window, so a
7382
+ * quiet mesh otherwise accumulates rows indefinitely.
7470
7383
  */
7471
7384
  pruneToolCallLog(olderThanMs) {
7472
- this.db.prepare("DELETE FROM mesh_tool_call_log WHERE called_at < ?").run(Date.now() - olderThanMs);
7385
+ return this.db.prepare("DELETE FROM mesh_tool_call_log WHERE called_at < ?").run(Date.now() - olderThanMs).changes;
7386
+ }
7387
+ /**
7388
+ * Retention prune for mesh_event_ledger (SoT 1-11 (b)). The ledger is append-only
7389
+ * with NO lifecycle GC of its own, so lifecycle events accumulate without bound
7390
+ * (the dominant mesh-runtime.db growth). Every production reader is bounded to a
7391
+ * recent window (readLedgerEntries tail/limit ≤ a few hundred; task-stats /
7392
+ * terminal-evidence scans look at recent tasks), so rows past a generous age only
7393
+ * cost space. Excluded from deletion — retained forever:
7394
+ * - coordinator_operating_note / _tombstone: runtime-accumulated lessons whose
7395
+ * whole point is surviving restarts; a tombstone must also outlive the notes
7396
+ * it retracts.
7397
+ * Timestamps are ISO-8601 TEXT, so the lexicographic `<` cutoff is a correct time
7398
+ * comparison; a malformed timestamp compares greater than any ISO date and is
7399
+ * conservatively retained. Returns rows deleted.
7400
+ */
7401
+ pruneEventLedger(olderThanMs) {
7402
+ const cutoffIso = new Date(Date.now() - Math.max(0, olderThanMs)).toISOString();
7403
+ return this.db.prepare(
7404
+ `DELETE FROM mesh_event_ledger
7405
+ WHERE timestamp < ?
7406
+ AND kind NOT IN ('coordinator_operating_note', 'coordinator_operating_note_tombstone')`
7407
+ ).run(cutoffIso).changes;
7408
+ }
7409
+ /**
7410
+ * Retention prune for TERMINAL (completed/cancelled/failed) mesh_queue rows
7411
+ * (SoT 1-11 (b)). Terminal rows are kept as recent history (mesh_task_history,
7412
+ * completion-dedup taskId lookups) but nothing ever deletes them, so the queue
7413
+ * table grows monotonically. Rows past the retention window serve no reader —
7414
+ * every dedup/attribution path operates on recent tasks — EXCEPT as a dependency
7415
+ * anchor: taskDependenciesSatisfied resolves dependsOn by id and treats a MISSING
7416
+ * row as not-completed, so deleting a completed row that a still-live
7417
+ * (pending/assigned) row depends on would permanently strand the dependent.
7418
+ * Those ids are collected first and excluded. Returns rows deleted.
7419
+ */
7420
+ pruneTerminalQueueEntries(olderThanMs) {
7421
+ const cutoffIso = new Date(Date.now() - Math.max(0, olderThanMs)).toISOString();
7422
+ return this.transaction(() => {
7423
+ const liveRows = this.db.prepare(
7424
+ `SELECT payload FROM mesh_queue WHERE status IN ('pending', 'assigned')`
7425
+ ).all();
7426
+ const protectedIds = /* @__PURE__ */ new Set();
7427
+ for (const row of liveRows) {
7428
+ try {
7429
+ const entry = JSON.parse(row.payload);
7430
+ if (Array.isArray(entry.dependsOn)) {
7431
+ for (const dep of entry.dependsOn) {
7432
+ if (typeof dep === "string" && dep) protectedIds.add(dep);
7433
+ }
7434
+ }
7435
+ } catch {
7436
+ }
7437
+ }
7438
+ const candidates = this.db.prepare(
7439
+ `SELECT id FROM mesh_queue
7440
+ WHERE status IN ('completed', 'cancelled', 'failed') AND updated_at < ?`
7441
+ ).all(cutoffIso);
7442
+ const deletable = candidates.map((r) => r.id).filter((id) => !protectedIds.has(id));
7443
+ let removed = 0;
7444
+ for (let i = 0; i < deletable.length; i += 500) {
7445
+ const chunk = deletable.slice(i, i + 500);
7446
+ removed += this.db.prepare(
7447
+ `DELETE FROM mesh_queue WHERE id IN (${chunk.map(() => "?").join(",")})`
7448
+ ).run(...chunk).changes;
7449
+ }
7450
+ return removed;
7451
+ });
7473
7452
  }
7474
7453
  // ── G2: Event Ledger ────────────────────────────────────────────────────
7475
7454
  appendLedgerEntry(entry) {
@@ -7955,6 +7934,9 @@ var init_mesh_runtime_store = __esm({
7955
7934
  return removed;
7956
7935
  }
7957
7936
  };
7937
+ MESH_EVENT_LEDGER_RETENTION_MS = 30 * 24 * 60 * 60 * 1e3;
7938
+ MESH_TOOL_CALL_LOG_RETENTION_MS = 14 * 24 * 60 * 60 * 1e3;
7939
+ MESH_TERMINAL_QUEUE_RETENTION_MS = 30 * 24 * 60 * 60 * 1e3;
7958
7940
  }
7959
7941
  });
7960
7942
 
@@ -16567,6 +16549,15 @@ function getStore() {
16567
16549
  return void 0;
16568
16550
  }
16569
16551
  }
16552
+ function registerUnresolvedForwardRetryNudge(handler) {
16553
+ retryNudgeHandler = handler;
16554
+ }
16555
+ function nudgeUnresolvedForwardRetry() {
16556
+ try {
16557
+ retryNudgeHandler?.();
16558
+ } catch {
16559
+ }
16560
+ }
16570
16561
  function enqueueUnresolvedDelegateForward(coordinatorDaemonId, eventName, forwardPayload) {
16571
16562
  const target = readNonEmptyString2(coordinatorDaemonId);
16572
16563
  const event = readNonEmptyString2(eventName);
@@ -16650,7 +16641,7 @@ function expireStaleUnresolvedDelegateForwards(nowMs = Date.now()) {
16650
16641
  return 0;
16651
16642
  }
16652
16643
  }
16653
- var import_crypto9, UNRESOLVED_FORWARD_OUTBOX_MESH_ID, UNRESOLVED_FORWARD_MAX_AGE_MS;
16644
+ var import_crypto9, UNRESOLVED_FORWARD_OUTBOX_MESH_ID, UNRESOLVED_FORWARD_MAX_AGE_MS, retryNudgeHandler;
16654
16645
  var init_mesh_unresolved_forward_outbox = __esm({
16655
16646
  "src/mesh/mesh-unresolved-forward-outbox.ts"() {
16656
16647
  "use strict";
@@ -19042,6 +19033,7 @@ function sweepExpiredRemoteIdleSessions() {
19042
19033
  if (now - lastPendingEventsPruneAt >= PENDING_EVENTS_PRUNE_INTERVAL_MS) {
19043
19034
  lastPendingEventsPruneAt = now;
19044
19035
  prunePendingMeshCoordinatorEventsRetention();
19036
+ pruneMeshRuntimeRetention();
19045
19037
  }
19046
19038
  }
19047
19039
  function isIntentionalCleanupStopMetadata(event) {
@@ -19898,25 +19890,6 @@ function handleMeshForwardEvent(components, payload) {
19898
19890
  v2Envelope: readV2EnvelopeFromWire(payload)
19899
19891
  });
19900
19892
  }
19901
- function enqueueCoordinatorForwardPush(coordinatorDaemonId, run) {
19902
- let lane = coordinatorForwardLanes.get(coordinatorDaemonId);
19903
- if (!lane) {
19904
- lane = { tail: Promise.resolve(), depth: 0 };
19905
- coordinatorForwardLanes.set(coordinatorDaemonId, lane);
19906
- }
19907
- const wasIdle = lane.depth === 0;
19908
- lane.depth += 1;
19909
- const dec = () => {
19910
- lane.depth -= 1;
19911
- };
19912
- if (wasIdle) {
19913
- lane.tail = Promise.resolve(run()).catch(() => {
19914
- }).then(dec, dec);
19915
- } else {
19916
- lane.tail = lane.tail.then(() => run()).catch(() => {
19917
- }).then(dec, dec);
19918
- }
19919
- }
19920
19893
  function forwardUnresolvedDelegateEvent(components, routing, event) {
19921
19894
  const coordinatorDaemonId = readNonEmptyString2(routing.coordinatorDaemonId);
19922
19895
  if (!coordinatorDaemonId) return false;
@@ -19953,28 +19926,15 @@ function forwardUnresolvedDelegateEvent(components, routing, event) {
19953
19926
  nodeId: readNonEmptyString2(routing.nodeId) || readNonEmptyString2(event.meshNodeId),
19954
19927
  event: eventName
19955
19928
  };
19956
- traceMeshEventStage("outbox_enqueue", fwdTraceCtx, `coordinatorDaemon=${coordinatorDaemonId} meshId=absent`);
19957
- traceMeshEventStage("forward_send", fwdTraceCtx, "immediate push");
19958
- const dispatchMeshCommand = components.dispatchMeshCommand;
19959
- enqueueCoordinatorForwardPush(coordinatorDaemonId, () => Promise.resolve(dispatchMeshCommand(coordinatorDaemonId, "mesh_forward_event", payload)).then((result) => {
19960
- if (result && result.success === false) {
19961
- LOG.warn("MeshEvents", `Immediate forward of ${eventName} to coordinator ${coordinatorDaemonId} rejected (${readNonEmptyString2(result.error) || "no reason"}) \u2014 left queued for retry`);
19962
- traceMeshEventDrop("immediate_forward_rejected", fwdTraceCtx, readNonEmptyString2(result.error) || "no reason");
19963
- return;
19964
- }
19965
- if (persisted) ackUnresolvedDelegateForwardByFingerprint(coordinatorDaemonId, eventName, payload);
19966
- }).catch((e) => {
19967
- LOG.warn("MeshEvents", `Immediate forward of ${eventName} to coordinator ${coordinatorDaemonId} failed: ${e?.message || e} \u2014 left queued for retry`);
19968
- }));
19969
- LOG.info("MeshEvents", `Durably forwarded ${eventName} for unresolved-mesh worker at ${routing.workspace || "(no workspace)"} to coordinator daemon ${coordinatorDaemonId}`);
19929
+ if (!persisted) {
19930
+ traceMeshEventDrop("outbox_enqueue_failed", fwdTraceCtx, `coordinatorDaemon=${coordinatorDaemonId}`);
19931
+ return false;
19932
+ }
19933
+ traceMeshEventStage("outbox_enqueue", fwdTraceCtx, `coordinatorDaemon=${coordinatorDaemonId} meshId=${readNonEmptyString2(payload.meshId) || "absent"}`);
19934
+ nudgeUnresolvedForwardRetry();
19935
+ LOG.info("MeshEvents", `Durably queued ${eventName} for unresolved-mesh worker at ${routing.workspace || "(no workspace)"} to coordinator daemon ${coordinatorDaemonId} (reconcile PHASE 0 delivers)`);
19970
19936
  return true;
19971
19937
  }
19972
- function ackUnresolvedDelegateForwardByFingerprint(coordinatorDaemonId, eventName, payload) {
19973
- const match = peekUnresolvedDelegateForwards().find(
19974
- (entry) => daemonIdsEquivalent(entry.coordinatorDaemonId, coordinatorDaemonId) && readNonEmptyString2(entry.payload.event) === eventName && readNonEmptyString2(entry.payload.targetSessionId || entry.payload.sessionId || entry.payload.instanceId) === readNonEmptyString2(payload.targetSessionId || payload.sessionId || payload.instanceId) && readNonEmptyString2(entry.payload.workspace) === readNonEmptyString2(payload.workspace)
19975
- );
19976
- if (match) ackUnresolvedDelegateForward(match.id);
19977
- }
19978
19938
  function flushPendingForMeshIdleCoordinators(components, meshId) {
19979
19939
  try {
19980
19940
  const store = MeshRuntimeStore.getInstance();
@@ -20107,7 +20067,7 @@ function setupMeshEventForwarding(components) {
20107
20067
  flushPendingForMeshIdleCoordinators(components, routing.meshId);
20108
20068
  });
20109
20069
  }
20110
- var REMOTE_IDLE_SESSION_TTL_MS, meshByWorkspaceCache, MESH_WORKSPACE_CACHE_TTL_MS, lastPendingEventsPruneAt, PENDING_EVENTS_PRUNE_INTERVAL_MS, INTENTIONAL_CLEANUP_STOP_SUPPRESSION_MS, RECENT_COMPLETION_FINGERPRINT_TTL_MS, RECONCILED_COMPLETION_SOURCES, coordinatorForwardLanes;
20070
+ var REMOTE_IDLE_SESSION_TTL_MS, meshByWorkspaceCache, MESH_WORKSPACE_CACHE_TTL_MS, lastPendingEventsPruneAt, PENDING_EVENTS_PRUNE_INTERVAL_MS, INTENTIONAL_CLEANUP_STOP_SUPPRESSION_MS, RECENT_COMPLETION_FINGERPRINT_TTL_MS, RECONCILED_COMPLETION_SOURCES;
20111
20071
  var init_mesh_event_forwarding = __esm({
20112
20072
  "src/mesh/mesh-event-forwarding.ts"() {
20113
20073
  "use strict";
@@ -20144,7 +20104,6 @@ var init_mesh_event_forwarding = __esm({
20144
20104
  "mcp_mesh_status_transcript_reconciliation",
20145
20105
  "no_progress_reconciliation"
20146
20106
  ]);
20147
- coordinatorForwardLanes = /* @__PURE__ */ new Map();
20148
20107
  }
20149
20108
  });
20150
20109
 
@@ -21123,6 +21082,65 @@ function recoverStrandedAssignedDispatches(components, meshId, store) {
21123
21082
  }
21124
21083
  }
21125
21084
  }
21085
+ function reconcileZombieAssignedTasks(components, mesh, selfIds) {
21086
+ const meshId = mesh.id;
21087
+ const assigned = getQueue(meshId, { status: ["assigned"] });
21088
+ if (!assigned.length) return;
21089
+ const nowMs = Date.now();
21090
+ const assignedNodeIsLocal = (assignedNodeId) => {
21091
+ if (!assignedNodeId) return true;
21092
+ if (selfIds.some((id) => daemonIdsEquivalent(id, assignedNodeId))) return true;
21093
+ const nodes = Array.isArray(mesh.nodes) ? mesh.nodes : [];
21094
+ const node = nodes.find((n) => meshNodeIdMatches(n, assignedNodeId));
21095
+ const nodeDaemonId = readNonEmptyString2(node?.daemonId);
21096
+ return !!nodeDaemonId && selfIds.some((id) => daemonIdsEquivalent(id, nodeDaemonId));
21097
+ };
21098
+ for (const row of assigned) {
21099
+ if (Number.isFinite(Date.parse(row.dispatchTimestamp ?? ""))) continue;
21100
+ const updatedMs = Date.parse(row.updatedAt ?? "");
21101
+ const createdMs = Date.parse(row.createdAt ?? "");
21102
+ const anchorMs = Number.isFinite(updatedMs) ? updatedMs : createdMs;
21103
+ if (!Number.isFinite(anchorMs)) continue;
21104
+ if (nowMs - anchorMs < ZOMBIE_ASSIGNED_MIN_AGE_MS) continue;
21105
+ const terminal = findTerminalLedgerEvidenceForTask({ meshId, taskId: row.id });
21106
+ if (terminal) {
21107
+ const status = terminal.kind === "task_completed" ? "completed" : "failed";
21108
+ updateTaskStatus(meshId, row.id, status);
21109
+ LOG.warn("MeshReconcile", `Zombie assigned task ${row.id} on mesh ${meshId} had ${terminal.kind} ledger evidence \u2014 flipped to ${status}`);
21110
+ continue;
21111
+ }
21112
+ if (!assignedNodeIsLocal(row.assignedNodeId)) continue;
21113
+ if (row.assignedSessionId) {
21114
+ const verdict = resolveSessionBusyVerdict(components, row.assignedSessionId);
21115
+ if (verdict !== "UNKNOWN") continue;
21116
+ }
21117
+ const reason = row.assignedSessionId ? "assigned_zombie_session_missing" : "assigned_zombie_no_session_bound";
21118
+ const failed = updateTaskStatus(meshId, row.id, "failed");
21119
+ if (!failed) continue;
21120
+ try {
21121
+ appendLedgerEntry(meshId, {
21122
+ kind: "task_failed",
21123
+ nodeId: row.assignedNodeId,
21124
+ sessionId: row.assignedSessionId,
21125
+ payload: {
21126
+ taskId: row.id,
21127
+ reason,
21128
+ source: "reconcile_zombie_assigned_sweep",
21129
+ ageMs: nowMs - anchorMs
21130
+ }
21131
+ });
21132
+ } catch {
21133
+ }
21134
+ LOG.warn("MeshReconcile", `Failed zombie assigned task ${row.id} on mesh ${meshId} (node=${row.assignedNodeId ?? "?"} session=${row.assignedSessionId ?? "?"}, no dispatchTimestamp, stale ${Math.round((nowMs - anchorMs) / 6e4)}m, ${reason})`);
21135
+ traceMeshEventDrop("assigned_zombie_failed", {
21136
+ taskId: row.id,
21137
+ sessionId: row.assignedSessionId,
21138
+ nodeId: row.assignedNodeId,
21139
+ meshId,
21140
+ event: "agent:generating_completed"
21141
+ }, `${reason} stale=${Math.round((nowMs - anchorMs) / 6e4)}m`);
21142
+ }
21143
+ }
21126
21144
  async function runMeshReconcileTick(components) {
21127
21145
  const localDaemonId = readNonEmptyString2(loadConfig().machineId) || void 0;
21128
21146
  const drainDaemonIds = resolveCoordinatorDaemonIds(components);
@@ -21161,6 +21179,11 @@ async function runMeshReconcileTick(components) {
21161
21179
  } catch (e) {
21162
21180
  LOG.warn("MeshReconcile", `Assigned-stranded watchdog failed for mesh ${mesh.id}: ${e?.message || e}`);
21163
21181
  }
21182
+ try {
21183
+ reconcileZombieAssignedTasks(components, mesh, selfIds);
21184
+ } catch (e) {
21185
+ LOG.warn("MeshReconcile", `Assigned-zombie sweep failed for mesh ${mesh.id}: ${e?.message || e}`);
21186
+ }
21164
21187
  }
21165
21188
  }
21166
21189
  for (const mesh of listMeshes()) {
@@ -21382,6 +21405,25 @@ function holdOrExpireStrictUnmatchedEvent(pending, wantSession, meshId) {
21382
21405
  LOG.warn("MeshReconcile", `Failed to ledger-expire strict-unmatched ${pending.event} for mesh ${meshId}: ${e?.message || e}`);
21383
21406
  }
21384
21407
  }
21408
+ function scheduleUnresolvedForwardNudge(components) {
21409
+ if (!components.dispatchMeshCommand) return;
21410
+ if (unresolvedForwardNudgeTimer) return;
21411
+ unresolvedForwardNudgeTimer = setTimeout(() => {
21412
+ unresolvedForwardNudgeTimer = void 0;
21413
+ if (unresolvedForwardNudgeRunning) return;
21414
+ unresolvedForwardNudgeRunning = true;
21415
+ void retryUnresolvedDelegateForwards(components).catch((e) => LOG.warn("MeshReconcile", `Nudged unresolved-forward retry failed: ${e?.message || e}`)).finally(() => {
21416
+ unresolvedForwardNudgeRunning = false;
21417
+ });
21418
+ }, UNRESOLVED_FORWARD_NUDGE_DELAY_MS);
21419
+ if (typeof unresolvedForwardNudgeTimer.unref === "function") unresolvedForwardNudgeTimer.unref();
21420
+ }
21421
+ function clearUnresolvedForwardNudge() {
21422
+ if (unresolvedForwardNudgeTimer) {
21423
+ clearTimeout(unresolvedForwardNudgeTimer);
21424
+ unresolvedForwardNudgeTimer = void 0;
21425
+ }
21426
+ }
21385
21427
  async function retryUnresolvedDelegateForwards(components) {
21386
21428
  const dispatchMeshCommand = components.dispatchMeshCommand;
21387
21429
  if (!dispatchMeshCommand) return;
@@ -21466,15 +21508,18 @@ function setupMeshReconcileLoop(components) {
21466
21508
  });
21467
21509
  }, intervalMs);
21468
21510
  if (typeof timer.unref === "function") timer.unref();
21511
+ registerUnresolvedForwardRetryNudge(() => scheduleUnresolvedForwardNudge(components));
21469
21512
  LOG.info("MeshReconcile", `Mesh reconcile loop started (interval ${intervalMs}ms)`);
21470
21513
  return {
21471
21514
  stop() {
21472
21515
  clearInterval(timer);
21516
+ registerUnresolvedForwardRetryNudge(void 0);
21517
+ clearUnresolvedForwardNudge();
21473
21518
  LOG.info("MeshReconcile", "Mesh reconcile loop stopped");
21474
21519
  }
21475
21520
  };
21476
21521
  }
21477
- var 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;
21522
+ var coordinatorModalParkState, heldEventLedgerRecorded, ASSIGNED_STRANDED_DEADLINE_MS, DELIVERED_NO_TURN_DEADLINE_MS, RECLAIM_UNKNOWN_GRACE_TICKS, deliveredNoTurnUnknownStreak, ZOMBIE_ASSIGNED_MIN_AGE_MS, STRICT_SESSION_MATCH_TTL_MS, unresolvedForwardRejectionCounts, MAX_FORWARD_REJECTIONS, UNRESOLVED_FORWARD_NUDGE_DELAY_MS, unresolvedForwardNudgeTimer, unresolvedForwardNudgeRunning;
21478
21523
  var init_mesh_reconcile_loop = __esm({
21479
21524
  "src/mesh/mesh-reconcile-loop.ts"() {
21480
21525
  "use strict";
@@ -21506,9 +21551,12 @@ var init_mesh_reconcile_loop = __esm({
21506
21551
  DELIVERED_NO_TURN_DEADLINE_MS = 15 * 6e4;
21507
21552
  RECLAIM_UNKNOWN_GRACE_TICKS = 3;
21508
21553
  deliveredNoTurnUnknownStreak = /* @__PURE__ */ new Map();
21554
+ ZOMBIE_ASSIGNED_MIN_AGE_MS = 30 * 60 * 1e3;
21509
21555
  STRICT_SESSION_MATCH_TTL_MS = 6e4;
21510
21556
  unresolvedForwardRejectionCounts = /* @__PURE__ */ new Map();
21511
21557
  MAX_FORWARD_REJECTIONS = 5;
21558
+ UNRESOLVED_FORWARD_NUDGE_DELAY_MS = 250;
21559
+ unresolvedForwardNudgeRunning = false;
21512
21560
  }
21513
21561
  });
21514
21562
 
@@ -27404,7 +27452,6 @@ __export(index_exports, {
27404
27452
  getLedgerSummary: () => getLedgerSummary,
27405
27453
  getLogLevel: () => getLogLevel,
27406
27454
  getMagiKindPanel: () => getMagiKindPanel,
27407
- getMagiPanel: () => getMagiPanel,
27408
27455
  getMesh: () => getMesh,
27409
27456
  getMeshByRepo: () => getMeshByRepo,
27410
27457
  getMeshMagiActivityByGroup: () => getMeshMagiActivityByGroup,
@@ -27462,7 +27509,6 @@ __export(index_exports, {
27462
27509
  listCoordinatorsForWorkspace: () => listCoordinatorsForWorkspace,
27463
27510
  listHostedCliRuntimes: () => listHostedCliRuntimes,
27464
27511
  listMagiKindPanels: () => listMagiKindPanels,
27465
- listMagiPanels: () => listMagiPanels,
27466
27512
  listMeshMissionSummaries: () => listMeshMissionSummaries,
27467
27513
  listMeshMissionsForTool: () => listMeshMissionsForTool,
27468
27514
  listMeshes: () => listMeshes,
@@ -27499,7 +27545,6 @@ __export(index_exports, {
27499
27545
  normalizeInputEnvelope: () => normalizeInputEnvelope,
27500
27546
  normalizeInteractivePrompt: () => normalizeInteractivePrompt,
27501
27547
  normalizeInteractivePromptResponse: () => normalizeInteractivePromptResponse,
27502
- normalizeMagiPanel: () => normalizeMagiPanel,
27503
27548
  normalizeMagiSlots: () => normalizeMagiSlots,
27504
27549
  normalizeManagedStatus: () => normalizeManagedStatus,
27505
27550
  normalizeMeshCapabilityTags: () => normalizeMeshCapabilityTags,
@@ -27542,7 +27587,6 @@ __export(index_exports, {
27542
27587
  registerExtensionProviders: () => registerExtensionProviders,
27543
27588
  registerMeshCoordinator: () => registerMeshCoordinator,
27544
27589
  removeMagiKindPanel: () => removeMagiKindPanel,
27545
- removeMagiPanel: () => removeMagiPanel,
27546
27590
  removeNode: () => removeNode,
27547
27591
  removeWorktree: () => removeWorktree,
27548
27592
  requeueHeldMeshCoordinatorEvents: () => requeueHeldMeshCoordinatorEvents,
@@ -27605,7 +27649,6 @@ __export(index_exports, {
27605
27649
  updateSessionDeliveryStatus: () => updateSessionDeliveryStatus,
27606
27650
  updateSessionTaskStatus: () => updateSessionTaskStatus,
27607
27651
  updateTaskStatus: () => updateTaskStatus,
27608
- upsertMagiPanel: () => upsertMagiPanel,
27609
27652
  upsertMeshMission: () => upsertMeshMission,
27610
27653
  upsertSavedProviderSession: () => upsertSavedProviderSession,
27611
27654
  validateChangeImpactConfig: () => validateChangeImpactConfig,
@@ -34619,6 +34662,16 @@ function isRuntimeFallbackHistorySessionId(candidateHistorySessionId, targetSess
34619
34662
  const candidate = typeof candidateHistorySessionId === "string" ? candidateHistorySessionId.trim() : "";
34620
34663
  return candidate === target;
34621
34664
  }
34665
+ function resolveNativeHistoryReadSession(args, candidateHistorySessionId) {
34666
+ const targetSid = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
34667
+ const explicitHistorySessionId = getExplicitHistorySessionId(args);
34668
+ const isRuntimeFallback = Boolean(
34669
+ targetSid && isRuntimeFallbackHistorySessionId(candidateHistorySessionId, targetSid) && (!explicitHistorySessionId || isRuntimeFallbackHistorySessionId(explicitHistorySessionId, targetSid))
34670
+ );
34671
+ const pinnedProviderSessionId = getBoundProviderSessionIdPin(args?.targetSessionId);
34672
+ const effectiveHistorySessionId = isRuntimeFallback ? pinnedProviderSessionId || void 0 : candidateHistorySessionId;
34673
+ return { isRuntimeFallback, pinnedProviderSessionId, effectiveHistorySessionId };
34674
+ }
34622
34675
  function getHistorySessionId(h, args) {
34623
34676
  const explicit = getExplicitHistorySessionId(args);
34624
34677
  if (explicit) return explicit;
@@ -35453,13 +35506,11 @@ async function handleChatHistory(h, args) {
35453
35506
  if (visibleCount > excludeRecentCount) excludeRecentCount = visibleCount;
35454
35507
  }
35455
35508
  const workspace = typeof args?.workspace === "string" ? args.workspace : typeof h.currentSession?.workspace === "string" ? h.currentSession.workspace : void 0;
35456
- const targetSidForHistory = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
35457
- const explicitHistorySessionIdForHistory = getExplicitHistorySessionId(args);
35458
- const historySessionIdIsRuntimeFallback = Boolean(
35459
- targetSidForHistory && isRuntimeFallbackHistorySessionId(historySessionId, targetSidForHistory) && (!explicitHistorySessionIdForHistory || isRuntimeFallbackHistorySessionId(explicitHistorySessionIdForHistory, targetSidForHistory))
35460
- );
35461
- const pinnedProviderSessionIdForHistory = getBoundProviderSessionIdPin(args?.targetSessionId);
35462
- const effectiveHistorySessionId = historySessionIdIsRuntimeFallback ? pinnedProviderSessionIdForHistory || void 0 : historySessionId;
35509
+ const {
35510
+ isRuntimeFallback: historySessionIdIsRuntimeFallback,
35511
+ pinnedProviderSessionId: pinnedProviderSessionIdForHistory,
35512
+ effectiveHistorySessionId
35513
+ } = resolveNativeHistoryReadSession(args, historySessionId);
35463
35514
  const exactNativeHistoryScope = Boolean(
35464
35515
  typeof args?.targetSessionId === "string" && args.targetSessionId.trim() || typeof args?.historySessionId === "string" && args.historySessionId.trim() && !historySessionIdIsRuntimeFallback || typeof args?.providerSessionId === "string" && args.providerSessionId.trim()
35465
35516
  );
@@ -35620,12 +35671,10 @@ async function handleReadChat(h, args) {
35620
35671
  let nativeHistory = null;
35621
35672
  let nativeHistoryError;
35622
35673
  if (supportsNative) {
35623
- const pinnedProviderSessionIdForRead = getBoundProviderSessionIdPin(targetSessionId);
35624
- const explicitHistorySessionIdForRead = getExplicitHistorySessionId(args);
35625
- const nativeReadSessionIdIsRuntimeFallback = Boolean(
35626
- targetSessionId && isRuntimeFallbackHistorySessionId(nativeHistoryReadSessionId, targetSessionId) && (!explicitHistorySessionIdForRead || isRuntimeFallbackHistorySessionId(explicitHistorySessionIdForRead, targetSessionId))
35627
- );
35628
- const effectiveNativeReadSessionId = nativeReadSessionIdIsRuntimeFallback ? pinnedProviderSessionIdForRead || void 0 : nativeHistoryReadSessionId;
35674
+ const {
35675
+ pinnedProviderSessionId: pinnedProviderSessionIdForRead,
35676
+ effectiveHistorySessionId: effectiveNativeReadSessionId
35677
+ } = resolveNativeHistoryReadSession(args, nativeHistoryReadSessionId);
35629
35678
  try {
35630
35679
  nativeHistory = readCliProviderNativeHistory(agentStr, {
35631
35680
  canonicalHistory: provider?.nativeHistory,
@@ -35902,12 +35951,11 @@ async function handleReadChat(h, args) {
35902
35951
  const workspace = targetSid ? typeof registrySessionWorkspace === "string" ? registrySessionWorkspace : argsWorkspace ?? currentSessionWorkspace : typeof currentSessionWorkspace === "string" ? currentSessionWorkspace : void 0;
35903
35952
  const intendedWorkspace = argsWorkspace;
35904
35953
  const supportsNative = supportsCliNativeTranscript(agentStr, provider) && isNativeSourceCanonicalHistory(provider?.nativeHistory);
35905
- const pinnedProviderSessionIdForHistory = getBoundProviderSessionIdPin(targetSid);
35906
- const explicitHistorySessionId = getExplicitHistorySessionId(args);
35907
- const historySessionIdIsRuntimeFallback = Boolean(
35908
- targetSid && isRuntimeFallbackHistorySessionId(historySessionId, targetSid) && (!explicitHistorySessionId || isRuntimeFallbackHistorySessionId(explicitHistorySessionId, targetSid))
35909
- );
35910
- const effectiveHistorySessionIdForRead = historySessionIdIsRuntimeFallback ? pinnedProviderSessionIdForHistory || void 0 : historySessionId;
35954
+ const {
35955
+ isRuntimeFallback: historySessionIdIsRuntimeFallback,
35956
+ pinnedProviderSessionId: pinnedProviderSessionIdForHistory,
35957
+ effectiveHistorySessionId: effectiveHistorySessionIdForRead
35958
+ } = resolveNativeHistoryReadSession(args, historySessionId);
35911
35959
  const history = supportsNative ? readCliProviderNativeHistory(agentStr, {
35912
35960
  canonicalHistory: provider?.nativeHistory,
35913
35961
  historySessionId: effectiveHistorySessionIdForRead,
@@ -54707,61 +54755,15 @@ var meshCrudHandlers = {
54707
54755
  return { success: false, error: e.message };
54708
54756
  }
54709
54757
  },
54710
- // ─── MAGI panels (machine-local config, sibling to meshes) ───────────────
54711
- // Panels live in ~/.adhdev/meshes.json `magiPanels` and are pure local config
54712
- // (no mesh ownership). These three handlers mirror list_meshes/create_mesh/
54713
- // update_mesh: dynamic-import the already-exported mesh-config accessors and
54714
- // surface normalizeMagiPanel's structured error codes (invalid_magi_panel,
54715
- // magi_panel_exists) verbatim so the dashboard can render them.
54716
- //
54717
- // Permission: magi_panel_set / magi_panel_remove are WRITE commands. They are
54718
- // intentionally NOT listed in canPeerUsePrivilegedShareCommand (daemon-cloud
54719
- // data-channel-router), so a peer holding ANY share permission hits its
54720
- // `default → false` branch — identical owner-only gating to create_mesh /
54721
- // update_mesh / list_meshes (none of which are listed there either). A trusted
54722
- // peer (no permission = the owner) passes the top `!permission → true` guard.
54723
- // Mirror, don't invent: do not add a new policy tier here.
54724
- //
54725
- // Resolvability (coupling / stale / available) is deliberately NOT computed
54726
- // here: buildMagiFanoutPlan lives in mcp-server, unreachable from daemon-core.
54727
- // magi_panel_list returns the raw definitions only; the dashboard derives
54728
- // member resolvability client-side (web-core MagiPanelManager, reusing the
54729
- // MagiGroupRow coupling logic) against live mesh_status.
54730
- magi_panel_list: async (_ctx, _args) => {
54731
- try {
54732
- const { listMagiPanels: listMagiPanels2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
54733
- return { success: true, panels: listMagiPanels2() };
54734
- } catch (e) {
54735
- return { success: false, error: e.message };
54736
- }
54737
- },
54738
- magi_panel_set: async (_ctx, args) => {
54739
- const name = typeof args?.name === "string" ? args.name.trim() : "";
54740
- if (!name) return { success: false, error: "invalid_magi_panel: panel name is required" };
54741
- try {
54742
- const { upsertMagiPanel: upsertMagiPanel2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
54743
- const panel = upsertMagiPanel2(name, args?.panel, { overwrite: args?.overwrite === true });
54744
- return { success: true, name, panel };
54745
- } catch (e) {
54746
- return { success: false, error: e.message };
54747
- }
54748
- },
54749
- magi_panel_remove: async (_ctx, args) => {
54750
- const name = typeof args?.name === "string" ? args.name.trim() : "";
54751
- if (!name) return { success: false, error: "invalid_magi_panel: panel name is required" };
54752
- try {
54753
- const { removeMagiPanel: removeMagiPanel2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
54754
- const removed = removeMagiPanel2(name);
54755
- return { success: true, removed };
54756
- } catch (e) {
54757
- return { success: false, error: e.message };
54758
- }
54759
- },
54760
54758
  // ─── MAGI kind → panel bindings (MAGI-KIND-PANEL, machine-local config) ───
54761
- // Per-task_kind slot lists in ~/.adhdev/meshes.json `magiKindPanels`. Same
54762
- // owner-only gating and structured-error precedent as the magi_panel_* handlers
54763
- // above (not listed in canPeerUsePrivilegedShareCommand owner-only). set/remove
54764
- // are WRITE commands; list is read-only. normalizeMagiSlots (inside setMagiKindPanel)
54759
+ // Per-task_kind slot lists in ~/.adhdev/meshes.json `magiKindPanels` — the SOLE
54760
+ // MAGI panel-resolution surface (the former named-panel magi_panel_* handlers were
54761
+ // removed). Owner-only gating: intentionally NOT listed in
54762
+ // canPeerUsePrivilegedShareCommand (daemon-cloud data-channel-router), so a peer
54763
+ // holding ANY share permission hits its `default → false` branch — identical
54764
+ // owner-only gating to create_mesh / update_mesh / list_meshes. A trusted peer (no
54765
+ // permission = the owner) passes the top `!permission → true` guard. set/remove are
54766
+ // WRITE commands; list is read-only. normalizeMagiSlots (inside setMagiKindPanel)
54765
54767
  // surfaces invalid_magi_kind_panel: … messages verbatim for the editor.
54766
54768
  magi_kind_panel_list: async (_ctx, _args) => {
54767
54769
  try {
@@ -69891,7 +69893,6 @@ var V1_CONTRACT_VERSION = "1.0.0";
69891
69893
  getLedgerSummary,
69892
69894
  getLogLevel,
69893
69895
  getMagiKindPanel,
69894
- getMagiPanel,
69895
69896
  getMesh,
69896
69897
  getMeshByRepo,
69897
69898
  getMeshMagiActivityByGroup,
@@ -69949,7 +69950,6 @@ var V1_CONTRACT_VERSION = "1.0.0";
69949
69950
  listCoordinatorsForWorkspace,
69950
69951
  listHostedCliRuntimes,
69951
69952
  listMagiKindPanels,
69952
- listMagiPanels,
69953
69953
  listMeshMissionSummaries,
69954
69954
  listMeshMissionsForTool,
69955
69955
  listMeshes,
@@ -69986,7 +69986,6 @@ var V1_CONTRACT_VERSION = "1.0.0";
69986
69986
  normalizeInputEnvelope,
69987
69987
  normalizeInteractivePrompt,
69988
69988
  normalizeInteractivePromptResponse,
69989
- normalizeMagiPanel,
69990
69989
  normalizeMagiSlots,
69991
69990
  normalizeManagedStatus,
69992
69991
  normalizeMeshCapabilityTags,
@@ -70029,7 +70028,6 @@ var V1_CONTRACT_VERSION = "1.0.0";
70029
70028
  registerExtensionProviders,
70030
70029
  registerMeshCoordinator,
70031
70030
  removeMagiKindPanel,
70032
- removeMagiPanel,
70033
70031
  removeNode,
70034
70032
  removeWorktree,
70035
70033
  requeueHeldMeshCoordinatorEvents,
@@ -70092,7 +70090,6 @@ var V1_CONTRACT_VERSION = "1.0.0";
70092
70090
  updateSessionDeliveryStatus,
70093
70091
  updateSessionTaskStatus,
70094
70092
  updateTaskStatus,
70095
- upsertMagiPanel,
70096
70093
  upsertMeshMission,
70097
70094
  upsertSavedProviderSession,
70098
70095
  validateChangeImpactConfig,