adhdev 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/cli/index.js CHANGED
@@ -46638,13 +46638,21 @@ function readBooleanValue(...values) {
46638
46638
  }
46639
46639
  return void 0;
46640
46640
  }
46641
- function readGitSubmodules(value) {
46641
+ function joinRepoPath(root, relativePath) {
46642
+ const normalizedRoot = typeof root === "string" ? root.trim().replace(/[\\/]+$/, "") : "";
46643
+ const normalizedPath = typeof relativePath === "string" ? relativePath.trim() : "";
46644
+ if (!normalizedPath) return void 0;
46645
+ if (/^(?:[A-Za-z]:[\\/]|\/)/.test(normalizedPath)) return normalizedPath;
46646
+ if (!normalizedRoot) return void 0;
46647
+ return `${normalizedRoot}/${normalizedPath.replace(/^[\\/]+/, "")}`;
46648
+ }
46649
+ function readGitSubmodules(value, parentRepoRoot) {
46642
46650
  if (!Array.isArray(value)) return void 0;
46643
46651
  const submodules = value.map((entry) => {
46644
46652
  const submodule = readObjectRecord(entry);
46645
46653
  const path42 = readStringValue(submodule.path);
46646
46654
  const commit = readStringValue(submodule.commit);
46647
- const repoPath = readStringValue(submodule.repoPath, submodule.repo_root);
46655
+ const repoPath = readStringValue(submodule.repoPath, submodule.repo_root) ?? joinRepoPath(parentRepoRoot, path42);
46648
46656
  if (!path42 || !commit || !repoPath) return null;
46649
46657
  return {
46650
46658
  path: path42,
@@ -46664,10 +46672,11 @@ function normalizeInlineMeshGitStatus(status, node, options) {
46664
46672
  const conflictFiles = Array.isArray(status.conflictFiles) ? status.conflictFiles.filter((value) => typeof value === "string") : [];
46665
46673
  const conflictCount = readNumberValue(status.conflicts) ?? conflictFiles.length;
46666
46674
  const hasConflicts = readBooleanValue(status.hasConflicts) ?? conflictCount > 0;
46667
- const submodules = readGitSubmodules(status.submodules);
46675
+ const repoRoot = readStringValue(status.repoRoot, status.repo_root, node?.repoRoot, node?.repo_root, status.workspace, node?.workspace) || void 0;
46676
+ const submodules = readGitSubmodules(status.submodules, repoRoot);
46668
46677
  return {
46669
46678
  workspace: readStringValue(status.workspace, node?.workspace) || "",
46670
- repoRoot: readStringValue(status.repoRoot, node?.repoRoot, node?.workspace) || null,
46679
+ repoRoot: repoRoot ?? null,
46671
46680
  isGitRepo,
46672
46681
  branch: readStringValue(status.branch) ?? null,
46673
46682
  headCommit: readStringValue(status.headCommit) ?? null,
@@ -46700,6 +46709,26 @@ function buildInlineMeshTransitGitStatus(node) {
46700
46709
  const status = Object.keys(directStatus).length ? directStatus : Object.keys(nestedStatus).length ? nestedStatus : Object.keys(probeDirectStatus).length ? probeDirectStatus : Object.keys(probeNestedStatus).length ? probeNestedStatus : {};
46701
46710
  return normalizeInlineMeshGitStatus(status, node, { lastCheckedAt: Date.now() });
46702
46711
  }
46712
+ function recordInlineMeshDirectGitTruth(node, git, source) {
46713
+ if (!node || typeof node !== "object" || Array.isArray(node)) return;
46714
+ const checkedAt = readNumberValue(git.lastCheckedAt) ?? Date.now();
46715
+ const updatedAt = new Date(checkedAt).toISOString();
46716
+ const nextGit = {
46717
+ ...git,
46718
+ lastCheckedAt: checkedAt
46719
+ };
46720
+ node.lastGit = {
46721
+ source,
46722
+ checkedAt,
46723
+ status: nextGit
46724
+ };
46725
+ node.last_git = node.lastGit;
46726
+ node.machineStatus = "online";
46727
+ node.updatedAt = updatedAt;
46728
+ node.lastSeenAt = updatedAt;
46729
+ const repoRoot = readStringValue(nextGit.repoRoot);
46730
+ if (repoRoot && !readStringValue(node.repoRoot)) node.repoRoot = repoRoot;
46731
+ }
46703
46732
  function buildCachedInlineMeshGitStatus(node) {
46704
46733
  const liveGit = buildInlineMeshTransitGitStatus(node);
46705
46734
  if (liveGit) return liveGit;
@@ -46742,7 +46771,6 @@ function stripInlineMeshTransientNodeState(node) {
46742
46771
  session_id: _sessionIdLegacy,
46743
46772
  providerType: _providerType,
46744
46773
  provider_type: _providerTypeLegacy,
46745
- providers: _providers,
46746
46774
  ...rest
46747
46775
  } = node;
46748
46776
  if (cachedStatus && !shouldDiscardCachedInlineMeshStatus(node)) {
@@ -46752,7 +46780,7 @@ function stripInlineMeshTransientNodeState(node) {
46752
46780
  }
46753
46781
  function hasInlineMeshTransientNodeState(node) {
46754
46782
  if (!node || typeof node !== "object" || Array.isArray(node)) return false;
46755
- 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;
46783
+ 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;
46756
46784
  }
46757
46785
  function readInlineMeshNodeId(node) {
46758
46786
  return readStringValue(node?.id, node?.nodeId) || "";
@@ -46878,6 +46906,109 @@ function toIsoTimestamp(value) {
46878
46906
  const stringValue = readStringValue(value);
46879
46907
  return stringValue || null;
46880
46908
  }
46909
+ function synthesizeMeshNodeFreshnessFromConnection(status) {
46910
+ const connection = readObjectRecord(status.connection);
46911
+ const connectionFreshAt = toIsoTimestamp(connection.lastCommandAt ?? connection.lastConnectedAt ?? connection.lastStateChangeAt);
46912
+ const git = readObjectRecord(status.git);
46913
+ const gitCheckedAt = toIsoTimestamp(git.lastCheckedAt);
46914
+ if (!status.lastSeenAt && connectionFreshAt) status.lastSeenAt = connectionFreshAt;
46915
+ if (!status.updatedAt && (gitCheckedAt || connectionFreshAt)) {
46916
+ status.updatedAt = gitCheckedAt ?? connectionFreshAt;
46917
+ }
46918
+ }
46919
+ function finalizeMeshNodeStatus(args) {
46920
+ const { status, node, daemonId, isSelfNode } = args;
46921
+ if (!readStringValue(status.machineStatus)) {
46922
+ const cachedStatus = readObjectRecord(node?.cachedStatus);
46923
+ const machineStatus = readStringValue(cachedStatus.machineStatus, cachedStatus.machine_status, node?.machineStatus);
46924
+ if (machineStatus) status.machineStatus = machineStatus;
46925
+ }
46926
+ synthesizeMeshNodeFreshnessFromConnection(status);
46927
+ const connectionState = readStringValue(readObjectRecord(status.connection).state);
46928
+ status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || connectionState === "connected" || isSelfNode);
46929
+ }
46930
+ async function probeRemoteMeshGitStatus(args) {
46931
+ if (!args.dispatchMeshCommand) return null;
46932
+ const remoteResult = await Promise.race([
46933
+ args.dispatchMeshCommand(args.daemonId, "git_status", { workspace: args.workspace }),
46934
+ new Promise((_2, reject) => setTimeout(() => reject(new Error("timeout")), args.timeoutMs))
46935
+ ]);
46936
+ const remoteGit = remoteResult?.status ?? remoteResult?.git ?? remoteResult;
46937
+ return remoteGit && typeof remoteGit === "object" && typeof remoteGit.isGitRepo === "boolean" ? remoteGit : null;
46938
+ }
46939
+ async function hydrateInlineMeshDirectTruth(args) {
46940
+ const nodes = Array.isArray(args.mesh?.nodes) ? args.mesh.nodes : [];
46941
+ if (!nodes.length) {
46942
+ return {
46943
+ directEvidenceCount: 0,
46944
+ localConfirmedCount: 0,
46945
+ peerAttemptedCount: 0,
46946
+ peerConfirmedCount: 0,
46947
+ unavailableNodeIds: []
46948
+ };
46949
+ }
46950
+ const selectedCoordinatorNodeId = readStringValue(
46951
+ args.mesh?.coordinator?.preferredNodeId,
46952
+ nodes[0]?.id,
46953
+ nodes[0]?.nodeId
46954
+ );
46955
+ let localConfirmedCount = 0;
46956
+ let peerAttemptedCount = 0;
46957
+ let peerConfirmedCount = 0;
46958
+ const unavailableNodeIds = [];
46959
+ for (const [nodeIndex, node] of nodes.entries()) {
46960
+ const nodeId = readStringValue(node?.id, node?.nodeId) || `node_${nodeIndex}`;
46961
+ const workspace = readStringValue(node?.workspace);
46962
+ const daemonId = readStringValue(node?.daemonId);
46963
+ const isSelfNode = Boolean(
46964
+ nodeId && selectedCoordinatorNodeId && nodeId === selectedCoordinatorNodeId
46965
+ ) || Boolean(
46966
+ daemonId && (daemonId === args.localMachineId || daemonId === args.statusInstanceId)
46967
+ ) || Boolean(args.meshSource !== "local_config" && nodeIndex === 0);
46968
+ if (!workspace) {
46969
+ if (!isSelfNode && daemonId) unavailableNodeIds.push(nodeId);
46970
+ continue;
46971
+ }
46972
+ if (isSelfNode && fs10.existsSync(workspace)) {
46973
+ try {
46974
+ const localGit = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
46975
+ if (localGit?.isGitRepo) {
46976
+ recordInlineMeshDirectGitTruth(node, localGit, "selected_coordinator_local_git");
46977
+ localConfirmedCount += 1;
46978
+ continue;
46979
+ }
46980
+ } catch {
46981
+ }
46982
+ }
46983
+ if (!daemonId || !args.dispatchMeshCommand) {
46984
+ if (!isSelfNode) unavailableNodeIds.push(nodeId);
46985
+ continue;
46986
+ }
46987
+ peerAttemptedCount += 1;
46988
+ try {
46989
+ const remoteGit = await probeRemoteMeshGitStatus({
46990
+ dispatchMeshCommand: args.dispatchMeshCommand,
46991
+ daemonId,
46992
+ workspace,
46993
+ timeoutMs: 8e3
46994
+ });
46995
+ if (remoteGit) {
46996
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
46997
+ peerConfirmedCount += 1;
46998
+ continue;
46999
+ }
47000
+ } catch {
47001
+ }
47002
+ unavailableNodeIds.push(nodeId);
47003
+ }
47004
+ return {
47005
+ directEvidenceCount: localConfirmedCount + peerConfirmedCount,
47006
+ localConfirmedCount,
47007
+ peerAttemptedCount,
47008
+ peerConfirmedCount,
47009
+ unavailableNodeIds
47010
+ };
47011
+ }
46881
47012
  function summarizeMeshSessionRecord(record2) {
46882
47013
  return {
46883
47014
  sessionId: readStringValue(record2?.sessionId) || "unknown",
@@ -48426,8 +48557,38 @@ var init_router = __esm({
48426
48557
  const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
48427
48558
  if (!meshId) return { success: false, error: "meshId required" };
48428
48559
  const meshRecord = await this.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
48429
- if (meshRecord?.mesh) return { success: true, mesh: meshRecord.mesh };
48430
- return { success: false, error: "Mesh not found" };
48560
+ if (!meshRecord?.mesh) return { success: false, error: "Mesh not found" };
48561
+ const requireDirectPeerTruth = args?.requireDirectPeerTruth === true;
48562
+ const directTruth = await hydrateInlineMeshDirectTruth({
48563
+ mesh: meshRecord.mesh,
48564
+ meshSource: meshRecord.source,
48565
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
48566
+ statusInstanceId: this.deps.statusInstanceId,
48567
+ localMachineId: loadConfig().machineId || ""
48568
+ });
48569
+ const directTruthSatisfied = meshRecord.source !== "inline_bootstrap" || directTruth.directEvidenceCount > 0;
48570
+ const sourceOfTruth = {
48571
+ membership: meshRecord.source === "inline_cache" ? "coordinator_inline_mesh_cache" : meshRecord.source === "local_config" ? "local_mesh_config" : "inline_bootstrap_snapshot",
48572
+ coordinatorOwnsLiveTruth: directTruthSatisfied,
48573
+ directPeerTruth: {
48574
+ required: requireDirectPeerTruth,
48575
+ satisfied: directTruthSatisfied,
48576
+ directEvidenceCount: directTruth.directEvidenceCount,
48577
+ localConfirmedCount: directTruth.localConfirmedCount,
48578
+ peerAttemptedCount: directTruth.peerAttemptedCount,
48579
+ peerConfirmedCount: directTruth.peerConfirmedCount,
48580
+ unavailableNodeIds: directTruth.unavailableNodeIds
48581
+ }
48582
+ };
48583
+ if (requireDirectPeerTruth && !directTruthSatisfied) {
48584
+ return {
48585
+ success: false,
48586
+ code: "mesh_direct_peer_truth_unavailable",
48587
+ error: "Selected coordinator could not confirm direct mesh truth yet. Bootstrap inventory stays unavailable until direct get_mesh probes succeed.",
48588
+ sourceOfTruth
48589
+ };
48590
+ }
48591
+ return { success: true, mesh: meshRecord.mesh, sourceOfTruth };
48431
48592
  }
48432
48593
  case "create_mesh": {
48433
48594
  const name = typeof args?.name === "string" ? args.name.trim() : "";
@@ -49355,25 +49516,51 @@ ${block}`);
49355
49516
  }
49356
49517
  if (workspace) {
49357
49518
  if (!fs10.existsSync(workspace)) {
49519
+ const inlineTransitGit = buildInlineMeshTransitGitStatus(node);
49358
49520
  let remoteProbeApplied = false;
49359
- if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand) {
49521
+ if (inlineTransitGit) {
49522
+ status.git = inlineTransitGit;
49523
+ status.health = inlineTransitGit.isGitRepo ? deriveMeshNodeHealthFromGit(inlineTransitGit) : "degraded";
49524
+ remoteProbeApplied = true;
49525
+ } else if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand) {
49360
49526
  try {
49361
- const remoteResult = await Promise.race([
49362
- this.deps.dispatchMeshCommand(daemonId, "git_status", { workspace }),
49363
- new Promise((_2, reject) => setTimeout(() => reject(new Error("timeout")), 8e3))
49364
- ]);
49365
- const remoteGit = remoteResult?.status ?? remoteResult?.git ?? remoteResult;
49366
- if (remoteGit && typeof remoteGit === "object" && typeof remoteGit.isGitRepo === "boolean") {
49527
+ const remoteGit = await probeRemoteMeshGitStatus({
49528
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
49529
+ daemonId,
49530
+ workspace,
49531
+ timeoutMs: 8e3
49532
+ });
49533
+ if (remoteGit) {
49367
49534
  status.git = remoteGit;
49368
49535
  status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
49536
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
49369
49537
  remoteProbeApplied = true;
49370
49538
  }
49371
49539
  } catch {
49540
+ const refreshedConnection = this.deps.getMeshPeerConnectionStatus?.(daemonId);
49541
+ const refreshedConnectionState = readStringValue(refreshedConnection?.state);
49542
+ if (refreshedConnection && refreshedConnectionState === "connected") {
49543
+ status.connection = refreshedConnection;
49544
+ try {
49545
+ const remoteGit = await probeRemoteMeshGitStatus({
49546
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
49547
+ daemonId,
49548
+ workspace,
49549
+ timeoutMs: 12e3
49550
+ });
49551
+ if (remoteGit) {
49552
+ status.git = remoteGit;
49553
+ status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
49554
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
49555
+ remoteProbeApplied = true;
49556
+ }
49557
+ } catch {
49558
+ }
49559
+ }
49372
49560
  }
49373
49561
  }
49374
49562
  if (!remoteProbeApplied) {
49375
49563
  const connectionState = readStringValue(status.connection?.state);
49376
- const inlineTransitGit = buildInlineMeshTransitGitStatus(node);
49377
49564
  const pendingPeerGitProbe = !inlineTransitGit && !isSelfNode && !!daemonId && (readStringValue(status.machineStatus) === "online" || readStringValue(status.health) === "online" || connectionState === "connecting" || connectionState === "connected" || connectionState === "unknown");
49378
49565
  if (pendingPeerGitProbe) {
49379
49566
  status.gitProbePending = true;
@@ -49384,12 +49571,12 @@ ${block}`);
49384
49571
  node,
49385
49572
  pendingPeerGitProbe ? { skipGit: true, skipError: true, skipHealth: true } : void 0
49386
49573
  )) {
49387
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
49574
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
49388
49575
  nodeStatuses.push(status);
49389
49576
  continue;
49390
49577
  }
49391
49578
  if (meshRecord?.source === "inline_cache" && !isSelfNode) {
49392
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
49579
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
49393
49580
  nodeStatuses.push(status);
49394
49581
  continue;
49395
49582
  }
@@ -49398,6 +49585,7 @@ ${block}`);
49398
49585
  try {
49399
49586
  const gitStatus = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
49400
49587
  status.git = gitStatus;
49588
+ recordInlineMeshDirectGitTruth(node, gitStatus, "selected_coordinator_local_git");
49401
49589
  if (gitStatus.isGitRepo) {
49402
49590
  status.health = deriveMeshNodeHealthFromGit(gitStatus);
49403
49591
  } else {
@@ -49413,7 +49601,7 @@ ${block}`);
49413
49601
  } else {
49414
49602
  applyCachedInlineMeshNodeStatus(status, node);
49415
49603
  }
49416
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
49604
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
49417
49605
  nodeStatuses.push(status);
49418
49606
  }
49419
49607
  return {
@@ -98456,7 +98644,7 @@ var init_adhdev_daemon = __esm({
98456
98644
  init_version();
98457
98645
  init_src();
98458
98646
  init_runtime_defaults();
98459
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.82-rc.30" });
98647
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.82-rc.31" });
98460
98648
  AdhdevDaemon = class _AdhdevDaemon {
98461
98649
  localHttpServer = null;
98462
98650
  localWss = null;