Skip to main content

ScriptPolicy

Trait ScriptPolicy 

Source
pub trait ScriptPolicy:
    Send
    + Sync
    + 'static {
    type State: Default + Send + Sync + 'static;

    // Required method
    fn check(
        &self,
        script: &ScriptCheck<'_>,
        state: &Self::State,
    ) -> impl Future<Output = ScriptDecision> + Send;

    // Provided method
    fn ended(
        &self,
        end: &ScriptEnd<'_>,
        state: &Self::State,
    ) -> impl Future<Output = ()> + Send { ... }
}
Expand description

Decides whether a script may run, before it does.

Every script of the terminal tool, the main agent’s and every subagent’s, and every Shell::run, is put to every policy of its shell ahead of the approval it needs. The policies of one shell decide concurrently and the strictest decision wins.

A policy keeps what it remembers in its State: every agent’s terminal, each subagent’s included, starts with a fresh one and shares it with nobody else. Calls run in parallel, so the state is shared by reference and the policy chooses how to synchronise it.

Required Associated Types§

Source

type State: Default + Send + Sync + 'static

What the policy remembers for one agent.

Required Methods§

Source

fn check( &self, script: &ScriptCheck<'_>, state: &Self::State, ) -> impl Future<Output = ScriptDecision> + Send

Decides on script.

Provided Methods§

Source

fn ended( &self, end: &ScriptEnd<'_>, state: &Self::State, ) -> impl Future<Output = ()> + Send

Told once how every script put to Self::check ended, whichever policy decided what: refused, never started, failed or exited. The result of a foreground script reaches the caller only after this returns, so a state it records holds for the agent’s next call; a background script’s end is told after its call returned.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§