@andespindola/brainlink 0.1.0-beta.127 → 0.1.0-beta.128

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/README.md CHANGED
@@ -84,7 +84,7 @@ Legacy `.jsonl.gz` packs are upgraded to `.blpk` automatically on first search/c
84
84
  - Graph renderer optimized for large datasets with viewport-driven node culling and edge lookup by visible nodes.
85
85
  - Canvas graph rendering uses the same batched node and edge pipeline for every graph size, reducing per-frame draw calls while keeping selected and hovered items highlighted.
86
86
  - WebGL acceleration is used when available for dense node and edge drawing, with Canvas 2D preserved as the interaction and fallback layer.
87
- - Graph rendering keeps the flat node scene and adds stable hierarchical mesh groups for vaults above 1000 notes, with every visible graph level capped at 1000 nodes, the macro level projected as its own graph, and recursive parent groups when a level itself exceeds 1000 groups.
87
+ - Graph rendering keeps the flat node scene and adds stable hierarchical mesh groups for vaults above 1000 notes, with every visible graph level filled toward 1000 nodes, each group capped at 1000 child nodes, and recursive parent groups when a level itself exceeds 1000 groups.
88
88
  - Large graph layout API automatically uses compact payload encoding with link-coverage-aware edge selection to reduce initial client load without hiding major relationships.
89
89
  - Large-segment layout spacing now grows logarithmically to keep initial visual density consistent between medium and very large vaults (for example, ~1k vs ~50k notes).
90
90
  - Graph coordinates are visually compacted across graph sizes so reset starts from a stable fitted scene and zoom-in progressively reveals local detail.
@@ -606,7 +606,7 @@ The graph UI shows:
606
606
  - graph rendering safeguards (batched canvas drawing across graph sizes, edge draw caps, lower redraw rate, zoom-aware interaction)
607
607
  - adaptive CPU safeguards for large graphs: idle frame pacing, throttled background physics updates and cached viewport dimensions to reduce redraw/layout overhead while preserving interaction responsiveness
608
608
  - WebGL node and edge acceleration when supported, falling back to Canvas 2D without changing graph behavior
609
- - large graph LOD keeps a recursive graph-of-graphs mesh model: zoom-out shows one projected graph level capped at 1000 group nodes, zoom-in expands the framed node from its current viewport position into its own radial child graph capped at 1000 nodes, micro view renders only that focused subgraph with dense-node label suppression in a local frame anchored to the rendered group node, and zoom-out restores sibling groups
609
+ - large graph LOD keeps a recursive graph-of-graphs mesh model: zoom-out fills the projected macro level toward 1000 lightweight group nodes, zoom-in expands the framed node from its current viewport position into its own radial child graph capped at 1000 nodes, micro view renders only that focused subgraph with dense-node label suppression in a local frame anchored to the rendered group node, and zoom-out restores sibling groups
610
610
 
611
611
  The server indexes before starting by default. Use `--no-index` to skip that step:
612
612
 
@@ -23,8 +23,8 @@ const transformCoordinateLimit = 20_000_000
23
23
  const hoverHitTestIntervalMs = 64
24
24
  const zoomRecoveryGuardMs = 4200
25
25
  const meshEdgeScaleThreshold = 0.09
26
- const meshEdgeMinBudget = 140
27
- const meshEdgeMaxBudget = 1400
26
+ const meshEdgeMinBudget = 90
27
+ const meshEdgeMaxBudget = 850
28
28
  const dragNeighborhoodMaxAffected = 180
29
29
  const dragSettleRounds = 3
30
30
  const wheelZoomExponent = 0.0009
@@ -1360,6 +1360,33 @@ const groupWithCoverage = (group, viewport) => ({
1360
1360
  coverage: groupViewportCoverage(group, viewport)
1361
1361
  })
1362
1362
 
