feat: whygraph serve — the Explorer playground panel - #36
Merged
Conversation
A read-only, loopback-only web UI served from the existing Docker image as its own long-lived container, launched with `whygraph serve`. The web API is a thin second adapter over the exact service functions the MCP tools call, so the panel's rationale/evidence/history can never drift from the MCP's. Backend (src/whygraph/serve/, FastAPI): - graphdata: bounded ego-graph with server-computed layered coordinates + a lazy dir→file→symbol containment tree (no client-side force layout — the fix for the old viewer being slow/glitchy). - routes: /api search, tree, graph/ego, node detail, evidence, history, commit/pr/issue. Rationale is split — GET is cache-only (never calls an LLM); POST runs whygraph_rationale_brief verbatim (the explicit Generate action). - Phase 2: lifting (weighted, directional edge roll-up to dir/file super-nodes) + coverage heatmap + /api/graph/overview (the LOD landing view). - app: SPA fallback; degrades gracefully to an API-only "UI not built" page. CodeGraph: generalize _calls_relations into relations(kind, incoming); add imports_/container/children/files + Phase-2 file_edges/definition_ranges. Empirically confirmed the `contains` edge direction against real data. Playground (src/playground/): Vite + React + TS, Tailwind (shadcn-style), @xyflow/react ego graph + elkjs overview, TanStack Query, cmdk palette, and a single canonical openNode() used by search, graph clicks, and relationship rows. Delivery: multi-stage Dockerfile (arch-independent playground-build stage) + the `whygraph` shim's `serve` branch (loopback -p, WHYGRAPH_PORT, --detach/ --stop/--logs) + a hatch build hook that packs the bundle into the wheel via `artifacts`. Makefile gains `playground`, `playground-dev`, and a `dev` HMR loop. Deps: fastapi>=0.110, uvicorn>=0.27. 558 tests pass; ruff clean.
- New User Guide page: what the panel is, how to run it, the container lifecycle (--detach/--stop/--logs, WHYGRAPH_PORT), the tree/graph/detail layout, button-triggered rationale + the "scan first" caveat, the coverage heatmap, and the `make dev` HMR loop. - Add it to the mkdocs nav and a card on the User Guide + Quickstart index. - CLI reference: add the `whygraph serve` command (it was missing) with its --port/--host flags and the shim-level lifecycle verbs; fix the count. - Short mentions in README and the Quickstart.
…M config Clarify that the Generate button uses the [rationale] provider + [llm.<provider>] api_key from whygraph.toml (what `whygraph init` sets up), with the provider env var only as a fallback — not an env-first requirement.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
whygraph serve— a read-only, loopback-only web Explorer playground served from the existing Docker image as its own long-lived container. Browse the code graph CodeGraph built, jump to any symbol, and read its rationale, evidence, relationships, and history side by side.The web API is a thin second adapter over the exact service functions the MCP tools call (
whygraph_rationale_brief,whygraph_evidence_for,whygraph_area_history, the resource readers), so the panel's cards can never drift from what an editor sees over MCP. Replaces the old viewer that was slow/glitchy on large graphs.Why this design
[rationale]+[llm.<provider>]config fromwhygraph.toml— same provider, key, and cache as the MCP tool.What's in it
Backend (
src/whygraph/serve/, FastAPI):graphdata— ego graph + lazy containment tree with server coordinates.routes—/apisearch, tree, graph/ego, node detail, evidence, history, commit/pr/issue. Rationale split into cache-onlyGETand generatePOST.lifting+coverage+/api/graph/overview— Phase-2 weighted/directional edge roll-up to dir/file super-nodes + a coverage heatmap (the LOD landing view).app— SPA fallback; degrades to an API-only "UI not built" page when the bundle is absent.CodeGraph (
services/codegraph/graph.py): generalized_calls_relations→relations(kind, incoming); addedimports_/container/children/files+ Phase-2file_edges/definition_ranges. Confirmed thecontainsedge direction empirically against real data.Playground (
src/playground/): Vite + React + TS, Tailwind (shadcn-style),@xyflow/reactego graph +elkjsoverview, TanStack Query,cmdkpalette, and a single canonicalopenNode()used by search, graph clicks, and relationship rows.Delivery: multi-stage Dockerfile (arch-independent
playground-buildstage); thewhygraphshim'sservebranch (loopback-p,WHYGRAPH_PORT,--detach/--stop/--logs); a hatch build hook that packs the bundle into the wheel viaartifacts.Makefilegainsplayground,playground-dev, and adevHMR loop.Deps:
fastapi>=0.110,uvicorn>=0.27(lockfile updated).Docs: new "Explorer playground" guide page + nav;
whygraph serveadded to the CLI reference (it was missing); README + Quickstart mentions.Try it
Testing
ruff check+ruff format --checkclean.TestClientintegration incl. the rationale split (GET makes no LLM call; POST equalswhygraph_rationale_briefverbatim — proves zero drift)..codegraphdata (tree, Cmd-K, ego graph, node detail, overview) and the shim lifecycle against a stubbeddocker; wheel packs the bundle with nosrc/playgroundleak; the frontend Docker stage builds.Notes for reviewers
ruff+pytest; the SPA was verified via a real production build + manual end-to-end smoke.mkdocs build --strictgate runs in CI (thematerialtheme isn't installable in the dev sandbox); links/nav/anchors were validated mechanically here.