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
impl TerminalSurface
Sourcepub fn new(engine: SurfaceEngine, caller: Caller) -> Self
pub fn new(engine: SurfaceEngine, caller: Caller) -> Self
The terminal over engine, as caller.
Sourcepub fn voice(self, voice: TerminalVoice) -> Self
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.
Sourcepub fn session(self, session: impl Into<String>) -> Self
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.
Sourcepub fn theme(self, theme: ThemeChoice) -> Self
pub fn theme(self, theme: ThemeChoice) -> Self
Light, dark, or detected from the terminal’s background (the default).
Sourcepub fn model(self, model: impl Into<String>) -> Self
pub fn model(self, model: impl Into<String>) -> Self
The model, for the status line, such as claude-sonnet-5-5.
Sourcepub fn place(self, place: impl Into<String>) -> Self
pub fn place(self, place: impl Into<String>) -> Self
Where the agents run, for the status line, such as kernel or in process.
Sourcepub fn home(self, url: impl Into<String>) -> Self
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).
Sourcepub fn poll_interval(self, poll: Duration) -> Self
pub fn poll_interval(self, poll: Duration) -> Self
How often the terminal reads the engine when the source signals nothing sooner.
Sourcepub fn notice(self, text: impl Into<String>) -> Self
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.");Sourcepub fn notices_from(self, notices: UnboundedReceiver<String>) -> Self
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());
});Sourcepub fn open_sessions_with<F>(self, open: F) -> Self
pub fn open_sessions_with<F>(self, open: F) -> Self
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())),
}
})
});Sourcepub fn command(self, command: Arc<dyn TerminalCommand>) -> Self
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);Sourcepub fn restore_on_signals(self, enabled: bool) -> Self
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?;Sourcepub fn capable_terminal() -> bool
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.
Sourcepub async fn run(self, ui: UiMode) -> Result<i32>
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.
Sourcepub async fn run_json<W: Write + Send>(
self,
message: Option<String>,
out: W,
) -> Result<i32>
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 type | What |
|---|---|
command | The outcome of sending the message: sent or queued |
entry, decisions, reset | A FeedFrame of the session, as the engine projects it |
agent | An 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 |
end | outcome (done, error, waitingForYou, budgetReached), exitCode, sessionId, text |
§Errors
Returns the writer’s I/O error.
Sourcepub async fn screen(&self, cols: u16, rows: u16) -> Result<Vec<u8>>
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
impl Clone for TerminalSurface
Auto Trait Implementations§
impl !RefUnwindSafe for TerminalSurface
impl !UnwindSafe for TerminalSurface
impl Forget for TerminalSurface
impl Freeze for TerminalSurfacewhere
*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
impl Sync for TerminalSurface
impl Unpin for TerminalSurface
impl UnsafeUnpin for TerminalSurfacewhere
*const ArcInner<Inner> is !null: UnsafeUnpin,
PhantomData<ArcInner<Inner>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<String>: UnsafeUnpin,
*const ArcInner<Mutex<Option<UnboundedReceiver<String>>>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Mutex<Option<UnboundedReceiver<String>>>>>: UnsafeUnpin,
*const ArcInner<dyn Fn(Option<String>) -> Pin<Box<dyn Future<Output = Result<String, String>> + Send>> + Sync + Send> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn Fn(Option<String>) -> Pin<Box<dyn Future<Output = Result<String, String>> + Send>> + Sync + Send>>: UnsafeUnpin,
PhantomData<Arc<dyn TerminalCommand>>: UnsafeUnpin,
*const ArcInner<Mutex<Option<TerminalVoice>>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Mutex<Option<TerminalVoice>>>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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