@andespindola/brainlink 0.1.0-beta.0 → 0.1.0-beta.10

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 (41) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +252 -19
  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 +255 -70
  8. package/dist/application/get-graph-layout.js +6 -3
  9. package/dist/application/get-graph-node.js +12 -0
  10. package/dist/application/get-graph-summary.js +12 -0
  11. package/dist/application/migrate-vault.js +91 -0
  12. package/dist/application/search-graph-node-ids.js +12 -0
  13. package/dist/application/search-knowledge.js +56 -1
  14. package/dist/application/server/routes.js +27 -1
  15. package/dist/cli/commands/agent-commands.js +412 -0
  16. package/dist/cli/commands/config-commands.js +167 -0
  17. package/dist/cli/commands/read-commands.js +25 -8
  18. package/dist/cli/commands/write-commands.js +191 -7
  19. package/dist/cli/main.js +4 -0
  20. package/dist/cli/runtime.js +5 -2
  21. package/dist/domain/embeddings.js +2 -1
  22. package/dist/domain/graph-layout.js +20 -14
  23. package/dist/domain/markdown.js +36 -4
  24. package/dist/infrastructure/config.js +96 -8
  25. package/dist/infrastructure/file-system-vault.js +15 -0
  26. package/dist/infrastructure/paths.js +9 -1
  27. package/dist/infrastructure/session-state.js +172 -0
  28. package/dist/infrastructure/sqlite/graph-reader.js +252 -105
  29. package/dist/infrastructure/sqlite/recovery.js +83 -0
  30. package/dist/infrastructure/sqlite/schema.js +4 -1
  31. package/dist/infrastructure/sqlite/search-reader.js +104 -72
  32. package/dist/infrastructure/sqlite-index.js +16 -3
  33. package/dist/mcp/main.js +11 -3
  34. package/dist/mcp/server.js +22 -2
  35. package/dist/mcp/startup.js +35 -0
  36. package/dist/mcp/tools.js +617 -21
  37. package/docs/AGENT_USAGE.md +95 -6
  38. package/docs/ARCHITECTURE.md +15 -1
  39. package/docs/QUICKSTART.md +104 -0
  40. package/docs/RELEASE.md +3 -3
  41. package/package.json +1 -1
@@ -39,9 +39,21 @@ $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`.
55
+
56
+ `autoIndexOnWrite` (default: `true`) controls whether `add` and MCP write tools index right after writing.
45
57
 
46
58
  ## Agent Namespaces
47
59
 
@@ -162,7 +174,7 @@ Required write behavior:
162
174
  2. Look for an existing related concept with `search`, `links` or `backlinks`.
163
175
  3. Add at least one `[[Existing Note Title]]` link unless the note is intentionally a root concept.
164
176
  4. Add useful `#tags` for retrieval.
165
- 5. Run `index` after the write.
177
+ 5. `add` writes are indexed by default. Only batch with explicit `--no-auto-index`, then run `index` once.
166
178
  6. Run `validate`, `broken-links` or `orphans` when the graph should be connected.
167
179
 
168
180
  Good linked note:
@@ -171,7 +183,6 @@ Good linked note:
171
183
  blink add "SQLite Index Rebuild" \
172
184
  --agent coding-agent \
173
185
  --content "Legacy derived indexes without agent columns are rebuilt because SQLite is disposable. Related: [[Architecture]], [[Agent Namespaces]]. #sqlite #architecture #decision"
174
- blink index
175
186
  blink validate --agent coding-agent
176
187
  ```
177
188
 
@@ -245,9 +256,9 @@ cp docs/templates/agent-note-template.md /tmp/agent-note.md
245
256
  When using MCP, use this compact sequence for the same memory discipline:
246
257
 
247
258
  1. Bootstrap context:
248
- - `brainlink_context` with `agent`, `query`, `mode: hybrid`, `limit`.
259
+ - `brainlink_bootstrap` with `agent`, optional `query`, `mode: hybrid`, `limit`.
249
260
  2. Capture durable decisions:
250
- - `brainlink_add_note` with explicit `[[wiki links]]` and `#tags`.
261
+ - `brainlink_add_note` or `brainlink_add_file` with explicit `[[wiki links]]` and `#tags`.
251
262
  3. Run maintenance before handoff or before the next step:
