@andespindola/brainlink 0.1.0-beta.124 → 0.1.0-beta.125

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 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 capped at 1000 nodes, the macro level projected as its own graph, 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 level capped at 1000 group nodes, zoom-in expands the framed node into its child graph capped at 1000 nodes, micro view renders only that focused subgraph in a local frame anchored to the group node, and zoom-out restores sibling groups
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 into its child graph capped at 1000 nodes, micro view renders only that focused subgraph in a local frame anchored to the 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
 
@@ -1233,6 +1233,40 @@ const createGroupRenderNode = group => ({
1233
1233
  radius: groupRenderRadius(group)
1234
1234
  })
1235
1235
 
1236
+ const arrangeGraphLevelNodes = (nodes, radiusForNode = () => 1) => {
1237
+ if (nodes.length <= 1) {
1238
+ return nodes
1239
+ }
1240
+
1241
+ const centerNode = nodes
1242
+ .map(node => ({
1243
+ node,
1244
+ score: Math.max(node.nodeIds?.length ?? 0, node.childGroupIds?.length ?? 0, 1) + (node.externalEdges?.length ?? 0)
1245
+ }))
1246
+ .sort((left, right) => right.score - left.score || left.node.title.localeCompare(right.node.title))[0]?.node
1247
+ const outerNodes = nodes
1248
+ .filter(node => node.id !== centerNode?.id)
1249
+ .sort((left, right) => left.segment.localeCompare(right.segment) || left.title.localeCompare(right.title))
1250
+ const baseRadius = Math.max(520, Math.min(2200, Math.sqrt(nodes.length) * 135))
1251
+ const goldenAngle = Math.PI * (3 - Math.sqrt(5))
1252
+ const arranged = centerNode
1253
+ ? [{ ...centerNode, x: 0, y: 0, radius: radiusForNode(centerNode) }]
1254
+ : []
1255
+
1256
+ outerNodes.forEach((node, index) => {
1257
+ const ringRadius = baseRadius * Math.sqrt((index + 1) / Math.max(outerNodes.length, 1))
1258
+ const angle = index * goldenAngle
1259
+ arranged.push({
1260
+ ...node,
1261
+ x: Math.cos(angle) * ringRadius,
1262
+ y: Math.sin(angle) * ringRadius,
1263
+ radius: radiusForNode(node)
1264
+ })
1265
+ })
1266
+
1267
+ return arranged
1268
+ }
1269
+
1236
1270
  const localGraphBounds = nodes => {
1237
1271
  if (nodes.length === 0) {
1238
1272
  return { centerX: 0, centerY: 0, radius: 1 }
@@ -1291,9 +1325,9 @@ const hierarchyGroupsForScale = () => {
1291
1325
  return []
1292
1326
  }
1293
1327
  if (state.transform.scale < hierarchyExpansionStartScale) {
1294
- return parentHierarchyGroups()
1328
+ return arrangeGraphLevelNodes(parentHierarchyGroups(), groupRenderRadius)
1295
1329
  }
1296
- return state.leafGroups
1330
+ return arrangeGraphLevelNodes(state.leafGroups, groupRenderRadius)
1297
1331
  }
1298
1332
 
1299
1333
  const groupViewportCoverage = (group, viewport) => {
@@ -1315,7 +1349,9 @@ const groupWithCoverage = (group, viewport) => ({
1315
1349
  })
1316
1350
 
1317
1351
  const updateHierarchyFocusGroup = (groups, viewport) => {
1318
- const current = state.hierarchyFocusGroupId ? state.groupById.get(state.hierarchyFocusGroupId) : null
1352
+ const current = state.hierarchyFocusGroupId
1353
+ ? groups.find(group => group.id === state.hierarchyFocusGroupId) ?? null
1354
+ : null
1319
1355
  const currentCoverage = current ? groupViewportCoverage(current, viewport) : 0
1320
1356
 
1321
1357
  if (
@@ -1973,7 +2009,11 @@ const fitView = (options = { useFiltered: true, preferHubCenter: true }) => {
1973
2009
  const width = Math.max(rect.width, 320)
1974
2010
  const height = Math.max(rect.height, 320)
1975
2011
  const nodes = options.useFiltered ? filteredNodes() : state.nodes
1976
- const bounds = graphBounds(nodes)
2012
+ const hierarchyFitNodes = state.groups.length > 0 && nodes.length > 1000
2013
+ ? arrangeGraphLevelNodes(parentHierarchyGroups(), groupRenderRadius).map(createGroupRenderNode)
2014
+ : null
2015
+ const fitNodes = hierarchyFitNodes ?? nodes
2016
+ const bounds = graphBounds(fitNodes)
1977
2017
 
1978
2018
  if (!bounds) {
1979
2019
  state.transform = { x: width / 2, y: height / 2, scale: 1 }
@@ -1993,17 +2033,20 @@ const fitView = (options = { useFiltered: true, preferHubCenter: true }) => {
1993
2033
  if (nodeCount <= 2000) return 140
1994
2034
  return 180
1995
2035
  }
1996
- const padding = paddingByNodeCount(nodes.length)
2036
+ const padding = paddingByNodeCount(fitNodes.length)
1997
2037
  const scaleX = width / (bounds.width + padding * 2)
1998
2038
  const scaleY = height / (bounds.height + padding * 2)
1999
2039
  const fitScale = Math.min(scaleX, scaleY)
2000
- const biasedScale = clampScale(fitScale * fitScaleBiasByNodeCount(nodes.length))
2001
- const scaleRange = autoFitScaleRangeByNodeCount(nodes.length)
2040
+ const biasedScale = clampScale(fitScale * fitScaleBiasByNodeCount(fitNodes.length))
2041
+ const scaleRange = autoFitScaleRangeByNodeCount(fitNodes.length)
2002
2042
  const baselineScale = clampScale(Math.min(scaleRange.max, Math.max(scaleRange.min, biasedScale)))
2003
- const resolvedScale = nodes.length > massiveGraphNodeThreshold
2043
+ const resolvedScale = nodes.length > massiveGraphNodeThreshold && !hierarchyFitNodes
2004
2044
  ? clampScale(Math.min(baselineScale, massiveAutoFitMacroScale))
2005
2045
  : baselineScale
2006
2046
  const hubCenter =
2047
+ hierarchyFitNodes
2048
+ ? null
2049
+ :
2007
2050
  options.preferHubCenter && isDominantHub(state.primaryHub, nodes.length) && nodes.some((node) => node.id === state.primaryHub.id)
2008
2051
  ? state.primaryHub
2009
2052
  : null
@@ -24,6 +24,40 @@ const childGraphRenderRadius = (group) => {
24
24
  const childCount = Math.max(group.nodeIds.length, group.childGroupIds.length, 1);
25
25
  return Math.max(420, Math.min(1800, Math.sqrt(childCount) * 24));
26
26
  };
27
+ const groupRenderRadius = (group) => {
28
+ const childCount = Math.max(group.nodeIds.length, group.childGroupIds.length, 1);
29
+ return 10 + Math.min(Math.log2(childCount + 1) * 4.2, 22);
30
+ };
31
+ const arrangeGraphLevelGroups = (groups) => {
32
+ if (groups.length <= 1) {
33
+ return groups.map((group) => ({ ...group, radius: groupRenderRadius(group) }));
34
+ }
35
+ const centerGroup = groups
36
+ .map((group) => ({
37
+ group,
38
+ score: Math.max(group.nodeIds.length, group.childGroupIds.length, 1) + group.externalEdges.length
39
+ }))
40
+ .sort((left, right) => right.score - left.score || left.group.title.localeCompare(right.group.title))[0]?.group;
41
+ const outerGroups = groups
42
+ .filter((group) => group.id !== centerGroup?.id)
43
+ .sort((left, right) => left.segment.localeCompare(right.segment) || left.title.localeCompare(right.title));
44
+ const baseRadius = Math.max(520, Math.min(2200, Math.sqrt(groups.length) * 135));
45
+ const goldenAngle = Math.PI * (3 - Math.sqrt(5));
46
+ const arranged = centerGroup
47
+ ? [{ ...centerGroup, x: 0, y: 0, radius: groupRenderRadius(centerGroup) }]
48
+ : [];
49
+ outerGroups.forEach((group, index) => {
50
+ const ringRadius = baseRadius * Math.sqrt((index + 1) / Math.max(outerGroups.length, 1));
51
+ const angle = index * goldenAngle;
52
+ arranged.push({
53
+ ...group,
54
+ x: Math.cos(angle) * ringRadius,
55
+ y: Math.sin(angle) * ringRadius,
56
+ radius: groupRenderRadius(group)
57
+ });
58
+ });
59
+ return arranged;
60
+ };
27
61
  const groupNode = (group) => [
28
62
  `group:${group.id}`,
29
63
  group.title,
@@ -145,8 +179,10 @@ export const getGraphView = async (vaultPath, input) => {
145
179
  }
146
180
  };
147
181
  }
148
- const visibleGroups = groups.filter((group) => group.parentId === null && inViewport(group, input));
149
- const focused = groups
182
+ const rootGroups = arrangeGraphLevelGroups(groups.filter((group) => group.parentId === null));
183
+ const leafGroups = arrangeGraphLevelGroups(groups.filter((group) => group.nodeIds.length > 0));
184
+ const visibleGroups = rootGroups.filter((group) => inViewport(group, input));
185
+ const focused = leafGroups
150
186
  .filter((group) => group.nodeIds.length > 0 && inViewport(group, input))
151
187
  .map((group) => ({ group, coverage: groupCoverage(group, input) }))
152
188
  .sort((left, right) => right.coverage - left.coverage)[0];
@@ -177,7 +213,7 @@ export const getGraphView = async (vaultPath, input) => {
177
213
  }
178
214
  };
179
215
  }
180
- const groupsToRender = (visibleGroups.length > 0 ? visibleGroups : groups.filter((group) => group.parentId === null)).slice(0, nodeLimit);
216
+ const groupsToRender = (visibleGroups.length > 0 ? visibleGroups : rootGroups).slice(0, nodeLimit);
181
217
  const viewNodes = groupsToRender.map(groupNode);
182
218
  return {
183
219
  signature,
@@ -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 those groups as normal mesh graph nodes, zoom-in expands a group only after it is framed in the viewport, and micro view renders only the focused subgraph in a local frame anchored to the 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 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 only after it is framed in the viewport, and micro view renders only the focused subgraph in a local frame anchored to the 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.124",
3
+ "version": "0.1.0-beta.125",
4
4
  "description": "Local-first knowledge memory for agents with Markdown, backlinks, indexing and context retrieval.",
5
5
  "type": "module",
6
6
  "license": "MIT",