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
ci(usecases): gate the second-brain, MCP and autoindex harnesses
xerj-org419672690055
diff --git a/.github/scripts/installer-lint.sh b/.github/scripts/installer-lint.shnew file mode 100755index 000000000..bd65fe7e4--- /dev/null+++ b/.github/scripts/installer-lint.sh@@ -0,0 +1,76 @@+#!/usr/bin/env bash+# Syntax gate for the two install scripts served from xerj.org — `curl | sh`+# and `irm | iex` are the first thing a new user runs, so a parse error there+# is a broken front door that no other job would catch (neither file is Rust,+# neither is executed by any test).+#+# Deliberately cheap and tool-optional: the parse checks below are the floor+# and always run; shellcheck (POSIX sh) and pwsh (PowerShell AST) sharpen them+# when the runner happens to have them, and are skipped — never failed — when+# it does not.+set -uo pipefail++HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"+REPO="$(cd "$HERE/../.." && pwd)"+SH="$REPO/landing/get"+PS="$REPO/landing/get.ps1"+ERR="$(mktemp)"+trap 'rm -f "$ERR"' EXIT++FAIL=0+note() { echo " $*"; }+bad() { echo "::error::$*"; FAIL=1; }++echo "── installer lint ──"++for f in "$SH" "$PS"; do+ [ -f "$f" ] || bad "installer missing: $f"+done+[ "$FAIL" = 0 ] || exit 1++# ── landing/get — POSIX sh ────────────────────────────────────────────────+if sh -n "$SH" 2>"$ERR"; then+ note "PASS: sh -n landing/get"+else+ bad "landing/get is not valid POSIX sh"+ sed 's/^/ /' "$ERR"+fi++# The script is piped into `sh`, so a bashism that a bash-as-sh runner happily+# accepts still breaks users on dash/ash. Those are SC3xxx, reported at warning+# severity — hence -S warning rather than errors-only. Style notes stay advisory.+if command -v shellcheck >/dev/null 2>&1; then+ if shellcheck -s sh -S warning "$SH"; then+ note "PASS: shellcheck -s sh (warnings and up)"+ else+ bad "shellcheck reported errors in landing/get"+ fi+else+ note "SKIP: shellcheck not installed"+fi++# ── landing/get.ps1 — PowerShell ──────────────────────────────────────────+# The path travels in the environment: `pwsh -Command` appends trailing argv+# to the command text rather than binding it to $args.+if command -v pwsh >/dev/null 2>&1; then+ if XERJ_PS_FILE="$PS" pwsh -NoProfile -NonInteractive -Command '+ $errors = $null+ [void][System.Management.Automation.Language.Parser]::ParseFile(+ $env:XERJ_PS_FILE, [ref]$null, [ref]$errors)+ if ($errors.Count -gt 0) { $errors | ForEach-Object { $_.ToString() }; exit 1 }+ exit 0'; then+ note "PASS: PowerShell parser accepts landing/get.ps1"+ else+ bad "landing/get.ps1 has PowerShell parse errors"+ fi+else+ note "SKIP: pwsh not installed"+fi++echo "──"+if [ "$FAIL" = 0 ]; then+ echo "INSTALLER LINT PASSED"+else+ echo "INSTALLER LINT FAILED"+ exit 1+fidiff --git a/.github/scripts/usecase-smoke.sh b/.github/scripts/usecase-smoke.shnew file mode 100755index 000000000..0e557662e--- /dev/null+++ b/.github/scripts/usecase-smoke.sh@@ -0,0 +1,180 @@+#!/usr/bin/env bash+# CI gate for the use-case harnesses under demo/usecases/.+#+# Those harnesses are the only executable proof that the shipped use cases+# still work — the brain HTTP surface, the MCP tool surface an agent sees, and+# autoindex's zero-config discovery. Until this script existed every one of+# them was run by hand, so a regression in any of the three was caught by+# nothing.+#+# It drives the EXISTING harnesses rather than restating them: gen-corpus.sh →+# boot-and-brain.sh → transcript.sh → mcp-smoke.sh, then run-eval.sh over a+# small generated corpus plus a search round-trip. Everything they need is+# passed as an env override, so this stays free of machine-specific paths.+#+# Deliberately self-contained: no browser, no model, no network, nothing+# outside the repo — only the release binaries, curl and jq.+#+# Env overrides:+# XERJ_BIN xerj binary (default <repo>/engine/target/release/xerj)+# XERJ_MCP_BIN xerj-mcp binary (default <repo>/engine/target/release/xerj-mcp)+# XERJ_USECASE_ROOT scratch root (default a fresh mktemp -d)+# XERJ_BRAIN_DEMO_PORT brain es-compat (default 9331; also takes +1/+2)+# XERJ_AUTOINDEX_PORT autoindex es-compat(default 9341; also takes +100/+101)+set -uo pipefail++HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"+REPO="$(cd "$HERE/../.." && pwd)"+SB="$REPO/demo/usecases/second-brain"++XERJ_BIN="${XERJ_BIN:-$REPO/engine/target/release/xerj}"+XERJ_MCP_BIN="${XERJ_MCP_BIN:-$REPO/engine/target/release/xerj-mcp}"+[ -f "$XERJ_BIN.exe" ] && XERJ_BIN="$XERJ_BIN.exe"+[ -f "$XERJ_MCP_BIN.exe" ] && XERJ_MCP_BIN="$XERJ_MCP_BIN.exe"++ROOT="${XERJ_USECASE_ROOT:-$(mktemp -d)}"+BRAIN_PORT="${XERJ_BRAIN_DEMO_PORT:-9331}"+AX_PORT="${XERJ_AUTOINDEX_PORT:-9341}"+BRAIN_ROOT="$ROOT/second-brain"+AX_WORK="$ROOT/autoindex"+AX_URL="http://localhost:$AX_PORT"+mkdir -p "$BRAIN_ROOT" "$AX_WORK"++FAILED=0+phase() { echo; echo "════ $* ════"; }+bad() { echo "::error::$*"; FAILED=$((FAILED + 1)); }+ok() { echo " PASS: $*"; }++# The brain server is spawned detached by `xerj brain` and outlives that+# command by design, so it must be stopped explicitly however we exit.+cleanup() {+ for pidfile in "$BRAIN_ROOT/data/server.pid" "$AX_WORK/server.pid"; do+ [ -s "$pidfile" ] && kill "$(cat "$pidfile")" 2>/dev/null+ done+ return 0+}+trap cleanup EXIT++# ── 0. preflight ──────────────────────────────────────────────────────────+phase "0. preflight"+for tool in curl jq; do+ command -v "$tool" >/dev/null 2>&1 \+ || { echo "::error::$tool is required by the use-case harnesses but is not installed"; exit 1; }+done++# Use the release binaries the job already built; build only the missing+# package if this is being run from a bare checkout.+build_if_missing() {+ local bin="$1" pkg="$2"+ [ -x "$bin" ] && return 0+ echo " $pkg not built at $bin — building it"+ command -v cargo >/dev/null 2>&1 \+ || { echo "::error::$bin is missing and cargo is not available to build $pkg"; exit 1; }+ (cd "$REPO/engine" && cargo build --release -p "$pkg") \+ || { echo "::error::failed to build $pkg"; exit 1; }+}+build_if_missing "$XERJ_BIN" xerj-server+build_if_missing "$XERJ_MCP_BIN" xerj-mcp+echo " xerj: $XERJ_BIN ($("$XERJ_BIN" --version 2>/dev/null | head -1))"+echo " xerj-mcp: $XERJ_MCP_BIN"+echo " scratch: $ROOT"++export XERJ_BIN XERJ_MCP_BIN++# ── 1. second brain: pinned corpus → live brain → API transcript ──────────+phase "1. second brain (corpus, boot, transcript)"+export XERJ_BRAIN_DEMO_ROOT="$BRAIN_ROOT"+export XERJ_BRAIN_DEMO_PORT="$BRAIN_PORT"++if bash "$SB/boot-and-brain.sh"; then+ ok "brain booted and indexed the pinned demo vault"+else+ bad "boot-and-brain.sh failed — no brain to assert against"+ tail -40 "$BRAIN_ROOT/data/server.log" 2>/dev/null+ echo "USE-CASE SMOKE FAILED"+ exit 1+fi++# overview/ego/link/unlink/as_of replay + the normative 400/404s.+if bash "$SB/transcript.sh"; then+ ok "second-brain API transcript"+else+ bad "second-brain API transcript failed (see the FAIL lines above)"+fi++# ── 2. the agent surface: MCP tools listed and callable ───────────────────+phase "2. MCP tool surface"+if bash "$SB/mcp-smoke.sh"; then+ ok "MCP tools listed and tools/call round-tripped"+else+ bad "MCP smoke failed (see the FAIL lines above)"+fi++# ── 3. autoindex: zero-config discovery, then find a value by search ──────+phase "3. autoindex discovery + query"+CORPUS="$AX_WORK/corpus"+mkdir -p "$CORPUS/orders" "$CORPUS/logs" "$CORPUS/people"+# Three shapes, three inferred datasets. The tokens are nonsense words so a+# hit can only come from THIS corpus having been discovered, parsed and made+# searchable — never from anything else on the runner.+cat > "$CORPUS/orders/orders.csv" <<'EOF'+order_id,customer,amount,placed_at+1,zanzibarite,42.50,2026-01-04+2,quovadium,17.25,2026-01-05+3,zanzibarite,99.00,2026-01-06+EOF+cat > "$CORPUS/people/people.jsonl" <<'EOF'+{"person_id":1,"name":"quovadium","city":"lisbon","role":"buyer"}+{"person_id":2,"name":"zanzibarite","city":"porto","role":"buyer"}+EOF+cat > "$CORPUS/logs/app.log" <<'EOF'+2026-01-04T10:00:00Z INFO checkout completed for zanzibarite+2026-01-04T10:00:01Z WARN retry scheduled for quovadium+2026-01-04T10:00:02Z ERROR payment declined for quovadium+EOF++export XERJ_AUTOINDEX_WORK="$AX_WORK" XERJ_AUTOINDEX_PORT="$AX_PORT"+if bash "$REPO/demo/usecases/autoindex/run-eval.sh" "$CORPUS" "$XERJ_BIN"; then+ ok "autoindex discovered the corpus and re-ran idempotently"+else+ bad "autoindex eval failed (discovery or idempotency)"+ tail -40 "$AX_WORK/server-$AX_PORT.log" 2>/dev/null+fi++curl -s -o /dev/null -m 30 -XPOST "$AX_URL/ax-*/_refresh" || true++# _cat/indices always emits the full `green open <name> …` row, so match the+# name column rather than anchoring at the start of the line.+DATASETS="$(curl -s -m 30 "$AX_URL/_cat/indices" | grep -cE '(^|[[:space:]])ax-' || true)"+echo " ax-* datasets: ${DATASETS:-0}"+if [ "${DATASETS:-0}" -ge 3 ]; then+ ok "each of the 3 source shapes became its own dataset"+else+ bad "expected >=3 ax-* datasets from the 3-shape corpus, got ${DATASETS:-0}"+fi++if curl -s -m 30 "$AX_URL/autoindex-catalog/_search?size=0" | jq -e '.hits' >/dev/null 2>&1; then+ ok "autoindex-catalog is queryable"+else+ bad "autoindex-catalog index is missing or unqueryable"+fi++# The discovery claim in full: a value that existed only inside a CSV cell is+# retrievable by search, with no schema and no mapping written by hand.+HITS="$(curl -s -m 30 -G "$AX_URL/ax-*/_search" --data-urlencode 'q=zanzibarite' \+ --data-urlencode 'size=0' | jq -r '.hits.total.value // .hits.total // 0')"+echo " hits for 'zanzibarite': ${HITS:-0}"+if [ "${HITS:-0}" -ge 3 ]; then+ ok "a CSV/JSONL/log value is searchable straight after discovery"+else+ bad "expected >=3 hits for 'zanzibarite' across the discovered datasets, got ${HITS:-0}"+fi++# ── summary ───────────────────────────────────────────────────────────────+echo+if [ "$FAILED" = 0 ]; then+ echo "USE-CASE SMOKE PASSED (second brain · MCP · autoindex)"+else+ echo "USE-CASE SMOKE FAILED — $FAILED phase(s) broken"+ exit 1+fidiff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 39fea0a23..d0e9cbf64 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -216,6 +216,45 @@ jobs:- name: THE MAP pipeline contractrun: node --test xerj-ux/test/*.test.mjs+ # The harnesses under demo/usecases/ are the only executable proof that the+ # shipped use cases still work — the brain HTTP surface, the MCP tool surface+ # an agent actually sees, and autoindex's zero-config discovery. Every one of+ # them was manual until this job, so a regression in any was caught by+ # nothing. The installer lint rides along: landing/get{,.ps1} had no+ # verification of any kind and needs no toolchain, so it gates first and+ # cheaply.+ usecase-smoke:+ name: Use-case harnesses (brain + MCP + autoindex)+ runs-on: ubuntu-latest+ steps:+ - uses: actions/checkout@v4++ - name: Installer script lint (landing/get, landing/get.ps1)+ run: bash .github/scripts/installer-lint.sh++ - name: Install Rust+ uses: dtolnay/rust-toolchain@stable++ - name: Cache+ uses: actions/cache@v4+ with:+ path: |+ ~/.cargo/registry/cache+ ~/.cargo/registry/index+ ~/.cargo/git/db+ engine/target+ key: ci-cargo-${{ hashFiles('engine/Cargo.lock') }}+ restore-keys: ci-cargo-++ - name: Build xerj + xerj-mcp (release)+ working-directory: engine+ run: cargo build --release -p xerj-server -p xerj-mcp++ # Drives the demo/usecases scripts themselves, so the thing CI gates is+ # the same thing a reader runs. No browser, no model, no network.+ - name: Use-case smoke (brain transcript, MCP tools, autoindex discovery)+ run: bash .github/scripts/usecase-smoke.sh+# Per-OS runtime gate. The earlier autoindex "Too many open files" crash was# macOS-only and slipped through because nothing in CI actually RAN the binary# on macOS/Windows. This job boots xerj and autoindexes a many-dataset corpusdiff --git a/demo/usecases/autoindex/run-eval.sh b/demo/usecases/autoindex/run-eval.shindex ea8a2dbcb..51c2b4f4b 100755--- a/demo/usecases/autoindex/run-eval.sh+++ b/demo/usecases/autoindex/run-eval.sh@@ -1,26 +1,47 @@#!/usr/bin/env bash# End-to-end eval of `xerj autoindex` against a corpus folder.#-# Boots a dedicated worktree server on es_compat :9260 (rest 9360, grpc 9361),-# runs autoindex over $CORPUS, exercises the 5 query classes + map, then-# re-runs to prove idempotency (counts must not change).+# Boots a dedicated server on es_compat $PORT (rest PORT+100, grpc PORT+101),+# runs autoindex over $CORPUS, then re-runs twice to prove idempotency — the+# resume path (all files done) and a full --fresh re-extract — and requires the+# per-index doc counts to be byte-identical to run 1. Ends with the data map.+#+# Nothing here is bound to one machine: every path is an env override with a+# default under the repo or $TMPDIR, so the same script gates CI and drives a+# local eval over a large corpus.## Usage: run-eval.sh [corpus-dir] [binary]+#+# Env overrides:+# XERJ_AUTOINDEX_CORPUS corpus folder (default ${TMPDIR:-/tmp}/xerj-discover/corpus)+# XERJ_BIN xerj binary (default <repo>/engine/target/release/xerj)+# XERJ_AUTOINDEX_PORT es-compat port (default 9260)+# XERJ_AUTOINDEX_WORK work dir (default ${TMPDIR:-/tmp}/xerj-autoindex)+#+# Exits non-zero if autoindex fails or idempotency breaks.set -uo pipefail-CORPUS="${1:-/tmp/xerj-discover/corpus}"-BIN="${2:-/home/claude/ai/xerj-autoindex-wt/engine/target/release/xerj}"-PORT=9260-DATA="/tmp/xerj-autoindex/data-build"-CFG="/tmp/xerj-autoindex/server-9260.toml"-LOG="/tmp/xerj-autoindex/server-9260.log"++HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"+REPO="$(cd "$HERE/../../.." && pwd)"++CORPUS="${1:-${XERJ_AUTOINDEX_CORPUS:-${TMPDIR:-/tmp}/xerj-discover/corpus}}"+BIN="${2:-${XERJ_BIN:-$REPO/engine/target/release/xerj}}"+PORT="${XERJ_AUTOINDEX_PORT:-9260}"+WORK="${XERJ_AUTOINDEX_WORK:-${TMPDIR:-/tmp}/xerj-autoindex}"+DATA="$WORK/data-build"+CFG="$WORK/server-$PORT.toml"+LOG="$WORK/server-$PORT.log"URL="http://localhost:$PORT"-STATE="/tmp/xerj-autoindex/state"+STATE="$WORK/state"++[ -x "$BIN" ] || { echo "xerj binary not found at $BIN"; exit 1; }+[ -d "$CORPUS" ] || { echo "corpus folder not found at $CORPUS"; exit 1; }-mkdir -p /tmp/xerj-autoindex+mkdir -p "$WORK"cat >"$CFG" <<EOF[server]-rest_port = 9360-grpc_port = 9361+rest_port = $((PORT + 100))+grpc_port = $((PORT + 101))es_compat_port = $PORTbind_address = "127.0.0.1"data_dir = "$DATA"@@ -32,21 +53,38 @@ EOFif ! curl -sf "$URL/" >/dev/null 2>&1; thenmkdir -p "$DATA""$BIN" --insecure --config "$CFG" --data-dir "$DATA" >"$LOG" 2>&1 &+ # Recorded so a caller (CI) can stop the server it made us start.+ echo $! > "$WORK/server.pid"echo "server pid $!"- for i in $(seq 1 60); do+ for _ in $(seq 1 60); docurl -sf "$URL/" >/dev/null 2>&1 && breaksleep 0.5doneficurl -sf "$URL/" >/dev/null || { echo "server failed to boot"; tail -20 "$LOG"; exit 1; }+FAIL=0+echo "=== autoindex run ($CORPUS) ==="time "$BIN" autoindex "$CORPUS" --url "$URL" --state-dir "$STATE" --fresh-echo "exit code: $?"+RC=$?+echo "exit code: $RC"+# 0 complete, 3 completed-with-junk (unreadable files recorded, never fatal).+if [ "$RC" != "0" ] && [ "$RC" != "3" ]; then+ echo "autoindex exited $RC (expected 0 or 3)"+ FAIL=1+fi++# Name + doc count only. The _cat row also carries on-disk size, which a+# --fresh re-extract legitimately changes (segments are rewritten), and the+# catalog is excluded outright because every run appends its own run record —+# a growing catalog is the design, not drift. Columns of the _cat row:+# green(1) open(2) name(3) uuid(4) pri(5) rep(6) docs(7).+counts() { curl -s "$URL/_cat/indices" | awk '$3 ~ /^ax-/ {print $3, $7}' | sort; }echo "=== per-index counts (run 1) ==="-curl -s "$URL/_cat/indices" | grep -E 'ax-|autoindex-catalog' | sort > /tmp/xerj-autoindex/counts-run1.txt-cat /tmp/xerj-autoindex/counts-run1.txt+curl -s "$URL/_cat/indices" | grep -E 'ax-|autoindex-catalog' | sort+counts > "$WORK/counts-run1.txt"echo "=== idempotency: re-run (resume path — all files done) ==="time "$BIN" autoindex "$CORPUS" --url "$URL" --state-dir "$STATE"@@ -54,9 +92,27 @@ time "$BIN" autoindex "$CORPUS" --url "$URL" --state-dir "$STATE"echo "=== idempotency: re-run with --fresh (full re-extract, idempotent ids) ==="time "$BIN" autoindex "$CORPUS" --url "$URL" --state-dir "$STATE" --fresh-curl -s "$URL/_cat/indices" | grep -E 'ax-|autoindex-catalog' | sort > /tmp/xerj-autoindex/counts-run3.txt-echo "=== count diff run1 vs run3 (must be empty on doc counts) ==="-diff /tmp/xerj-autoindex/counts-run1.txt /tmp/xerj-autoindex/counts-run3.txt && echo "IDENTICAL COUNTS ✓"+counts > "$WORK/counts-run3.txt"+echo "=== doc-count diff run1 vs run3 (must be empty) ==="+cat "$WORK/counts-run3.txt"+if diff "$WORK/counts-run1.txt" "$WORK/counts-run3.txt"; then+ echo "IDENTICAL COUNTS ✓"+else+ echo "doc counts drifted across re-runs — autoindex is not idempotent"+ FAIL=1+fiecho "=== data map ==="-"$BIN" autoindex map --url "$URL" | head -80+# Captured, then headed — piping straight into `head` closes stdout under the+# writer, and the map aborts on the resulting EPIPE (a core dump that hides+# whether `map` itself worked).+"$BIN" autoindex map --url "$URL" > "$WORK/map.md"+MAP_RC=$?+head -80 "$WORK/map.md"+if [ "$MAP_RC" != "0" ]; then+ echo "autoindex map exited $MAP_RC"+ FAIL=1+fi++[ "$FAIL" = 0 ] && echo "RESULT: PASS" || echo "RESULT: FAIL"+exit "$FAIL"diff --git a/demo/usecases/second-brain/README.md b/demo/usecases/second-brain/README.mdindex b0e1f98ec..33f1fc392 100644--- a/demo/usecases/second-brain/README.md+++ b/demo/usecases/second-brain/README.md@@ -43,6 +43,9 @@ port `9331` (override with `XERJ_BRAIN_DEMO_ROOT` / `XERJ_BRAIN_DEMO_PORT`),binaries from `engine/target/release/`. All scripts are idempotent; stop thebooted server with `kill $(cat <root>/data/server.pid)`.+These three are also what CI runs, via `.github/scripts/usecase-smoke.sh` — so+the gate on every PR is this exact harness, not a separate copy of it.+## What the transcript proves1. **Overview** — brain exists, live/retired counts, all five detectorsdiff --git a/demo/usecases/second-brain/transcript.sh b/demo/usecases/second-brain/transcript.shindex 588a31c3e..5fd1bbff5 100755--- a/demo/usecases/second-brain/transcript.sh+++ b/demo/usecases/second-brain/transcript.sh@@ -66,8 +66,12 @@ ck "contract xerj-second-brain/1" J '.contract == "xerj-second-brain/1"ck "embedder honesty marker is lexical" J '.embedder == "lexical-feature-hash"'ck "edges.total >= 1" J '.edges.total >= 1'ck "invalidated == total - live" J '.edges.invalidated == .edges.total - .edges.live'-for tag in wikilink@1 mdlink@1 href@1 sequence@1 samedir@1; do- ck "detector $tag has live edges" J --arg t "$tag" '[.detectors[] | select(.detector == $t and .live > 0)] | length == 1'+# Matched on the detector family, not the pinned `@N`: the contract is that+# each of these five fires on the vault, while the version is *designed* to+# move (detect/mod.rs mandates bumping @N on any behavior change), so pinning+# it here would fail every deliberate bump instead of every real regression.+for tag in wikilink mdlink href sequence samedir; do+ ck "detector $tag has live edges" J --arg t "$tag@" '[.detectors[] | select((.detector | startswith($t)) and .live > 0)] | length == 1'doneck "not_shown accounting present" J '.not_shown | has("types_not_listed") and has("hubs_out_not_listed")'echo " measured: $(jq -c '{edges, types: [.types[] | {(.type): .live}] | add}' "$WORK/resp.json")"