8000 feat(hub): agent-facing surface: xerj-hub skill + init MCP registration (plan §9) by xerj-org · Pull Request #1406 · xerj-org/xerj · GitHub
[go: up one dir, main page]

Skip to content

feat(hub): agent-facing surface: xerj-hub skill + init MCP registration (plan §9) - #1406

Merged
xerj-org merged 4 commits into
feat/hub-v2-basefrom
feat/hub-v2-agent-surface
Oct 15, 2026
Merged

xerj-org merged 4 commits into
feat/hub-v2-basefrom
feat/hub-v2-agent-surface

Conversation

@xerj-org
@xerj-org xerj-org commented Oct 14, 2026 •
Copy link
Copy Markdown
Owner

Plan §9 (agent-facing surface) of Corpus Hub v2, part 1: what xerj init installs. Base is feat/hub-v2-base.

The llms.txt / llms-full.txt draft is no longer in this PR. It moved to draft PR #1410 against main ([HOLD until release with xerj ask]), because feat/hub-v2-base becomes one integration PR into main, anything under landing/ on main can deploy to xerj.org, and the draft describes commands, MCP tools and hosted routes no released binary has. This branch was rebuilt on the current feat/hub-v2-base without the two docs(llms): DRAFT commits (force-pushed with lease). It touches no file under landing/.

Commits

# commit files
1 feat(init): install the xerj-hub skill and print the MCP registration per client (plan §9) engine/crates/xerj-autoindex/src/init.rs, demo/playbooks/AGENT_FTX_HARNESS.md
2 docs(readme): add the xerj-hub row to the engine crate map engine/README.md
3 fix(init): tell agents in the hub skill that a one-word question needs ask init.rs
4 fix(init): stop promising unserved xerj_hub_* MCP tools; print a pasteable, URL-correct registration init.rs, engine/README.md

What it does

xerj init writes, next to the existing xerj skill, .claude/skills/xerj-hub/SKILL.md (when .claude/ exists in the project or $HOME) and .cursor/rules/xerj-hub.mdc (when .cursor/ exists). Written only when absent; an edited file is kept; --dry-run writes nothing; a second run reports kept. The skill teaches HUB / LOCAL / NEITHER, xerj "<question>" (and xerj ask "<word>" for one word), --def, exits 1/3/4/5, xerj hub pull, safe node stop, the hosted switch, and MCP registration per client. init ends by printing the MCP registration for the clients .mcp.json does not cover.

Adversarial review (commit 4)

sev finding fix
High Skill + printed text sent agents to xerj_hub_ask/def/find and used "xerj_hub_ask is in the tool list" as the registration proof. xerj mcp serves none of them (plan step 7 deferred, docs/hub-v2-grpc-mcp-notes.md). Skill says this build's xerj mcp has no hub tool; success tool is xerj_search. Test no_unserved_hub_mcp_tool_is_promised guards it; update with step 7.
Medium Printed claude mcp add ... "$(command -v xerj)" only works in a POSIX shell, and ignored --url/$XERJ_URL, so it registered a different node than .mcp.json. Printed line uses the resolved absolute binary path (shell-quoted per OS) and -e XERJ_URL=<url> when non-default. Two new tests.
Low Exit 5 (no hub public key) missing. Added.
Low kill $(cat ~/xerj-node.pid) referenced a file nothing creates; node resolution described as localhost:9200 only. Reworded; xerj hub stop success lines added; --url/$XERJ_URL/localhost:9200.

Known and NOT changed (pre-existing init.rs behaviour, outside this diff): backup() ignores a failed .bak copy and still overwrites .mcp.json; the "already registered" check is a substring match on "xerj"; write_if_absent never refreshes an unedited skill, so installs made now keep the "no hub tool" text after step 7 ships (needs a version marker); dirs_home() and xerj-hub's hub_home() read only HOME, which Windows usually lacks.

Gates

check result
cargo test --release -p xerj-autoindex init 26 passed
cargo fmt -p xerj-autoindex -- --check clean
cargo clippy -p xerj-autoindex --tests -- -D warnings clean

Not re-run after the rebuild: the real-binary xerj init smoke and xerj-engine --test docs_capability_lists (the README row still names xerj-hub).

🤖 Generated with Claude Code

… per client (plan §9)

Corpus Hub v2 plan §9, first bullet group. `xerj "<question>"` only helps if
an agent knows when to reach for it, so `xerj init` now writes a second
teaching file beside the existing one:

  .claude/skills/xerj-hub/SKILL.md   when .claude/ exists (cwd or $HOME),
                                     the same signal the xerj skill uses
  .cursor/rules/xerj-hub.mdc         when .cursor/ exists, same text

