Skip to content

VS Code graph: use Curiosity Engine's viewer only (0.14.1) - #17

Merged
benjsmith merged 1 commit into
mainfrom
feat/vscode-graph-ce-only
Oct 9, 2026
Merged

benjsmith merged 1 commit into
mainfrom
feat/vscode-graph-ce-only

Conversation

@benjsmith

Copy link
Copy Markdown
Owner

Switch Bay VS's Open Graph now mounts Curiosity Engine's own viewer (CEEmbed), the same one the PWA Graph tab has used since 0.14.0. The last in-repo fork of CE's wiki-view is deleted.

How it works

  • frontend/src/webview-graph.ts (built by vite.webview.config.ts into extensions/switchbay-vs/media/graph/) is a thin host. It loads CE's scripts with the shared loadCeModules, injects Switch Bay's ceEmbedShell.html, and mounts the canvas with CEEmbed.create.

  • The extension builds CE's wiki-view bundle with wiki_render.py, rebuilding it when it's older than the wiki or after a change. It serves the bundle's static/ and figures as webview resources. CSP: default-src 'none', scripts/styles/images/fonts from webview.cspSource only. localResourceRoots is media/graph + the bundle dir.

  • CE's API calls go to a virtual .invalid origin via window.ceApi. vscodeGraphBridge.ts turns those fetches into postMessage round-trips, and extensions/switchbay-vs/src/graphBundle.ts answers them from disk:

    • data.json
    • /api/page GET/POST, with CE's own rule: only notes/ and todos/ .md pages
    • curation history

    Everything else returns 404, like CE's server.

  • If CE isn't installed (ceViewerAvailable), the panel says "Graph needs Curiosity Engine" instead of breaking. This matches the PWA hiding its tab.

  • File watchers call refreshGraph(), which repaints an open graph on wiki-page or graph-db changes (debounced; bundle-build events are ignored). A switchbay.wikiRoot or workspace-folder change re-renders the panel for the new workspace.

  • Kept from the old webview:

    • Open markdown / Open preview / Reveal in Explorer / To plot / To sketch / To slideshow, in the page window and on right-click (classic)
    • search hits posted to the Wiki/Files trees
    • VS Code light/dark theme
    • curation replay
  • New: CE's page window (properties, body, subgraph, KaTeX, DOMPurify-sanitised) and note editing.

Removed

frontend/src/widgets/graph/: static/graph.js, static/modal.js, static/subgraph.js, static/vendor/knowledge-atlas.js, atlas.ts, init.ts, init-globals.ts, load.ts, template.ts, graphSearch.ts + graphSearch.test.ts, curationReplayAnim.ts, ce-graph.css, static.d.ts. GraphData moved to src/lib/graphTypes.ts, and the CE window globals are now in widgets/embed/ceGlobals.d.ts. The webview build no longer copies the PWA's public/ (icons, service worker) into the extension.

Also fixed (PWA too)

  • CE's embed never calls CurationReplay.init, so the replay button did nothing in the 0.14.0 Graph tab. bindCeReplay now wires it after each fresh canvas shell.
  • CE's Edit module forgets its "Saved" toast on re-init. A remount right after saving left the toast stuck and its timer threw. Remounts now wait for it (waitForCeToast).

Tests

  • New Node tests: vscodeGraphBridge.test.ts (7), plus one bindCeReplay test in ceHostBridge.test.ts. CE embed Node tests: 29/29.
  • New extension tests: graphBundle.test.ts (6). pnpm --dir extensions/switchbay-vs run test is 20/20.
  • New tests/unit/test_vscode_graph_ce_only.py (fork deleted, nothing references widgets/graph, the webview mounts CE, the extension handles missing CE). test_procedure_execution_palette.py no longer reads fork files.
  • Python unit suite: 1432 passed, 4 skipped. The 6 test_runtime.py failures are box-specific Node path resolution and also fail on main; they pass in CI.
  • tsc -b, the PWA vite build, build:webview, and the Playwright graph-ce-embed.spec.ts (3/3) all pass.
  • extensions/switchbay-vs/pnpm-workspace.yaml records explicit allowBuilds: false for keytar / @vscode/vsce-sign, so pnpm install --frozen-lockfile (pnpm 11) exits 0 for make vscode-compile.

CI changes (extension tests, new Node tests, graph-ce-embed e2e) aren't in this PR because the token has no workflow scope. A complete ci.yml is provided separately.

Parity table is in the comment below.

The Switch Bay VS graph view now mounts CE's own viewer (CEEmbed), the
same one the PWA Graph tab uses. The extension builds CE's wiki-view
bundle with wiki_render.py, serves its scripts and figures as webview
resources (CSP limited to the webview source, resource roots limited to
media/graph and the bundle), and answers CE's API calls over
postMessage: data.json (rebuilt when stale), /api/page for notes/todos
with CE's own path rules, and curation history.

