@andespindola/brainlink 0.1.0-beta.1 → 0.1.0-beta.11

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 (43) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +241 -10
  3. package/dist/application/add-note.js +62 -13
  4. package/dist/application/analyze-vault.js +104 -9
  5. package/dist/application/frontend/client-css.js +154 -71
  6. package/dist/application/frontend/client-html.js +42 -33
  7. package/dist/application/frontend/client-js.js +316 -84
  8. package/dist/application/get-graph-layout.js +22 -7
  9. package/dist/application/get-graph-node.js +12 -0
  10. package/dist/application/get-graph-summary.js +12 -0
  11. package/dist/application/index-vault.js +7 -0
  12. package/dist/application/migrate-vault.js +91 -0
  13. package/dist/application/search-graph-node-ids.js +12 -0
  14. package/dist/application/search-knowledge.js +74 -4
  15. package/dist/application/server/routes.js +27 -1
  16. package/dist/cli/commands/agent-commands.js +412 -0
  17. package/dist/cli/commands/config-commands.js +167 -0
  18. package/dist/cli/commands/read-commands.js +25 -8
  19. package/dist/cli/commands/write-commands.js +173 -4
  20. package/dist/cli/main.js +4 -0
  21. package/dist/cli/runtime.js +5 -2
  22. package/dist/domain/embeddings.js +2 -1
  23. package/dist/domain/graph-layout.js +20 -14
  24. package/dist/domain/markdown.js +36 -4
  25. package/dist/infrastructure/config.js +94 -8
  26. package/dist/infrastructure/file-system-vault.js +15 -0
  27. package/dist/infrastructure/paths.js +9 -1
  28. package/dist/infrastructure/search-packs.js +151 -0
  29. package/dist/infrastructure/session-state.js +172 -0
  30. package/dist/infrastructure/sqlite/graph-reader.js +252 -105
  31. package/dist/infrastructure/sqlite/recovery.js +83 -0
  32. package/dist/infrastructure/sqlite/schema.js +4 -1
  33. package/dist/infrastructure/sqlite/search-reader.js +104 -72
  34. package/dist/infrastructure/sqlite-index.js +16 -3
  35. package/dist/mcp/main.js +11 -3
  36. package/dist/mcp/server.js +17 -2
  37. package/dist/mcp/startup.js +35 -0
  38. package/dist/mcp/tools.js +571 -19
  39. package/docs/AGENT_USAGE.md +87 -3
  40. package/docs/ARCHITECTURE.md +16 -1
  41. package/docs/QUICKSTART.md +104 -0
  42. package/docs/RELEASE.md +3 -3
  43. package/package.json +1 -1
@@ -39,9 +39,19 @@ $HOME/.brainlink/vault
39
39
 
40
40
  `blink server` follows the same rule, so it serves the default Brainlink vault instead of the current working directory.
41
41
 
42
- Use `--vault <path>` for a one-off custom vault, or set `vault` in `brainlink.config.json` / `.brainlink.json` for a workspace-level custom default. Set `BRAINLINK_HOME` when the whole Brainlink home directory should live somewhere else.
42
+ Use `--vault <path>` for a one-off custom vault, or set `vault` in config for a persistent default.
43
+ Configuration precedence is:
44
+
45
+ 1. global: `$BRAINLINK_HOME/brainlink.config.json` (or `$HOME/.brainlink/brainlink.config.json`)
46
+ 2. local: `./brainlink.config.json`
47
+ 3. local legacy: `./.brainlink.json`
48
+
49
+ Set `BRAINLINK_HOME` when the whole Brainlink home directory should live somewhere else.
50
+
51
+ Use `blink config where` and `blink config doctor` to inspect active paths and effective source.
43
52
 
