Front-Ends#
Verso has three front-ends that consume the engine. Two are visual (Blazor Server and VS Code) and share the same Razor component library. The third is the CLI, which drives the engine headlessly. All three use the same engine API, so the notebook behavior is identical regardless of hosting environment.
Shared UI (Verso.Blazor.Shared)#
The Verso.Blazor.Shared project is a Razor Class Library that contains every UI component used by both the Blazor Server and VS Code front-ends. Neither host implements its own notebook rendering. They inject an INotebookService and the shared components handle everything.
Key Components#
| Component | Description |
|---|---|
Cell.razor |
Full cell widget: gutter (run button, cell index, collapse chevron), toolbar (cell type, language, actions), Monaco editor, and output area. Handles all MIME types inline including HTML, SVG, Mermaid, images, JSON trees, and CSV tables. |
Toolbar.razor |
Top-level notebook toolbar: file operations (hidden in VS Code), run all, layout switcher, theme switcher, export menu, and extension-defined actions. |
MonacoEditor.razor |
Monaco editor wrapper with parameters for value, language, and callbacks for completions, hover, and diagnostics. |
LayoutRenderer.razor |
Hosts the active layout, portaling cells into the layout's HTML for custom-renderer layouts. |
CustomLayoutFrame.razor |
Sandboxed iframe host for isolated layout renderers. |
ExtensionPanel.razor |
Sidebar listing loaded extensions with enable/disable controls. |
CellPropertiesPanel.razor |
Cell properties sidebar showing extension-contributed property sections for the selected cell. Conditional on the active layout's SupportsPropertiesPanel flag. |
VariableExplorer.razor |
Variable inspector sidebar showing all shared variables. |
ThemeProvider.razor |
Injects CSS variables from the active theme into a <style> tag. |
SettingsPanel.razor |
Extension settings editor. |
ExtensionConsentDialog.razor |
Modal dialog for approving third-party extension packages. |
INotebookService#
INotebookService (namespace Verso.Blazor.Shared.Services) is the abstraction that decouples the UI from the engine. It covers notebook CRUD, cell operations, execution, IntelliSense, layout/theme switching, extension management, variable exploration, toolbar actions, and cell interaction dispatch.
Each hosting environment provides its own implementation:
| Host | Implementation | Engine Access |
|---|---|---|
| Blazor Server | ServerNotebookService |
Direct, in-process |
| VS Code (WASM) | RemoteNotebookService |
JSON-RPC via host process |
Editor diagnostics#
Hover and completions are pulled: Monaco asks for them. Diagnostics are pushed: monaco-interop.js decides when to ask, calls MonacoEditor.GetDiagnostics, which goes through Cell.razor to INotebookService.GetDiagnosticsAsync, and replaces the cell's markers under the owner verso-kernel. ServerNotebookService calls the kernel in process; RemoteNotebookService sends kernel/getDiagnostics to Verso.Host.
The refresh policy is set by the expensive kernels, where a request is a full compilation:
- Edit: debounced, 500 ms after the last change the user makes. Text set from .NET (a reload, a tool editing cells) does not ask unless that editor has focus; the next focus asks instead.
- Focus: when a cell's editor gains focus, since variable-dependent kernels (SQL, HTTP, HTML) change their answer when another cell runs, not when this text changes. Skipped when the text is the version last answered and nothing has happened since that could change the answer (a run ending, a restart, a language change).
- Run: after the cell's own run finishes.
- Restart: markers are cleared in every cell, whichever kernel restarted, not recomputed.
While any cell is running no request is issued (NotebookCellContext.IsAnyExecuting, passed to the editor as DiagnosticsSuspended). Verso.Host answers requests one at a time, so a request during a run would wait for the run, and some kernels answer empty while executing. A refresh asked for in that time runs once the run is over. One request is in flight per editor; a reply for text that has since changed is dropped; a failed request (null) keeps the markers that are showing, while an empty list clears them. Cells over 2,000 lines are not analyzed.
Monaco's bundled TypeScript worker would otherwise mark JavaScript and TypeScript cells as if each were a standalone file, so its validation is turned off when Monaco loads; its completion and hover stay on.
Isolated (iframe) layouts need more than the base notebook operations, so hosts also implement IIsolatedLayoutHost (an extension of INotebookService in Verso.Blazor.Shared.Services). It covers frame allocation, renderer-package fetch, mount and unmount lifecycle, the message pump between the frame and the kernel, and theme propagation. Blazor Server implements it in-process; Blazor WASM implements it over JSON-RPC.
Static Assets#
The shared project includes JavaScript interop files in wwwroot/js/:
| File | Purpose |
|---|---|
monaco-interop.js |
Monaco editor initialization, completions, hover, diagnostics |
cell-interact-interop.js |
Click/event dispatch for interactive cell outputs |
cell-drag-interop.js |
Cell reordering via drag-and-drop |
dashboard-interop.js |
Dashboard grid drag and resize |
parameters-interop.js |
Parameter cell form event delegation |
mermaid-interop.js |
Mermaid diagram rendering |
katex-interop.js |
KaTeX typesetting of TeX math in rendered Markdown |
panel-resize-interop.js |
Sidebar resize handle |
file-download-interop.js |
Browser download trigger (Server mode) |
user-prefs-interop.js |
VS Code global state read/write |
tag-input-interop.js |
Tag input field (comma/Enter to add tags) for the properties panel |
Blazor Server (Verso.Blazor)#
The simplest hosting model. The engine runs in-process alongside the Blazor Server app. There is no serialization boundary between the UI and the engine.
Startup#
Program.cs configures a standard Blazor Server application:
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents(options => {
options.DisconnectedCircuitRetentionPeriod = TimeSpan.FromHours(1);
});
builder.Services.AddScoped<INotebookService, ServerNotebookService>();
The DisconnectedCircuitRetentionPeriod is set to one hour so users can recover from brief network interruptions without losing their session.
ServerNotebookService#
ServerNotebookService (namespace Verso.Blazor.Services) directly holds a Scaffold and ExtensionHost. When a notebook is opened or created:
- Creates a fresh
ExtensionHostand callsLoadBuiltInExtensionsAsync() - Wires the consent handler for the extension approval dialog
- Creates a
Scaffoldwith the notebook model and extension host - Calls
InitializeSubsystems()to populate themes, layouts, and settings - Subscribes to engine events (
OnVariablesChanged,OnExtensionStatusChanged, etc.) - Warms up kernels in the background via
Task.Run
Engine events are forwarded to the UI through Action? events on the service, which trigger Blazor's StateHasChanged() to re-render.
Project References#
Verso.Blazor references the engine (Verso), all kernel extension packages (Verso.FSharp, Verso.JavaScript, Verso.Python, Verso.PowerShell, Verso.Ado, Verso.Http), the DataFrame formatter package (Verso.DataFrame), and the shared UI library (Verso.Blazor.Shared). The PowerShell host adapter is internal to Verso.PowerShell.
VS Code Extension#
The VS Code front-end uses a three-process architecture:
+--------------------------+ JSON-RPC +------------------+
| VS Code Extension | <-- stdin/stdout -> | Verso.Host.dll |
| (TypeScript, node.js) | | (.NET process) |
+--------------------------+ +------------------+
| |
| postMessage | Scaffold
v | ExtensionHost
+--------------------------+ |
| Blazor WASM Webview | Engine runs here
| (browser sandbox) |
+--------------------------+
Extension Entry Point#
extension.ts activates by:
- Resolving the path to
Verso.Host.dll - Registering
BlazorEditorProvideras aCustomEditorProviderfor.versofiles withretainContextWhenHidden: true - Conditionally registering Copilot chat participant and language model tools if the
vscode.chatandvscode.lmAPIs are available
BlazorEditorProvider#
When a .verso file is opened:
- Creates a
VersoDocumentwrapping the file URI - Sets up the webview with
localResourceRootspointing to the bundled Blazor WASM assets - Spawns a dedicated
HostProcess(one .NET process per open notebook) - Creates a
BlazorBridgeconnecting the webview to that host - Sends
notebook/opento the host to initialize the engine session - Notifies the WASM app that the notebook is ready
Each open notebook gets its own host process and bridge. When the editor panel is closed, the host process is terminated.
Save operations flow through the host: saveCustomDocument sends notebook/save to the host, receives serialized content, and writes it via vscode.workspace.fs.writeFile. The request carries an optional format parameter (default "verso") that selects the serializer by FormatId. When the verso.preserveOriginalFormat setting is enabled and the document's extension matches a writable non-native serializer (currently .ipynb), the editor sends format: "jupyter" so the file round-trips in place; otherwise it falls back to the original convert-to-.verso behavior.
HostProcess#
HostProcess (TypeScript, vscode/src/host/hostProcess.ts) manages a dotnet Verso.Host.dll child process. Communication is line-delimited JSON-RPC over stdin/stdout:
start()spawns the process and waits for thehost/readynotificationsendRequest<T>(method, params)writes a JSON-RPC request, stores a pendingPromise, and resolves it when the response arrivesonNotification(method, handler)registers callbacks for server-push notificationsdispose()sendshost/shutdownand force-kills after a timeout
BlazorBridge#
BlazorBridge (TypeScript, vscode/src/blazor/blazorBridge.ts) is the relay between the WASM webview and the host process:
- Listens for
jsonrpc-requestmessages from the webview - Injects the
notebookIdinto every request - Forwards to the host via
HostProcess.sendRequest() - Returns results to the webview as
jsonrpc-responsemessages - Forwards host notifications (
cell/executionState,variable/changed, etc.) to the webview asjsonrpc-notificationmessages - Intercepts a small set of operations locally (file save dialogs, user preferences)
- Tracks mutation methods and fires
onDidEdit()for VS Code dirty-document tracking
Blazor WASM (Verso.Blazor.Wasm)#
The WASM project runs in the webview sandbox. It references only Verso.Abstractions and Verso.Blazor.Shared. It has no reference to the engine or any kernel project.
RemoteNotebookService implements INotebookService by forwarding all calls through VsCodeBridge, which calls into JavaScript interop (vscode-bridge.js) to post messages to the VS Code extension.
The WASM app maintains a local state cache populated from the notebook/opened notification. Source updates are debounced (250ms) before forwarding to the host to avoid flooding the JSON-RPC channel during fast typing.
Some requests use a detached bridge path instead of awaiting the full JSON-RPC round-trip inside the webview call stack. This allows the webview to keep processing host notifications while a long-running request such as execution/run is still pending.
WebviewNavigationManager stubs NavigationManager with app:/// as the base URI because the vscode-webview:// scheme is not parseable by System.Uri.
Message Flow#
A complete round-trip for a cell execution in VS Code:
Cell.razor calls NotebookService.ExecuteCellAsync(cellId)
-> RemoteNotebookService calls VsCodeBridge.RequestAsync("execution/run", { cellId })
-> VsCodeBridge calls JS vscodeBridge.sendRequest("execution/run", paramsJson)
-> vscode-bridge.js posts { type: "jsonrpc-request", method, params } to VS Code
-> BlazorBridge receives the message
-> Enriches params with notebookId
-> HostProcess.sendRequest("execution/run", enrichedParams)
-> Writes JSON-RPC line to Verso.Host stdin
-> HostSession dispatches to ExecutionHandler
-> Scaffold.ExecuteCellAsync runs the pipeline
-> Result written as JSON-RPC response to stdout
-> HostProcess resolves the pending Promise
-> BlazorBridge posts { type: "jsonrpc-response", result } to webview
-> vscode-bridge.js resolves the pending Promise
-> VsCodeBridge deserializes and returns to RemoteNotebookService
-> RemoteNotebookService fires UI events
-> Components re-render
Notifications (execution state changes, variable updates) flow in the reverse direction without a request ID.
Live Output and Interactive Input#
Kernels can append outputs while a cell is still running. In VS Code, this uses the output/update host notification:
Kernel calls context.WriteOutputAsync(output)
-> ExecutionPipeline appends the output and notifies Scaffold
-> HostSession sends output/update { notebookId, cellId }
-> BlazorBridge forwards the notification to the webview
-> RemoteNotebookService refreshes the local cell output cache
-> Notebook components re-render before execution/run completes
Kernels can also request a single input value through IExecutionContext.RequestInputAsync. VS Code handles this with input/request and input/response:
Kernel calls context.RequestInputAsync(prompt, isPassword, ct)
-> NotebookSession creates a pending input request
-> HostSession sends input/request { notebookId, requestId, cellId, prompt, isPassword }
-> BlazorBridge shows a VS Code input box
-> BlazorBridge sends input/response { notebookId, requestId, value, cancelled }
-> NotebookSession resolves the pending request
-> Kernel execution resumes
input/response is handled by the host read loop outside the normal sequential request queue. This is required because the queued execution/run request is still active while the kernel is waiting for the user's answer.
Verso.Host#
Verso.Host is a console application that serves as the engine host for VS Code. It communicates via line-delimited JSON-RPC on stdin/stdout.
Startup#
Program.cs sets console encoding to UTF-8, emits a host/ready notification, then enters a read loop on stdin. A shared stdoutLock ensures atomic response writes. Incoming messages are queued through a Channel<T> and dispatched sequentially by HostSession. A small set of re-entrant responses, such as extension/consentResponse and input/response, are handled directly in the read loop so they can unblock an already-running request.
HostSession and NotebookSession#
HostSession manages multiple concurrent notebook sessions keyed by generated IDs (nb-1, nb-2, etc.). DispatchAsync routes methods to typed handler classes via a large switch expression:
| Handler | Methods |
|---|---|
NotebookHandler |
open, close, save, getLanguages, getCellTypes, setFilePath |
CellHandler |
add, insert, remove, move, updateSource, changeType, changeLanguage |
ExecutionHandler |
run, runAll, cancel |
KernelHandler |
restart, getCompletions, getDiagnostics, getHoverInfo |
OutputHandler |
clearAll |
InteractionHandler |
interact (cell interaction dispatch) |
LayoutHandler |
getLayouts, switch, render, getCellContainer |
ThemeHandler |
getThemes, switch, getTheme |
ExtensionHandler |
list, enable, disable, consentResponse |
SettingsHandler |
getDefinitions, get, update, reset |
ToolbarHandler |
getEnabledStates, execute |
PropertiesHandler |
getSections, updateProperty, getSupported |
ParameterHandler |
list, add, update, remove |
VariableHandler |
list, inspect |
Method names are centralized in Protocol.MethodNames. The TypeScript protocol.ts in the VS Code extension mirrors the same method names.
NotebookSession also owns session-scoped callbacks that are not exposed as standalone handler classes. It subscribes to Scaffold.OnCellOutputUpdated and sends output/update, and it implements the pending request table for input/request / input/response.
CLI (Verso.Cli)#
The CLI is a .NET global tool with six commands. It references all kernel packages and the Blazor Server project.
verso serve#
Builds a Kestrel-hosted Blazor Server application via BlazorHostBuilder. This reuses the same ServerNotebookService and shared Razor components as the standalone Verso.Blazor project. The builder detects whether the static web assets manifest is valid (running from build output vs. installed as a global tool) and switches between Development and Production mode accordingly. In Production mode, bundled wwwroot files are served via PhysicalFileProvider.
verso run#
Creates a HeadlessRunner that builds a Scaffold and ExtensionHost, resolves parameters from --param flags (with type coercion against the notebook's parameter definitions), and executes cells sequentially. Output is rendered to the terminal via OutputRenderer (text mode) or written as structured JSON via JsonOutputWriter. Exit codes are deterministic for CI integration.
verso convert#
Uses the extension host's serializers to read a notebook in one format and write it in another. Supports .verso, .ipynb, and .dib as input formats. Output format is specified with --to. The --strip-outputs flag removes all cell outputs before writing.
verso info#
Displays the CLI version, .NET runtime version, engine version, and all discovered extensions, serializers, and formatters.