@andespindola/brainlink 0.1.0-alpha.9 → 0.1.0-beta.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.
@@ -41,6 +41,10 @@ $HOME/.brainlink/vault
41
41
 
42
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.
43
43
 
44
+ 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.
45
+
46
+ `autoIndexOnWrite` (default: `true`) controls whether `add` and MCP write tools index right after writing.
47
+
44
48
  ## Agent Namespaces
45
49
 
46
50
  Each agent writes into a dedicated namespace under `agents/<agent-id>/`:
@@ -133,6 +137,7 @@ Rules:
133
137
 
134
138
  - Use a clear title.
135
139
  - Use `[[Note Title]]` for relationships.
140
+ - Put priority markers near links when the relationship is important.
136
141
  - Use tags for retrieval.
137
142
  - Keep each note focused.
138
143
  - Prefer summaries over raw transcripts.
@@ -144,13 +149,22 @@ Brainlink only builds graph edges from Markdown `[[wiki links]]`.
144
149
 
145
150
  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.
146
151
 
152
+ 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:
153
+
154
+ ```md
155
+ - [ ] Review [[Architecture]] priority: high
156
+ Related: [[Incident Runbook]] #critical
157
+ ```
158
+
159
+ Agents should use weighted graph output to sort relationships by importance. Edges expose `weight` and `priority`, where priority is one of `low`, `normal`, `high` or `critical`.
160
+
147
161
  Required write behavior:
148
162
 
149
163
  1. Choose a clear title for the new note.
150
164
  2. Look for an existing related concept with `search`, `links` or `backlinks`.
151
165
  3. Add at least one `[[Existing Note Title]]` link unless the note is intentionally a root concept.
152
166
  4. Add useful `#tags` for retrieval.
153
- 5. Run `index` after the write.
167
+ 5. `add` writes are indexed by default. Only batch with explicit `--no-auto-index`, then run `index` once.
154
168
  6. Run `validate`, `broken-links` or `orphans` when the graph should be connected.
155
169
 
156
170
  Good linked note:
@@ -159,7 +173,6 @@ Good linked note:
159
173
  blink add "SQLite Index Rebuild" \
160
174
  --agent coding-agent \
161
175
  --content "Legacy derived indexes without agent columns are rebuilt because SQLite is disposable. Related: [[Architecture]], [[Agent Namespaces]]. #sqlite #architecture #decision"
162
- blink index
163
176
  blink validate --agent coding-agent
164
177
  ```
165
178
 
@@ -196,6 +209,54 @@ If the context is empty or weak:
196
209
  3. Inspect links and backlinks.
197
210
  4. Only then answer from general reasoning.
198
211
 
212
+ ## Optimized Agent Workflow (1 to 7)
213
+
214
+ Use this exact loop for higher signal and lower noise:
215
+
216
+ 1. Read memory before decisions:
217
+ - `blink context "<task>" --agent "$BLINK_AGENT" --json`
218
+ - Add `--mode hybrid` for mixed retrieval.
219
+ 2. Keep vault structure deterministic:
220
+ - Keep shared knowledge in `agents/shared`.
221
+ - Keep private work-in-progress in your own agent namespace.
222
+ 3. Write durable notes only, with explicit links and tags:
223
+ - include at least one `[[...]]` link
224
+ - include `#tags` for retrieval
225
+ 4. Store only stable decisions and update an existing note when possible.
226
+ 5. Use cache-conscious read/refresh cycle:
227
+ - prefer targeted queries over broad dumps.
228
+ - avoid re-indexing unless note set changed.
229
+ 6. Run guardrails regularly:
230
+ - `npm run brainlink:sync -- --vault ./vault --agent "$BLINK_AGENT"`.
231
+ - the sync flow runs `index`, `stats`, `validate`, `broken-links`, `orphans` and a quick context probe.
232
+ 7. Before responding:
233
+ - cite sources from context output
234
+ - keep output anchored in retrieved references.
235
+
236
+ Templates are available in `docs/templates` for quick note creation.
237
+
238
+ Recommended template:
239
+
240
+ ```bash
241
+ cp docs/templates/agent-note-template.md /tmp/agent-note.md
242
+ ```
243
+
244
+ ### MCP Usage for the Optimized Flow
245
+
246
+ When using MCP, use this compact sequence for the same memory discipline:
247
+
248
+ 1. Bootstrap context:
249
+ - `brainlink_context` with `agent`, `query`, `mode: hybrid`, `limit`.
250
+ 2. Capture durable decisions:
251
+ - `brainlink_add_note` or `brainlink_add_file` with explicit `[[wiki links]]` and `#tags`.
252
+ 3. Run maintenance before handoff or before the next step:
253
+ - `brainlink_sync` with `agent`, `contextQuery`, `mode: hybrid`.
254
+ 4. Diagnose graph issues only when needed:
255
+ - `brainlink_validate`, `brainlink_broken_links`, `brainlink_orphans`.
256
+ 5. Inspect relationships:
257
+ - `brainlink_graph`.
258
+ 6. Use `brainlink_stats` for a quick health snapshot.
259
+
199
260
  ## Examples For Common Coding Agents
