@adhdev/daemon-standalone 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
@@ -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,12 @@ ${(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;
46198
+ }
46199
+ function inlineMeshCarriesTransientNodeTruth(inlineMesh) {
46200
+ if (!inlineMesh || typeof inlineMesh !== "object" || Array.isArray(inlineMesh)) return false;
46201
+ if (!Array.isArray(inlineMesh.nodes) || inlineMesh.nodes.length === 0) return false;
46202
+ return inlineMesh.nodes.some((node) => hasInlineMeshTransientNodeState(node));
46170
46203
  }
46171
46204
  function readInlineMeshNodeId(node) {
46172
46205
  return readStringValue(node?.id, node?.nodeId) || "";
@@ -46292,6 +46325,109 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
46292
46325
  const stringValue = readStringValue(value);
46293
46326
  return stringValue || null;
46294
46327
  }
46328
+ function synthesizeMeshNodeFreshnessFromConnection(status) {
46329
+ const connection = readObjectRecord(status.connection);
46330
+ const connectionFreshAt = toIsoTimestamp(connection.lastCommandAt ?? connection.lastConnectedAt ?? connection.lastStateChangeAt);
46331
+ const git = readObjectRecord(status.git);
46332
+ const gitCheckedAt = toIsoTimestamp(git.lastCheckedAt);
46333
+ if (!status.lastSeenAt && connectionFreshAt) status.lastSeenAt = connectionFreshAt;
46334
+ if (!status.updatedAt && (gitCheckedAt || connectionFreshAt)) {
46335
+ status.updatedAt = gitCheckedAt ?? connectionFreshAt;
46336
+ }
46337
+ }
46338
+ function finalizeMeshNodeStatus(args) {
46339
+ const { status, node, daemonId, isSelfNode } = args;
46340
+ if (!readStringValue(status.machineStatus)) {
46341
+ const cachedStatus = readObjectRecord(node?.cachedStatus);
46342
+ const machineStatus = readStringValue(cachedStatus.machineStatus, cachedStatus.machine_status, node?.machineStatus);
46343
+ if (machineStatus) status.machineStatus = machineStatus;
46344
+ }
46345
+ synthesizeMeshNodeFreshnessFromConnection(status);
46346
+ const connectionState = readStringValue(readObjectRecord(status.connection).state);
46347
+ status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || connectionState === "connected" || isSelfNode);
46348
+ }
46349
+ async function probeRemoteMeshGitStatus(args) {
46350
+ if (!args.dispatchMeshCommand) return null;
46351
+ const remoteResult = await Promise.race([
46352
+ args.dispatchMeshCommand(args.daemonId, "git_status", { workspace: args.workspace }),
46353
+ new Promise((_, reject) => setTimeout(() => reject(new Error("timeout")), args.timeoutMs))
46354
+ ]);
46355
+ const remoteGit = remoteResult?.status ?? remoteResult?.git ?? remoteResult;
46356
+ return remoteGit && typeof remoteGit === "object" && typeof remoteGit.isGitRepo === "boolean" ? remoteGit : null;
46357
+ }
46358
+ async function hydrateInlineMeshDirectTruth(args) {
46359
+ const nodes = Array.isArray(args.mesh?.nodes) ? args.mesh.nodes : [];
46360
+ if (!nodes.length) {
46361
+ return {
46362
+ directEvidenceCount: 0,
46363
+ localConfirmedCount: 0,
46364
+ peerAttemptedCount: 0,
46365
+ peerConfirmedCount: 0,
46366
+ unavailableNodeIds: []
46367
+ };
46368
+ }
46369
+ const selectedCoordinatorNodeId = readStringValue(
46370
+ args.mesh?.coordinator?.preferredNodeId,
46371
+ nodes[0]?.id,
46372
+ nodes[0]?.nodeId
46373
+ );
46374
+ let localConfirmedCount = 0;
46375
+ let peerAttemptedCount = 0;
46376
+ let peerConfirmedCount = 0;
46377
+ const unavailableNodeIds = [];
46378
+ for (const [nodeIndex, node] of nodes.entries()) {
46379
+ const nodeId = readStringValue(node?.id, node?.nodeId) || `node_${nodeIndex}`;
46380
+ const workspace = readStringValue(node?.workspace);
46381
+ const daemonId = readStringValue(node?.daemonId);
46382
+ const isSelfNode = Boolean(
46383
+ nodeId && selectedCoordinatorNodeId && nodeId === selectedCoordinatorNodeId
46384
+ ) || Boolean(
46385
+ daemonId && (daemonId === args.localMachineId || daemonId === args.statusInstanceId)
46386
+ ) || Boolean(args.meshSource !== "local_config" && nodeIndex === 0);
46387
+ if (!workspace) {
46388
+ if (!isSelfNode && daemonId) unavailableNodeIds.push(nodeId);
46389
+ continue;
46390
+ }
46391
+ if (isSelfNode && fs10.existsSync(workspace)) {
46392
+ try {
46393
+ const localGit = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
46394
+ if (localGit?.isGitRepo) {
46395
+ recordInlineMeshDirectGitTruth(node, localGit, "selected_coordinator_local_git");
46396
+ localConfirmedCount += 1;
46397
+ continue;
46398
+ }
46399
+ } catch {
46400
+ }
46401
+ }
46402
+ if (!daemonId || !args.dispatchMeshCommand) {
46403
+ if (!isSelfNode) unavailableNodeIds.push(nodeId);
46404
+ continue;
46405
+ }
46406
+ peerAttemptedCount += 1;
46407
+ try {
46408
+ const remoteGit = await probeRemoteMeshGitStatus({
46409
+ dispatchMeshCommand: args.dispatchMeshCommand,
46410
+ daemonId,
46411
+ workspace,
46412
+ timeoutMs: 8e3
46413
+ });
46414
+ if (remoteGit) {
46415
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
46416
+ peerConfirmedCount += 1;
46417
+ continue;
46418
+ }
46419
+ } catch {
46420
+ }
46421
+ unavailableNodeIds.push(nodeId);
46422
+ }
46423
+ return {
46424
+ directEvidenceCount: localConfirmedCount + peerConfirmedCount,
46425
+ localConfirmedCount,
46426
+ peerAttemptedCount,
46427
+ peerConfirmedCount,
46428
+ unavailableNodeIds
46429
+ };
46430
+ }
46295
46431
  function summarizeMeshSessionRecord(record2) {
46296
46432
  return {
46297
46433
  sessionId: readStringValue(record2?.sessionId) || "unknown",
@@ -46794,8 +46930,10 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
46794
46930
  if (preferInline) {
46795
46931
  const cached22 = this.getCachedInlineMesh(meshId);
46796
46932
  if (cached22) return { mesh: cached22, inline: true, source: "inline_cache" };
46797
- const warmedInline2 = this.warmInlineMeshCache(meshId, inlineMesh);
46798
- if (warmedInline2) return { mesh: warmedInline2, inline: true, source: "inline_bootstrap" };
46933
+ if (inlineMeshCarriesTransientNodeTruth(inlineMesh)) {
46934
+ this.warmInlineMeshCache(meshId, inlineMesh);
46935
+ return { mesh: inlineMesh, inline: true, source: "inline_bootstrap" };
46936
+ }
46799
46937
  }
46800
46938
  try {
46801
46939
  const { getMesh: getMesh3 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
@@ -47803,8 +47941,38 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
47803
47941
  const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
47804
47942
  if (!meshId) return { success: false, error: "meshId required" };
47805
47943
  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" };
47944
+ if (!meshRecord?.mesh) return { success: false, error: "Mesh not found" };
47945
+ const requireDirectPeerTruth = args?.requireDirectPeerTruth === true;
47946
+ const directTruth = await hydrateInlineMeshDirectTruth({
47947
+ mesh: meshRecord.mesh,
47948
+ meshSource: meshRecord.source,
47949
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
47950
+ statusInstanceId: this.deps.statusInstanceId,
47951
+ localMachineId: loadConfig2().machineId || ""
47952
+ });
47953
+ const directTruthSatisfied = meshRecord.source !== "inline_bootstrap" || directTruth.directEvidenceCount > 0;
47954
+ const sourceOfTruth = {
47955
+ membership: meshRecord.source === "inline_cache" ? "coordinator_inline_mesh_cache" : meshRecord.source === "local_config" ? "local_mesh_config" : "inline_bootstrap_snapshot",
47956
+ coordinatorOwnsLiveTruth: directTruthSatisfied,
47957
+ directPeerTruth: {
47958
+ required: requireDirectPeerTruth,
47959
+ satisfied: directTruthSatisfied,
47960
+ directEvidenceCount: directTruth.directEvidenceCount,
47961
+ localConfirmedCount: directTruth.localConfirmedCount,
47962
+ peerAttemptedCount: directTruth.peerAttemptedCount,
47963
+ peerConfirmedCount: directTruth.peerConfirmedCount,
47964
+ unavailableNodeIds: directTruth.unavailableNodeIds
47965
+ }
47966
+ };
47967
+ if (requireDirectPeerTruth && !directTruthSatisfied) {
47968
+ return {
47969
+ success: false,
47970
+ code: "mesh_direct_peer_truth_unavailable",
47971
+ error: "Selected coordinator could not confirm direct mesh truth yet. Bootstrap inventory stays unavailable until direct get_mesh probes succeed.",
47972
+ sourceOfTruth
47973
+ };
47974
+ }
47975
+ return { success: true, mesh: meshRecord.mesh, sourceOfTruth };
47808
47976
  }
47809
47977
  case "create_mesh": {
47810
47978
  const name = typeof args?.name === "string" ? args.name.trim() : "";
@@ -48732,25 +48900,51 @@ ${block}`);
48732
48900
  }
48733
48901
  if (workspace) {
48734
48902
  if (!fs10.existsSync(workspace)) {
48903
+ const inlineTransitGit = buildInlineMeshTransitGitStatus(node);
48735
48904
  let remoteProbeApplied = false;
48736
- if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand) {
48905
+ if (inlineTransitGit) {
48906
+ status.git = inlineTransitGit;
48907
+ status.health = inlineTransitGit.isGitRepo ? deriveMeshNodeHealthFromGit(inlineTransitGit) : "degraded";
48908
+ remoteProbeApplied = true;
48909
+ } else if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand) {
48737
48910
  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") {
48911
+ const remoteGit = await probeRemoteMeshGitStatus({
48912
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
48913
+ daemonId,
48914
+ workspace,
48915
+ timeoutMs: 8e3
48916
+ });
48917
+ if (remoteGit) {
48744
48918
  status.git = remoteGit;
48745
48919
  status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
48920
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
48746
48921
  remoteProbeApplied = true;
48747
48922
  }
48748
48923
  } catch {
48924
+ const refreshedConnection = this.deps.getMeshPeerConnectionStatus?.(daemonId);
48925
+ const refreshedConnectionState = readStringValue(refreshedConnection?.state);
48926
+ if (refreshedConnection && refreshedConnectionState === "connected") {
48927
+ status.connection = refreshedConnection;
48928
+ try {
48929
+ const remoteGit = await probeRemoteMeshGitStatus({
48930
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
48931
+ daemonId,
48932
+ workspace,
48933
+ timeoutMs: 12e3
48934
+ });
48935
+ if (remoteGit) {
48936
+ status.git = remoteGit;
48937
+ status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
48938
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
48939
+ remoteProbeApplied = true;
48940
+ }
48941
+ } catch {
48942
+ }
48943
+ }
48749
48944
  }
48750
48945
  }
48751
48946
  if (!remoteProbeApplied) {
48752
48947
  const connectionState = readStringValue(status.connection?.state);
48753
- const inlineTransitGit = buildInlineMeshTransitGitStatus(node);
48754
48948
  const pendingPeerGitProbe = !inlineTransitGit && !isSelfNode && !!daemonId && (readStringValue(status.machineStatus) === "online" || readStringValue(status.health) === "online" || connectionState === "connecting" || connectionState === "connected" || connectionState === "unknown");
48755
48949
  if (pendingPeerGitProbe) {
48756
48950
  status.gitProbePending = true;
@@ -48761,12 +48955,12 @@ ${block}`);
48761
48955
  node,
48762
48956
  pendingPeerGitProbe ? { skipGit: true, skipError: true, skipHealth: true } : void 0
48763
48957
  )) {
48764
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
48958
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
48765
48959
  nodeStatuses.push(status);
48766
48960
  continue;
48767
48961
  }
48768
48962
  if (meshRecord?.source === "inline_cache" && !isSelfNode) {
48769
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
48963
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
48770
48964
  nodeStatuses.push(status);
48771
48965
  continue;
48772
48966
  }
@@ -48775,6 +48969,7 @@ ${block}`);
48775
48969
  try {
48776
48970
  const gitStatus = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
48777
48971
  status.git = gitStatus;
48972
+ recordInlineMeshDirectGitTruth(node, gitStatus, "selected_coordinator_local_git");
48778
48973
  if (gitStatus.isGitRepo) {
48779
48974
  status.health = deriveMeshNodeHealthFromGit(gitStatus);
48780
48975
  } else {
@@ -48790,7 +48985,7 @@ ${block}`);
48790
48985
  } else {
48791
48986
  applyCachedInlineMeshNodeStatus(status, node);
48792
48987
  }
48793
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
48988
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
48794
48989
  nodeStatuses.push(status);
48795
48990
  }
48796
48991
  return {