@adhdev/daemon-standalone 0.9.82-rc.1 → 0.9.82-rc.11

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
@@ -24046,10 +24046,18 @@ Follow these recovery rules:
24046
24046
  drainPendingMeshCoordinatorEvents: () => drainPendingMeshCoordinatorEvents,
24047
24047
  getPendingMeshCoordinatorEvents: () => getPendingMeshCoordinatorEvents,
24048
24048
  handleMeshForwardEvent: () => handleMeshForwardEvent,
24049
+ queuePendingMeshCoordinatorEvent: () => queuePendingMeshCoordinatorEvent,
24049
24050
  setupMeshEventForwarding: () => setupMeshEventForwarding,
24050
24051
  triggerMeshQueue: () => triggerMeshQueue,
24051
24052
  tryAssignQueueTask: () => tryAssignQueueTask
24052
24053
  });
24054
+ function queuePendingMeshCoordinatorEvent(event) {
24055
+ if (pendingMeshCoordinatorEvents.length >= MAX_PENDING_EVENTS) {
24056
+ return false;
24057
+ }
24058
+ pendingMeshCoordinatorEvents.push(event);
24059
+ return true;
24060
+ }
24053
24061
  function drainPendingMeshCoordinatorEvents() {
24054
24062
  return pendingMeshCoordinatorEvents.splice(0);
24055
24063
  }
@@ -24621,17 +24629,18 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
24621
24629
  return true;
24622
24630
  });
24623
24631
  if (coordinatorInstances.length === 0) {
24624
- if (pendingMeshCoordinatorEvents.length < MAX_PENDING_EVENTS) {
24625
- pendingMeshCoordinatorEvents.push({
24626
- event: args.event,
24627
- meshId: args.meshId,
24628
- nodeLabel: args.nodeLabel,
24629
- metadataEvent: {
24630
- ...args.metadataEvent,
24631
- ...recoveryContext ? { recoveryContext } : {}
24632
- },
24633
- queuedAt: Date.now()
24634
- });
24632
+ if (queuePendingMeshCoordinatorEvent({
24633
+ event: args.event,
24634
+ meshId: args.meshId,
24635
+ nodeLabel: args.nodeLabel,
24636
+ nodeId: args.nodeId || void 0,
24637
+ workspace: readNonEmptyString(args.metadataEvent.workspace),
24638
+ metadataEvent: {
24639
+ ...args.metadataEvent,
24640
+ ...recoveryContext ? { recoveryContext } : {}
24641
+ },
24642
+ queuedAt: Date.now()
24643
+ })) {
24635
24644
  LOG2.info("MeshEvents", `Queued ${args.event} for MCP coordinator (mesh ${args.meshId})`);
24636
24645
  }
24637
24646
  return { success: true, forwarded: 0 };
@@ -28013,6 +28022,7 @@ ${lastSnapshot}`;
28013
28022
  prepareSessionChatTailUpdate: () => prepareSessionChatTailUpdate2,
28014
28023
  prepareSessionModalUpdate: () => prepareSessionModalUpdate2,
28015
28024
  probeCdpPort: () => probeCdpPort,
28025
+ queuePendingMeshCoordinatorEvent: () => queuePendingMeshCoordinatorEvent,
28016
28026
  readChatHistory: () => readChatHistory,
28017
28027
  readLedgerEntries: () => readLedgerEntries,
28018
28028
  readLedgerSlice: () => readLedgerSlice,
@@ -28062,8 +28072,14 @@ ${lastSnapshot}`;
28062
28072
  const includeSubmodules = options.includeSubmodules !== false;
28063
28073
  try {
28064
28074
  const repo = await resolveGitRepository(workspace, options);
28065
- const statusOutput = await runGit(repo, ["status", "--porcelain=v2", "--branch"], options);
28066
- const parsed = parsePorcelainV2Status(statusOutput.stdout);
28075
+ let parsed = await readPorcelainStatus(repo, options);
28076
+ let upstreamProbe = getInitialUpstreamProbe(parsed);
28077
+ if (options.refreshUpstream) {
28078
+ upstreamProbe = await refreshTrackedUpstream(repo, parsed, options);
28079
+ if (upstreamProbe.upstreamStatus === "fresh") {
28080
+ parsed = await readPorcelainStatus(repo, options);
28081
+ }
28082
+ }
28067
28083
  const head = await readHead(repo, options);
28068
28084
  const stashCount = await readStashCount(repo, options);
28069
28085
  let submodules;
@@ -28078,6 +28094,9 @@ ${lastSnapshot}`;
28078
28094
  headCommit: head.commit,
28079
28095
  headMessage: head.message,
28080
28096
  upstream: parsed.upstream,
28097
+ upstreamStatus: parsed.upstream ? upstreamProbe.upstreamStatus : "no_upstream",
28098
+ upstreamFetchedAt: upstreamProbe.upstreamFetchedAt,
28099
+ upstreamFetchError: upstreamProbe.upstreamFetchError,
28081
28100
  ahead: parsed.ahead,
28082
28101
  behind: parsed.behind,
28083
28102
  staged: parsed.staged,
@@ -28102,6 +28121,60 @@ ${lastSnapshot}`;
28102
28121
  );
28103
28122
  }
28104
28123
  }
