TypeSafe Jev for first-tool / skill routing (~300ms, fail-open) — not indexing
Area
- gitnexus-web (browser UI / WASM / workers) — primary
- gitnexus (CLI / core / indexing / MCP server) — optional follow-up, opt-in only
Problem or opportunity
GitNexus is already fast at the things it owns: tree-sitter parse, LadybugDB, BM25/hybrid query, Cypher. TypeSafe Jev cannot speed any of that (and must not be asked to). It is a judgment model (POST /v1/systemone, Choice + Noul, ~300ms, max output tokens 0) — it names which option, it does not generate Cypher, embeddings, or answers.
Two hops still go through a chat model today, and those are the only places Jev helps:
Web Graph RAG agent (
gitnexus-web/src/core/llm/agent.ts) —createReactAgentwith 7 tools (search,cypher,grep,read,overview,explore,impact). Every user question starts with a full LLM tool-call just to pick the first tool.BASE_SYSTEM_PROMPTis ~1.3k tokens of tool policy before that hop. Recursion limit is 50. Related: #435 (prompt dilution), #438 (iteration budget).Host-agent GitNexus skills —
gitnexus analyzeinstalls a small overlapping catalog (gitnexus-exploring/impact-analysis/debugging/refactoring/guide/cli, plus plan/review/work/pdg/taint).ai-context.tsalready documents the failure mode: “skills are skipped 56% of the time (Vercel eval data)”, which is why the CLAUDE.md/AGENTS.md block inlines workflows. Related: #2510 (move tool-usage policy off AGENTS.md onto MCPinstructions). A calibrated picker would make those skills actually load instead of stuffing more RFC 2119 into the markdown.
MCP currently exposes ~17 tools (query, cypher, context, impact, explain, pdg_query, route_map, tool_map, …) with no MCP instructions field (gitnexus/src/mcp/server.ts). Hosts guess among schemas; GitNexus then appends “Next:” hints because “Agents often stop after one tool call.”
Proposed solution
Treat Jev as an optional router, never as a provider or indexer.
Phase 1 — web chat only (small, shippable)
Before the LangChain ReAct loop, one TypeSafe call:
which= Choice over the 7 Graph RAG tool names (short criteria, not the full system prompt)- gate nouls:
code_question,needs_graph,needs_file_read(same 0.30 mean as the skill-suggestion cookbook) - On a hit: seed the agent with that tool call (or a one-line “start with
search”) so the chat model skips the first selection hop - On miss / no key / timeout: fail-open — today’s ReAct path unchanged
- Wall: ~2.5s abort, 1 attempt, no tiny/smol/chat fallback (a wrong first tool is worse than none)
- Only when the user already opted into a cloud LLM and has
TYPESAFE_API_KEY(web chat is already a network path)
Live check of this cookbook shape (39-way Choice, jev-1.13.0): p50 ~330ms, p95 ~372ms, 0/6 over 2.5s. Seven tools should be cheaper.
Phase 2 — optional MCP route (only with a key)
A single opt-in tool, e.g. gitnexus_route({ prompt }) → { skill?, tool, hint }, Choice over the standard skill catalog + MCP tool names. Disabled unless TYPESAFE_API_KEY is set. Complements #2510: policy can shrink because a judge picks the tool instead of a 660-token CLAUDE.md block. Default MCP stays local/no-network.
Privacy / no-network policy (opt-in, minimal payload)
GitNexus’s advertised contract is CLI+MCP: “Everything local, no network.” Web UI: “Everything in-browser, no server.” A TypeSafe hop is a cloud API call, so this feature is off by default on every path. Having an OpenAI/Anthropic/Ollama key is not consent for a second vendor.
Payload (the whole point of Jev being cheap): one POST /v1/systemone whose state is the current user question, hard-truncated (e.g. 500 chars). Choice options are the public 7 Graph RAG tool names already in GRAPH_RAG_TOOL_NAMES. Not sent: source, diffs, graph, Cypher, embeddings, repo path, remotes, SKILL.md bodies, prior chat, system prompt, or tool results. That is a strict subset of what web chat already sends to the session LLM.
User opt-in, not an env-var side effect:
- Web: Settings toggle default off, with copy that this sends the question text (not code) to TypeSafe. Requires a TypeSafe key in the same panel.
- CLI+MCP: both
GITNEXUS_TYPESAFE_ROUTING=1andTYPESAFE_API_KEY. A TypeSafe key alone does not enable it.gitnexus_routeis absent fromListToolsotherwise. GitNexus never auto-calls TypeSafe; the host must invoke the tool. analyze/ embeddings / defaultmcp/serve: zero TypeSafe requests (network-intercept tests).
TypeSafe states they do not train on Input and offer enterprise ZDR. GitNexus still sends as little as possible, only after the toggle/flag.
See the follow-up comment on this issue for the acceptance-criteria extras.
Explicitly out of scope
| Idea | Why not |
|---|---|
Speeding analyze, tree-sitter, LadybugDB, embeddings |
Different bottleneck. See #1444 / #3295 |
| Generating Cypher or chat answers with Jev | Max output tokens 0 |
| Default-on for CLI+MCP | README: “Everything local, no network.” A TypeSafe hop is a cloud call — opt-in only |
Replacing hybrid/BM25 query or --embeddings |
Jev is not an embedder |
| Tournament / GodsBoy-style chunking | Catalog is 7 tools / ~6–10 skills, far under Choice’s 255 cap |
Alternatives considered
- Bigger system prompt / more RFC 2119 — already the current design, and skills are still skipped 56% of the time.
- MCP
instructionsonly (#2510) — still the right place for policy; it does not pick among 17 tools in 300ms. This issue is the picker; that one is the transport. - Cheaper chat model as router (
gpt-4o-mini/ Ollama) — still a generation model, still seconds, still can emit a wrong tool name with high confidence. Jev’s product is calibrated Choice/Noul, not tokens. - Heuristic regex (“what breaks” →
impact) — cheap and local; keep as a no-key fallback. It will miss paraphrases, which is the 56% skip problem.
Acceptance criteria
- Web: with TypeSafe authenticated, the first Graph RAG action is chosen without a chat-model tool-selection hop on obvious queries (
searchvsimpactvsgrep). - Web: without a key, with HTTP error, or past 2.5s, behavior is byte-identical to today (fail-open tests).
- Jev is never registered as an LLM provider in
gitnexus-web/src/core/llm/types.ts. - CLI
analyze/ embeddings / MCP default path make zero TypeSafe calls. - If Phase 2 ships:
gitnexus_routeis absent from the tool list unlessTYPESAFE_API_KEYis set; read-only policy treats it as read-only. - Docs: one README/env row for
TYPESAFE_API_KEY(required by CONTRIBUTING for newGITNEXUS_*/ related env).
Constraints
- Privacy: must not phone home during index/serve for users who never set a TypeSafe key.
pi-fabric/ TypeSafe clients do not auto-retry; a late inject is worse than none.- Do not change
TypeSafeJudge-style retry budgets used by other products; this path wants 1 attempt. - Cookbook call 2 (rerank top-3 with SKILL.md excerpts) is unnecessary at 7 tools.
Prior art
- TypeSafe cookbook: Skill suggestion (call 1 = Choice + 3 gate nouls, gate 0.30)
- Native
POST /v1/systemoneusage: elizaOS, LangChainlangchain_typesafe, Vercel typesafe-ai — Jev is not a chat model - GitNexus already has the catalog and the eval number (56% skill skip) — this is wiring a judge in front of lists that already exist
Source: abhigyanpatwari/GitNexus