200
261
 
201
262
  These examples assume the agent can run shell commands in the user workspace.
@@ -286,8 +347,12 @@ $HOME/.brainlink/vault/
286
347
 
287
348
  ```bash
288
349
  blink add "Note Title" --vault ./vault --content "Markdown content"
350
+ blink add "Note Title" --vault ./vault --content-file ./notes.md
351
+ blink add "Note Title" --vault ./vault --content-file ./notes.md --no-auto-index
289
352
  ```
290
353
 
354
+ `--content` and `--content-file` are mutually exclusive. Use `--no-auto-index` if you want to defer indexing in batch operations.
355
+
291
356
  This creates a slugged Markdown file with frontmatter and a heading.
292
357
 
293
358
  The CLI blocks common secret patterns by default. Do not use `--allow-sensitive` unless the vault is intentionally protected.
@@ -456,6 +521,7 @@ Available MCP tools:
456
521
  - `brainlink_context`
457
522
  - `brainlink_search`
458
523
  - `brainlink_add_note`
524
+ - `brainlink_add_file`
459
525
  - `brainlink_index`
460
526
  - `brainlink_validate`
461
527
  - `brainlink_graph`
@@ -464,6 +530,8 @@ Available MCP tools:
464
530
 
465
531
  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:
466
532
 
533
+ `brainlink_graph` returns weighted edges. Agents should prefer higher `weight` and stronger `priority` when deciding which related notes matter most.
534
+
467
535
  ```bash
468
536
  export BRAINLINK_ALLOWED_VAULTS="/absolute/path/to/project-vault"
469
537
  ```
@@ -552,4 +620,5 @@ Weak retrieval usually means:
552
620
  - Local embeddings are deterministic and provider-free; remote embedding providers are not implemented yet.
553
621
  - MCP integration is available through the `brainlink-mcp` stdio server.
554
622
  - HTTP API is local and unauthenticated.
555
- - Watch mode depends on platform filesystem watcher behavior.
623
+ - Bucket vaults support S3-compatible `s3://bucket/prefix` URIs and use a local cache for SQLite indexes.
624
+ - Watch mode depends on platform filesystem watcher behavior and is only supported for local filesystem vaults.
@@ -105,13 +105,15 @@ Application code depends on domain rules and infrastructure interfaces.
105
105
  The infrastructure layer handles side effects:
106
106
 
107
107
  - reading Markdown files from disk
108
+ - mirroring S3-compatible bucket Markdown into a local cache
108
109
  - writing Markdown notes
109
110
  - creating `.brainlink`
110
111
  - writing and querying SQLite
111
112
  - running FTS, semantic and hybrid retrieval
112
113
  - narrowing semantic candidates through SQLite embedding buckets before cosine scoring
113
114
 
114
- SQLite is an index, not the canonical storage model.
115
+ SQLite is an index, not the canonical storage model. For bucket vaults, Markdown
116
+ objects in the bucket remain canonical and SQLite is still local derived data.
115
117
 
116
118
  ## Indexing Flow
117
119
 
@@ -216,6 +218,23 @@ source note -> target note
216
218
 
217
219
  The `backlinks` command queries indexed links pointing to a target title. With `--agent`, it only returns links from that namespace.
218
220
 
221
+ ## Weighted Links
222
+
223
+ Each indexed wiki link is stored as a graph edge with:
224
+
225
+ - `weight`: numeric relationship strength.
226
+ - `priority`: one of `low`, `normal`, `high` or `critical`.
227
+
228
+ The parser derives weight from repeated links, task-list context, heading context and priority markers on the same line as a wiki link. Examples:
229
+
230
+ ```md
231
+ Related: [[Architecture]]
232
+ - [ ] Review [[Architecture]] priority: high
233
+ Escalate [[Incident Runbook]] #critical
234
+ ```
235
+
236
+ Backlink and graph readers return those fields to CLI JSON, HTTP API and MCP clients. Backlink queries use the normalized `to_title_key` column instead of applying `lower(...)` at read time.
237
+
219
238
  ## Context Building
