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 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, or relative to cwd) to a concrete absolute path.

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 new(config: HostConfig) -> Result<Host, 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<(), Error>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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<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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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