@adhdev/daemon-core 0.9.82-rc.448 → 0.9.82-rc.449

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -404,10 +404,10 @@ function readInjected(value) {
404
404
  }
405
405
  function getDaemonBuildInfo() {
406
406
  if (cached) return cached;
407
- const commit = readInjected(true ? "7636b9d4fc6c456ebfe178b9b0a7b81664b02257" : void 0) ?? "unknown";
408
- const commitShort = readInjected(true ? "7636b9d4" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
409
- const version = readInjected(true ? "0.9.82-rc.448" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
410
- const builtAt = readInjected(true ? "2026-07-02T00:30:54.215Z" : void 0);
407
+ const commit = readInjected(true ? "fe0e4d2aa03aea2793c2379e5ffc89abef5143d6" : void 0) ?? "unknown";
408
+ const commitShort = readInjected(true ? "fe0e4d2a" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
409
+ const version = readInjected(true ? "0.9.82-rc.449" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
410
+ const builtAt = readInjected(true ? "2026-07-03T01:58:07.610Z" : void 0);
411
411
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
412
412
  return cached;
413
413
  }
@@ -37593,6 +37593,16 @@ var TerminalAdapter = class {
37593
37593
  this.recordEvent("input", capPreview(escapeControl(text)), text.length);
37594
37594
  this.pty?.write(text);
37595
37595
  }
37596
+ /** Forward runtime metadata (meshNodeId, workspaceLabel, lifecycle, …) to
37597
+ * the underlying transport so it reaches the session registry. The spec
37598
+ * path previously dropped everything but providerSessionId here, which
37599
+ * left autoLaunch's meshNodeId stamp unbound on the record (see
37600
+ * SESSION-ACCUMULATION-LEAK). No-op when the transport does not support
37601
+ * metadata updates (e.g. plain node-pty). */
37602
+ updateMeta(meta, replace = false) {
37603
+ if (!this.pty || typeof this.pty.updateMeta !== "function") return;
37604
+ this.pty.updateMeta(meta, replace);
37605
+ }
37596
37606
  /** Debug-only: most-recent PTY input/output/resize/cursor events, oldest
37597
37607
  * first. Pure observation — never consulted by the FSM. */
37598
37608
  getEventTimeline(limit = MAX_PTY_EVENTS) {
@@ -37892,6 +37902,13 @@ var FsmDriver = class {
37892
37902
  return;
37893
37903
  }
37894
37904
  }
37905
+ /** Forward runtime metadata to the terminal transport so mesh binding
37906
+ * fields (meshNodeId / meshNodeFor / workspaceLabel / lifecycle) reach
37907
+ * the session registry. Not a DashboardCommand — this is a control-plane
37908
+ * update, not user input. */
37909
+ updateMeta(meta, replace = false) {
37910
+ this.adapter.updateMeta(meta, replace);
37911
+ }
37895
37912
  snapshot() {
37896
37913
  return this.adapter.snapshot();
37897
37914
  }
@@ -40096,9 +40113,14 @@ var SpecCliAdapter = class _SpecCliAdapter {
40096
40113
  };
40097
40114
  }
40098
40115
  updateRuntimeMeta(meta) {
40099
- if (meta && typeof meta.providerSessionId === "string") {
40116
+ if (!meta) return;
40117
+ if (typeof meta.providerSessionId === "string") {
40100
40118
  this.providerSessionId = meta.providerSessionId;
40101
40119
  }
40120
+ try {
40121
+ this.driver.updateMeta(meta);
40122
+ } catch {
40123
+ }
40102
40124
  }
40103
40125
  refreshProviderDefinition() {
40104
40126
  }
@@ -44539,14 +44561,15 @@ var DaemonCliManager = class {
44539
44561
  console.error(colorize("red", ` \u2717 Failed to save recent activity: ${e}`));
44540
44562
  }
44541
44563
  }
44542
- getTransportFactory(runtimeId, providerType, workspace, cliArgs, providerSessionId, attachExisting = false) {
44564
+ getTransportFactory(runtimeId, providerType, workspace, cliArgs, providerSessionId, attachExisting = false, initialMeta) {
44543
44565
  return this.deps.createPtyTransportFactory?.({
44544
44566
  runtimeId,
44545
44567
  providerType,
44546
44568
  workspace,
44547
44569
  cliArgs,
44548
44570
  providerSessionId,
44549
- attachExisting
44571
+ attachExisting,
44572
+ ...initialMeta && Object.keys(initialMeta).length ? { initialMeta } : {}
44550
44573
  }) || void 0;
44551
44574
  }
44552
44575
  createAdapter(cliType, workingDir, cliArgs, runtimeId, providerSessionId, attachExisting = false, extraEnv) {
@@ -44602,13 +44625,25 @@ var DaemonCliManager = class {
44602
44625
  const instanceManager = this.deps.getInstanceManager();
44603
44626
  const sessionRegistry = this.deps.getSessionRegistry?.() || null;
44604
44627
  if (!instanceManager) throw new Error("InstanceManager not available");
44628
+ const launchMeshNodeId = typeof settings?.meshNodeId === "string" ? settings.meshNodeId.trim() : "";
44629
+ const launchMeshNodeFor = typeof settings?.meshNodeFor === "string" ? settings.meshNodeFor.trim() : "";
44630
+ const launchAutoLaunchedForQueueTaskId = typeof settings?.autoLaunchedForQueueTaskId === "string" ? settings.autoLaunchedForQueueTaskId.trim() : "";
44631
+ const launchRecordMeta = {
44632
+ ...launchMeshNodeId ? { meshNodeId: launchMeshNodeId } : {},
44633
+ ...launchMeshNodeFor ? { meshNodeFor: launchMeshNodeFor } : {},
44634
+ ...settings?.launchedByCoordinator === true ? { launchedByCoordinator: true } : {},
44635
+ ...launchAutoLaunchedForQueueTaskId ? { autoLaunchedForQueueTaskId: launchAutoLaunchedForQueueTaskId } : {}
44636
+ };
44605
44637
  const transportFactory = this.getTransportFactory(
44606
44638
  key2,
44607
44639
  normalizedType,
44608
44640
  resolvedDir,
44609
44641
  cliArgs,
44610
44642
  options?.providerSessionId,
44611
- attachExisting
44643
+ attachExisting,
44644
+ // Only seed at create time for fresh launches — an attach restores an
44645
+ // existing record whose meta is already stamped; re-seeding could clobber.
44646
+ attachExisting ? void 0 : launchRecordMeta
44612
44647
  );
44613
44648
  const cliInstance = new CliProviderInstance(provider, resolvedDir, cliArgs, key2, transportFactory, options);
44614
44649
  try {
@@ -44645,17 +44680,9 @@ var DaemonCliManager = class {
44645
44680
  throw new Error(`Failed to start ${provider.displayName || provider.name || cliType}: ${spawnErr?.message}`);
44646
44681
  }
44647
44682
  this.adapters.set(key2, cliInstance.getAdapter());
44648
- const launchMeshNodeId = typeof settings?.meshNodeId === "string" ? settings.meshNodeId.trim() : "";
44649
- const launchMeshNodeFor = typeof settings?.meshNodeFor === "string" ? settings.meshNodeFor.trim() : "";
44650
- const launchAutoLaunchedForQueueTaskId = typeof settings?.autoLaunchedForQueueTaskId === "string" ? settings.autoLaunchedForQueueTaskId.trim() : "";
44651
- if (launchMeshNodeId || launchMeshNodeFor || launchAutoLaunchedForQueueTaskId) {
44683
+ if (Object.keys(launchRecordMeta).length) {
44652
44684
  try {
44653
- cliInstance.getAdapter().updateRuntimeMeta?.({
44654
- ...launchMeshNodeId ? { meshNodeId: launchMeshNodeId } : {},
44655
- ...launchMeshNodeFor ? { meshNodeFor: launchMeshNodeFor } : {},
44656
- ...settings?.launchedByCoordinator === true ? { launchedByCoordinator: true } : {},
44657
- ...launchAutoLaunchedForQueueTaskId ? { autoLaunchedForQueueTaskId: launchAutoLaunchedForQueueTaskId } : {}
44658
- });
44685
+ cliInstance.getAdapter().updateRuntimeMeta?.({ ...launchRecordMeta });
44659
44686
  } catch {
44660
44687
  }
44661
44688
  }
@@ -50125,6 +50152,8 @@ var meshCrudHandlers = {
50125
50152
  const sessionIds = Array.isArray(args?.sessionIds) ? args.sessionIds.map((id) => typeof id === "string" ? id.trim() : "").filter(Boolean) : void 0;
50126
50153
  const source = args?.source === "magi_session_cleanup" ? "magi_session_cleanup" : "mesh_cleanup_sessions";
50127
50154
  const requireAutoLaunchedForTaskIds = args?.requireAutoLaunchedForTaskIds && typeof args.requireAutoLaunchedForTaskIds === "object" && !Array.isArray(args.requireAutoLaunchedForTaskIds) ? args.requireAutoLaunchedForTaskIds : void 0;
50155
+ const reclaimOrphans = args?.reclaimOrphans === true;
50156
+ const liveMeshNodeIds = Array.isArray(mesh?.nodes) ? mesh.nodes.map((n) => normalizeMeshNodeId(n)).filter(Boolean) : [];
50128
50157
  const result = await ctx.cleanupMeshSessions({
50129
50158
  meshId,
50130
50159
  nodeId,
@@ -50133,7 +50162,9 @@ var meshCrudHandlers = {
50133
50162
  sessionIds,
50134
50163
  dryRun: args?.dryRun === true,
50135
50164
  source,
50136
- requireAutoLaunchedForTaskIds
50165
+ requireAutoLaunchedForTaskIds,
50166
+ reclaimOrphans,
50167
+ liveMeshNodeIds
50137
50168
  });
50138
50169
  return result;
50139
50170
  } catch (e) {
@@ -56218,6 +56249,13 @@ var DaemonCommandRouter = class {
56218
56249
  }
56219
56250
  if (!this.deps.sessionHostControl) return { success: false, error: "Session host control unavailable" };
56220
56251
  const requestedSessionIds = Array.isArray(args.sessionIds) ? new Set(args.sessionIds.map((id) => typeof id === "string" ? id.trim() : "").filter(Boolean)) : void 0;
56252
+ const reclaimOrphans = args.reclaimOrphans === true;
56253
+ const liveMeshNodeIds = Array.isArray(args.liveMeshNodeIds) ? args.liveMeshNodeIds.map((id) => typeof id === "string" ? id.trim() : "").filter(Boolean) : [];
56254
+ const isNodeStillLive = (candidateNodeId) => {
56255
+ if (!candidateNodeId) return false;
56256
+ return liveMeshNodeIds.some((liveId) => liveId === candidateNodeId || meshNodeIdMatches({ id: liveId }, candidateNodeId) || daemonIdsEquivalent(liveId, candidateNodeId));
56257
+ };
56258
+ const reclaimedOrphanSessionIds = [];
56221
56259
  const sessions = await this.deps.sessionHostControl.listSessions();
56222
56260
  const matched = sessions.filter((record) => this.sessionMatchesMeshNode(record, args.node, args.nodeId, requestedSessionIds));
56223
56261
  const hasExplicitSessionIds = !!requestedSessionIds?.size;
@@ -56286,7 +56324,8 @@ var DaemonCommandRouter = class {
56286
56324
  const matchedByWorkspaceOnly = !recordNodeId;
56287
56325
  const isWorktreeNodeRemoval = cleanupSource === "mesh_remove_node" && args.node?.isLocalWorktree === true;
56288
56326
  const cleanWorkspaceOnlyForWorktree = isWorktreeNodeRemoval && matchedByWorkspaceOnly;
56289
- if (!hasExplicitSessionIds && liveRuntime && !delegateBoundToThisNode && !cleanWorkspaceOnlyForWorktree) {
56327
+ const reclaimableOrphan = reclaimOrphans && liveRuntime && !delegateBoundToThisNode && (matchedByWorkspaceOnly || !isNodeStillLive(recordNodeId));
56328
+ if (!hasExplicitSessionIds && liveRuntime && !delegateBoundToThisNode && !cleanWorkspaceOnlyForWorktree && !reclaimableOrphan) {
56290
56329
  skippedSessionIds.push(sessionId);
56291
56330
  skippedLiveSessionIds.push(sessionId);
56292
56331
  const reason = recordNodeId && recordNodeId !== args.nodeId ? `live_delegate_bound_to_other_node:${recordNodeId}` : matchedByWorkspaceOnly ? "live_session_matched_by_workspace_only_no_node_binding" : "live_session_not_bound_to_this_node";
@@ -56296,6 +56335,10 @@ var DaemonCommandRouter = class {
56296
56335
  if (cleanWorkspaceOnlyForWorktree && !delegateBoundToThisNode) {
56297
56336
  actedLiveDelegateSessionIds.push(sessionId);
56298
56337
  }
56338
+ if (reclaimableOrphan && !cleanWorkspaceOnlyForWorktree && !delegateBoundToThisNode) {
56339
+ reclaimedOrphanSessionIds.push(sessionId);
56340
+ actedLiveDelegateSessionIds.push(sessionId);
56341
+ }
56299
56342
  if (!hasExplicitSessionIds && liveRuntime && delegateBoundToThisNode && args.mode === "delete_stopped") {
56300
56343
  skippedSessionIds.push(sessionId);
56301
56344
  skippedLiveSessionIds.push(sessionId);
@@ -56368,6 +56411,7 @@ var DaemonCommandRouter = class {
56368
56411
  skippedCoordinatorSessionIds,
56369
56412
  ...skippedMarkerMismatchSessionIds.length ? { skippedMarkerMismatchSessionIds } : {},
56370
56413
  ...actedLiveDelegateSessionIds.length ? { actedLiveDelegateSessionIds } : {},
56414
+ ...reclaimedOrphanSessionIds.length ? { reclaimedOrphanSessionIds } : {},
56371
56415
  ...skippedLiveSessionReasons.length ? { skippedLiveSessionReasons } : {},
56372
56416
  ...deleteUnsupported ? {
56373
56417
  deleteUnsupported: true,