@adhdev/daemon-core 0.9.82-rc.30 → 0.9.82-rc.31

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
@@ -23839,13 +23839,21 @@ function readBooleanValue(...values) {
23839
23839
  }
23840
23840
  return void 0;
23841
23841
  }
23842
- function readGitSubmodules(value) {
23842
+ function joinRepoPath(root, relativePath) {
23843
+ const normalizedRoot = typeof root === "string" ? root.trim().replace(/[\\/]+$/, "") : "";
23844
+ const normalizedPath = typeof relativePath === "string" ? relativePath.trim() : "";
23845
+ if (!normalizedPath) return void 0;
23846
+ if (/^(?:[A-Za-z]:[\\/]|\/)/.test(normalizedPath)) return normalizedPath;
23847
+ if (!normalizedRoot) return void 0;
23848
+ return `${normalizedRoot}/${normalizedPath.replace(/^[\\/]+/, "")}`;
23849
+ }
23850
+ function readGitSubmodules(value, parentRepoRoot) {
23843
23851
  if (!Array.isArray(value)) return void 0;
23844
23852
  const submodules = value.map((entry) => {
23845
23853
  const submodule = readObjectRecord(entry);
23846
23854
  const path28 = readStringValue(submodule.path);
23847
23855
  const commit = readStringValue(submodule.commit);
23848
- const repoPath = readStringValue(submodule.repoPath, submodule.repo_root);
23856
+ const repoPath = readStringValue(submodule.repoPath, submodule.repo_root) ?? joinRepoPath(parentRepoRoot, path28);
23849
23857
  if (!path28 || !commit || !repoPath) return null;
23850
23858
  return {
23851
23859
  path: path28,
@@ -23865,10 +23873,11 @@ function normalizeInlineMeshGitStatus(status, node, options) {
23865
23873
  const conflictFiles = Array.isArray(status.conflictFiles) ? status.conflictFiles.filter((value) => typeof value === "string") : [];
23866
23874
  const conflictCount = readNumberValue(status.conflicts) ?? conflictFiles.length;
23867
23875
  const hasConflicts = readBooleanValue(status.hasConflicts) ?? conflictCount > 0;
23868
- const submodules = readGitSubmodules(status.submodules);
23876
+ const repoRoot = readStringValue(status.repoRoot, status.repo_root, node?.repoRoot, node?.repo_root, status.workspace, node?.workspace) || void 0;
23877
+ const submodules = readGitSubmodules(status.submodules, repoRoot);
23869
23878
  return {
23870
23879
  workspace: readStringValue(status.workspace, node?.workspace) || "",
23871
- repoRoot: readStringValue(status.repoRoot, node?.repoRoot, node?.workspace) || null,
23880
+ repoRoot: repoRoot ?? null,
23872
23881
  isGitRepo,
23873
23882
  branch: readStringValue(status.branch) ?? null,
23874
23883
  headCommit: readStringValue(status.headCommit) ?? null,
@@ -23901,6 +23910,26 @@ function buildInlineMeshTransitGitStatus(node) {
23901
23910
  const status = Object.keys(directStatus).length ? directStatus : Object.keys(nestedStatus).length ? nestedStatus : Object.keys(probeDirectStatus).length ? probeDirectStatus : Object.keys(probeNestedStatus).length ? probeNestedStatus : {};
23902
23911
  return normalizeInlineMeshGitStatus(status, node, { lastCheckedAt: Date.now() });
23903
23912
  }
23913
+ function recordInlineMeshDirectGitTruth(node, git, source) {
23914
+ if (!node || typeof node !== "object" || Array.isArray(node)) return;
23915
+ const checkedAt = readNumberValue(git.lastCheckedAt) ?? Date.now();
23916
+ const updatedAt = new Date(checkedAt).toISOString();
23917
+ const nextGit = {
23918
+ ...git,
23919
+ lastCheckedAt: checkedAt
23920
+ };
23921
+ node.lastGit = {
23922
+ source,
23923
+ checkedAt,
23924
+ status: nextGit
23925
+ };
23926
+ node.last_git = node.lastGit;
23927
+ node.machineStatus = "online";
23928
+ node.updatedAt = updatedAt;
23929
+ node.lastSeenAt = updatedAt;
23930
+ const repoRoot = readStringValue(nextGit.repoRoot);
23931
+ if (repoRoot && !readStringValue(node.repoRoot)) node.repoRoot = repoRoot;
23932
+ }
23904
23933
  function buildCachedInlineMeshGitStatus(node) {
23905
23934
  const liveGit = buildInlineMeshTransitGitStatus(node);
23906
23935
  if (liveGit) return liveGit;
@@ -23943,7 +23972,6 @@ function stripInlineMeshTransientNodeState(node) {
23943
23972
  session_id: _sessionIdLegacy,
23944
23973
  providerType: _providerType,
23945
23974
  provider_type: _providerTypeLegacy,
23946
- providers: _providers,
23947
23975
  ...rest
23948
23976
  } = node;
23949
23977
  if (cachedStatus && !shouldDiscardCachedInlineMeshStatus(node)) {
@@ -23953,7 +23981,7 @@ function stripInlineMeshTransientNodeState(node) {
23953
23981
  }
23954
23982
  function hasInlineMeshTransientNodeState(node) {
23955
23983
  if (!node || typeof node !== "object" || Array.isArray(node)) return false;
23956
- return "cachedStatus" in node || "lastGit" in node || "last_git" in node || "lastProbe" in node || "last_probe" in node || "error" in node || "health" in node || "machineStatus" in node || "lastSeenAt" in node || "last_seen_at" in node || "updatedAt" in node || "updated_at" in node || "activeSession" in node || "active_session" in node || "activeSessionId" in node || "active_session_id" in node || "sessionId" in node || "session_id" in node || "providerType" in node || "provider_type" in node || "providers" in node;
23984
+ return "cachedStatus" in node || "lastGit" in node || "last_git" in node || "lastProbe" in node || "last_probe" in node || "error" in node || "health" in node || "machineStatus" in node || "lastSeenAt" in node || "last_seen_at" in node || "updatedAt" in node || "updated_at" in node || "activeSession" in node || "active_session" in node || "activeSessionId" in node || "active_session_id" in node || "sessionId" in node || "session_id" in node || "providerType" in node || "provider_type" in node;
23957
23985
  }
23958
23986
  function readInlineMeshNodeId(node) {
23959
23987
  return readStringValue(node?.id, node?.nodeId) || "";
@@ -24079,6 +24107,109 @@ function toIsoTimestamp(value) {
24079
24107
  const stringValue = readStringValue(value);
24080
24108
  return stringValue || null;
24081
24109
  }
24110
+ function synthesizeMeshNodeFreshnessFromConnection(status) {
24111
+ const connection = readObjectRecord(status.connection);
24112
+ const connectionFreshAt = toIsoTimestamp(connection.lastCommandAt ?? connection.lastConnectedAt ?? connection.lastStateChangeAt);
24113
+ const git = readObjectRecord(status.git);
24114
+ const gitCheckedAt = toIsoTimestamp(git.lastCheckedAt);
24115
+ if (!status.lastSeenAt && connectionFreshAt) status.lastSeenAt = connectionFreshAt;
24116
+ if (!status.updatedAt && (gitCheckedAt || connectionFreshAt)) {
24117
+ status.updatedAt = gitCheckedAt ?? connectionFreshAt;
24118
+ }
24119
+ }
24120
+ function finalizeMeshNodeStatus(args) {
24121
+ const { status, node, daemonId, isSelfNode } = args;
24122
+ if (!readStringValue(status.machineStatus)) {
24123
+ const cachedStatus = readObjectRecord(node?.cachedStatus);
24124
+ const machineStatus = readStringValue(cachedStatus.machineStatus, cachedStatus.machine_status, node?.machineStatus);
24125
+ if (machineStatus) status.machineStatus = machineStatus;
24126
+ }
24127
+ synthesizeMeshNodeFreshnessFromConnection(status);
24128
+ const connectionState = readStringValue(readObjectRecord(status.connection).state);
24129
+ status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || connectionState === "connected" || isSelfNode);
24130
+ }
24131
+ async function probeRemoteMeshGitStatus(args) {
24132
+ if (!args.dispatchMeshCommand) return null;
24133
+ const remoteResult = await Promise.race([
24134
+ args.dispatchMeshCommand(args.daemonId, "git_status", { workspace: args.workspace }),
24135
+ new Promise((_, reject) => setTimeout(() => reject(new Error("timeout")), args.timeoutMs))
24136
+ ]);
24137
+ const remoteGit = remoteResult?.status ?? remoteResult?.git ?? remoteResult;
24138
+ return remoteGit && typeof remoteGit === "object" && typeof remoteGit.isGitRepo === "boolean" ? remoteGit : null;
24139
+ }
24140
+ async function hydrateInlineMeshDirectTruth(args) {
24141
+ const nodes = Array.isArray(args.mesh?.nodes) ? args.mesh.nodes : [];
24142
+ if (!nodes.length) {
24143
+ return {
24144
+ directEvidenceCount: 0,
24145
+ localConfirmedCount: 0,
24146
+ peerAttemptedCount: 0,
24147
+ peerConfirmedCount: 0,
24148
+ unavailableNodeIds: []
24149
+ };
24150
+ }
24151
+ const selectedCoordinatorNodeId = readStringValue(
24152
+ args.mesh?.coordinator?.preferredNodeId,
24153
+ nodes[0]?.id,
24154
+ nodes[0]?.nodeId
24155
+ );
24156
+ let localConfirmedCount = 0;
24157
+ let peerAttemptedCount = 0;
24158
+ let peerConfirmedCount = 0;
24159
+ const unavailableNodeIds = [];
24160
+ for (const [nodeIndex, node] of nodes.entries()) {
24161
+ const nodeId = readStringValue(node?.id, node?.nodeId) || `node_${nodeIndex}`;
24162
+ const workspace = readStringValue(node?.workspace);
24163
+ const daemonId = readStringValue(node?.daemonId);
24164
+ const isSelfNode = Boolean(
24165
+ nodeId && selectedCoordinatorNodeId && nodeId === selectedCoordinatorNodeId
24166
+ ) || Boolean(
24167
+ daemonId && (daemonId === args.localMachineId || daemonId === args.statusInstanceId)
24168
+ ) || Boolean(args.meshSource !== "local_config" && nodeIndex === 0);
24169
+ if (!workspace) {
24170
+ if (!isSelfNode && daemonId) unavailableNodeIds.push(nodeId);
24171
+ continue;
24172
+ }
24173
+ if (isSelfNode && fs10.existsSync(workspace)) {
24174
+ try {
24175
+ const localGit = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
24176
+ if (localGit?.isGitRepo) {
24177
+ recordInlineMeshDirectGitTruth(node, localGit, "selected_coordinator_local_git");
24178
+ localConfirmedCount += 1;
24179
+ continue;
24180
+ }
24181
+ } catch {
24182
+ }
24183
+ }
24184
+ if (!daemonId || !args.dispatchMeshCommand) {
24185
+ if (!isSelfNode) unavailableNodeIds.push(nodeId);
24186
+ continue;
24187
+ }
24188
+ peerAttemptedCount += 1;
24189
+ try {
24190
+ const remoteGit = await probeRemoteMeshGitStatus({
24191
+ dispatchMeshCommand: args.dispatchMeshCommand,
24192
+ daemonId,
24193
+ workspace,
24194
+ timeoutMs: 8e3
24195
+ });
24196
+ if (remoteGit) {
24197
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
24198
+ peerConfirmedCount += 1;
24199
+ continue;
24200
+ }
24201
+ } catch {
24202
+ }
24203
+ unavailableNodeIds.push(nodeId);
24204
+ }
24205
+ return {
24206
+ directEvidenceCount: localConfirmedCount + peerConfirmedCount,
24207
+ localConfirmedCount,
24208
+ peerAttemptedCount,
24209
+ peerConfirmedCount,
24210
+ unavailableNodeIds
24211
+ };
24212
+ }
24082
24213
  function summarizeMeshSessionRecord(record) {
24083
24214
  return {
24084
24215
  sessionId: readStringValue(record?.sessionId) || "unknown",
@@ -25590,8 +25721,38 @@ var DaemonCommandRouter = class {
25590
25721
  const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
25591
25722
  if (!meshId) return { success: false, error: "meshId required" };
25592
25723
  const meshRecord = await this.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
25593
- if (meshRecord?.mesh) return { success: true, mesh: meshRecord.mesh };
25594
- return { success: false, error: "Mesh not found" };
25724
+ if (!meshRecord?.mesh) return { success: false, error: "Mesh not found" };
25725
+ const requireDirectPeerTruth = args?.requireDirectPeerTruth === true;
25726
+ const directTruth = await hydrateInlineMeshDirectTruth({
25727
+ mesh: meshRecord.mesh,
25728
+ meshSource: meshRecord.source,
25729
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
25730
+ statusInstanceId: this.deps.statusInstanceId,
25731
+ localMachineId: loadConfig().machineId || ""
25732
+ });
25733
+ const directTruthSatisfied = meshRecord.source !== "inline_bootstrap" || directTruth.directEvidenceCount > 0;
25734
+ const sourceOfTruth = {
25735
+ membership: meshRecord.source === "inline_cache" ? "coordinator_inline_mesh_cache" : meshRecord.source === "local_config" ? "local_mesh_config" : "inline_bootstrap_snapshot",
25736
+ coordinatorOwnsLiveTruth: directTruthSatisfied,
25737
+ directPeerTruth: {
25738
+ required: requireDirectPeerTruth,
25739
+ satisfied: directTruthSatisfied,
25740
+ directEvidenceCount: directTruth.directEvidenceCount,
25741
+ localConfirmedCount: directTruth.localConfirmedCount,
25742
+ peerAttemptedCount: directTruth.peerAttemptedCount,
25743
+ peerConfirmedCount: directTruth.peerConfirmedCount,
25744
+ unavailableNodeIds: directTruth.unavailableNodeIds
25745
+ }
25746
+ };
25747
+ if (requireDirectPeerTruth && !directTruthSatisfied) {
25748
+ return {
25749
+ success: false,
25750
+ code: "mesh_direct_peer_truth_unavailable",
25751
+ error: "Selected coordinator could not confirm direct mesh truth yet. Bootstrap inventory stays unavailable until direct get_mesh probes succeed.",
25752
+ sourceOfTruth
25753
+ };
25754
+ }
25755
+ return { success: true, mesh: meshRecord.mesh, sourceOfTruth };
25595
25756
  }
25596
25757
  case "create_mesh": {
25597
25758
  const name = typeof args?.name === "string" ? args.name.trim() : "";
@@ -26519,25 +26680,51 @@ ${block}`);
26519
26680
  }
26520
26681
  if (workspace) {
26521
26682
  if (!fs10.existsSync(workspace)) {
26683
+ const inlineTransitGit = buildInlineMeshTransitGitStatus(node);
26522
26684
  let remoteProbeApplied = false;
26523
- if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand) {
26685
+ if (inlineTransitGit) {
26686
+ status.git = inlineTransitGit;
26687
+ status.health = inlineTransitGit.isGitRepo ? deriveMeshNodeHealthFromGit(inlineTransitGit) : "degraded";
26688
+ remoteProbeApplied = true;
26689
+ } else if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand) {
26524
26690
  try {
26525
- const remoteResult = await Promise.race([
26526
- this.deps.dispatchMeshCommand(daemonId, "git_status", { workspace }),
26527
- new Promise((_, reject) => setTimeout(() => reject(new Error("timeout")), 8e3))
26528
- ]);
26529
- const remoteGit = remoteResult?.status ?? remoteResult?.git ?? remoteResult;
26530
- if (remoteGit && typeof remoteGit === "object" && typeof remoteGit.isGitRepo === "boolean") {
26691
+ const remoteGit = await probeRemoteMeshGitStatus({
26692
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
26693
+ daemonId,
26694
+ workspace,
26695
+ timeoutMs: 8e3
26696
+ });
26697
+ if (remoteGit) {
26531
26698
  status.git = remoteGit;
26532
26699
  status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
26700
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
26533
26701
  remoteProbeApplied = true;
26534
26702
  }
26535
26703
  } catch {
26704
+ const refreshedConnection = this.deps.getMeshPeerConnectionStatus?.(daemonId);
26705
+ const refreshedConnectionState = readStringValue(refreshedConnection?.state);
26706
+ if (refreshedConnection && refreshedConnectionState === "connected") {
26707
+ status.connection = refreshedConnection;
26708
+ try {
26709
+ const remoteGit = await probeRemoteMeshGitStatus({
26710
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
26711
+ daemonId,
26712
+ workspace,
26713
+ timeoutMs: 12e3
26714
+ });
26715
+ if (remoteGit) {
26716
+ status.git = remoteGit;
26717
+ status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
26718
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
26719
+ remoteProbeApplied = true;
26720
+ }
26721
+ } catch {
26722
+ }
26723
+ }
26536
26724
  }
26537
26725
  }
26538
26726
  if (!remoteProbeApplied) {
26539
26727
  const connectionState = readStringValue(status.connection?.state);
26540
- const inlineTransitGit = buildInlineMeshTransitGitStatus(node);
26541
26728
  const pendingPeerGitProbe = !inlineTransitGit && !isSelfNode && !!daemonId && (readStringValue(status.machineStatus) === "online" || readStringValue(status.health) === "online" || connectionState === "connecting" || connectionState === "connected" || connectionState === "unknown");
26542
26729
  if (pendingPeerGitProbe) {
26543
26730
  status.gitProbePending = true;
@@ -26548,12 +26735,12 @@ ${block}`);
26548
26735
  node,
26549
26736
  pendingPeerGitProbe ? { skipGit: true, skipError: true, skipHealth: true } : void 0
26550
26737
  )) {
26551
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
26738
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
26552
26739
  nodeStatuses.push(status);
26553
26740
  continue;
26554
26741
  }
26555
26742
  if (meshRecord?.source === "inline_cache" && !isSelfNode) {
26556
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
26743
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
26557
26744
  nodeStatuses.push(status);
26558
26745
  continue;
26559
26746
  }
@@ -26562,6 +26749,7 @@ ${block}`);
26562
26749
  try {
26563
26750
  const gitStatus = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
26564
26751
  status.git = gitStatus;
26752
+ recordInlineMeshDirectGitTruth(node, gitStatus, "selected_coordinator_local_git");
26565
26753
  if (gitStatus.isGitRepo) {
26566
26754
  status.health = deriveMeshNodeHealthFromGit(gitStatus);
26567
26755
  } else {
@@ -26577,7 +26765,7 @@ ${block}`);
26577
26765
  } else {
26578
26766
  applyCachedInlineMeshNodeStatus(status, node);
26579
26767
  }
26580
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
26768
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
26581
26769
  nodeStatuses.push(status);
26582
26770
  }
26583
26771
  return {