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

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,12 @@ 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;
23985
+ }
23986
+ function inlineMeshCarriesTransientNodeTruth(inlineMesh) {
23987
+ if (!inlineMesh || typeof inlineMesh !== "object" || Array.isArray(inlineMesh)) return false;
23988
+ if (!Array.isArray(inlineMesh.nodes) || inlineMesh.nodes.length === 0) return false;
23989
+ return inlineMesh.nodes.some((node) => hasInlineMeshTransientNodeState(node));
23957
23990
  }
23958
23991
  function readInlineMeshNodeId(node) {
23959
23992
  return readStringValue(node?.id, node?.nodeId) || "";
@@ -24079,6 +24112,109 @@ function toIsoTimestamp(value) {
24079
24112
  const stringValue = readStringValue(value);
24080
24113
  return stringValue || null;
24081
24114
  }
24115
+ function synthesizeMeshNodeFreshnessFromConnection(status) {
24116
+ const connection = readObjectRecord(status.connection);
24117
+ const connectionFreshAt = toIsoTimestamp(connection.lastCommandAt ?? connection.lastConnectedAt ?? connection.lastStateChangeAt);
24118
+ const git = readObjectRecord(status.git);
24119
+ const gitCheckedAt = toIsoTimestamp(git.lastCheckedAt);
24120
+ if (!status.lastSeenAt && connectionFreshAt) status.lastSeenAt = connectionFreshAt;
24121
+ if (!status.updatedAt && (gitCheckedAt || connectionFreshAt)) {
24122
+ status.updatedAt = gitCheckedAt ?? connectionFreshAt;
24123
+ }
24124
+ }
24125
+ function finalizeMeshNodeStatus(args) {
24126
+ const { status, node, daemonId, isSelfNode } = args;
24127
+ if (!readStringValue(status.machineStatus)) {
24128
+ const cachedStatus = readObjectRecord(node?.cachedStatus);
24129
+ const machineStatus = readStringValue(cachedStatus.machineStatus, cachedStatus.machine_status, node?.machineStatus);
24130
+ if (machineStatus) status.machineStatus = machineStatus;
24131
+ }
24132
+ synthesizeMeshNodeFreshnessFromConnection(status);
24133
+ const connectionState = readStringValue(readObjectRecord(status.connection).state);
24134
+ status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || connectionState === "connected" || isSelfNode);
24135
+ }
24136
+ async function probeRemoteMeshGitStatus(args) {
24137
+ if (!args.dispatchMeshCommand) return null;
24138
+ const remoteResult = await Promise.race([
24139
+ args.dispatchMeshCommand(args.daemonId, "git_status", { workspace: args.workspace }),
24140
+ new Promise((_, reject) => setTimeout(() => reject(new Error("timeout")), args.timeoutMs))
24141
+ ]);
24142
+ const remoteGit = remoteResult?.status ?? remoteResult?.git ?? remoteResult;
24143
+ return remoteGit && typeof remoteGit === "object" && typeof remoteGit.isGitRepo === "boolean" ? remoteGit : null;
24144
+ }
24145
+ async function hydrateInlineMeshDirectTruth(args) {
24146
+ const nodes = Array.isArray(args.mesh?.nodes) ? args.mesh.nodes : [];
24147
+ if (!nodes.length) {
24148
+ return {
24149
+ directEvidenceCount: 0,
24150
+ localConfirmedCount: 0,
24151
+ peerAttemptedCount: 0,
24152
+ peerConfirmedCount: 0,
24153
+ unavailableNodeIds: []
24154
+ };
24155
+ }
24156
+ const selectedCoordinatorNodeId = readStringValue(
24157
+ args.mesh?.coordinator?.preferredNodeId,
24158
+ nodes[0]?.id,
24159
+ nodes[0]?.nodeId
24160
+ );
24161
+ let localConfirmedCount = 0;
24162
+ let peerAttemptedCount = 0;
24163
+ let peerConfirmedCount = 0;
24164
+ const unavailableNodeIds = [];
24165
+ for (const [nodeIndex, node] of nodes.entries()) {
24166
+ const nodeId = readStringValue(node?.id, node?.nodeId) || `node_${nodeIndex}`;
24167
+ const workspace = readStringValue(node?.workspace);
24168
+ const daemonId = readStringValue(node?.daemonId);
24169
+ const isSelfNode = Boolean(
24170
+ nodeId && selectedCoordinatorNodeId && nodeId === selectedCoordinatorNodeId
24171
+ ) || Boolean(
24172
+ daemonId && (daemonId === args.localMachineId || daemonId === args.statusInstanceId)
24173
+ ) || Boolean(args.meshSource !== "local_config" && nodeIndex === 0);
24174
+ if (!workspace) {
24175
+ if (!isSelfNode && daemonId) unavailableNodeIds.push(nodeId);
24176
+ continue;
24177
+ }
24178
+ if (isSelfNode && fs10.existsSync(workspace)) {
24179
+ try {
24180
+ const localGit = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
24181
+ if (localGit?.isGitRepo) {
24182
+ recordInlineMeshDirectGitTruth(node, localGit, "selected_coordinator_local_git");
24183
+ localConfirmedCount += 1;
24184
+ continue;
24185
+ }
24186
+ } catch {
24187
+ }
24188
+ }
24189
+ if (!daemonId || !args.dispatchMeshCommand) {
24190
+ if (!isSelfNode) unavailableNodeIds.push(nodeId);
24191
+ continue;
24192
+ }
24193
+ peerAttemptedCount += 1;
24194
+ try {
24195
+ const remoteGit = await probeRemoteMeshGitStatus({
24196
+ dispatchMeshCommand: args.dispatchMeshCommand,
24197
+ daemonId,
24198
+ workspace,
24199
+ timeoutMs: 8e3
24200
+ });
24201
+ if (remoteGit) {
24202
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
24203
+ peerConfirmedCount += 1;
24204
+ continue;
24205
+ }
24206
+ } catch {
24207
+ }
24208
+ unavailableNodeIds.push(nodeId);
24209
+ }
24210
+ return {
24211
+ directEvidenceCount: localConfirmedCount + peerConfirmedCount,
24212
+ localConfirmedCount,
24213
+ peerAttemptedCount,
24214
+ peerConfirmedCount,
24215
+ unavailableNodeIds
24216
+ };
24217
+ }
24082
24218
  function summarizeMeshSessionRecord(record) {
24083
24219
  return {
24084
24220
  sessionId: readStringValue(record?.sessionId) || "unknown",
@@ -24581,8 +24717,10 @@ var DaemonCommandRouter = class {
24581
24717
  if (preferInline) {
24582
24718
  const cached2 = this.getCachedInlineMesh(meshId);
24583
24719
  if (cached2) return { mesh: cached2, inline: true, source: "inline_cache" };
24584
- const warmedInline2 = this.warmInlineMeshCache(meshId, inlineMesh);
24585
- if (warmedInline2) return { mesh: warmedInline2, inline: true, source: "inline_bootstrap" };
24720
+ if (inlineMeshCarriesTransientNodeTruth(inlineMesh)) {
24721
+ this.warmInlineMeshCache(meshId, inlineMesh);
24722
+ return { mesh: inlineMesh, inline: true, source: "inline_bootstrap" };
24723
+ }
24586
24724
  }
24587
24725
  try {
24588
24726
  const { getMesh: getMesh3 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
@@ -25590,8 +25728,38 @@ var DaemonCommandRouter = class {
25590
25728
  const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
25591
25729
  if (!meshId) return { success: false, error: "meshId required" };
25592
25730
  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" };
25731
+ if (!meshRecord?.mesh) return { success: false, error: "Mesh not found" };
25732
+ const requireDirectPeerTruth = args?.requireDirectPeerTruth === true;
25733
+ const directTruth = await hydrateInlineMeshDirectTruth({
25734
+ mesh: meshRecord.mesh,
25735
+ meshSource: meshRecord.source,
25736
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
25737
+ statusInstanceId: this.deps.statusInstanceId,
25738
+ localMachineId: loadConfig().machineId || ""
25739
+ });
25740
+ const directTruthSatisfied = meshRecord.source !== "inline_bootstrap" || directTruth.directEvidenceCount > 0;
25741
+ const sourceOfTruth = {
25742
+ membership: meshRecord.source === "inline_cache" ? "coordinator_inline_mesh_cache" : meshRecord.source === "local_config" ? "local_mesh_config" : "inline_bootstrap_snapshot",
25743
+ coordinatorOwnsLiveTruth: directTruthSatisfied,
25744
+ directPeerTruth: {
25745
+ required: requireDirectPeerTruth,
25746
+ satisfied: directTruthSatisfied,
25747
+ directEvidenceCount: directTruth.directEvidenceCount,
25748
+ localConfirmedCount: directTruth.localConfirmedCount,
25749
+ peerAttemptedCount: directTruth.peerAttemptedCount,
25750
+ peerConfirmedCount: directTruth.peerConfirmedCount,
25751
+ unavailableNodeIds: directTruth.unavailableNodeIds
25752
+ }
25753
+ };
25754
+ if (requireDirectPeerTruth && !directTruthSatisfied) {
25755
+ return {
25756
+ success: false,
25757
+ code: "mesh_direct_peer_truth_unavailable",
25758
+ error: "Selected coordinator could not confirm direct mesh truth yet. Bootstrap inventory stays unavailable until direct get_mesh probes succeed.",
25759
+ sourceOfTruth
25760
+ };
25761
+ }
25762
+ return { success: true, mesh: meshRecord.mesh, sourceOfTruth };
25595
25763
  }
25596
25764
  case "create_mesh": {
25597
25765
  const name = typeof args?.name === "string" ? args.name.trim() : "";
@@ -26519,25 +26687,51 @@ ${block}`);
26519
26687
  }
26520
26688
  if (workspace) {
26521
26689
  if (!fs10.existsSync(workspace)) {
26690
+ const inlineTransitGit = buildInlineMeshTransitGitStatus(node);
26522
26691
  let remoteProbeApplied = false;
26523
- if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand) {
26692
+ if (inlineTransitGit) {
26693
+ status.git = inlineTransitGit;
26694
+ status.health = inlineTransitGit.isGitRepo ? deriveMeshNodeHealthFromGit(inlineTransitGit) : "degraded";
26695
+ remoteProbeApplied = true;
26696
+ } else if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand) {
26524
26697
  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") {
26698
+ const remoteGit = await probeRemoteMeshGitStatus({
26699
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
26700
+ daemonId,
26701
+ workspace,
26702
+ timeoutMs: 8e3
26703
+ });
26704
+ if (remoteGit) {
26531
26705
  status.git = remoteGit;
26532
26706
  status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
26707
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
26533
26708
  remoteProbeApplied = true;
26534
26709
  }
26535
26710
  } catch {
26711
+ const refreshedConnection = this.deps.getMeshPeerConnectionStatus?.(daemonId);
26712
+ const refreshedConnectionState = readStringValue(refreshedConnection?.state);
26713
+ if (refreshedConnection && refreshedConnectionState === "connected") {
26714
+ status.connection = refreshedConnection;
26715
+ try {
26716
+ const remoteGit = await probeRemoteMeshGitStatus({
26717
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
26718
+ daemonId,
26719
+ workspace,
26720
+ timeoutMs: 12e3
26721
+ });
26722
+ if (remoteGit) {
26723
+ status.git = remoteGit;
26724
+ status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
26725
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
26726
+ remoteProbeApplied = true;
26727
+ }
26728
+ } catch {
26729
+ }
26730
+ }
26536
26731
  }
26537
26732
  }
26538
26733
  if (!remoteProbeApplied) {
26539
26734
  const connectionState = readStringValue(status.connection?.state);
26540
- const inlineTransitGit = buildInlineMeshTransitGitStatus(node);
26541
26735
  const pendingPeerGitProbe = !inlineTransitGit && !isSelfNode && !!daemonId && (readStringValue(status.machineStatus) === "online" || readStringValue(status.health) === "online" || connectionState === "connecting" || connectionState === "connected" || connectionState === "unknown");
26542
26736
  if (pendingPeerGitProbe) {
26543
26737
  status.gitProbePending = true;
@@ -26548,12 +26742,12 @@ ${block}`);
26548
26742
  node,
26549
26743
  pendingPeerGitProbe ? { skipGit: true, skipError: true, skipHealth: true } : void 0
26550
26744
  )) {
26551
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
26745
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
26552
26746
  nodeStatuses.push(status);
26553
26747
  continue;
26554
26748
  }
26555
26749
  if (meshRecord?.source === "inline_cache" && !isSelfNode) {
26556
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
26750
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
26557
26751
  nodeStatuses.push(status);
26558
26752
  continue;
26559
26753
  }
@@ -26562,6 +26756,7 @@ ${block}`);
26562
26756
  try {
26563
26757
  const gitStatus = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
26564
26758
  status.git = gitStatus;
26759
+ recordInlineMeshDirectGitTruth(node, gitStatus, "selected_coordinator_local_git");
26565
26760
  if (gitStatus.isGitRepo) {
26566
26761
  status.health = deriveMeshNodeHealthFromGit(gitStatus);
26567
26762
  } else {
@@ -26577,7 +26772,7 @@ ${block}`);
26577
26772
  } else {
26578
26773
  applyCachedInlineMeshNodeStatus(status, node);
26579
26774
  }
26580
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
26775
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
26581
26776
  nodeStatuses.push(status);
26582
26777
  }
26583
26778
  return {