@andespindola/brainlink 0.1.0-beta.99 → 1.0.1

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 (48) hide show
  1. package/AGENTS.md +6 -6
  2. package/CHANGELOG.md +14 -0
  3. package/README.md +198 -38
  4. package/dist/application/add-note.js +13 -44
  5. package/dist/application/analyze-vault.js +1 -1
  6. package/dist/application/auto-migrate-configured-vault.js +37 -0
  7. package/dist/application/build-context.js +119 -20
  8. package/dist/application/canonical-context-links.js +209 -0
  9. package/dist/application/delete-note.js +80 -0
  10. package/dist/application/frontend/client-css.js +212 -42
  11. package/dist/application/frontend/client-html.js +42 -28
  12. package/dist/application/frontend/client-js.js +1294 -3222
  13. package/dist/application/frontend/client-render-worker-js.js +676 -0
  14. package/dist/application/get-graph-contexts.js +33 -0
  15. package/dist/application/get-graph-layout.js +62 -8
  16. package/dist/application/get-graph-stream-chunk.js +326 -0
  17. package/dist/application/get-graph-view.js +246 -0
  18. package/dist/application/graph-view-state.js +66 -0
  19. package/dist/application/import-legacy-sqlite.js +3 -33
  20. package/dist/application/index-vault.js +35 -22
  21. package/dist/application/migrate-context-links.js +79 -0
  22. package/dist/application/search-graph-node-ids.js +63 -3
  23. package/dist/application/server/routes.js +197 -12
  24. package/dist/cli/commands/read-commands.js +39 -3
  25. package/dist/cli/commands/vault-commands.js +182 -0
  26. package/dist/cli/commands/write-commands.js +172 -12
  27. package/dist/cli/main.js +2 -0
  28. package/dist/cli/runtime.js +10 -2
  29. package/dist/domain/context.js +1 -0
  30. package/dist/domain/graph-contexts.js +180 -0
  31. package/dist/domain/graph-layout.js +347 -21
  32. package/dist/domain/markdown.js +53 -9
  33. package/dist/infrastructure/config.js +105 -6
  34. package/dist/infrastructure/context-packs.js +122 -0
  35. package/dist/infrastructure/file-index.js +6 -3
  36. package/dist/infrastructure/file-system-vault.js +21 -1
  37. package/dist/infrastructure/index-state.js +2 -0
  38. package/dist/infrastructure/vault-migration-state.js +69 -0
  39. package/dist/infrastructure/volatile-memory.js +100 -0
  40. package/dist/mcp/http-server.js +97 -0
  41. package/dist/mcp/runtime.js +20 -0
  42. package/dist/mcp/server.js +41 -13
  43. package/dist/mcp/tools.js +226 -14
  44. package/docs/AGENT_USAGE.md +60 -5
  45. package/docs/ARCHITECTURE.md +11 -0
  46. package/docs/QUICKSTART.md +3 -1
  47. package/docs/RELEASE.md +4 -3
  48. package/package.json +3 -1
@@ -51,11 +51,26 @@ Set `BRAINLINK_HOME` when the whole Brainlink home directory should live somewhe
51
51
  Use `blink config where` and `blink config doctor` to inspect active paths and effective source.
52
52
 
53
53
  You can also set `defaultAgent` in `brainlink.config.json` / `.brainlink.json` (for example `"defaultAgent": "coding-agent"`). When set, CLI commands and MCP calls reuse it when `--agent`/`agent` is not passed.
54
- You can set `agentProfiles` to define per-agent defaults for `defaultSearchMode`, `defaultSearchLimit` and `defaultContextTokens`.
54
+ You can set `agentProfiles` to define per-agent defaults for `defaultSearchMode`, `defaultSearchLimit`, `defaultContextTokens`, `defaultContextStrategy` and `defaultContextCacheTtlMs`.
55
55
  You can tune search-pack compression with `searchPack.rowChunkSize`, `searchPack.compressionLevel` and `searchPack.useDictionary`.
