@andespindola/brainlink 0.1.0-beta.7 → 0.1.0-beta.71

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.
Files changed (63) hide show
  1. package/AGENTS.md +8 -5
  2. package/CHANGELOG.md +58 -2
  3. package/CONTRIBUTING.md +2 -2
  4. package/COPYRIGHT.md +5 -0
  5. package/README.md +266 -20
  6. package/SECURITY.md +1 -1
  7. package/dist/application/add-note.js +62 -13
  8. package/dist/application/analyze-vault.js +95 -8
  9. package/dist/application/build-context.js +56 -1
  10. package/dist/application/dedupe-notes.js +226 -0
  11. package/dist/application/frontend/client-css.js +138 -103
  12. package/dist/application/frontend/client-html.js +47 -41
  13. package/dist/application/frontend/client-js.js +2120 -128
  14. package/dist/application/frontend/client-worker-js.js +66 -0
  15. package/dist/application/get-graph-layout.js +18 -6
  16. package/dist/application/get-graph-node.js +12 -0
  17. package/dist/application/get-graph-summary.js +12 -0
  18. package/dist/application/get-graph.js +3 -3
  19. package/dist/application/import-legacy-sqlite.js +296 -0
  20. package/dist/application/index-vault.js +252 -19
  21. package/dist/application/list-agents.js +3 -3
  22. package/dist/application/list-links.js +5 -5
  23. package/dist/application/migrate-vault.js +91 -0
  24. package/dist/application/offline-pack-backup.js +44 -0
  25. package/dist/application/search-graph-node-ids.js +12 -0
  26. package/dist/application/search-knowledge.js +75 -5
  27. package/dist/application/server/routes.js +102 -1
  28. package/dist/application/start-server.js +75 -4
  29. package/dist/application/watch-vault.js +23 -2
  30. package/dist/benchmarks/large-vault.js +1 -1
  31. package/dist/cli/commands/agent-commands.js +419 -0
  32. package/dist/cli/commands/config-commands.js +167 -0
  33. package/dist/cli/commands/read-commands.js +25 -8
  34. package/dist/cli/commands/write-commands.js +989 -10
  35. package/dist/cli/main.js +4 -0
  36. package/dist/cli/runtime.js +5 -2
  37. package/dist/domain/context.js +53 -11
  38. package/dist/domain/embeddings.js +2 -1
  39. package/dist/domain/graph-layout.js +62 -15
  40. package/dist/domain/markdown.js +36 -4
  41. package/dist/domain/middle-out.js +18 -0
  42. package/dist/infrastructure/config.js +132 -8
  43. package/dist/infrastructure/file-index.js +358 -0
  44. package/dist/infrastructure/file-system-vault.js +30 -0
  45. package/dist/infrastructure/index-state.js +56 -0
  46. package/dist/infrastructure/paths.js +9 -1
  47. package/dist/infrastructure/private-pack-codec.js +134 -0
  48. package/dist/infrastructure/search-packs.js +452 -0
  49. package/dist/infrastructure/session-state.js +172 -0
  50. package/dist/mcp/main.js +11 -3
  51. package/dist/mcp/server.js +27 -2
  52. package/dist/mcp/startup.js +35 -0
  53. package/dist/mcp/tools.js +633 -19
  54. package/docs/AGENT_USAGE.md +178 -16
  55. package/docs/ARCHITECTURE.md +37 -26
  56. package/docs/QUICKSTART.md +111 -0
  57. package/package.json +6 -4
  58. package/dist/infrastructure/sqlite/document-writer.js +0 -51
  59. package/dist/infrastructure/sqlite/graph-reader.js +0 -120
  60. package/dist/infrastructure/sqlite/schema.js +0 -111
  61. package/dist/infrastructure/sqlite/search-reader.js +0 -156
  62. package/dist/infrastructure/sqlite/types.js +0 -1
  63. package/dist/infrastructure/sqlite-index.js +0 -25
package/AGENTS.md CHANGED
@@ -6,19 +6,19 @@ This file tells coding agents and AI assistants how to use this repository.
6
6
 
7
7
  Brainlink is a local-first knowledge memory for agents.
8
8
 
9
- It reads a Markdown vault, extracts `[[wiki links]]` and `#tags`, builds a local SQLite full-text index, and returns compact context packages that agents can inject into prompts.
9
+ It reads a Markdown vault, extracts `[[wiki links]]` and `#tags`, builds a local file index at `.brainlink/index.json`, and returns compact context packages that agents can inject into prompts.
10
10
 
11
11
  ## Source Of Truth
12
12
 
13
13
  Markdown files are the source of truth.
14
14
 
15
- The SQLite database at `.brainlink/brainlink.db` is a derived index. It can be deleted and rebuilt with:
15
+ The JSON index at `.brainlink/index.json` is derived. It can be deleted and rebuilt with:
16
16
 
17
17
  ```bash
18
18
  npm run dev -- index --vault ./vault
19
19
  ```
20
20
 
21
- Do not store permanent knowledge only in SQLite.
21
+ Do not store permanent knowledge only in index artifacts.
22
22
 
23
23
  By default, the installed Brainlink CLI uses `$HOME/.brainlink/vault` as its vault. Passing `--vault` or setting `vault` in `brainlink.config.json` intentionally selects a custom vault such as `./vault`.
24
24
 
@@ -83,6 +83,9 @@ Use watch mode while editing notes:
83
83
  ```bash
84
84
  npm run dev -- server --vault ./vault --watch
85
85
  npm run dev -- watch --vault ./vault
86
+ npm run dev -- bench --vault ./vault
87
+ npm run dev -- bench --vault ./vault --watch
88
+ npm run dev -- pack-backup --vault ./vault
86
89
  ```
87
90
 
88
91
  Start MCP over stdio:
