@adhdev/daemon-core 0.9.77-rc.51 → 0.9.77-rc.52

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.mjs CHANGED
@@ -7388,6 +7388,231 @@ function buildMeshLedgerReconciliationEvidence(meshId, replicas) {
7388
7388
 
7389
7389
  // src/index.ts
7390
7390
  init_mesh_work_queue();
7391
+
7392
+ // src/mesh/mesh-visualization.ts
7393
+ function isDirty(git) {
7394
+ if (!git) return false;
7395
+ return git.staged + git.modified + git.untracked + git.deleted + git.renamed > 0;
7396
+ }
7397
+ function dirtyFileCount(git) {
7398
+ if (!git) return 0;
7399
+ return git.staged + git.modified + git.untracked + git.deleted + git.renamed;
7400
+ }
7401
+ function detectOrphanReasons(node, defaultBranch) {
7402
+ const reasons = [];
7403
+ const git = node.git;
7404
+ if (!git) {
7405
+ reasons.push("No git status available");
7406
+ return reasons;
7407
+ }
7408
+ if (!git.isGitRepo) {
7409
+ reasons.push("Not a git repository");
7410
+ return reasons;
7411
+ }
7412
+ if (git.branch === null && git.headCommit) {
7413
+ reasons.push("Detached HEAD");
7414
+ }
7415
+ if (git.branch && !git.upstream) {
7416
+ if (defaultBranch && git.branch !== defaultBranch) {
7417
+ reasons.push(`No upstream: ${git.branch}`);
7418
+ }
7419
+ }
7420
+ if (git.branch && git.upstream === null && defaultBranch && git.branch !== defaultBranch) {
7421
+ if (!reasons.includes(`No upstream: ${git.branch}`)) {
7422
+ reasons.push(`No upstream: ${git.branch}`);
7423
+ }
7424
+ }
7425
+ if (node.error) {
7426
+ reasons.push(`Error: ${node.error}`);
7427
+ }
7428
+ return reasons;
7429
+ }
7430
+ function nodeHealthPriority(health) {
7431
+ switch (health) {
7432
+ case "online":
7433
+ return 0;
7434
+ case "dirty":
7435
+ return 1;
7436
+ case "degraded":
7437
+ return 2;
7438
+ case "wrong_branch":
7439
+ return 3;
7440
+ case "offline":
7441
+ return 4;
7442
+ case "unknown":
7443
+ return 5;
7444
+ default:
7445
+ return 5;
7446
+ }
7447
+ }
7448
+ function pickDominantHealth(healths) {
7449
+ if (healths.length === 0) return "unknown";
7450
+ return healths.reduce(
7451
+ (best, h) => nodeHealthPriority(h) > nodeHealthPriority(best) ? h : best
7452
+ );
7453
+ }
7454
+ function buildMeshGraph(status) {
7455
+ const nodes = [];
7456
+ const edges = [];
7457
+ const warnings = [];
7458
+ const branchToNodeIds = /* @__PURE__ */ new Map();
7459
+ for (const nodeStatus of status.nodes) {
7460
+ const git = nodeStatus.git;
7461
+ const branch = git?.branch || null;
7462
+ const orphanReasons = detectOrphanReasons(nodeStatus, null);
7463
+ const dirty = isDirty(git);
7464
+ const dfc = dirtyFileCount(git);
7465
+ let type = "worktreeNode";
7466
+ if (orphanReasons.length > 0) {
7467
+ type = "orphanNode";
7468
+ }
7469
+ const graphNode = {
7470
+ id: nodeStatus.nodeId,
7471
+ type,
7472
+ label: nodeStatus.machineLabel || nodeStatus.nodeId.slice(0, 8),
7473
+ workspace: nodeStatus.workspace,
7474
+ branch,
7475
+ health: nodeStatus.health,
7476
+ ahead: git?.ahead ?? 0,
7477
+ behind: git?.behind ?? 0,
7478
+ dirty,
7479
+ dirtyFiles: dfc,
7480
+ hasConflicts: git?.hasConflicts ?? false,
7481
+ activeSessionCount: nodeStatus.activeSessions?.length ?? 0,
7482
+ activeSessions: nodeStatus.activeSessions ?? [],
7483
+ providers: nodeStatus.providers ?? [],
7484
+ isOrphan: orphanReasons.length > 0,
7485
+ orphanReasons,
7486
+ source: nodeStatus
7487
+ };
7488
+ nodes.push(graphNode);
7489
+ if (branch) {
7490
+ const list = branchToNodeIds.get(branch) ?? [];
7491
+ list.push(graphNode.id);
7492
+ branchToNodeIds.set(branch, list);
7493
+ }
7494
+ }
7495
+ const branchUpstreamCounts = /* @__PURE__ */ new Map();
7496
+ for (const n of status.nodes) {
7497
+ const b = n.git?.branch;
7498
+ const upstream = n.git?.upstream;
7499
+ if (b && upstream) {
7500
+ branchUpstreamCounts.set(b, (branchUpstreamCounts.get(b) ?? 0) + 1);
7501
+ }
7502
+ }
7503
+ let inferredDefaultBranch = null;
7504
+ let bestCount = 0;
7505
+ for (const [b, count] of branchUpstreamCounts) {
7506
+ if (count > bestCount) {
7507
+ bestCount = count;
7508
+ inferredDefaultBranch = b;
7509
+ }
7510
+ }
7511
+ const defaultBranchNodeId = inferredDefaultBranch ? `__branch_${inferredDefaultBranch}` : null;
7512
+ if (defaultBranchNodeId && inferredDefaultBranch) {
7513
+ const branchNodes = branchToNodeIds.get(inferredDefaultBranch) ?? [];
7514
+ const branchHealths = branchNodes.map(
7515
+ (id) => nodes.find((n) => n.id === id).health
7516
+ );
7517
+ const defaultNode = {
7518
+ id: defaultBranchNodeId,
7519
+ type: "defaultBranchNode",
7520
+ label: inferredDefaultBranch,
7521
+ workspace: "",
7522
+ branch: inferredDefaultBranch,
7523
+ health: pickDominantHealth(branchHealths),
7524
+ ahead: 0,
7525
+ behind: 0,
7526
+ dirty: false,
7527
+ dirtyFiles: 0,
7528
+ hasConflicts: false,
7529
+ activeSessionCount: 0,
7530
+ activeSessions: [],
7531
+ providers: [],
7532
+ isOrphan: false,
7533
+ orphanReasons: [],
7534
+ nextStepHint: branchNodes.length > 0 ? `${branchNodes.length} node(s) on default branch` : void 0,
7535
+ source: {
7536
+ nodeId: defaultBranchNodeId,
7537
+ machineLabel: inferredDefaultBranch,
7538
+ workspace: "",
7539
+ health: "online",
7540
+ providers: [],
7541
+ activeSessions: []
7542
+ }
7543
+ };
7544
+ nodes.push(defaultNode);
7545
+ const seenBranches = /* @__PURE__ */ new Set();
7546
+ for (const n of nodes) {
7547
+ if (n.type === "defaultBranchNode") continue;
7548
+ if (!n.branch) continue;
7549
+ if (n.branch === inferredDefaultBranch) {
7550
+ edges.push({
7551
+ id: `${defaultBranchNodeId}--${n.id}`,
7552
+ source: defaultBranchNodeId,
7553
+ target: n.id,
7554
+ type: "parentBranch",
7555
+ label: "default"
7556
+ });
7557
+ continue;
7558
+ }
7559
+ if (seenBranches.has(n.branch)) continue;
7560
+ seenBranches.add(n.branch);
7561
+ edges.push({
7562
+ id: `${defaultBranchNodeId}--branch_${n.branch}`,
7563
+ source: defaultBranchNodeId,
7564
+ target: n.branch,
7565
+ type: "parentBranch",
7566
+ label: n.branch
7567
+ });
7568
+ }
7569
+ }
7570
+ for (const [branch, ids] of branchToNodeIds) {
7571
+ if (ids.length < 2) continue;
7572
+ for (let i = 1; i < ids.length; i++) {
7573
+ edges.push({
7574
+ id: `wt_${ids[0]}--${ids[i]}`,
7575
+ source: ids[0],
7576
+ target: ids[i],
7577
+ type: "worktreeLink",
7578
+ label: branch
7579
+ });
7580
+ }
7581
+ }
7582
+ const orphanCount = nodes.filter((n) => n.isOrphan).length;
7583
+ if (orphanCount > 0) {
7584
+ warnings.push(`${orphanCount} orphan node(s) detected`);
7585
+ }
7586
+ const conflictCount = nodes.filter((n) => n.hasConflicts).length;
7587
+ if (conflictCount > 0) {
7588
+ warnings.push(`${conflictCount} node(s) with merge conflicts`);
7589
+ }
7590
+ const offlineCount = nodes.filter((n) => n.health === "offline").length;
7591
+ if (offlineCount > 0) {
7592
+ warnings.push(`${offlineCount} node(s) offline`);
7593
+ }
7594
+ const stats = {
7595
+ totalNodes: status.nodes.length,
7596
+ onlineNodes: status.nodes.filter((n) => n.health === "online").length,
7597
+ dirtyNodes: nodes.filter((n) => n.dirty).length,
7598
+ orphanNodes: orphanCount,
7599
+ errorNodes: status.nodes.filter((n) => !!n.error).length,
7600
+ offlineNodes: offlineCount,
7601
+ totalActiveSessions: status.nodes.reduce((sum, n) => sum + (n.activeSessions?.length ?? 0), 0)
7602
+ };
7603
+ return {
7604
+ meshId: status.meshId,
7605
+ meshName: status.meshName,
7606
+ repoIdentity: status.repoIdentity,
7607
+ refreshedAt: status.refreshedAt,
7608
+ nodes,
7609
+ edges,
7610
+ stats,
7611
+ warnings
7612
+ };
7613
+ }
7614
+
7615
+ // src/index.ts
7391
7616
  init_mesh_events();
7392
7617
 
7393
7618
  // src/mesh/p2p-relay-failure.ts
@@ -33807,6 +34032,7 @@ export {
33807
34032
  buildChatTailDeliverySignature,
33808
34033
  buildCoordinatorSystemPrompt,
33809
34034
  buildMachineInfo,
34035
+ buildMeshGraph,
33810
34036
  buildMeshLedgerReconciliationEvidence,
33811
34037
  buildMeshLedgerReplicaEvidence,
33812
34038
  buildP2pRelayFailurePayload,