RunMat
GitHub

Host Integration

The session API is intentionally host-neutral. Different frontends wrap it differently, but they all submit source through ExecutionRequest and consume structured results.

CLI REPL

The CLI REPL creates one RunMatSession, keeps it alive for the process, and submits each line as SourceInput::Text { name: "<repl>", text }. Special dot commands such as .stats, .gc, and .info are handled by the CLI before code reaches the session.

The CLI uses in-memory line-editor history. Persistent notebook or command history is not part of runmat-core.

WASM And TypeScript

RunMatWasm wraps RunMatSession for browser and TypeScript callers. Its main methods include:

MethodRole
executeRequestSubmit source and return a serialized execution payload.
resetSessionRecreate the underlying session while preserving configuration.
cancelExecutionRequest cooperative cancellation.
setInputHandlerRoute runtime input prompts to JavaScript.
workspaceSnapshotReturn workspace metadata and preview tokens.
materializeVariableMaterialize a workspace value by name or token.
exportWorkspaceState / importWorkspaceStatePersist or restore workspace replay payloads.
setFusionPlanEnabled / fusionPlanForSourceEmit or inspect fusion plan metadata.
clearWorkspace / disposeClear state and release host callbacks.

The WASM wrapper temporarily moves the Rust session out of its RefCell around async operations. This avoids holding a mutable borrow across await while preserving a single logical session.

Notebook Hosts

runmat-core does not define a notebook cell graph. Notebook-style hosts should keep their own cell model, source order, dirty state, execution history, and persistence. They should use the same RunMatSession when cells share a workspace, and they should provide meaningful source names so diagnostics and source identities remain useful.

Cell re-execution is host policy. The session only sees the source request it is asked to run and the workspace state already present in that session.

Editor And LSP Hosts

Editor integrations should use session results for runtime state, not for static language facts. Static parse/lower/diagnostic features belong in the compiler and LSP layers. Runtime workspace snapshots are useful for variable panes, hover previews, and live plotting state after execution.

Lifecycle Responsibilities

Hosts should:

  • Serialize requests per session.
  • Decide when to create, reset, or dispose sessions.
  • Persist notebook cells, command history, and UI layout outside runmat-core.
  • Use workspace deltas for routine updates and full snapshots when requested.
  • Treat preview tokens as short-lived.
  • Handle cancellation as cooperative.
  • Keep source names stable enough for diagnostics and source-bound workspace keys.