@@ -107,10 +110,10 @@ npm run dev -- doctor --vault ./vault
107
110
 
108
111
  - Keep domain rules in `src/domain`.
109
112
  - Keep use cases in `src/application`.
110
- - Keep filesystem and SQLite details in `src/infrastructure`.
113
+ - Keep filesystem and index details in `src/infrastructure`.
111
114
  - Keep CLI concerns in `src/cli`.
112
115
  - Prefer pure functions for parsing, ranking, formatting, and transformation.
113
- - Do not make SQLite the canonical storage layer.
116
+ - Do not make index artifacts the canonical storage layer.
114
117
  - Do not add comments with emojis.
115
118
  - Keep JSON output backwards compatible where possible.
116
119
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,61 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.0-beta.4
4
+
5
+ - Added bootstrap session-state persistence in `$BRAINLINK_HOME/session-state.json` for vault/agent readiness tracking.
6
+ - Added MCP `brainlink_policy` tool and default bootstrap enforcement for read tools.
7
+ - Added `agent install --self-test` diagnostics and bootstrap readiness details in `agent status`.
8
+ - Added `agent upgrade` for legacy installations to reapply latest MCP/plugin defaults with self-test diagnostics.
9
+ - Added `config doctor --fix` safe autofix mode with dry-run default behavior.
10
+ - Added detailed per-file migration reporting through `migrate-vault --report`.
11
+ - Added `quickstart` command to run plug-and-play vault + bootstrap + agent setup in one flow.
12
+ - Added structured MCP `nextActions` in bootstrap/policy/preflight responses for automatic client continuation.
13
+ - Added default MCP read auto-bootstrap behavior controlled by `brainlink_policy.autoBootstrapOnRead`.
14
+ - Added default MCP startup bootstrap behavior controlled by `brainlink_policy.autoBootstrapOnStartup`.
15
+ - Added CLI MCP policy presets through `blink agent policy --preset fully-auto|strict`.
16
+ - Added write-time non-orphan enforcement by auto-linking notes without wiki edges to agent hub notes.
17
+ - Added MCP `brainlink_policy` presets (`fully-auto`, `strict`) for one-call policy switching.
18
+ - Added MCP write connectivity metadata in `brainlink_add_note`/`brainlink_add_file` responses.
19
+ - Added MCP `brainlink_recommendations` tool for plug-and-play workflow guidance.
20
+ - Improved graph/index robustness by splitting oversized paragraphs into bounded chunks and dropping self-referential links.
21
+ - Added `agentProfiles` configuration support so CLI and MCP can resolve per-agent defaults for mode/limit/tokens.
22
+ - Added short-lived hybrid search cache with automatic invalidation on index changes.
23
+ - Added `stats --extended` observability output with storage, quality and latency probes.
24
+ - Added `docs/QUICKSTART.md` and aligned README/agent docs with the latest CLI/MCP flows.
25
+ - Added middle-out context assembly so chunk selection expands around the strongest note chunk.
26
+ - Added compressed-space pack prefiltering (token bloom index) before `.blpk` decryption and scan.
27
+ - Improved graph UI auto-fit and viewport recovery so loaded nodes are re-centered when zoom/pan drifts to empty canvas.
28
+ - Added cross-platform native desktop GUI auto-open for `blink server` (macOS Swift/WebKit, Windows PowerShell WinForms, Linux Python GTK/WebKit2), with app-window/browser fallback.
29
+ - Changed Linux default UI launch to app-window/browser for lighter startup; Linux native GUI is now opt-in via `BRAINLINK_LINUX_NATIVE_GUI=1`.
30
+ - Added native GUI parent-process monitoring so GUI windows close automatically when `blink server` stops.
31
+ - Improved non-mac browser detection fallback to try installed Edge/Chrome/Firefox/Chromium candidates before system default open.
32
+ - Improved graph filter rendering to keep hub anchor nodes visible (`Memory Hub`/`MOC`/high-degree fallback) for coherent relationship context.
33
+ - Fixed graph modal content loading by correcting agent query parameter composition for `/api/graph-node` and `/api/graph-filter` requests.
34
+ - Improved 50k+ graph rendering performance with viewport-aware spatial node culling, cached render visibility, and node-adjacent edge selection to avoid full graph scans every frame.
35
+ - Added incremental vault indexing with file snapshots to reuse unchanged documents/chunks/embeddings, plus adaptive search-pack rebuild thresholds to avoid full re-compression on small edits.
36
+ - Reduced large-graph HTTP payload size with compact `/api/graph-layout` encoding for high-node vaults and capped transmitted edges to improve UI load responsiveness.
37
+ - Added aggressive graph LOD clustering when zoomed out, dynamic per-zoom edge render budgets, and a dedicated frontend worker for off-main-thread graph filter matching.
38
+ - Improved Linux browser fallback launch stability by auto-applying Chromium compatibility flags (`--ozone-platform=x11`, `--disable-gpu`, `--disable-features=Vulkan,VaapiVideoDecoder`, `--disable-background-networking`) for app-window/browser modes.
39
+ - Improved massive-graph UI responsiveness with stricter render budgets, adaptive heavy-graph frame throttling, reduced interaction hit-test frequency, and URL-first agent selection on initial graph load.
40
+ - Improved 50k+ graph LOD behavior so zoomed-out views render lightweight cluster overviews and progressively reveal nodes/edges only as zoom increases.
41
+ - Added `blink bench` with realtime index phase telemetry and per-run compressed-pack analysis (input/output bytes, ratio, saved space, rebuild reason and duration), including continuous watch mode.
42
+ - Added tunable single-stage search-pack compression settings (`searchPack.rowChunkSize`, `searchPack.compressionLevel`, `searchPack.useDictionary`).
43
+ - Added benchmark guardrails for compression savings and latency regression (`searchPack.guardrailMinSavingsPercent`, `searchPack.guardrailMaxLatencyRegressionPercent`), reported in `blink bench`.
44
+ - Added `blink pack-backup` for offline second-stage compression backups of encrypted `.blpk` packs, outside the online query path.
45
+ - Hardened Linux browser launch flags for Ubuntu 26 Chromium/Wayland compatibility (`--disable-vulkan`, `--use-gl=swiftshader`, `--ozone-platform-hint=x11`).
46
+ - Improved pack resilience by auto-repairing missing search-pack manifests from existing `.blpk` files, avoiding unnecessary full repacks on small incremental updates.
47
+ - Updated Linux graph auto-open behavior to prioritize the system default browser (`xdg-open`) before explicit browser fallbacks.
48
+ - Removed implicit Chromium dependency in Linux auto-open flow; app-window launch is now opt-in (`BRAINLINK_LINUX_APP_WINDOW=1`).
49
+
50
+ ## 0.1.0-beta.3
51
+
52
+ - Added CLI configuration commands for effective vault management, including `config where`, `config get`, `config doctor` and `config set-vault`.
53
+ - Added explicit `migrate-vault` command with `--dry-run` preview and conflict-preserving copy behavior.
54
+ - Added one-command agent setup through `agent install` plus `agent status` diagnostics.
55
+ - Added MCP `brainlink_bootstrap` default entrypoint guidance for plug-and-play agent memory flows.
56
+ - Added migration coverage for S3 bucket vault targets.
57
+ - Updated architecture and agent-usage documentation to reflect current CLI/MCP behavior and configuration precedence.
58
+
3
59
  ## 0.1.0-beta.2
