@andespindola/brainlink 0.1.0-beta.157 → 0.1.0-beta.158

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
@@ -82,9 +82,9 @@ Legacy `.jsonl.gz` packs are upgraded to `.blpk` automatically on first search/c
82
82
  - Built-in MCP stdio server for agent tool integration.
83
83
  - Local HTTP API.
84
84
  - Realtime graph UI with agent selector and colored knowledge groups.
85
- - Graph renderer uses a cauliflower-style hub layout: the primary hub stays centered, segment hubs anchor surrounding lobes, and real weighted `[[wiki link]]` edges stay preserved for backlinks, ranking and context traversal.
86
- - The full filtered graph stays visible during zoom/pan, rendering every visible node and edge without viewport culling or edge caps in the main view.
87
- - Graph exploration uses viewport-first chunk streaming (`/api/graph-stream`) with explicit node/edge budgets.
85
+ - Graph renderer uses a cauliflower-style hub layout: the primary hub stays centered, segment hubs anchor surrounding lobes, and visual edges are simplified to root hub -> segment hubs -> local context nodes.
86
+ - Real weighted `[[wiki link]]` edges stay preserved in the indexed graph APIs for backlinks, ranking and context traversal; the browser layout uses a separate visual edge layer for readability.
87
+ - Graph exploration uses stable chunk streaming (`/api/graph-stream`) with explicit node/edge budgets, returning the full mode-level scene while it fits the budget.
88
88
  - Render pipeline uses WebGL in a dedicated worker through `OffscreenCanvas`, keeping the main thread focused on UI controls and details panels.
89
89
  - Large graph layout API automatically uses compact payload encoding with link-coverage-aware edge selection to reduce initial client load without hiding major relationships.
90
90
  - 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).
@@ -599,8 +599,8 @@ When native GUI is used, the GUI window automatically closes when the `blink ser
599
599
  The graph UI shows:
600
600
 
601
601
  - notes as nodes
602
- - all non-self `[[wiki links]]` inside `## Context Links` as weighted edges
603
- - default cauliflower-style layout centered on the primary hub, with segment hubs anchoring surrounding lobes and without rewriting or flattening underlying relationships
602
+ - all non-self `[[wiki links]]` inside `## Context Links` as weighted indexed edges
603
+ - default cauliflower-style visual layout centered on the primary hub, with segment hubs anchoring surrounding lobes and visual edges simplified to root hub -> segment hubs -> local context nodes
604
604
  - details opened in a non-modal side panel (tags, outgoing links, backlinks, full Markdown content), so zoom and pan remain available while inspecting data
605
605
  - neutral graph nodes with segment/group metadata
606
606
  - agent selector (id-only labels) for isolated views
@@ -619,7 +619,7 @@ The graph UI shows:
619
619
  - graph rendering safeguards (batched GPU draw calls, lower redraw rate, zoom-aware interaction)
620
620
  - 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
621
621
  - worker-first WebGL rendering with Canvas fallback when `OffscreenCanvas` or worker rendering is unavailable
622
- - large graph view keeps one semantic graph model across zoom levels, uses segment clusters at high zoom-out, and shows node titles as zoom approaches readable scale
622
+ - large graph view keeps one indexed graph model across zoom levels, uses a stable visual hierarchy for rendering, uses segment clusters at high zoom-out, and shows node titles as zoom approaches readable scale
623
623
 
624
624
  The server indexes before starting by default. Use `--no-index` to skip that step:
625
625
 
@@ -5,7 +5,7 @@ import { addVisualContextEdges } from '../domain/graph-contexts.js';
5
5
  import { createCauliflowerGraphLayout } from '../domain/graph-layout.js';
6
6
  import { indexStoragePath } from '../infrastructure/file-index.js';
7
7
  import { getGraphSummary } from './get-graph-summary.js';
8
- const graphLayoutVersion = 7;
8
+ const graphLayoutVersion = 8;
9
9
  const graphLayoutCache = new Map();
10
10
  const safeCacheSegment = (value, fallback) => value?.replace(/[^a-zA-Z0-9_-]/g, '_') || fallback;
