@adhdev/daemon-standalone 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.js CHANGED
@@ -46052,13 +46052,21 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
46052
46052
  }
46053
46053
  return void 0;
46054
46054
  }
46055
- function readGitSubmodules(value) {
46055
+ function joinRepoPath(root, relativePath) {
46056
+ const normalizedRoot = typeof root === "string" ? root.trim().replace(/[\\/]+$/, "") : "";
46057
+ const normalizedPath = typeof relativePath === "string" ? relativePath.trim() : "";
46058
+ if (!normalizedPath) return void 0;
46059
+ if (/^(?:[A-Za-z]:[\\/]|\/)/.test(normalizedPath)) return normalizedPath;
46060
+ if (!normalizedRoot) return void 0;
46061
+ return `${normalizedRoot}/${normalizedPath.replace(/^[\\/]+/, "")}`;
46062
+ }
46063
+ function readGitSubmodules(value, parentRepoRoot) {
46056
46064
  if (!Array.isArray(value)) return void 0;
46057
46065
  const submodules = value.map((entry) => {
46058
46066
  const submodule = readObjectRecord(entry);
46059
46067
  const path28 = readStringValue(submodule.path);
46060
46068
  const commit = readStringValue(submodule.commit);
46061
- const repoPath = readStringValue(submodule.repoPath, submodule.repo_root);
46069
+ const repoPath = readStringValue(submodule.repoPath, submodule.repo_root) ?? joinRepoPath(parentRepoRoot, path28);
46062
46070
  if (!path28 || !commit || !repoPath) return null;
46063
46071
  return {
46064
46072
  path: path28,
@@ -46078,10 +46086,11 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
46078
46086
  const conflictFiles = Array.isArray(status.conflictFiles) ? status.conflictFiles.filter((value) => typeof value === "string") : [];
46079
46087
  const conflictCount = readNumberValue(status.conflicts) ?? conflictFiles.length;
46080
46088
  const hasConflicts = readBooleanValue(status.hasConflicts) ?? conflictCount > 0;
46081
- const submodules = readGitSubmodules(status.submodules);
46089
+ const repoRoot = readStringValue(status.repoRoot, status.repo_root, node?.repoRoot, node?.repo_root, status.workspace, node?.workspace) || void 0;
46090
+ const submodules = readGitSubmodules(status.submodules, repoRoot);
46082
46091
  return {
46083
46092
  workspace: readStringValue(status.workspace, node?.workspace) || "",
46084
- repoRoot: readStringValue(status.repoRoot, node?.repoRoot, node?.workspace) || null,
46093
+ repoRoot: repoRoot ?? null,
46085
46094
  isGitRepo,
46086
46095
  branch: readStringValue(status.branch) ?? null,
46087
46096
  headCommit: readStringValue(status.headCommit) ?? null,
@@ -46114,6 +46123,26 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
46114
46123
  const status = Object.keys(directStatus).length ? directStatus : Object.keys(nestedStatus).length ? nestedStatus : Object.keys(probeDirectStatus).length ? probeDirectStatus : Object.keys(probeNestedStatus).length ? probeNestedStatus : {};
46115
46124
  return normalizeInlineMeshGitStatus(status, node, { lastCheckedAt: Date.now() });
46116
46125
  }
46126
+ function recordInlineMeshDirectGitTruth(node, git, source) {
46127
+ if (!node || typeof node !== "object" || Array.isArray(node)) return;
46128
+ const checkedAt = readNumberValue(git.lastCheckedAt) ?? Date.now();
46129
+ const updatedAt = new Date(checkedAt).toISOString();
46130
+ const nextGit = {
46131
+ ...git,
46132
+ lastCheckedAt: checkedAt
46133
+ };
46134
+ node.lastGit = {
46135
+ source,
46136
+ checkedAt,
46137
+ status: nextGit
46138
+ };
46139
+ node.last_git = node.lastGit;
46140
+ node.machineStatus = "online";
46141
+ node.updatedAt = updatedAt;
46142
+ node.lastSeenAt = updatedAt;
46143
+ const repoRoot = readStringValue(nextGit.repoRoot);
46144
+ if (repoRoot && !readStringValue(node.repoRoot)) node.repoRoot = repoRoot;
46145
+ }
46117
46146
  function buildCachedInlineMeshGitStatus(node) {
46118
46147
  const liveGit = buildInlineMeshTransitGitStatus(node);
46119
46148
  if (liveGit) return liveGit;
@@ -46156,7 +46185,6 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
46156
46185
  session_id: _sessionIdLegacy,
46157
46186
  providerType: _providerType,
46158
46187
  provider_type: _providerTypeLegacy,
46159
- providers: _providers,
46160
46188
  ...rest
46161
46189
  } = node;
46162
46190
  if (cachedStatus && !shouldDiscardCachedInlineMeshStatus(node)) {
@@ -46166,7 +46194,7 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
46166
46194
  }
46167
46195
  function hasInlineMeshTransientNodeState(node) {
46168
46196
  if (!node || typeof node !== "object" || Array.isArray(node)) return false;
46169
- 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;
46197
+ 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;
46170
46198
  }
46171
46199
  function readInlineMeshNodeId(node) {
46172
46200
  return readStringValue(node?.id, node?.nodeId) || "";
@@ -46292,6 +46320,109 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
46292
46320
  const stringValue = readStringValue(value);
46293
46321
  return stringValue || null;
46294
46322
  }
46323
+ function synthesizeMeshNodeFreshnessFromConnection(status) {
46324
+ const connection = readObjectRecord(status.connection);
46325
+ const connectionFreshAt = toIsoTimestamp(connection.lastCommandAt ?? connection.lastConnectedAt ?? connection.lastStateChangeAt);
46326
+ const git = readObjectRecord(status.git);
46327
+ const gitCheckedAt = toIsoTimestamp(git.lastCheckedAt);
46328
+ if (!status.lastSeenAt && connectionFreshAt) status.lastSeenAt = connectionFreshAt;
46329
+ if (!status.updatedAt && (gitCheckedAt || connectionFreshAt)) {
46330
+ status.updatedAt = gitCheckedAt ?? connectionFreshAt;
46331
+ }
46332
+ }
46333
+ function finalizeMeshNodeStatus(args) {
46334
+ const { status, node, daemonId, isSelfNode } = args;
46335
+ if (!readStringValue(status.machineStatus)) {
46336
+ const cachedStatus = readObjectRecord(node?.cachedStatus);
46337
+ const machineStatus = readStringValue(cachedStatus.machineStatus, cachedStatus.machine_status, node?.machineStatus);
46338
+ if (machineStatus) status.machineStatus = machineStatus;
46339
+ }
46340
+ synthesizeMeshNodeFreshnessFromConnection(status);
46341
+ const connectionState = readStringValue(readObjectRecord(status.connection).state);
46342
+ status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || connectionState === "connected" || isSelfNode);
46343
+ }
46344
+ async function probeRemoteMeshGitStatus(args) {
46345
+ if (!args.dispatchMeshCommand) return null;
46346
+ const remoteResult = await Promise.race([
46347
+ args.dispatchMeshCommand(args.daemonId, "git_status", { workspace: args.workspace }),
46348
+ new Promise((_, reject) => setTimeout(() => reject(new Error("timeout")), args.timeoutMs))
46349
+ ]);
46350
+ const remoteGit = remoteResult?.status ?? remoteResult?.git ?? remoteResult;
46351
+ return remoteGit && typeof remoteGit === "object" && typeof remoteGit.isGitRepo === "boolean" ? remoteGit : null;
46352
+ }
46353
+ async function hydrateInlineMeshDirectTruth(args) {
46354
+ const nodes = Array.isArray(args.mesh?.nodes) ? args.mesh.nodes : [];
46355
+ if (!nodes.length) {
46356
+ return {
46357
+ directEvidenceCount: 0,
46358
+ localConfirmedCount: 0,
46359
+ peerAttemptedCount: 0,
46360
+ peerConfirmedCount: 0,
46361
+ unavailableNodeIds: []
46362
+ };
46363
+ }
46364
+ const selectedCoordinatorNodeId = readStringValue(
46365
+ args.mesh?.coordinator?.preferredNodeId,
46366
+ nodes[0]?.id,
46367
+ nodes[0]?.nodeId
46368
+ );
46369
+ let localConfirmedCount = 0;
46370
+ let peerAttemptedCount = 0;
46371
+ let peerConfirmedCount = 0;
46372
+ const unavailableNodeIds = [];
46373
+ for (const [nodeIndex, node] of nodes.entries()) {
46374
+ const nodeId = readStringValue(node?.id, node?.nodeId) || `node_${nodeIndex}`;
46375
+ const workspace = readStringValue(node?.workspace);
46376
+ const daemonId = readStringValue(node?.daemonId);
46377
+ const isSelfNode = Boolean(
46378
+ nodeId && selectedCoordinatorNodeId && nodeId === selectedCoordinatorNodeId
46379
+ ) || Boolean(
46380
+ daemonId && (daemonId === args.localMachineId || daemonId === args.statusInstanceId)
46381
+ ) || Boolean(args.meshSource !== "local_config" && nodeIndex === 0);
46382
+ if (!workspace) {
46383
+ if (!isSelfNode && daemonId) unavailableNodeIds.push(nodeId);
46384
+ continue;
46385
+ }
46386
+ if (isSelfNode && fs10.existsSync(workspace)) {
46387
+ try {
46388
+ const localGit = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
46389
+ if (localGit?.isGitRepo) {
46390
+ recordInlineMeshDirectGitTruth(node, localGit, "selected_coordinator_local_git");
46391
+ localConfirmedCount += 1;
46392
+ continue;
46393
+ }
46394
+ } catch {
46395
+ }
46396
+ }
46397
+ if (!daemonId || !args.dispatchMeshCommand) {
46398
+ if (!isSelfNode) unavailableNodeIds.push(nodeId);
46399
+ continue;
46400
+ }
46401
+ peerAttemptedCount += 1;
46402
+ try {
46403
+ const remoteGit = await probeRemoteMeshGitStatus({
46404
+ dispatchMeshCommand: args.dispatchMeshCommand,
46405
+ daemonId,
46406
+ workspace,
46407
+ timeoutMs: 8e3
46408
+ });
46409
+ if (remoteGit) {
46410
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
46411
+ peerConfirmedCount += 1;
46412
+ continue;
46413
+ }
46414
+ } catch {
46415
+ }
46416
+ unavailableNodeIds.push(nodeId);
46417
+ }
46418
+ return {
46419
+ directEvidenceCount: localConfirmedCount + peerConfirmedCount,
46420
+ localConfirmedCount,
46421
+ peerAttemptedCount,
46422
+ peerConfirmedCount,
46423
+ unavailableNodeIds
46424
+ };
46425
+ }
46295
46426
  function summarizeMeshSessionRecord(record2) {
46296
46427
  return {
46297
46428
  sessionId: readStringValue(record2?.sessionId) || "unknown",
@@ -47803,8 +47934,38 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
47803
47934
  const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
47804
47935
  if (!meshId) return { success: false, error: "meshId required" };
47805
47936
  const meshRecord = await this.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
47806
- if (meshRecord?.mesh) return { success: true, mesh: meshRecord.mesh };
47807
- return { success: false, error: "Mesh not found" };
47937
+ if (!meshRecord?.mesh) return { success: false, error: "Mesh not found" };
47938
+ const requireDirectPeerTruth = args?.requireDirectPeerTruth === true;
47939
+ const directTruth = await hydrateInlineMeshDirectTruth({
47940
+ mesh: meshRecord.mesh,
47941
+ meshSource: meshRecord.source,
47942
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
47943
+ statusInstanceId: this.deps.statusInstanceId,
47944
+ localMachineId: loadConfig2().machineId || ""
47945
+ });
47946
+ const directTruthSatisfied = meshRecord.source !== "inline_bootstrap" || directTruth.directEvidenceCount > 0;
47947
+ const sourceOfTruth = {
47948
+ membership: meshRecord.source === "inline_cache" ? "coordinator_inline_mesh_cache" : meshRecord.source === "local_config" ? "local_mesh_config" : "inline_bootstrap_snapshot",
47949
+ coordinatorOwnsLiveTruth: directTruthSatisfied,
47950
+ directPeerTruth: {
47951
+ required: requireDirectPeerTruth,
47952
+ satisfied: directTruthSatisfied,
47953
+ directEvidenceCount: directTruth.directEvidenceCount,
47954
+ localConfirmedCount: directTruth.localConfirmedCount,
47955
+ peerAttemptedCount: directTruth.peerAttemptedCount,
47956
+ peerConfirmedCount: directTruth.peerConfirmedCount,
47957
+ unavailableNodeIds: directTruth.unavailableNodeIds
47958
+ }
47959
+ };
47960
+ if (requireDirectPeerTruth && !directTruthSatisfied) {
47961
+ return {
47962
+ success: false,
47963
+ code: "mesh_direct_peer_truth_unavailable",
47964
+ error: "Selected coordinator could not confirm direct mesh truth yet. Bootstrap inventory stays unavailable until direct get_mesh probes succeed.",
47965
+ sourceOfTruth
47966
+ };
47967
+ }
47968
+ return { success: true, mesh: meshRecord.mesh, sourceOfTruth };
47808
47969
  }
47809
47970
  case "create_mesh": {
47810
47971
  const name = typeof args?.name === "string" ? args.name.trim() : "";
@@ -48732,25 +48893,51 @@ ${block}`);
48732
48893
  }
48733
48894
  if (workspace) {
48734
48895
  if (!fs10.existsSync(workspace)) {
48896
+ const inlineTransitGit = buildInlineMeshTransitGitStatus(node);
48735
48897
  let remoteProbeApplied = false;
48736
- if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand) {
48898
+ if (inlineTransitGit) {
48899
+ status.git = inlineTransitGit;
48900
+ status.health = inlineTransitGit.isGitRepo ? deriveMeshNodeHealthFromGit(inlineTransitGit) : "degraded";
48901
+ remoteProbeApplied = true;
48902
+ } else if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand) {
48737
48903
  try {
48738
- const remoteResult = await Promise.race([
48739
- this.deps.dispatchMeshCommand(daemonId, "git_status", { workspace }),
48740
- new Promise((_, reject) => setTimeout(() => reject(new Error("timeout")), 8e3))
48741
- ]);
48742
- const remoteGit = remoteResult?.status ?? remoteResult?.git ?? remoteResult;
48743
- if (remoteGit && typeof remoteGit === "object" && typeof remoteGit.isGitRepo === "boolean") {
48904
+ const remoteGit = await probeRemoteMeshGitStatus({
48905
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
48906
+ daemonId,
48907
+ workspace,
48908
+ timeoutMs: 8e3
48909
+ });
48910
+ if (remoteGit) {
48744
48911
  status.git = remoteGit;
48745
48912
  status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
48913
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
48746
48914
  remoteProbeApplied = true;
48747
48915
  }
48748
48916
  } catch {
48917
+ const refreshedConnection = this.deps.getMeshPeerConnectionStatus?.(daemonId);
48918
+ const refreshedConnectionState = readStringValue(refreshedConnection?.state);
48919
+ if (refreshedConnection && refreshedConnectionState === "connected") {
48920
+ status.connection = refreshedConnection;
48921
+ try {
48922
+ const remoteGit = await probeRemoteMeshGitStatus({
48923
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
48924
+ daemonId,
48925
+ workspace,
48926
+ timeoutMs: 12e3
48927
+ });
48928
+ if (remoteGit) {
48929
+ status.git = remoteGit;
48930
+ status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
48931
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
48932
+ remoteProbeApplied = true;
48933
+ }
48934
+ } catch {
48935
+ }
48936
+ }
48749
48937
  }
48750
48938
  }
48751
48939
  if (!remoteProbeApplied) {
48752
48940
  const connectionState = readStringValue(status.connection?.state);
48753
- const inlineTransitGit = buildInlineMeshTransitGitStatus(node);
48754
48941
  const pendingPeerGitProbe = !inlineTransitGit && !isSelfNode && !!daemonId && (readStringValue(status.machineStatus) === "online" || readStringValue(status.health) === "online" || connectionState === "connecting" || connectionState === "connected" || connectionState === "unknown");
48755
48942
  if (pendingPeerGitProbe) {
48756
48943
  status.gitProbePending = true;
@@ -48761,12 +48948,12 @@ ${block}`);
48761
48948
  node,
48762
48949
  pendingPeerGitProbe ? { skipGit: true, skipError: true, skipHealth: true } : void 0
48763
48950
  )) {
48764
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
48951
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
48765
48952
  nodeStatuses.push(status);
48766
48953
  continue;
48767
48954
  }
48768
48955
  if (meshRecord?.source === "inline_cache" && !isSelfNode) {
48769
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
48956
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
48770
48957
  nodeStatuses.push(status);
48771
48958
  continue;
48772
48959
  }
@@ -48775,6 +48962,7 @@ ${block}`);
48775
48962
  try {
48776
48963
  const gitStatus = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
48777
48964
  status.git = gitStatus;
48965
+ recordInlineMeshDirectGitTruth(node, gitStatus, "selected_coordinator_local_git");
48778
48966
  if (gitStatus.isGitRepo) {
48779
48967
  status.health = deriveMeshNodeHealthFromGit(gitStatus);
48780
48968
  } else {
@@ -48790,7 +48978,7 @@ ${block}`);
48790
48978
  } else {
48791
48979
  applyCachedInlineMeshNodeStatus(status, node);
48792
48980
  }
48793
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
48981
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
48794
48982
  nodeStatuses.push(status);
48795
48983
  }
48796
48984
  return {