@andespindola/brainlink 0.1.0-beta.1 → 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.
- package/CHANGELOG.md +46 -0
- package/README.md +239 -10
- package/dist/application/add-note.js +62 -13
- package/dist/application/analyze-vault.js +104 -9
- package/dist/application/frontend/client-css.js +154 -71
- package/dist/application/frontend/client-html.js +42 -33
- package/dist/application/frontend/client-js.js +255 -70
- package/dist/application/get-graph-layout.js +6 -3
- package/dist/application/get-graph-node.js +12 -0
- package/dist/application/get-graph-summary.js +12 -0
- package/dist/application/migrate-vault.js +91 -0
- package/dist/application/search-graph-node-ids.js +12 -0
- package/dist/application/search-knowledge.js +56 -1
- package/dist/application/server/routes.js +27 -1
- package/dist/cli/commands/agent-commands.js +412 -0
- package/dist/cli/commands/config-commands.js +167 -0
- package/dist/cli/commands/read-commands.js +25 -8
- package/dist/cli/commands/write-commands.js +173 -4
- package/dist/cli/main.js +4 -0
- package/dist/cli/runtime.js +5 -2
- package/dist/domain/embeddings.js +2 -1
- package/dist/domain/graph-layout.js +20 -14
- package/dist/domain/markdown.js +36 -4
- package/dist/infrastructure/config.js +94 -8
- package/dist/infrastructure/file-system-vault.js +15 -0
- package/dist/infrastructure/paths.js +9 -1
- package/dist/infrastructure/session-state.js +172 -0
- package/dist/infrastructure/sqlite/graph-reader.js +252 -105
- package/dist/infrastructure/sqlite/recovery.js +83 -0
- package/dist/infrastructure/sqlite/schema.js +4 -1
- package/dist/infrastructure/sqlite/search-reader.js +104 -72
- package/dist/infrastructure/sqlite-index.js +16 -3
- package/dist/mcp/main.js +11 -3
- package/dist/mcp/server.js +17 -2
- package/dist/mcp/startup.js +35 -0
- package/dist/mcp/tools.js +571 -19
- package/docs/AGENT_USAGE.md +86 -3
- package/docs/ARCHITECTURE.md +15 -1
- package/docs/QUICKSTART.md +104 -0
- package/docs/RELEASE.md +3 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,51 @@
|
|
|
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
|
+
|
|
26
|
+
## 0.1.0-beta.3
|
|
27
|
+
|
|
28
|
+
- Added CLI configuration commands for effective vault management, including `config where`, `config get`, `config doctor` and `config set-vault`.
|
|
29
|
+
- Added explicit `migrate-vault` command with `--dry-run` preview and conflict-preserving copy behavior.
|
|
30
|
+
- Added one-command agent setup through `agent install` plus `agent status` diagnostics.
|
|
31
|
+
- Added MCP `brainlink_bootstrap` default entrypoint guidance for plug-and-play agent memory flows.
|
|
32
|
+
- Added migration coverage for S3 bucket vault targets.
|
|
33
|
+
- Updated architecture and agent-usage documentation to reflect current CLI/MCP behavior and configuration precedence.
|
|
34
|
+
|
|
35
|
+
## 0.1.0-beta.2
|
|
36
|
+
|
|
37
|
+
- Added MCP installation guidance for direct server configuration and local client stores.
|
|
38
|
+
- Documented MCP vault allowlisting with `BRAINLINK_ALLOWED_VAULTS`.
|
|
39
|
+
- Aligned the documented MCP tool list with the current server tools.
|
|
40
|
+
- Updated release documentation for the beta package line.
|
|
41
|
+
|
|
42
|
+
## 0.1.0-beta.0
|
|
43
|
+
|
|
44
|
+
- Promoted the package to the beta prerelease channel.
|
|
45
|
+
- Added built-in MCP stdio server distribution through `brainlink-mcp`.
|
|
46
|
+
- Added agent namespaces, auto-indexing on writes and file ingestion flows.
|
|
47
|
+
- Added S3-compatible bucket vault support and weighted graph relationships.
|
|
48
|
+
|
|
3
49
|
## 0.1.0-alpha.0
|
|
4
50
|
|
|
5
51
|
- Added local-first Markdown vault indexing.
|
package/README.md
CHANGED
|
@@ -57,6 +57,7 @@ LLMs do not have infinite context. Brainlink gives agents an external memory lay
|
|
|
57
57
|
6. Brainlink returns compact, source-backed context.
|
|
58
58
|
|
|
59
59
|
Markdown is the source of truth. `.brainlink/brainlink.db` is only a rebuildable index.
|
|
60
|
+
Brainlink now keeps an automatic rollback snapshot at `.brainlink/brainlink.db.backup`. If the main SQLite file is corrupted, Brainlink automatically restores from snapshot (or recreates a clean index when no snapshot exists).
|
|
60
61
|
|
|
61
62
|
## Features
|
|
62
63
|
|
|
@@ -106,6 +107,8 @@ npx @andespindola/brainlink@latest --help
|
|
|
106
107
|
|
|
107
108
|
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
109
|
|
|
110
|
+
For a condensed setup path, see [docs/QUICKSTART.md](./docs/QUICKSTART.md).
|
|
111
|
+
|
|
109
112
|
### 1. Check Whether Brainlink Is Installed
|
|
110
113
|
|
|
111
114
|
```bash
|
|
@@ -380,19 +383,154 @@ Example MCP client configuration:
|
|
|
380
383
|
}
|
|
381
384
|
```
|
|
382
385
|
|
|
386
|
+
### One-Command Agent Setup
|
|
387
|
+
|
|
388
|
+
If your agent runtime is Codex-compatible, run:
|
|
389
|
+
|
|
390
|
+
```bash
|
|
391
|
+
blink agent install --self-test
|
|
392
|
+
blink agent upgrade
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
This configures `~/.codex/config.toml` with Brainlink MCP (`brainlink-mcp`) so Brainlink is available by default in agent sessions.
|
|
396
|
+
|
|
397
|
+
If you are inside this repository and want plugin gallery setup too:
|
|
398
|
+
|
|
399
|
+
```bash
|
|
400
|
+
blink agent install --plugin-path ./plugins/brainlink
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
To verify:
|
|
404
|
+
|
|
405
|
+
```bash
|
|
406
|
+
blink agent status
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
For fully automated first run (vault index + health + bootstrap readiness + agent integration):
|
|
410
|
+
|
|
411
|
+
```bash
|
|
412
|
+
blink quickstart --query "what should I know before this task?" --json
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
For a locked-down setup, allowlist the vaults that MCP clients may access:
|
|
416
|
+
|
|
417
|
+
```json
|
|
418
|
+
{
|
|
419
|
+
"mcpServers": {
|
|
420
|
+
"brainlink": {
|
|
421
|
+
"command": "brainlink-mcp",
|
|
422
|
+
"env": {
|
|
423
|
+
"BRAINLINK_ALLOWED_VAULTS": "/absolute/path/to/project-vault,/absolute/path/to/team-vault"
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
### Install In MCP Client Stores
|
|
431
|
+
|
|
432
|
+
Brainlink can be exposed to MCP-compatible client stores in two ways:
|
|
433
|
+
|
|
434
|
+
1. Register the stdio server directly when the client accepts `mcpServers` configuration.
|
|
435
|
+
2. Register the local plugin from this repository when the client supports a plugin gallery or local marketplace.
|
|
436
|
+
|
|
437
|
+
Direct MCP server setup:
|
|
438
|
+
|
|
439
|
+
```bash
|
|
440
|
+
npm install -g @andespindola/brainlink@latest
|
|
441
|
+
command -v brainlink-mcp
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
Use this server configuration in any MCP-compatible client that reads a JSON MCP manifest:
|
|
445
|
+
|
|
446
|
+
```json
|
|
447
|
+
{
|
|
448
|
+
"mcpServers": {
|
|
449
|
+
"brainlink": {
|
|
450
|
+
"command": "brainlink-mcp"
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
Local plugin gallery setup:
|
|
457
|
+
|
|
458
|
+
```bash
|
|
459
|
+
npm install -g @andespindola/brainlink@latest
|
|
460
|
+
git clone https://github.com/andersonflima/brainlink.git "$HOME/brainlink"
|
|
461
|
+
mkdir -p "$HOME/plugins"
|
|
462
|
+
ln -s "$HOME/brainlink/plugins/brainlink" "$HOME/plugins/brainlink"
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
Then register the plugin in the local marketplace file used by compatible clients:
|
|
466
|
+
|
|
467
|
+
```bash
|
|
468
|
+
node <<'NODE'
|
|
469
|
+
const fs = require('node:fs')
|
|
470
|
+
const os = require('node:os')
|
|
471
|
+
const path = require('node:path')
|
|
472
|
+
|
|
473
|
+
const marketplacePath = path.join(os.homedir(), '.agents', 'plugins', 'marketplace.json')
|
|
474
|
+
const pluginEntry = {
|
|
475
|
+
name: 'brainlink',
|
|
476
|
+
source: {
|
|
477
|
+
source: 'local',
|
|
478
|
+
path: './plugins/brainlink'
|
|
479
|
+
},
|
|
480
|
+
policy: {
|
|
481
|
+
installation: 'AVAILABLE',
|
|
482
|
+
authentication: 'ON_INSTALL'
|
|
483
|
+
},
|
|
484
|
+
category: 'Productivity'
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
fs.mkdirSync(path.dirname(marketplacePath), { recursive: true })
|
|
488
|
+
|
|
489
|
+
const marketplace = fs.existsSync(marketplacePath)
|
|
490
|
+
? JSON.parse(fs.readFileSync(marketplacePath, 'utf8'))
|
|
491
|
+
: {
|
|
492
|
+
name: 'local',
|
|
493
|
+
interface: {
|
|
494
|
+
displayName: 'Local'
|
|
495
|
+
},
|
|
496
|
+
plugins: []
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
const plugins = Array.isArray(marketplace.plugins) ? marketplace.plugins : []
|
|
500
|
+
marketplace.plugins = [...plugins.filter((plugin) => plugin?.name !== 'brainlink'), pluginEntry]
|
|
501
|
+
|
|
502
|
+
fs.writeFileSync(marketplacePath, `${JSON.stringify(marketplace, null, 2)}\n`)
|
|
503
|
+
NODE
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
Restart the client after changing marketplace or MCP configuration so it reloads the Brainlink entry. The plugin starts `brainlink-mcp` and exposes the same tool set listed below.
|
|
507
|
+
|
|
383
508
|
Available tools:
|
|
384
509
|
|
|
510
|
+
- `brainlink_bootstrap`: plug-and-play entrypoint that runs index + health checks and can return context in one call.
|
|
511
|
+
- `brainlink_policy`: read or update bootstrap/context-first policy, including presets (`preset: "fully-auto" | "strict"`).
|
|
512
|
+
- `brainlink_recommendations`: return an automatic action plan so agents can run Brainlink in the recommended order.
|
|
385
513
|
- `brainlink_context`: read indexed context for a task or question.
|
|
386
514
|
- `brainlink_search`: search indexed notes.
|
|
387
515
|
- `brainlink_add_note`: write durable Markdown memory and reindex.
|
|
388
516
|
- `brainlink_add_file`: ingest a local file as a note and reindex.
|
|
389
517
|
- `brainlink_index`: rebuild the vault index.
|
|
518
|
+
- `brainlink_stats`: read indexed vault statistics.
|
|
390
519
|
- `brainlink_validate`: validate broken links and orphan notes.
|
|
520
|
+
- `brainlink_sync`: run index, stats, validation, broken-link and orphan checks in one call.
|
|
391
521
|
- `brainlink_graph`: read indexed graph nodes and weighted links.
|
|
392
522
|
- `brainlink_broken_links`: list unresolved wiki links.
|
|
393
523
|
- `brainlink_orphans`: list disconnected notes.
|
|
394
524
|
|
|
395
|
-
|
|
525
|
+
For the most automatic workflow, start MCP sessions with `brainlink_bootstrap` (optionally with `query`) and then continue with `brainlink_context`/`brainlink_add_note`.
|
|
526
|
+
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.
|
|
527
|
+
By default, MCP startup already runs bootstrap on the configured default vault/agent (`autoBootstrapOnStartup=true`), so sessions begin warm.
|
|
528
|
+
By default, Brainlink enforces bootstrap and auto-runs it for read tools when session state is missing or stale (`autoBootstrapOnRead=true`).
|
|
529
|
+
If you disable `autoBootstrapOnRead` through `brainlink_policy`, read tools return a preflight instruction with suggested `brainlink_bootstrap` arguments.
|
|
530
|
+
`brainlink_bootstrap`, `brainlink_policy` and preflight responses include structured `nextActions` so MCP clients can continue automatically without custom parsing.
|
|
531
|
+
For one-call planning, use `brainlink_recommendations` to get the recommended tool sequence for the current vault/agent/query.
|
|
532
|
+
|
|
533
|
+
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.
|
|
396
534
|
|
|
397
535
|
Agents can raise the importance of a relationship by putting priority markers on the same line as a wiki link:
|
|
398
536
|
|
|
@@ -417,11 +555,14 @@ The graph UI shows:
|
|
|
417
555
|
|
|
418
556
|
- notes as nodes
|
|
419
557
|
- `[[wiki links]]` as weighted edges
|
|
420
|
-
-
|
|
421
|
-
- full Markdown content for the selected note
|
|
558
|
+
- details opened on node click (tags, outgoing links, backlinks, full Markdown content)
|
|
422
559
|
- neutral graph nodes with segment/group metadata
|
|
423
560
|
- agent selector for isolated views
|
|
561
|
+
- graph filter matches title, path, tags and note content
|
|
424
562
|
- realtime refresh while `--watch` is enabled
|
|
563
|
+
- graph controls for zoom in, zoom out, fit visible nodes and reset-to-fit-all
|
|
564
|
+
- wheel zoom anchored to cursor position for faster navigation in large graphs
|
|
565
|
+
- floating graph totals (notes, links, tags) below the Brainlink title
|
|
425
566
|
|
|
426
567
|
The server indexes before starting by default. Use `--no-index` to skip that step:
|
|
427
568
|
|
|
@@ -440,6 +581,7 @@ Routes:
|
|
|
440
581
|
- `GET /api/agents`
|
|
441
582
|
- `GET /api/graph`
|
|
442
583
|
- `GET /api/graph-layout`
|
|
584
|
+
- `GET /api/graph-node?id=<node-id>`
|
|
443
585
|
- `GET /api/search?q=<query>&limit=10&mode=hybrid`
|
|
444
586
|
- `GET /api/context?q=<query>&limit=12&tokens=2000&mode=hybrid`
|
|
445
587
|
- `GET /api/links`
|
|
@@ -461,14 +603,77 @@ Read routes accept `agent=<agent-id>`:
|
|
|
461
603
|
|
|
462
604
|
Every command works with either `brainlink` or `blink`.
|
|
463
605
|
|
|
606
|
+
### `agent`
|
|
607
|
+
|
|
608
|
+
```bash
|
|
609
|
+
blink agent install
|
|
610
|
+
blink agent install --self-test
|
|
611
|
+
blink agent upgrade
|
|
612
|
+
blink agent policy --preset fully-auto
|
|
613
|
+
blink agent policy --preset strict
|
|
614
|
+
blink agent policy --enforce-context-first false
|
|
615
|
+
blink agent install --plugin-path ./plugins/brainlink
|
|
616
|
+
blink agent install --mcp-only --allowed-vaults "/absolute/vault,/absolute/team-vault"
|
|
617
|
+
blink agent status
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
Installs/checks agent integration. `install` writes Brainlink MCP config into `~/.codex/config.toml`.
|
|
621
|
+
When plugin files are available, it also links Brainlink plugin files into `~/plugins/brainlink` and updates `~/.agents/plugins/marketplace.json`.
|
|
622
|
+
With `--self-test`, install also validates MCP block presence, command wiring and local plugin registration signals.
|
|
623
|
+
Use `agent upgrade` on legacy installations to reapply current defaults and run the same self-test diagnostics.
|
|
624
|
+
Use `agent policy --preset fully-auto` for plug-and-play defaults, or `agent policy --preset strict` to require explicit bootstrap calls.
|
|
625
|
+
Both presets keep `enforceContextFirst=true` so Brainlink stays the primary context source for MCP sessions.
|
|
626
|
+
|
|
627
|
+
### `quickstart`
|
|
628
|
+
|
|
629
|
+
```bash
|
|
630
|
+
blink quickstart --json
|
|
631
|
+
blink quickstart --vault ./team-vault --agent coding-agent --query "architecture decisions" --json
|
|
632
|
+
blink quickstart --vault ./team-vault --mcp-only --json
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
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.
|
|
636
|
+
When `--mode`, `--limit` or `--tokens` are omitted, quickstart uses agent profile defaults when available.
|
|
637
|
+
|
|
638
|
+
### `config`
|
|
639
|
+
|
|
640
|
+
```bash
|
|
641
|
+
blink config where
|
|
642
|
+
blink config get vault
|
|
643
|
+
blink config doctor
|
|
644
|
+
blink config doctor --fix
|
|
645
|
+
blink config set-vault /absolute/path/to/existing-vault
|
|
646
|
+
blink config set-vault /absolute/path/to/existing-vault --migrate-from ~/.brainlink/vault
|
|
647
|
+
blink config set-vault "s3://my-memory-bucket/brainlink" --global
|
|
648
|
+
```
|
|
649
|
+
|
|
650
|
+
`config set-vault` writes configuration through CLI (no manual file edits required).
|
|
651
|
+
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.
|
|
652
|
+
Use `--global` to write to `$BRAINLINK_HOME/brainlink.config.json`, `--no-migrate` to skip migration, and `--no-index` to skip post-migration indexing.
|
|
653
|
+
`config doctor` is dry-run by default; use `--fix` to apply safe config normalization and allowlist fixes.
|
|
654
|
+
|
|
655
|
+
### `migrate-vault`
|
|
656
|
+
|
|
657
|
+
```bash
|
|
658
|
+
blink migrate-vault --from ~/.brainlink/vault --to ./team-vault --dry-run
|
|
659
|
+
blink migrate-vault --from ~/.brainlink/vault --to ./team-vault
|
|
660
|
+
blink migrate-vault --from ~/.brainlink/vault --to "s3://my-memory-bucket/brainlink"
|
|
661
|
+
blink migrate-vault --from ~/.brainlink/vault --to ./team-vault --report ./migration-report.json
|
|
662
|
+
```
|
|
663
|
+
|
|
664
|
+
Runs explicit markdown migration between vaults while preserving conflicts as `.conflict-<timestamp>` files.
|
|
665
|
+
Use `--dry-run` to preview `copied`, `conflicted` and `unchanged` counts before writing.
|
|
666
|
+
|
|
464
667
|
### `init`
|
|
465
668
|
|
|
466
669
|
```bash
|
|
467
670
|
blink init
|
|
468
671
|
blink init ./vault
|
|
672
|
+
blink init ./team-vault --migrate-from ~/.brainlink/vault
|
|
469
673
|
```
|
|
470
674
|
|
|
471
675
|
Initializes vault metadata. Without an argument, Brainlink initializes the default vault at `$HOME/.brainlink/vault`.
|
|
676
|
+
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.
|
|
472
677
|
|
|
473
678
|
### `add`
|
|
474
679
|
|
|
@@ -482,6 +687,7 @@ blink add "Note Title" --vault ./vault --content-file ./notes.md --no-auto-index
|
|
|
482
687
|
`--content` and `--content-file` are mutually exclusive. Add `--no-auto-index` when you want to defer reindexing.
|
|
483
688
|
|
|
484
689
|
Creates a Markdown note under `agents/<agent-id>/`. Common secret patterns are blocked by default; use `--allow-sensitive` only for an intentionally protected vault.
|
|
690
|
+
To avoid disconnected memory, Brainlink auto-adds a fallback wiki edge when a note is written without links, creating agent hub notes when needed.
|
|
485
691
|
|
|
486
692
|
### `index`
|
|
487
693
|
|
|
@@ -510,6 +716,7 @@ blink search "query" --vault ./vault --mode semantic --json
|
|
|
510
716
|
```
|
|
511
717
|
|
|
512
718
|
Runs retrieval over indexed chunks.
|
|
719
|
+
If `--mode` or `--limit` is omitted, Brainlink resolves values from the current agent profile before falling back to global defaults.
|
|
513
720
|
|
|
514
721
|
Modes:
|
|
515
722
|
|
|
@@ -517,6 +724,8 @@ Modes:
|
|
|
517
724
|
- `fts`: exact lexical retrieval through SQLite FTS.
|
|
518
725
|
- `semantic`: local deterministic embedding similarity only.
|
|
519
726
|
|
|
727
|
+
Hybrid results are cached in-memory for a short TTL and invalidated automatically when the local index file changes.
|
|
728
|
+
|
|
520
729
|
### `context`
|
|
521
730
|
|
|
522
731
|
```bash
|
|
@@ -559,9 +768,11 @@ Prints indexed graph data. Edges include `weight` and `priority` so agents can c
|
|
|
559
768
|
```bash
|
|
560
769
|
blink stats --vault ./vault
|
|
561
770
|
blink stats --vault ./vault --agent coding-agent --json
|
|
771
|
+
blink stats --vault ./vault --agent coding-agent --extended --json
|
|
562
772
|
```
|
|
563
773
|
|
|
564
774
|
Prints vault metrics.
|
|
775
|
+
Use `--extended` to include storage footprint, link quality ratios and observability probes (`index`, `search`, `context` latencies).
|
|
565
776
|
|
|
566
777
|
### `broken-links`
|
|
567
778
|
|
|
@@ -593,7 +804,7 @@ Validates graph health. The command exits non-zero when required checks fail.
|
|
|
593
804
|
blink doctor --vault ./vault
|
|
594
805
|
```
|
|
595
806
|
|
|
596
|
-
Runs environment and vault checks.
|
|
807
|
+
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).
|
|
597
808
|
|
|
598
809
|
### `watch`
|
|
599
810
|
|
|
@@ -630,7 +841,13 @@ npm run --silent dev -- context "question" --vault ./vault --json
|
|
|
630
841
|
|
|
631
842
|
## Configuration
|
|
632
843
|
|
|
633
|
-
Brainlink
|
|
844
|
+
Brainlink merges configuration in this order:
|
|
845
|
+
|
|
846
|
+
1. Global: `$BRAINLINK_HOME/brainlink.config.json` (or `$HOME/.brainlink/brainlink.config.json` by default)
|
|
847
|
+
2. Local: `brainlink.config.json` in the current working directory
|
|
848
|
+
3. Local legacy compatibility: `.brainlink.json` in the current working directory
|
|
849
|
+
|
|
850
|
+
If no `vault` is configured and no `--vault` flag is passed, Brainlink uses `$HOME/.brainlink/vault`.
|
|
634
851
|
|
|
635
852
|
```json
|
|
636
853
|
{
|
|
@@ -644,13 +861,24 @@ Brainlink reads `brainlink.config.json` or `.brainlink.json` from the current wo
|
|
|
644
861
|
"defaultContextTokens": 2000,
|
|
645
862
|
"embeddingProvider": "local",
|
|
646
863
|
"defaultSearchMode": "hybrid",
|
|
647
|
-
"chunkSize": 1200
|
|
864
|
+
"chunkSize": 1200,
|
|
865
|
+
"agentProfiles": {
|
|
866
|
+
"coding-agent": {
|
|
867
|
+
"defaultSearchMode": "semantic",
|
|
868
|
+
"defaultSearchLimit": 8,
|
|
869
|
+
"defaultContextTokens": 2400
|
|
870
|
+
},
|
|
871
|
+
"*": {
|
|
872
|
+
"defaultSearchMode": "hybrid"
|
|
873
|
+
}
|
|
874
|
+
}
|
|
648
875
|
}
|
|
876
|
+
```
|
|
649
877
|
|
|
650
878
|
`defaultAgent` is optional. When set, CLI and MCP calls that omit `--agent`/`agent` use this value automatically. If not set, behavior remains as before.
|
|
879
|
+
`agentProfiles` is optional. When present, CLI and MCP resolve `mode`, `limit` and `tokens` per agent automatically, then fallback to global defaults.
|
|
651
880
|
|
|
652
881
|
`autoIndexOnWrite` is optional and defaults to `true`. Set it to `false` to defer indexing after writes.
|
|
653
|
-
```
|
|
654
882
|
|
|
655
883
|
Use `"embeddingProvider": "none"` when you want FTS-only indexing.
|
|
656
884
|
|
|
@@ -763,17 +991,18 @@ Detailed notes:
|
|
|
763
991
|
- HTTP API is local and unauthenticated.
|
|
764
992
|
- Watch mode depends on the platform filesystem watcher.
|
|
765
993
|
|
|
766
|
-
##
|
|
994
|
+
## Beta Scope
|
|
767
995
|
|
|
768
|
-
`0.1.0-
|
|
996
|
+
The `0.1.0-beta` line is intended to stabilize the local-first memory loop:
|
|
769
997
|
|
|
770
998
|
- Markdown as durable memory.
|
|
771
999
|
- SQLite FTS plus local embeddings and semantic buckets as rebuildable retrieval index.
|
|
772
1000
|
- CLI as the primary agent interface.
|
|
773
1001
|
- HTTP graph API and frontend as inspection tools.
|
|
774
1002
|
- Agent namespaces to avoid context mixing.
|
|
1003
|
+
- MCP tools for context retrieval, durable memory writes and graph maintenance.
|
|
775
1004
|
|
|
776
|
-
The
|
|
1005
|
+
The beta includes local semantic retrieval. Remote embedding providers, remote auth, advanced deduplication and graph editing are future milestones.
|
|
777
1006
|
|
|
778
1007
|
## Security
|
|
779
1008
|
|
|
@@ -1,30 +1,79 @@
|
|
|
1
|
+
import { access } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
1
3
|
import { writeMarkdownFile } from '../infrastructure/file-system-vault.js';
|
|
2
4
|
import { sanitizeAgentId, sharedAgentId } from '../domain/agents.js';
|
|
5
|
+
import { extractWikiLinks } from '../domain/markdown.js';
|
|
3
6
|
import { validateNoteInput } from '../domain/note-safety.js';
|
|
7
|
+
import { ensureVault } from '../infrastructure/file-system-vault.js';
|
|
4
8
|
const slugify = (title) => title
|
|
5
9
|
.normalize('NFKD')
|
|
6
10
|
.replace(/[\u0300-\u036f]/g, '')
|
|
7
11
|
.toLowerCase()
|
|
8
12
|
.replace(/[^a-z0-9]+/g, '-')
|
|
9
13
|
.replace(/^-+|-+$/g, '');
|
|
10
|
-
|
|
14
|
+
const systemHubTitle = 'Memory Hub';
|
|
15
|
+
const systemRootTitle = 'Knowledge Root';
|
|
16
|
+
const normalizeTitle = (title) => title.trim().replace(/\.md$/i, '').toLowerCase();
|
|
17
|
+
const noteFilename = (agentId, title) => `agents/${agentId}/${slugify(title) || 'untitled'}.md`;
|
|
18
|
+
const buildNote = (title, content, agentId) => [
|
|
19
|
+
`---`,
|
|
20
|
+
`title: "${title.replaceAll('"', '\\"')}"`,
|
|
21
|
+
`agent: "${agentId}"`,
|
|
22
|
+
`---`,
|
|
23
|
+
'',
|
|
24
|
+
`# ${title}`,
|
|
25
|
+
'',
|
|
26
|
+
content.trim(),
|
|
27
|
+
''
|
|
28
|
+
].join('\n');
|
|
29
|
+
const ensureSystemNote = async (vaultPath, absoluteVaultPath, agentId, title, content) => {
|
|
30
|
+
const filename = noteFilename(agentId, title);
|
|
31
|
+
const absolutePath = join(absoluteVaultPath, filename);
|
|
32
|
+
try {
|
|
33
|
+
await access(absolutePath);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
catch { }
|
|
37
|
+
await writeMarkdownFile(vaultPath, filename, buildNote(title, content, agentId));
|
|
38
|
+
};
|
|
39
|
+
const ensureNonOrphanContent = async (vaultPath, absoluteVaultPath, title, content, agentId) => {
|
|
40
|
+
const links = extractWikiLinks(content).filter((link) => normalizeTitle(link) !== normalizeTitle(title));
|
|
41
|
+
if (links.length > 0) {
|
|
42
|
+
return {
|
|
43
|
+
content: content.trim(),
|
|
44
|
+
autoLinked: false,
|
|
45
|
+
linkTarget: null
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const fallbackTitle = normalizeTitle(title) === normalizeTitle(systemHubTitle) ? systemRootTitle : systemHubTitle;
|
|
49
|
+
if (fallbackTitle === systemRootTitle) {
|
|
50
|
+
await ensureSystemNote(vaultPath, absoluteVaultPath, agentId, systemRootTitle, `Entry point for agent memory. [[${systemHubTitle}]] #memory #root`);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
await ensureSystemNote(vaultPath, absoluteVaultPath, agentId, systemHubTitle, 'Central memory index for this agent namespace. #memory #hub');
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
content: `${content.trim()}\n\nRelated: [[${fallbackTitle}]]`,
|
|
57
|
+
autoLinked: true,
|
|
58
|
+
linkTarget: fallbackTitle
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
export const addNoteWithMetadata = async (vaultPath, title, content, agentId = sharedAgentId, options = {}) => {
|
|
11
62
|
validateNoteInput({
|
|
12
63
|
title,
|
|
13
64
|
content,
|
|
14
65
|
allowSensitive: options.allowSensitive
|
|
15
66
|
});
|
|
16
67
|
const sanitizedAgentId = sanitizeAgentId(agentId);
|
|
68
|
+
const absoluteVaultPath = await ensureVault(vaultPath);
|
|
17
69
|
const filename = `agents/${sanitizedAgentId}/${slugify(title) || 'untitled'}.md`;
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
content.trim(),
|
|
27
|
-
''
|
|
28
|
-
].join('\n');
|
|
29
|
-
return writeMarkdownFile(vaultPath, filename, note);
|
|
70
|
+
const linkedContent = await ensureNonOrphanContent(vaultPath, absoluteVaultPath, title, content, sanitizedAgentId);
|
|
71
|
+
const note = buildNote(title, linkedContent.content, sanitizedAgentId);
|
|
72
|
+
const path = await writeMarkdownFile(vaultPath, filename, note);
|
|
73
|
+
return {
|
|
74
|
+
path,
|
|
75
|
+
autoLinked: linkedContent.autoLinked,
|
|
76
|
+
linkTarget: linkedContent.linkTarget
|
|
77
|
+
};
|
|
30
78
|
};
|
|
79
|
+
export const addNote = async (vaultPath, title, content, agentId = sharedAgentId, options = {}) => (await addNoteWithMetadata(vaultPath, title, content, agentId, options)).path;
|
|
@@ -1,10 +1,91 @@
|
|
|
1
|
+
import { stat } from 'node:fs/promises';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { performance } from 'node:perf_hooks';
|
|
4
|
+
import { join } from 'node:path';
|
|
1
5
|
import { validateGraph, getBrokenLinks, getOrphanNodes, getVaultStats } from '../domain/graph-analysis.js';
|
|
2
|
-
import { ensureVault, readMarkdownFiles } from '../infrastructure/file-system-vault.js';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
import { ensureVault, listVaultFiles, readMarkdownFiles } from '../infrastructure/file-system-vault.js';
|
|
7
|
+
import { resolveAgentRuntimeDefaults } from '../infrastructure/config.js';
|
|
8
|
+
import { getGraphSummary } from './get-graph-summary.js';
|
|
9
|
+
import { buildContextPackage } from './build-context.js';
|
|
10
|
+
import { indexVault } from './index-vault.js';
|
|
11
|
+
import { searchKnowledge } from './search-knowledge.js';
|
|
12
|
+
import { loadBrainlinkConfig } from '../infrastructure/config.js';
|
|
13
|
+
export const getStats = async (vaultPath, agentId) => getVaultStats(await getGraphSummary(vaultPath, agentId));
|
|
14
|
+
export const getBrokenLinksReport = async (vaultPath, agentId) => getBrokenLinks(await getGraphSummary(vaultPath, agentId));
|
|
15
|
+
export const getOrphansReport = async (vaultPath, agentId) => getOrphanNodes(await getGraphSummary(vaultPath, agentId));
|
|
16
|
+
export const validateVault = async (vaultPath, agentId) => validateGraph(await getGraphSummary(vaultPath, agentId));
|
|
17
|
+
const toRatio = (part, total) => total === 0 ? 0 : Number((part / total).toFixed(4));
|
|
18
|
+
export const getExtendedStats = async (vaultPath, agentId) => {
|
|
19
|
+
const absoluteVaultPath = await ensureVault(vaultPath);
|
|
20
|
+
const graph = await getGraphSummary(absoluteVaultPath, agentId);
|
|
21
|
+
const stats = getVaultStats(graph);
|
|
22
|
+
const markdownFiles = await readMarkdownFiles(absoluteVaultPath);
|
|
23
|
+
const allFiles = await listVaultFiles(absoluteVaultPath);
|
|
24
|
+
const totalBytes = (await Promise.all(allFiles.map(async (filePath) => {
|
|
25
|
+
try {
|
|
26
|
+
return (await stat(filePath)).size;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
}))).reduce((sum, value) => sum + value, 0);
|
|
32
|
+
const updatedAt = markdownFiles
|
|
33
|
+
.map((file) => file.updatedAt.getTime())
|
|
34
|
+
.filter((time) => Number.isFinite(time))
|
|
35
|
+
.sort((left, right) => left - right);
|
|
36
|
+
const priorities = graph.edges.reduce((state, edge) => ({
|
|
37
|
+
...state,
|
|
38
|
+
[edge.priority]: state[edge.priority] + 1
|
|
39
|
+
}), {
|
|
40
|
+
low: 0,
|
|
41
|
+
normal: 0,
|
|
42
|
+
high: 0,
|
|
43
|
+
critical: 0
|
|
44
|
+
});
|
|
45
|
+
const config = await loadBrainlinkConfig();
|
|
46
|
+
const defaults = resolveAgentRuntimeDefaults(config, agentId);
|
|
47
|
+
const probeQuery = graph.nodes[0]?.title ?? 'architecture';
|
|
48
|
+
const indexStart = performance.now();
|
|
49
|
+
await indexVault(absoluteVaultPath);
|
|
50
|
+
const indexLatency = performance.now() - indexStart;
|
|
51
|
+
const searchStart = performance.now();
|
|
52
|
+
await searchKnowledge(absoluteVaultPath, probeQuery, Math.min(defaults.defaultSearchLimit, 8), agentId, 'hybrid');
|
|
53
|
+
const searchLatency = performance.now() - searchStart;
|
|
54
|
+
const contextStart = performance.now();
|
|
55
|
+
await buildContextPackage(absoluteVaultPath, probeQuery, Math.min(defaults.defaultSearchLimit, 8), defaults.defaultContextTokens, agentId, 'hybrid');
|
|
56
|
+
const contextLatency = performance.now() - contextStart;
|
|
57
|
+
return {
|
|
58
|
+
stats,
|
|
59
|
+
storage: {
|
|
60
|
+
markdownFileCount: markdownFiles.length,
|
|
61
|
+
totalFileCount: allFiles.length,
|
|
62
|
+
totalBytes,
|
|
63
|
+
averageMarkdownBytes: markdownFiles.length === 0
|
|
64
|
+
? 0
|
|
65
|
+
: Math.round(markdownFiles.reduce((sum, file) => sum + Buffer.byteLength(file.content, 'utf8'), 0) / markdownFiles.length),
|
|
66
|
+
...(updatedAt.length > 0
|
|
67
|
+
? {
|
|
68
|
+
oldestNoteUpdatedAt: new Date(updatedAt[0]).toISOString(),
|
|
69
|
+
newestNoteUpdatedAt: new Date(updatedAt[updatedAt.length - 1]).toISOString()
|
|
70
|
+
}
|
|
71
|
+
: {})
|
|
72
|
+
},
|
|
73
|
+
quality: {
|
|
74
|
+
resolvedLinkRatio: toRatio(stats.resolvedLinkCount, stats.linkCount),
|
|
75
|
+
brokenLinkRatio: toRatio(stats.brokenLinkCount, stats.linkCount),
|
|
76
|
+
orphanRatio: toRatio(stats.orphanCount, Math.max(stats.documentCount, 1)),
|
|
77
|
+
priorityDistribution: priorities
|
|
78
|
+
},
|
|
79
|
+
observability: {
|
|
80
|
+
probeQuery,
|
|
81
|
+
latenciesMs: {
|
|
82
|
+
index: Number(indexLatency.toFixed(2)),
|
|
83
|
+
search: Number(searchLatency.toFixed(2)),
|
|
84
|
+
context: Number(contextLatency.toFixed(2))
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
};
|
|
8
89
|
const createCheck = (name, ok, message) => ({
|
|
9
90
|
name,
|
|
10
91
|
ok,
|
|
@@ -13,16 +94,30 @@ const createCheck = (name, ok, message) => ({
|
|
|
13
94
|
export const doctorVault = async (vaultPath) => {
|
|
14
95
|
const absoluteVaultPath = await ensureVault(vaultPath);
|
|
15
96
|
const files = await readMarkdownFiles(absoluteVaultPath);
|
|
16
|
-
const graph = await
|
|
97
|
+
const graph = await getGraphSummary(absoluteVaultPath);
|
|
17
98
|
const validation = validateGraph(graph);
|
|
99
|
+
const backupPath = join(absoluteVaultPath, '.brainlink', 'brainlink.db.backup');
|
|
100
|
+
const hasBackup = existsSync(backupPath);
|
|
101
|
+
const backupReady = graph.nodes.length === 0 || hasBackup;
|
|
18
102
|
const checks = [
|
|
19
103
|
createCheck('vault', true, `Vault ready at ${absoluteVaultPath}`),
|
|
20
104
|
createCheck('markdown-files', files.length > 0, `${files.length} markdown files found`),
|
|
21
105
|
createCheck('index', graph.nodes.length > 0, `${graph.nodes.length} indexed documents found`),
|
|
22
|
-
createCheck('broken-links', validation.brokenLinks.length === 0, `${validation.brokenLinks.length} broken links found`)
|
|
106
|
+
createCheck('broken-links', validation.brokenLinks.length === 0, `${validation.brokenLinks.length} broken links found`),
|
|
107
|
+
createCheck('index-backup', backupReady, backupReady
|
|
108
|
+
? (hasBackup ? 'SQLite recovery snapshot is available' : 'No index yet. Snapshot will be created after first indexing run')
|
|
109
|
+
: 'Recovery snapshot missing. Run blink index to create a rollback snapshot')
|
|
23
110
|
];
|
|
111
|
+
const recommendations = files.length === 0 && graph.nodes.length === 0
|
|
112
|
+
? [
|
|
113
|
+
`Vault is empty. Add your first note: blink add "Architecture" --vault "${absoluteVaultPath}" --content "Markdown source of truth. #architecture"`,
|
|
114
|
+
`If this path is not the expected vault, inspect active config: blink config where`,
|
|
115
|
+
`If you changed vault recently, migrate existing memory: blink migrate-vault --from ~/.brainlink/vault --to "${absoluteVaultPath}"`
|
|
116
|
+
]
|
|
117
|
+
: [];
|
|
24
118
|
return {
|
|
25
119
|
ok: checks.every((check) => check.ok),
|
|
26
|
-
checks
|
|
120
|
+
checks,
|
|
121
|
+
...(recommendations.length > 0 ? { recommendations } : {})
|
|
27
122
|
};
|
|
28
123
|
};
|