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,
) -> Result<Self>
pub fn with_backend( backend: Arc<dyn KernelBackend>, config: KernelConfig, ) -> Result<Self>
Create a kernel with a custom backend.
This constructor allows embedding kaish in other systems that provide their own storage backend (e.g., CRDT-backed storage in kaijutsu). The provided backend will be used for all file operations in builtins.
Note: A VfsRouter is still created internally for compatibility with
the vfs() method, but it won’t be used for execution context operations.
Sourcepub fn with_backend_and_virtual_paths(
backend: Arc<dyn KernelBackend>,
config: KernelConfig,
) -> Result<Self>
pub fn with_backend_and_virtual_paths( backend: Arc<dyn KernelBackend>, config: KernelConfig, ) -> Result<Self>
Create a kernel with a custom backend and automatic /v/* path support.
This is the recommended constructor for embedders who want their custom backend
to also support kaish’s virtual filesystems (like /v/jobs for job observability).
Paths are routed as follows:
/v/*→ Internal VFS (JobFs at/v/jobs, MemoryFs at/v/blobs, etc.)- Everything else → Your custom backend
§Example
let my_backend: Arc<dyn KernelBackend> = Arc::new(MyBackend::new());
let kernel = Kernel::with_backend_and_virtual_paths(my_backend, config)?;
// Now agents can use /v/jobs to monitor background commands
kernel.execute("cargo build &").await?;
kernel.execute("cat /v/jobs/1/stdout").await?;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.