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/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,12 @@ 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;
45796
+ }
45797
+ function inlineMeshCarriesTransientNodeTruth(inlineMesh) {
45798
+ if (!inlineMesh || typeof inlineMesh !== "object" || Array.isArray(inlineMesh)) return false;
45799
+ if (!Array.isArray(inlineMesh.nodes) || inlineMesh.nodes.length === 0) return false;
45800
+ return inlineMesh.nodes.some((node) => hasInlineMeshTransientNodeState(node));
45768
45801
  }
45769
45802
  function readInlineMeshNodeId(node) {
45770
45803
  return readStringValue(node?.id, node?.nodeId) || "";
@@ -45890,6 +45923,109 @@ function toIsoTimestamp(value) {
45890
45923
  const stringValue = readStringValue(value);
45891
45924
  return stringValue || null;
45892
45925
  }
45926
+ function synthesizeMeshNodeFreshnessFromConnection(status) {
45927
+ const connection = readObjectRecord(status.connection);
45928
+ const connectionFreshAt = toIsoTimestamp(connection.lastCommandAt ?? connection.lastConnectedAt ?? connection.lastStateChangeAt);
45929
+ const git = readObjectRecord(status.git);
45930
+ const gitCheckedAt = toIsoTimestamp(git.lastCheckedAt);
45931
+ if (!status.lastSeenAt && connectionFreshAt) status.lastSeenAt = connectionFreshAt;
45932
+ if (!status.updatedAt && (gitCheckedAt || connectionFreshAt)) {
45933
+ status.updatedAt = gitCheckedAt ?? connectionFreshAt;
45934
+ }
45935
+ }
45936
+ function finalizeMeshNodeStatus(args) {
45937
+ const { status, node, daemonId, isSelfNode } = args;
45938
+ if (!readStringValue(status.machineStatus)) {
45939
+ const cachedStatus = readObjectRecord(node?.cachedStatus);
45940
+ const machineStatus = readStringValue(cachedStatus.machineStatus, cachedStatus.machine_status, node?.machineStatus);
45941
+ if (machineStatus) status.machineStatus = machineStatus;
45942
+ }
45943
+ synthesizeMeshNodeFreshnessFromConnection(status);
45944
+ const connectionState = readStringValue(readObjectRecord(status.connection).state);
45945
+ status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || connectionState === "connected" || isSelfNode);
45946
+ }
45947
+ async function probeRemoteMeshGitStatus(args) {
45948
+ if (!args.dispatchMeshCommand) return null;
45949
+ const remoteResult = await Promise.race([
45950
+ args.dispatchMeshCommand(args.daemonId, "git_status", { workspace: args.workspace }),
45951
+ new Promise((_2, reject) => setTimeout(() => reject(new Error("timeout")), args.timeoutMs))
45952
+ ]);
45953
+ const remoteGit = remoteResult?.status ?? remoteResult?.git ?? remoteResult;
45954
+ return remoteGit && typeof remoteGit === "object" && typeof remoteGit.isGitRepo === "boolean" ? remoteGit : null;
45955
+ }
45956
+ async function hydrateInlineMeshDirectTruth(args) {
45957
+ const nodes = Array.isArray(args.mesh?.nodes) ? args.mesh.nodes : [];
45958
+ if (!nodes.length) {
45959
+ return {
45960
+ directEvidenceCount: 0,
45961
+ localConfirmedCount: 0,
45962
+ peerAttemptedCount: 0,
45963
+ peerConfirmedCount: 0,
45964
+ unavailableNodeIds: []
45965
+ };
45966
+ }
45967
+ const selectedCoordinatorNodeId = readStringValue(
45968
+ args.mesh?.coordinator?.preferredNodeId,
45969
+ nodes[0]?.id,
45970
+ nodes[0]?.nodeId
45971
+ );
45972
+ let localConfirmedCount = 0;
45973
+ let peerAttemptedCount = 0;
45974
+ let peerConfirmedCount = 0;
45975
+ const unavailableNodeIds = [];
45976
+ for (const [nodeIndex, node] of nodes.entries()) {
45977
+ const nodeId = readStringValue(node?.id, node?.nodeId) || `node_${nodeIndex}`;
45978
+ const workspace = readStringValue(node?.workspace);
45979
+ const daemonId = readStringValue(node?.daemonId);
45980
+ const isSelfNode = Boolean(
45981
+ nodeId && selectedCoordinatorNodeId && nodeId === selectedCoordinatorNodeId
45982
+ ) || Boolean(
45983
+ daemonId && (daemonId === args.localMachineId || daemonId === args.statusInstanceId)
45984
+ ) || Boolean(args.meshSource !== "local_config" && nodeIndex === 0);
45985
+ if (!workspace) {
45986
+ if (!isSelfNode && daemonId) unavailableNodeIds.push(nodeId);
45987
+ continue;
45988
+ }
45989
+ if (isSelfNode && fs10.existsSync(workspace)) {
45990
+ try {
45991
+ const localGit = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
45992
+ if (localGit?.isGitRepo) {
45993
+ recordInlineMeshDirectGitTruth(node, localGit, "selected_coordinator_local_git");
45994
+ localConfirmedCount += 1;
45995
+ continue;
45996
+ }
45997
+ } catch {
45998
+ }
45999
+ }
46000
+ if (!daemonId || !args.dispatchMeshCommand) {
46001
+ if (!isSelfNode) unavailableNodeIds.push(nodeId);
46002
+ continue;
46003
+ }
46004
+ peerAttemptedCount += 1;
46005
+ try {
46006
+ const remoteGit = await probeRemoteMeshGitStatus({
46007
+ dispatchMeshCommand: args.dispatchMeshCommand,
46008
+ daemonId,
46009
+ workspace,
46010
+ timeoutMs: 8e3
46011
+ });
46012
+ if (remoteGit) {
46013
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
46014
+ peerConfirmedCount += 1;
46015
+ continue;
46016
+ }
46017
+ } catch {
46018
+ }
46019
+ unavailableNodeIds.push(nodeId);
46020
+ }
46021
+ return {
46022
+ directEvidenceCount: localConfirmedCount + peerConfirmedCount,
46023
+ localConfirmedCount,
46024
+ peerAttemptedCount,
46025
+ peerConfirmedCount,
46026
+ unavailableNodeIds
46027
+ };
46028
+ }
45893
46029
  function summarizeMeshSessionRecord(record2) {
45894
46030
  return {
45895
46031
  sessionId: readStringValue(record2?.sessionId) || "unknown",
@@ -46429,8 +46565,10 @@ var init_router = __esm({
46429
46565
  if (preferInline) {
46430
46566
  const cached3 = this.getCachedInlineMesh(meshId);
46431
46567
  if (cached3) return { mesh: cached3, inline: true, source: "inline_cache" };
46432
- const warmedInline2 = this.warmInlineMeshCache(meshId, inlineMesh);
46433
- if (warmedInline2) return { mesh: warmedInline2, inline: true, source: "inline_bootstrap" };
46568
+ if (inlineMeshCarriesTransientNodeTruth(inlineMesh)) {
46569
+ this.warmInlineMeshCache(meshId, inlineMesh);
46570
+ return { mesh: inlineMesh, inline: true, source: "inline_bootstrap" };
46571
+ }
46434
46572
  }
46435
46573
  try {
46436
46574
  const { getMesh: getMesh3 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
@@ -47438,8 +47576,38 @@ var init_router = __esm({
47438
47576
  const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
47439
47577
  if (!meshId) return { success: false, error: "meshId required" };
47440
47578
  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" };
47579
+ if (!meshRecord?.mesh) return { success: false, error: "Mesh not found" };
47580
+ const requireDirectPeerTruth = args?.requireDirectPeerTruth === true;
47581
+ const directTruth = await hydrateInlineMeshDirectTruth({
47582
+ mesh: meshRecord.mesh,
47583
+ meshSource: meshRecord.source,
47584
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
47585
+ statusInstanceId: this.deps.statusInstanceId,
47586
+ localMachineId: loadConfig().machineId || ""
47587
+ });
47588
+ const directTruthSatisfied = meshRecord.source !== "inline_bootstrap" || directTruth.directEvidenceCount > 0;
47589
+ const sourceOfTruth = {
47590
+ membership: meshRecord.source === "inline_cache" ? "coordinator_inline_mesh_cache" : meshRecord.source === "local_config" ? "local_mesh_config" : "inline_bootstrap_snapshot",
47591
+ coordinatorOwnsLiveTruth: directTruthSatisfied,
47592
+ directPeerTruth: {
47593
+ required: requireDirectPeerTruth,
47594
+ satisfied: directTruthSatisfied,
47595
+ directEvidenceCount: directTruth.directEvidenceCount,
47596
+ localConfirmedCount: directTruth.localConfirmedCount,
47597
+ peerAttemptedCount: directTruth.peerAttemptedCount,
47598
+ peerConfirmedCount: directTruth.peerConfirmedCount,
47599
+ unavailableNodeIds: directTruth.unavailableNodeIds
47600
+ }
47601
+ };
47602
+ if (requireDirectPeerTruth && !directTruthSatisfied) {
47603
+ return {
47604
+ success: false,
47605
+ code: "mesh_direct_peer_truth_unavailable",
47606
+ error: "Selected coordinator could not confirm direct mesh truth yet. Bootstrap inventory stays unavailable until direct get_mesh probes succeed.",
47607
+ sourceOfTruth
47608
+ };
47609
+ }
47610
+ return { success: true, mesh: meshRecord.mesh, sourceOfTruth };
47443
47611
  }
47444
47612
  case "create_mesh": {
47445
47613
  const name = typeof args?.name === "string" ? args.name.trim() : "";
@@ -48367,25 +48535,51 @@ ${block}`);
48367
48535
  }
48368
48536
  if (workspace) {
48369
48537
  if (!fs10.existsSync(workspace)) {
48538
+ const inlineTransitGit = buildInlineMeshTransitGitStatus(node);
48370
48539
  let remoteProbeApplied = false;
48371
- if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand) {
48540
+ if (inlineTransitGit) {
48541
+ status.git = inlineTransitGit;
48542
+ status.health = inlineTransitGit.isGitRepo ? deriveMeshNodeHealthFromGit(inlineTransitGit) : "degraded";
48543
+ remoteProbeApplied = true;
48544
+ } else if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand) {
48372
48545
  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") {
48546
+ const remoteGit = await probeRemoteMeshGitStatus({
48547
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
48548
+ daemonId,
48549
+ workspace,
48550
+ timeoutMs: 8e3
48551
+ });
48552
+ if (remoteGit) {
48379
48553
  status.git = remoteGit;
48380
48554
  status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
48555
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
48381
48556
  remoteProbeApplied = true;
48382
48557
  }
48383
48558
  } catch {
48559
+ const refreshedConnection = this.deps.getMeshPeerConnectionStatus?.(daemonId);
48560
+ const refreshedConnectionState = readStringValue(refreshedConnection?.state);
48561
+ if (refreshedConnection && refreshedConnectionState === "connected") {
48562
+ status.connection = refreshedConnection;
48563
+ try {
48564
+ const remoteGit = await probeRemoteMeshGitStatus({
48565
+ dispatchMeshCommand: this.deps.dispatchMeshCommand,
48566
+ daemonId,
48567
+ workspace,
48568
+ timeoutMs: 12e3
48569
+ });
48570
+ if (remoteGit) {
48571
+ status.git = remoteGit;
48572
+ status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
48573
+ recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
48574
+ remoteProbeApplied = true;
48575
+ }
48576
+ } catch {
48577
+ }
48578
+ }
48384
48579
  }
48385
48580
  }
48386
48581
  if (!remoteProbeApplied) {
48387
48582
  const connectionState = readStringValue(status.connection?.state);
48388
- const inlineTransitGit = buildInlineMeshTransitGitStatus(node);
48389
48583
  const pendingPeerGitProbe = !inlineTransitGit && !isSelfNode && !!daemonId && (readStringValue(status.machineStatus) === "online" || readStringValue(status.health) === "online" || connectionState === "connecting" || connectionState === "connected" || connectionState === "unknown");
48390
48584
  if (pendingPeerGitProbe) {
48391
48585
  status.gitProbePending = true;
@@ -48396,12 +48590,12 @@ ${block}`);
48396
48590
  node,
48397
48591
  pendingPeerGitProbe ? { skipGit: true, skipError: true, skipHealth: true } : void 0
48398
48592
  )) {
48399
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
48593
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
48400
48594
  nodeStatuses.push(status);
48401
48595
  continue;
48402
48596
  }
48403
48597
  if (meshRecord?.source === "inline_cache" && !isSelfNode) {
48404
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
48598
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
48405
48599
  nodeStatuses.push(status);
48406
48600
  continue;
48407
48601
  }
@@ -48410,6 +48604,7 @@ ${block}`);
48410
48604
  try {
48411
48605
  const gitStatus = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
48412
48606
  status.git = gitStatus;
48607
+ recordInlineMeshDirectGitTruth(node, gitStatus, "selected_coordinator_local_git");
48413
48608
  if (gitStatus.isGitRepo) {
48414
48609
  status.health = deriveMeshNodeHealthFromGit(gitStatus);
48415
48610
  } else {
@@ -48425,7 +48620,7 @@ ${block}`);
48425
48620
  } else {
48426
48621
  applyCachedInlineMeshNodeStatus(status, node);
48427
48622
  }
48428
- status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
48623
+ finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
48429
48624
  nodeStatuses.push(status);
48430
48625
  }
48431
48626
  return {
@@ -67283,7 +67478,7 @@ var init_adhdev_daemon = __esm({
67283
67478
  init_version();
67284
67479
  init_src();
67285
67480
  init_runtime_defaults();
67286
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.82-rc.30" });
67481
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.82-rc.32" });
67287
67482
  AdhdevDaemon = class _AdhdevDaemon {
67288
67483
  localHttpServer = null;
67289
67484
  localWss = null;