56
56
  Guardrails for benchmark acceptance are configured with `searchPack.guardrailMinSavingsPercent` and `searchPack.guardrailMaxLatencyRegressionPercent`.
57
57
 
58
58
  `autoIndexOnWrite` (default: `true`) controls whether `add` and MCP write tools index right after writing.
59
+ `autoCanonicalContextLinks` (default: `true`) controls whether CLI/MCP write tools add canonical `## Context Links` to inferred context hubs.
60
+
61
+ ## Central MCP Service
62
+
63
+ For clustered applications, run Brainlink as one central MCP service and let workloads connect to it over Streamable HTTP:
64
+
65
+ ```bash
66
+ BRAINLINK_MCP_TOKEN="change-me" brainlink mcp-server \
67
+ --vault /data/vault \
68
+ --host 0.0.0.0 \
69
+ --port 3333 \
70
+ --path /mcp
71
+ ```
72
+
73
+ The central service exposes `/mcp` for MCP clients plus `/healthz` and `/readyz` for platform probes. Use a Kubernetes `Service` for internal discovery, mount the Markdown vault through a persistent volume, and pass `Authorization: Bearer <token>` from clients when `BRAINLINK_MCP_TOKEN` or `--token` is configured.
59
74
 
60
75
  ## Agent Namespaces
61
76
 
@@ -161,7 +176,7 @@ Brainlink only builds graph edges from Markdown `[[wiki links]]`.
161
176
 
162
177
  The `context` command is read-only. It retrieves indexed notes and returns a compact package for the model, but it does not write memory, create backlinks, infer relationships or modify the graph. If an agent reads context and then learns something durable, the agent must write a note with explicit links before that knowledge becomes connected memory.
163
178
 
164
- Graph edges are weighted during indexing. Repeated links increase weight. Links inside headings or task-list lines receive a small boost. Priority markers on the same line as a link raise its priority:
179
+ Graph edges are weighted during indexing. Repeated links increase weight. Links inside headings or task-list lines receive a small boost. Priority markers on the same line as a link raise its priority. The graph relationship model indexes every non-self Markdown `[[wiki link]]` as an edge, including structural hub links such as `Memory Hub`, `Knowledge Root`, `MOC` and map notes. Older indexes without the current graph link model version are automatically rebuilt on the next index run.
165
180
 
166
181
  ```md
167
182
  - [ ] Review [[Architecture]] priority: high
@@ -292,6 +307,8 @@ blink add "Implementation Boundary" \
292
307
  blink index
293
308
  ```
294
309
 
310
+ Use `blink index --full` when you need to rebuild every note from Markdown source. Full reindexing builds the replacement index before persisting it, preserving the previous context until the new index is ready. Brainlink also runs this complete source reindex automatically when it detects an older stored graph link model.
311
+
295
312
  ### Claude Code-Style Agent
296
313
 
297
314
  Use Brainlink as a preflight memory read before editing files:
@@ -368,6 +385,28 @@ blink config set-vault /absolute/path/to/vault --global
368
385
 
369
386
  `config set-vault` updates Brainlink config through CLI. By default it writes local `brainlink.config.json`, appends the vault to `allowedVaults`, and migrates markdown when the target is empty.
370
387
 
388
+ ### Manage Known Vaults
389
+
390
+ ```bash
391
+ blink vaults list
392
+ blink vaults use /absolute/path/to/vault
393
+ blink vaults use /absolute/path/to/vault --global
394
+ blink vaults delete /absolute/path/to/vault --yes
395
+ ```
396
+
397
+ `vaults list` shows the configured default vault, allowlisted vaults and the built-in default vault, including local existence and Markdown/index counts when available.
398
+ `vaults use` switches the default vault without migrating memory.
399
+ `vaults delete` deletes only local filesystem vaults, requires `--yes`, and refuses deleting the current default vault.
400
+
401
+ ### Delete Notes
402
+
403
+ ```bash
404
+ blink delete-note --title "Architecture" --yes
405
+ blink delete-note --path agents/shared/architecture.md --yes
406
+ ```
407
+
408
+ `delete-note` deletes durable Markdown notes only, requires explicit confirmation, accepts either `--title` or `--path`, and reindexes by default. MCP exposes the same capability as `brainlink_delete_note` with `confirm: true`.
409
+
371
410
  ### Migrate Vaults Explicitly