11
11
  const graphLayoutStoragePath = (vaultPath, options) => {
@@ -107,13 +107,15 @@ const selectTopByRelevance = (items, relevanceById, budget) => [...items]
107
107
  .slice(0, Math.max(1, budget));
108
108
  const selectNearNodes = (nodes, cache, input) => {
109
109
  const padding = Math.max(input.width, input.height) * viewportPaddingFactor;
110
- const viewportNodes = nodes.filter((node) => inViewport(node, input, padding));
110
+ const candidateNodes = nodes.length <= input.nodeBudget
111
+ ? nodes
112
+ : nodes.filter((node) => inViewport(node, input, padding));
111
113
  const relevance = new Map();
112
- for (let index = 0; index < viewportNodes.length; index += 1) {
113
- const node = viewportNodes[index];
114
+ for (let index = 0; index < candidateNodes.length; index += 1) {
115
+ const node = candidateNodes[index];
114
116
  relevance.set(node.id, rankNodeRelevance(node, input, cache.degrees));
115
117
  }
116
- const selected = selectTopByRelevance(viewportNodes, relevance, input.nodeBudget);
118
+ const selected = selectTopByRelevance(candidateNodes, relevance, input.nodeBudget);
117
119
  return selected.map((node) => [
118
120
  node.id,
119
121
  node.title,
@@ -127,13 +129,15 @@ const selectNearNodes = (nodes, cache, input) => {
127
129
  };
128
130
  const selectMidNodes = (nodes, cache, input) => {
129
131
  const padding = Math.max(input.width, input.height) * (viewportPaddingFactor + 0.08);
130
- const viewportNodes = nodes.filter((node) => inViewport(node, input, padding));
132
+ const candidateNodes = nodes.length <= input.nodeBudget
133
+ ? nodes
134
+ : nodes.filter((node) => inViewport(node, input, padding));
131
135
  const relevance = new Map();
132
- for (let index = 0; index < viewportNodes.length; index += 1) {
133
- const node = viewportNodes[index];
136
+ for (let index = 0; index < candidateNodes.length; index += 1) {
137
+ const node = candidateNodes[index];
134
138
  relevance.set(node.id, rankNodeRelevance(node, input, cache.degrees) * 1.1);
135
139
  }
136
- const selected = selectTopByRelevance(viewportNodes, relevance, input.nodeBudget);
140
+ const selected = selectTopByRelevance(candidateNodes, relevance, input.nodeBudget);
137
141
  return selected.map((node) => [
138
142
  node.id,
139
143
  node.title,
@@ -147,14 +151,12 @@ const selectMidNodes = (nodes, cache, input) => {
147
151
  };
148
152
  const selectFarClusters = (nodes, input, nodeBudget) => {
149
153
  const roots = createSegmentClusters(nodes);
150
- const padding = Math.max(input.width, input.height) * 0.12;
151
- const candidates = roots.filter((group) => inViewport(group, input, padding));
152
154
  const relevance = new Map();
153
- for (let index = 0; index < candidates.length; index += 1) {
154
- const group = candidates[index];
155
+ for (let index = 0; index < roots.length; index += 1) {
156
+ const group = roots[index];
155
157
  relevance.set(group.id, rankGroupRelevance(group, input));
156
158
  }
157
- const selected = selectTopByRelevance(candidates, relevance, nodeBudget);
159
+ const selected = selectTopByRelevance(roots, relevance, nodeBudget);
158
160
  return selected.map((group) => [
159
161
  `cluster:${group.id}`,
160
162
  group.title,
@@ -219,13 +219,13 @@ const segmentCenterRadius = (segments) => {
219
219
  const circumference = segments.reduce((total, [, nodes]) => total + petalRadiusForSegmentSize(nodes.length) * 2 + 180, 0);
220
220
  return Math.max(520, circumference / (Math.PI * 2));
221
221
  };
222
- const createCauliflowerSegmentNodes = (segments, degrees, primaryHubId, segmentGroups) => ([segment, nodes], segmentIndex) => {
222
+ const createCauliflowerSegmentNodes = (segments, degrees, rootHubId, segmentGroups) => ([segment, nodes], segmentIndex) => {
223
223
  const sortedNodes = [...nodes].sort(byDegreeThenTitle(degrees));
224
- const segmentHub = selectSegmentHub(sortedNodes, degrees, primaryHubId);
224
+ const segmentHub = selectSegmentHub(sortedNodes, degrees, rootHubId);
225
225
  const angle = segmentAngle(segment, segmentIndex, segmentGroups.length);
226
226
  const globalRadius = segmentCenterRadius(segmentGroups);
227
227
  const petalRadius = petalRadiusForSegmentSize(sortedNodes.length);
228
- const isPrimarySegment = Boolean(segmentHub && segmentHub.id === primaryHubId);
228
+ const isPrimarySegment = Boolean(segmentHub && segmentHub.id === rootHubId);
229
229
  const centerX = isPrimarySegment || globalRadius === 0 ? 0 : Math.cos(angle) * globalRadius;
230
230
  const centerY = isPrimarySegment || globalRadius === 0 ? 0 : Math.sin(angle) * (globalRadius * 0.86);
231
231
  const nonHubNodes = sortedNodes.filter((node) => node.id !== segmentHub?.id);
@@ -254,6 +254,41 @@ const createCauliflowerSegmentNodes = (segments, degrees, primaryHubId, segmentG
254
254
  });
255
255
  return [...hubNode, ...petalNodes];
256
256
  };
257
+ const createVisualEdge = (source, target, weight, priority) => ({
258
+ source: source.id,
259
+ target: target.id,
260
+ targetTitle: target.title,
261
+ weight,
262
+ priority
263
+ });
264
+ const createCauliflowerVisualEdges = (segmentGroups, degrees, rootHubId) => {
265
+ const nodeById = new Map(segmentGroups.flatMap(([, nodes]) => nodes.map((node) => [node.id, node])));
266
+ const rootHub = rootHubId ? nodeById.get(rootHubId) ?? null : null;
267
+ const edges = new Map();
268
+ const addEdge = (edge) => {
269
+ if (!edge.target || edge.source === edge.target) {
270
+ return;
271
+ }
272
+ edges.set(`${edge.source}|${edge.target}`, edge);
273
+ };
274
+ segmentGroups.forEach(([, nodes]) => {
275
+ const segmentHub = selectSegmentHub(nodes, degrees, rootHubId);
276
+ const parent = segmentHub ?? rootHub;
277
+ if (!parent) {
278
+ return;
279
+ }
280
+ if (rootHub && parent.id !== rootHub.id) {
281
+ addEdge(createVisualEdge(rootHub, parent, 6, 'high'));
282
+ }
283
+ nodes.forEach((node) => {
284
+ if (node.id === parent.id || node.id === rootHub?.id) {
285
+ return;
286
+ }
287
+ addEdge(createVisualEdge(parent, node, 1, 'low'));
288
+ });
289
+ });
290
+ return Array.from(edges.values());
291
+ };
257
292
  const distanceBetween = (left, right) => Math.hypot(right.x - left.x, right.y - left.y);
258
293
  const layoutBounds = (nodes) => {
259
294
  if (nodes.length === 0) {
@@ -576,13 +611,14 @@ export const createCauliflowerGraphLayout = (graph) => {
576
611
  const segments = assignSegments(graph.nodes, graph.edges, degrees);
577
612
  const segmentGroups = Array.from(groupNodesBySegment(graph.nodes, segments).entries())
578
613
  .sort(([left], [right]) => left.localeCompare(right));
579
- const primaryHubId = selectPrimaryHubId(graph.nodes, degrees);
580
- const nodes = relaxCollisions(segmentGroups.flatMap(createCauliflowerSegmentNodes(segments, degrees, primaryHubId, segmentGroups)), 156, 28);
581
- const centeredNodes = centerLayoutByNode(nodes, primaryHubId);
582
- const groups = createGraphLayoutHierarchy(centeredNodes, graph.edges, degrees);
614
+ const rootHubId = selectPrimaryHubId(graph.nodes, degrees) ?? selectHighestDegreeNodeId(graph.nodes, degrees);
615
+ const nodes = relaxCollisions(segmentGroups.flatMap(createCauliflowerSegmentNodes(segments, degrees, rootHubId, segmentGroups)), 156, 28);
616
+ const centeredNodes = centerLayoutByNode(nodes, rootHubId);
617
+ const visualEdges = createCauliflowerVisualEdges(segmentGroups, degrees, rootHubId);
618
+ const groups = createGraphLayoutHierarchy(centeredNodes, visualEdges, degrees);
583
619
  return {
584
620
  nodes: centeredNodes,
585
- edges: graph.edges,
621
+ edges: visualEdges,
586
622
  ...(groups.length > 0 ? { groups } : {})
587
623
  };
588
624
  };
@@ -610,7 +610,7 @@ Without `--vault`, the graph UI serves `$HOME/.brainlink/vault`.
610
610
 
611
611
  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.
612
612
 
613
- 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 and applied immediately without delayed focus interpolation. Keyboard shortcuts are `+` (zoom in), `-` (zoom out) and `0` (reset fit). Double-click on empty canvas zooms in at cursor position. Clicking a node opens its details panel. Totals for notes, links and tags stay visible as floating metrics under the Brainlink title, and node details open in a non-modal side panel (tags, outgoing links, backlinks and Markdown content), so zoom and pan remain available during inspection. The visual layout is a cauliflower hub layout: the primary hub stays centered, segment hubs anchor surrounding lobes, and underlying weighted wiki-link edges are preserved for backlinks, ranking and context traversal. At high zoom-out, graph streams show segment hub clusters first; zooming in progressively reveals the individual nodes inside those lobes. Node titles appear as zoom approaches readable scale, limited to on-screen nodes in very large graphs.
613
+ 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 and applied immediately without delayed focus interpolation. Keyboard shortcuts are `+` (zoom in), `-` (zoom out) and `0` (reset fit). Double-click on empty canvas zooms in at cursor position. Clicking a node opens its details panel. Totals for notes, links and tags stay visible as floating metrics under the Brainlink title, and node details open in a non-modal side panel (tags, outgoing links, backlinks and Markdown content), so zoom and pan remain available during inspection. The visual layout is a cauliflower hub layout: the primary hub stays centered, segment hubs anchor surrounding lobes, and visual edges are simplified to root hub -> segment hubs -> local context nodes. Indexed weighted wiki-link edges remain available for backlinks, ranking and context traversal outside the render layer. At high zoom-out, graph streams show segment hub clusters first; zooming in progressively reveals the individual nodes inside those lobes. Node titles appear as zoom approaches readable scale, limited to on-screen nodes in very large graphs.
614
614
  During graph filtering, Brainlink keeps hub context nodes visible (`Memory Hub`/`MOC`/high-degree fallback) so filtered views still show relationship anchors.
615
615
 
616
616
  The command reindexes by default, then serves:
@@ -162,7 +162,7 @@ server command
162
162
  ```
163
163
 
164
164
  The graph UI is intentionally read-only. Markdown remains the write interface and index artifacts remain derived data.
165
- The cauliflower layout is visual only: it keeps the indexed weighted wiki-link edges unchanged so backlinks, ranking and context traversal keep their original semantics. The primary hub is centered, segment hubs anchor surrounding lobes, and zoomed-out graph streams summarize those lobes as segment clusters before revealing individual nodes on zoom-in.
165
+ The cauliflower layout is a visual projection over the indexed graph. Indexed weighted wiki-link edges remain unchanged for backlinks, ranking, graph reads and context traversal. The browser layout renders a simplified hierarchy instead: primary hub -> segment hubs -> local context nodes. This avoids unstable cross-context visual edges while preserving the real relationship model outside the render layer. Zoomed-out graph streams summarize those lobes as segment clusters before revealing individual nodes on zoom-in.
166
166
 
167
167
  ## HTTP API Flow
168
168
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andespindola/brainlink",
3
- "version": "0.1.0-beta.157",
3
+ "version": "0.1.0-beta.158",
4
4
  "description": "Local-first knowledge memory for agents with Markdown, backlinks, indexing and context retrieval.",
5
5
  "type": "module",
6
6
  "license": "MIT",