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/index.js CHANGED
@@ -45650,13 +45650,21 @@ function readBooleanValue(...values) {
45650
45650
  }
45651
45651
  return void 0;
45652
45652
  }
45653
- function readGitSubmodules(value) {
45653
+ function joinRepoPath(root, relativePath) {
45654
+ const normalizedRoot = typeof root === "string" ? root.trim().replace(/[\\/]+$/, "") : "";
45655
+ const normalizedPath = typeof relativePath === "string" ? relativePath.trim() : "";
45656
+ if (!normalizedPath) return void 0;
45657
+ if (/^(?:[A-Za-z]:[\\/]|\/)/.test(normalizedPath)) return normalizedPath;
45658
+ if (!normalizedRoot) return void 0;
45659
+ return `${normalizedRoot}/${normalizedPath.replace(/^[\\/]+/, "")}`;
45660
+ }
45661
+ function readGitSubmodules(value, parentRepoRoot) {
45654
45662
  if (!Array.isArray(value)) return void 0;
45655
45663
  const submodules = value.map((entry) => {
45656
45664
  const submodule = readObjectRecord(entry);
45657
45665
  const path35 = readStringValue(submodule.path);
45658
45666
  const commit = readStringValue(submodule.commit);
45659
- const repoPath = readStringValue(submodule.repoPath, submodule.repo_root);
45667
+ const repoPath = readStringValue(submodule.repoPath, submodule.repo_root) ?? joinRepoPath(parentRepoRoot, path35);
45660
45668
  if (!path35 || !commit || !repoPath) return null;
45661
45669
  return {
45662
45670
  path: path35,
@@ -45676,10 +45684,11 @@ function normalizeInlineMeshGitStatus(status, node, options) {
45676
45684
  const conflictFiles = Array.isArray(status.conflictFiles) ? status.conflictFiles.filter((value) => typeof value === "string") : [];
45677
45685
  const conflictCount = readNumberValue(status.conflicts) ?? conflictFiles.length;
45678
45686
  const hasConflicts = readBooleanValue(status.hasConflicts) ?? conflictCount > 0;
45679
- const submodules = readGitSubmodules(status.submodules);
45687
+ const repoRoot = readStringValue(status.repoRoot, status.repo_root, node?.repoRoot, node?.repo_root, status.workspace, node?.workspace) || void 0;
45688
+ const submodules = readGitSubmodules(status.submodules, repoRoot);
45680
45689
  return {
45681
45690
  workspace: readStringValue(status.workspace, node?.workspace) || "",
45682
- repoRoot: readStringValue(status.repoRoot, node?.repoRoot, node?.workspace) || null,
45691
+ repoRoot: repoRoot ?? null,
45683
45692
  isGitRepo,
45684
45693
  branch: readStringValue(status.branch) ?? null,
45685
45694
  headCommit: readStringValue(status.headCommit) ?? null,
@@ -45712,6 +45721,26 @@ function buildInlineMeshTransitGitStatus(node) {
45712
45721
  const status = Object.keys(directStatus).length ? directStatus : Object.keys(nestedStatus).length ? nestedStatus : Object.keys(probeDirectStatus).length ? probeDirectStatus : Object.keys(probeNestedStatus).length ? probeNestedStatus : {};
45713
45722
  return normalizeInlineMeshGitStatus(status, node, { lastCheckedAt: Date.now() });
45714
45723
  }
45724
+ function recordInlineMeshDirectGitTruth(node, git, source) {
45725
+ if (!node || typeof node !== "object" || Array.isArray(node)) return;
45726
+ const checkedAt = readNumberValue(git.lastCheckedAt) ?? Date.now();
45727
+ const updatedAt = new Date(checkedAt).toISOString();
45728
+ const nextGit = {
45729
+ ...git,
45730
+ lastCheckedAt: checkedAt
45731
+ };
45732
+ node.lastGit = {
45733
+ source,
45734
+ checkedAt,
45735
+ status: nextGit
45736
+ };
45737
+ node.last_git = node.lastGit;
45738
+ node.machineStatus = "online";
45739
+ node.updatedAt = updatedAt;
45740
+ node.lastSeenAt = updatedAt;
45741
+ const repoRoot = readStringValue(nextGit.repoRoot);
45742
+ if (repoRoot && !readStringValue(node.repoRoot)) node.repoRoot = repoRoot;
45743
+ }
45715
45744
  function buildCachedInlineMeshGitStatus(node) {
45716
45745
  const liveGit = buildInlineMeshTransitGitStatus(node);
45717
45746
  if (liveGit) return liveGit;
@@ -45754,7 +45783,6 @@ function stripInlineMeshTransientNodeState(node) {
45754
45783
  session_id: _sessionIdLegacy,
45755
45784
  providerType: _providerType,
45756
45785
  provider_type: _providerTypeLegacy,
45757
- providers: _providers,
45758
45786
  ...rest
45759
45787
  } = node;
45760
45788
  if (cachedStatus && !shouldDiscardCachedInlineMeshStatus(node)) {
@@ -45764,7 +45792,7 @@ function stripInlineMeshTransientNodeState(node) {
45764
45792
  }
45765
45793
  function hasInlineMeshTransientNodeState(node) {
45766
45794
  if (!node || typeof node !== "object" || Array.isArray(node)) return false;
45767
- 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;
45795
+ 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;
45768
45796
  }
45769
45797
  function readInlineMeshNodeId(node) {
45770
45798
  return readStringValue(node?.id, node?.nodeId) || "";
@@ -45890,6 +45918,109 @@ function toIsoTimestamp(value) {
45890
45918
  const stringValue = readStringValue(value);
45891
45919
  return stringValue || null;
45892
45920
  }
45921
+ function synthesizeMeshNodeFreshnessFromConnection(status) {
45922
+ const connection = readObjectRecord(status.connection);
45923
+ const connectionFreshAt = toIsoTimestamp(connection.lastCommandAt ?? connection.lastConnectedAt ?? connection.lastStateChangeAt);
45924
+ const git = readObjectRecord(status.git);
45925
+ const gitCheckedAt = toIsoTimestamp(git.lastCheckedAt);
45926
+ if (!status.lastSeenAt && connectionFreshAt) status.lastSeenAt = connectionFreshAt;
45927
+ if (!status.updatedAt && (gitCheckedAt || connectionFreshAt)) {
45928
+ status.updatedAt = gitCheckedAt ?? connectionFreshAt;
45929
+ }
45930
+ }
45931
+ function finalizeMeshNodeStatus(args) {
45932
+ const { status, node, daemonId, isSelfNode } = args;
45933
+ if (!readStringValue(status.machineStatus)) {
45934
+ const cachedStatus = readObjectRecord(node?.cachedStatus);
45935
+ const machineStatus = readStringValue(cachedStatus.machineStatus, cachedStatus.machine_status, node?.machineStatus);
45936
+ if (machineStatus) status.machineStatus = machineStatus;
45937
+ }
45938
+ synthesizeMeshNodeFreshnessFromConnection(status);
45939
+ const connectionState = readStringValue(readObjectRecord(status.connection).state);
45940
+ status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || connectionState === "connected" || isSelfNode);
45941
+ }
45942
+ async function probeRemoteMeshGitStatus(args) {
45943
+ if (!args.dispatchMeshCommand) return null;
45944
+ const remoteResult = await Promise.race([
45945
+ args.dispatchMeshCommand(args.daemonId, "git_status", { workspace: args.workspace }),
45946
+ new Promise((_2, reject) => setTimeout(() => reject(new Error("timeout")), args.timeoutMs))
45947
+ ]);
45948
+ const remoteGit = remoteResult?.status ?? remoteResult?.git ?? remoteResult;
45949
+ return remoteGit && typeof remoteGit === "object" && typeof remoteGit.isGitRepo === "boolean" ? remoteGit : null;
45950
+ }
45951
+ async function hydrateInlineMeshDirectTruth(args) {
45952
+ const nodes = Array.isArray(args.mesh?.nodes) ? args.mesh.nodes : [];
45953
+ if (!nodes.length) {
45954
+ return {
45955
+ directEvidenceCount: 0,
45956
+ localConfirmedCount: 0,
45957
+ peerAttemptedCount: 0,
45958
+ peerConfirmedCount: 0,
45959
+ unavailableNodeIds: []
45960
+ };
45961
+ }
45962
+ const selectedCoordinatorNodeId = readStringValue(
45963
+ args.mesh?.coordinator?.preferredNodeId,
45964
+ nodes[0]?.id,
45965
+ nodes[0]?.nodeId
45966
+ );
45967
+ let localConfirmedCount = 0;
45968
+ let peerAttemptedCount = 0;
45969
+ let peerConfirmedCount = 0;
45970
+ const unavailableNodeIds = [];
45971
+ for (const [nodeIndex, node] of nodes.entries()) {
45972
+ const nodeId = readStringValue(node?.id, node?.nodeId) || `node_${nodeIndex}`;
45973
+ const workspace = readStringValue(node?.workspace);
45974
+ const daemonId = readStringValue(node?.daemonId);
45975
+ const isSelfNode = Boolean(
45976
+ nodeId && selectedCoordinatorNodeId && nodeId === selectedCoordinatorNodeId
45977
+ ) || Boolean(
45978
+ daemonId && (daemonId === args.localMachineId || daemonId === args.statusInstanceId)
45979
+ ) || Boolean(args.meshSource !== "local_config" && nodeIndex === 0);
45980
+ if (!workspace) {
45981
+ if (!isSelfNode && daemonId) unavailableNodeIds.push(nodeId);
45982
+ continue;
45983
+ }
45984
+ if (isSelfNode && fs10.existsSync(workspace)) {
45985
+ try {
45986
+ const localGit = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
45987
+ if (localGit?.isGitRepo) {
45988
+ recordInlineMeshDirectGitTruth(node, localGit, "selected_coordinator_local_git");
45989
+ localConfirmedCount += 1;
45990
+ continue;
45991
+ }
45992
+ } catch {
45993
+ }
45994
+ }
45995
+ if (!daemonId || !args.dispatchMeshCommand) {
45996
+ if (!isSelfNode) unavailableNodeIds.push(nodeId);
45997
+ continue;
45998
+ }
45999
+ peerAttemptedCount += 1;
46000
+ try {
46001
+ const remoteGit = await probeRemoteMeshGitStatus({
46002
+ dispatchMeshCommand: args.dispatchMeshCommand,
46003
+ daemonId,
46004
+ workspace,
46005
+ timeoutMs: 8e3
46006
+ });
46007
+ if (remoteGit) {
46008
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
46009
+ peerConfirmedCount += 1;
46010
+ continue;
46011
+ }
46012
+ } catch {
46013
+ }
46014
+ unavailableNodeIds.push(nodeId);
46015
+ }
46016
+ return {
46017
+ directEvidenceCount: localConfirmedCount + peerConfirmedCount,
46018
+ localConfirmedCount,
46019
+ peerAttemptedCount,
46020
+ peerConfirmedCount,
46021
+ unavailableNodeIds
46022
+ };
46023
+ }
45893
46024
  function summarizeMeshSessionRecord(record2) {
45894
46025
  return {
45895
46026
  sessionId: readStringValue(record2?.sessionId) || "unknown",
@@ -47438,8 +47569,38 @@ var init_router = __esm({
47438
47569
  const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
47439
47570
  if (!meshId) return { success: false, error: "meshId required" };
47440
47571
  const meshRecord = await this.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
47441
- if (meshRecord?.mesh) return { success: true, mesh: meshRecord.mesh };
47442
- return { success: false, error: "Mesh not found" };
47572
+ if (!meshRecord?.mesh) return { success: false, error: "Mesh not found" };
47573
+ const requireDirectPeerTruth = args?.requireDirectPeerTruth === true;
47574
+ const directTruth = await hydrateInlineMeshDirectTruth({
47575
+ mesh: meshRecord.mesh,
47576
+ meshSource: meshRecord.source,
47577
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
47578
+ statusInstanceId: this.deps.statusInstanceId,
47579
+ localMachineId: loadConfig().machineId || ""
47580
+ });
47581
+ const directTruthSatisfied = meshRecord.source !== "inline_bootstrap" || directTruth.directEvidenceCount > 0;
47582
+ const sourceOfTruth = {
47583
+ membership: meshRecord.source === "inline_cache" ? "coordinator_inline_mesh_cache" : meshRecord.source === "local_config" ? "local_mesh_config" : "inline_bootstrap_snapshot",
47584
+ coordinatorOwnsLiveTruth: directTruthSatisfied,
47585
+ directPeerTruth: {
47586
+ required: requireDirectPeerTruth,
47587
+ satisfied: directTruthSatisfied,
47588
+ directEvidenceCount: directTruth.directEvidenceCount,
47589
+ localConfirmedCount: directTruth.localConfirmedCount,
47590
+ peerAttemptedCount: directTruth.peerAttemptedCount,
47591
+ peerConfirmedCount: directTruth.peerConfirmedCount,
47592
+ unavailableNodeIds: directTruth.unavailableNodeIds
47593
+ }
47594
+ };
47595
+ if (requireDirectPeerTruth && !directTruthSatisfied) {
47596
+ return {
47597
+ success: false,
47598
+ code: "mesh_direct_peer_truth_unavailable",
47599
+ error: "Selected coordinator could not confirm direct mesh truth yet. Bootstrap inventory stays unavailable until direct get_mesh probes succeed.",
47600
+ sourceOfTruth
47601
+ };
47602
+ }
47603
+ return { success: true, mesh: meshRecord.mesh, sourceOfTruth };
47443
47604
  }
47444
47605
  case "create_mesh": {
47445
47606
  const name = typeof args?.name === "string" ? args.name.trim() : "";
@@ -48367,25 +48528,51 @@ ${block}`);
48367
48528
  }
48368
48529
  if (workspace) {
48369
48530
  if (!fs10.existsSync(workspace)) {
48531
+ const inlineTransitGit = buildInlineMeshTransitGitStatus(node);
48370
48532
  let remoteProbeApplied = false;
48371
- if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand) {
48533
+ if (inlineTransitGit) {
48534
+ status.git = inlineTransitGit;
48535
+ status.health = inlineTransitGit.isGitRepo ? deriveMeshNodeHealthFromGit(inlineTransitGit) : "degraded";
48536
+ remoteProbeApplied = true;
48537
+ } else if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand) {
48372
48538
  try {
48373
- const remoteResult = await Promise.race([
48374
- this.deps.dispatchMeshCommand(daemonId, "git_status", { workspace }),
48375
- new Promise((_2, reject) => setTimeout(() => reject(new Error("timeout")), 8e3))
48376
- ]);
48377
- const remoteGit = remoteResult?.status ?? remoteResult?.git ?? remoteResult;
48378
- if (remoteGit && typeof remoteGit === "object" && typeof remoteGit.isGitRepo === "boolean") {
48539
+ const remoteGit = await probeRemoteMeshGitStatus({
48540
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
48541
+ daemonId,
48542
+ workspace,
48543
+ timeoutMs: 8e3
48544
+ });
48545
+ if (remoteGit) {
48379
48546
  status.git = remoteGit;
48380
48547
  status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
48548
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
48381
48549
  remoteProbeApplied = true;
48382
48550
  }
48383
48551
  } catch {
48552
+ const refreshedConnection = this.deps.getMeshPeerConnectionStatus?.(daemonId);
48553
+ const refreshedConnectionState = readStringValue(refreshedConnection?.state);
48554
+ if (refreshedConnection && refreshedConnectionState === "connected") {
48555
+ status.connection = refreshedConnection;
48556
+ try {
48557
+ const remoteGit = await probeRemoteMeshGitStatus({
48558
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
48559
+ daemonId,
48560
+ workspace,
48561
+ timeoutMs: 12e3
48562
+ });
48563
+ if (remoteGit) {
48564
+ status.git = remoteGit;
48565
+ status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
48566
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
48567
+ remoteProbeApplied = true;
48568
+ }
48569
+ } catch {
48570
+ }
48571
+ }
48384
48572
  }
48385
48573
  }
48386
48574
  if (!remoteProbeApplied) {
48387
48575
  const connectionState = readStringValue(status.connection?.state);
48388
- const inlineTransitGit = buildInlineMeshTransitGitStatus(node);
48389
48576
  const pendingPeerGitProbe = !inlineTransitGit && !isSelfNode && !!daemonId && (readStringValue(status.machineStatus) === "online" || readStringValue(status.health) === "online" || connectionState === "connecting" || connectionState === "connected" || connectionState === "unknown");
48390
48577
  if (pendingPeerGitProbe) {
48391
48578
  status.gitProbePending = true;
@@ -48396,12 +48583,12 @@ ${block}`);
48396
48583
  node,
48397
48584
  pendingPeerGitProbe ? { skipGit: true, skipError: true, skipHealth: true } : void 0
48398
48585
  )) {
48399
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
48586
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
48400
48587
  nodeStatuses.push(status);
48401
48588
  continue;
48402
48589
  }
48403
48590
  if (meshRecord?.source === "inline_cache" && !isSelfNode) {
48404
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
48591
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
48405
48592
  nodeStatuses.push(status);
48406
48593
  continue;
48407
48594
  }
@@ -48410,6 +48597,7 @@ ${block}`);
48410
48597
  try {
48411
48598
  const gitStatus = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
48412
48599
  status.git = gitStatus;
48600
+ recordInlineMeshDirectGitTruth(node, gitStatus, "selected_coordinator_local_git");
48413
48601
  if (gitStatus.isGitRepo) {
48414
48602
  status.health = deriveMeshNodeHealthFromGit(gitStatus);
48415
48603
  } else {
@@ -48425,7 +48613,7 @@ ${block}`);
48425
48613
  } else {
48426
48614
  applyCachedInlineMeshNodeStatus(status, node);
48427
48615
  }
48428
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
48616
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
48429
48617
  nodeStatuses.push(status);
48430
48618
  }
48431
48619
  return {
@@ -67283,7 +67471,7 @@ var init_adhdev_daemon = __esm({
67283
67471
  init_version();
67284
67472
  init_src();
67285
67473
  init_runtime_defaults();
67286
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.82-rc.30" });
67474
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.82-rc.31" });
67287
67475
  AdhdevDaemon = class _AdhdevDaemon {
67288
67476
  localHttpServer = null;
67289
67477
  localWss = null;