adhdev 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/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,12 @@ 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;
46784
+ }
46785
+ function inlineMeshCarriesTransientNodeTruth(inlineMesh) {
46786
+ if (!inlineMesh || typeof inlineMesh !== "object" || Array.isArray(inlineMesh)) return false;
46787
+ if (!Array.isArray(inlineMesh.nodes) || inlineMesh.nodes.length === 0) return false;
46788
+ return inlineMesh.nodes.some((node) => hasInlineMeshTransientNodeState(node));
46756
46789
  }
46757
46790
  function readInlineMeshNodeId(node) {
46758
46791
  return readStringValue(node?.id, node?.nodeId) || "";
@@ -46878,6 +46911,109 @@ function toIsoTimestamp(value) {
46878
46911
  const stringValue = readStringValue(value);
46879
46912
  return stringValue || null;
46880
46913
  }
46914
+ function synthesizeMeshNodeFreshnessFromConnection(status) {
46915
+ const connection = readObjectRecord(status.connection);
46916
+ const connectionFreshAt = toIsoTimestamp(connection.lastCommandAt ?? connection.lastConnectedAt ?? connection.lastStateChangeAt);
46917
+ const git = readObjectRecord(status.git);
46918
+ const gitCheckedAt = toIsoTimestamp(git.lastCheckedAt);
46919
+ if (!status.lastSeenAt && connectionFreshAt) status.lastSeenAt = connectionFreshAt;
46920
+ if (!status.updatedAt && (gitCheckedAt || connectionFreshAt)) {
46921
+ status.updatedAt = gitCheckedAt ?? connectionFreshAt;
46922
+ }
46923
+ }
46924
+ function finalizeMeshNodeStatus(args) {
46925
+ const { status, node, daemonId, isSelfNode } = args;
46926
+ if (!readStringValue(status.machineStatus)) {
46927
+ const cachedStatus = readObjectRecord(node?.cachedStatus);
46928
+ const machineStatus = readStringValue(cachedStatus.machineStatus, cachedStatus.machine_status, node?.machineStatus);
46929
+ if (machineStatus) status.machineStatus = machineStatus;
46930
+ }
46931
+ synthesizeMeshNodeFreshnessFromConnection(status);
46932
+ const connectionState = readStringValue(readObjectRecord(status.connection).state);
46933
+ status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || connectionState === "connected" || isSelfNode);
46934
+ }
46935
+ async function probeRemoteMeshGitStatus(args) {
46936
+ if (!args.dispatchMeshCommand) return null;
46937
+ const remoteResult = await Promise.race([
46938
+ args.dispatchMeshCommand(args.daemonId, "git_status", { workspace: args.workspace }),
46939
+ new Promise((_2, reject) => setTimeout(() => reject(new Error("timeout")), args.timeoutMs))
46940
+ ]);
46941
+ const remoteGit = remoteResult?.status ?? remoteResult?.git ?? remoteResult;
46942
+ return remoteGit && typeof remoteGit === "object" && typeof remoteGit.isGitRepo === "boolean" ? remoteGit : null;
46943
+ }
46944
+ async function hydrateInlineMeshDirectTruth(args) {
46945
+ const nodes = Array.isArray(args.mesh?.nodes) ? args.mesh.nodes : [];
46946
+ if (!nodes.length) {
46947
+ return {
46948
+ directEvidenceCount: 0,
46949
+ localConfirmedCount: 0,
46950
+ peerAttemptedCount: 0,
46951
+ peerConfirmedCount: 0,
46952
+ unavailableNodeIds: []
46953
+ };
46954
+ }
46955
+ const selectedCoordinatorNodeId = readStringValue(
46956
+ args.mesh?.coordinator?.preferredNodeId,
46957
+ nodes[0]?.id,
46958
+ nodes[0]?.nodeId
46959
+ );
46960
+ let localConfirmedCount = 0;
46961
+ let peerAttemptedCount = 0;
46962
+ let peerConfirmedCount = 0;
46963
+ const unavailableNodeIds = [];
46964
+ for (const [nodeIndex, node] of nodes.entries()) {
46965
+ const nodeId = readStringValue(node?.id, node?.nodeId) || `node_${nodeIndex}`;
46966
+ const workspace = readStringValue(node?.workspace);
46967
+ const daemonId = readStringValue(node?.daemonId);
46968
+ const isSelfNode = Boolean(
46969
+ nodeId && selectedCoordinatorNodeId && nodeId === selectedCoordinatorNodeId
46970
+ ) || Boolean(
46971
+ daemonId && (daemonId === args.localMachineId || daemonId === args.statusInstanceId)
46972
+ ) || Boolean(args.meshSource !== "local_config" && nodeIndex === 0);
46973
+ if (!workspace) {
46974
+ if (!isSelfNode && daemonId) unavailableNodeIds.push(nodeId);
46975
+ continue;
46976
+ }
46977
+ if (isSelfNode && fs10.existsSync(workspace)) {
46978
+ try {
46979
+ const localGit = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
46980
+ if (localGit?.isGitRepo) {
46981
+ recordInlineMeshDirectGitTruth(node, localGit, "selected_coordinator_local_git");
46982
+ localConfirmedCount += 1;
46983
+ continue;
46984
+ }
46985
+ } catch {
46986
+ }
46987
+ }
46988
+ if (!daemonId || !args.dispatchMeshCommand) {
46989
+ if (!isSelfNode) unavailableNodeIds.push(nodeId);
46990
+ continue;
46991
+ }
46992
+ peerAttemptedCount += 1;
46993
+ try {
46994
+ const remoteGit = await probeRemoteMeshGitStatus({
46995
+ dispatchMeshCommand: args.dispatchMeshCommand,
46996
+ daemonId,
46997
+ workspace,
46998
+ timeoutMs: 8e3
46999
+ });
47000
+ if (remoteGit) {
47001
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
47002
+ peerConfirmedCount += 1;
47003
+ continue;
47004
+ }
47005
+ } catch {
47006
+ }
47007
+ unavailableNodeIds.push(nodeId);
47008
+ }
47009
+ return {
47010
+ directEvidenceCount: localConfirmedCount + peerConfirmedCount,
47011
+ localConfirmedCount,
47012
+ peerAttemptedCount,
47013
+ peerConfirmedCount,
47014
+ unavailableNodeIds
47015
+ };
47016
+ }
46881
47017
  function summarizeMeshSessionRecord(record2) {
46882
47018
  return {
46883
47019
  sessionId: readStringValue(record2?.sessionId) || "unknown",
@@ -47417,8 +47553,10 @@ var init_router = __esm({
47417
47553
  if (preferInline) {
47418
47554
  const cached3 = this.getCachedInlineMesh(meshId);
47419
47555
  if (cached3) return { mesh: cached3, inline: true, source: "inline_cache" };
47420
- const warmedInline2 = this.warmInlineMeshCache(meshId, inlineMesh);
47421
- if (warmedInline2) return { mesh: warmedInline2, inline: true, source: "inline_bootstrap" };
47556
+ if (inlineMeshCarriesTransientNodeTruth(inlineMesh)) {
47557
+ this.warmInlineMeshCache(meshId, inlineMesh);
47558
+ return { mesh: inlineMesh, inline: true, source: "inline_bootstrap" };
47559
+ }
47422
47560
  }
47423
47561
  try {
47424
47562
  const { getMesh: getMesh3 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
@@ -48426,8 +48564,38 @@ var init_router = __esm({
48426
48564
  const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
48427
48565
  if (!meshId) return { success: false, error: "meshId required" };
48428
48566
  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" };
48567
+ if (!meshRecord?.mesh) return { success: false, error: "Mesh not found" };
48568
+ const requireDirectPeerTruth = args?.requireDirectPeerTruth === true;
48569
+ const directTruth = await hydrateInlineMeshDirectTruth({
48570
+ mesh: meshRecord.mesh,
48571
+ meshSource: meshRecord.source,
48572
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
48573
+ statusInstanceId: this.deps.statusInstanceId,
48574
+ localMachineId: loadConfig().machineId || ""
48575
+ });
48576
+ const directTruthSatisfied = meshRecord.source !== "inline_bootstrap" || directTruth.directEvidenceCount > 0;
48577
+ const sourceOfTruth = {
48578
+ membership: meshRecord.source === "inline_cache" ? "coordinator_inline_mesh_cache" : meshRecord.source === "local_config" ? "local_mesh_config" : "inline_bootstrap_snapshot",
48579
+ coordinatorOwnsLiveTruth: directTruthSatisfied,
48580
+ directPeerTruth: {
48581
+ required: requireDirectPeerTruth,
48582
+ satisfied: directTruthSatisfied,
48583
+ directEvidenceCount: directTruth.directEvidenceCount,
48584
+ localConfirmedCount: directTruth.localConfirmedCount,
48585
+ peerAttemptedCount: directTruth.peerAttemptedCount,
48586
+ peerConfirmedCount: directTruth.peerConfirmedCount,
48587
+ unavailableNodeIds: directTruth.unavailableNodeIds
48588
+ }
48589
+ };
48590
+ if (requireDirectPeerTruth && !directTruthSatisfied) {
48591
+ return {
48592
+ success: false,
48593
+ code: "mesh_direct_peer_truth_unavailable",
48594
+ error: "Selected coordinator could not confirm direct mesh truth yet. Bootstrap inventory stays unavailable until direct get_mesh probes succeed.",
48595
+ sourceOfTruth
48596
+ };
48597
+ }
48598
+ return { success: true, mesh: meshRecord.mesh, sourceOfTruth };
48431
48599
  }
48432
48600
  case "create_mesh": {
48433
48601
  const name = typeof args?.name === "string" ? args.name.trim() : "";
@@ -49355,25 +49523,51 @@ ${block}`);
49355
49523
  }
49356
49524
  if (workspace) {
49357
49525
  if (!fs10.existsSync(workspace)) {
49526
+ const inlineTransitGit = buildInlineMeshTransitGitStatus(node);
49358
49527
  let remoteProbeApplied = false;
49359
- if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand) {
49528
+ if (inlineTransitGit) {
49529
+ status.git = inlineTransitGit;
49530
+ status.health = inlineTransitGit.isGitRepo ? deriveMeshNodeHealthFromGit(inlineTransitGit) : "degraded";
49531
+ remoteProbeApplied = true;
49532
+ } else if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand) {
49360
49533
  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") {
49534
+ const remoteGit = await probeRemoteMeshGitStatus({
49535
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
49536
+ daemonId,
49537
+ workspace,
49538
+ timeoutMs: 8e3
49539
+ });
49540
+ if (remoteGit) {
49367
49541
  status.git = remoteGit;
49368
49542
  status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
49543
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
49369
49544
  remoteProbeApplied = true;
49370
49545
  }
49371
49546
  } catch {
49547
+ const refreshedConnection = this.deps.getMeshPeerConnectionStatus?.(daemonId);
49548
+ const refreshedConnectionState = readStringValue(refreshedConnection?.state);
49549
+ if (refreshedConnection && refreshedConnectionState === "connected") {
49550
+ status.connection = refreshedConnection;
49551
+ try {
49552
+ const remoteGit = await probeRemoteMeshGitStatus({
49553
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
49554
+ daemonId,
49555
+ workspace,
49556
+ timeoutMs: 12e3
49557
+ });
49558
+ if (remoteGit) {
49559
+ status.git = remoteGit;
49560
+ status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
49561
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
49562
+ remoteProbeApplied = true;
49563
+ }
49564
+ } catch {
49565
+ }
49566
+ }
49372
49567
  }
49373
49568
  }
49374
49569
  if (!remoteProbeApplied) {
49375
49570
  const connectionState = readStringValue(status.connection?.state);
49376
- const inlineTransitGit = buildInlineMeshTransitGitStatus(node);
49377
49571
  const pendingPeerGitProbe = !inlineTransitGit && !isSelfNode && !!daemonId && (readStringValue(status.machineStatus) === "online" || readStringValue(status.health) === "online" || connectionState === "connecting" || connectionState === "connected" || connectionState === "unknown");
49378
49572
  if (pendingPeerGitProbe) {
49379
49573
  status.gitProbePending = true;
@@ -49384,12 +49578,12 @@ ${block}`);
49384
49578
  node,
49385
49579
  pendingPeerGitProbe ? { skipGit: true, skipError: true, skipHealth: true } : void 0
49386
49580
  )) {
49387
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
49581
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
49388
49582
  nodeStatuses.push(status);
49389
49583
  continue;
49390
49584
  }
49391
49585
  if (meshRecord?.source === "inline_cache" && !isSelfNode) {
49392
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
49586
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
49393
49587
  nodeStatuses.push(status);
49394
49588
  continue;
49395
49589
  }
@@ -49398,6 +49592,7 @@ ${block}`);
49398
49592
  try {
49399
49593
  const gitStatus = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
49400
49594
  status.git = gitStatus;
49595
+ recordInlineMeshDirectGitTruth(node, gitStatus, "selected_coordinator_local_git");
49401
49596
  if (gitStatus.isGitRepo) {
49402
49597
  status.health = deriveMeshNodeHealthFromGit(gitStatus);
49403
49598
  } else {
@@ -49413,7 +49608,7 @@ ${block}`);
49413
49608
  } else {
49414
49609
  applyCachedInlineMeshNodeStatus(status, node);
49415
49610
  }
49416
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
49611
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
49417
49612
  nodeStatuses.push(status);
49418
49613
  }
49419
49614
  return {
@@ -98456,7 +98651,7 @@ var init_adhdev_daemon = __esm({
98456
98651
  init_version();
98457
98652
  init_src();
98458
98653
  init_runtime_defaults();
98459
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.82-rc.30" });
98654
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.82-rc.32" });
98460
98655
  AdhdevDaemon = class _AdhdevDaemon {
98461
98656
  localHttpServer = null;
98462
98657
  localWss = null;