Skip to main content

TerminalSurface

Struct TerminalSurface 

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

The terminal surface over an engine, for one caller (spec 3.3 §5.2).

The caller is the person at the keyboard: SurfaceKind::Terminal with Origin::Keyboard, and with_paired_local only when the terminal reaches the kernel on its own machine, which lets it approve high-risk calls and resume after a stop (§7.2, S-I10).

Implementations§

Source§

impl TerminalSurface

Source

pub fn new(engine: SurfaceEngine, caller: Caller) -> Self

The terminal over engine, as caller.

Source

pub fn voice(self, voice: TerminalVoice) -> Self

Talks with the agents by voice (spec 3.3 §5.6; feature voice): the conversation’s own session is the thread shown, its state is a line above the message box — in the inline UI, what it heard and each countdown are printed into the scrollback — and c cancels a spoken “allow once” while it counts down. In process only: the conversation runs on the hub’s harness. JSON output and piped input have no voice conversation.

Source

pub fn session(self, session: impl Into<String>) -> Self

Opens session. Without one, the terminal opens the session of the oldest decision waiting for the caller, else a new session.

Source

pub fn theme(self, theme: ThemeChoice) -> Self

Light, dark, or detected from the terminal’s background (the default).

Source

pub fn model(self, model: impl Into<String>) -> Self

The model, for the status line, such as claude-sonnet-5-5.

Source

pub fn place(self, place: impl Into<String>) -> Self

Where the agents run, for the status line, such as kernel or in process.

Source

pub fn home(self, url: impl Into<String>) -> Self

The web home’s address, such as http://127.0.0.1:8080: a decision with images links to itself there, and o opens it (spec 3.7 §8.2, board choice A16).

Source

pub fn poll_interval(self, poll: Duration) -> Self

How often the terminal reads the engine when the source signals nothing sooner.

Source

pub fn notice(self, text: impl Into<String>) -> Self

A line the full-screen and inline UIs show under the thread when they start, such as a workspace that is not trusted (spec 3.3 §5.2). JSON mode writes none.

§Example
let me = Caller::human("ana", SurfaceKind::Terminal, Origin::Keyboard);
let terminal = TerminalSurface::new(engine, me)
    .notice("Instruction files in this workspace are not loaded: it is not trusted.");
Source

pub fn notices_from(self, notices: UnboundedReceiver<String>) -> Self

Lines the full-screen and inline UIs show under the thread as they arrive on notices, as notice shows one at the start: what work the application runs beside the terminal found, such as long-term memory catching up on earlier sessions. JSON mode writes none. Once the terminal has ended, a send fails and hands the line back, so the application can print it.

§Example
let (tx, rx) = tokio::sync::mpsc::unbounded_channel();
let me = Caller::human("ana", SurfaceKind::Terminal, Origin::Keyboard);
let terminal = TerminalSurface::new(engine, me).notices_from(rx);
tokio::spawn(async move {
    let _ = tx.send("2 facts from an earlier session were added".to_string());
});
Source

pub fn open_sessions_with<F>(self, open: F) -> Self
where F: Fn(Option<String>) -> BoxFuture<'static, Result<String, String>> + Send + Sync + 'static,

How /session opens a session in the full-screen and inline UIs: open gets the id typed, or None for /session new, and returns the session to show, or why it may not be opened, which the terminal shows. Without it, any id opens as given. An application whose sessions are bound to something, such as the workspace a harness works in, checks and records that binding here (spec 3.3 §5.2).

§Example
let me = Caller::human("ana", SurfaceKind::Terminal, Origin::Keyboard);
let terminal = TerminalSurface::new(engine, me).open_sessions_with(|requested| {
    Box::pin(async move {
        match requested {
            Some(id) if id.starts_with("ops-") => Ok(id),
            Some(id) => Err(format!("session {id} is not one of this workspace's")),
            None => Ok(format!("ops-{}", uuid::Uuid::new_v4())),
        }
    })
});
Source

pub fn command(self, command: Arc<dyn TerminalCommand>) -> Self

Adds a slash command: /name args in the message box runs it and shows what it returns, and Tab completes its name (spec 3.3 §5.2). The terminal’s own commands win over one of the same name, and so does the first one added.

§Example
let me = Caller::human("ana", SurfaceKind::Terminal, Origin::Keyboard);
let terminal = TerminalSurface::new(engine, me).command(todos);
Source

pub fn restore_on_signals(self, enabled: bool) -> Self

Whether the full-screen and inline UIs give the terminal back on SIGINT, SIGTERM and SIGHUP (Ctrl-C elsewhere) and end with 130, 143 or 129: on by default.

