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/index.js CHANGED
@@ -45650,6 +45650,70 @@ function readBooleanValue(...values) {
45650
45650
  }
45651
45651
  return void 0;
45652
45652
  }
45653
+ function summarizeRepoMeshDebugGit(git) {
45654
+ const record2 = readObjectRecord(git);
45655
+ if (!Object.keys(record2).length) return null;
45656
+ const submodules = Array.isArray(record2.submodules) ? record2.submodules.map((entry) => ({
45657
+ path: readStringValue(entry?.path) ?? null,
45658
+ commit: readStringValue(entry?.commit)?.slice(0, 12) ?? null,
45659
+ dirty: readBooleanValue(entry?.dirty) ?? false,
45660
+ outOfSync: readBooleanValue(entry?.outOfSync, entry?.out_of_sync) ?? false
45661
+ })) : [];
45662
+ return {
45663
+ isGitRepo: readBooleanValue(record2.isGitRepo),
45664
+ workspace: readStringValue(record2.workspace) ?? null,
45665
+ repoRoot: readStringValue(record2.repoRoot, record2.repo_root) ?? null,
45666
+ branch: readStringValue(record2.branch) ?? null,
45667
+ upstream: readStringValue(record2.upstream) ?? null,
45668
+ upstreamStatus: readStringValue(record2.upstreamStatus, record2.upstream_status) ?? null,
45669
+ headCommit: readStringValue(record2.headCommit, record2.head_commit)?.slice(0, 12) ?? null,
45670
+ ahead: readNumberValue(record2.ahead) ?? null,
45671
+ behind: readNumberValue(record2.behind) ?? null,
45672
+ dirtyCounts: {
45673
+ staged: readNumberValue(record2.staged) ?? 0,
45674
+ modified: readNumberValue(record2.modified) ?? 0,
45675
+ untracked: readNumberValue(record2.untracked) ?? 0,
45676
+ deleted: readNumberValue(record2.deleted) ?? 0,
45677
+ renamed: readNumberValue(record2.renamed) ?? 0
45678
+ },
45679
+ lastCheckedAt: readNumberValue(record2.lastCheckedAt, record2.last_checked_at) ?? null,
45680
+ submoduleCount: submodules.length,
45681
+ submodules
45682
+ };
45683
+ }
45684
+ function summarizeRepoMeshStatusDebug(status) {
45685
+ const nodes = Array.isArray(status?.nodes) ? status.nodes : [];
45686
+ return {
45687
+ success: status?.success,
45688
+ meshId: readStringValue(status?.meshId, status?.mesh_id) ?? null,
45689
+ refreshedAt: readStringValue(status?.refreshedAt, status?.refreshed_at) ?? null,
45690
+ sourceOfTruth: status?.sourceOfTruth ?? null,
45691
+ nodeCount: nodes.length,
45692
+ nodes: nodes.map((node) => ({
45693
+ nodeId: readStringValue(node?.nodeId, node?.id) ?? null,
45694
+ daemonId: readStringValue(node?.daemonId, node?.daemon_id) ?? null,
45695
+ workspace: readStringValue(node?.workspace, node?.git?.workspace) ?? null,
45696
+ health: readStringValue(node?.health) ?? null,
45697
+ machineStatus: readStringValue(node?.machineStatus, node?.machine_status) ?? null,
45698
+ connection: node?.connection && typeof node.connection === "object" ? {
45699
+ state: readStringValue(node.connection.state) ?? null,
45700
+ transport: readStringValue(node.connection.transport) ?? null,
45701
+ source: readStringValue(node.connection.source) ?? null,
45702
+ reported: readBooleanValue(node.connection.reported) ?? null
45703
+ } : null,
45704
+ gitProbePending: node?.gitProbePending === true,
45705
+ launchReady: node?.launchReady === true,
45706
+ git: summarizeRepoMeshDebugGit(node?.git)
45707
+ }))
45708
+ };
45709
+ }
45710
+ function logRepoMeshStatusDebug(event, fields) {
45711
+ try {
45712
+ LOG.info("MeshStatusDebug", `[RepoMeshStatusDebug] ${JSON.stringify({ event, ...fields })}`);
45713
+ } catch {
45714
+ LOG.info("MeshStatusDebug", `[RepoMeshStatusDebug] ${event}`);
45715
+ }
45716
+ }
45653
45717
  function joinRepoPath(root, relativePath) {
45654
45718
  const normalizedRoot = typeof root === "string" ? root.trim().replace(/[\\/]+$/, "") : "";
45655
45719
  const normalizedPath = typeof relativePath === "string" ? relativePath.trim() : "";
@@ -45718,8 +45782,12 @@ function buildInlineMeshTransitGitStatus(node) {
45718
45782
  const probeGitResult = readObjectRecord(probeGit.result);
45719
45783
  const probeDirectStatus = readObjectRecord(probeGit.status);
45720
45784
  const probeNestedStatus = readObjectRecord(probeGitResult.status);
45721
- const status = Object.keys(directStatus).length ? directStatus : Object.keys(nestedStatus).length ? nestedStatus : Object.keys(probeDirectStatus).length ? probeDirectStatus : Object.keys(probeNestedStatus).length ? probeNestedStatus : {};
45722
- return normalizeInlineMeshGitStatus(status, node, { lastCheckedAt: Date.now() });
45785
+ const candidates = [directStatus, nestedStatus, probeDirectStatus, probeNestedStatus];
45786
+ for (const status of candidates) {
45787
+ const normalized = normalizeInlineMeshGitStatus(status, node, { lastCheckedAt: Date.now() });
45788
+ if (normalized) return normalized;
45789
+ }
45790
+ return void 0;
45723
45791
  }
45724
45792
  function recordInlineMeshDirectGitTruth(node, git, source) {
45725
45793
  if (!node || typeof node !== "object" || Array.isArray(node)) return;
@@ -46625,10 +46693,69 @@ var init_router = __esm({
46625
46693
  if (typeof structuredClone === "function") return structuredClone(value);
46626
46694
  return JSON.parse(JSON.stringify(value));
46627
46695
  }
46628
- getCachedAggregateMeshStatus(meshId) {
46696
+ hydrateCachedAggregateMeshStatusFromInline(snapshot, mesh, options) {
46697
+ if (!mesh || typeof mesh !== "object" || !Array.isArray(mesh.nodes) || !Array.isArray(snapshot?.nodes)) return snapshot;
46698
+ const inlineNodesById = /* @__PURE__ */ new Map();
46699
+ for (const node of mesh.nodes) {
46700
+ const nodeId = readInlineMeshNodeId(node);
46701
+ if (nodeId) inlineNodesById.set(nodeId, node);
46702
+ }
46703
+ if (!inlineNodesById.size) return snapshot;
46704
+ let changed = false;
46705
+ const unavailableNodeIds = /* @__PURE__ */ new Set();
46706
+ const sourceOfTruth = readObjectRecord(snapshot.sourceOfTruth);
46707
+ const directPeerTruth = readObjectRecord(sourceOfTruth.directPeerTruth);
46708
+ for (const entry of Array.isArray(directPeerTruth.unavailableNodeIds) ? directPeerTruth.unavailableNodeIds : []) {
46709
+ const nodeId = readStringValue(entry);
46710
+ if (nodeId) unavailableNodeIds.add(nodeId);
46711
+ }
46712
+ const nodes = snapshot.nodes.map((statusNode) => {
46713
+ const nodeId = readStringValue(statusNode?.nodeId, statusNode?.id);
46714
+ const inlineNode = nodeId ? inlineNodesById.get(nodeId) : void 0;
46715
+ if (!inlineNode) return statusNode;
46716
+ const liveGit = buildInlineMeshTransitGitStatus(inlineNode);
46717
+ if (!liveGit) return statusNode;
46718
+ const nextStatus = { ...statusNode };
46719
+ nextStatus.git = liveGit;
46720
+ nextStatus.health = deriveMeshNodeHealthFromGit(liveGit);
46721
+ delete nextStatus.gitProbePending;
46722
+ if (readStringValue(nextStatus.error) === "waiting for live peer git snapshot") delete nextStatus.error;
46723
+ if (!readStringValue(nextStatus.machineStatus)) nextStatus.machineStatus = "online";
46724
+ if (nodeId) unavailableNodeIds.delete(nodeId);
46725
+ changed = true;
46726
+ return nextStatus;
46727
+ });
46728
+ if (!changed && !(options?.requireDirectPeerTruth && unavailableNodeIds.size > 0)) return snapshot;
46729
+ const nextSourceOfTruth = {
46730
+ ...sourceOfTruth,
46731
+ ...Object.keys(directPeerTruth).length ? {
46732
+ directPeerTruth: {
46733
+ ...directPeerTruth,
46734
+ satisfied: options?.requireDirectPeerTruth === true ? unavailableNodeIds.size === 0 : directPeerTruth.satisfied,
46735
+ unavailableNodeIds: [...unavailableNodeIds]
46736
+ },
46737
+ ...options?.requireDirectPeerTruth === true ? {
46738
+ coordinatorOwnsLiveTruth: unavailableNodeIds.size === 0,
46739
+ currentStatus: unavailableNodeIds.size === 0 ? "live_git_and_session_probes" : "direct_peer_truth_unavailable"
46740
+ } : {}
46741
+ } : {}
46742
+ };
46743
+ return {
46744
+ ...snapshot,
46745
+ ...options?.requireDirectPeerTruth === true && unavailableNodeIds.size > 0 ? {
46746
+ success: false,
46747
+ code: "mesh_direct_peer_truth_unavailable",
46748
+ error: "Selected coordinator could not confirm direct mesh truth for every remote node yet."
46749
+ } : {},
46750
+ sourceOfTruth: nextSourceOfTruth,
46751
+ nodes
46752
+ };
46753
+ }
46754
+ getCachedAggregateMeshStatus(meshId, mesh, options) {
46629
46755
  const cached2 = this.aggregateMeshStatusCache.get(meshId);
46630
46756
  if (!cached2?.snapshot || cached2.snapshot.success !== true || !Array.isArray(cached2.snapshot.nodes)) return null;
46631
- const snapshot = this.cloneJsonValue(cached2.snapshot);
46757
+ let snapshot = this.cloneJsonValue(cached2.snapshot);
46758
+ snapshot = this.hydrateCachedAggregateMeshStatusFromInline(snapshot, mesh, options);
46632
46759
  const ageMs = Math.max(0, Date.now() - cached2.builtAt);
46633
46760
  const sourceOfTruth = snapshot.sourceOfTruth && typeof snapshot.sourceOfTruth === "object" ? snapshot.sourceOfTruth : {};
46634
46761
  snapshot.sourceOfTruth = {
@@ -46688,7 +46815,14 @@ var init_router = __esm({
46688
46815
  const preferInline = options?.preferInline === true;
46689
46816
  if (preferInline) {
46690
46817
  const cached3 = this.getCachedInlineMesh(meshId);
46691
- if (cached3) return { mesh: cached3, inline: true, source: "inline_cache" };
46818
+ if (cached3) {
46819
+ if (inlineMeshCarriesTransientNodeTruth(inlineMesh)) {
46820
+ const merged = reconcileInlineMeshCache(cached3, inlineMesh);
46821
+ this.inlineMeshCache.set(meshId, sanitizeInlineMesh(merged));
46822
+ return { mesh: merged, inline: true, source: "inline_cache" };
46823
+ }
46824
+ return { mesh: cached3, inline: true, source: "inline_cache" };
46825
+ }
46692
46826
  if (inlineMeshCarriesTransientNodeTruth(inlineMesh)) {
46693
46827
  this.warmInlineMeshCache(meshId, inlineMesh);
46694
46828
  return { mesh: inlineMesh, inline: true, source: "inline_bootstrap" };
@@ -48668,8 +48802,16 @@ ${block}`);
48668
48802
  if (!mesh) return { success: false, error: "Mesh not found" };
48669
48803
  const refreshRequested = args?.refresh === true || args?.forceRefresh === true;
48670
48804
  if (!refreshRequested) {
48671
- const cachedStatus = this.getCachedAggregateMeshStatus(meshId);
48672
- if (cachedStatus) return cachedStatus;
48805
+ const cachedStatus = this.getCachedAggregateMeshStatus(meshId, mesh, { requireDirectPeerTruth: args?.requireDirectPeerTruth === true });
48806
+ if (cachedStatus) {
48807
+ logRepoMeshStatusDebug("return_cached", {
48808
+ meshId,
48809
+ command: "mesh_status",
48810
+ refreshRequested,
48811
+ summary: summarizeRepoMeshStatusDebug(cachedStatus)
48812
+ });
48813
+ return cachedStatus;
48814
+ }
48673
48815
  }
48674
48816
  const refreshReason = refreshRequested ? "explicit_refresh" : "cold_cache_miss";
48675
48817
  const { getMeshQueueStats: getMeshQueueStats2, getQueue: getQueue2 } = await Promise.resolve().then(() => (init_mesh_work_queue(), mesh_work_queue_exports));
@@ -48695,9 +48837,9 @@ ${block}`);
48695
48837
  peerConfirmedCount: 0,
48696
48838
  unavailableNodeIds: []
48697
48839
  };
48698
- const directTruthSatisfied = meshRecord.source !== "inline_bootstrap" || directTruth.directEvidenceCount > 0;
48840
+ const directTruthSatisfied = !requireDirectPeerTruth || directTruth.directEvidenceCount > 0 && directTruth.unavailableNodeIds.length === 0;
48699
48841
  if (requireDirectPeerTruth && !directTruthSatisfied) {
48700
- return {
48842
+ const failureResult = {
48701
48843
  success: false,
48702
48844
  code: "mesh_direct_peer_truth_unavailable",
48703
48845
  error: "Selected coordinator could not confirm direct mesh truth yet. Bootstrap inventory stays unavailable until direct mesh_status probes succeed.",
@@ -48716,6 +48858,14 @@ ${block}`);
48716
48858
  }
48717
48859
  }
48718
48860
  };
48861
+ logRepoMeshStatusDebug("direct_truth_unavailable", {
48862
+ meshId,
48863
+ command: "mesh_status",
48864
+ refreshRequested,
48865
+ meshSource: meshRecord.source,
48866
+ directTruth
48867
+ });
48868
+ return failureResult;
48719
48869
  }
48720
48870
  const directTruthUnavailableNodeIds = new Set(directTruth.unavailableNodeIds);
48721
48871
  const selectedCoordinatorNodeId = readStringValue(
@@ -48923,7 +49073,17 @@ ${block}`);
48923
49073
  queue: { tasks: queue, summary: queueSummary },
48924
49074
  ledger: { entries: ledgerEntries, summary: ledgerSummary }
48925
49075
  };
48926
- return this.rememberAggregateMeshStatus(meshId, statusResult, refreshReason);
49076
+ const rememberedStatus = this.rememberAggregateMeshStatus(meshId, statusResult, refreshReason);
49077
+ logRepoMeshStatusDebug("return_live", {
49078
+ meshId,
49079
+ command: "mesh_status",
49080
+ refreshRequested,
49081
+ refreshReason,
49082
+ meshSource: meshRecord.source,
49083
+ directTruth,
49084
+ summary: summarizeRepoMeshStatusDebug(rememberedStatus)
49085
+ });
49086
+ return rememberedStatus;
48927
49087
  } catch (e) {
48928
49088
  return { success: false, error: e.message };
48929
49089
  }
@@ -67070,6 +67230,84 @@ var daemon_mesh_manager_exports = {};
67070
67230
  __export(daemon_mesh_manager_exports, {
67071
67231
  DaemonMeshManager: () => DaemonMeshManager
67072
67232
  });
67233
+ function asRecord(value) {
67234
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
67235
+ }
67236
+ function summarizeMeshCommandArgs(command, args) {
67237
+ if (command === "git_status") {
67238
+ return {
67239
+ workspace: typeof args.workspace === "string" ? args.workspace : null,
67240
+ refreshUpstream: args.refreshUpstream === true,
67241
+ includeSubmodules: args.includeSubmodules === true
67242
+ };
67243
+ }
67244
+ if (command === "mesh_status" || command === "get_mesh") {
67245
+ const inlineMesh = asRecord(args.inlineMesh);
67246
+ const inlineNodes = Array.isArray(inlineMesh.nodes) ? inlineMesh.nodes : [];
67247
+ return {
67248
+ meshId: typeof args.meshId === "string" ? args.meshId : null,
67249
+ requireDirectPeerTruth: args.requireDirectPeerTruth === true,
67250
+ refresh: args.refresh === true,
67251
+ inlineMeshNodes: inlineNodes.length
67252
+ };
67253
+ }
67254
+ return { keys: Object.keys(args).sort() };
67255
+ }
67256
+ function summarizeMeshCommandGitResult(result) {
67257
+ const envelope = asRecord(result);
67258
+ const nestedResult = asRecord(envelope.result);
67259
+ 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 : {};
67260
+ if (!Object.keys(status).length) return null;
67261
+ const submodules = Array.isArray(status.submodules) ? status.submodules.map((entry) => ({
67262
+ path: typeof entry?.path === "string" ? entry.path : null,
67263
+ commit: typeof entry?.commit === "string" ? entry.commit.slice(0, 12) : null,
67264
+ dirty: entry?.dirty === true,
67265
+ outOfSync: entry?.outOfSync === true
67266
+ })) : [];
67267
+ return {
67268
+ workspace: typeof status.workspace === "string" ? status.workspace : null,
67269
+ repoRoot: typeof status.repoRoot === "string" ? status.repoRoot : null,
67270
+ isGitRepo: status.isGitRepo,
67271
+ branch: status.branch ?? null,
67272
+ upstream: status.upstream ?? null,
67273
+ upstreamStatus: status.upstreamStatus ?? null,
67274
+ headCommit: typeof status.headCommit === "string" ? status.headCommit.slice(0, 12) : status.headCommit ?? null,
67275
+ ahead: status.ahead ?? null,
67276
+ behind: status.behind ?? null,
67277
+ dirtyCounts: {
67278
+ staged: status.staged ?? 0,
67279
+ modified: status.modified ?? 0,
67280
+ untracked: status.untracked ?? 0,
67281
+ deleted: status.deleted ?? 0,
67282
+ renamed: status.renamed ?? 0
67283
+ },
67284
+ lastCheckedAt: status.lastCheckedAt ?? null,
67285
+ submoduleCount: submodules.length,
67286
+ submodules
67287
+ };
67288
+ }
67289
+ function summarizeMeshCommandResult(command, result) {
67290
+ if (command === "git_status") return summarizeMeshCommandGitResult(result);
67291
+ const record2 = asRecord(result);
67292
+ if (command === "mesh_status") {
67293
+ const nodes = Array.isArray(record2.nodes) ? record2.nodes : [];
67294
+ return {
67295
+ success: record2.success,
67296
+ meshId: record2.meshId ?? null,
67297
+ sourceOfTruth: record2.sourceOfTruth ?? null,
67298
+ nodeCount: nodes.length,
67299
+ nodes: nodes.map((node) => ({
67300
+ nodeId: node?.nodeId ?? node?.id ?? null,
67301
+ daemonId: node?.daemonId ?? null,
67302
+ workspace: node?.workspace ?? node?.git?.workspace ?? null,
67303
+ health: node?.health ?? null,
67304
+ gitProbePending: node?.gitProbePending === true,
67305
+ git: summarizeMeshCommandGitResult({ status: node?.git })
67306
+ }))
67307
+ };
67308
+ }
67309
+ return null;
67310
+ }
67073
67311
  function interpolateArgs(args, context) {
67074
67312
  const result = {};
67075
67313
  for (const [k, v] of Object.entries(args)) {
@@ -67259,7 +67497,9 @@ var init_daemon_mesh_manager = __esm({
67259
67497
  targetDaemonId,
67260
67498
  sentAt: (/* @__PURE__ */ new Date()).toISOString(),
67261
67499
  peerState: peer.state,
67262
- success: !error48
67500
+ success: !error48,
67501
+ resultSummary: !error48 ? summarizeMeshCommandGitResult(result) : null,
67502
+ error: error48
67263
67503
  });
67264
67504
  } catch (err) {
67265
67505
  LOG.warn("Mesh", `[Mesh] Failed to send command result: ${err.message}`);
@@ -67353,7 +67593,8 @@ var init_daemon_mesh_manager = __esm({
67353
67593
  queuedAt,
67354
67594
  sentAt,
67355
67595
  peerState: peer.state,
67356
- transport: peer.isRelay === true ? "relay" : peer.isRelay === false ? "direct" : "unknown"
67596
+ transport: peer.isRelay === true ? "relay" : peer.isRelay === false ? "direct" : "unknown",
67597
+ argsSummary: summarizeMeshCommandArgs(command, args)
67357
67598
  });
67358
67599
  try {
67359
67600
  peer.dataChannel.sendMessage(JSON.stringify(payload));
@@ -67381,7 +67622,8 @@ var init_daemon_mesh_manager = __esm({
67381
67622
  targetDaemonId,
67382
67623
  queuedAt,
67383
67624
  peerState: peer.state,
67384
- transport: peer.isRelay === true ? "relay" : peer.isRelay === false ? "direct" : "unknown"
67625
+ transport: peer.isRelay === true ? "relay" : peer.isRelay === false ? "direct" : "unknown",
67626
+ argsSummary: summarizeMeshCommandArgs(command, args)
67385
67627
  });
67386
67628
  if (!peer.commandQueue) {
67387
67629
  peer.commandQueue = [];
@@ -67568,7 +67810,8 @@ var init_daemon_mesh_manager = __esm({
67568
67810
  sentAt,
67569
67811
  peerState: entry.state,
67570
67812
  transport: entry.isRelay === true ? "relay" : entry.isRelay === false ? "direct" : "unknown",
67571
- flushed: true
67813
+ flushed: true,
67814
+ argsSummary: summarizeMeshCommandArgs(item.command, item.args)
67572
67815
  });
67573
67816
  dc.sendMessage(JSON.stringify({
67574
67817
  type: "mesh_command",
@@ -67603,7 +67846,8 @@ var init_daemon_mesh_manager = __esm({
67603
67846
  requestId: data.requestId,
67604
67847
  command: data.command,
67605
67848
  senderDaemonId: targetDaemonId,
67606
- receivedAt: (/* @__PURE__ */ new Date()).toISOString()
67849
+ receivedAt: (/* @__PURE__ */ new Date()).toISOString(),
67850
+ argsSummary: summarizeMeshCommandArgs(data.command, asRecord(data.args))
67607
67851
  });
67608
67852
  if (this.commandCallback) {
67609
67853
  this.commandCallback(targetDaemonId, data.command, data.args, data.requestId).catch((e) => {
@@ -67620,7 +67864,9 @@ var init_daemon_mesh_manager = __esm({
67620
67864
  queuedAt: pending.queuedAt,
67621
67865
  sentAt: pending.sentAt,
67622
67866
  receivedAt: (/* @__PURE__ */ new Date()).toISOString(),
67623
- success: data.success === true
67867
+ success: data.success === true,
67868
+ resultSummary: data.success === true ? summarizeMeshCommandResult(pending.command, data.result) : null,
67869
+ error: data.success === true ? void 0 : data.error
67624
67870
  });
67625
67871
  if (data.success) {
67626
67872
  pending.resolve(data.result);
@@ -67890,7 +68136,7 @@ var init_adhdev_daemon = __esm({
67890
68136
  init_version();
67891
68137
  init_src();
67892
68138
  init_runtime_defaults();
67893
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.82-rc.43" });
68139
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.82-rc.45" });
67894
68140
  AdhdevDaemon = class _AdhdevDaemon {
67895
68141
  localHttpServer = null;
67896
68142
  localWss = null;