Docs · API reference · Verso

Scaffold Class#

Core orchestrator: cell CRUD, kernel registry, execution dispatch, shared state, and subsystem hooks.

public sealed class Scaffold : System.IAsyncDisposable

Inheritance System.Object → Scaffold

Implements System.IAsyncDisposable

Properties#

FilePath Property#

The notebook's current file path, or null when the notebook has no backing file.

public string? FilePath { get; }

Property Value#

System.String

HostRestartHandler Property#

Optional external handler invoked instead of the in-process kernel restart. Set by host supervisors (e.g. the VS Code extension) that need to kill and respawn the entire process to release native resources like file handles pinned by the default AssemblyLoadContext.

When set, RestartKernelAsync(string) calls this handler and skips the in-process dispose/reinit cycle. When null, the in-process restart runs (used by CLI, REPL, and server hosts).

public System.Func<string?,System.Threading.Tasks.Task>? HostRestartHandler { get; set; }

Property Value#

System.Func<System.String,System.Threading.Tasks.Task>

InputRequester Property#

Optional front-end hook used by kernels that need a single line of user input during execution, such as PowerShell Read-Host.

public System.Func<System.Guid,string,bool,System.Threading.CancellationToken,System.Threading.Tasks.Task<string?>>? InputRequester { get; set; }

Property Value#

System.Func<System.Guid,System.String,System.Boolean,System.Threading.CancellationToken,System.Threading.Tasks.Task<System.String>>

LayoutCapabilities Property#

Gets the layout capabilities from the active layout, or all capabilities if no LayoutManager is active.

public Verso.Abstractions.LayoutCapabilities LayoutCapabilities { get; }

Property Value#

LayoutCapabilities

LayoutManager Property#

Gets the LayoutManager subsystem, or null if not initialized.

public Verso.LayoutManager? LayoutManager { get; }

Property Value#

LayoutManager

Metadata Property#

Notebook metadata in the form extensions see it, for hosts building an IVersoContext outside the execution pipeline.

public Verso.Abstractions.INotebookMetadata Metadata { get; }

Property Value#

INotebookMetadata

NotebookOps Property#

Gets the INotebookOperations implementation for this scaffold.

public Verso.Abstractions.INotebookOperations NotebookOps { get; }

Property Value#

INotebookOperations

OutputChannels Property#

Gets this notebook's output channels. A host that can route messages to a rendered output attaches an IOutputChannelTransport here; one that cannot leaves it alone, and the contexts handed to kernels report no channels at all so they write static output.

public Verso.Execution.OutputChannelHost OutputChannels { get; }

Property Value#

OutputChannelHost

SettingsManager Property#

Gets the SettingsManager subsystem, or null if not initialized.

public Verso.SettingsManager? SettingsManager { get; }

Property Value#

SettingsManager

ThemeContext Property#

Gets the active theme context. Delegates to the ThemeEngine if initialized, otherwise falls back to StubThemeContext.

public Verso.Abstractions.IThemeContext ThemeContext { get; }

Property Value#

IThemeContext

ThemeEngine Property#

Gets the ThemeEngine subsystem, or null if not initialized.

public Verso.ThemeEngine? ThemeEngine { get; }

Property Value#

ThemeEngine

Methods#

ClearAllOutputs() Method#

Clears all outputs from all cells in the notebook. Render-only cells (Markdown and other cell types whose "output" is the rendered form of their source rather than the result of kernel execution) are left untouched, so clearing outputs does not collapse them back to raw source. This matches Jupyter and Polyglot, where a rendered Markdown cell stays rendered when outputs are cleared.

public void ClearAllOutputs();

ExecuteCodeCaptureOutputsAsync(string, string, CancellationToken) Method#

Executes arbitrary code and returns both the execution result and the outputs it produced. The outputs accumulate on a transient cell that is never added to the notebook.

public System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<Verso.Abstractions.CellOutput>> ExecuteCodeCaptureOutputsAsync(string code, string? language=null, System.Threading.CancellationToken ct=default(System.Threading.CancellationToken));

Parameters#

code System.String

language System.String

ct System.Threading.CancellationToken

Returns#

System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<CellOutput>>

InitializeSubsystems() Method#

Initializes the ThemeEngine and LayoutManager from extensions discovered by the ExtensionHost. Call after LoadBuiltInExtensionsAsync().

public void InitializeSubsystems();

