AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
docs(second-brain): publish the verified use case — story, exact reproduction, live contract harness, landing page
xerj-orgb77c7a9146ae
diff --git a/docs/usecases/second-brain/README.md b/docs/usecases/second-brain/README.mdnew file mode 100644index 000000000..58bc181d7--- /dev/null+++ b/docs/usecases/second-brain/README.md@@ -0,0 +1,220 @@+# Second brain: point one binary at your notes++`xerj brain <folder>` turns a folder of notes into a queryable, bi-temporal,+provenance-carrying knowledge graph — one command, one static binary, no graph+database, no LLM, no embedding service, no config. A console dashboard then+shows what your notes believe, and an MCP surface gives your agent the same+four verbs.++Everything below was run live against this repository's own `docs/` folder —+121 real files, 5.7 MB, including code, images, and config junk. Every number+and every JSON body in this document is captured output, not an illustration.+Where something was *not* measured, it says so.++**The positioning sentence, first:** XERJ does not understand your notes. It+makes the structure you already wrote queryable, timestamped, and+evidence-backed — deterministically. It is a search engine with a graph-shaped+index over its own documents. It is **not** a graph database and it is not a+brain: there is no query language, no shortest-path, no PageRank, and no+unbounded traversal — by design. Edges are ordinary documents; expansion is a+bounded, batched read (at most 2 hops per call).++---++## The three claims++1. **Every link shows its evidence.** A link is not an assertion, it is+ evidence: for authored links (wiki-links, markdown links, hrefs) the+ detector records the exact text that justified the link, with its byte+ offset. Structural links (files that sit together, sections in sequence)+ carry a generated rationale instead — and the UI labels those as+ rationales, never as quotes. Links with no evidence say so.+2. **Replayable at any moment.** Every link is bi-temporal: it has a+ believed-since moment and, if retired, a retired moment. Retired links are+ invalidated, never deleted. You can ask what the brain believed last+ Tuesday, and the retired link comes back — with its retirement visible.+3. **One binary, zero config.** `xerj brain <folder>` discovers the files,+ boots (or attaches to) the server, indexes, detects links, and prints the+ dashboard URL. Re-running the same command converges and adds nothing.++## The real run++```+$ xerj brain /home/claude/ai/xerj/docs+brain 'docs': 121 files (5 MB) under /home/claude/ai/xerj/docs+booted xerj server (pid 339338) — data: …/p5-brain/data+phase A: 7 datasets inferred, 14 junk/skipped files+phase B: indexing 106 files with 8 workers → http://localhost:9340+done in 0.5s — 7 datasets, 561 records live …+✓ your second brain is ready — 121 files, 364 links, 0.7s+ → http://localhost:9340/_xerj-console/#/second-brain?brain=docs+ agents: XERJ_URL=http://localhost:9340 xerj-mcp+```++0.7 s cold on this corpus. Exit code was 3 — the documented+"ready-with-junk" code, because 14 of the 121 files (images, binaries, one+YAML-frontmatter markdown file the sniffer misread — see the warts section)+were skipped rather than indexed. Re-running the same command attached to the+live server, converged in 0.14 s, exited 0, and created zero duplicate links.+Determinism and idempotence on real data, observed, not asserted.++## Claim 1, shown: every link shows its evidence++A live edge from the ego endpoint of one note in the docs brain+(`GET /_graph/docs/ego?node=<id>&include_nodes=true`):++```json+{+ "edge_id": "2b9e125d0a5ca4962fce942d6fd80a48",+ "src": "ca404d04d54db94a7d60f873cfabc8dc",+ "dst": "a640b6d0f75c3f1d405153dc6315b075",+ "type": "mdlink",+ "weight": 0.9,+ "hop": 1,+ "direction": "in",+ "valid_at": 1785165764150,+ "invalid_at": null,+ "created_at": 1785405638505,+ "detector": "mdlink@1",+ "confidence": 0.9,+ "evidence": {+ "quote": "Consistent with the [earlier run](wordpress-audit-with-xerj.md), and now with a",+ "source": "research/wordpress-authz-agentic-audit.md",+ "offset": 1568+ }+}+```++The quote was verified **byte-for-byte against the file on disk**: that exact+text exists verbatim in `research/wordpress-authz-agentic-audit.md`. The+offset is section-relative (byte offset within the section the link was found+in), which is what the contract mandates.++The honest fine print, which the UI also carries: the schema permits links+without evidence (a manually asserted link may carry none — the UI then says+"no evidence recorded — asserted, not detected"), and structural detectors+(`samedir@1`, `sequence@1`) emit rationales like *"a.md and b.md share+directory notes/"*, not text extracted from your notes. So the claim is+"every link shows its evidence", not "every link has a quote".++## Claim 2, shown: replayable at any moment++The full loop, run live, captured responses:++```+# 1. Assert a manual link+POST /_graph/docs/link → 201, edge_id 51a2a80c…++# 2. Retire it+DELETE /_graph/docs/link/51a2a80c… → {"invalidated":true,"invalid_at":1785405730710}++# 3. Ask now+GET /_graph/docs/ego?node=… → 0 edges, "not_shown": {"expired_excluded": 1}++# 4. Ask about the moment before the retirement+GET /_graph/docs/ego?node=…&as_of=<t_before_retire>+ → the link is BACK, with its quote,+ and its later invalid_at visible++# 5. Ask now, including retired links+GET /_graph/docs/ego?node=…&include_expired=true+ → the tombstone is present+```++Retired, never deleted, replayable. The ledger accounting stayed exact+through the whole session: 366 total belief intervals = 364 detected + 1+manual + 1 new interval from a re-assert; 364 live / 2 retired — and the CLI,+the HTTP API, and the MCP surface all reported the same numbers.++Note step 3: when links are excluded from an answer, the response *says so*+(`not_shown` accounting) instead of silently narrowing the world. Every list+endpoint carries this.++## The dashboard++`xerj brain` prints a console URL that opens the SECOND BRAIN dashboard: one+note in the center, inbound links left, outbound right, grouped by what+taught them, with a belief-time scrubber that narrates what changed between+then and now ("2 appeared · 1 retired between …"). Hovering a link floats up+its evidence; clicking pins the full paper trail.++The dashboard's language rule is binding: human-visible surfaces say *link /+believed since / retired / what taught this* — never `edge`, `src`, `dst`,+`valid_at`, `as_of`. Schema vocabulary appears in exactly one place, the+pinned paper trail, because that is the copy-for-your-agent surface.++Verification status, stated precisely: the dashboard's entire data contract+was executed against the live docs brain — the real data layer plus the real+render functions for all nine panels ran in Node, 47/47 checks passing,+including the retire-then-replay loop and the language rule on real rendered+output. What was **not** verified: real-browser pixel and interaction+behavior (drag, hover cards) in an actual browser. The rendering logic is+proven; the pixels are not.++## The agent surface++`xerj-mcp` (stdio, `XERJ_URL=http://localhost:9340 xerj-mcp`) exposes four+brain tools, proven live in this session: `xerj_brain_ego`,+`xerj_brain_link`, `xerj_brain_unlink`, `xerj_brain_overview`. A real+`xerj_brain_overview` call round-tripped with the correct live/retired counts+and `"contract": "xerj-second-brain/1"`. Because the whole pipeline is+deterministic — same folder in, byte-identical brain out — an agent can cite+it.++## Measured numbers (this corpus only)++| What | Measured |+| --- | --- |+| Corpus | 121 files, 5.7 MB (52 markdown + 69 code/image/config) |+| Links detected | 364 |+| Cold run | 0.7 s |+| Convergent re-run | 0.14 s, exit 0, zero duplicates |+| Data dir | 12 MB (~2.1× source — includes full document storage + graph index) |+| Test suites | graph_expand 5/5 · brain_cli 3/3 · autoindex 109/109 · console-api 76/76 · mcp 25/25 · engine lib 241/241 |+| ES-compat conformance gate | 1360 passed · 0 failed · 3 skipped, with the graph feature on the same server |++**Not measured:** token economics for agents, behavior at large corpus sizes+(nothing beyond the 5.7 MB corpus here and a 518 MB corpus in earlier+autoindex work, which did not exercise the graph), and any comparison against+other note tools. No such numbers are claimed.++## What this does NOT do++- **It does not understand your notes.** The detectors are structural and+ lexical: wiki-links, markdown links, hrefs, directory adjacency, section+ sequence. There is no semantic similarity, no entity extraction, no LLM in+ the loop. The node-store embedder is a lexical feature hash and the API+ says so verbatim (`"embedder": "lexical-feature-hash"`).+- **It is not a graph database.** No Cypher, no shortest-path, no+ variable-depth traversal. Expansion is capped at 2 hops per call; you+ iterate from the response's reachable set. The 400 you get for `hops > 2`+ tells you exactly this.+- **On a corpus without authored links, the brain is mostly sort order.**+ Directory-adjacency and sequence links dominate when there are no+ wiki/markdown links; the dashboard splits AUTHORED vs STRUCTURAL counts so+ this is visible instead of flattering.+- **Scale is unproven.** 121 files in 0.7 s is the measurement; behavior at+ 100k notes is not measured and not claimed.++## Known warts (real, observed, not blocking)++- **CLI progress-counter off-by-one:** on this corpus the phase-B progress+ line printed "365 edges (mdlink 84)" while the server truth — and the final+ summary — was 364 (mdlink 83). Suspected cause is a byte-identical+ duplicate-path alias producing two detections of one link; hypothesis, not+ root-caused.+- **YAML-frontmatter markdown can sniff as YAML:** one `SKILL.md` with+ frontmatter landed in junk/skipped instead of being indexed.+- **Stale resume journals can pollute links** after a wiped data dir;+ `--fresh` re-walks everything and is the mitigation.+- **Wikilink detection was not exercised on this corpus** (real docs use+ markdown links); it is covered by the demo-corpus run (30 wikilinks) and+ the autoindex test suite.+- One pre-existing red test in the tree+ (`reindex_pages_past_10k_via_keyset`, inherited from `main`) — unrelated to+ this feature, real, out of scope here.++## Reproduce it++Every step, exactly: [REPRODUCE.md](REPRODUCE.md).+The normative contract: [docs/design/SECOND_BRAIN_SPEC.md](../../design/SECOND_BRAIN_SPEC.md).diff --git a/docs/usecases/second-brain/REPRODUCE.md b/docs/usecases/second-brain/REPRODUCE.mdnew file mode 100644index 000000000..61289c8bf--- /dev/null+++ b/docs/usecases/second-brain/REPRODUCE.md@@ -0,0 +1,180 @@+# Reproduce the second-brain use case, exactly++Every command below was run on branch `feat/second-brain`. The corpus is this+repository's own `docs/` folder, so the whole thing reproduces from a clone.+Numbers (0.7 s, 364 links, …) are from one machine and one corpus; yours will+differ in the details, and the invariants (idempotence, evidence, replay)+should not.++Throughout, `$REPO` is the repository root and `$DATA` is a fresh, empty+directory for the brain's server data.++## 0. Build (scoped — never workspace-wide)++```sh+cd $REPO/engine+cargo build --release -j 32 -p xerj-engine -p xerj-api -p xerj-autoindex \+ -p xerj-console-api -p xerj-server -p xerj-mcp+```++## 1. Run the brain++```sh+DATA=$(mktemp -d)+$REPO/engine/target/release/xerj brain $REPO/docs \+ --url http://localhost:9340 --data-dir "$DATA" --no-open+```++Expected shape (values vary with the current state of `docs/`):++```+brain 'docs': 121 files (5 MB) under …/docs+booted xerj server (pid …) — data: …/data+phase A: 7 datasets inferred, 14 junk/skipped files+phase B: indexing 106 files with 8 workers → http://localhost:9340+✓ your second brain is ready — 121 files, 364 links, 0.7s+ → http://localhost:9340/_xerj-console/#/second-brain?brain=docs+```++Exit codes: `0` ready · `3` ready-with-junk (unreadable files recorded, never+fatal — expected on this corpus, which contains images and binaries) · `1`+nothing indexable / server failure · `2` usage.++**Idempotence check** — run the identical command again. It must attach to the+already-running server, converge fast (0.14 s here), exit `0`, and the link+count must not grow.++The booted server keeps its own admin key at `$DATA/admin.key`; every direct+HTTP call below needs it:++```sh+AUTH="Authorization: ApiKey $(cat "$DATA/admin.key")"+```++## 2. Claim 1 — evidence on every link++Pick a hub node from the overview, then ask for its neighborhood:++```sh+curl -s -H "$AUTH" 'http://localhost:9340/_graph/docs/overview' | python3 -m json.tool+# take an id from .hubs.in[0].id (call it $NODE)++curl -s -H "$AUTH" \+ "http://localhost:9340/_graph/docs/ego?node=$NODE&include_nodes=true" \+ | python3 -m json.tool+```++Verify one quote against the source file (this is the whole point):++```sh+# for an authored edge (detector mdlink@1 / wikilink@1 / href@1):+# evidence.quote must be verbatim text from evidence.source+grep -F "<paste evidence.quote here>" $REPO/docs/<evidence.source>+```++Notes on what you will see:+- `evidence.offset` is the byte offset **within the section** the link was+ found in, not within the whole file (contract §6.5).+- Structural edges (`samedir@1`, `sequence@1`) carry generated rationales+ ("a.md and b.md share directory …"), offset 0 — not extracted text.++## 3. Claim 2 — retire, then replay++```sh+# capture a moment before the retirement+T_BEFORE=$(date +%s%3N)++# assert a manual link (src/dst are node ids from step 2)+curl -s -H "$AUTH" -H 'content-type: application/json' \+ -X POST http://localhost:9340/_graph/docs/link \+ -d '{"src":"<id1>","dst":"<id2>","type":"manual"}'+# → 201 {"edge_id":"…", …}++# retire it+curl -s -H "$AUTH" -X DELETE http://localhost:9340/_graph/docs/link/<edge_id>+# → {"invalidated":true,"invalid_at":<ms>}++# now: the link is gone, and the response SAYS one link was excluded+curl -s -H "$AUTH" "http://localhost:9340/_graph/docs/ego?node=<id1>&types=manual"+# → 0 edges, "not_shown":{"expired_excluded":1,…}++# replay the moment before the retirement: the link comes back,+# with its later invalid_at visible+curl -s -H "$AUTH" \+ "http://localhost:9340/_graph/docs/ego?node=<id1>&types=manual&as_of=$T_BEFORE"++# or ask now with tombstones included+curl -s -H "$AUTH" \+ "http://localhost:9340/_graph/docs/ego?node=<id1>&types=manual&include_expired=true"+```++Also check that the 2-hop cap refuses honestly:++```sh+curl -s -H "$AUTH" "http://localhost:9340/_graph/docs/ego?node=<id1>&hops=3"+# → 400, "…not a graph database…"+```++## 4. The dashboard++Open `http://localhost:9340/_xerj-console/#/second-brain?brain=docs` in a+browser (the console handles its own login using the same bootstrap+credentials). What to look for: the ego ledger with links grouped by what+taught them, evidence on hover/click, the belief-time scrubber narrating+appeared/retired counts, and the AUTHORED vs STRUCTURAL split.++Automated equivalent (what our verification ran — the real data layer plus+the real renderers for all nine panels, in Node, against the live server;+47/47 checks; needs Node ≥ 20):++```sh+XERJ_URL=http://localhost:9340 XERJ_BRAIN=docs \+XERJ_ADMIN_KEY_FILE="$DATA/admin.key" \+ node $REPO/docs/usecases/second-brain/contract-check.mjs+```++Note: this proves the rendering logic and data contract, not real-browser+pixels/interactions — those were not machine-verified.++## 5. The agent surface (MCP)++```sh+XERJ_URL=http://localhost:9340 \+XERJ_AUTH="ApiKey $(cat "$DATA/admin.key")" \+ $REPO/engine/target/release/xerj-mcp+```++Then over stdio: `tools/list` must include `xerj_brain_ego`,+`xerj_brain_link`, `xerj_brain_unlink`, `xerj_brain_overview`; a+`tools/call` of `xerj_brain_overview` with `{"brain":"docs"}` must round-trip+with `"contract": "xerj-second-brain/1"` and edge counts that match step 2.++## 6. Test suites++```sh+cd $REPO/engine+cargo test --release -p xerj-engine --test graph_expand # 5+cargo test --release -p xerj-server --test brain_cli # 3+cargo test --release -p xerj-autoindex # 109+cargo test --release -p xerj-console-api # 76+cargo test --release -p xerj-mcp # 25+cargo test --release -p xerj-engine --lib # 241+cargo test --release -p xerj-api --lib # 84 pass, 1 fail+```++The one xerj-api failure (`reindex_pages_past_10k_via_keyset`) is+pre-existing on `main` (its commit is an ancestor of `main`) and unrelated to+the graph feature; it is listed so you are not surprised by it.++## 7. Cleanup++```sh+kill <server pid printed at boot> # or: pkill -f 'xerj.*9340'+rm -rf "$DATA"+```++## Environment used for the published numbers++Linux x86-64, release build, 121 files / 5.7 MB corpus, fresh data dir, port+9340. Token economics and large-corpus scaling were not measured; treat any+extrapolation as yours, not ours.diff --git a/docs/usecases/second-brain/contract-check.mjs b/docs/usecases/second-brain/contract-check.mjsnew file mode 100644index 000000000..cf18d0698--- /dev/null+++ b/docs/usecases/second-brain/contract-check.mjs@@ -0,0 +1,105 @@+// Second-brain live contract check: runs the REAL UX data layer+// (xerj-ux/src/data/second-brain-api.js) and the REAL panel renderers+// (xerj-ux/src/ux/ego-ledger.js) in Node against a LIVE brain server —+// field-for-field, whatever the dashboard dereferences must exist and behave.+//+// Usage (see REPRODUCE.md):+// XERJ_URL=http://localhost:9340 XERJ_BRAIN=docs \+// XERJ_ADMIN_KEY_FILE=$DATA/admin.key node contract-check.mjs+//+// This proves the rendering logic and the data contract. It does NOT prove+// real-browser pixels or pointer interactions.+import { readFileSync } from 'node:fs';++const BASE = process.env.XERJ_URL || 'http://localhost:9340';+const BRAIN = process.env.XERJ_BRAIN || 'docs';+const KEY = process.env.XERJ_ADMIN_KEY+ || (process.env.XERJ_ADMIN_KEY_FILE+ ? readFileSync(process.env.XERJ_ADMIN_KEY_FILE, 'utf8').trim()+ : null);++globalThis.location = { hash: `#/second-brain?brain=${BRAIN}` };+const rawFetch = globalThis.fetch;+globalThis.fetch = (url, opts = {}) =>+ rawFetch(url, {+ ...opts,+ headers: { ...(opts.headers || {}), ...(KEY ? { authorization: `ApiKey ${KEY}` } : {}) },+ });++const { liveSecondBrain } = await import(new URL('../../../xerj-ux/src/data/second-brain-api.js', import.meta.url));+const { renderPanelBody } = await import(new URL('../../../xerj-ux/src/ux/ego-ledger.js', import.meta.url));++let fails = 0;+const ok = (c, m) => { if (c) console.log(` ok ${m}`); else { fails++; console.log(` FAIL ${m}`); } };++let d = await liveSecondBrain(BASE, {}, undefined);+const live0 = d.overview.edges.live;+const inv0 = d.overview.edges.invalidated;+ok(d.sb.connected === true, 'connected to real brain server');+ok(d.brain === BRAIN, `brain discovered from -edges suffix = ${d.brain}`);+ok(Number.isInteger(d.overview.edges.total) && d.overview.edges.total > 0, `overview.edges.total = ${d.overview.edges.total}`);+ok(d.overview.embedder === 'lexical-feature-hash', 'embedder honesty marker present');+ok(typeof d.overview.nodes_index === 'string' && d.overview.nodes_index.length > 0, `nodes_index = ${String(d.overview.nodes_index).slice(0, 60)}…`);+ok(Array.isArray(d.overview.types) && d.overview.types.every((t) => 'type' in t && 'live' in t), 'types[] shape {type,live}');+ok(Array.isArray(d.overview.detectors) && d.overview.detectors.every((t) => 'detector' in t && 'live' in t), 'detectors[] shape {detector,live}');+ok(d.overview.hubs && Array.isArray(d.overview.hubs.in) && Array.isArray(d.overview.hubs.out), 'hubs.in/out arrays');+ok(Array.isArray(d.overview.created_over_time) && d.overview.created_over_time.every((b) => 't' in b && 'count' in b), 'created_over_time[] {t,count}');+ok(d.overview.not_shown && 'hubs_out_not_listed' in d.overview.not_shown, 'overview.not_shown accounting');+ok(d.sb.focus, `default focus chosen = ${d.sb.focus}`);+ok(d.ego && Array.isArray(d.ego.edges) && d.ego.edges.length > 0, `belief fetched (${d.ego && d.ego.edges && d.ego.edges.length} links)`);+const e0 = d.ego.edges[0];+for (const f of ['edge_id', 'src', 'dst', 'type', 'weight', 'hop', 'direction', 'valid_at', 'created_at', 'detector', 'confidence']) {+ ok(f in e0, `edge field present: ${f}`);+}+ok('invalid_at' in e0, 'edge field present: invalid_at (null when live)');+ok(d.ego.nodes && typeof d.ego.nodes === 'object', 'ego.nodes map present (include_nodes)');+const n0 = Object.values(d.ego.nodes)[0];+ok(n0 && 'title' in n0 && 'preview' in n0, 'node hydration fields {title,preview}');+ok(d.ego.not_shown && 'edges_clipped' in d.ego.not_shown && 'dangling_nodes' in d.ego.not_shown, 'ego.not_shown accounting');+ok(Array.isArray(d.ego.neighbors) && (d.ego.neighbors.length === 0 || ('via_edge' in d.ego.neighbors[0])), 'neighbors[] {id,hop,via_edge}');+ok(d.sb.timeline && d.sb.timeline.edges.length > 0, `timeline fetched (${d.sb.timeline && d.sb.timeline.edges.length} edges)`);+ok(Object.keys(d.sb.names).length > 0, `names hydrated (${Object.keys(d.sb.names).length})`);++const IDS = ['edgesLive', 'edgesTotal', 'invalidated', 'detectors', 'typeDist', 'edgeTimeline', 'ego', 'hubs', 'notShown'];+let all = '';+for (const id of IDS) {+ let html = '', threw = null;+ try { html = renderPanelBody(id, d); } catch (e) { threw = e; }+ ok(!threw && html.length > 0, `render ${id}${threw ? ` THREW ${threw.stack}` : ''}`);+ all += html;+}+ok(all.includes('recall is lexical (feature hashing) — not neural'), 'embedder note rendered');+ok(all.includes('data-sb-scrub'), 'scrubber rendered');+const banned = ['valid_at', 'as_of', 'edge_id'].filter((w) => {+ const visible = all.replace(/<[^>]*>/g, ' ').replace(/data-[a-z-]+="[^"]*"/g, ' ');+ return visible.includes(w);+});+ok(banned.length === 0, `LANGUAGE rule on real data (leaked: ${banned.join(',') || 'none'})`);++// retire a real link, replay before/after, then re-assert to converge back+const focus = d.sb.focus;+const anEdge = d.ego.edges.find((e) => e.hop === 1 && e.invalid_at == null);+const before = Date.now() - 5000;+const del = await fetch(`${BASE}/_graph/${BRAIN}/link/${anEdge.edge_id}`, { method: 'DELETE' });+const delBody = await del.json();+ok(del.ok && delBody.invalidated === true, `retired real link ${anEdge.edge_id.slice(0, 8)}… (${anEdge.detector})`);++globalThis.location.hash = `#/second-brain?brain=${BRAIN}&focus=${focus}&as_of=${before}`;+d = await liveSecondBrain(BASE, {}, undefined);+ok(d.overview.edges.live === live0, `time-travel: ${live0} believed before retirement (got ${d.overview.edges.live})`);++globalThis.location.hash = `#/second-brain?brain=${BRAIN}&focus=${focus}&as_of=${Date.now()}`;+d = await liveSecondBrain(BASE, {}, undefined);+ok(d.overview.edges.live === live0 - 1 && d.overview.edges.invalidated === inv0 + 1, `now: one fewer believed, one more retired (${d.overview.edges.live}/${d.overview.edges.invalidated})`);+ok(renderPanelBody('ego', d).includes('sb-expired'), 'retired link drawn struck-through');+ok(renderPanelBody('invalidated', d).includes('retired'), 'RETIRED panel shows churn');++const re = await fetch(`${BASE}/_graph/${BRAIN}/link`, {+ method: 'POST',+ headers: { 'content-type': 'application/json' },+ body: JSON.stringify({ src: anEdge.src, dst: anEdge.dst, type: anEdge.type, weight: anEdge.weight, detector: anEdge.detector, confidence: anEdge.confidence, evidence: anEdge.evidence }),+});+console.log(` info re-assert after retire: HTTP ${re.status}`);++console.log(fails === 0 ? '\nALL LIVE CONTRACT CHECKS PASSED' : `\n${fails} CHECK(S) FAILED`);+process.exit(fails ? 1 : 0);diff --git a/landing/use-cases/second-brain.html b/landing/use-cases/second-brain.htmlnew file mode 100644index 000000000..48fe56e75--- /dev/null+++ b/landing/use-cases/second-brain.html@@ -0,0 +1,278 @@+<!DOCTYPE html>+<html lang="en" data-theme="night">+<head>+<meta charset="UTF-8">+<meta name="viewport" content="width=device-width, initial-scale=1.0">+<title>XERJ.ai — One command turns a folder of notes into a second brain with receipts</title>+<meta name="description" content="xerj brain <folder> — one binary, zero config — turns a folder of notes into a queryable, bi-temporal, evidence-carrying knowledge graph. Every link shows the text that taught it; retired links are kept, never deleted, and any past moment is replayable. Measured live: 121 files to 364 links in 0.7 s. Not a graph database, no LLM — deterministic structure over your own documents. Sources in docs/usecases/second-brain.">+<meta property="og:title" content="XERJ.ai — One command turns a folder of notes into a second brain with receipts">+<meta property="og:description" content="Point one binary at your notes: every link shows its evidence, retired links are kept and replayable at any moment, and your agent gets the same four verbs over MCP. Measured on a real folder — 121 files to 364 links in 0.7 s. Deterministic, no graph DB, no LLM.">+<link rel="preconnect" href="https://fonts.googleapis.com">+<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>+<link href="https://fonts.googleapis.com/css2?family=Big+Shoulders+Display:wght@400;700;800;900&family=Inter:wght@400;500;600;700&family=IBM+Plex+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;700&display=swap" rel="stylesheet">+<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><rect width='100' height='100' fill='%230b0b0d'/><text x='50' y='68' font-size='60' font-family='Big Shoulders Display,sans-serif' font-weight='900' fill='%23ffc400' text-anchor='middle'>X</text></svg>">+<link rel="stylesheet" href="/style.css?v=sc0706">+</head>+<body>++<!-- nav -->+<nav class="nav" aria-label="Primary">+ <a href="/index.html" class="brand">XERJ.AI</a>+ <a href="/index.html">HOME</a>+ <a href="/product.html">PRODUCT</a>+ <span class="nav-drop active">+ <a href="/use-cases.html" class="active">USE CASES</a>+ </span>+ <a href="/case-studies.html">CASE STUDIES</a>+ <span class="spacer"></span>+ <a href="/for-agents.html">FOR AGENTS</a>+ <a href="/docs/index.html">DOCS</a>+ <a href="/docs/recipes/index.html">RECIPES</a>+ <a href="/playground.html">DASHBOARDS</a>+ <a href="https://github.com/xerj-org/xerj" rel="external">GITHUB</a>+ <span class="theme">+ <button type="button" data-theme="day">DAY</button>+ <span class="dash">·</span>+ <button type="button" data-theme="night" class="active">NIGHT</button>+ </span>+</nav>+++<nav class="uc-subnav" aria-label="Use cases">+ <a href="/use-cases.html">ALL USE CASES</a>+ <a href="/use-cases/security-analytics.html">SECURITY ANALYTICS</a>+ <a href="/use-cases/operational-intelligence.html">OPERATIONAL INTELLIGENCE</a>+ <a href="/use-cases/ai-search-retrieval.html">AI SEARCH</a>+ <a href="/use-cases/semantic-analytics.html">SEMANTIC ANALYTICS</a>+ <a href="/use-cases/code-security-audit.html">AI SECURITY REVIEW</a>+ <a href="/use-cases/elasticsearch-replacement.html">ES REPLACEMENT</a>+ <a href="/use-cases/unified-observability.html">OBSERVABILITY</a>+</nav>++<div class="uc-hero">+ <div class="uc-eyebrow">USE CASE · SECOND BRAIN</div>+ <h1>POINT IT AT A FOLDER.<br>EVERY LINK SHOWS ITS EVIDENCE.<br><span class="accent">REPLAY ANY MOMENT.</span></h1>+ <p class="uc-lead">One command — <code class="inline">xerj brain ~/notes</code> — and a folder of notes becomes a queryable, timestamped, evidence-carrying knowledge graph. No graph database, no ETL, no LLM, no embedding service, no config file. Two questions no note tool answers become one HTTP call each: <em>why does this link exist</em> — every link carries the exact text that taught it, verified byte-for-byte against the file on disk — and <em>what did my notes believe last Tuesday</em> — retired links are kept, never deleted, and any past moment is replayable. Be clear about what this is: XERJ does not understand your notes. It makes the structure you already wrote queryable, timestamped, and evidence-backed — deterministically. Same folder in, byte-identical brain out, which is exactly why an agent can cite it. The proof run below is real and unstaged: this repository's own docs folder — 121 files, 5.7 MB, images and config junk included — to 364 links in 0.7 s.</p>+ <div class="kicker"><span>FOR</span><span class="dash">·</span><span>AI AGENTS</span><span class="dash">·</span><span>NOTE-TAKERS</span><span class="dash">·</span><span>LOCAL-FIRST BUILDERS</span></div>+</div>++<div class="proof-row">++ <div class="stat">+ <div class="num">0.7 s</div>+ <div class="label">FOLDER → QUERYABLE BRAIN</div>+ <div class="ctx">121 real files · 5.7 MB · 364 links · re-run converges in 0.14 s with zero duplicates</div>+ </div>++ <div class="stat">+ <div class="num">364</div>+ <div class="label">LINKS, EACH WITH ITS EVIDENCE</div>+ <div class="ctx">authored links carry the verbatim quote + byte offset · structural links carry a labeled rationale · absence is shown, never papered over</div>+ </div>++ <div class="stat">+ <div class="num">0</div>+ <div class="label">LINKS EVER DELETED</div>+ <div class="ctx">retired links are invalidated, kept, and replayable · excluded links are counted in every response</div>+ </div>++</div>+++<section class="scene-section">+ <h2 class="scene" style="font-size:var(--fs-56);">ONE COMMAND. <span class="accent">CAPTURED, NOT STAGED.</span></h2>+ <p class="wide">The terminal output below is from the verification run, verbatim — the corpus is the XERJ repository's own docs folder, junk included. Fourteen files (images, binaries, one frontmatter file the sniffer misread — documented in the sources) were skipped and <em>said so</em>: exit code 3 is the documented "ready with junk" state, never a silent success.</p>+ <pre class="code">$ xerj brain /home/claude/ai/xerj/docs+brain 'docs': 121 files (5 MB) under /home/claude/ai/xerj/docs+booted xerj server (pid 339338) — data: …/brain/data+phase A: 7 datasets inferred, 14 junk/skipped files+phase B: indexing 106 files with 8 workers → http://localhost:9340+✓ your second brain is ready — 121 files, 364 links, 0.7s+ → http://localhost:9340/_xerj-console/#/second-brain?brain=docs+ agents: XERJ_URL=http://localhost:9340 xerj-mcp+<span class="comment"># run it again: attaches to the live server, converges in 0.14s, exit 0,+# zero duplicate links — determinism observed on real data, not asserted</span></pre>+</section>++<div class="pain-solve">+ <div class="pain">+ <h3>THE NOTE-GRAVEYARD PROBLEM</h3>+ <ul><li><strong>Your links are assertions, not evidence.</strong> A graph view shows that two notes connect; it cannot show you the sentence that connected them, so you re-read both notes to remember why.</li><li><strong>Deleting a link destroys history.</strong> Every note tool treats the graph as "now" — there is no way to ask what your notes believed before last month's reorganization.</li><li><strong>The tools that can answer these questions cost a stack.</strong> Temporal knowledge graphs for agents ship as a graph database plus an LLM extraction pipeline plus an embedding service.</li><li><strong>LLM-extracted graphs are non-reproducible.</strong> Run the extraction twice, get two different graphs — an agent cannot cite what it cannot re-derive.</li><li><strong>Hairball graph views don't answer questions.</strong> A global force-directed layout of a thousand notes is decoration, not an interface.</li></ul>+ </div>+ <div class="solve">+ <h3>THE XERJ ANSWER</h3>+ <ul><li><strong>Links are evidence.</strong> Six deterministic detectors (wiki-links, markdown links, hrefs, directory adjacency, section sequence, end-to-end) record what taught each link — authored links carry the verbatim quote and byte offset from your note.</li><li><strong>Retired, never deleted.</strong> Every link is bi-temporal — believed-since, and retired-at if retired. Ask about any past moment and the retired link comes back, retirement visible.</li><li><strong>One static binary.</strong> Discovery, indexing, link detection, HTTP API, dashboard, and MCP surface — <code class="inline">xerj brain <folder></code>, nothing else to install or configure.</li><li><strong>Deterministic, so citable.</strong> Same folder in, byte-identical brain out; re-runs converge instead of accreting. An agent can quote the brain and the quote traces to a file and an offset.</li><li><strong>A ledger, not a hairball.</strong> One note in the center, inbound links left, outbound right, grouped by what taught them, with a belief-time scrubber — every answer is a bounded list with honest "not shown" accounting.</li></ul>+ </div>+</div>+++<section class="scene-section">+ <h2 class="scene" style="font-size:var(--fs-56);">WHY DOES THIS LINK EXIST? <span class="accent">HERE IS THE SENTENCE.</span></h2>+ <p class="wide">A live link from the proof run, as the API returns it. The quote was checked byte-for-byte against the source file on disk — that exact text exists at that place in that note. This JSON is the paper trail, and it is the one surface where the raw schema shows; everywhere a human reads, the words are <em>link, believed since, retired, what taught this</em>.</p>+ <pre class="code">$ curl "localhost:9340/_graph/docs/ego?node=$NODE&include_nodes=true"+{+ "type": "mdlink",+ "detector": "mdlink@1",+ "confidence": 0.9,+ "direction": "in",+ "valid_at": 1785165764150, <span class="comment"># believed since</span>+ "invalid_at": null, <span class="comment"># never retired</span>+ "evidence": {+ "quote": "Consistent with the [earlier run](wordpress-audit-with-xerj.md), and now with a",+ "source": "research/wordpress-authz-agentic-audit.md",+ "offset": 1568 <span class="comment"># byte offset in the section — verified verbatim on disk</span>+ }+}</pre>+ <p class="wide">The honest fine print, which the dashboard also carries: structural links — files that sit together, sections in sequence — carry a generated <em>rationale</em> ("these files sit together in notes/"), labeled as one and never presented as text from your note. A manually asserted link may carry no evidence at all, and then the row says <em>no evidence recorded — asserted, not detected</em>. The claim is "every link shows its evidence" — not "every link has a quote".</p>+</section>+++<section class="scene-section">+ <h2 class="scene" style="font-size:var(--fs-56);">WHAT DID MY NOTES BELIEVE <span class="accent">LAST TUESDAY?</span></h2>+ <p class="wide">The full loop, run live during verification — assert, retire, replay. Note the third call: when links are excluded from an answer, the response counts them instead of silently narrowing the world.</p>+ <pre class="code"><span class="comment"># assert a link</span>+$ curl -X POST localhost:9340/_graph/docs/link -d '{"src":"…","dst":"…","type":"manual"}'+→ 201 · edge_id 51a2a80c…++<span class="comment"># retire it — invalidated, not deleted</span>+$ curl -X DELETE localhost:9340/_graph/docs/link/51a2a80c…+→ {"invalidated": true, "invalid_at": 1785405730710}++<span class="comment"># ask NOW: gone — and the response says one link was excluded</span>+$ curl "…/ego?node=…"+→ 0 links · "not_shown": {"expired_excluded": 1}++<span class="comment"># replay the moment before the retirement: the link is BACK,+# with its quote, and its later retirement visible</span>+$ curl "…/ego?node=…&as_of=$T_BEFORE_RETIRE"</pre>+ <p class="wide">The dashboard makes the same loop physical: a belief-time scrubber that narrates what changed — "2 appeared · 1 retired between then and this moment" — with retired links drawn struck-through, and a URL that pins a brain, a note, and a moment, so a link you share is a <em>belief state</em>, not just a page. Through the whole verification session the ledger stayed exact: 364 detected + 2 asserted belief intervals, 364 live / 2 retired — and the CLI, the HTTP API, and the MCP surface all reported the same numbers.</p>+</section>+++<section class="scene-section">+ <h2 class="scene" style="font-size:var(--fs-56);">THE BUYER WHO CARES MOST <span class="accent">IS AN AGENT.</span></h2>+ <p class="wide">Neighborhood-plus-moment-plus-evidence is what temporal-knowledge-graph stacks for agents charge a graph-database-plus-LLM pipeline for. XERJ ships it in one static binary, over MCP: four verbs — <code class="inline">xerj_brain_ego</code>, <code class="inline">xerj_brain_link</code>, <code class="inline">xerj_brain_unlink</code>, <code class="inline">xerj_brain_overview</code> — proven live in the verification run, round-tripping real counts under <code class="inline">contract: xerj-second-brain/1</code>. And because detection is deterministic, the agent's citations are re-derivable: the quote in the answer traces to a file and a byte offset that will be there tomorrow.</p>+ <pre class="code">$ XERJ_URL=http://localhost:9340 xerj-mcp+<span class="comment"># tools/list → …, xerj_brain_ego, xerj_brain_link, xerj_brain_unlink, xerj_brain_overview+# every brain answer carries not_shown accounting — the agent knows what it wasn't shown</span></pre>+</section>+++<section class="scene-section">+ <h2 class="scene" style="font-size:var(--fs-56);">WHAT IT <span class="accent">DOES NOT DO.</span></h2>+ <p class="wide">A use case is only worth publishing with its limits attached. These are the four that matter, stated the way the sources state them.</p>+ <div class="laws">+ <div class="n">01</div>+ <div class="law">+ <div class="t">IT DOES NOT <span class="accent">UNDERSTAND YOUR NOTES.</span></div>+ <div class="b">+ The detectors are structural and lexical — wiki-links, markdown links, hrefs,+ directory adjacency, section sequence. No semantic similarity, no entity+ extraction, no LLM anywhere in the loop, and the node store's recall is+ lexical feature hashing, which the API declares verbatim+ (<code class="inline">"embedder": "lexical-feature-hash"</code>). What you get is+ the structure you already wrote, made queryable — nothing more is claimed.+ </div>+ </div>++ <div class="n">02</div>+ <div class="law">+ <div class="t">IT IS NOT A <span class="accent">GRAPH DATABASE.</span></div>+ <div class="b">+ No Cypher, no shortest-path, no PageRank, no unbounded traversal — by design.+ Links are ordinary documents in a search engine; expansion is a bounded,+ batched read capped at 2 hops per call, and asking for more returns a 400+ that says exactly this. You iterate from the response's reachable set.+ </div>+ </div>++ <div class="n">03</div>+ <div class="law">+ <div class="t">WITHOUT AUTHORED LINKS, THE BRAIN IS <span class="accent">MOSTLY SORT ORDER.</span></div>+ <div class="b">+ On a folder with no wiki-links or markdown links, directory-adjacency and+ sequence links dominate — structure XERJ inferred from file layout, not+ structure you wrote. The dashboard splits AUTHORED from STRUCTURAL counts+ so this is visible instead of flattering: "0 authored · 214 structural" is+ an honest description of such a corpus, and the dashboard will say it.+ </div>+ </div>++ <div class="n">04</div>+ <div class="law">+ <div class="t">SCALE AND TOKENS: <span class="accent">NOT MEASURED.</span></div>+ <div class="b">+ The published numbers are one corpus: 121 files, 5.7 MB, 364 links, 0.7 s,+ 12 MB on disk (~2.1× source). Behavior at 100k notes is not measured and not+ claimed; token economics for agents were not measured; no head-to-head+ against other note tools was run. Two small observed defects ship with the+ sources rather than hidden: a CLI progress line once over-counted by one+ (the final summary and the server agreed), and one markdown file with YAML+ frontmatter was misclassified as YAML and skipped.+ </div>+ </div>+ </div>+</section>+++<section class="scene-section">+ <h2 class="scene" style="font-size:var(--fs-56);">READ THE <span class="accent">SOURCES.</span></h2>+ <p class="wide">Everything above is published: the captured run, the verified API responses, the full reproduction recipe down to exit codes and the auth header, and the live contract-check harness that exercises the real dashboard code against a real brain. Setup is one build and one command.</p>+ <div style="display:flex; gap:var(--sp-6); margin-top:var(--sp-6); flex-wrap:wrap;">+ <a href="https://github.com/xerj-org/xerj/tree/main/docs/usecases/second-brain" rel="external" class="cta" style="font-size:var(--fs-20); padding:var(--sp-4) 0; border-bottom:0; flex:1; min-width:280px;">+ <span>OPEN THE USE CASE</span>+ <span class="arrow">→</span>+ </a>+ <a href="https://github.com/xerj-org/xerj/blob/main/docs/usecases/second-brain/REPRODUCE.md" rel="external" class="cta" style="font-size:var(--fs-20); padding:var(--sp-4) 0; border-bottom:0; flex:1; min-width:280px;">+ <span>REPRODUCE IT</span>+ <span class="arrow">→</span>+ </a>+ </div>+</section>++<section class="lead-capture" id="demo">+ <div class="kicker"><span>READY?</span><span class="dash">·</span><span>REQUEST ACCESS</span></div>+ <h3>RUN IT ON<br><span class="accent">YOUR NOTES.</span></h3>+ <p>Tell us what your notes look like — the folder shape, the link styles you actually use, the moment you wish you could replay. We'll come back with what the detectors will and won't find there, honestly.</p>+ <form class="lead-form" id="leadForm" action="#" method="post" novalidate>+ <input type="email" name="email" placeholder="[email protected]" required aria-label="Work email" autocomplete="email" />+ <button type="submit" class="demo">SEE THE DEMO <span class="arrow">→</span></button>+ <span class="note">We only use this email to follow up about XERJ — nothing else. No spam, no reselling.</span>+ <span class="ok">✓ THANKS. WE'LL FOLLOW UP WITHIN ONE BUSINESS DAY.</span>+ </form>+</section>++<footer class="footer">+ <span>XERJ.AI · USE CASES · V0.1</span>+ <span>STORAGE FOR THE AGENT ERA</span>+ <span><a href="/index.html">HOME</a> · <a href="/use-cases.html">ALL USE CASES</a> · <a href="/docs/index.html">DOCS</a> · <a href="/playground.html">DASHBOARDS</a> · <a href="/llms.txt">LLMS.TXT</a></span>+</footer>++<script>+ (function () {+ const root = document.documentElement;+ for (const btn of document.querySelectorAll('[data-theme]')) {+ btn.addEventListener('click', () => {+ const t = btn.getAttribute('data-theme');+ root.setAttribute('data-theme', t);+ for (const b of document.querySelectorAll('[data-theme]')) {+ b.classList.toggle('active', b.getAttribute('data-theme') === t);+ }+ });+ }+ const form = document.getElementById('leadForm');+ if (form) {+ form.addEventListener('submit', (e) => {+ e.preventDefault();+ const email = form.querySelector('input[type=email]').value.trim();+ if (!email || !email.includes('@')) return;+ console.log('[xerj lead]', email);+ try { fetch('/lead', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ email: email, source: 'second-brain' }), keepalive: true }).catch(function () {}); } catch (_) {}+ form.classList.add('sent');+ });+ }+ })();+</script>++</body>+</html>