What the file says (and a unit test pins each of these, so deleting one
fails the build):

- the decision rule: HUB for public material you cannot quote, LOCAL for
  your own files, NEITHER for what you already know exactly;
- the one line, `xerj "<question>"`, and what a good answer looks like
  (corpus, pin date and licence on the first line, then the passage, then
  `answered from:`);
- `xerj ask --def <SYMBOL>` for exact questions;
- what to do on exit 4 (ambiguous: re-run with --corpus), exit 1 (the hub
  does not hold it: say so), exit 3 (pack failed verification), and on
  `run: xerj hub pull <slug> (<MB> MB)` for a large pack;
- "stop only the node you started": `xerj hub stop` for XERJ's own node,
  `kill $(cat ~/xerj-node.pid)` for one you saved a PID for, never
  `pkill xerj` / `killall xerj`;
- where the question goes (hosted hub is off by default inside a git repo);
- the MCP tools and the registration PER CLIENT: `claude mcp add`, the
  `mcpServers` root key (.mcp.json, Cursor, Windsurf, Claude Desktop,
  Cline) and VS Code's `servers` root key (an `mcpServers` block there is
  silently ignored).

`xerj init` also ends by printing that registration, which is what plan §7
asks for ("`xerj init` prints the MCP registration") and what the llms.txt
study asks for (rule 5: print it, per client, with the root key). A unit
test ties the printed block to the skill so the two cannot drift.

Mechanism: mirrors the existing skill exactly (written only when absent,
never overwrites an edited file, `--dry-run` reports and writes nothing,
second run says `kept`). The four near-identical write blocks collapse into
one `write_if_absent` helper; behaviour of the existing two is unchanged and
their tests still pass.

The text is a raw string in init.rs, not a .md asset: the repository ignores
*.md by default, and an include_str! of an ignored file compiles locally
and fails in CI. Its description has no angle brackets (the Agent Skills
spec forbids XML-like tags there) and no line exceeds 300 characters
(llms.txt study rule 7); both are tested.

Also updates demo/playbooks/AGENT_FTX_HARNESS.md: what `xerj init` writes,
and the §9 harness assertion (a shell-less persona reaches an answer through
`xerj_hub_ask` in one call). That assertion needs a build whose tools/list
names xerj_hub_ask (plan §7); it was not run here.

Verification: cargo test -p xerj-autoindex --lib init:: (19 passed, 10 new);
cargo fmt -p xerj-autoindex --check; cargo clippy -p xerj-autoindex
--all-targets -- -D warnings; and the real binary (cargo build -p xerj-server)
in a throwaway project and HOME: `xerj init --dry-run` writes nothing,
`xerj init` writes the six files, a second run says `kept` for all six, the
Cursor rule is byte-identical to the skill, and `xerj init --help` lists them.