44
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`.
45
55
 
46
56
  `autoIndexOnWrite` (default: `true`) controls whether `add` and MCP write tools index right after writing.
47
57
 
@@ -246,7 +256,7 @@ cp docs/templates/agent-note-template.md /tmp/agent-note.md
246
256
  When using MCP, use this compact sequence for the same memory discipline:
247
257
 
248
258
  1. Bootstrap context:
249
- - `brainlink_context` with `agent`, `query`, `mode: hybrid`, `limit`.
259
+ - `brainlink_bootstrap` with `agent`, optional `query`, `mode: hybrid`, `limit`.
250
260
  2. Capture durable decisions:
251
261
  - `brainlink_add_note` or `brainlink_add_file` with explicit `[[wiki links]]` and `#tags`.
252
262
  3. Run maintenance before handoff or before the next step:
@@ -341,7 +351,57 @@ $HOME/.brainlink/vault/
341
351
  .brainlink/
342
352
  ```
343
353
 
344
- `blink init ./vault` creates a custom vault instead.
354
+ `blink init ./vault` creates a custom vault instead. If the custom vault is empty and the default `$HOME/.brainlink/vault` already has Markdown memory, Brainlink copies that content into the custom vault and reindexes it. Use `blink init ./vault --no-migrate-existing` to intentionally start empty, or `blink init ./vault --migrate-from <old-vault>` to migrate from a specific previous vault. Existing target files are not overwritten; conflicting source files are preserved with a `.conflict-<timestamp>` suffix.
355
+
356
+ ### Configure Defaults
357
+
358
+ ```bash
359
+ blink config where
360
+ blink config get vault
361
+ blink config doctor
362
+ blink config doctor --fix
363
+ blink config set-vault /absolute/path/to/vault
364
+ blink config set-vault /absolute/path/to/vault --global
365
+ ```
366
+
367
+ `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.
368
+
369
+ ### Migrate Vaults Explicitly
370
+
371
+ ```bash
372
+ blink migrate-vault --from ~/.brainlink/vault --to ./team-vault --dry-run
373
+ blink migrate-vault --from ~/.brainlink/vault --to ./team-vault
374
+ blink migrate-vault --from ~/.brainlink/vault --to "s3://my-memory-bucket/brainlink"
375
+ blink migrate-vault --from ~/.brainlink/vault --to ./team-vault --report ./migration-report.json
376
+ ```
377
+
378
+ Use `--dry-run` to preview `copied`, `conflicted`, `unchanged` before writing files.
379
+
380
+ ### Install Agent Integration
381
+
382
+ ```bash
383
+ blink agent install
384
+ blink agent install --self-test
385
+ blink agent upgrade
386
+ blink agent policy --preset fully-auto
387
+ blink agent policy --preset strict
388
+ blink agent install --plugin-path ./plugins/brainlink
389
+ blink agent status
390
+ ```
391
+
392
+ `agent install` configures Brainlink MCP in `~/.codex/config.toml` so compatible agents can use Brainlink by default.
393
+ Use `agent upgrade` on legacy installations to reapply the latest defaults and run self-test diagnostics.
394
+ Use `agent policy --preset fully-auto` to keep startup/read auto-bootstrap enabled, or `agent policy --preset strict` to force explicit bootstrap calls.
395
+
396
+ ### Quickstart Plug-And-Play
397
+
398
+ ```bash
399
+ blink quickstart --json
400
+ blink quickstart --vault ./team-vault --agent coding-agent --query "architecture decisions" --json
401
+ blink quickstart --vault ./team-vault --mcp-only --json
402
+ ```
403
+
404
+ `quickstart` runs index, doctor, stats and validation, marks bootstrap readiness for MCP sessions, optionally returns context, and updates agent integration by default.
345
405
 
346
406
  ### Add A Note
347
407
 
@@ -356,6 +416,7 @@ blink add "Note Title" --vault ./vault --content-file ./notes.md --no-auto-index
356
416
  This creates a slugged Markdown file with frontmatter and a heading.
357
417
 
358
418
  The CLI blocks common secret patterns by default. Do not use `--allow-sensitive` unless the vault is intentionally protected.
419
+ Brainlink also auto-connects notes that have no `[[wiki links]]` by adding a fallback edge to an agent hub note, so new memory does not stay disconnected.
359
420
 
