Skip to main content

ToolContext

Struct ToolContext 

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

Proof that a tool invocation has passed the capability leash, carrying the least-authority caveats it is permitted to act under.

Constructible only inside this crate (see ToolContext::mint, called solely by crate::Gate::authorize). There is intentionally no public constructor and no pub field — that un-forgeability is the enforcement.

Implementations§

Source§

impl ToolContext

Source

pub fn caveats(&self) -> &Caveats

The effective (least-authority) caveats this invocation may act under.

Source

pub fn sandbox_kind(&self) -> SandboxKind

The OS-level sandbox actually in force for this invocation.

Source

pub fn strength_floor(&self) -> AxisEnforcement

The required fence strength (ADR 0012 D3): a confinement site refuses to spawn when the real backend cannot enforce every restricted axis at or above this floor. Default is the permissive AxisEnforcement::Advisory (set on the crate::Gate); a strong principal raises it to Kernel.

Source

pub fn check_exec(&self, program: &str) -> Result<(), ToolError>

Leash check: may this invocation execute program?

Allowed iff exec is All, or the bounded exec scope contains the program as named (the string passed in, typically argv0 or a PATH-resolved absolute path) or its basename (Path::new(program).file_name()).

This is what makes bare-name grants usable: a grant of ["git"] allows git, /usr/bin/git, and /opt/homebrew/bin/git alike, because the resolved absolute path the interceptor hands in has basename git. To pin an exact executable instead, grant a full path: a grant of ["/usr/bin/git"] matches only /usr/bin/git, not a git found elsewhere on PATH.

Security tradeoff: a bare-name grant authorizes any binary named git reachable on PATH (PATH ordering / shadowing decides which one actually runs). When that ambiguity is unacceptable, grant the full path to pin exactly. A grant that contains a path separator only ever matches that exact path (its basename is still considered, but a grant like ["/bin/echo"] will not be matched by a bare echo because the grant’s own basename echo is compared against the program token, not the reverse — see [exec_scope_allows]). Out-of-scope programs are denied here, before the tool spawns anything.

Source

pub fn check_net(&self, host: &str) -> Result<(), ToolError>

Leash check: may this invocation reach network host?

Source

pub fn check_path_read(&self, path: &Path) -> Result<(), ToolError>

Leash check: may this invocation read path?

See Self::check_path_write for the canonicalization contract; the only difference is which axis (fs_read) is consulted.

Source

pub fn check_path_write(&self, path: &Path) -> Result<(), ToolError>

Leash check: may this invocation write path?

Canonicalizes first, then tests membership (DESIGN §6): the path is resolved to a real, symlink-free location and rejected if it escapes the granted scope via .. or a symlink. Membership is a containment test against each granted scope entry (an entry authorizes that path and its descendants), computed on canonical paths — never a raw string prefix. This closes the @repo/../../etc traversal class.

Trait Implementations§

Source§

impl Clone for ToolContext

Source§

fn clone(&self) -> ToolContext

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 ToolContext

Source§

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

Formats the value using the given formatter. 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<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<F, T> ConvertInto<T> for F
where T: ConvertFrom<F>,

Source§

fn convert_into(self) -> T

Infallibly converts a value of type Self to a value of type T.
Source§

impl<F, T> ConvertTryFrom<F> for T
where F: ConvertInto<T>,

Source§

type Error = !

The type of an error that can occur during a conversion. Read more
Source§

fn convert_try_from(value: F) -> Result<T, !>

Fallibly converts a value of type F to a value of type Self.
Source§

impl<F, T> ConvertTryInto<T> for F
where T: ConvertTryFrom<F>,

Source§

type Error = <T as ConvertTryFrom<F>>::Error

The type of an error that can occur during a conversion. Read more
Source§

fn convert_try_into(self) -> Result<T, <T as ConvertTryFrom<F>>::Error>

Fallibly converts a value of type Self to a value of type T.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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