Skip to main content

Runner

Struct Runner 

Source
pub struct Runner {
    pub mode: RunnerMode,
    pub wsl_options: WslOptions,
    pub buffer_config: BufferConfig,
}
Expand description

Runner for cross-platform Claude CLI execution with automatic detection

Fields§

§mode: RunnerMode

The execution mode to use

§wsl_options: WslOptions

WSL-specific configuration options

§buffer_config: BufferConfig

Output buffering configuration

Implementations§

Source§

impl Runner

Source

pub fn detect_auto() -> Result<RunnerMode, RunnerError>

Detect the best runner mode automatically

On Windows:

  1. Try claude --version on PATH -> Native if succeeds
  2. Else try wsl -e claude --version -> WSL if returns 0
  3. Else: friendly preflight error suggesting wsl --install if needed

On Linux/macOS: always Native

Source

pub fn test_native_claude() -> Result<(), RunnerError>

Test if native Claude CLI is available

Source

pub fn test_wsl_claude() -> Result<(), RunnerError>

Test if WSL Claude CLI is available

Source

pub fn validate(&self) -> Result<(), RunnerError>

Validate the runner configuration

Source

pub fn description(&self) -> String

Get a user-friendly description of the runner configuration

Source§

impl Runner

Source

pub fn new(mode: RunnerMode, wsl_options: WslOptions) -> Self

Create a new Runner with the specified mode and options

Source

pub const fn with_buffer_config( mode: RunnerMode, wsl_options: WslOptions, buffer_config: BufferConfig, ) -> Self

Create a new Runner with custom buffer configuration

Source

pub fn parse_ndjson(stdout: &str) -> NdjsonResult

Parse NDJSON output from Claude CLI

Treats stdout as NDJSON where each line is a JSON object. Returns the last valid JSON object found, or NoValidJson with a tail excerpt.

§Arguments
  • stdout - The stdout content to parse
§Returns
  • NdjsonResult::ValidJson - If at least one valid JSON object was found (returns the last one)
  • NdjsonResult::NoValidJson - If no valid JSON was found (includes tail excerpt for error reporting)
Source

pub fn native() -> Self

Create a Runner with native mode

Source

pub fn auto() -> Result<Self, RunnerError>

Create a Runner with automatic detection

The runner will be in Auto mode and will detect the appropriate concrete mode (Native or WSL) during execution.

§Internal API

This is an internal helper for future use. The CLI only supports native and wsl modes via --runner-mode. Auto mode detection is handled internally when the config specifies runner_mode = "auto", but goes through Runner::with_buffer_config().

Source

pub async fn execute_claude( &self, args: &[String], stdin_content: &str, timeout_duration: Option<Duration>, ) -> Result<ClaudeResponse, RunnerError>

Execute Claude CLI with the configured runner mode

Uses wsl.exe --exec with argv (no shell) for WSL execution and pipes packet via STDIN. Records runner_distro from wsl -l -q or $WSL_DISTRO_NAME for WSL mode.

Source§

impl Runner

Source

pub fn get_claude_version_sync(&self) -> Result<String, RunnerError>

Get the Claude CLI version synchronously, respecting runner mode

This method is used during initialization to capture the Claude CLI version without requiring an async runtime. It correctly routes through WSL when the runner is configured for WSL mode.

§Returns
  • Ok(String) - The version string (e.g., “0.8.1”)
  • Err(RunnerError) - Failed to execute or parse version
Source§

impl Runner

Source

pub fn get_wsl_distro_name(&self) -> Option<String>

Get the WSL distro name from wsl -l -q or $WSL_DISTRO_NAME

Trait Implementations§

Source§

impl Clone for Runner

Source§

fn clone(&self) -> Runner

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Runner

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Runner

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.