pub struct CodeEngine { /* private fields */ }Expand description
The trusty_code_tui::TuiEngine adapter for tcode tui — see module docs.
Implementations§
Source§impl CodeEngine
impl CodeEngine
Sourcepub async fn connect(project_path: Option<PathBuf>) -> Result<Self, EngineError>
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.
Sourcepub fn with_socket(
socket: impl Into<PathBuf>,
project_path: Option<PathBuf>,
) -> Self
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.
Sourcepub fn with_socket_delegating(
socket: impl Into<PathBuf>,
project_path: Option<PathBuf>,
) -> Self
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).
Sourcepub fn daemon_socket(&self) -> &Path
pub fn daemon_socket(&self) -> &Path
The socket this engine dials (test/debug convenience).
Sourcepub async fn cancel_session_outcome(&self) -> Result<CancelOutcome, EngineError>
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
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,
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,
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,
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>
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>
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,
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,
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,
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,
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,
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,
handle_input — chiefly workstream activation
changes (DOC-48 §5.3). Read moreAuto Trait Implementations§
impl Freeze for CodeEngine
impl RefUnwindSafe for CodeEngine
impl Send for CodeEngine
impl Sync for CodeEngine
impl Unpin for CodeEngine
impl UnsafeUnpin for CodeEngine
impl UnwindSafe for CodeEngine
Blanket Implementations§
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
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