4
60
 
5
61
  - Added MCP installation guidance for direct server configuration and local client stores.
@@ -17,8 +73,8 @@
17
73
  ## 0.1.0-alpha.0
18
74
 
19
75
  - Added local-first Markdown vault indexing.
20
- - Added SQLite FTS, local semantic retrieval, wiki links, backlinks and graph retrieval.
21
- - Added SQLite semantic bucket indexing to narrow vector candidates for larger vaults.
76
+ - Added local full-text indexing, local semantic retrieval, wiki links, backlinks and graph retrieval.
77
+ - Added semantic candidate bucket indexing to narrow vector candidates for larger vaults.
22
78
  - Optimized title/link resolution with precomputed agent-scoped title maps.
23
79
  - Added CLI, JSON output, HTTP API and graph UI.
24
80
  - Added vault diagnostics: stats, broken links, orphans, validation and doctor.
package/CONTRIBUTING.md CHANGED
@@ -22,7 +22,7 @@ npm run pack:smoke
22
22
  ## Design Rules
23
23
 
24
24
  - Markdown files are the source of truth.
25
- - SQLite is a derived index and must remain rebuildable.
25
+ - Local index artifacts are derived and must remain rebuildable.
26
26
  - Domain parsing, graph analysis and layout should stay pure and testable.
27
- - CLI, HTTP, filesystem and SQLite code are adapters around application use cases.
27
+ - CLI, HTTP, filesystem and index code are adapters around application use cases.
28
28
  - MCP integration should live outside this package by wrapping the CLI with `--json`.
package/COPYRIGHT.md ADDED
@@ -0,0 +1,5 @@
1
+ Copyright (c) 2026 Substructa
2
+
3
+ This project is licensed under the MIT License.
4
+
5
+ See [LICENSE](./LICENSE) for full terms.
package/README.md CHANGED
@@ -52,11 +52,15 @@ LLMs do not have infinite context. Brainlink gives agents an external memory lay
52
52
  1. Durable knowledge is written as Markdown.
53
53
  2. Notes are connected with `[[wiki links]]`.
54
54
  3. Concepts are classified with `#tags`.
55
- 4. Brainlink builds a local SQLite index with FTS records and local embeddings.
55
+ 4. Brainlink builds a local JSON index (`.brainlink/index.json`) and private encrypted search packs.
56
56
  5. Agents query the index before responding.
57
57
  6. Brainlink returns compact, source-backed context.
58
58
 
59
- Markdown is the source of truth. `.brainlink/brainlink.db` is only a rebuildable index.
59
+ Markdown is the source of truth. `.brainlink/index.json` is a rebuildable index artifact.
60
+ After each index run, Brainlink also writes private encrypted search packs at `.brainlink/search-packs/*.blpk` to preserve fast retrieval and portable recovery.
61
+ Online retrieval always uses a single compression stage per pack; optional second-stage compression is reserved for offline backup artifacts only.
62
+ Pack decryption uses a Brainlink key from `$BRAINLINK_HOME/keys` or from `BRAINLINK_SEARCH_PACK_KEY` when explicitly configured.
63
+ Legacy `.jsonl.gz` packs are upgraded to `.blpk` automatically on first search/context access.
60
64
 
61
65
  ## Features
62
66
 
@@ -64,8 +68,12 @@ Markdown is the source of truth. `.brainlink/brainlink.db` is only a rebuildable
64
68
  - Obsidian-compatible `[[wiki links]]` and `#tags`.
65
69
  - Weighted graph edges so agents can rank relationship importance and priority.
66
70
  - Backlinks, broken-link reports, orphan detection and validation.
67
- - Full-text, semantic and hybrid retrieval modes.
68
- - SQLite-backed semantic candidate buckets for larger vaults.
71
+ - Full-text, semantic and hybrid retrieval on a local file index.
72
+ - Middle-out context assembly around the strongest chunk per document.
73
+ - In-process index and context caching with automatic invalidation on index updates.
74
+ - Compressed-space prefiltering for `.blpk` packs before decryption and scan.
75
+ - Incremental indexing that reprocesses only changed markdown files and reuses existing chunks/embeddings for unchanged notes.
76
+ - Adaptive compressed-pack rebuild policy to keep indexing fast during small edit batches.
69
77
  - Agent namespaces under `agents/<agent-id>/`.