372
411
 
373
412
  ```bash
@@ -539,9 +578,14 @@ blink context "how does authentication work?" --vault ./vault --limit 12 --token
539
578
  blink context "how does authentication work?" --vault ./vault --json
540
579
  blink context "how does authentication work?" --vault ./vault --agent coding-agent --json
541
580
  blink context "how does authentication work?" --vault ./vault --agent coding-agent --mode hybrid --json
581
+ blink context "how does authentication work?" --vault ./vault --agent coding-agent --strategy cag --json
582
+ blink context "how does authentication work?" --vault ./vault --agent coding-agent --strategy auto --json
583
+ blink context-packs --vault ./vault --json
584
+ blink context-packs --vault ./vault --stale --clear
542
585
  ```
543
586
 
544
587
  This returns a Markdown context package optimized for prompt injection.
588
+ The default strategy is configured by `defaultContextStrategy` and starts as `rag`. Use `--strategy cag` when the same agent/task context should be served from a persisted context pack when the index and volatile-memory signatures are unchanged. Use `--strategy auto` when Brainlink should use CAG on fresh pack hits and RAG otherwise. Context responses include `cache`, `metrics`, `requestedStrategy` and `recommendedStrategy` metadata. CAG packs live under `.brainlink/context-packs` and are rebuildable derived artifacts.
545
589
 
546
590
  ### Inspect Links
547
591
 
@@ -607,7 +651,7 @@ Without `--vault`, the graph UI serves `$HOME/.brainlink/vault`.
607
651
 
608
652
  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
653
 
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).
654
+ 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.
611
655
  During graph filtering, Brainlink keeps hub context nodes visible (`Memory Hub`/`MOC`/high-degree fallback) so filtered views still show relationship anchors.
612
656
 
613
657
  The command reindexes by default, then serves:
@@ -625,12 +669,14 @@ Use `--no-index` when you need to inspect the current index without rebuilding i
625
669
  blink server --vault ./vault --no-index
626
670
  ```
627
671
 
628
- Use `--watch` to keep the graph updated after Markdown edits:
672
+ The server watches Markdown files by default and keeps the graph updated after edits:
629
673
 
630
674
  ```bash
631
- blink server --vault ./vault --watch
675
+ blink server --vault ./vault
632
676
  ```
633
677
 
678
+ Use `--no-watch` when you need to run the graph server without realtime reindexing.
679
+
634
680
  ### Watch A Vault
635
681
 
636
682
  ```bash
@@ -665,16 +711,22 @@ Available MCP tools:
665
711
  - `brainlink_policy`
666
712
  - `brainlink_recommendations`
667
713
  - `brainlink_context`
714
+ - `brainlink_context_packs`
668
715
  - `brainlink_search`
669
716
  - `brainlink_dedupe`
670
717
  - `brainlink_resolve_duplicate`
671
718
  - `brainlink_add_note`
719
+ - `brainlink_delete_note`
672
720
  - `brainlink_add_file`
721
+ - `brainlink_canonicalize_context_links`
722
+ - `brainlink_volatile_add`
723
+ - `brainlink_volatile_clear`
673
724
  - `brainlink_index`
674
725
  - `brainlink_stats`
675
726
  - `brainlink_validate`
676
727
  - `brainlink_sync`
677
728
  - `brainlink_graph`
729
+ - `brainlink_graph_contexts`
678
730
  - `brainlink_broken_links`
679
731
  - `brainlink_orphans`
680
732
 
