adhdev 0.9.82-rc.43 → 0.9.82-rc.45

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,6 +46638,70 @@ function readBooleanValue(...values) {
46638
46638
  }
46639
46639
  return void 0;
46640
46640
  }
46641
+ function summarizeRepoMeshDebugGit(git) {
46642
+ const record2 = readObjectRecord(git);
46643
+ if (!Object.keys(record2).length) return null;
46644
+ const submodules = Array.isArray(record2.submodules) ? record2.submodules.map((entry) => ({
46645
+ path: readStringValue(entry?.path) ?? null,
46646
+ commit: readStringValue(entry?.commit)?.slice(0, 12) ?? null,
46647
+ dirty: readBooleanValue(entry?.dirty) ?? false,
46648
+ outOfSync: readBooleanValue(entry?.outOfSync, entry?.out_of_sync) ?? false
46649
+ })) : [];
46650
+ return {
46651
+ isGitRepo: readBooleanValue(record2.isGitRepo),
46652
+ workspace: readStringValue(record2.workspace) ?? null,
46653
+ repoRoot: readStringValue(record2.repoRoot, record2.repo_root) ?? null,
46654
+ branch: readStringValue(record2.branch) ?? null,
46655
+ upstream: readStringValue(record2.upstream) ?? null,
46656
+ upstreamStatus: readStringValue(record2.upstreamStatus, record2.upstream_status) ?? null,
46657
+ headCommit: readStringValue(record2.headCommit, record2.head_commit)?.slice(0, 12) ?? null,
46658
+ ahead: readNumberValue(record2.ahead) ?? null,
46659
+ behind: readNumberValue(record2.behind) ?? null,
46660
+ dirtyCounts: {
46661
+ staged: readNumberValue(record2.staged) ?? 0,
46662
+ modified: readNumberValue(record2.modified) ?? 0,
46663
+ untracked: readNumberValue(record2.untracked) ?? 0,
46664
+ deleted: readNumberValue(record2.deleted) ?? 0,
46665
+ renamed: readNumberValue(record2.renamed) ?? 0
46666
+ },
46667
+ lastCheckedAt: readNumberValue(record2.lastCheckedAt, record2.last_checked_at) ?? null,
46668
+ submoduleCount: submodules.length,
46669
+ submodules
46670
+ };
46671
+ }
46672
+ function summarizeRepoMeshStatusDebug(status) {
46673
+ const nodes = Array.isArray(status?.nodes) ? status.nodes : [];
46674
+ return {
46675
+ success: status?.success,
46676
+ meshId: readStringValue(status?.meshId, status?.mesh_id) ?? null,
46677
+ refreshedAt: readStringValue(status?.refreshedAt, status?.refreshed_at) ?? null,
46678
+ sourceOfTruth: status?.sourceOfTruth ?? null,
46679
+ nodeCount: nodes.length,
46680
+ nodes: nodes.map((node) => ({
46681
+ nodeId: readStringValue(node?.nodeId, node?.id) ?? null,
46682
+ daemonId: readStringValue(node?.daemonId, node?.daemon_id) ?? null,
46683
+ workspace: readStringValue(node?.workspace, node?.git?.workspace) ?? null,
46684
+ health: readStringValue(node?.health) ?? null,
46685
+ machineStatus: readStringValue(node?.machineStatus, node?.machine_status) ?? null,
46686
+ connection: node?.connection && typeof node.connection === "object" ? {
46687
+ state: readStringValue(node.connection.state) ?? null,
46688
+ transport: readStringValue(node.connection.transport) ?? null,
46689
+ source: readStringValue(node.connection.source) ?? null,
46690
+ reported: readBooleanValue(node.connection.reported) ?? null
46691
+ } : null,
46692
+ gitProbePending: node?.gitProbePending === true,
46693
+ launchReady: node?.launchReady === true,
46694
+ git: summarizeRepoMeshDebugGit(node?.git)
46695
+ }))
46696
+ };
46697
+ }
46698
+ function logRepoMeshStatusDebug(event, fields) {
46699
+ try {
46700
+ LOG.info("MeshStatusDebug", `[RepoMeshStatusDebug] ${JSON.stringify({ event, ...fields })}`);
46701
+ } catch {
46702
+ LOG.info("MeshStatusDebug", `[RepoMeshStatusDebug] ${event}`);
46703
+ }
46704
+ }
46641
46705
  function joinRepoPath(root, relativePath) {
46642
46706
  const normalizedRoot = typeof root === "string" ? root.trim().replace(/[\\/]+$/, "") : "";
46643
46707
  const normalizedPath = typeof relativePath === "string" ? relativePath.trim() : "";
@@ -46706,8 +46770,12 @@ function buildInlineMeshTransitGitStatus(node) {
46706
46770
  const probeGitResult = readObjectRecord(probeGit.result);
46707
46771
  const probeDirectStatus = readObjectRecord(probeGit.status);
46708
46772
  const probeNestedStatus = readObjectRecord(probeGitResult.status);
46709
- const status = Object.keys(directStatus).length ? directStatus : Object.keys(nestedStatus).length ? nestedStatus : Object.keys(probeDirectStatus).length ? probeDirectStatus : Object.keys(probeNestedStatus).length ? probeNestedStatus : {};
46710
- return normalizeInlineMeshGitStatus(status, node, { lastCheckedAt: Date.now() });
46773
+ const candidates = [directStatus, nestedStatus, probeDirectStatus, probeNestedStatus];
46774
+ for (const status of candidates) {
46775
+ const normalized = normalizeInlineMeshGitStatus(status, node, { lastCheckedAt: Date.now() });
46776
+ if (normalized) return normalized;
46777
+ }
46778
+ return void 0;
46711
46779
  }
46712
46780
  function recordInlineMeshDirectGitTruth(node, git, source) {
46713
46781
  if (!node || typeof node !== "object" || Array.isArray(node)) return;
@@ -47613,10 +47681,69 @@ var init_router = __esm({
47613
47681
  if (typeof structuredClone === "function") return structuredClone(value);
47614
47682
  return JSON.parse(JSON.stringify(value));
47615
47683
  }
47616
- getCachedAggregateMeshStatus(meshId) {
47684
+ hydrateCachedAggregateMeshStatusFromInline(snapshot, mesh, options) {
47685
+ if (!mesh || typeof mesh !== "object" || !Array.isArray(mesh.nodes) || !Array.isArray(snapshot?.nodes)) return snapshot;
47686
+ const inlineNodesById = /* @__PURE__ */ new Map();
47687
+ for (const node of mesh.nodes) {
47688
+ const nodeId = readInlineMeshNodeId(node);
47689
+ if (nodeId) inlineNodesById.set(nodeId, node);
47690
+ }
47691
+ if (!inlineNodesById.size) return snapshot;
47692
+ let changed = false;
47693
+ const unavailableNodeIds = /* @__PURE__ */ new Set();
47694
+ const sourceOfTruth = readObjectRecord(snapshot.sourceOfTruth);
47695
+ const directPeerTruth = readObjectRecord(sourceOfTruth.directPeerTruth);
47696
+ for (const entry of Array.isArray(directPeerTruth.unavailableNodeIds) ? directPeerTruth.unavailableNodeIds : []) {
47697
+ const nodeId = readStringValue(entry);
47698
+ if (nodeId) unavailableNodeIds.add(nodeId);
47699
+ }
47700
+ const nodes = snapshot.nodes.map((statusNode) => {
47701
+ const nodeId = readStringValue(statusNode?.nodeId, statusNode?.id);
47702
+ const inlineNode = nodeId ? inlineNodesById.get(nodeId) : void 0;
47703
+ if (!inlineNode) return statusNode;
47704
+ const liveGit = buildInlineMeshTransitGitStatus(inlineNode);
47705
+ if (!liveGit) return statusNode;
47706
+ const nextStatus = { ...statusNode };
47707
+ nextStatus.git = liveGit;
47708
+ nextStatus.health = deriveMeshNodeHealthFromGit(liveGit);
47709
+ delete nextStatus.gitProbePending;
47710
+ if (readStringValue(nextStatus.error) === "waiting for live peer git snapshot") delete nextStatus.error;
47711
+ if (!readStringValue(nextStatus.machineStatus)) nextStatus.machineStatus = "online";
47712
+ if (nodeId) unavailableNodeIds.delete(nodeId);
47713
+ changed = true;
47714
+ return nextStatus;
47715
+ });
47716
+ if (!changed && !(options?.requireDirectPeerTruth && unavailableNodeIds.size > 0)) return snapshot;
47717
+ const nextSourceOfTruth = {
47718
+ ...sourceOfTruth,
47719
+ ...Object.keys(directPeerTruth).length ? {
47720
+ directPeerTruth: {
47721
+ ...directPeerTruth,
47722
+ satisfied: options?.requireDirectPeerTruth === true ? unavailableNodeIds.size === 0 : directPeerTruth.satisfied,
47723
+ unavailableNodeIds: [...unavailableNodeIds]
47724
+ },
47725
+ ...options?.requireDirectPeerTruth === true ? {
47726
+ coordinatorOwnsLiveTruth: unavailableNodeIds.size === 0,
47727
+ currentStatus: unavailableNodeIds.size === 0 ? "live_git_and_session_probes" : "direct_peer_truth_unavailable"
47728
+ } : {}
47729
+ } : {}
47730
+ };
47731
+ return {
47732
+ ...snapshot,
47733
+ ...options?.requireDirectPeerTruth === true && unavailableNodeIds.size > 0 ? {
47734
+ success: false,
47735
+ code: "mesh_direct_peer_truth_unavailable",
47736
+ error: "Selected coordinator could not confirm direct mesh truth for every remote node yet."
47737
+ } : {},
47738
+ sourceOfTruth: nextSourceOfTruth,
47739
+ nodes
47740
+ };
47741
+ }
47742
+ getCachedAggregateMeshStatus(meshId, mesh, options) {
47617
47743
  const cached2 = this.aggregateMeshStatusCache.get(meshId);
47618
47744
  if (!cached2?.snapshot || cached2.snapshot.success !== true || !Array.isArray(cached2.snapshot.nodes)) return null;
47619
- const snapshot = this.cloneJsonValue(cached2.snapshot);
47745
+ let snapshot = this.cloneJsonValue(cached2.snapshot);
47746
+ snapshot = this.hydrateCachedAggregateMeshStatusFromInline(snapshot, mesh, options);
47620
47747
  const ageMs = Math.max(0, Date.now() - cached2.builtAt);
47621
47748
  const sourceOfTruth = snapshot.sourceOfTruth && typeof snapshot.sourceOfTruth === "object" ? snapshot.sourceOfTruth : {};
47622
47749
  snapshot.sourceOfTruth = {
@@ -47676,7 +47803,14 @@ var init_router = __esm({
47676
47803
  const preferInline = options?.preferInline === true;
47677
47804
  if (preferInline) {
47678
47805
  const cached3 = this.getCachedInlineMesh(meshId);
47679
- if (cached3) return { mesh: cached3, inline: true, source: "inline_cache" };
47806
+ if (cached3) {
47807
+ if (inlineMeshCarriesTransientNodeTruth(inlineMesh)) {
47808
+ const merged = reconcileInlineMeshCache(cached3, inlineMesh);
47809
+ this.inlineMeshCache.set(meshId, sanitizeInlineMesh(merged));
47810
+ return { mesh: merged, inline: true, source: "inline_cache" };
47811
+ }
47812
+ return { mesh: cached3, inline: true, source: "inline_cache" };
47813
+ }
47680
47814
  if (inlineMeshCarriesTransientNodeTruth(inlineMesh)) {
47681
47815
  this.warmInlineMeshCache(meshId, inlineMesh);
47682
47816
  return { mesh: inlineMesh, inline: true, source: "inline_bootstrap" };
@@ -49656,8 +49790,16 @@ ${block}`);
49656
49790
  if (!mesh) return { success: false, error: "Mesh not found" };
49657
49791
  const refreshRequested = args?.refresh === true || args?.forceRefresh === true;
49658
49792
  if (!refreshRequested) {
49659
- const cachedStatus = this.getCachedAggregateMeshStatus(meshId);
49660
- if (cachedStatus) return cachedStatus;
49793
+ const cachedStatus = this.getCachedAggregateMeshStatus(meshId, mesh, { requireDirectPeerTruth: args?.requireDirectPeerTruth === true });
49794
+ if (cachedStatus) {
49795
+ logRepoMeshStatusDebug("return_cached", {
49796
+ meshId,
49797
+ command: "mesh_status",
49798
+ refreshRequested,
49799
+ summary: summarizeRepoMeshStatusDebug(cachedStatus)
49800
+ });
49801
+ return cachedStatus;
49802
+ }
49661
49803
  }
49662
49804
  const refreshReason = refreshRequested ? "explicit_refresh" : "cold_cache_miss";
49663
49805
  const { getMeshQueueStats: getMeshQueueStats2, getQueue: getQueue2 } = await Promise.resolve().then(() => (init_mesh_work_queue(), mesh_work_queue_exports));
@@ -49683,9 +49825,9 @@ ${block}`);
49683
49825
  peerConfirmedCount: 0,
49684
49826
  unavailableNodeIds: []
49685
49827
  };
49686
- const directTruthSatisfied = meshRecord.source !== "inline_bootstrap" || directTruth.directEvidenceCount > 0;
49828
+ const directTruthSatisfied = !requireDirectPeerTruth || directTruth.directEvidenceCount > 0 && directTruth.unavailableNodeIds.length === 0;
49687
49829
  if (requireDirectPeerTruth && !directTruthSatisfied) {
49688
- return {
49830
+ const failureResult = {
49689
49831
  success: false,
49690
49832
  code: "mesh_direct_peer_truth_unavailable",
49691
49833
  error: "Selected coordinator could not confirm direct mesh truth yet. Bootstrap inventory stays unavailable until direct mesh_status probes succeed.",
@@ -49704,6 +49846,14 @@ ${block}`);
49704
49846
  }
49705
49847
  }
49706
49848
  };
49849
+ logRepoMeshStatusDebug("direct_truth_unavailable", {
49850
+ meshId,
49851
+ command: "mesh_status",
49852
+ refreshRequested,
49853
+ meshSource: meshRecord.source,
49854
+ directTruth
49855
+ });
49856
+ return failureResult;
49707
49857
  }
49708
49858
  const directTruthUnavailableNodeIds = new Set(directTruth.unavailableNodeIds);
49709
49859
  const selectedCoordinatorNodeId = readStringValue(
@@ -49911,7 +50061,17 @@ ${block}`);
49911
50061
  queue: { tasks: queue, summary: queueSummary },
49912
50062
  ledger: { entries: ledgerEntries, summary: ledgerSummary }
49913
50063
  };
49914
- return this.rememberAggregateMeshStatus(meshId, statusResult, refreshReason);
50064
+ const rememberedStatus = this.rememberAggregateMeshStatus(meshId, statusResult, refreshReason);
50065
+ logRepoMeshStatusDebug("return_live", {
50066
+ meshId,
50067
+ command: "mesh_status",
50068
+ refreshRequested,
50069
+ refreshReason,
50070
+ meshSource: meshRecord.source,
50071
+ directTruth,
50072
+ summary: summarizeRepoMeshStatusDebug(rememberedStatus)
50073
+ });
50074
+ return rememberedStatus;
49915
50075
  } catch (e) {
49916
50076
  return { success: false, error: e.message };
49917
50077
  }
@@ -98240,6 +98400,84 @@ var daemon_mesh_manager_exports = {};
98240
98400
  __export(daemon_mesh_manager_exports, {
98241
98401
  DaemonMeshManager: () => DaemonMeshManager
98242
98402
  });
98403
+ function asRecord(value) {
98404
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
98405
+ }
98406
+ function summarizeMeshCommandArgs(command, args) {
98407
+ if (command === "git_status") {
98408
+ return {
98409
+ workspace: typeof args.workspace === "string" ? args.workspace : null,
98410
+ refreshUpstream: args.refreshUpstream === true,
98411
+ includeSubmodules: args.includeSubmodules === true
98412
+ };
98413
+ }
98414
+ if (command === "mesh_status" || command === "get_mesh") {
98415
+ const inlineMesh = asRecord(args.inlineMesh);
98416
+ const inlineNodes = Array.isArray(inlineMesh.nodes) ? inlineMesh.nodes : [];
98417
+ return {
98418
+ meshId: typeof args.meshId === "string" ? args.meshId : null,
98419
+ requireDirectPeerTruth: args.requireDirectPeerTruth === true,
98420
+ refresh: args.refresh === true,
98421
+ inlineMeshNodes: inlineNodes.length
98422
+ };
98423
+ }
98424
+ return { keys: Object.keys(args).sort() };
98425
+ }
98426
+ function summarizeMeshCommandGitResult(result) {
98427
+ const envelope = asRecord(result);
98428
+ const nestedResult = asRecord(envelope.result);
98429
+ const status = Object.keys(asRecord(envelope.status)).length ? asRecord(envelope.status) : Object.keys(asRecord(nestedResult.status)).length ? asRecord(nestedResult.status) : Object.keys(envelope).length ? envelope : {};
98430
+ if (!Object.keys(status).length) return null;
98431
+ const submodules = Array.isArray(status.submodules) ? status.submodules.map((entry) => ({
98432
+ path: typeof entry?.path === "string" ? entry.path : null,
98433
+ commit: typeof entry?.commit === "string" ? entry.commit.slice(0, 12) : null,
98434
+ dirty: entry?.dirty === true,
98435
+ outOfSync: entry?.outOfSync === true
98436
+ })) : [];
98437
+ return {
98438
+ workspace: typeof status.workspace === "string" ? status.workspace : null,
98439
+ repoRoot: typeof status.repoRoot === "string" ? status.repoRoot : null,
98440
+ isGitRepo: status.isGitRepo,
98441
+ branch: status.branch ?? null,
98442
+ upstream: status.upstream ?? null,
98443
+ upstreamStatus: status.upstreamStatus ?? null,
98444
+ headCommit: typeof status.headCommit === "string" ? status.headCommit.slice(0, 12) : status.headCommit ?? null,
98445
+ ahead: status.ahead ?? null,
98446
+ behind: status.behind ?? null,
98447
+ dirtyCounts: {
98448
+ staged: status.staged ?? 0,
98449
+ modified: status.modified ?? 0,
98450
+ untracked: status.untracked ?? 0,
98451
+ deleted: status.deleted ?? 0,
98452
+ renamed: status.renamed ?? 0
98453
+ },
98454
+ lastCheckedAt: status.lastCheckedAt ?? null,
98455
+ submoduleCount: submodules.length,
98456
+ submodules
98457
+ };
98458
+ }
98459
+ function summarizeMeshCommandResult(command, result) {
98460
+ if (command === "git_status") return summarizeMeshCommandGitResult(result);
98461
+ const record2 = asRecord(result);
98462
+ if (command === "mesh_status") {
98463
+ const nodes = Array.isArray(record2.nodes) ? record2.nodes : [];
98464
+ return {
98465
+ success: record2.success,
98466
+ meshId: record2.meshId ?? null,
98467
+ sourceOfTruth: record2.sourceOfTruth ?? null,
98468
+ nodeCount: nodes.length,
98469
+ nodes: nodes.map((node) => ({
98470
+ nodeId: node?.nodeId ?? node?.id ?? null,
98471
+ daemonId: node?.daemonId ?? null,
98472
+ workspace: node?.workspace ?? node?.git?.workspace ?? null,
98473
+ health: node?.health ?? null,
98474
+ gitProbePending: node?.gitProbePending === true,
98475
+ git: summarizeMeshCommandGitResult({ status: node?.git })
98476
+ }))
98477
+ };
98478
+ }
98479
+ return null;
98480
+ }
98243
98481
  function interpolateArgs(args, context) {
98244
98482
  const result = {};
98245
98483
  for (const [k, v] of Object.entries(args)) {
@@ -98429,7 +98667,9 @@ var init_daemon_mesh_manager = __esm({
98429
98667
  targetDaemonId,
98430
98668
  sentAt: (/* @__PURE__ */ new Date()).toISOString(),
98431
98669
  peerState: peer.state,
98432
- success: !error48
98670
+ success: !error48,
98671
+ resultSummary: !error48 ? summarizeMeshCommandGitResult(result) : null,
98672
+ error: error48
98433
98673
  });
98434
98674
  } catch (err) {
98435
98675
  LOG.warn("Mesh", `[Mesh] Failed to send command result: ${err.message}`);
@@ -98523,7 +98763,8 @@ var init_daemon_mesh_manager = __esm({
98523
98763
  queuedAt,
98524
98764
  sentAt,
98525
98765
  peerState: peer.state,
98526
- transport: peer.isRelay === true ? "relay" : peer.isRelay === false ? "direct" : "unknown"
98766
+ transport: peer.isRelay === true ? "relay" : peer.isRelay === false ? "direct" : "unknown",
98767
+ argsSummary: summarizeMeshCommandArgs(command, args)
98527
98768
  });
98528
98769
  try {
98529
98770
  peer.dataChannel.sendMessage(JSON.stringify(payload));
@@ -98551,7 +98792,8 @@ var init_daemon_mesh_manager = __esm({
98551
98792
  targetDaemonId,
98552
98793
  queuedAt,
98553
98794
  peerState: peer.state,
98554
- transport: peer.isRelay === true ? "relay" : peer.isRelay === false ? "direct" : "unknown"
98795
+ transport: peer.isRelay === true ? "relay" : peer.isRelay === false ? "direct" : "unknown",
98796
+ argsSummary: summarizeMeshCommandArgs(command, args)
98555
98797
  });
98556
98798
  if (!peer.commandQueue) {
98557
98799
  peer.commandQueue = [];
@@ -98738,7 +98980,8 @@ var init_daemon_mesh_manager = __esm({
98738
98980
  sentAt,
98739
98981
  peerState: entry.state,
98740
98982
  transport: entry.isRelay === true ? "relay" : entry.isRelay === false ? "direct" : "unknown",
98741
- flushed: true
98983
+ flushed: true,
98984
+ argsSummary: summarizeMeshCommandArgs(item.command, item.args)
98742
98985
  });
98743
98986
  dc.sendMessage(JSON.stringify({
98744
98987
  type: "mesh_command",
@@ -98773,7 +99016,8 @@ var init_daemon_mesh_manager = __esm({
98773
99016
  requestId: data.requestId,
98774
99017
  command: data.command,
98775
99018
  senderDaemonId: targetDaemonId,
98776
- receivedAt: (/* @__PURE__ */ new Date()).toISOString()
99019
+ receivedAt: (/* @__PURE__ */ new Date()).toISOString(),
99020
+ argsSummary: summarizeMeshCommandArgs(data.command, asRecord(data.args))
98777
99021
  });
98778
99022
  if (this.commandCallback) {
98779
99023
  this.commandCallback(targetDaemonId, data.command, data.args, data.requestId).catch((e) => {
@@ -98790,7 +99034,9 @@ var init_daemon_mesh_manager = __esm({
98790
99034
  queuedAt: pending.queuedAt,
98791
99035
  sentAt: pending.sentAt,
98792
99036
  receivedAt: (/* @__PURE__ */ new Date()).toISOString(),
98793
- success: data.success === true
99037
+ success: data.success === true,
99038
+ resultSummary: data.success === true ? summarizeMeshCommandResult(pending.command, data.result) : null,
99039
+ error: data.success === true ? void 0 : data.error
98794
99040
  });
98795
99041
  if (data.success) {
98796
99042
  pending.resolve(data.result);
@@ -99060,7 +99306,7 @@ var init_adhdev_daemon = __esm({
99060
99306
  init_version();
99061
99307
  init_src();
99062
99308
  init_runtime_defaults();
99063
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.82-rc.43" });
99309
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.82-rc.45" });
99064
99310
  AdhdevDaemon = class _AdhdevDaemon {
99065
99311
  localHttpServer = null;
99066
99312
  localWss = null;