Skip to main content

Kernel

Struct Kernel 

Source
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

Source

pub fn new(config: KernelConfig) -> Result<Self>

Create a new kernel with the given configuration.

Source

pub fn transient() -> Result<Self>

Create a transient kernel (no persistence).

Source

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.

Source

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?;
Source

pub fn name(&self) -> &str

Get the kernel name.

Source

pub async fn execute(&self, input: &str) -> Result<ExecResult>

Execute kaish source code.

Returns the result of the last statement executed.

Source

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.

Source

pub async fn get_var(&self, name: &str) -> Option<Value>

Get a variable value.

Source

pub async fn set_var(&self, name: &str, value: Value)

Set a variable value.

Source

pub async fn list_vars(&self) -> Vec<(String, Value)>

List all variables.

Source

pub async fn cwd(&self) -> PathBuf

Get current working directory.

Source

pub async fn set_cwd(&self, path: PathBuf)

Set current working directory.

Source

pub async fn last_result(&self) -> ExecResult

Get the last result ($?).

Source

pub fn tool_schemas(&self) -> Vec<ToolSchema>

Get available tool schemas.

Source

pub fn jobs(&self) -> Arc<JobManager>

Get job manager.

Source

pub fn vfs(&self) -> Arc<VfsRouter>

Get VFS router.

Source

pub async fn reset(&self) -> Result<()>

Reset kernel to initial state.

Clears in-memory variables and resets cwd to root. History is not cleared (it persists across resets).

Source

pub async fn shutdown(self) -> Result<()>

Shutdown the kernel.

Auto Trait Implementations§

§

impl !Freeze for Kernel

§

impl !RefUnwindSafe for Kernel

§

impl Send for Kernel

§

impl Sync for Kernel

§

impl Unpin for Kernel

§

impl !UnwindSafe for Kernel

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

Source§

type Proj<U: 'src> = U

Source§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more