@@ -684,11 +736,13 @@ If `autoBootstrapOnRead` or `enforceContextFirst` are disabled through `brainlin
684
736
  `brainlink_bootstrap`, `brainlink_policy` and preflight responses include structured `nextActions` so clients can continue tool flows automatically.
685
737
  `brainlink_policy` also accepts policy presets (`fully-auto`, `strict`) so MCP clients can switch behavior in one call.
686
738
  `brainlink_recommendations` returns the suggested execution order so an agent can follow Brainlink best practices automatically.
739
+ MCP context is plug-and-play: agents may omit `strategy` for the configured default, pass `strategy: "rag"` for explicit fresh retrieval assembly, pass `strategy: "cag"` to reuse persisted context packs when the task context is stable or repeated, or pass `strategy: "auto"` to use CAG on fresh pack hits and RAG otherwise. `brainlink_recommendations`, policy next actions and preflight responses return executable context arguments, so clients can continue without custom parsing. `brainlink_context_packs` lists or clears persisted CAG packs.
687
740
 
688
741
  MCP clients can pass `vault` and `agent` arguments per tool call. Set `BRAINLINK_ALLOWED_VAULTS` when exposing Brainlink to an external agent process so a tool cannot pass arbitrary vault paths:
689
742
 
690
743
  `brainlink_graph` returns weighted edges. Agents should prefer higher `weight` and stronger `priority` when deciding which related notes matter most.
691
744
  `brainlink_add_note` and `brainlink_add_file` return `writeConnectivity` metadata and guarantee at least one edge for new notes.
745
+ Agents should use `brainlink_volatile_add` for temporary task state, hypotheses, local execution details and unconfirmed findings. Volatile memory is included in `brainlink_context` with `Volatile: true`, expires by TTL and does not create durable Markdown notes or graph edges.
692
746
 
693
747
  ```bash
694
748
  export BRAINLINK_ALLOWED_VAULTS="/absolute/path/to/project-vault"
@@ -699,6 +753,7 @@ export BRAINLINK_ALLOWED_VAULTS="/absolute/path/to/project-vault"
699
753
  ```txt
700
754
  GET /api/graph
701
755
  GET /api/graph-layout
756
+ GET /api/graph-view?x=<x>&y=<y>&w=<width>&h=<height>&scale=<scale>
702
757
  GET /api/graph-node?id=<node-id>
703
758
  GET /api/graph-filter?q=<query>&limit=<n>
704
759
  GET /api/search?q=<query>&limit=10&mode=hybrid
@@ -136,6 +136,8 @@ read markdown files
136
136
 
137
137
  ```txt
138
138
  question
139
+ -> selected strategy: rag | cag | auto
140
+ -> if cag/auto and fresh context pack exists, return cached Markdown package
139
141
  -> selected mode: fts | semantic | hybrid
140
142
  -> optional query embedding
141
143
  -> optional compressed pack prefilter (token bloom)
@@ -145,8 +147,12 @@ question
145
147
  -> ranked chunks with textScore and semanticScore
146
148
  -> token-budget selection
147
149
  -> Markdown context package
