Skip to main content

CommandHost

Trait CommandHost 

Source
pub trait CommandHost: Send + Sync {
    // Required methods
    fn commands(&self) -> Vec<CommandInfo>;
    fn changes(&self, name: &str, args: &str) -> bool;
    fn run<'life0, 'life1, 'async_trait>(
        &'life0 self,
        call: &'life1 CommandCall,
    ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn tightens<'life0, 'life1, 'async_trait>(
        &'life0 self,
        call: &'life1 CommandCall,
    ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn session_mode<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        user: &'life1 str,
        session: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn always_allow_offer<'life0, 'life1, 'async_trait>(
        &'life0 self,
        request: &'life1 ApprovalRequest,
    ) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn prepare_always_allow<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        request: &'life1 ApprovalRequest,
        by: &'life2 SubjectRef,
    ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn grant_always_allow<'life0, 'life1, 'async_trait>(
        &'life0 self,
        request: &'life1 ApprovalRequest,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

What the harness gives the kernel so a surface attached to it runs the REPL’s commands and answers “Always allow” (spec 3.3 §5.2, §7.2). A run’s CommandCall names the caller; the host runs a command in that person’s session only.

§Example

use adk_kernel::control::{CommandCall, CommandHost, CommandInfo};

struct Uptime;

#[async_trait::async_trait]
impl CommandHost for Uptime {
    fn commands(&self) -> Vec<CommandInfo> {
        vec![CommandInfo::new("uptime", "How long the kernel has run")]
    }

    fn changes(&self, _: &str, _: &str) -> bool {
        false
    }

    async fn run(&self, call: &CommandCall) -> adk_kernel::Result<String> {
        let place = if call.reach.is_local() { "here" } else { "over HTTP" };
        Ok(format!("Up 3 hours; you called {place}"))
    }
}

Required Methods§

Source

fn commands(&self) -> Vec<CommandInfo>

The commands, in /help order.

Source

fn changes(&self, name: &str, args: &str) -> bool

Whether /name args changes something — a rule, the memory, the mode — rather than reads: while everything is stopped, it is refused unless it tightens.

Source

fn run<'life0, 'life1, 'async_trait>( &'life0 self, call: &'life1 CommandCall, ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Runs call: /name args for its user in their session; returns what to show.

§Errors

A NotFound error for a command it does not offer, or the command’s error.

Provided Methods§

Source

fn tightens<'life0, 'life1, 'async_trait>( &'life0 self, call: &'life1 CommandCall, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Whether call, which changes something, only makes the agents do less — revokes a rule, forgets a fact, turns the sandbox on, sets a stricter mode — so it runs while everything is stopped, and a person can clean up before Resume all (spec 3.3 §5.2, S-I10). By default nothing does, and every change is refused until Resume all.

§Errors

The host’s error, such as a store it reads the session’s mode from.

Source

fn session_mode<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, user: &'life1 str, session: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

The mode of user’s session session, as the harness names it (read_only, plan, ask, auto); None when the host keeps no modes, and by default.

§Errors

The host’s error.

Source

fn always_allow_offer<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 ApprovalRequest, ) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

The words of “Always allow” for the waiting decision request, when the harness can make a standing rule of its call; None otherwise, and by default.

§Errors

The host’s error.

Source

fn prepare_always_allow<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, request: &'life1 ApprovalRequest, by: &'life2 SubjectRef, ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Makes the standing rule “Always allow” creates for the waiting decision request, as by, and keeps it until grant_always_allow; returns its words.

§Errors

An InvalidInput error when no standing rule applies to the call; by default, a Config error.

Source

fn grant_always_allow<'life0, 'life1, 'async_trait>( &'life0 self, request: &'life1 ApprovalRequest, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Grants the rule prepared for request, which was allowed.

§Errors

A NotFound error when no rule was prepared for it; by default, a Config error.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§