Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: optimize tag edge computation, scale graph sim, harden bridge map parsing
Adam Eivy15b741e63f37
diff --git a/client/src/lib/graphSimulation.js b/client/src/lib/graphSimulation.jsindex 4e80f03f19..46ac2f71cb 100644--- a/client/src/lib/graphSimulation.js+++ b/client/src/lib/graphSimulation.js@@ -41,11 +41,16 @@ function tickSim(nodes, edges, alpha) {}const MAX_ITERATIONS = 300;+const LARGE_GRAPH_THRESHOLD = 200;function settleSimulation(nodes, edges) {+ // Scale iterations down for large graphs to keep the main thread responsive+ const cap = nodes.length > LARGE_GRAPH_THRESHOLD+ ? Math.max(50, Math.round(MAX_ITERATIONS * (LARGE_GRAPH_THRESHOLD / nodes.length)))+ : MAX_ITERATIONS;let alpha = 1;let iter = 0;- while (alpha > ALPHA_MIN && iter < MAX_ITERATIONS) {+ while (alpha > ALPHA_MIN && iter < cap) {tickSim(nodes, edges, alpha);alpha *= ALPHA_DECAY;iter++;diff --git a/server/services/brainGraph.js b/server/services/brainGraph.jsindex 8bbe4ecb40..4fc7cc78ab 100644--- a/server/services/brainGraph.js+++ b/server/services/brainGraph.js@@ -84,25 +84,35 @@ export async function getBrainGraphData() {}}- // 4. Compute tag-based edges (Jaccard >= 0.3)+ // 4. Compute tag-based edges (Jaccard >= 0.3) using inverted index+ const tagIndex = new Map(); // tag → Set of node indicesfor (let i = 0; i < nodes.length; i++) {- for (let j = i + 1; j < nodes.length; j++) {- const a = nodes[i], b = nodes[j];- const edgeKey = [a.id, b.id].sort().join('-');- if (seenEdges.has(edgeKey)) continue;-- const similarity = jaccardSimilarity(a.tags, b.tags);- if (similarity >= 0.3) {- seenEdges.add(edgeKey);- edges.push({- source: a.id,- target: b.id,- type: 'shared_tag',- weight: similarity- });+ for (const tag of nodes[i].tags || []) {+ if (!tagIndex.has(tag)) tagIndex.set(tag, new Set());+ tagIndex.get(tag).add(i);+ }+ }+ const candidatePairs = new Set();+ for (const indices of tagIndex.values()) {+ const arr = [...indices];+ for (let x = 0; x < arr.length; x++) {+ for (let y = x + 1; y < arr.length; y++) {+ const lo = Math.min(arr[x], arr[y]), hi = Math.max(arr[x], arr[y]);+ candidatePairs.add(`${lo}:${hi}`);}}}+ for (const pair of candidatePairs) {+ const [i, j] = pair.split(':').map(Number);+ const a = nodes[i], b = nodes[j];+ const edgeKey = [a.id, b.id].sort().join('-');+ if (seenEdges.has(edgeKey)) continue;+ const similarity = jaccardSimilarity(a.tags, b.tags);+ if (similarity >= 0.3) {+ seenEdges.add(edgeKey);+ edges.push({ source: a.id, target: b.id, type: 'shared_tag', weight: similarity });+ }+ }return { nodes, edges, hasEmbeddings };}diff --git a/server/services/brainMemoryBridge.js b/server/services/brainMemoryBridge.jsindex 6371386b63..091cf26d29 100644--- a/server/services/brainMemoryBridge.js+++ b/server/services/brainMemoryBridge.js@@ -45,7 +45,12 @@ export async function loadBridgeMap() {return bridgeMap;}const raw = await readFile(BRIDGE_MAP_PATH, 'utf-8');- bridgeMap = JSON.parse(raw);+ try {+ bridgeMap = JSON.parse(raw);+ } catch (err) {+ console.error(`❌ Corrupt bridge map, resetting: ${err.message}`);+ bridgeMap = {};+ }return bridgeMap;}