Title: VS Code + Colab frontends, with kernel-side scene replay (#281) by sspickle · Pull Request #293 · vpython/vpython-jupyter · GitHub
Open Graph Title: VS Code + Colab frontends, with kernel-side scene replay (#281) by sspickle · Pull Request #293 · vpython/vpython-jupyter
X Title: VS Code + Colab frontends, with kernel-side scene replay (#281) by sspickle · Pull Request #293 · vpython/vpython-jupyter
Description: What this is The kernel half of VPython support for VS Code notebooks and Google Colab (#281), plus the scene-replay architecture that makes both reliable. With this branch, VPython works in three hosts: Host Transport Module Classic Jupyter Comm down / websocket up (unchanged) with_notebook.py VS Code whole protocol over the kernel's tornado websocket with_wsfrontend.py Google Colab whole protocol over Jupyter comms with_colab.py Status: working end-to-end in both new hosts. Scenes render live — objects, animation via rate(), zoom/orbit interaction, textures; text() with fonts in VS Code — verified on macOS with VS Code 1.133 and in real Colab (including full-brightness scene replay across output-frame re-renders). VS Code: websocket-only mode Under VS Code (auto-detected via VSCODE_PID/VSCODE_CWD, overridable with VPYTHON_FRONTEND=ws|jupyter), vpython skips the classic Comm + nbextension machinery and speaks the entire wire protocol over the tornado websocket it already runs, announcing the port with a custom-MIME display output: application/vnd.vpython.v1+json {"api": 1, "port": N, "wsuri": "/ws"} The companion renderer extension — https://github.com/vpython/vscode-vpython — picks that up, loads GlowScript + glowcomm_host.js in the notebook output webview, connects, and drives the standard trigger ping-pong. Why websocket-only: VS Code's Jupyter extension deprecated third-party access to raw kernel messaging (the ipywidgets comm mechanism), so the classic Comm downlink is unreachable from a renderer extension — but a webview can open a WebSocket to the kernel's tornado server directly (both directions verified in a spike). Moving the downlink onto the websocket the kernel already runs makes the whole protocol renderer-reachable with no Jupyter plumbing at all. Colab: comm-only mode Colab is the mirror image: output frames are sandboxed cross-origin iframes that cannot reach the kernel's tornado port (the port-proxy authenticates with Google cookies that don't flow there), but Colab shims Jupyter comms (google.colab.kernel.comms). So with_colab.py runs the whole protocol over a comm instead. Colab's platform quirks shaped the design (each was found empirically): Browser-initiated handshake: the kernel registers a passive comm target at import; the JS calls comms.open when its frame has actually loaded. (Kernel-initiated opens race Colab's async iframe lifecycle; kernel-side retry loops make Colab drop display outputs.) A per-session nonce freezes out zombie frames from saved outputs. No import-time display: Colab always drops display output emitted during import, so the scene box is shown by an explicit wc.show() call. CDN bootstrap: large inline