@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.js CHANGED
@@ -24072,13 +24072,21 @@ function readBooleanValue(...values) {
24072
24072
  }
24073
24073
  return void 0;
24074
24074
  }
24075
- function readGitSubmodules(value) {
24075
+ function joinRepoPath(root, relativePath) {
24076
+ const normalizedRoot = typeof root === "string" ? root.trim().replace(/[\\/]+$/, "") : "";
24077
+ const normalizedPath = typeof relativePath === "string" ? relativePath.trim() : "";
24078
+ if (!normalizedPath) return void 0;
24079
+ if (/^(?:[A-Za-z]:[\\/]|\/)/.test(normalizedPath)) return normalizedPath;
24080
+ if (!normalizedRoot) return void 0;
24081
+ return `${normalizedRoot}/${normalizedPath.replace(/^[\\/]+/, "")}`;
24082
+ }
24083
+ function readGitSubmodules(value, parentRepoRoot) {
24076
24084
  if (!Array.isArray(value)) return void 0;
24077
24085
  const submodules = value.map((entry) => {
24078
24086
  const submodule = readObjectRecord(entry);
24079
24087
  const path28 = readStringValue(submodule.path);
24080
24088
  const commit = readStringValue(submodule.commit);
24081
- const repoPath = readStringValue(submodule.repoPath, submodule.repo_root);
24089
+ const repoPath = readStringValue(submodule.repoPath, submodule.repo_root) ?? joinRepoPath(parentRepoRoot, path28);
24082
24090
  if (!path28 || !commit || !repoPath) return null;
24083
24091
  return {
24084
24092
  path: path28,
@@ -24098,10 +24106,11 @@ function normalizeInlineMeshGitStatus(status, node, options) {
24098
24106
  const conflictFiles = Array.isArray(status.conflictFiles) ? status.conflictFiles.filter((value) => typeof value === "string") : [];
24099
24107
  const conflictCount = readNumberValue(status.conflicts) ?? conflictFiles.length;
24100
24108
  const hasConflicts = readBooleanValue(status.hasConflicts) ?? conflictCount > 0;
24101
- const submodules = readGitSubmodules(status.submodules);
24109
+ const repoRoot = readStringValue(status.repoRoot, status.repo_root, node?.repoRoot, node?.repo_root, status.workspace, node?.workspace) || void 0;
24110
+ const submodules = readGitSubmodules(status.submodules, repoRoot);
24102
24111
  return {
24103
24112
  workspace: readStringValue(status.workspace, node?.workspace) || "",
24104
- repoRoot: readStringValue(status.repoRoot, node?.repoRoot, node?.workspace) || null,
24113
+ repoRoot: repoRoot ?? null,
24105
24114
  isGitRepo,
24106
24115
  branch: readStringValue(status.branch) ?? null,
24107
24116
  headCommit: readStringValue(status.headCommit) ?? null,
@@ -24134,6 +24143,26 @@ function buildInlineMeshTransitGitStatus(node) {
24134
24143
  const status = Object.keys(directStatus).length ? directStatus : Object.keys(nestedStatus).length ? nestedStatus : Object.keys(probeDirectStatus).length ? probeDirectStatus : Object.keys(probeNestedStatus).length ? probeNestedStatus : {};
24135
24144
  return normalizeInlineMeshGitStatus(status, node, { lastCheckedAt: Date.now() });
24136
24145
  }
24146
+ function recordInlineMeshDirectGitTruth(node, git, source) {
24147
+ if (!node || typeof node !== "object" || Array.isArray(node)) return;
24148
+ const checkedAt = readNumberValue(git.lastCheckedAt) ?? Date.now();
24149
+ const updatedAt = new Date(checkedAt).toISOString();
24150
+ const nextGit = {
24151
+ ...git,
24152
+ lastCheckedAt: checkedAt
24153
+ };
24154
+ node.lastGit = {
24155
+ source,
24156
+ checkedAt,
24157
+ status: nextGit
24158
+ };
24159
+ node.last_git = node.lastGit;
24160
+ node.machineStatus = "online";
24161
+ node.updatedAt = updatedAt;
24162
+ node.lastSeenAt = updatedAt;
24163
+ const repoRoot = readStringValue(nextGit.repoRoot);
24164
+ if (repoRoot && !readStringValue(node.repoRoot)) node.repoRoot = repoRoot;
24165
+ }
24137
24166
  function buildCachedInlineMeshGitStatus(node) {
24138
24167
  const liveGit = buildInlineMeshTransitGitStatus(node);
24139
24168
  if (liveGit) return liveGit;
@@ -24176,7 +24205,6 @@ function stripInlineMeshTransientNodeState(node) {
24176
24205
  session_id: _sessionIdLegacy,
24177
24206
  providerType: _providerType,
24178
24207
  provider_type: _providerTypeLegacy,
24179
- providers: _providers,
24180
24208
  ...rest
24181
24209
  } = node;
24182
24210
  if (cachedStatus && !shouldDiscardCachedInlineMeshStatus(node)) {
@@ -24186,7 +24214,12 @@ function stripInlineMeshTransientNodeState(node) {
24186
24214
  }
24187
24215
  function hasInlineMeshTransientNodeState(node) {
24188
24216
  if (!node || typeof node !== "object" || Array.isArray(node)) return false;
24189
- 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;
24217
+ 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;
24218
+ }
24219
+ function inlineMeshCarriesTransientNodeTruth(inlineMesh) {
24220
+ if (!inlineMesh || typeof inlineMesh !== "object" || Array.isArray(inlineMesh)) return false;
24221
+ if (!Array.isArray(inlineMesh.nodes) || inlineMesh.nodes.length === 0) return false;
24222
+ return inlineMesh.nodes.some((node) => hasInlineMeshTransientNodeState(node));
24190
24223
  }
24191
24224
  function readInlineMeshNodeId(node) {
24192
24225
  return readStringValue(node?.id, node?.nodeId) || "";
@@ -24312,6 +24345,109 @@ function toIsoTimestamp(value) {
24312
24345
  const stringValue = readStringValue(value);
24313
24346
  return stringValue || null;
24314
24347
  }
24348
+ function synthesizeMeshNodeFreshnessFromConnection(status) {
24349
+ const connection = readObjectRecord(status.connection);
24350
+ const connectionFreshAt = toIsoTimestamp(connection.lastCommandAt ?? connection.lastConnectedAt ?? connection.lastStateChangeAt);
24351
+ const git = readObjectRecord(status.git);
24352
+ const gitCheckedAt = toIsoTimestamp(git.lastCheckedAt);
24353
+ if (!status.lastSeenAt && connectionFreshAt) status.lastSeenAt = connectionFreshAt;
24354
+ if (!status.updatedAt && (gitCheckedAt || connectionFreshAt)) {
24355
+ status.updatedAt = gitCheckedAt ?? connectionFreshAt;
24356
+ }
24357
+ }
24358
+ function finalizeMeshNodeStatus(args) {
24359
+ const { status, node, daemonId, isSelfNode } = args;
24360
+ if (!readStringValue(status.machineStatus)) {
24361
+ const cachedStatus = readObjectRecord(node?.cachedStatus);
24362
+ const machineStatus = readStringValue(cachedStatus.machineStatus, cachedStatus.machine_status, node?.machineStatus);
24363
+ if (machineStatus) status.machineStatus = machineStatus;
24364
+ }
24365
+ synthesizeMeshNodeFreshnessFromConnection(status);
24366
+ const connectionState = readStringValue(readObjectRecord(status.connection).state);
24367
+ status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || connectionState === "connected" || isSelfNode);
24368
+ }
24369
+ async function probeRemoteMeshGitStatus(args) {
24370
+ if (!args.dispatchMeshCommand) return null;
24371
+ const remoteResult = await Promise.race([
24372
+ args.dispatchMeshCommand(args.daemonId, "git_status", { workspace: args.workspace }),
24373
+ new Promise((_, reject) => setTimeout(() => reject(new Error("timeout")), args.timeoutMs))
24374
+ ]);
24375
+ const remoteGit = remoteResult?.status ?? remoteResult?.git ?? remoteResult;
24376
+ return remoteGit && typeof remoteGit === "object" && typeof remoteGit.isGitRepo === "boolean" ? remoteGit : null;
24377
+ }
24378
+ async function hydrateInlineMeshDirectTruth(args) {
24379
+ const nodes = Array.isArray(args.mesh?.nodes) ? args.mesh.nodes : [];
24380
+ if (!nodes.length) {
24381
+ return {
24382
+ directEvidenceCount: 0,
24383
+ localConfirmedCount: 0,
24384
+ peerAttemptedCount: 0,
24385
+ peerConfirmedCount: 0,
24386
+ unavailableNodeIds: []
24387
+ };
24388
+ }
24389
+ const selectedCoordinatorNodeId = readStringValue(
24390
+ args.mesh?.coordinator?.preferredNodeId,
24391
+ nodes[0]?.id,
24392
+ nodes[0]?.nodeId
24393
+ );
24394
+ let localConfirmedCount = 0;
24395
+ let peerAttemptedCount = 0;
24396
+ let peerConfirmedCount = 0;
24397
+ const unavailableNodeIds = [];
24398
+ for (const [nodeIndex, node] of nodes.entries()) {
24399
+ const nodeId = readStringValue(node?.id, node?.nodeId) || `node_${nodeIndex}`;
24400
+ const workspace = readStringValue(node?.workspace);
24401
+ const daemonId = readStringValue(node?.daemonId);
24402
+ const isSelfNode = Boolean(
24403
+ nodeId && selectedCoordinatorNodeId && nodeId === selectedCoordinatorNodeId
24404
+ ) || Boolean(
24405
+ daemonId && (daemonId === args.localMachineId || daemonId === args.statusInstanceId)
24406
+ ) || Boolean(args.meshSource !== "local_config" && nodeIndex === 0);
24407
+ if (!workspace) {
24408
+ if (!isSelfNode && daemonId) unavailableNodeIds.push(nodeId);
24409
+ continue;
24410
+ }
24411
+ if (isSelfNode && fs10.existsSync(workspace)) {
24412
+ try {
24413
+ const localGit = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
24414
+ if (localGit?.isGitRepo) {
24415
+ recordInlineMeshDirectGitTruth(node, localGit, "selected_coordinator_local_git");
24416
+ localConfirmedCount += 1;
24417
+ continue;
24418
+ }
24419
+ } catch {
24420
+ }
24421
+ }
24422
+ if (!daemonId || !args.dispatchMeshCommand) {
24423
+ if (!isSelfNode) unavailableNodeIds.push(nodeId);
24424
+ continue;
24425
+ }
24426
+ peerAttemptedCount += 1;
24427
+ try {
24428
+ const remoteGit = await probeRemoteMeshGitStatus({
24429
+ dispatchMeshCommand: args.dispatchMeshCommand,
24430
+ daemonId,
24431
+ workspace,
24432
+ timeoutMs: 8e3
24433
+ });
24434
+ if (remoteGit) {
24435
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
24436
+ peerConfirmedCount += 1;
24437
+ continue;
24438
+ }
24439
+ } catch {
24440
+ }
24441
+ unavailableNodeIds.push(nodeId);
24442
+ }
24443
+ return {
24444
+ directEvidenceCount: localConfirmedCount + peerConfirmedCount,
24445
+ localConfirmedCount,
24446
+ peerAttemptedCount,
24447
+ peerConfirmedCount,
24448
+ unavailableNodeIds
24449
+ };
24450
+ }
24315
24451
  function summarizeMeshSessionRecord(record) {
24316
24452
  return {
24317
24453
  sessionId: readStringValue(record?.sessionId) || "unknown",
@@ -24814,8 +24950,10 @@ var DaemonCommandRouter = class {
24814
24950
  if (preferInline) {
24815
24951
  const cached2 = this.getCachedInlineMesh(meshId);
24816
24952
  if (cached2) return { mesh: cached2, inline: true, source: "inline_cache" };
24817
- const warmedInline2 = this.warmInlineMeshCache(meshId, inlineMesh);
24818
- if (warmedInline2) return { mesh: warmedInline2, inline: true, source: "inline_bootstrap" };
24953
+ if (inlineMeshCarriesTransientNodeTruth(inlineMesh)) {
24954
+ this.warmInlineMeshCache(meshId, inlineMesh);
24955
+ return { mesh: inlineMesh, inline: true, source: "inline_bootstrap" };
24956
+ }
24819
24957
  }
24820
24958
  try {
24821
24959
  const { getMesh: getMesh3 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
@@ -25823,8 +25961,38 @@ var DaemonCommandRouter = class {
25823
25961
  const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
25824
25962
  if (!meshId) return { success: false, error: "meshId required" };
25825
25963
  const meshRecord = await this.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
25826
- if (meshRecord?.mesh) return { success: true, mesh: meshRecord.mesh };
25827
- return { success: false, error: "Mesh not found" };
25964
+ if (!meshRecord?.mesh) return { success: false, error: "Mesh not found" };
25965
+ const requireDirectPeerTruth = args?.requireDirectPeerTruth === true;
25966
+ const directTruth = await hydrateInlineMeshDirectTruth({
25967
+ mesh: meshRecord.mesh,
25968
+ meshSource: meshRecord.source,
25969
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
25970
+ statusInstanceId: this.deps.statusInstanceId,
25971
+ localMachineId: loadConfig().machineId || ""
25972
+ });
25973
+ const directTruthSatisfied = meshRecord.source !== "inline_bootstrap" || directTruth.directEvidenceCount > 0;
25974
+ const sourceOfTruth = {
25975
+ membership: meshRecord.source === "inline_cache" ? "coordinator_inline_mesh_cache" : meshRecord.source === "local_config" ? "local_mesh_config" : "inline_bootstrap_snapshot",
25976
+ coordinatorOwnsLiveTruth: directTruthSatisfied,
25977
+ directPeerTruth: {
25978
+ required: requireDirectPeerTruth,
25979
+ satisfied: directTruthSatisfied,
25980
+ directEvidenceCount: directTruth.directEvidenceCount,
25981
+ localConfirmedCount: directTruth.localConfirmedCount,
25982
+ peerAttemptedCount: directTruth.peerAttemptedCount,
25983
+ peerConfirmedCount: directTruth.peerConfirmedCount,
25984
+ unavailableNodeIds: directTruth.unavailableNodeIds
25985
+ }
25986
+ };
25987
+ if (requireDirectPeerTruth && !directTruthSatisfied) {
25988
+ return {
25989
+ success: false,
25990
+ code: "mesh_direct_peer_truth_unavailable",
25991
+ error: "Selected coordinator could not confirm direct mesh truth yet. Bootstrap inventory stays unavailable until direct get_mesh probes succeed.",
25992
+ sourceOfTruth
25993
+ };
25994
+ }
25995
+ return { success: true, mesh: meshRecord.mesh, sourceOfTruth };
25828
25996
  }
25829
25997
  case "create_mesh": {
25830
25998
  const name = typeof args?.name === "string" ? args.name.trim() : "";
@@ -26752,25 +26920,51 @@ ${block}`);
26752
26920
  }
26753
26921
  if (workspace) {
26754
26922
  if (!fs10.existsSync(workspace)) {
26923
+ const inlineTransitGit = buildInlineMeshTransitGitStatus(node);
26755
26924
  let remoteProbeApplied = false;
26756
- if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand) {
26925
+ if (inlineTransitGit) {
26926
+ status.git = inlineTransitGit;
26927
+ status.health = inlineTransitGit.isGitRepo ? deriveMeshNodeHealthFromGit(inlineTransitGit) : "degraded";
26928
+ remoteProbeApplied = true;
26929
+ } else if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand) {
26757
26930
  try {
26758
- const remoteResult = await Promise.race([
26759
- this.deps.dispatchMeshCommand(daemonId, "git_status", { workspace }),
26760
- new Promise((_, reject) => setTimeout(() => reject(new Error("timeout")), 8e3))
26761
- ]);
26762
- const remoteGit = remoteResult?.status ?? remoteResult?.git ?? remoteResult;
26763
- if (remoteGit && typeof remoteGit === "object" && typeof remoteGit.isGitRepo === "boolean") {
26931
+ const remoteGit = await probeRemoteMeshGitStatus({
26932
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
26933
+ daemonId,
26934
+ workspace,
26935
+ timeoutMs: 8e3
26936
+ });
26937
+ if (remoteGit) {
26764
26938
  status.git = remoteGit;
26765
26939
  status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
26940
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
26766
26941
  remoteProbeApplied = true;
26767
26942
  }
26768
26943
  } catch {
26944
+ const refreshedConnection = this.deps.getMeshPeerConnectionStatus?.(daemonId);
26945
+ const refreshedConnectionState = readStringValue(refreshedConnection?.state);
26946
+ if (refreshedConnection && refreshedConnectionState === "connected") {
26947
+ status.connection = refreshedConnection;
26948
+ try {
26949
+ const remoteGit = await probeRemoteMeshGitStatus({
26950
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
26951
+ daemonId,
26952
+ workspace,
26953
+ timeoutMs: 12e3
26954
+ });
26955
+ if (remoteGit) {
26956
+ status.git = remoteGit;
26957
+ status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
26958
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
26959
+ remoteProbeApplied = true;
26960
+ }
26961
+ } catch {
26962
+ }
26963
+ }
26769
26964
  }
26770
26965
  }
26771
26966
  if (!remoteProbeApplied) {
26772
26967
  const connectionState = readStringValue(status.connection?.state);
26773
- const inlineTransitGit = buildInlineMeshTransitGitStatus(node);
26774
26968
  const pendingPeerGitProbe = !inlineTransitGit && !isSelfNode && !!daemonId && (readStringValue(status.machineStatus) === "online" || readStringValue(status.health) === "online" || connectionState === "connecting" || connectionState === "connected" || connectionState === "unknown");
26775
26969
  if (pendingPeerGitProbe) {
26776
26970
  status.gitProbePending = true;
@@ -26781,12 +26975,12 @@ ${block}`);
26781
26975
  node,
26782
26976
  pendingPeerGitProbe ? { skipGit: true, skipError: true, skipHealth: true } : void 0
26783
26977
  )) {
26784
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
26978
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
26785
26979
  nodeStatuses.push(status);
26786
26980
  continue;
26787
26981
  }
26788
26982
  if (meshRecord?.source === "inline_cache" && !isSelfNode) {
26789
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
26983
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
26790
26984
  nodeStatuses.push(status);
26791
26985
  continue;
26792
26986
  }
@@ -26795,6 +26989,7 @@ ${block}`);
26795
26989
  try {
26796
26990
  const gitStatus = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
26797
26991
  status.git = gitStatus;
26992
+ recordInlineMeshDirectGitTruth(node, gitStatus, "selected_coordinator_local_git");
26798
26993
  if (gitStatus.isGitRepo) {
26799
26994
  status.health = deriveMeshNodeHealthFromGit(gitStatus);
26800
26995
  } else {
@@ -26810,7 +27005,7 @@ ${block}`);
26810
27005
  } else {
26811
27006
  applyCachedInlineMeshNodeStatus(status, node);
26812
27007
  }
26813
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
27008
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
26814
27009
  nodeStatuses.push(status);
26815
27010
  }
26816
27011
  return {