360
421
  For agent-private memory:
361
422
 
@@ -395,6 +456,7 @@ blink search "authentication token policy" --vault ./vault --mode semantic --jso
395
456
  ```
396
457
 
397
458
  This returns matching chunks with title, source path, score, `textScore`, `semanticScore`, `searchMode`, and content.
459
+ If `--mode`/`--limit` are omitted, Brainlink resolves those values from the active agent profile before global defaults.
398
460
 
399
461
  Search modes:
400
462
 
@@ -402,6 +464,8 @@ Search modes:
402
464
  - `fts`: lexical SQLite full-text search only.
403
465
  - `semantic`: local deterministic embedding similarity with SQLite bucket candidate narrowing.
404
466
 
467
+ Hybrid results are cached in-memory for a short TTL and invalidated when `.brainlink/brainlink.db` changes.
468
+
405
469
  ### Build Agent Context
406
470
 
407
471
  ```bash
@@ -467,6 +531,8 @@ Without `--vault`, the graph UI serves `$HOME/.brainlink/vault`.
467
531
 
468
532
  The frontend includes an agent selector. Selecting an agent calls the same read APIs with `agent=<agent-id>` and renders that namespace instead of merging every agent into one graph.
469
533
 
534
+ Graph navigation controls include zoom in, zoom out, fit visible nodes and reset-to-fit-all nodes. Mouse wheel zoom is anchored to the cursor. 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).
535
+
470
536
  The command reindexes by default, then serves:
471
537
 
472
538
  ```txt
@@ -518,19 +584,32 @@ Example MCP client configuration:
518
584
 
519
585
  Available MCP tools:
520
586
 
587
+ - `brainlink_bootstrap`
588
+ - `brainlink_policy`
589
+ - `brainlink_recommendations`
521
590
  - `brainlink_context`
522
591
  - `brainlink_search`
523
592
  - `brainlink_add_note`
524
593
  - `brainlink_add_file`
525
594
  - `brainlink_index`
595
+ - `brainlink_stats`
526
596
  - `brainlink_validate`
597
+ - `brainlink_sync`
527
598
  - `brainlink_graph`
528
599
  - `brainlink_broken_links`
529
600
  - `brainlink_orphans`
530
601
 
602
+ Recommended start of every memory-dependent task: call `brainlink_bootstrap` first, then `brainlink_context`. By default, Brainlink enforces context-first for non-context MCP reads (`enforceContextFirst=true`), and also enforces bootstrap with auto-bootstrap on reads when state is missing or stale (`autoBootstrapOnRead=true`).
603
+ MCP startup also bootstraps the configured default vault/agent automatically (`autoBootstrapOnStartup=true`), so sessions start warm without manual calls.
604
+ If `autoBootstrapOnRead` or `enforceContextFirst` are disabled through `brainlink_policy`, behavior is relaxed accordingly; otherwise read tools return preflight-required responses when requirements are not satisfied.
605
+ `brainlink_bootstrap`, `brainlink_policy` and preflight responses include structured `nextActions` so clients can continue tool flows automatically.
606
+ `brainlink_policy` also accepts policy presets (`fully-auto`, `strict`) so MCP clients can switch behavior in one call.
607
+ `brainlink_recommendations` returns the suggested execution order so an agent can follow Brainlink best practices automatically.
608
+
531
609
  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:
532
610
 
533
611
  `brainlink_graph` returns weighted edges. Agents should prefer higher `weight` and stronger `priority` when deciding which related notes matter most.
612
+ `brainlink_add_note` and `brainlink_add_file` return `writeConnectivity` metadata and guarantee at least one edge for new notes.
534
613
 
535
614
  ```bash
536
615
  export BRAINLINK_ALLOWED_VAULTS="/absolute/path/to/project-vault"
