Skip to main content

Host

Struct Host 

Source
pub struct Host { /* private fields */ }
Expand description

The injectable side-effect seam (ADR-0008). Construct once per session, share behind an Arc; holds the jail root + policy and the exec/truncation limits.

Implementations§

Source§

impl Host

Source

pub async fn read_file( &self, cwd: &Path, path: &Path, ) -> Result<FileRead, FsError>

Read a file (jail-resolved), returning its lossy-UTF-8 contents + stat.

§Errors

FsError::Path if the path escapes the jail; FsError::Io if the read fails.

Source

pub async fn write_file( &self, cwd: &Path, path: &Path, contents: &str, ) -> Result<FileStat, FsError>

Create-or-overwrite a file (jail-resolved), returning its post-write stat.

Does not auto-create parent directories (a mistyped nested path silently creating dirs is a footgun); a missing parent surfaces as an IO error.

§Errors

FsError::Path if the path escapes the jail; FsError::Io if the write fails.

Source

pub async fn create_dir( &self, cwd: &Path, path: &Path, parents: bool, exist_ok: bool, ) -> Result<(), FsError>

Create a directory (jail-resolved) — an explicit, opt-in mkdir, separate from Host::write_file, which deliberately never auto-creates dirs. A pack calls this when it wants a harness’s real “create the parent dir on write” behavior (e.g. Claude Code’s Edit/Write), without changing the footgun-avoidance default for everyone else.

  • parents — create missing intermediate dirs (mkdir -p); when false, a missing parent is an error.
  • exist_ok — succeed if the target dir already exists; when false, an existing target is an error (mkdir without -p’s tolerance).
§Errors

FsError::Path if the path escapes the jail; FsError::Io on a missing parent (when !parents), an existing target (when !exist_ok), or any other IO failure.

Source

pub async fn remove_file(&self, cwd: &Path, path: &Path) -> Result<(), FsError>

Remove a single file (jail-resolved). Never recursive — a directory target surfaces as an IO error (codex’s apply_patch refuses to delete a directory). The explicit delete seam for a pack that ports a real “delete file” behavior (codex apply_patch’s *** Delete File: and the source side of *** Move to:).

§Errors

FsError::Path if the path escapes the jail; FsError::Io if the removal fails (missing file, a directory target, or any other IO failure).

Source

pub async fn stat(&self, cwd: &Path, path: &Path) -> Result<FileStat, FsError>

Stat a file (jail-resolved).

§Errors

FsError::Path if the path escapes the jail; FsError::Io if the stat fails.

Source

pub async fn read_dir( &self, cwd: &Path, path: &Path, ) -> Result<Vec<DirEntry>, FsError>

List a directory’s immediate entries (jail-resolved), unsorted.

§Errors

FsError::Path if the path escapes the jail; FsError::Io if it is not a readable directory.

Source§

impl Host

Source

pub async fn resolve_in_jail( &self, cwd: &Path, candidate: &Path, ) -> Result<PathBuf, PathError>

Resolve candidate (absolute, ~-prefixed, or relative to cwd) to a concrete absolute path.

A leading ~ or ~/ is expanded against $HOME before anything else, so a model-supplied ~/.config/x names the real home path instead of a literal ~ directory under cwd. Only ~ and ~/… expand; ~user is left alone, and with no $HOME the path is unchanged. Expansion is not a permission: the expanded path still faces the jail below, and under PathPolicy::Jailed a home path outside the workspace is rejected as an escape — the point is that the rejection now names the path the caller actually meant.

Under PathPolicy::Jailed the result is guaranteed to live under the workspace root — .., absolute, and symlink escapes are rejected — while paths whose leaf does not yet exist (create-new-file) are still allowed. Under PathPolicy::Unrestricted the path is only made absolute; nothing is rejected.

§Errors

PathError::Escape if a jailed path escapes the root; PathError::Io if an ancestor cannot be canonicalized.

Source§

impl Host

Source

pub async fn exec( &self, req: ExecRequest, cancel: &CancellationToken, ) -> Result<ExecOutput, ExecError>

Run req through the shell, capturing output under the host’s limits and honoring cooperative cancel.

A command that fails, times out, or is cancelled is a successful capture with the corresponding fields set — the pack decides how to present it.

§Errors

ExecError::Spawn only if the shell process itself cannot be started.

Source

pub async fn run_capture( &self, program: &Path, args: &[String], cwd: &Path, timeout: Option<Duration>, cancel: &CancellationToken, ) -> Result<ExecOutput, ExecError>

Run a resolved program with explicit argv (no shell — safe for untrusted args like a regex or glob), capturing output under the same limits/kill/cancel machinery as Host::exec. Used by rg-backed tools (Task 11).

§Errors

ExecError::Spawn if the program cannot be started (e.g. rg not on PATH).

Source§

impl Host

Source

pub async fn walk( &self, cwd: &Path, path: &Path, opts: WalkOptions, ) -> Result<Vec<WalkEntry>, FsError>

Walk path (jail-resolved against cwd) with grok-style standard filters. Hidden files and .git are always skipped (standard_filters(true)); the three gitignore sources are toggled together by WalkOptions::respect_gitignore.

§Errors

FsError::Path when the jail rejects path; FsError::Io when the root does not exist or is unreadable.

Source

pub async fn is_path_ignored( &self, cwd: &Path, path: &Path, ) -> Result<bool, FsError>

Whether path (jail-resolved against cwd) is gitignored relative to the workspace’s git root. false when the workspace is not a git repo (grok’s allow-all rule). Non-existent paths fall back to their parent for resolution (grok’s new-file-creation case).

The matcher is built once per host from the git root’s .gitignore and .git/info/exclude. Known limitation vs grok (documented): nested .gitignore files in subdirectories are not consulted here — the Host::walk path handles them fully via the walker.

§Errors

FsError::Path when the jail rejects path.

Source§

impl Host

Source

pub fn add_root(&self, dir: &Path) -> Result<PathBuf, PathError>

Widen the jail with another root at runtime (/add-dir).

Returns the canonicalized root on success. Both forms are recorded, for the same reason Host::new records both: a root behind a symlink must still satisfy the lexical pre-check. Adding an already-present root is a no-op rather than an error, so repeating the command is harmless.

§Errors

PathError::InvalidRoot when dir does not exist or cannot be canonicalized — the jail is left untouched.

Source

pub fn new(config: HostConfig) -> Result<Self, PathError>

Build a host, canonicalizing workspace_root (the jail root must be a real, symlink-resolved absolute path).

§Errors

PathError::InvalidRoot if workspace_root does not exist or cannot be canonicalized.

Source

pub fn workspace_root(&self) -> &Path

The canonicalized jail root.

Source

pub fn path_policy(&self) -> PathPolicy

The active path policy.

Source

pub fn limits(&self) -> &ExecLimits

The shell execution limits.

Trait Implementations§

Source§

impl Clone for Host

Source§

fn clone(&self) -> Host

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Host

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Host

§

impl !RefUnwindSafe for Host

§

impl !UnwindSafe for Host

§

impl Send for Host

§

impl Sync for Host

§

impl Unpin for Host

§

impl UnsafeUnpin for Host

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.