70
78
  - S3-compatible bucket vaults through `s3://bucket/prefix` URIs.
71
79
  - CLI with machine-readable `--json` output.
@@ -73,6 +81,12 @@ Markdown is the source of truth. `.brainlink/brainlink.db` is only a rebuildable
73
81
  - Built-in MCP stdio server for agent tool integration.
74
82
  - Local HTTP API.
75
83
  - Realtime graph UI with agent selector and colored knowledge groups.
84
+ - Graph renderer optimized for large datasets with viewport-driven node culling and edge lookup by visible nodes.
85
+ - Large graph layout API automatically uses compact payload encoding with link-coverage-aware edge selection to reduce initial client load without hiding major relationships.
86
+ - Zoomed-out graph LOD now clusters dense regions and progressively expands nodes as zoom increases.
87
+ - Graph reset starts in macro "galaxy" overview mode and progressively reveals nearby nodes as zoom increases, including smaller vaults.
88
+ - Graph filtering runs in a dedicated browser worker to keep the UI thread responsive during heavy datasets.
89
+ - Edge rendering budgets adapt to zoom level to prevent frame spikes on large graph panoramas.
76
90
 
77
91
  ## Install
78
92
 
@@ -106,6 +120,8 @@ npx @andespindola/brainlink@latest --help
106
120
 
107
121
  This section is written for agents. If you are an AI agent operating in a user workspace, use this workflow to install and use Brainlink without requiring the user to run commands manually.
108
122
 
123
+ For a condensed setup path, see [docs/QUICKSTART.md](./docs/QUICKSTART.md).
124
+
109
125
  ### 1. Check Whether Brainlink Is Installed
110
126
 
111
127
  ```bash
@@ -280,7 +296,7 @@ export BRAINLINK_S3_FORCE_PATH_STYLE=1
280
296
 
281
297
  Bucket vaults mirror Markdown into a local cache under
282
298
  `$BRAINLINK_HOME/bucket-cache`. The bucket remains canonical; the local
283
- `.brainlink/brainlink.db` stays a disposable index. Run `index` after remote
299
+ `.brainlink/index.json` stays a disposable index artifact. Run `index` after remote
284
300
  bucket changes before relying on `search`, `context`, graph or validation
285
301
  commands. Watch mode is only supported for local filesystem vaults.
286
302
 
@@ -296,7 +312,7 @@ vault/
296
312
  research-agent/
297
313
  source-review-policy.md
298
314
  .brainlink/
299
- brainlink.db
315
+ index.json
300
316
  ```
301
317
 
302
318
  Permanent data:
@@ -306,7 +322,7 @@ Permanent data:
306
322
 
307
323
  Rebuildable data:
308
324
 
309
- - `.brainlink/brainlink.db`
325
+ - `.brainlink/index.json`
310
326
  - full-text records
311
327
  - local embedding vectors
312
328
  - local embedding buckets
@@ -380,6 +396,36 @@ Example MCP client configuration:
380
396
  }
381
397
  ```
382
398
 
399
+ ### One-Command Agent Setup
400
+
401
+ If your agent runtime is Codex-compatible, run:
402
+
403
+ ```bash
404
+ blink agent install --self-test
405
+ blink agent upgrade
406
+ ```
407
+
408
+ This configures `~/.codex/config.toml` with Brainlink MCP (`brainlink-mcp`) so Brainlink is available by default in agent sessions.
409
+ `agent install` and `agent upgrade` also apply the MCP `fully-auto` bootstrap policy by default (`enforceBootstrap`, `enforceContextFirst`, `autoBootstrapOnRead`, `autoBootstrapOnStartup` all enabled).
410
+
411
+ If you are inside this repository and want plugin gallery setup too:
412
+
413
+ ```bash
414
+ blink agent install --plugin-path ./plugins/brainlink
415
+ ```
416
+
417
+ To verify:
418
+
419
+ ```bash
420
+ blink agent status
421
+ ```
422
+
423
+ For fully automated first run (vault index + health + bootstrap readiness + agent integration):
424
+
425
+ ```bash
426
+ blink quickstart --query "what should I know before this task?" --json
427
+ ```
428
+
383
429
  For a locked-down setup, allowlist the vaults that MCP clients may access:
384
430
 
385
431
  ```json
@@ -475,8 +521,13 @@ Restart the client after changing marketplace or MCP configuration so it reloads
475
521
 
476
522
  Available tools:
477
523
 
524
+ - `brainlink_bootstrap`: plug-and-play entrypoint that runs index + health checks and can return context in one call.
525
+ - `brainlink_policy`: read or update bootstrap/context-first policy, including presets (`preset: "fully-auto" | "strict"`).
526
+ - `brainlink_recommendations`: return an automatic action plan so agents can run Brainlink in the recommended order.
478
527
  - `brainlink_context`: read indexed context for a task or question.
479
528
  - `brainlink_search`: search indexed notes.
529
+ - `brainlink_dedupe`: detect duplicate candidates using exact hash + semantic similarity scores.
530
+ - `brainlink_resolve_duplicate`: resolve duplicate pairs (`merge`, `link`, `ignore`) with connectivity-safe fallback edges.
480
531
  - `brainlink_add_note`: write durable Markdown memory and reindex.
481
532
  - `brainlink_add_file`: ingest a local file as a note and reindex.
482
533
  - `brainlink_index`: rebuild the vault index.
@@ -487,7 +538,15 @@ Available tools:
487
538
  - `brainlink_broken_links`: list unresolved wiki links.
488
539
  - `brainlink_orphans`: list disconnected notes.
489
540
 