The view keeps the old webview's features: open markdown / preview /
reveal / plot / sketch / slideshow (page window and right-click), search
hits marked in the Wiki and Files trees, VS Code light/dark theme. It
also gains CE's page window and note editing, repaints on wiki changes,
and reloads when the wiki root changes. Without a CE install it shows a
message instead of a graph.

Removes the remaining fork under frontend/src/widgets/graph (graph.js,
modal.js, subgraph.js, knowledge-atlas.js, atlas.ts, init.ts, load.ts,
template.ts, graphSearch, curationReplayAnim, ce-graph.css); GraphData
types move to src/lib/graphTypes.ts. A unit test keeps the fork out.

Also: wire CE's replay control (the embed never initialises it), and
wait for CE's "Saved" toast before a canvas remount so it can't stick.

Signed-off-by: benjsmith <benjamincharlessmith@gmail.com>
@benjsmith

Copy link
Copy Markdown
Owner Author

VS Code graph parity (CE viewer), commit be5da3b

How it was run. Headless Chromium against the built media/graph bundle. A small Node harness on 127.0.0.1:8815 plays the extension host. It applies the same HTML transform and CSP as graphWebviewHtml (webview.cspSource → the harness origin, plus connect-src for the harness transport only), provides acquireVsCodeApi(), and answers every postMessage with the extension's compiled out/graphBundle.js (answerCeApi, bundleFresh). Bundles were built with the same wiki_render.py build command as rebuildViewer. Workspaces: ml-walkthrough (234 pages / 622 edges, kuzu) and second-ws (9 pages). CE 1.9.2.

Check Result Detail
Mount ✅ CE classic viewer painted, status hidden, 0 CSP violations, 0 page errors
Counts ✅ data.json 234 nodes / 622 edges; drawn 234 / 622
view: Atlas ⇄ Classic ✅ Atlas canvas mounts in place, no navigation (CE's chooser would reload the webview)
Search / Escape ✅ "transformer": 6 hits → 6 wiki paths + 5 vault source paths posted to the Wiki/Files trees; Escape clears the box and sends empty hits
Page window ✅ Node click opens "[con] Transformer architecture" (body + subgraph); Open markdown / More… → To slideshow post open / deck with the right path; Escape closes
Right-click menu ✅ Classic node → Reveal in Explorer posts reveal:concepts/transformer-architecture.md
Note edit ✅ Padlock loads source over the bridge; Save writes wiki/notes/…md, rebuilds, and the page window re-renders with the edit
Edit scope ✅ Padlock hidden on concept pages; a bridged write to a concept page → HTTP 400
Theme ✅ vscode-light → data-theme=light (--bg #0f1115 → #f8f9fb); back to dark
Sanitising ✅ onerror / <script> / javascript: stripped from page HTML; window.__xss never set
Wiki-change refresh ✅ Add a page + refresh → 234→235 nodes incl. the new page; delete → 234
Replay ✅ Replay overlay opens; history fetched over the bridge
Workspace switch ✅ second-ws: 9 nodes drawn (data.json 9), its own page present, no ml-walkthrough pages
KaTeX ✅ $E = mc^2$ renders in the page window, no CSP violations or failed loads
No CE install ✅ (unit) ceViewerAvailable tests; the panel then shows "Graph needs Curiosity Engine" (not rendered headlessly)

Not exercised in a real VS Code. These steps ran in Chromium with the harness standing in for VS Code:

  • the vscode-webview:// resource URIs and VS Code's own webview CSP
  • onDidReceiveMessage / postMessage wiring in webviews.ts
  • the file watchers → refreshGraph() (simulated by posting {type:"refresh"} after marking the bundle stale)
  • the switchbay.wikiRoot change → re-render (simulated by loading the panel for the other workspace)
  • openWikiPage / revealInExplorer / the chat commands the posted messages trigger
  • the progress notification and warnings

The extension-side logic for these is the unchanged handler code from before, plus graphBundle.ts, which is unit-tested.

Feature check vs the old VS Code webview: nothing lost. Every old action is still there: open, preview, reveal, plot, sketch, slideshow, search → trees, theme, replay. CE's split control is removed in VS Code because splitting needs Switch Bay's daemon; the old webview didn't offer split either. Clicking a node now opens CE's page window instead of jumping straight to the markdown. Open markdown is one click away in that window and on right-click.

@benjsmith
benjsmith merged commit e1d8aac into main Oct 9, 2026
7 checks passed
@benjsmith
benjsmith deleted the feat/vscode-graph-ce-only branch October 12, 2026 06:01
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