252
263
  - `brainlink_sync` with `agent`, `contextQuery`, `mode: hybrid`.
253
264
  4. Diagnose graph issues only when needed:
@@ -340,17 +351,72 @@ $HOME/.brainlink/vault/
340
351
  .brainlink/
341
352
  ```
342
353
 
343
- `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.
344
405
 
345
406
  ### Add A Note
346
407
 
347
408
  ```bash
348
409
  blink add "Note Title" --vault ./vault --content "Markdown content"
410
+ blink add "Note Title" --vault ./vault --content-file ./notes.md
411
+ blink add "Note Title" --vault ./vault --content-file ./notes.md --no-auto-index
349
412
  ```
350
413
 
414
+ `--content` and `--content-file` are mutually exclusive. Use `--no-auto-index` if you want to defer indexing in batch operations.
415
+
351
416
  This creates a slugged Markdown file with frontmatter and a heading.
352
417
 
353
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.
354
420
 
355
421
  For agent-private memory:
356
422
 
@@ -390,6 +456,7 @@ blink search "authentication token policy" --vault ./vault --mode semantic --jso
390
456
  ```
391
457
 
392
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.
393
460
 
394
461
  Search modes:
395
462
 
@@ -397,6 +464,8 @@ Search modes:
397
464
  - `fts`: lexical SQLite full-text search only.
398
465
  - `semantic`: local deterministic embedding similarity with SQLite bucket candidate narrowing.
399
466
 
467
+ Hybrid results are cached in-memory for a short TTL and invalidated when `.brainlink/brainlink.db` changes.
468
+
400
469
  ### Build Agent Context
401
470
 
402
471
  ```bash
@@ -462,6 +531,8 @@ Without `--vault`, the graph UI serves `$HOME/.brainlink/vault`.
462
531
 
463
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.
464
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
+
465
536
  The command reindexes by default, then serves:
466
537
 
467
538
  ```txt
@@ -513,18 +584,32 @@ Example MCP client configuration:
513
584
 
514
585
  Available MCP tools:
515
586
 
587
+ - `brainlink_bootstrap`
588
+ - `brainlink_policy`
589
+ - `brainlink_recommendations`
516
590
  - `brainlink_context`
517
591
  - `brainlink_search`
518
592
  - `brainlink_add_note`
593
+ - `brainlink_add_file`
519
594
  - `brainlink_index`
595
+ - `brainlink_stats`
520
596
  - `brainlink_validate`
597
+ - `brainlink_sync`
521
598
  - `brainlink_graph`
522
599
  - `brainlink_broken_links`
523
600
  - `brainlink_orphans`
524
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
+
525
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:
526
610
 
527
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.
528
613
 
529
614
  ```bash
530
615
  export BRAINLINK_ALLOWED_VAULTS="/absolute/path/to/project-vault"
@@ -535,6 +620,8 @@ export BRAINLINK_ALLOWED_VAULTS="/absolute/path/to/project-vault"
535
620
  ```txt
536
621
  GET /api/graph
537
622
  GET /api/graph-layout
623
+ GET /api/graph-node?id=<node-id>
624
+ GET /api/graph-filter?q=<query>&limit=<n>
538
625
  GET /api/search?q=<query>&limit=10&mode=hybrid
539
626
  GET /api/context?q=<query>&limit=12&tokens=2000&mode=hybrid
540
627
  GET /api/links
@@ -547,6 +634,8 @@ GET /api/validate
547
634
 
548
635
  The HTTP API is read-only. Use the CLI for writes and indexing.
549
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
+
550
639
  ## Agent Integration Contract
551
640
 
552
641
  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,12 @@ 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.
290
304
 
291
305
  ### CLI First
292
306
 
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.
307
+ 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
308
 
295
309
  ### Functional Core
296
310
 
@@ -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.0",
3
+ "version": "0.1.0-beta.10",
4
4
  "description": "Local-first knowledge memory for agents with Markdown, backlinks, indexing and context retrieval.",
5
5
  "type": "module",
6
6
  "license": "MIT",