490
- The same linking rule applies through MCP: `brainlink_context` is read-only, and real graph links require Markdown notes with explicit `[[wiki links]]`. `brainlink_add_note` and `brainlink_add_file` reindex by default and include the index result when enabled.
541
+ For the most automatic workflow, start MCP sessions with `brainlink_bootstrap` (optionally with `query`) and then continue with `brainlink_context`/`brainlink_add_note`.
542
+ By default, Brainlink enforces context-first for MCP reads (`enforceContextFirst=true`): non-context read tools return preflight until `brainlink_context` is called for the vault/agent session.
543
+ By default, MCP startup already runs bootstrap on the configured default vault/agent (`autoBootstrapOnStartup=true`), so sessions begin warm.
544
+ By default, Brainlink enforces bootstrap and auto-runs it for read tools when session state is missing or stale (`autoBootstrapOnRead=true`).
545
+ If you disable `autoBootstrapOnRead` through `brainlink_policy`, read tools return a preflight instruction with suggested `brainlink_bootstrap` arguments.
546
+ `brainlink_bootstrap`, `brainlink_policy` and preflight responses include structured `nextActions` so MCP clients can continue automatically without custom parsing.
547
+ For one-call planning, use `brainlink_recommendations` to get the recommended tool sequence for the current vault/agent/query.
548
+
549
+ The same linking rule applies through MCP: `brainlink_context` is read-only, and real graph links require Markdown notes with explicit `[[wiki links]]`. `brainlink_add_note` and `brainlink_add_file` reindex by default and include index + `writeConnectivity` metadata. Brainlink guarantees at least one edge per new note by auto-linking when needed.
491
550
 
492
551
  Agents can raise the importance of a relationship by putting priority markers on the same line as a wiki link:
493
552
 