Dependency, stated so nobody is surprised: the text describes `xerj ask`,
`xerj hub stop` and `xerj hub config` (open PR #1402 into this base) and the
xerj_hub_* MCP tools (plan §7, not on the base yet). It is accurate only for a
binary that has them, so this should not be released without them.
`docs_capability_lists::the_readme_crate_map_lists_every_workspace_crate`
fails on feat/hub-v2-base: the keystone step added `engine/crates/xerj-hub`
but engine/README.md's `### Crate Map` has no row for it, so the test reports

    engine/README.md's crate map has no row for ["xerj-hub"]

Plan §9 requires "the docs drift tests pass", and the base branch cannot
reach main with that test red. One row, in the table's existing shape
(first cell is the crate, then its purpose); the sentence under the table
already says the test fails if a crate is missing.

The row describes what the crate does on this branch (pull, verify and
restore signed pre-indexed packs; build them for CI; route a question to a
corpus) and its one workspace dependency that matters, per its own
Cargo.toml description. It makes no claim about a release.

Verification: cargo test -p xerj-engine --test docs_capability_lists
(15 passed, was 14 passed / 1 failed).
…s `ask`

`xerj "<question>"` is the bare form of `xerj ask "<question>"` only when the
question contains a space (plan §5: argv[1] is not a subcommand, does not
start with "-", and contains a space). `xerj compressBound` has no space, so
it falls through to the server's argument parser and fails with an error that
has nothing to do with the hub. An agent that asks about a single identifier
would hit exactly that, and the skill is where it learns the command.

One sentence in the skill's "Ask the hub" section: the bare form needs a space
in the question; for a single word write `xerj ask "<word>"`. The exact-symbol
case keeps its own form, `xerj ask --def <SYMBOL>`. A unit test pins the new
sentence with the others.

Verification: cargo test -p xerj-autoindex --lib init:: (19 passed);
cargo fmt -p xerj-autoindex --check.
…eable, URL-correct registration

Adversarial review of #1406 (Corpus Hub v2 plan section 9).

1. HIGH: the hub skill and init's closing message sent agents to the MCP
   tools xerj_hub_ask / xerj_hub_def / xerj_hub_find and made "`xerj_hub_ask`
   is in the tool list" the proof that registration worked. `xerj mcp` on
   feat/hub-v2-base serves none of them (plan step 7 is deferred:
   docs/hub-v2-grpc-mcp-notes.md; `git grep xerj_hub_ engine/crates/xerj-mcp`
   is empty). A correct registration therefore looked failed, and an MCP-only
   agent was told to call tools that do not exist. The skill now says this
   build's `xerj mcp` has no hub tool, to ask the hub with the shell line, and
   to prefer an `xerj_hub_*` tool if a newer build lists one; the success
   tool is `xerj_search` (MCP_SUCCESS_TOOL), which is served today. New test
   `no_unserved_hub_mcp_tool_is_promised` fails if either text names a hub
   tool again; step 7 updates it together with the skill.

2. MEDIUM: the printed Claude Code line was
   `claude mcp add --scope user xerj -- "$(command -v xerj)" mcp`, which only
   a POSIX shell expands (PowerShell/cmd get a literal `$(...)`), although init
   already resolves its own absolute path for .mcp.json. It also dropped
   `--url` / $XERJ_URL, so the user-scope registration pointed at a different
   node than the .mcp.json init just wrote. The printed line is now built from
   current_exe() (shell-quoted: POSIX single quotes, Windows double quotes)
   and carries `-e XERJ_URL=<url>` when the URL is not the default, in the
   `claude mcp add <name> -e K=V -- <cmd>` order `claude mcp add --help`
   documents. The skill (static text) keeps the `$(command -v xerj)` form and
   says what to substitute in PowerShell. Tests:
   `printed_claude_line_uses_this_binary_and_this_url`,
   `shell_quote_survives_a_single_quote_on_unix`.

3. LOW: the skill omitted exit 5 (no hub public key; xerj-hub ask.rs
   EXIT_NO_KEY); now listed.
4. LOW: the skill told agents to `kill $(cat ~/xerj-node.pid)`, a file nothing
   tells them to create; now "kill only the PID you recorded". `xerj hub stop`
   carries its two success lines (cli.rs stop_in), and node resolution reads
   --url / $XERJ_URL / localhost:9200 as node.rs resolve_url does.
5. engine/README.md: the xerj-hub row names `xerj ask` too.

Gates (scoped): cargo test --release -p xerj-autoindex init: 26 passed;
cargo fmt -p xerj-autoindex --check clean; cargo clippy -p xerj-autoindex
--tests -D warnings clean.

Not changed (pre-existing, recorded on #1406): backup() ignores a failed
.bak copy and still overwrites .mcp.json; the "already registered" check is a
substring match on "xerj"; write_if_absent never refreshes an unedited skill,
so installs keep this text after step 7 lands.
@xerj-org
xerj-org merged commit 0e1375e into feat/hub-v2-base Oct 15, 2026
1 check passed
lamardealmaker pushed a commit to lamardealmaker/xerj that referenced this pull request Oct 15, 2026
…replace an unreadable AGENTS.md

`xerj init` promises (module doc) to "never touch a byte we did not write
without a .bak backup". Two paths broke that, both on main today:

1. backup() did `let _ = fs::copy(path, bak)` and returned true regardless,
   so when the copy failed (read-only dir, a directory at the .bak path, disk
   full) init went on to overwrite .mcp.json / append to AGENTS.md with no
   backup, and reported "merged". backup() now returns Result and a failed
   copy aborts init with "could not back up <file> to <bak> (<err>); not
   touching it".

2. AGENTS.md: any read_to_string error took the "file absent" branch and
   wrote a fresh "# Agent notes" file over it. An existing AGENTS.md that is
   not valid UTF-8 (or unreadable for permissions) was therefore replaced
   wholesale with no backup. Only NotFound now creates the file; any other
   read error aborts with the reason.

Tests (both fail on the old code: the run succeeded and overwrote the file):
- failed_backup_leaves_mcp_json_untouched: a directory at .mcp.json.bak makes
  the copy fail; init errors and .mcp.json is byte-identical.
- unreadable_agents_md_is_not_replaced: a non-UTF-8 AGENTS.md is left
  byte-identical and init names it in the error.

Found while reviewing xerj-org#1406 (Corpus Hub v2 init work), which carries the same
helpers; split out as its own small PR to main per the small-PR directive.

Gates (scoped): cargo test --release -p xerj-autoindex init: 13 passed;
cargo fmt --check clean; cargo clippy -p xerj-autoindex --tests -D warnings
clean.
lamardealmaker pushed a commit to lamardealmaker/xerj that referenced this pull request Oct 15, 2026
…(plan §7)

Corpus Hub v2 step 7, slice 4 of 4 (stacked on the flow-seams slice). Adds
the three tools specified in docs/hub-v2-grpc-mcp-notes.md to `xerj mcp`
(engine/crates/xerj-mcp/src/hub.rs, dispatched from lib.rs call_tool and
appended to tool_specs()).

Thin adapters over the code the CLI runs — xerj-mcp now depends on xerj-hub
and calls it, it does not copy it:
- xerj_hub_ask {question, corpus?, mode?, max_tokens?} -> ask::run_ask_with,
  i.e. `xerj ask "<q>" [--corpus] [--def|--how|--files] [--max-tokens]`.
- xerj_hub_def {slug, symbol, k?} -> the same flow as
  `xerj ask --corpus <slug> --def <SYMBOL>`, with k carried through.
- xerj_hub_find {question, k?} -> ask::run_find, the routing half of
  `xerj ask` (deps, sketches, exact-symbol evidence, cached bonus).
Text = the §1 rendering with the flow's notices on top (MCP has no stderr);
structuredContent = the Answer JSON (or the FindOutcome). A miss and an
ambiguous route are not errors; everything else without an answer is.

Read-only, on purpose: the flow runs with no_fetch, so a tool call never
downloads a pack — a corpus that is not on this machine is answered with the
`xerj hub pull <slug>` line — and therefore can never trigger the pull's
least-recently-used eviction (a delete) behind an agent's back. Excluded
corpora are never pulled/served/hinted (the flow's own policy) and never
listed by find; approach-only hits carry the warning. Inputs are refused
before anything runs: 512-byte question/symbol cap, slugs through the pull's
own valid_slug, k 1..=50 (find 1..=10), max_tokens 1..=8192, mode enum.
The node is this server's --url/XERJ_URL, else the automatic hub node; the
standalone xerj-mcp binary starts that node with the `xerj` beside it (or on
PATH), never with itself.

The hub skill `xerj init` installs (engine/crates/xerj-autoindex/src/init.rs)
said "this build has no hub tool"; it now names exactly the three tools, their
CLI equivalents and the never-downloads rule. The PR xerj-org#1406 guard
no_unserved_hub_mcp_tool_is_promised becomes
the_hub_skill_names_exactly_the_hub_tools_mcp_serves: every served tool is
named and no other xerj_hub_* name appears. `xerj_search` stays the
registration check.

landing/docs/agents/schemas/mcp-tools.json is regenerated with
scripts/mcp-schema-check.sh --write from the real binary (16 tools); the
published-schema drift gate requires it in the same change.

exactly_the_five_search_tools_advertise_max_tokens now states the one
exception: xerj_hub_ask's max_tokens is the hub's SOFT cap (xerj ask
--max-tokens), and its description must not claim xerj-org#1058's never-exceeded
contract.

Tests:
- tests/hub_tools.rs (own binary: process-global env): a real in-process
  node with the mini-c / approach-only fixture restored as `xerj hub pull`
  leaves it (ledger, packs/<slug>/<pin8>/pack.json, fresh cached catalogue).
  JSON-RPC tools/list carries the three with valid schemas (required ⊆
  properties, typed, described); tools/call xerj_hub_def -> value 128 from
  limits.h, answered_from local_pack, structuredContent parses as Answer; k=1
  honoured; sketch-routed xerj_hub_ask names mini-c; approach-only warning on
  every hit; excluded refused with no pull hint; a not-cached corpus gets the
  pull line and NOTHING is written under packs/ or pulls/; find lists mini-c
  first (cached) and never the excluded corpus; bad slug/k/oversize/mode/
  missing question refused; the node's xc-* indices unchanged.
- hub::tests (argument checks, outcome mapping); lib tools_list_has_all_sixteen.
- xerj-mcp: 79 lib + 1 + 4 (drift) pass; xerj-autoindex init:: 22 pass;
  xerj-rerank egress_inventory 4 pass; scripts/mcp-schema-check.sh PASS.
- clippy -p xerj-mcp -p xerj-autoindex --all-targets -D warnings, fmt: clean.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0