RefreshLiveOutputsAsync(Nullable<TimeSpan>, CancellationToken) Method#

Asks every live output for its current state and writes what comes back into the notebook, so that saving records what the reader is looking at rather than what the cell drew. Called by a host on its way into serialization.

public System.Threading.Tasks.Task RefreshLiveOutputsAsync(System.Nullable<System.TimeSpan> bound=null, System.Threading.CancellationToken ct=default(System.Threading.CancellationToken));

Parameters#

bound System.Nullable<System.TimeSpan>

ct System.Threading.CancellationToken

Returns#

System.Threading.Tasks.Task

Remarks#

Every output is asked at once and they share one deadline, so a notebook with ten live widgets costs what one does. An output that declines, fails, or has not answered when the deadline passes keeps the content it already had, which is the state it was last known to be in and always something a file can hold. A save is never blocked and never fails here.

A cell's output list has no lock shared with the executions that rebuild it, so this reads each list defensively and finds its way back by channel id rather than by remembering a position. A save arriving while a cell is running therefore refreshes what it can and leaves the rest as it was, which is the same outcome as an output that did not answer.

RenderTransientCellsAsync(CancellationToken) Method#

Renders every cell whose type is render-only (no kernel) and declares transient outputs (PersistsOutputs is false), when the cell has source but no outputs yet. Hosts call this when a notebook opens so markup cells (e.g. Markdown) display rendered on first paint instead of as raw source. The render pipeline runs directly: execution counts are not incremented and no execution events fire, so rendering at open cannot mark the notebook as edited.

public System.Threading.Tasks.Task RenderTransientCellsAsync(System.Threading.CancellationToken ct=default(System.Threading.CancellationToken));

Parameters#

ct System.Threading.CancellationToken

Returns#

System.Threading.Tasks.Task

RestartKernelAsync(string) Method#

Restarts a kernel. When HostRestartHandler is set the call is delegated externally (the supervisor will respawn the process); otherwise the kernel is disposed in-process, the variable store is cleared, and the kernel is re-warmed.

public System.Threading.Tasks.Task RestartKernelAsync(string? kernelId=null);

Parameters#

kernelId System.String

Returns#

System.Threading.Tasks.Task

SetFilePath(string) Method#

Updates the notebook file path used for resolving relative paths (e.g. in #!import). This is called after construction when the file path is not available at open time.

public void SetFilePath(string? filePath);

Parameters#

filePath System.String

WarmUpKernelAsync(string) Method#

Eagerly initializes a kernel so IntelliSense is available before the first execution. Safe to call concurrently; concurrent calls for the same language share a single init task.

public System.Threading.Tasks.Task WarmUpKernelAsync(string languageId);

Parameters#

languageId System.String

Returns#

System.Threading.Tasks.Task

Events#

OnCellExecuted Event#

Raised after a cell finishes execution and its CellModel execution metadata has been stamped (ExecutionCount, LastElapsed, LastStatus). Observers may read those fields directly from the cell.

public event Action<Guid>? OnCellExecuted;

Event Type#

System.Action<System.Guid>

OnCellExecuting Event#

Raised when a cell is about to begin execution. Fires once per cell for both single-cell and Run All paths. Observers (UI, variable explorer, binding router, host RPC bridge) use this to drive per-cell state transitions without polling.

public event Action<Guid>? OnCellExecuting;

Event Type#

System.Action<System.Guid>

OnCellOutputUpdated Event#

Raised when a cell receives output during execution before the cell has completed. Remote front-ends use this to refresh running cell output.

public event Action<Guid>? OnCellOutputUpdated;

Event Type#

System.Action<System.Guid>

OnKernelRestarted Event#

Raised after an in-process kernel restart completes and the fresh kernel is warm.

public event Action<string?>? OnKernelRestarted;

Event Type#

System.Action<System.String>

OnKernelRestartFailed Event#

Raised when an in-process kernel restart fails (dispose or warm-up threw). The old kernel is gone at this point, so observers should treat the kernel as unavailable until a later restart succeeds.

public event Action<string?,Exception>? OnKernelRestartFailed;

Event Type#

System.Action<System.String,System.Exception>

OnKernelRestarting Event#

Raised when an in-process kernel restart begins, before the old kernel is disposed. Not raised when HostRestartHandler is set: the external supervisor owns the restart lifecycle and its own progress signaling in that case.

public event Action<string?>? OnKernelRestarting;

Event Type#

System.Action<System.String>