@@ -541,6 +620,8 @@ export BRAINLINK_ALLOWED_VAULTS="/absolute/path/to/project-vault"
541
620
  ```txt
542
621
  GET /api/graph
543
622
  GET /api/graph-layout
623
+ GET /api/graph-node?id=<node-id>
624
+ GET /api/graph-filter?q=<query>&limit=<n>
544
625
  GET /api/search?q=<query>&limit=10&mode=hybrid
545
626
  GET /api/context?q=<query>&limit=12&tokens=2000&mode=hybrid
546
627
  GET /api/links
@@ -553,6 +634,9 @@ GET /api/validate
553
634
 
554
635
  The HTTP API is read-only. Use the CLI for writes and indexing.
555
636
 
637
+ Brainlink maintains an automatic SQLite rollback snapshot at `.brainlink/brainlink.db.backup`. When `.brainlink/brainlink.db` is corrupted, Brainlink restores from snapshot automatically or recreates a clean index if no snapshot exists yet.
638
+ Indexing also writes compressed search packs at `.brainlink/search-packs/*.jsonl.gz`; when SQLite cannot be opened, Brainlink falls back to pack-based search automatically.
639
+
556
640
  ## Agent Integration Contract
557
641
 
558
642
  Input:
@@ -34,6 +34,8 @@ src/
34
34
 
35
35
  cli/
36
36
  commands/
37
+ agent-commands.ts
38
+ config-commands.ts
37
39
  read-commands.ts
38
40
  write-commands.ts
39
41
  main.ts
@@ -57,7 +59,13 @@ src/
57
59
  schema.ts
58
60
  search-reader.ts
59
61
  file-system-vault.ts
62
+ session-state.ts
60
63
  sqlite-index.ts
64
+
65
+ mcp/
66
+ main.ts
67
+ server.ts
68
+ tools.ts
61
69
  ```
62
70
 
63
71
  ## Domain
@@ -181,6 +189,10 @@ MCP client
181
189
  ```
182
190
 
183
191
  The MCP adapter stays thin. It validates tool inputs, resolves the configured vault and calls the same application use cases used by the CLI.
192
+ At server startup, Brainlink runs a bootstrap pass on the configured default vault/agent, then keeps enforcing bootstrap policy on read tools.
193
+ For MCP agents, non-context read tools also enforce context-first by default, requiring a recent `brainlink_context` call before additional reads.
194
+ When `mode`/`limit`/`tokens` are omitted, MCP read tools resolve per-agent defaults from `agentProfiles` and then fallback to global config defaults.
195
+ Session state is persisted in `$BRAINLINK_HOME/session-state.json` with independent bootstrap/context freshness per vault/agent so read tools can enforce bootstrap and context-first policies with optional automation.
184
196
 
185
197
  ## Link Resolution
186
198
 
@@ -287,10 +299,13 @@ Markdown keeps the system portable, inspectable, Git-friendly, and compatible wi
287
299
  ### SQLite As Local Index
288
300
 
289
301
  SQLite gives fast local search, local vector storage and rebuildable retrieval without forcing users to run external infrastructure.
302
+ Hybrid retrieval also uses a short-lived in-memory cache keyed by vault/query/agent and invalidated by index file mtime to reduce repeated query latency.
303
+ Brainlink also writes a local rollback snapshot (`.brainlink/brainlink.db.backup`) after successful indexing. On corruption detection (`quick_check`/SQLite malformed errors), Brainlink restores from snapshot automatically before reopening the index.
304
+ Indexing additionally exports compressed pack files (`.brainlink/search-packs/*.jsonl.gz`) from indexed chunks. Search falls back to these packs when SQLite is unavailable, preserving retrieval continuity in degraded mode.
290
305
 
291
306
  ### CLI First
292
307
 
293
- The CLI is the smallest useful integration surface for agents. HTTP is a local inspection adapter, and MCP can be implemented outside this package by wrapping the CLI.
308
+ The CLI is the smallest useful integration surface for agents. HTTP is a local inspection adapter, and Brainlink also ships a built-in MCP server (`brainlink-mcp`) that uses the same application use cases.
294
309
 
295
310
  ### Functional Core
296
311
 
@@ -0,0 +1,104 @@
1
+ # Quickstart
2
+
3
+ Use this path when you want Brainlink running as agent memory with the smallest setup.
4
+
5
+ ## 1) Install Brainlink
6
+
7
+ ```bash
8
+ npm install -g @andespindola/brainlink@latest
9
+ ```
10
+
11
+ ## 2) Install Agent Integration
12
+
13
+ ```bash
14
+ blink agent install --self-test
15
+ blink agent upgrade
16
+ blink agent policy --preset fully-auto
17
+ blink agent status
18
+ ```
19
+
20
+ For local plugin gallery in this repository:
21
+
22
+ ```bash
23
+ blink agent install --plugin-path ./plugins/brainlink --self-test
24
+ ```
25
+
26
+ One-command setup and readiness check:
27
+
28
+ ```bash
29
+ blink quickstart --query "what should I know before this task?" --json
30
+ ```
31
+
32
+ ## 3) Initialize Or Select Vault
33
+
34
+ ```bash
35
+ blink init
36
+ blink config where
37
+ ```
38
+
39
+ To set a different default vault:
40
+
41
+ ```bash
42
+ blink config set-vault /absolute/path/to/vault
43
+ ```
44
+
45
+ Optional per-agent retrieval defaults in `brainlink.config.json`:
46
+
47
+ ```json
48
+ {
49
+ "agentProfiles": {
50
+ "coding-agent": {
51
+ "defaultSearchMode": "semantic",
52
+ "defaultSearchLimit": 8,
53
+ "defaultContextTokens": 2400
54
+ }
55
+ }
56
+ }
57
+ ```
58
+
59
+ ## 4) Run Bootstrap Before Work
60
+
61
+ MCP clients should call `brainlink_bootstrap` first for each vault/agent session, then `brainlink_context`.
62
+ By default, Brainlink enforces context-first for non-context read tools, so a fresh `brainlink_context` call is required before other MCP reads.
63
+ Read tools auto-bootstrap by default when state is missing/stale, and bootstrap/preflight responses include structured `nextActions` for automatic client flows.
64
+ MCP startup also runs bootstrap automatically for the configured default vault/agent.
65
+
66
+ For CLI workflows:
67
+
68
+ ```bash
69
+ blink context "what should I know before this task?" --mode hybrid --json
70
+ ```
71
+
72
+ ## 5) Write Durable Memory
73
+
74
+ ```bash
75
+ blink add "Architecture Decision" --content "Use explicit [[Bounded Context]] links and #tags. #architecture #decision"
76
+ ```
77
+
78
+ ## 6) Validate Health
79
+
80
+ ```bash
81
+ blink validate
82
+ blink doctor
83
+ blink stats --extended --json
84
+ ```
85
+
86
+ ## 7) Migrate Existing Memory (Optional)
87
+
88
+ Preview first:
89
+
90
+ ```bash
91
+ blink migrate-vault --from ~/.brainlink/vault --to ./team-vault --dry-run --report ./migration-report.json
92
+ ```
93
+
94
+ Apply:
95
+
96
+ ```bash
97
+ blink migrate-vault --from ~/.brainlink/vault --to ./team-vault --report ./migration-report.json
98
+ ```
99
+
100
+ S3 target:
101
+
102
+ ```bash
103
+ blink migrate-vault --from ~/.brainlink/vault --to "s3://my-memory-bucket/brainlink" --dry-run
104
+ ```
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
- ## Alpha Release Checklist
5
+ ## Beta 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,9 @@ 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-alpha.1` publishes with `--tag alpha`.
54
+ - Prerelease versions publish under their prerelease dist-tag, for example `0.1.0-beta.1` publishes with `--tag beta`.
55
55
 
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-alpha.4` becomes `0.1.0-alpha.5`.
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
57
 
58
58
  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
59
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andespindola/brainlink",
3
- "version": "0.1.0-beta.1",
3
+ "version": "0.1.0-beta.11",
4
4
  "description": "Local-first knowledge memory for agents with Markdown, backlinks, indexing and context retrieval.",
5
5
  "type": "module",
6
6
  "license": "MIT",