220
239
 
221
240
  `context` uses search results and selects one chunk per document while staying inside an estimated token budget.
@@ -240,6 +259,7 @@ Relevant content
240
259
  Permanent:
241
260
 
242
261
  - Markdown files
262
+ - S3-compatible Markdown objects when the vault is `s3://bucket/prefix`
243
263
  - optional Git history around the vault
244
264
 
245
265
  Canonical agent memory lives under:
@@ -251,6 +271,7 @@ vault/agents/<agent-id>/**/*.md
251
271
  Rebuildable:
252
272
 
253
273
  - `.brainlink/brainlink.db`
274
+ - `$BRAINLINK_HOME/bucket-cache`
254
275
  - FTS records
255
276
  - local embedding vectors
256
277
  - local embedding bucket index
package/docs/RELEASE.md CHANGED
@@ -32,7 +32,7 @@ blink context "release smoke" --vault ./tmp-vault --mode hybrid --json
32
32
  blink server --vault ./tmp-vault --host 127.0.0.1 --port 4321
33
33
  ```
34
34
 
35
- 9. Verify the server refuses accidental public binds:
35
+ 9. Verify the server refuses public binds:
36
36
 
37
37
  ```bash
38
38
  blink server --vault ./tmp-vault --host 0.0.0.0
@@ -0,0 +1,27 @@
1
+ # Namespace Bootstrap for New Agent
2
+
3
+ # <agent-id> Agent Notes
4
+
5
+ ## Purpose
6
+
7
+ - Scope:
8
+ - Owner:
9
+ - Active project contexts:
10
+
11
+ ## Core Notes
12
+
13
+ - [[Architecture]]
14
+ - [[Coding Conventions]]
15
+ - [[Runbook]]
16
+ - [[Decision Log]]
17
+ - [[Open Questions]]
18
+
19
+ ## Process
20
+
21
+ 1. Before task: context "<task>" --agent <agent-id> --json
22
+ 2. During task: document durable findings with explicit [[wiki links]]
23
+ 3. After task: add note + index + validation run
24
+
25
+ ## Tags
26
+
27
+ #agent #<agent-id> #process
@@ -0,0 +1,31 @@
1
+ # Agent Note Template
2
+
3
+ # <Title>
4
+
5
+ ## Context
6
+
7
+ - What was decided or discovered.
8
+ - Why this happened.
9
+ - Expected impact or expected behavior.
10
+
11
+ ## References
12
+
13
+ - [[Parent concept]]
14
+ - [[Related decision]]
15
+
16
+ ## Notes
17
+
18
+ #decision #<domain> #agent
19
+
20
+ ---
21
+
22
+ ## Changelog
23
+
24
+ - YYYY-MM-DD: created
25
+
26
+ ## Durability checklist
27
+
28
+ - The note has a clear title.
29
+ - It links to at least one existing note (unless this is a root concept).
30
+ - It has at least one `#tag`.
31
+ - The content is stable knowledge, not one-off chat or session noise.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andespindola/brainlink",
3
- "version": "0.1.0-alpha.9",
3
+ "version": "0.1.0-beta.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",
@@ -44,9 +44,11 @@
44
44
  },
45
45
  "scripts": {
46
46
  "clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
47
- "build": "npm run clean && tsc -p tsconfig.json",
47
+ "build": "npm run clean && npx --yes snyk test && tsc -p tsconfig.json",
48
48
  "dev": "tsx src/cli/main.ts",
49
49
  "dev:mcp": "tsx src/mcp/main.ts",
50
+ "brainlink:sync": "bash scripts/brainlink-sync.sh",
51
+ "security": "npx --yes snyk test",
50
52
  "test": "vitest run --config vitest.config.ts",
51
53
  "check": "npm run build && npm run test",
52
54
  "benchmark:large": "tsx src/benchmarks/large-vault.ts",
@@ -54,6 +56,7 @@
54
56
  "pack:smoke": "npm pack --dry-run"
55
57
  },
56
58
  "dependencies": {
59
+ "@aws-sdk/client-s3": "^3.1038.0",
57
60
  "@modelcontextprotocol/sdk": "^1.29.0",
58
61
  "better-sqlite3": "^12.9.0",
59
62
  "commander": "^14.0.2",