Skip to content

codedb_remote: add 'wiki' backend (wiki.codes) alongside codegraff#312

Merged
justrach merged 1 commit intorelease/0.2.579from
feat/remote-wiki-backend
Apr 22, 2026
Merged

codedb_remote: add 'wiki' backend (wiki.codes) alongside codegraff#312
justrach merged 1 commit intorelease/0.2.579from
feat/remote-wiki-backend

Conversation

@justrach
Copy link
Copy Markdown
Owner

Resolves #311.

Summary

`codedb_remote` today hits `codedb.codegraff.com` only. Its sibling project codedb-cloud / wiki.codes is a Zig-native parquet router on Hetzner with more repos indexed, the exact-identifier-lookup `symbol` action, and hot-pin `policy` — but agents using codedb have no path to it.

This PR adds an optional `backend` field. Default stays `"codegraff"` — every existing caller is unchanged on the wire. Opt in with `backend="wiki"` to reach the new capabilities.

Surface

action codegraff (default) wiki
tree
outline
search
meta
symbol (new)
policy (new)

Cross-backend mismatches get a clear error:
```
action 'meta' not supported on backend 'wiki'
(wiki supports: tree, outline, search, symbol, policy)
```

Wire details

  • URL: `https://www.wiki.codes/api/query?slug=&endpoint=&q=` via the Vercel proxy. Server-side-auths to the Hetzner router. No client secrets needed.
  • Slug: derived by replacing `/` with `-` (matches wiki's canonical naming: `rust-lang/rust` → `rust-lang-rust`, `vercel/next.js` → `vercel-next-js`).
  • Auth: none from the agent's side — same UX as the existing codegraff backend.
  • Validation: same repo-format + path-traversal rules as today.

Verified live

```
$ echo '{"jsonrpc":"2.0","method":"tools/call","params":{"name":"codedb_remote",
"arguments":{"repo":"rust-lang/rust","action":"symbol","query":"HashMap",
"backend":"wiki"}},"id":2}' | codedb mcp

→ 25 hits in 686ms, including:
library/std/src/collections/hash/map.rs:247 struct_def "pub struct HashMap<"
library/std/src/collections/hash/map.rs:256 impl_block
src/tools/clippy/tests/ui-toml/toml_disallowed_types/.../conf_disallowed_types.rs:12
src/tools/rust-analyzer/crates/ide-assists/src/handlers/auto_import.rs:408
...
```

Also verified negative paths:

  • `backend=wiki action=meta` → clear rejection
  • `backend=codegraff action=symbol` → clear rejection
  • `backend=garbage` → clear rejection

Out of scope

  • Auto-failover between backends (codegraff 404 → try wiki). Follow-up if agents want a single "best effort" mode.
  • Writing to wiki (`/admin/ingest`). That's authenticated; bundling it would mean exposing a token. Read-only for now.
  • Swapping the default backend. Every existing caller stays on codegraff unless they opt in.

Test plan

  • `zig build` green
  • Live `codedb_remote` call with `backend=wiki` against rust-lang/rust returns 25 real HashMap definitions
  • Validation rejects cross-backend action mismatches with useful error text
  • Existing codegraff default behavior unchanged (same URL, same result shape)

🤖 Generated with Claude Code

codedb_remote today only hits codedb.codegraff.com (WASM-on-Workers
indexer). Its sibling project codedb-cloud / wiki.codes is a
Zig-native parquet router with a superset of actions and more repos
indexed, but agents using codedb have no path to it.

Adds an optional `backend` field to codedb_remote. Default stays
"codegraff" — every existing caller is unchanged on the wire.

Backends + supported actions:

  codegraff (default):  tree, outline, search, meta
  wiki:                 tree, outline, search, symbol, policy

`symbol` (exact-identifier definition lookup across an indexed repo)
and `policy` (hot-pin size class) are new capabilities from wiki that
codegraff doesn't expose; `meta` stays codegraff-only.

Wiki requests go through the Vercel `/api/query` proxy at
https://www.wiki.codes which server-side-auths to the Hetzner router.
No client secrets, no API key. Slug is derived from the repo arg by
replacing '/' with '-' (matches wiki's canonical naming: rust-lang/rust
→ rust-lang-rust).

Per-backend action allowlists reject cross-backend mismatches with a
clear error:
  action 'meta' not supported on backend 'wiki'
    (wiki supports: tree, outline, search, symbol, policy)

Verified live against wiki.codes:
  codedb_remote repo=rust-lang/rust backend=wiki action=symbol
                query=HashMap
  → 25 hits in 686ms including
    library/std/src/collections/hash/map.rs:247 struct_def
    and impl_blocks, plus clippy + rust-analyzer test files

Closes #311.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

Benchmark Regression Report

Threshold: 10.00%

Tool Base (ns) Head (ns) Delta Status
codedb_bundle 313698 318584 +1.56% OK
codedb_changes 33458 31214 -6.71% OK
codedb_deps 4771 4918 +3.08% OK
codedb_edit 4414 4447 +0.75% OK
codedb_find 44865 43519 -3.00% OK
codedb_hot 54465 61655 +13.20% FAIL
codedb_outline 150882 156435 +3.68% OK
codedb_read 54158 55494 +2.47% OK
codedb_search 142237 144327 +1.47% OK
codedb_snapshot 2024954 2050554 +1.26% OK
codedb_status 242217 240172 -0.84% OK
codedb_symbol 35977 43571 +21.11% FAIL
codedb_tree 45324 47138 +4.00% OK
codedb_word 39926 43020 +7.75% OK

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8bbe4447d1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/mcp.zig
}
@memcpy(slug_buf[0..repo.len], repo);
for (slug_buf[0..repo.len]) |*c| {
if (c.* == '/') c.* = '-';
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve unambiguous repo identity in wiki slug mapping

The wiki path derivation flattens owner/repo by replacing only / with -, which makes distinct valid repos collide (for example, foo/bar-baz and foo-bar/baz both map to foo-bar-baz). When both are indexed upstream, codedb_remote can return results for the wrong repository with no error, which can silently corrupt analysis. Use an unambiguous encoding (e.g., separate owner/repo params or escaping component dashes) before building slug.

Useful? React with 👍 / 👎.

@justrach justrach merged commit 1f04fad into release/0.2.579 Apr 22, 2026
1 check passed
@justrach justrach deleted the feat/remote-wiki-backend branch April 22, 2026 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant