@adhdev/daemon-core 0.9.82-rc.16 → 0.9.82-rc.18

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
@@ -23865,6 +23865,36 @@ function summarizeMeshSessionRecord(record) {
23865
23865
  isCached: false
23866
23866
  };
23867
23867
  }
23868
+ function readLiveMeshNodeWorkspace(args) {
23869
+ const directNodeWorkspace = args.liveSessionRecords.find((record) => readStringValue(record?.meta?.meshNodeId) === args.nodeId && readStringValue(record?.workspace));
23870
+ if (directNodeWorkspace) {
23871
+ return readStringValue(directNodeWorkspace.workspace) || "";
23872
+ }
23873
+ if (args.allowCoordinatorSession) {
23874
+ const coordinatorWorkspace = args.liveSessionRecords.find((record) => readStringValue(record?.meta?.meshCoordinatorFor) === args.meshId && readStringValue(record?.workspace));
23875
+ if (coordinatorWorkspace) {
23876
+ return readStringValue(coordinatorWorkspace.workspace) || "";
23877
+ }
23878
+ }
23879
+ return "";
23880
+ }
23881
+ function collectLiveMeshSessionRecords(args) {
23882
+ const matches = args.liveSessionRecords.filter((record) => {
23883
+ if (readStringValue(record?.meta?.meshNodeId) === args.nodeId) return true;
23884
+ const recordWorkspace = readStringValue(record?.workspace);
23885
+ const nodeWorkspace = readStringValue(args.node?.workspace);
23886
+ return !!recordWorkspace && !!nodeWorkspace && recordWorkspace === nodeWorkspace;
23887
+ });
23888
+ if (args.allowCoordinatorSession) {
23889
+ for (const record of args.liveSessionRecords) {
23890
+ if (readStringValue(record?.meta?.meshCoordinatorFor) !== args.meshId) continue;
23891
+ const sessionId = readStringValue(record?.sessionId);
23892
+ if (sessionId && matches.some((entry) => readStringValue(entry?.sessionId) === sessionId)) continue;
23893
+ matches.push(record);
23894
+ }
23895
+ }
23896
+ return matches;
23897
+ }
23868
23898
  function applyCachedInlineMeshNodeStatus(status, node) {
23869
23899
  const cachedStatus = readObjectRecord(node?.cachedStatus);
23870
23900
  const git = buildCachedInlineMeshGitStatus(node);
@@ -25817,7 +25847,14 @@ var DaemonCommandRouter = class {
25817
25847
  cliType
25818
25848
  };
25819
25849
  }
25820
- const workspace = typeof coordinatorNode.workspace === "string" ? coordinatorNode.workspace.trim() : "";
25850
+ const sessionHostRecords = this.deps.sessionHostControl?.listSessions ? await this.deps.sessionHostControl.listSessions().catch(() => []) : [];
25851
+ const liveMeshSessions = partitionSessionHostRecords(Array.isArray(sessionHostRecords) ? sessionHostRecords : []).liveRuntimes;
25852
+ const workspace = readLiveMeshNodeWorkspace({
25853
+ meshId,
25854
+ nodeId: String(coordinatorNode.id || coordinatorNode.nodeId || preferredCoordinatorNodeId || ""),
25855
+ liveSessionRecords: liveMeshSessions,
25856
+ allowCoordinatorSession: true
25857
+ }) || (typeof coordinatorNode.workspace === "string" ? coordinatorNode.workspace.trim() : "");
25821
25858
  if (!workspace) return { success: false, error: "Coordinator node workspace required", meshId, cliType };
25822
25859
  if (!cliType) {
25823
25860
  const resolved = await resolveProviderTypeFromPriority({
@@ -26128,7 +26165,12 @@ ${block}`);
26128
26165
  const sessionHostRecords = this.deps.sessionHostControl?.listSessions ? await this.deps.sessionHostControl.listSessions().catch(() => []) : [];
26129
26166
  const liveMeshSessions = partitionSessionHostRecords(Array.isArray(sessionHostRecords) ? sessionHostRecords : []).liveRuntimes;
26130
26167
  const localMachineId = loadConfig().machineId || "";
26131
- const inlineCoordinatorNodeId = meshRecord?.inline && Array.isArray(mesh.nodes) ? readStringValue(mesh.nodes[0]?.id, mesh.nodes[0]?.nodeId) : void 0;
26168
+ const selectedCoordinatorNodeId = readStringValue(
26169
+ mesh.coordinator?.preferredNodeId,
26170
+ mesh.nodes?.[0]?.id,
26171
+ mesh.nodes?.[0]?.nodeId
26172
+ );
26173
+ const inlineCoordinatorNodeId = meshRecord?.inline && Array.isArray(mesh.nodes) ? selectedCoordinatorNodeId : void 0;
26132
26174
  const refreshedAt = (/* @__PURE__ */ new Date()).toISOString();
26133
26175
  const nodeStatuses = [];
26134
26176
  for (const [nodeIndex, node] of (mesh.nodes || []).entries()) {
@@ -26187,7 +26229,20 @@ ${block}`);
26187
26229
  reason: "Node has no daemon id, so mesh transport cannot be reported from the selected coordinator."
26188
26230
  };
26189
26231
  }
26190
- const matchedLiveSessionRecords = liveMeshSessions.filter((record) => this.sessionMatchesMeshNode(record, node, nodeId));
26232
+ const matchedLiveSessionRecords = collectLiveMeshSessionRecords({
26233
+ meshId,
26234
+ node,
26235
+ nodeId,
26236
+ liveSessionRecords: liveMeshSessions,
26237
+ allowCoordinatorSession: nodeId === selectedCoordinatorNodeId
26238
+ });
26239
+ const workspace = readLiveMeshNodeWorkspace({
26240
+ meshId,
26241
+ nodeId,
26242
+ liveSessionRecords: matchedLiveSessionRecords,
26243
+ allowCoordinatorSession: nodeId === selectedCoordinatorNodeId
26244
+ }) || (typeof node.workspace === "string" ? node.workspace : "");
26245
+ status.workspace = workspace || node.workspace;
26191
26246
  if (matchedLiveSessionRecords.length > 0) {
26192
26247
  const sessionIds = matchedLiveSessionRecords.map((record) => typeof record?.sessionId === "string" ? record.sessionId : "").filter(Boolean);
26193
26248
  const providerTypes = matchedLiveSessionRecords.map((record) => readStringValue(record?.providerType)).filter(Boolean);
@@ -26197,14 +26252,14 @@ ${block}`);
26197
26252
  status.providers = Array.from(/* @__PURE__ */ new Set([...Array.isArray(status.providers) ? status.providers : [], ...providerTypes]));
26198
26253
  }
26199
26254
  }
26200
- if (node.workspace && typeof node.workspace === "string") {
26201
- if (!fs10.existsSync(node.workspace) && applyCachedInlineMeshNodeStatus(status, node)) {
26255
+ if (workspace) {
26256
+ if (!fs10.existsSync(workspace) && applyCachedInlineMeshNodeStatus(status, node)) {
26202
26257
  status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
26203
26258
  nodeStatuses.push(status);
26204
26259
  continue;
26205
26260
  }
26206
26261
  try {
26207
- const gitStatus = await getGitRepoStatus(node.workspace, { timeoutMs: 1e4, refreshUpstream: true });
26262
+ const gitStatus = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
26208
26263
  status.git = gitStatus;
26209
26264
  if (gitStatus.isGitRepo) {
26210
26265
  status.health = deriveMeshNodeHealthFromGit(gitStatus);