The handlers are tokio’s, which last as long as the process: once run has returned, these signals no longer end the process unless something else handles them. An application that goes on after the terminal and relies on their default action turns this off and handles them itself.

§Example
let me = Caller::human("ana", SurfaceKind::Terminal, Origin::Keyboard);
// This application serves on after the terminal and handles its own signals.
TerminalSurface::new(engine, me).restore_on_signals(false).run(UiMode::FullScreen).await?;
Source

pub fn capable_terminal() -> bool

Whether standard input and output are a terminal the full-screen UI (spec 3.3 §5.2) can draw on: both are terminals, TERM is not dumb, and the window is at least 60 by 16.

Source

pub async fn run(self, ui: UiMode) -> Result<i32>

Runs the terminal until the person leaves, or a signal ends it; returns the exit code (spec 3.3 §5.2).

Full screen takes the alternate screen, raw mode and bracketed paste; inline takes raw mode and bracketed paste and prints into the scrollback. Both give the terminal back on exit, on a panic in the terminal’s own code (a panic another task catches, such as a tool’s, leaves it), and on SIGINT, SIGTERM and SIGHUP unless restore_on_signals turns that off. With standard input not a terminal, or TERM=dumb, inline writes plain lines, each line read is a message, and the run ends as run_json does once input ends and the turn settles.

§Errors

Returns the terminal’s I/O error, or the engine’s error from the first read.

Source

pub async fn run_json<W: Write + Send>( self, message: Option<String>, out: W, ) -> Result<i32>

Sends message (when given) and writes the session’s engine events to out, one JSON object per line, until the turn settles; then an end line, and returns the exit code (spec 3.3 §5.2).

Line typeWhat
commandThe outcome of sending the message: sent or queued
entry, decisions, resetA FeedFrame of the session, as the engine projects it
agentAn agent a person added changed while the run lasted (spec 3.3 §5.7): change is added, changed, paused, resumed or removed, agent its roster row
endoutcome (done, error, waitingForYou, budgetReached), exitCode, sessionId, text
§Errors

Returns the writer’s I/O error.

Source

pub async fn screen(&self, cols: u16, rows: u16) -> Result<Vec<u8>>

One frame of the full-screen UI (spec 3.3 §5.2) as a terminal of cols by rows receives it — the escape sequences and text, drawn from what the engine shows now, with the decision keys live — for tests, screenshots and documentation. Auto draws the dark set, in 24-bit colour.

§Errors

Returns the engine’s error from reading the shown session’s thread.

Trait Implementations§

Source§

impl Clone for TerminalSurface

Source§

fn clone(&self) -> Self

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 TerminalSurface

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for TerminalSurface

§

impl !UnwindSafe for TerminalSurface

§

impl Forget for TerminalSurface

§

impl Freeze for TerminalSurface
where *const ArcInner<Inner> is !null: Freeze, PhantomData<ArcInner<Inner>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, PhantomData<String>: Freeze, *const ArcInner<Mutex<Option<UnboundedReceiver<String>>>> is !null: Freeze, PhantomData<ArcInner<Mutex<Option<UnboundedReceiver<String>>>>>: Freeze, *const ArcInner<dyn Fn(Option<String>) -> Pin<Box<dyn Future<Output = Result<String, String>> + Send>> + Sync + Send> is !null: Freeze, PhantomData<ArcInner<dyn Fn(Option<String>) -> Pin<Box<dyn Future<Output = Result<String, String>> + Send>> + Sync + Send>>: Freeze, PhantomData<Arc<dyn TerminalCommand>>: Freeze, *const ArcInner<Mutex<Option<TerminalVoice>>> is !null: Freeze, PhantomData<ArcInner<Mutex<Option<TerminalVoice>>>>: Freeze,

§

impl Move for TerminalSurface

§

impl Send for TerminalSurface
where Arc<Inner>: Send, RawVecInner: Send, Arc<Mutex<Option<UnboundedReceiver<String>>>>: Send, Arc<dyn Fn(Option<String>) -> Pin<Box<dyn Future<Output = Result<String, String>> + Send>> + Sync + Send>: Send, Arc<dyn TerminalCommand>: Send, Arc<Mutex<Option<TerminalVoice>>>: Send,

§

impl Sync for TerminalSurface
where Arc<Inner>: Sync, RawVecInner: Sync, Arc<Mutex<Option<UnboundedReceiver<String>>>>: Sync, Arc<dyn Fn(Option<String>) -> Pin<Box<dyn Future<Output = Result<String, String>> + Send>> + Sync + Send>: Sync, Arc<dyn TerminalCommand>: Sync, Arc<Mutex<Option<TerminalVoice>>>: Sync,

§

impl Unpin for TerminalSurface

§

impl UnsafeUnpin for TerminalSurface

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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> 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> 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