pub struct Kernel { /* private fields */ }Expand description
The Kernel (核) — executes kaish code.
This is the primary interface for running kaish commands. It owns all the runtime state: variables, tools, VFS, jobs, and persistence.
Implementations§
Source§impl Kernel
impl Kernel
Sourcepub fn new(config: KernelConfig) -> Result<Self>
pub fn new(config: KernelConfig) -> Result<Self>
Create a new kernel with the given configuration.
Sourcepub fn with_backend(
backend: Arc<dyn KernelBackend>,
config: KernelConfig,
configure_vfs: impl FnOnce(&mut VfsRouter),
) -> Result<Self>
pub fn with_backend( backend: Arc<dyn KernelBackend>, config: KernelConfig, configure_vfs: impl FnOnce(&mut VfsRouter), ) -> Result<Self>
Create a kernel with a custom backend and /v/* virtual path support.
This is the constructor for embedding kaish in other systems that provide their own storage backend (e.g., CRDT-backed storage in kaijutsu).
A VirtualOverlayBackend routes paths automatically:
/v/*→ Internal VFS (JobFs at/v/jobs, MemoryFs at/v/blobs)- Everything else → Your custom backend
The optional configure_vfs closure lets you add additional virtual mounts
(e.g., /v/docs for CRDT blocks) after the built-in mounts are set up.
Note: The config’s vfs_mode is ignored — all non-/v/* path routing
is handled by your custom backend. The config is only used for name, cwd,
skip_validation, and interactive.
§Example
// Simple: default /v/* mounts only
let kernel = Kernel::with_backend(backend, config, |_| {})?;
// With custom mounts
let kernel = Kernel::with_backend(backend, config, |vfs| {
vfs.mount_arc("/v/docs", docs_fs);
vfs.mount_arc("/v/g", git_fs);
})?;Sourcepub async fn execute(&self, input: &str) -> Result<ExecResult>
pub async fn execute(&self, input: &str) -> Result<ExecResult>
Execute kaish source code.
Returns the result of the last statement executed.
Sourcepub async fn execute_streaming(
&self,
input: &str,
on_output: &mut dyn FnMut(&ExecResult),
) -> Result<ExecResult>
pub async fn execute_streaming( &self, input: &str, on_output: &mut dyn FnMut(&ExecResult), ) -> Result<ExecResult>
Execute kaish source code with a per-statement callback.
Each statement’s result is passed to on_output as it completes,
allowing callers to flush output incrementally (e.g., print builtin
output immediately rather than buffering until the script finishes).
External commands in interactive mode already stream to the terminal
via Stdio::inherit(), so the callback mainly handles builtins.
Sourcepub async fn last_result(&self) -> ExecResult
pub async fn last_result(&self) -> ExecResult
Get the last result ($?).
Sourcepub fn tool_schemas(&self) -> Vec<ToolSchema>
pub fn tool_schemas(&self) -> Vec<ToolSchema>
Get available tool schemas.
Sourcepub fn jobs(&self) -> Arc<JobManager>
pub fn jobs(&self) -> Arc<JobManager>
Get job manager.
Trait Implementations§
Source§impl CommandDispatcher for Kernel
impl CommandDispatcher for Kernel
Source§fn dispatch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
cmd: &'life1 Command,
ctx: &'life2 mut ExecContext,
) -> Pin<Box<dyn Future<Output = Result<ExecResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn dispatch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
cmd: &'life1 Command,
ctx: &'life2 mut ExecContext,
) -> Pin<Box<dyn Future<Output = Result<ExecResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Dispatch a command through the Kernel’s full resolution chain.
This is the single path for all command execution when called from the pipeline runner. It provides the full dispatch chain: user tools → builtins → .kai scripts → external commands → backend tools.