150
+ -> if cag/auto, persist derived context pack with current data signature
151
+ -> return cache, strategy and timing metrics
148
152
  ```
149
153
 
154
+ Context packs are stored under `.brainlink/context-packs/*.json`. They are derived artifacts keyed by query, agent, mode, limit and token budget, and are invalidated by the combined index and volatile-memory signature. Markdown remains the source of truth. The `auto` strategy uses CAG on fresh pack hits and falls back to RAG assembly otherwise, refreshing a pack for later calls.
155
+
150
156
  ## Graph Server Flow
151
157
 
152
158
  ```txt
@@ -154,11 +160,15 @@ server command
154
160
  -> optional index rebuild
155
161
  -> HTTP server
156
162
  -> /api/agents lists indexed namespaces
163
+ -> /api/graph-contexts lists visual graph contexts
157
164
  -> /api/graph reads indexed documents and links
165
+ -> /api/graph-layout derives a cauliflower hub layout from indexed graph data
166
+ -> optional context query narrows the layout to a segment-scoped cauliflower subgraph
158
167
  -> browser renders graph canvas
159
168
  ```
160
169
 
161
170
  The graph UI is intentionally read-only. Markdown remains the write interface and index artifacts remain derived data.
171
+ 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.
162
172
 
163
173
  ## HTTP API Flow
164
174
 
@@ -171,6 +181,7 @@ HTTP request
171
181
  ```
172
182
 
173
183
  The HTTP API is local-first and unauthenticated. It is meant for local agents, browser UI, and development workflows.
184
+ The route adapter caches generated frontend assets (`/`, `/styles.css`, `/app.js`, `/app-worker.js`) and graph-layout JSON payloads by layout signature to reduce repeated CPU and allocation pressure during navigation.
174
185
 
175
186
  ## MCP Flow
176
187
 
@@ -50,7 +50,9 @@ Optional per-agent retrieval defaults in `brainlink.config.json`:
50
50
  "coding-agent": {
51
51
  "defaultSearchMode": "semantic",
52
52
  "defaultSearchLimit": 8,
53
- "defaultContextTokens": 2400
53
+ "defaultContextTokens": 2400,
54
+ "defaultContextStrategy": "auto",
55
+ "defaultContextCacheTtlMs": 120000
54
56
  }
55
57
  }
56
58
  }
package/docs/RELEASE.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Brainlink releases are built from the CLI package. Do not publish until the package name, npm account and version are confirmed.
4
4
 
5
- ## Beta Release Checklist
5
+ ## Release Checklist
6
6
 
7
7
  1. Confirm `package.json` name, version, repository, license and bin entries.
8
8
  2. Run `npm install` from a clean checkout when dependencies changed.
@@ -51,9 +51,10 @@ The preferred path is the `Publish npm` GitHub Actions workflow:
51
51
  - GitHub Release `published`: runs checks, pack smoke, then publishes to npm with provenance.
52
52
  - Manual `workflow_dispatch`: runs a dry run by default. Disable `dry_run` only for an intentional manual publish.
53
53
  - Manual `workflow_dispatch` accepts an optional `dist_tag` override. Use `latest` only when the default npm install command should resolve to that version.
54
- - Prerelease versions publish under their prerelease dist-tag, for example `0.1.0-beta.1` publishes with `--tag beta`.
54
+ - Stable versions publish under the `latest` dist-tag by default.
55
+ - Prerelease versions publish under their prerelease dist-tag, for example `1.1.0-beta.1` publishes with `--tag beta`.
55
56
 
56
- On `main`, the publish job checks npm before publishing. If the version already exists, it automatically bumps the package inside the runner to the next available version before checks, packing and publishing. For example, `0.1.0-beta.4` becomes `0.1.0-beta.5`.
57
+ On `main`, the publish job checks npm before publishing. If the version already exists, it automatically bumps the package inside the runner to the next available version before checks, packing and publishing. For example, `1.0.0` becomes `1.0.1`, and `1.1.0-beta.4` becomes `1.1.0-beta.5`.
57
58
 
58
59
  The automatic bump is intentionally not pushed back to `main`. The branch stays protected, and npm remains the source of truth for the latest published package version.
59
60
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andespindola/brainlink",
3
- "version": "0.1.0-beta.99",
3
+ "version": "1.0.1",
4
4
  "description": "Local-first knowledge memory for agents with Markdown, backlinks, indexing and context retrieval.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -48,6 +48,7 @@
48
48
  "build": "npm run clean && npx --yes snyk test && tsc -p tsconfig.json",
49
49
  "dev": "tsx src/cli/main.ts",
50
50
  "dev:mcp": "tsx src/mcp/main.ts",
51
+ "dev:mcp:http": "tsx src/cli/main.ts mcp-server",
51
52
  "brainlink:sync": "bash scripts/brainlink-sync.sh",
52
53
  "security": "npx --yes snyk test",
53
54
  "test": "vitest run --config vitest.config.ts",
@@ -63,6 +64,7 @@
63
64
  "zod": "^4.3.6"
64
65
  },
65
66
  "overrides": {
67
+ "hono": "4.12.21",
66
68
  "qs": "6.15.2"
67
69
  },
68
70
  "devDependencies": {