webview
Serve the knowledge graph database in an interactive web visualisation — pan and zoom, filter by node kind, search symbols, and inspect a node’s edges.
Source: src/commands/webview_command.ts ·
front-end: contribs/webview
Synopsis
npx codespine webview [options]Arguments
None.
Options
| Option | Default | Description |
|---|---|---|
-o, --output-folder <dir> | ./.codespine | Output folder; the Kùzu database is read from <dir>/graph.kuzu. |
-p, --port <port> | 4173 | HTTP port to listen on. |
-s, --source <dir> | . | Fallback project root for GitHub deep-links, used only when the graph recorded no source provenance (see GitHub links). |
What it does
- Resolves the database path and checks it exists. If not, it prints an error
(
database not found … — run extract then load first), sets exit code1, and returns. - Resolves the GitHub source. It prefers the provenance
extractrecorded in the database — the exact commit and in-repo prefix that was parsed — and falls back to detecting it live from--source. A found source is injected aswindow.GRAPH_SOURCE, so every node can deep-link to its declaration on GitHub at that commit; when neither is available, file paths render as plain text. - Reads the whole graph once at startup. It opens the Kùzu store and runs
two Cypher queries — one for all nodes, one for all edges — then serializes
the result into a JavaScript snippet that assigns
window.GRAPH_DATA. It logs how many nodes and edges were loaded. - Starts a plain Node
httpserver:GET /js_autogenerated/graph_data.jsreturns the in-memory graph snippet. This is the script the page loads on boot.- Every other path is served as a static file from the bundled
contribs/webview/webdirectory (/maps toindex.html). - The static file path is normalized and confined to the web root, so
requests cannot escape the directory with
..traversal. Anything outside it, or any missing file, returns404 not found.
- Prints the URL and waits. Stop it with
Ctrl+C.
Served MIME types cover .html, .css, .js, .json, .png, and .svg;
anything else falls back to application/octet-stream.
The visualisation
The page is a single interactive graph (Cytoscape) with a control sidebar:
- Search — find any symbol or file by name and jump to it.
- Colour by — switch the node encoding between structural (node kind),
runtime (a self-time heat map, after
enrich), and community (the module index fromcluster, drawn with a legend). - Filter — toggle node kinds and edge kinds on and off to isolate one layer
(just
CALLS, say, or hideParameternodes); hide whole communities. - Inspect — click a node for its details and one-hop edges, and follow it to its exact line on GitHub (below).
- Theme — dark or light, following the system preference.
GitHub links
When the served graph carries source provenance — recorded by
extract at build time, or detected live from --source —
each node links to its declaration on GitHub at the exact parsed commit. Built
outside a git checkout, and with no --source fallback, the visualisation shows
plain-text paths instead.
Output
loaded ~390 nodes, ~1.3k edges from /…/.codespine/graph.kuzu
✓ serving the knowledge graph at http://localhost:4173/
press Ctrl+C to stopExamples
# serve the default database on the default port
npx codespine webview
# choose a port
npx codespine webview --port 8080
# point GitHub links at a specific checkout when the graph recorded no source
npx codespine webview --source ../my-projectNotes and caveats
- The graph is read once, at startup. Edits to the database after the server
starts are not reflected — re-run
extractandload, then restartwebviewto see changes. - The whole graph is sent to the browser in one payload. This is fine for the graphs this tool produces; very large graphs will produce a large initial download.
- Holding the database open here can block a concurrent
load. Stop the server before reloading. - The static assets are resolved relative to the command’s own module, so the
same command works both from
src/(viatsx) and from the publisheddist/package.
See also
load— build the databasewebviewserves.contribs/webview— the front-end this command serves.
Last updated on