28124
+ async function readPorcelainStatus(repo, options) {
28125
+ const statusOutput = await runGit(repo, ["status", "--porcelain=v2", "--branch"], options);
28126
+ return parsePorcelainV2Status(statusOutput.stdout);
28127
+ }
28128
+ function getInitialUpstreamProbe(parsed) {
28129
+ return {
28130
+ upstreamStatus: parsed.upstream ? "unchecked" : "no_upstream"
28131
+ };
28132
+ }
28133
+ async function refreshTrackedUpstream(repo, parsed, options) {
28134
+ if (!parsed.upstream || !parsed.branch) {
28135
+ return { upstreamStatus: "no_upstream" };
28136
+ }
28137
+ const remoteName = await readBranchRemote(repo, parsed.branch, options) ?? inferRemoteName(parsed.upstream);
28138
+ if (!remoteName) {
28139
+ return {
28140
+ upstreamStatus: "stale",
28141
+ upstreamFetchError: `Unable to resolve remote for upstream '${parsed.upstream}'`
28142
+ };
28143
+ }
28144
+ try {
28145
+ await runGit(repo, ["fetch", "--quiet", "--prune", "--no-tags", remoteName], options);
28146
+ return {
28147
+ upstreamStatus: "fresh",
28148
+ upstreamFetchedAt: Date.now()
28149
+ };
28150
+ } catch (error48) {
28151
+ return {
28152
+ upstreamStatus: "stale",
28153
+ upstreamFetchError: formatGitError(error48)
28154
+ };
28155
+ }
28156
+ }
28157
+ async function readBranchRemote(repo, branch, options) {
28158
+ try {
28159
+ const result = await runGit(repo, ["config", "--get", `branch.${branch}.remote`], options);
28160
+ return result.stdout.trim() || null;
28161
+ } catch {
28162
+ return null;
28163
+ }
28164
+ }
28165
+ function inferRemoteName(upstream) {
28166
+ const [remoteName] = upstream.split("/");
28167
+ return remoteName?.trim() || null;
28168
+ }
28169
+ function formatGitError(error48) {
28170
+ if (error48 instanceof GitCommandError) {
28171
+ return error48.stderr || error48.message;
28172
+ }
28173
+ if (error48 instanceof Error) {
28174
+ return error48.message;
28175
+ }
28176
+ return String(error48);
28177
+ }
28105
28178
  function parsePorcelainV2Status(output) {
28106
28179
  const parsed = {
28107
28180
  branch: null,
@@ -28196,6 +28269,7 @@ ${lastSnapshot}`;
28196
28269
  headCommit: null,
28197
28270
  headMessage: null,
28198
28271
  upstream: null,
28272
+ upstreamStatus: "unavailable",
28199
28273
  ahead: 0,
28200
28274
  behind: 0,
28201
28275
  staged: 0,
@@ -28472,6 +28546,9 @@ ${lastSnapshot}`;
28472
28546
  isGitRepo: status.isGitRepo,
28473
28547
  repoRoot: status.repoRoot,
28474
28548
  branch: status.branch,
28549
+ upstreamStatus: status.upstreamStatus,
28550
+ upstreamFetchedAt: status.upstreamFetchedAt,
28551
+ upstreamFetchError: status.upstreamFetchError,
28475
28552
  dirty: status.staged > 0 || status.modified > 0 || status.untracked > 0 || status.deleted > 0 || status.renamed > 0 || conflictCount > 0 || changedFiles > 0,
28476
28553
  changedFiles,
28477
28554
  ahead: status.ahead,
@@ -28810,7 +28887,7 @@ ${lastSnapshot}`;
28810
28887
  });
28811
28888
  function createDefaultGitCommandServices() {
28812
28889
  return {
28813
- getStatus: ({ workspace }) => getGitRepoStatus(workspace),
28890
+ getStatus: ({ workspace, refreshUpstream }) => getGitRepoStatus(workspace, { refreshUpstream }),
28814
28891
  getDiffSummary: ({ workspace }) => getGitDiffSummary(workspace),
28815
28892
  getDiffFile: ({ workspace, path: filePath }) => getGitFileDiff(workspace, filePath),
28816
28893
  createSnapshot: ({ workspace, reason, sessionId, turnId }) => defaultSnapshotStore.create({
@@ -28896,7 +28973,7 @@ ${lastSnapshot}`;
28896
28973
  switch (command) {
28897
28974
  case "git_status": {
28898
28975
  if (!services.getStatus) return serviceNotImplemented(command);
28899
- const status = await runService(() => services.getStatus({ workspace }));
28976
+ const status = await runService(() => services.getStatus({ workspace, refreshUpstream: optionalBoolean(args?.refreshUpstream) }));
28900
28977
  return "success" in status ? status : { success: true, status };
28901
28978
  }
28902
28979
  case "git_diff_summary": {
@@ -45791,6 +45868,240 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
45791
45868
  return true;
45792
45869
  });
45793
45870
  }
45871
+ function readObjectRecord(value) {
45872
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
45873
+ }
45874
+ function readStringValue(...values) {
45875
+ for (const value of values) {
45876
+ if (typeof value === "string" && value.trim()) return value.trim();
45877
+ }
45878
+ return void 0;
45879
+ }
45880
+ function readNumberValue(...values) {
45881
+ for (const value of values) {
45882
+ if (typeof value === "number" && Number.isFinite(value)) return value;
45883
+ }
45884
+ return void 0;
45885
+ }
45886
+ function readBooleanValue(...values) {
45887
+ for (const value of values) {
45888
+ if (typeof value === "boolean") return value;
45889
+ }
45890
+ return void 0;
45891
+ }
45892
+ function readGitSubmodules(value) {
45893
+ if (!Array.isArray(value)) return void 0;
45894
+ const submodules = value.map((entry) => {
45895
+ const submodule = readObjectRecord(entry);
45896
+ const path28 = readStringValue(submodule.path);
45897
+ const commit = readStringValue(submodule.commit);
45898
+ const repoPath = readStringValue(submodule.repoPath, submodule.repo_root);
45899
+ if (!path28 || !commit || !repoPath) return null;
45900
+ return {
45901
+ path: path28,
45902
+ commit,
45903
+ repoPath,
45904
+ dirty: readBooleanValue(submodule.dirty) ?? false,
45905
+ outOfSync: readBooleanValue(submodule.outOfSync, submodule.out_of_sync) ?? false,
45906
+ lastCheckedAt: readNumberValue(submodule.lastCheckedAt, submodule.last_checked_at) ?? Date.now(),
45907
+ ...readStringValue(submodule.error) ? { error: readStringValue(submodule.error) } : {}
45908
+ };
45909
+ }).filter((entry) => entry !== null);
45910
+ return submodules.length > 0 ? submodules : void 0;
45911
+ }
45912
+ function buildCachedInlineMeshGitStatus(node) {
45913
+ const cachedStatus = readObjectRecord(node?.cachedStatus);
45914
+ const cachedGit = readObjectRecord(cachedStatus.git);
45915
+ if (Object.keys(cachedGit).length) {
45916
+ const conflictFiles2 = Array.isArray(cachedGit.conflictFiles) ? cachedGit.conflictFiles.filter((value) => typeof value === "string") : [];
45917
+ const conflictCount2 = readNumberValue(cachedGit.conflicts) ?? conflictFiles2.length;
45918
+ const hasConflicts2 = readBooleanValue(cachedGit.hasConflicts) ?? conflictCount2 > 0;
45919
+ const isGitRepo2 = readBooleanValue(cachedGit.isGitRepo);
45920
+ if (isGitRepo2 !== void 0) {
45921
+ const submodules2 = readGitSubmodules(cachedGit.submodules);
45922
+ return {
45923
+ workspace: readStringValue(cachedGit.workspace, node?.workspace) || "",
45924
+ repoRoot: readStringValue(cachedGit.repoRoot, node?.repoRoot, node?.workspace) || null,
45925
+ isGitRepo: isGitRepo2,
45926
+ branch: readStringValue(cachedGit.branch) ?? null,
45927
+ headCommit: readStringValue(cachedGit.headCommit) ?? null,
45928
+ headMessage: readStringValue(cachedGit.headMessage) ?? null,
45929
+ upstream: readStringValue(cachedGit.upstream) ?? null,
45930
+ ahead: readNumberValue(cachedGit.ahead) ?? 0,
45931
+ behind: readNumberValue(cachedGit.behind) ?? 0,
45932
+ staged: readNumberValue(cachedGit.staged) ?? 0,
45933
+ modified: readNumberValue(cachedGit.modified) ?? 0,
45934
+ untracked: readNumberValue(cachedGit.untracked) ?? 0,
45935
+ deleted: readNumberValue(cachedGit.deleted) ?? 0,
45936
+ renamed: readNumberValue(cachedGit.renamed) ?? 0,
45937
+ hasConflicts: hasConflicts2,
45938
+ conflictFiles: conflictFiles2,
45939
+ stashCount: readNumberValue(cachedGit.stashCount) ?? 0,
45940
+ lastCheckedAt: readNumberValue(cachedGit.lastCheckedAt) ?? Date.now(),
45941
+ ...submodules2 ? { submodules: submodules2 } : {}
45942
+ };
45943
+ }
45944
+ }
45945
+ const rawGit = readObjectRecord(node?.lastGit ?? node?.last_git);
45946
+ const gitResult = readObjectRecord(rawGit.result);
45947
+ const directStatus = readObjectRecord(rawGit.status);
45948
+ const nestedStatus = readObjectRecord(gitResult.status);
45949
+ const rawProbe = readObjectRecord(node?.lastProbe ?? node?.last_probe);
45950
+ const probeGit = readObjectRecord(rawProbe.git);
45951
+ const probeGitResult = readObjectRecord(probeGit.result);
45952
+ const probeDirectStatus = readObjectRecord(probeGit.status);
45953
+ const probeNestedStatus = readObjectRecord(probeGitResult.status);
45954
+ const status = Object.keys(directStatus).length ? directStatus : Object.keys(nestedStatus).length ? nestedStatus : Object.keys(probeDirectStatus).length ? probeDirectStatus : Object.keys(probeNestedStatus).length ? probeNestedStatus : {};
45955
+ const isGitRepo = readBooleanValue(status.isGitRepo);
45956
+ if (!Object.keys(status).length || isGitRepo === void 0) return void 0;
45957
+ const conflictFiles = Array.isArray(status.conflictFiles) ? status.conflictFiles.filter((value) => typeof value === "string") : [];
45958
+ const conflictCount = readNumberValue(status.conflicts) ?? conflictFiles.length;
45959
+ const hasConflicts = readBooleanValue(status.hasConflicts) ?? conflictCount > 0;
45960
+ const submodules = readGitSubmodules(status.submodules);
45961
+ return {
45962
+ workspace: readStringValue(status.workspace, node?.workspace) || "",
45963
+ repoRoot: readStringValue(status.repoRoot, node?.repoRoot, node?.workspace) || null,
45964
+ isGitRepo,
45965
+ branch: readStringValue(status.branch) ?? null,
45966
+ headCommit: readStringValue(status.headCommit) ?? null,
45967
+ headMessage: readStringValue(status.headMessage) ?? null,
45968
+ upstream: readStringValue(status.upstream) ?? null,
45969
+ ahead: readNumberValue(status.ahead) ?? 0,
45970
+ behind: readNumberValue(status.behind) ?? 0,
45971
+ staged: readNumberValue(status.staged) ?? 0,
45972
+ modified: readNumberValue(status.modified) ?? 0,
45973
+ untracked: readNumberValue(status.untracked) ?? 0,
45974
+ deleted: readNumberValue(status.deleted) ?? 0,
45975
+ renamed: readNumberValue(status.renamed) ?? 0,
45976
+ hasConflicts,
45977
+ conflictFiles,
45978
+ stashCount: readNumberValue(status.stashCount) ?? 0,
45979
+ lastCheckedAt: Date.now(),
45980
+ ...submodules ? { submodules } : {}
45981
+ };
45982
+ }
45983
+ function hasGitWorktreeChanges(git) {
45984
+ if (!git) return false;
45985
+ return Number(git.staged || 0) + Number(git.modified || 0) + Number(git.untracked || 0) + Number(git.deleted || 0) + Number(git.renamed || 0) > 0;
45986
+ }
45987
+ function getGitSubmoduleDriftState(git) {
45988
+ const submodules = Array.isArray(git?.submodules) ? git.submodules : [];
45989
+ let dirty = false;
45990
+ let outOfSync = false;
45991
+ for (const entry of submodules) {
45992
+ const submodule = readObjectRecord(entry);
45993
+ if (readBooleanValue(submodule.dirty) === true) dirty = true;
45994
+ if (readBooleanValue(submodule.outOfSync) === true || !!readStringValue(submodule.error)) outOfSync = true;
45995
+ }
45996
+ return { dirty, outOfSync };
45997
+ }
45998
+ function deriveMeshNodeHealthFromGit(git) {
45999
+ if (!git || readBooleanValue(git.isGitRepo) === false) return "degraded";
46000
+ const branch = readStringValue(git.branch);
46001
+ if (!branch) return "degraded";
46002
+ const submoduleDrift = getGitSubmoduleDriftState(git);
46003
+ if (submoduleDrift.outOfSync) return "degraded";
46004
+ if (submoduleDrift.dirty || hasGitWorktreeChanges(git)) return "dirty";
46005
+ return "online";
46006
+ }
46007
+ function readCachedInlineMeshActiveSessions(node) {
46008
+ const cachedStatus = readObjectRecord(node?.cachedStatus);
46009
+ const activeSession = readObjectRecord(cachedStatus.activeSession);
46010
+ const fallbackSession = Object.keys(activeSession).length ? activeSession : readObjectRecord(node?.activeSession ?? node?.active_session);
46011
+ const sessionId = readStringValue(fallbackSession.id, fallbackSession.sessionId, fallbackSession.session_id, node?.activeSessionId, node?.active_session_id, node?.sessionId, node?.session_id);
46012
+ return sessionId ? [sessionId] : [];
46013
+ }
46014
+ function readCachedInlineMeshActiveSessionDetails(node) {
46015
+ const cachedStatus = readObjectRecord(node?.cachedStatus);
46016
+ const activeSession = readObjectRecord(cachedStatus.activeSession);
46017
+ const fallbackSession = Object.keys(activeSession).length ? activeSession : readObjectRecord(node?.activeSession ?? node?.active_session);
46018
+ const sessionId = readStringValue(
46019
+ fallbackSession.id,
46020
+ fallbackSession.sessionId,
46021
+ fallbackSession.session_id,
46022
+ node?.activeSessionId,
46023
+ node?.active_session_id,
46024
+ node?.sessionId,
46025
+ node?.session_id
46026
+ );
46027
+ if (!sessionId) return [];
46028
+ return [{
46029
+ sessionId,
46030
+ providerType: readStringValue(
46031
+ fallbackSession.providerType,
46032
+ fallbackSession.provider_type,
46033
+ fallbackSession.cliType,
46034
+ fallbackSession.cli_type,
46035
+ fallbackSession.provider,
46036
+ node?.providerType,
46037
+ node?.provider_type
46038
+ ),
46039
+ state: readStringValue(fallbackSession.status, fallbackSession.state, fallbackSession.lifecycle),
46040
+ lifecycle: readStringValue(fallbackSession.lifecycle),
46041
+ title: readStringValue(fallbackSession.title, fallbackSession.displayName, fallbackSession.display_name) ?? null,
46042
+ workspace: readStringValue(fallbackSession.workspace, node?.workspace) ?? null,
46043
+ lastActivityAt: readStringValue(fallbackSession.lastActivityAt, fallbackSession.last_activity_at) ?? null,
46044
+ recoveryState: readStringValue(fallbackSession.recoveryState, fallbackSession.recovery_state) ?? null,
46045
+ isCached: true
46046
+ }];
46047
+ }
46048
+ function readLiveMeshSessionState(record2) {
46049
+ return readStringValue(
46050
+ record2?.meta?.sessionStatus,
46051
+ record2?.meta?.status,
46052
+ record2?.meta?.providerStatus,
46053
+ record2?.status,
46054
+ record2?.state,
46055
+ record2?.lifecycle
46056
+ );
46057
+ }
46058
+ function toIsoTimestamp(value) {
46059
+ if (typeof value === "number" && Number.isFinite(value)) return new Date(value).toISOString();
46060
+ const stringValue = readStringValue(value);
46061
+ return stringValue || null;
46062
+ }
46063
+ function summarizeMeshSessionRecord(record2) {
46064
+ return {
46065
+ sessionId: readStringValue(record2?.sessionId) || "unknown",
46066
+ providerType: readStringValue(record2?.providerType),
46067
+ state: readLiveMeshSessionState(record2),
46068
+ lifecycle: readStringValue(record2?.lifecycle),
46069
+ surfaceKind: getSessionHostSurfaceKind(record2),
46070
+ recoveryState: readStringValue(record2?.meta?.runtimeRecoveryState) ?? null,
46071
+ workspace: readStringValue(record2?.workspace) ?? null,
46072
+ title: readStringValue(record2?.displayName, record2?.workspaceLabel) ?? null,
46073
+ lastActivityAt: toIsoTimestamp(record2?.updatedAt ?? record2?.lastActivityAt ?? record2?.last_activity_at),
46074
+ isCached: false
46075
+ };
46076
+ }
46077
+ function applyCachedInlineMeshNodeStatus(status, node) {
46078
+ const cachedStatus = readObjectRecord(node?.cachedStatus);
46079
+ const git = buildCachedInlineMeshGitStatus(node);
46080
+ const error48 = readStringValue(cachedStatus.error, node?.error);
46081
+ const health = readStringValue(cachedStatus.health, node?.health);
46082
+ const machineStatus = readStringValue(cachedStatus.machineStatus, node?.machineStatus);
46083
+ const lastSeenAt = toIsoTimestamp(cachedStatus.lastSeenAt ?? cachedStatus.last_seen_at ?? node?.lastSeenAt ?? node?.last_seen_at);
46084
+ const updatedAt = toIsoTimestamp(cachedStatus.updatedAt ?? cachedStatus.updated_at ?? node?.updatedAt ?? node?.updated_at);
46085
+ const activeSessions = readCachedInlineMeshActiveSessions(node);
46086
+ const activeSessionDetails = readCachedInlineMeshActiveSessionDetails(node);
46087
+ if (!git && !error48 && !health && !machineStatus && !lastSeenAt && !updatedAt && activeSessions.length === 0) return false;
46088
+ if (git) status.git = git;
46089
+ if (error48) status.error = error48;
46090
+ if (machineStatus) status.machineStatus = machineStatus;
46091
+ if (lastSeenAt) status.lastSeenAt = lastSeenAt;
46092
+ if (updatedAt) status.updatedAt = updatedAt;
46093
+ if (activeSessions.length > 0) status.activeSessions = activeSessions;
46094
+ if (activeSessionDetails.length > 0) status.activeSessionDetails = activeSessionDetails;
46095
+ if (health) {
46096
+ status.health = health;
46097
+ return true;
46098
+ }
46099
+ if (git) {
46100
+ status.health = deriveMeshNodeHealthFromGit(git);
46101
+ return true;
46102
+ }
46103
+ return activeSessions.length > 0 || !!machineStatus || !!lastSeenAt || !!updatedAt;
46104
+ }
45794
46105
  async function resolveProviderTypeFromPriority(args) {
45795
46106
  if (!args.providerPriority.length) {
45796
46107
  return { error: `Node '${args.nodeId}' has no providerPriority policy; pass cliType explicitly or configure node.policy.providerPriority` };
@@ -46192,7 +46503,12 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
46192
46503
  }
46193
46504
  return this.inlineMeshCache.get(meshId);
46194
46505
  }
46195
- async getMeshForCommand(meshId, inlineMesh) {
46506
+ async getMeshForCommand(meshId, inlineMesh, options) {
46507
+ const preferInline = options?.preferInline === true;
46508
+ if (preferInline) {
46509
+ const cached22 = this.getCachedInlineMesh(meshId, inlineMesh);
46510
+ if (cached22) return { mesh: cached22, inline: true };
46511
+ }
46196
46512
  try {
46197
46513
  const { getMesh: getMesh3 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
46198
46514
  const mesh = getMesh3(meshId);
@@ -48015,7 +48331,7 @@ ${block}`);
48015
48331
  const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
48016
48332
  if (!meshId) return { success: false, error: "meshId required" };
48017
48333
  try {
48018
- const meshRecord = await this.getMeshForCommand(meshId, args?.inlineMesh);
48334
+ const meshRecord = await this.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
48019
48335
  const mesh = meshRecord?.mesh;
48020
48336
  if (!mesh) return { success: false, error: "Mesh not found" };
48021
48337
  const { getMeshQueueStats: getMeshQueueStats2, getQueue: getQueue2 } = await Promise.resolve().then(() => (init_mesh_work_queue(), mesh_work_queue_exports));
@@ -48024,84 +48340,102 @@ ${block}`);
48024
48340
  const { readLedgerEntries: readLedgerEntries2, getLedgerSummary: getLedgerSummary2 } = await Promise.resolve().then(() => (init_mesh_ledger(), mesh_ledger_exports));
48025
48341
  const ledgerEntries = readLedgerEntries2(meshId, { tail: 20 });
48026
48342
  const ledgerSummary = getLedgerSummary2(meshId);
48343
+ const sessionHostRecords = this.deps.sessionHostControl?.listSessions ? await this.deps.sessionHostControl.listSessions().catch(() => []) : [];
48344
+ const liveMeshSessions = partitionSessionHostRecords(Array.isArray(sessionHostRecords) ? sessionHostRecords : []).liveRuntimes;
48345
+ const localMachineId = loadConfig2().machineId || "";
48346
+ const inlineCoordinatorNodeId = meshRecord?.inline && Array.isArray(mesh.nodes) ? readStringValue(mesh.nodes[0]?.id, mesh.nodes[0]?.nodeId) : void 0;
48347
+ const refreshedAt = (/* @__PURE__ */ new Date()).toISOString();
48027
48348
  const nodeStatuses = [];
48028
- for (const node of mesh.nodes || []) {
48349
+ for (const [nodeIndex, node] of (mesh.nodes || []).entries()) {
48350
+ const nodeId = String(node.id || node.nodeId || "");
48351
+ const daemonId = readStringValue(node.daemonId);
48352
+ const providerPriority = readProviderPriorityFromPolicy(node.policy);
48353
+ const isSelfNode = Boolean(
48354
+ nodeId && inlineCoordinatorNodeId && nodeId === inlineCoordinatorNodeId
48355
+ ) || Boolean(
48356
+ daemonId && (daemonId === localMachineId || daemonId === this.deps.statusInstanceId)
48357
+ ) || Boolean(meshRecord?.inline && nodeIndex === 0);
48029
48358
  const status = {
48030
- nodeId: node.id || node.nodeId,
48359
+ nodeId,
48031
48360
  machineLabel: node.machineLabel || node.id || node.nodeId,
48032
48361
  workspace: node.workspace,
48033
48362
  repoRoot: node.repoRoot,
48034
48363
  isLocalWorktree: node.isLocalWorktree,
48035
48364
  worktreeBranch: node.worktreeBranch,
48036
- daemonId: node.daemonId,
48365
+ daemonId,
48037
48366
  machineId: node.machineId,
48367
+ machineStatus: node.machineStatus,
48038
48368
  health: "unknown",
48039
48369
  providers: node.providers || [],
48040
- activeSessions: []
48370
+ providerPriority,
48371
+ activeSessions: [],
48372
+ activeSessionDetails: [],
48373
+ launchReady: false
48041
48374
  };
48375
+ if (isSelfNode) {
48376
+ status.connection = {
48377
+ perspective: "selected_coordinator",
48378
+ source: "mesh_peer_status",
48379
+ state: "self",
48380
+ transport: "local",
48381
+ reported: true,
48382
+ reason: "Selected coordinator daemon",
48383
+ lastStateChangeAt: refreshedAt
48384
+ };
48385
+ } else if (daemonId) {
48386
+ const connection = this.deps.getMeshPeerConnectionStatus?.(daemonId);
48387
+ status.connection = connection ?? {
48388
+ perspective: "selected_coordinator",
48389
+ source: "not_reported",
48390
+ state: "unknown",
48391
+ transport: "unknown",
48392
+ reported: false,
48393
+ reason: "No live mesh peer telemetry reported by the selected coordinator yet."
48394
+ };
48395
+ } else {
48396
+ status.connection = {
48397
+ perspective: "selected_coordinator",
48398
+ source: "not_reported",
48399
+ state: "unknown",
48400
+ transport: "unknown",
48401
+ reported: false,
48402
+ reason: "Node has no daemon id, so mesh transport cannot be reported from the selected coordinator."
48403
+ };
48404
+ }
48405
+ const matchedLiveSessionRecords = liveMeshSessions.filter((record2) => this.sessionMatchesMeshNode(record2, node, nodeId));
48406
+ if (matchedLiveSessionRecords.length > 0) {
48407
+ const sessionIds = matchedLiveSessionRecords.map((record2) => typeof record2?.sessionId === "string" ? record2.sessionId : "").filter(Boolean);
48408
+ const providerTypes = matchedLiveSessionRecords.map((record2) => readStringValue(record2?.providerType)).filter(Boolean);
48409
+ status.activeSessions = sessionIds;
48410
+ status.activeSessionDetails = matchedLiveSessionRecords.map(summarizeMeshSessionRecord);
48411
+ if (providerTypes.length > 0) {
48412
+ status.providers = Array.from(/* @__PURE__ */ new Set([...Array.isArray(status.providers) ? status.providers : [], ...providerTypes]));
48413
+ }
48414
+ }
48042
48415
  if (node.workspace && typeof node.workspace === "string") {
48416
+ if (!fs10.existsSync(node.workspace) && applyCachedInlineMeshNodeStatus(status, node)) {
48417
+ status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
48418
+ nodeStatuses.push(status);
48419
+ continue;
48420
+ }
48043
48421
  try {
48044
- const { execFile: execFile3 } = await import("child_process");
48045
- const { promisify: promisify3 } = await import("util");
48046
- const execFileAsync3 = promisify3(execFile3);
48047
- const runGit2 = async (args2) => {
48048
- const result = await execFileAsync3("git", ["-C", node.workspace, ...args2], {
48049
- encoding: "utf8",
48050
- timeout: 1e4
48051
- });
48052
- return result.stdout.trim();
48053
- };
48054
- const branch = await runGit2(["branch", "--show-current"]).catch(() => "");
48055
- const porc = await runGit2(["status", "--porcelain"]).catch(() => "");
48056
- const headCommit = await runGit2(["rev-parse", "--short", "HEAD"]).catch(() => null);
48057
- const headMessage = await runGit2(["log", "-1", "--format=%s"]).catch(() => null);
48058
- const upstream = await runGit2(["rev-parse", "--abbrev-ref", "@{upstream}"]).catch(() => null);
48059
- const aheadBehind = await runGit2(["rev-list", "--left-right", "--count", "@{upstream}...HEAD"]).catch(() => "");
48060
- const stashCount = await runGit2(["stash", "list"]).catch(() => "");
48061
- let ahead = 0, behind = 0;
48062
- if (aheadBehind) {
48063
- const parts = aheadBehind.split(/\s+/);
48064
- if (parts.length >= 2) {
48065
- behind = parseInt(parts[0], 10) || 0;
48066
- ahead = parseInt(parts[1], 10) || 0;
48067
- }
48068
- }
48069
- const dirty = porc.length > 0;
48070
- const lines = porc ? porc.split("\n").filter(Boolean) : [];
48071
- let staged = 0, modified = 0, untracked = 0, deleted = 0, renamed = 0;
48072
- for (const line of lines) {
48073
- const xy = line.slice(0, 2);
48074
- if (xy[0] !== " " && xy[0] !== "?") staged++;
48075
- if (xy[1] === "M") modified++;
48076
- if (xy[1] === "D") deleted++;
48077
- if (xy[0] === "R" || xy[1] === "R") renamed++;
48078
- if (xy === "??") untracked++;
48422
+ const gitStatus = await getGitRepoStatus(node.workspace, { timeoutMs: 1e4, refreshUpstream: true });
48423
+ status.git = gitStatus;
48424
+ if (gitStatus.isGitRepo) {
48425
+ status.health = deriveMeshNodeHealthFromGit(gitStatus);
48426
+ } else {
48427
+ status.health = "degraded";
48428
+ if (gitStatus.error && !status.error) status.error = gitStatus.error;
48079
48429
  }
48080
- status.git = {
48081
- workspace: node.workspace,
48082
- repoRoot: node.workspace,
48083
- isGitRepo: true,
48084
- branch: branch || null,
48085
- headCommit,
48086
- headMessage,
48087
- upstream,
48088
- ahead,
48089
- behind,
48090
- staged,
48091
- modified,
48092
- untracked,
48093
- deleted,
48094
- renamed,
48095
- hasConflicts: false,
48096
- conflictFiles: [],
48097
- stashCount: stashCount ? stashCount.split("\n").filter(Boolean).length : 0,
48098
- lastCheckedAt: Date.now()
48099
- };
48100
- status.health = branch ? dirty ? "dirty" : "online" : "degraded";
48101
48430
  } catch {
48102
- status.health = "degraded";
48431
+ if (!applyCachedInlineMeshNodeStatus(status, node)) {
48432
+ status.health = "degraded";
48433
+ }
48103
48434
  }
48435
+ } else {
48436
+ applyCachedInlineMeshNodeStatus(status, node);
48104
48437
  }
48438
+ status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
48105
48439
  nodeStatuses.push(status);
48106
48440
  }
48107
48441
  return {
@@ -48110,6 +48444,7 @@ ${block}`);
48110
48444
  meshName: mesh.name,
48111
48445
  repoIdentity: mesh.repoIdentity,
48112
48446
  defaultBranch: mesh.defaultBranch,
48447
+ refreshedAt: (/* @__PURE__ */ new Date()).toISOString(),
48113
48448
  nodes: nodeStatuses,
48114
48449
  queue: { tasks: queue, summary: queueSummary },
48115
48450
  ledger: { entries: ledgerEntries, summary: ledgerSummary }
@@ -55985,6 +56320,7 @@ data: ${JSON.stringify(msg.data)}
55985
56320
  sessionHostControl: config2.sessionHostControl,
55986
56321
  statusInstanceId: config2.statusInstanceId,
55987
56322
  statusVersion: config2.statusVersion,
56323
+ getMeshPeerConnectionStatus: config2.getMeshPeerConnectionStatus,
55988
56324
  getCdpLogFn: config2.getCdpLogFn || ((ideType) => LOG2.forComponent(`CDP:${ideType}`).asLogFn())
55989
56325
  });
55990
56326
  poller = new AgentStreamPoller({