Skip to main content

CodeEngine

Struct CodeEngine 

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

The trusty_code_tui::TuiEngine adapter for tcode tui — see module docs.

Implementations§

Source§

impl CodeEngine

Source

pub async fn connect(project_path: Option<PathBuf>) -> Result<Self, EngineError>

Build a CodeEngine dialling the daemon’s well-known socket (crate::serve::uds::socket_path).

Why (#6637): this replaces discover, which raced a TCODE_DAEMON_URL against an http_addr file and liveness-pinged whichever it found. The socket path is derived from the data directory, so there is one answer and nothing to choose between. project_path is forwarded to session.create in setup() (mirrors session::protocol::create’s project param — None is a fully valid, projectless session).

§Errors

EngineError::NoDaemon when nothing is answering on the socket. This client does not start one — tcode tui’s auto-spawn owns that decision.

Source

pub fn with_socket( socket: impl Into<PathBuf>, project_path: Option<PathBuf>, ) -> Self

Build a CodeEngine dialling an explicit socket — the constructor tcode tui’s auto-spawn path and every test in tests/tui_client_engine.rs use.

(#8184) The session this engine creates runs the SOLO agent — see CodeEngine::with_socket_delegating for the PM opt-in.

Source

pub fn with_socket_delegating( socket: impl Into<PathBuf>, project_path: Option<PathBuf>, ) -> Self

CodeEngine::with_socket for a session that runs the DELEGATING PM — tcode tui --delegate (#8184).

Why: the interactive default is the solo agent, so PM/delegation mode needs one named surface to be asked for. A second constructor rather than a third parameter: every other call site wants the default. What: sends session.create’s delegate: true from setup. Test: tui_delegate_opt_in_creates_a_delegating_session (in tests/tui_client_engine.rs).

Source

pub fn daemon_socket(&self) -> &Path

The socket this engine dials (test/debug convenience).

Source

pub async fn cancel_session_outcome(&self) -> Result<CancelOutcome, EngineError>

Ask the daemon to cancel this session’s run and report WHICH of the two cancel outcomes came back (#8207).

Why: the daemon answers a confirmed stop and an unconfirmed one with two different things — a session snapshot and -32010 cancel_unconfirmed — but TuiEngine::cancel_session returns anyhow::Result<()>, which flattens the second into an opaque error string. That made the domain code unreadable from the only client that reaches it, which is what the code was minted to prevent. This is the typed half; the trait method below adapts it to the signature trusty-code-tui owns, and the TUI’s own “still cancelling…” render is a separate change in that crate. What: -32010 becomes CancelOutcome::StillCancelling carrying the daemon’s own sentence. Every other RPC or transport failure stays an error, and no session at all is CancelOutcome::NoSession — there was nothing to stop.

§Errors

EngineError::Rpc for any daemon refusal other than -32010, and EngineError::Transport for a socket failure. Test: engine_tests::cancel_unconfirmed_is_a_still_cancelling_outcome, engine_tests::any_other_refusal_stays_an_error.

Trait Implementations§

Source§

impl TuiEngine for CodeEngine

Source§

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

#8207: the trait’s Result<()> cannot carry the two-way outcome, so this adapts CodeEngine::cancel_session_outcome to it. An unconfirmed cancel stays an error — a cancel that did not land must not read as one that did — but with the daemon’s plain sentence rather than an opaque -32010 dump. The TUI reaches Self::cancel_session_reply instead, which keeps the distinction; this one-state form remains for a caller that only needs to know whether the request was delivered.

Source§

fn cancel_session_reply<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = CancelReply> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

#8207: project CodeEngine::cancel_session_outcome onto the TUI’s own CancelReply, which is the shape the TUI can render as three distinct states instead of “cancelled or not”.

Why: this is the crate boundary where the wire vocabulary has to stop. CancelReply’s payloads are shown to the user verbatim, and EngineError::Rpc’s own Display embeds the JSON-RPC code — which is exactly the daemon returned an error (-32003) shape #8207 was filed about. So a refusal is reduced to the daemon’s message here, where the code is still a separate field, rather than anywhere downstream where only a flattened string survives. What: the projection itself is [cancel_reply_from], so every arm is unit-testable without a daemon socket. Test: engine_tests::cancel_reply_reports_a_confirmed_stop, engine_tests::cancel_reply_keeps_an_unconfirmed_cancel_distinct, engine_tests::cancel_reply_strips_the_rpc_code_from_a_refusal.

Source§

fn respond_permission<'life0, 'async_trait>( &'life0 self, request_id: String, answer: PermissionAnswer, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Answer one suspended permission request over session.permission.respond (#3422).

Why: an ask rule parks the tool call inside the daemon’s gate (crate::permissions::gate), and only the daemon’s broker can release it — same thin-client reasoning as cancel_session above (DOC-39 §2.1 C-2, ADR-0063). The TUI decided nothing; it named a button. What: translates the shared crate’s PermissionAnswer into this daemon’s own PermissionDecision and sends its wire word, so the vocabulary has exactly one definition (crate::permissions::protocol). With no session yet (setup has not run) there is no request to answer, so this is a no-op rather than an error.

§Errors

Propagates the RPC failure, including the daemon’s -32602 for a request_id nobody is waiting on — an answer that did not land must not read as one that did. Test: respond_permission_releases_a_suspended_call, respond_permission_without_a_session_is_a_noop (both in tests/tui_client_engine.rs).

Source§

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

Engine-routed slash commands this MVP supports — served from the cache setup() populates (EngineState::commands_cache). This is a SYNCHRONOUS trait method (#3428) — the cache exists precisely so this never needs to perform network I/O on the calling path; see EngineState::commands’s docs for the std::sync::Mutex rationale.

Source§

fn picker(&self, name: &str) -> Option<PickerRequest>

The "workstream" picker — served from the cache EngineState::refresh_workstream_cache populates (in setup(), after /workstream activate, and on every observed WorkstreamActivationChanged). None for any other picker name (this engine has exactly one) or before the cache has been populated at least once. dispatch_command is "/workstream activate" — matching workstream_subcommand’s parsing exactly, so the shared event loop’s "{dispatch_command} {selected.id}" resubmission ("/workstream activate <id>") round-trips through handle_input correctly.

Source§

fn handle_input<'life0, 'async_trait>( &'life0 self, line: String, tx: UnboundedSender<ReplEvent>, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Process one submitted line — either free-form chat input or a slash command the shared router didn’t handle client-side. Read more
Source§

fn setup<'life0, 'async_trait>( &'life0 self, tx: UnboundedSender<ReplEvent>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Load initial state (session id, model, workstream, roster, …) before the render loop starts. Read more
Source§

fn subscribe_workstream_events<'life0, 'async_trait>( &'life0 self, tx: UnboundedSender<ReplEvent>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Open (or re-open) a subscription to backend-pushed events that aren’t direct responses to handle_input — chiefly workstream activation changes (DOC-48 §5.3). Read more
Source§

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

Graceful shutdown — close any open backend connections. 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<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<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
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> Same for T

Source§

type Output = T

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