1363
+ const distanceToViewportCenter = (item, viewport) => {
1364
+ const centerX = (viewport.minX + viewport.maxX) / 2
1365
+ const centerY = (viewport.minY + viewport.maxY) / 2
1366
+ return Math.hypot(item.x - centerX, item.y - centerY)
1367
+ }
1368
+
1369
+ const selectViewportItemsWithFill = (items, viewport, limit = renderNodeBudget) => {
1370
+ const visible = items.filter(item =>
1371
+ item.x + item.radius >= viewport.minX &&
1372
+ item.x - item.radius <= viewport.maxX &&
1373
+ item.y + item.radius >= viewport.minY &&
1374
+ item.y - item.radius <= viewport.maxY
1375
+ )
1376
+
1377
+ if (visible.length >= limit) {
1378
+ return visible.slice(0, limit)
1379
+ }
1380
+
1381
+ const selectedIds = new Set(visible.map(item => item.id))
1382
+ const fill = items
1383
+ .filter(item => !selectedIds.has(item.id))
1384
+ .sort((left, right) => distanceToViewportCenter(left, viewport) - distanceToViewportCenter(right, viewport) || left.id.localeCompare(right.id))
1385
+ .slice(0, Math.max(0, limit - visible.length))
1386
+
1387
+ return visible.concat(fill)
1388
+ }
1389
+
1363
1390
  const updateHierarchyFocusGroup = (groups, viewport) => {
1364
1391
  const current = state.hierarchyFocusGroupId
1365
1392
  ? groups.find(group => group.id === state.hierarchyFocusGroupId) ?? null
@@ -1451,14 +1478,7 @@ const computeHierarchyRenderVisibility = (viewport) => {
1451
1478
  return false
1452
1479
  }
1453
1480
 
1454
- const groups = hierarchyGroupsForScale()
1455
- .filter(group =>
1456
- group.x + group.radius >= viewport.minX &&
1457
- group.x - group.radius <= viewport.maxX &&
1458
- group.y + group.radius >= viewport.minY &&
1459
- group.y - group.radius <= viewport.maxY
1460
- )
1461
- .slice(0, renderNodeBudget)
1481
+ const groups = selectViewportItemsWithFill(hierarchyGroupsForScale(), viewport, renderNodeBudget)
1462
1482
  const focus = updateHierarchyFocusGroup(groups, viewport)
1463
1483
  const progress = focus ? hierarchyViewportProgress(focus, viewport) : 0
1464
1484
  const groupNodes = groups.map(createGroupRenderNode)
@@ -1555,12 +1575,12 @@ const buildMeshEdgesForNodes = (nodes, existingEdges) => {
1555
1575
 
1556
1576
  const desiredBudget = Math.min(
1557
1577
  meshEdgeMaxBudget,
1558
- Math.max(meshEdgeMinBudget, Math.floor(edgeBudgetForCurrentFrame() * 0.62))
1578
+ Math.max(meshEdgeMinBudget, Math.floor(edgeBudgetForCurrentFrame() * 0.36))
1559
1579
  )
1560
1580
  const perNodeNeighborCount =
1561
- state.transform.scale >= 1.05 ? 4
1562
- : state.transform.scale >= 0.62 ? 3
1563
- : 2
1581
+ state.transform.scale >= 1.05 ? 3
1582
+ : state.transform.scale >= 0.62 ? 2
1583
+ : 1
1564
1584
  const cellSize = Math.max(120, 280 / Math.max(state.transform.scale, 0.0001))
1565
1585
  const maxDistance = 980
1566
1586
  const maxDistanceSquared = maxDistance * maxDistance
@@ -4,12 +4,13 @@ import { dirname, join } from 'node:path';
4
4
  import { createCauliflowerGraphLayout } from '../domain/graph-layout.js';
5
5
  import { indexStoragePath } from '../infrastructure/file-index.js';
6
6
  import { getGraphSummary } from './get-graph-summary.js';
7
+ const graphLayoutVersion = 2;
7
8
  const graphLayoutCache = new Map();
8
9
  const graphLayoutStoragePath = (vaultPath, agentId) => join(vaultPath, '.brainlink', `graph-layout-${agentId?.replace(/[^a-zA-Z0-9_-]/g, '_') ?? 'all'}.json`);
9
10
  const readPersistedLayout = async (vaultPath, databaseSignature, agentId) => {
10
11
  try {
11
12
  const parsed = JSON.parse(await readFile(graphLayoutStoragePath(vaultPath, agentId), 'utf8'));
12
- return parsed.databaseSignature === databaseSignature ? parsed : null;
13
+ return parsed.databaseSignature === databaseSignature && parsed.layoutVersion === graphLayoutVersion ? parsed : null;
13
14
  }
14
15
  catch {
15
16
  return null;
@@ -44,7 +45,7 @@ export const getGraphLayout = async (vaultPath, agentId) => {
44
45
  const databaseSignature = await readDatabaseSignature(vaultPath);
45
46
  const cacheKey = `${vaultPath}:${agentId ?? ''}`;
46
47
  const cached = graphLayoutCache.get(cacheKey);
47
- if (cached?.databaseSignature === databaseSignature) {
48
+ if (cached?.databaseSignature === databaseSignature && cached.layoutVersion === graphLayoutVersion) {
48
49
  return {
49
50
  signature: cached.signature,
50
51
  layout: cached.layout
@@ -65,7 +66,7 @@ export const getGraphLayout = async (vaultPath, agentId) => {
65
66
  ...rawLayout,
66
67
  nodes: rawLayout.nodes.map((node) => ({ ...node, content: '' }))
67
68
  };
68
- const nextCache = { databaseSignature, signature, layout };
69
+ const nextCache = { layoutVersion: graphLayoutVersion, databaseSignature, signature, layout };
69
70
  graphLayoutCache.set(cacheKey, nextCache);
70
71
  await writePersistedLayout(vaultPath, agentId, nextCache);
71
72
  return {
@@ -2,8 +2,8 @@ import { getGraphLayout } from './get-graph-layout.js';
2
2
  const macroScale = 0.24;
3
3
  const microCoverage = 0.72;
4
4
  const nodeLimit = 1000;
5
- const edgeLimit = 5000;
6
- const meshEdgeLimit = 2500;
5
+ const edgeLimit = 3200;
6
+ const meshEdgeLimit = 1200;
7
7
  const inViewport = (item, input) => {
8
8
  const radius = item.radius ?? 48;
9
9
  return (item.x + radius >= input.x &&
@@ -58,6 +58,23 @@ const arrangeGraphLevelGroups = (groups) => {
58
58
  });
59
59
  return arranged;
60
60
  };
61
+ const distanceToViewportCenter = (item, input) => {
62
+ const centerX = input.x + input.width / 2;
63
+ const centerY = input.y + input.height / 2;
64
+ return Math.hypot(item.x - centerX, item.y - centerY);
65
+ };
66
+ const selectViewportItemsWithFill = (items, input, limit = nodeLimit) => {
67
+ const visible = items.filter((item) => inViewport(item, input));
68
+ if (visible.length >= limit) {
69
+ return visible.slice(0, limit);
70
+ }
71
+ const selectedIds = new Set(visible.map((item) => item.id));
72
+ const fill = items
73
+ .filter((item) => !selectedIds.has(item.id))
74
+ .sort((left, right) => distanceToViewportCenter(left, input) - distanceToViewportCenter(right, input) || left.id.localeCompare(right.id))
75
+ .slice(0, Math.max(0, limit - visible.length));
76
+ return visible.concat(fill);
77
+ };
61
78
  const groupNode = (group) => [
62
79
  `group:${group.id}`,
63
80
  group.title,
@@ -195,7 +212,7 @@ export const getGraphView = async (vaultPath, input) => {
195
212
  }
196
213
  const rootGroups = arrangeGraphLevelGroups(groups.filter((group) => group.parentId === null));
197
214
  const leafGroups = arrangeGraphLevelGroups(groups.filter((group) => group.nodeIds.length > 0));
198
- const visibleGroups = rootGroups.filter((group) => inViewport(group, input));
215
+ const visibleGroups = selectViewportItemsWithFill(rootGroups, input);
199
216
  const focused = leafGroups
200
217
  .filter((group) => group.nodeIds.length > 0 && inViewport(group, input))
201
218
  .map((group) => ({ group, coverage: groupCoverage(group, input) }))
@@ -222,7 +239,7 @@ export const getGraphView = async (vaultPath, input) => {
222
239
  }
223
240
  };
224
241
  }
225
- const groupsToRender = (visibleGroups.length > 0 ? visibleGroups : rootGroups).slice(0, nodeLimit);
242
+ const groupsToRender = visibleGroups.slice(0, nodeLimit);
226
243
  const viewNodes = groupsToRender.map(groupNode);
227
244
  return {
228
245
  signature,
@@ -231,9 +231,13 @@ const chunkNodes = (nodes, degrees, groupNodeLimit = hierarchyGroupNodeLimit) =>
231
231
  return degreeDelta;
232
232
  return left.title.localeCompare(right.title);
233
233
  });
234
+ const groupCountTarget = Math.min(groupNodeLimit, sortedNodes.length);
235
+ const chunkSize = sortedNodes.length <= groupNodeLimit * groupNodeLimit
236
+ ? Math.max(1, Math.ceil(sortedNodes.length / groupCountTarget))
237
+ : groupNodeLimit;
234
238
  const chunks = [];
235
- for (let index = 0; index < sortedNodes.length; index += groupNodeLimit) {
236
- chunks.push(sortedNodes.slice(index, index + groupNodeLimit));
239
+ for (let index = 0; index < sortedNodes.length; index += chunkSize) {
240
+ chunks.push(sortedNodes.slice(index, index + chunkSize));
237
241
  }
238
242
  return chunks;
239
243
  };
@@ -607,7 +607,7 @@ Without `--vault`, the graph UI serves `$HOME/.brainlink/vault`.
607
607
 
608
608
  The frontend includes an agent selector that shows only the agent id. Selecting an agent calls the same read APIs with `agent=<agent-id>` and renders that namespace instead of merging every agent into one graph.
609
609
 
610
- Graph navigation controls include zoom in, zoom out, fit visible nodes and reset-to-fit-all nodes. Mouse wheel zoom (including `cmd+scroll` and `ctrl+scroll`) is anchored to the cursor. Keyboard shortcuts are `+` (zoom in), `-` (zoom out) and `0` (reset fit). Double-click on canvas zooms in at cursor position. Totals for notes, links and tags stay visible as floating metrics under the Brainlink title, and node details open on click in a modal (tags, outgoing links, backlinks and Markdown content). Vaults above 1000 notes also expose stable hierarchy mesh groups of up to 1000 direct nodes, with recursive parent groups when a level exceeds 1000 groups; zoom-out renders the macro level as a projected mesh graph of group nodes, zoom-in expands a group from the focused node's current viewport position only after it is framed, and micro view renders only the focused radial child graph with dense-node label suppression in a local frame anchored to the rendered group node until zoom-out restores sibling groups.
610
+ Graph navigation controls include zoom in, zoom out, fit visible nodes and reset-to-fit-all nodes. Mouse wheel zoom (including `cmd+scroll` and `ctrl+scroll`) is anchored to the cursor. Keyboard shortcuts are `+` (zoom in), `-` (zoom out) and `0` (reset fit). Double-click on canvas zooms in at cursor position. Totals for notes, links and tags stay visible as floating metrics under the Brainlink title, and node details open on click in a modal (tags, outgoing links, backlinks and Markdown content). Vaults above 1000 notes also expose stable hierarchy mesh groups that fill each visible graph level toward 1000 nodes while keeping every group capped at 1000 child nodes; zoom-out renders the macro level as a projected mesh graph of group nodes, zoom-in expands a group from the focused node's current viewport position only after it is framed, and micro view renders only the focused radial child graph with dense-node label suppression in a local frame anchored to the rendered group node until zoom-out restores sibling groups.
611
611
  During graph filtering, Brainlink keeps hub context nodes visible (`Memory Hub`/`MOC`/high-degree fallback) so filtered views still show relationship anchors.
612
612
 
613
613
  The command reindexes by default, then serves:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andespindola/brainlink",
3
- "version": "0.1.0-beta.127",
3
+ "version": "0.1.0-beta.128",
4
4
  "description": "Local-first knowledge memory for agents with Markdown, backlinks, indexing and context retrieval.",
5
5
  "type": "module",
6
6
  "license": "MIT",