@@ -507,16 +566,35 @@ blink server --host 127.0.0.1 --port 4321 --watch
507
566
  ```
508
567
 
509
568
  By default, the server uses `$HOME/.brainlink/vault`. Pass `--vault ./vault` only when you want to inspect a custom vault.
569
+ By default, `blink server` tries to open the graph in a native desktop GUI window:
570
+ - macOS: Swift + WebKit
571
+ - Windows: PowerShell WinForms WebBrowser
572
+ - Linux: optional Python GTK + WebKit2 (requires `python3` + `gi` + `WebKit2`)
573
+
574
+ On Linux, native GUI is disabled by default for better startup performance. Enable it with `BRAINLINK_LINUX_NATIVE_GUI=1`.
575
+ If native GUI launch is unavailable on your system, it falls back to dedicated app-window mode and then to the default browser.
576
+ For Chromium-family browsers on Linux (`chromium`, `chromium-browser`, `google-chrome`, `microsoft-edge`, `brave-browser`), Brainlink now auto-applies compatibility flags during launch (`--ozone-platform=x11`, `--ozone-platform-hint=x11`, `--disable-gpu`, `--disable-vulkan`, `--use-gl=swiftshader`, `--disable-features=Vulkan,VaapiVideoDecoder`, `--disable-background-networking`) to avoid common Wayland/Vulkan/VAAPI startup issues.
577
+ On Linux, Brainlink opens the graph through the system default browser first (`xdg-open`), then `$BROWSER`/detected browsers as fallback. Chromium-family app-window mode is optional via `BRAINLINK_LINUX_APP_WINDOW=1`.
578
+ Use `--no-open` to keep it headless.
579
+ When native GUI is used, the GUI window automatically closes when the `blink server` process stops.
510
580
 
511
581
  The graph UI shows:
512
582
 
513
583
  - notes as nodes
514
584
  - `[[wiki links]]` as weighted edges
515
- - backlinks and outgoing links
516
- - full Markdown content for the selected note
585
+ - details opened on node click (tags, outgoing links, backlinks, full Markdown content)
517
586
  - neutral graph nodes with segment/group metadata
518
- - agent selector for isolated views
587
+ - agent selector (id-only labels) for isolated views
588
+ - graph filter matches title, path, tags and note content
589
+ - graph filter keeps hub context nodes visible (`Memory Hub`/`MOC`/high-degree fallback) to preserve relationship readability
519
590
  - realtime refresh while `--watch` is enabled
591
+ - graph controls for zoom in, zoom out, fit visible nodes and reset-to-fit-all
592
+ - wheel zoom (including `cmd+scroll` and `ctrl+scroll`) anchored to cursor position for faster navigation in large graphs
593
+ - keyboard shortcuts: `+` zoom in, `-` zoom out, `0` reset fit
594
+ - double-click on canvas zooms in at cursor position
595
+ - floating graph totals (notes, links, tags) below the Brainlink title
596
+ - large-graph rendering safeguards (edge draw caps, lower redraw rate, zoom-aware interaction)
597
+ - massive-graph LOD progression: zoomed-out views prefer lightweight clusters, then progressively reveal nodes and edges as zoom increases
520
598
 
521
599
  The server indexes before starting by default. Use `--no-index` to skip that step:
522
600
 
@@ -535,6 +613,7 @@ Routes:
535
613
  - `GET /api/agents`
536
614
  - `GET /api/graph`
537
615
  - `GET /api/graph-layout`
616
+ - `GET /api/graph-node?id=<node-id>`
538
617
  - `GET /api/search?q=<query>&limit=10&mode=hybrid`
539
618
  - `GET /api/context?q=<query>&limit=12&tokens=2000&mode=hybrid`
540
619
  - `GET /api/links`
@@ -556,14 +635,89 @@ Read routes accept `agent=<agent-id>`:
556
635
 
557
636
  Every command works with either `brainlink` or `blink`.
558
637
 
638
+ ### `agent`
639
+
640
+ ```bash
641
+ blink agent install
642
+ blink agent install --self-test
643
+ blink agent upgrade
644
+ blink agent policy --preset fully-auto
645
+ blink agent policy --preset strict
646
+ blink agent policy --enforce-context-first false
647
+ blink agent install --plugin-path ./plugins/brainlink
648
+ blink agent install --mcp-only --allowed-vaults "/absolute/vault,/absolute/team-vault"
649
+ blink agent status
650
+ ```
651
+
652
+ Installs/checks agent integration. `install` writes Brainlink MCP config into `~/.codex/config.toml`.
653
+ When plugin files are available, it also links Brainlink plugin files into `~/plugins/brainlink` and updates `~/.agents/plugins/marketplace.json`.
654
+ With `--self-test`, install also validates MCP block presence, command wiring and local plugin registration signals.
655
+ Use `agent upgrade` on legacy installations to reapply current defaults and run the same self-test diagnostics.
656
+ Use `agent policy --preset fully-auto` for plug-and-play defaults, or `agent policy --preset strict` to require explicit bootstrap calls.
657
+ Both presets keep `enforceContextFirst=true` so Brainlink stays the primary context source for MCP sessions.
658
+
659
+ ### `quickstart`
660
+
661
+ ```bash
662
+ blink quickstart --json
663
+ blink quickstart --vault ./team-vault --agent coding-agent --query "architecture decisions" --json
664
+ blink quickstart --vault ./team-vault --mcp-only --json
665
+ ```
666
+
667
+ Runs index + doctor + stats + validation, refreshes bootstrap session readiness, optionally returns context for a query, and (by default) upgrades local agent integration for plug-and-play MCP usage.
668
+ When `--mode`, `--limit` or `--tokens` are omitted, quickstart uses agent profile defaults when available.
669
+
670
+ ### `config`
671
+
672
+ ```bash
673
+ blink config where
674
+ blink config get vault
675
+ blink config doctor
676
+ blink config doctor --fix
677
+ blink config set-vault /absolute/path/to/existing-vault
678
+ blink config set-vault /absolute/path/to/existing-vault --migrate-from ~/.brainlink/vault
679
+ blink config set-vault "s3://my-memory-bucket/brainlink" --global
680
+ ```
681
+
682
+ `config set-vault` writes configuration through CLI (no manual file edits required).
683
+ By default it writes local config (`./brainlink.config.json`), appends the vault to `allowedVaults`, and migrates Markdown memory from the current configured vault when the target is empty.
684
+ Use `--global` to write to `$BRAINLINK_HOME/brainlink.config.json`, `--no-migrate` to skip migration, and `--no-index` to skip post-migration indexing.
685
+ `config doctor` is dry-run by default; use `--fix` to apply safe config normalization and allowlist fixes.
686
+
687
+ ### `migrate-vault`
688
+
689
+ ```bash
690
+ blink migrate-vault --from ~/.brainlink/vault --to ./team-vault --dry-run
691
+ blink migrate-vault --from ~/.brainlink/vault --to ./team-vault
692
+ blink migrate-vault --from ~/.brainlink/vault --to "s3://my-memory-bucket/brainlink"
693
+ blink migrate-vault --from ~/.brainlink/vault --to ./team-vault --report ./migration-report.json
694
+ ```
695
+
696
+ Runs explicit markdown migration between vaults while preserving conflicts as `.conflict-<timestamp>` files.
697
+ Use `--dry-run` to preview `copied`, `conflicted` and `unchanged` counts before writing.
698
+
699
+ ### `db-import`
700
+
701
+ ```bash
702
+ blink db-import --vault ./team-vault
703
+ blink db-import --vault ./team-vault --db ./legacy/brainlink.db
704
+ blink db-import --vault ./team-vault --db ./legacy/brainlink.db --table legacy_notes --dry-run
705
+ ```
706
+
707
+ Imports durable memory from a legacy SQLite database into Markdown notes (`agents/<agent-id>/*.md`) and reindexes by default.
708
+ When `--db` is omitted, Brainlink auto-detects common legacy paths such as `<vault>/.brainlink/brainlink.db`.
709
+ Use `--agent <id>` to force all imported rows into one namespace, `--limit` for incremental imports, `--dry-run` to preview without writing files, and `--no-index` to defer reindexing.
710
+
559
711
  ### `init`
560
712
 
561
713
  ```bash
562
714
  blink init
563
715
  blink init ./vault
716
+ blink init ./team-vault --migrate-from ~/.brainlink/vault
564
717
  ```
565
718
 
566
719
  Initializes vault metadata. Without an argument, Brainlink initializes the default vault at `$HOME/.brainlink/vault`.
720
+ When initializing an empty custom vault, existing Markdown content from the default vault is copied into it and reindexed so context is not left behind. Use `--no-migrate-existing` to start with an empty custom vault, or `--migrate-from <vault>` to copy from a specific source. Existing target files are never overwritten; conflicting source files are preserved with a `.conflict-<timestamp>` suffix.
567
721
 
568
722
  ### `add`
569
723
 
@@ -577,6 +731,29 @@ blink add "Note Title" --vault ./vault --content-file ./notes.md --no-auto-index
577
731
  `--content` and `--content-file` are mutually exclusive. Add `--no-auto-index` when you want to defer reindexing.
578
732
 
579
733
  Creates a Markdown note under `agents/<agent-id>/`. Common secret patterns are blocked by default; use `--allow-sensitive` only for an intentionally protected vault.
734
+ To avoid disconnected memory, Brainlink auto-adds a fallback wiki edge when a note is written without links, creating agent hub notes when needed.
735
+ `add` also returns `possibleDuplicates` (exact hash + semantic candidates) so agents can resolve duplicate memory right after writes.
736
+
737
+ ### `dedupe`
738
+
739
+ ```bash
740
+ blink dedupe --vault ./vault --json
741
+ blink dedupe --vault ./vault --agent coding-agent --limit 20 --min-score 0.92 --json
742
+ blink dedupe --vault ./vault --no-semantic --json
743
+ ```
744
+
745
+ Detects `possibleDuplicate` pairs using exact content hashes and optional semantic similarity.
746
+
747
+ ### `dedupe-resolve`
748
+
749
+ ```bash
750
+ blink dedupe-resolve --vault ./vault --left agents/shared/a.md --right agents/shared/b.md --action merge --json
751
+ blink dedupe-resolve --vault ./vault --left agents/shared/a.md --right agents/shared/b.md --action link --json
752
+ blink dedupe-resolve --vault ./vault --left agents/shared/a.md --right agents/shared/b.md --action ignore --json
753
+ ```
754
+
755
+ Resolves a duplicate pair with `merge`, `link` or `ignore`.
756
+ When action is not `merge`, Brainlink still creates a low-priority related edge (`#related-to`) so notes remain connected.
580
757
 
581
758
  ### `index`
582
759
 
@@ -587,6 +764,38 @@ blink index --vault ./vault
587
764
 
588
765
  Rebuilds the local index from Markdown files.
589
766
 
767
+ ### `bench`
768
+
769
+ ```bash
770
+ blink bench --vault ./vault
771
+ blink bench --vault ./vault --watch
772
+ blink bench --vault ./vault --watch --debounce 500
773
+ blink bench --vault ./vault --json
774
+ ```
775
+
776
+ Runs indexing with realtime phase telemetry (`start`, `scan`, `parse`, `embed`, `persist`, `packs`, `complete`) and prints a benchmark summary at the end of each run.
777
+
778
+ Summary includes compression behavior for `.blpk` packs when rebuild happens:
779
+ - pack rebuild reason
780
+ - pack count and pack build duration
781
+ - uncompressed input bytes vs compressed output bytes
782
+ - saved percentage
783
+ - objective guardrails (minimum savings and maximum latency regression thresholds)
784
+
785
+ Use `--watch` to keep benchmarking incremental reindex runs after Markdown changes (local filesystem vaults only).
786
+ When `.brainlink/search-packs/manifest.json` is missing but `.blpk` files exist, Brainlink repairs the manifest first and avoids unnecessary full pack rebuild on small edits.
787
+
788
+ ### `pack-backup`
789
+
790
+ ```bash
791
+ blink pack-backup --vault ./vault
792
+ blink pack-backup --vault ./vault --output ./vault/.brainlink/backups/custom.blpkbak.gz
793
+ blink pack-backup --vault ./vault --json
794
+ ```
795
+
796
+ Creates an offline backup artifact of encrypted search packs with a second compression pass.
797
+ This is intentionally outside the online retrieval path (`index`, `search`, `context`).
798
+
590
799
  ### `agents`
591
800
 
592
801
  ```bash
@@ -605,13 +814,17 @@ blink search "query" --vault ./vault --mode semantic --json
605
814
  ```
606
815
 
607
816
  Runs retrieval over indexed chunks.
817
+ If `--mode` or `--limit` is omitted, Brainlink resolves values from the current agent profile before falling back to global defaults.
608
818
 
609
819
  Modes:
610
820
 
611
- - `hybrid`: default; combines SQLite FTS with local embedding similarity.
612
- - `fts`: exact lexical retrieval through SQLite FTS.
821
+ - `hybrid`: default; combines lexical matching with local embedding similarity.
822
+ - `fts`: exact lexical retrieval from the file index.
613
823
  - `semantic`: local deterministic embedding similarity only.
614
824
 
825
+ Hybrid results are cached in-memory for a short TTL and invalidated automatically when the local index file changes.
826
+ Context selection uses a middle-out strategy: it starts from the strongest chunk in a note and expands to neighboring chunks while respecting token budget.
827
+
615
828
  ### `context`
616
829
 
617
830
  ```bash
@@ -621,6 +834,7 @@ blink context "question" --vault ./vault --agent coding-agent --mode hybrid --js
621
834
  ```
622
835
 
623
836
  Builds a compact context package for an agent.
837
+ Repeated calls with the same vault, agent, query, mode and token/limit settings are served from a short in-memory cache while the index is unchanged.
624
838
 
625
839
  ### `links`
626
840
 
@@ -654,9 +868,11 @@ Prints indexed graph data. Edges include `weight` and `priority` so agents can c
654
868
  ```bash
655
869
  blink stats --vault ./vault
656
870
  blink stats --vault ./vault --agent coding-agent --json
871
+ blink stats --vault ./vault --agent coding-agent --extended --json
657
872
  ```
658
873
 
659
874
  Prints vault metrics.
875
+ Use `--extended` to include storage footprint, link quality ratios and observability probes (`index`, `search`, `context` latencies).
660
876
 
661
877
  ### `broken-links`
662
878
 
@@ -688,7 +904,7 @@ Validates graph health. The command exits non-zero when required checks fail.
688
904
  blink doctor --vault ./vault
689
905
  ```
690
906
 
691
- Runs environment and vault checks.
907
+ Runs environment and vault checks. When vault has zero markdown and zero indexed documents, `doctor` prints recommended next steps (add note, inspect config source, migrate memory).
692
908
 
693
909
  ### `watch`
694
910
 
@@ -703,9 +919,15 @@ Watches Markdown files and rebuilds the index when notes change.
703
919
  ```bash
704
920
  blink server --watch
705
921
  blink server --vault ./vault --watch
922
+ blink server --vault ./vault --watch --no-open
706
923
  ```
707
924
 
708
925
  Starts the local read-only graph UI and HTTP API.
926
+ By default, it tries to open a native desktop GUI window for the graph URL.
927
+ On Linux, native GUI is disabled by default; enable it with `BRAINLINK_LINUX_NATIVE_GUI=1`.
928
+ If native GUI launch is unavailable, it falls back to dedicated app-window mode and then browser open.
929
+ When fallback opens Chromium-family browsers on Linux, Brainlink automatically uses compatibility launch flags for stable rendering on Ubuntu/Wayland setups.
930
+ Use `--no-open` to skip that behavior.
709
931
 
710
932
  The HTTP server only binds to loopback hosts such as `127.0.0.1`, `localhost` or `::1`.
711
933
 
@@ -725,7 +947,13 @@ npm run --silent dev -- context "question" --vault ./vault --json
725
947
 
726
948
  ## Configuration
727
949
 
728
- Brainlink reads `brainlink.config.json` or `.brainlink.json` from the current working directory. If no `vault` is configured and no `--vault` flag is passed, Brainlink uses `$HOME/.brainlink/vault`.
950
+ Brainlink merges configuration in this order:
951
+
952
+ 1. Global: `$BRAINLINK_HOME/brainlink.config.json` (or `$HOME/.brainlink/brainlink.config.json` by default)
953
+ 2. Local: `brainlink.config.json` in the current working directory
954
+ 3. Local legacy compatibility: `.brainlink.json` in the current working directory
955
+
956
+ If no `vault` is configured and no `--vault` flag is passed, Brainlink uses `$HOME/.brainlink/vault`.
729
957
 
730
958
  ```json
731
959
  {
@@ -739,11 +967,29 @@ Brainlink reads `brainlink.config.json` or `.brainlink.json` from the current wo
739
967
  "defaultContextTokens": 2000,
740
968
  "embeddingProvider": "local",
741
969
  "defaultSearchMode": "hybrid",
742
- "chunkSize": 1200
970
+ "chunkSize": 1200,
971
+ "searchPack": {
972
+ "rowChunkSize": 5000,
973
+ "compressionLevel": 5,
974
+ "useDictionary": true,
975
+ "guardrailMinSavingsPercent": 8,
976
+ "guardrailMaxLatencyRegressionPercent": 5
977
+ },
978
+ "agentProfiles": {
979
+ "coding-agent": {
980
+ "defaultSearchMode": "semantic",
981
+ "defaultSearchLimit": 8,
982
+ "defaultContextTokens": 2400
983
+ },
984
+ "*": {
985
+ "defaultSearchMode": "hybrid"
986
+ }
987
+ }
743
988
  }
744
989
  ```
745
990
 
746
991
  `defaultAgent` is optional. When set, CLI and MCP calls that omit `--agent`/`agent` use this value automatically. If not set, behavior remains as before.
992
+ `agentProfiles` is optional. When present, CLI and MCP resolve `mode`, `limit` and `tokens` per agent automatically, then fallback to global defaults.
747
993
 
748
994
  `autoIndexOnWrite` is optional and defaults to `true`. Set it to `false` to defer indexing after writes.
749
995
 
@@ -840,7 +1086,7 @@ src/
840
1086
  application/ use cases
841
1087
  cli/ command-line adapter
842
1088
  domain/ pure knowledge rules
843
- infrastructure/ filesystem and SQLite adapters
1089
+ infrastructure/ filesystem and index adapters
844
1090
  ```
845
1091
 
846
1092
  Detailed notes:
@@ -852,7 +1098,6 @@ Detailed notes:
852
1098
  ## Current Limits
853
1099
 
854
1100
  - Semantic search uses deterministic local embeddings, not a remote model provider.
855
- - Semantic search uses SQLite embedding buckets to narrow candidates before cosine scoring.
856
1101
  - `embeddingProvider` currently supports `local` and `none`.
857
1102
  - Link resolution is title-based inside each agent namespace, with `shared` as fallback.
858
1103
  - HTTP API is local and unauthenticated.
@@ -863,7 +1108,7 @@ Detailed notes:
863
1108
  The `0.1.0-beta` line is intended to stabilize the local-first memory loop:
864
1109
 
865
1110
  - Markdown as durable memory.
866
- - SQLite FTS plus local embeddings and semantic buckets as rebuildable retrieval index.
1111
+ - Rebuildable file index plus local embeddings and encrypted pack exports.
867
1112
  - CLI as the primary agent interface.
868
1113
  - HTTP graph API and frontend as inspection tools.
869
1114
  - Agent namespaces to avoid context mixing.
@@ -879,7 +1124,7 @@ Brainlink is local-first by default.
879
1124
  - Brainlink HTTP is localhost-only and refuses non-loopback hosts.
880
1125
  - Brainlink blocks common secret patterns by default when adding notes. Use `--allow-sensitive` only for intentional, protected vaults.
881
1126
  - Do not store secrets, credentials, API keys or regulated personal data unless the vault is protected by your own storage controls.
882
- - Treat `.brainlink/brainlink.db` as disposable derived data.
1127
+ - Treat `.brainlink/index.json` and `.brainlink/search-packs/` as disposable derived artifacts.
883
1128
 
884
1129
  See [SECURITY.md](SECURITY.md).
885
1130
 
@@ -890,6 +1135,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md).
890
1135
  ## License
891
1136
 
892
1137
  MIT. See [LICENSE](LICENSE).
1138
+ Copyright (c) 2026 Substructa. See [COPYRIGHT.md](COPYRIGHT.md).
893
1139
 
894
1140
  ### Memory Optimization Loop (1-7)
895
1141
 
package/SECURITY.md CHANGED
@@ -7,7 +7,7 @@ Brainlink is local-first.
7
7
  - The HTTP server binds to `127.0.0.1` by default.
8
8
  - The HTTP server always refuses non-loopback hosts.
9
9
  - The HTTP server is read-only and does not expose note creation, indexing or update routes.
10
- - The SQLite database is a derived local index.
10
+ - Local index artifacts (`.brainlink/index.json` and `.brainlink/search-packs/`) are derived data.
11
11
  - Markdown files are user-owned source data.
12
12
  - Brainlink-created Markdown files use `0600` permissions.
13
13
  - Brainlink-created directories and `.brainlink` use `0700` permissions.