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
fix(xerj-code): preserve JSON output for empty search results
Amakuraib066683017ac
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex e16214a95..1d5d76809 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -96,6 +96,9 @@ jobs:- name: Corpus manifest round-triprun: tools/xerj-code/tests/test_xc_corpus.sh+ - name: Retrieval output and state-ledger regressions+ run: python3 tools/xerj-code/tests/test_state_ledger.py+- name: Vetted hub manifests validaterun: python3 tools/xerj-code/tests/validate_manifest.py --hub tools/xerj-code/hub/*.jsondiff --git a/CHANGELOG.md b/CHANGELOG.mdindex 16a4a91c7..908eb5eb6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -26,6 +26,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0exposes the same two parameters. Raised by @Vinz2168 from a shared-memoryagent integration where neither single mode was enough.+### Fixed++- **`xc.py --json` emits JSON for empty search results.** Previously, a query+ with no hits printed the human-readable no-match message before reaching the+ JSON output branch, breaking callers that parse stdout. Empty results now+ preserve the JSON response and still exit `1`; matching results exit `0`, and+ a corpus with no live indices retains its distinct exit `3` diagnostic.+## [1.0.0-rc.74] - 2026-09-08### Addeddiff --git a/tools/xerj-code/README.md b/tools/xerj-code/README.mdindex c785fe981..9a3459177 100644--- a/tools/xerj-code/README.md+++ b/tools/xerj-code/README.md@@ -88,8 +88,16 @@ already knows, it is overhead. `SKILL.md` and[`docs/case-studies/reference-coding/`](../../docs/case-studies/reference-coding/)carry the measured numbers, including the cases where this loses.+## Machine-readable retrieval++Pass `--json` to return the search result as JSON, including when no passages+match. Check both stdout and the exit status: matching results exit `0`, while+an empty `hits.hits` array exits `1`. A corpus with no live indices still exits+`3` with a diagnostic on stderr; it is not an empty search result.+## Tests```shtools/xerj-code/tests/test_xc_corpus.sh # offline; local git fixtures over file://+python3 tools/xerj-code/tests/test_state_ledger.py # offline; mocked HTTP responses```diff --git a/tools/xerj-code/scripts/xc.py b/tools/xerj-code/scripts/xc.pyindex 645b4afb0..ac5daea6f 100755--- a/tools/xerj-code/scripts/xc.py+++ b/tools/xerj-code/scripts/xc.py@@ -646,6 +646,14 @@ def main():if note and not args.json:print(f'@mode {note}' if args.meatl else f"[{note}]")+ if args.json:+ # Empty results must remain machine-readable without turning a miss+ # into a successful retrieval (the exit-code contract is unchanged).+ print(json.dumps(res, indent=1))+ if not hits:+ sys.exit(1)+ return+if not hits:# Say so explicitly. A silent miss makes the next agent re-run the same# dead query; this is the line that stops the loop.@@ -655,10 +663,6 @@ def main():f"normal work rather than forcing a bad match.")sys.exit(1)- if args.json:- print(json.dumps(res, indent=1))- return-licences = {}man = os.path.join(ROOT, "corpora", args.corpus, "corpus.json")if os.path.exists(man):diff --git a/tools/xerj-code/tests/test_state_ledger.py b/tools/xerj-code/tests/test_state_ledger.pyindex c307d3abb..266298fe6 100755--- a/tools/xerj-code/tests/test_state_ledger.py+++ b/tools/xerj-code/tests/test_state_ledger.py@@ -180,6 +180,50 @@ def main():check("list flags the fixture as NOT loaded","NOT loaded here" in blob, repr(blob))+ # --json must be parseable for a genuine miss as well as a match. Keep the+ # existing exit codes and the raw response (including BM25 metadata).+ for mode, extra in (("bm25", []), ("hybrid", []), ("semantic", []),+ ("bm25", ["--meatl"])):+ label = mode + (" +meatl" if extra else "")+ code, out, err = run_query(+ mod, indices=[{"index": f"{PREFIX}-1"}], search_hits=[],+ argv=[CORPUS, "nonexistent xyzzy plugh", "--json", "--mode", mode]+ + extra)+ expected = {"hits": {"hits": []}}+ if mode == "bm25":+ expected["hits"]["total"] = {"value": 0}+ try:+ payload = json.loads(out)+ except ValueError:+ payload = None+ check(f"json {label} miss keeps exit code 1", code == 1, f"got {code}")+ check(f"json {label} miss emits the empty response",+ payload == expected, repr(out))+ check(f"json {label} miss has no stderr", err == "", repr(err))++ code, out, err = run_query(+ mod, indices=[{"index": f"{PREFIX}-1"}], search_hits=HIT,+ argv=[CORPUS, "two way parse_two_way", "--json"])+ check("json match keeps exit code 0", code == 0, f"got {code}")+ check("json match preserves the raw response",+ json.loads(out) == {"hits": {"total": {"value": 1}, "hits": HIT}},+ repr(out))++ code, out, err = run_query(mod, indices=[], search_hits=[],+ argv=[CORPUS, "two way string search", "--json"])+ check("json unloaded corpus keeps exit code 3", code == 3, f"got {code}")+ check("json unloaded corpus has no search response", out == "", repr(out))+ check("json unloaded corpus keeps its actionable stderr",+ "0 live indices" in err and "xc-index.sh" in err, repr(err))++ code, out, err = run_query(+ mod, indices=[{"index": f"{PREFIX}-1"}], search_hits=[],+ argv=[CORPUS, "nonexistent xyzzy plugh", "--meatl"])+ check("meatl miss keeps exit code 1", code == 1, f"got {code}")+ check("meatl miss keeps its no-match record",+ out == '@no q="nonexistent xyzzy plugh" why=no-match-in-corpus\n',+ repr(out))+print(f"\n{passed} passed, {failed} failed")sys.exit(1 if failed else 0)