pub struct App { /* private fields */ }Implementations§
Source§impl App
impl App
pub fn config(&self) -> &Config
Sourcepub fn cancel(&self)
pub fn cancel(&self)
Request graceful cancellation of the currently-running turn (if any). Safe to call from any task; the engine observes the token and halts at the next safe point.
Sourcepub fn permissions_cache(&self) -> Arc<SessionCache>
pub fn permissions_cache(&self) -> Arc<SessionCache>
Exposes the session cache so front-ends can write “Allow for session”
decisions resolved by the user. Exposed as Arc so callers can drop
their reference freely.
Sourcepub fn session_id(&self) -> String
pub fn session_id(&self) -> String
M3: the underlying motosan session id. Always populated; ephemeral sessions use a synthetic id internally.
Sourcepub async fn session_history(&self) -> Result<Vec<Message>>
pub async fn session_history(&self) -> Result<Vec<Message>>
M3: snapshot of the session’s persisted message history. Used by the
binary on --continue / --session to seed the TUI transcript so
the user can see what was said in prior runs. AgentSession::resume
already populates this internally for the agent to use as context
on the next turn; this method exposes it so the front-end can
render it too. Returns motosan’s Vec<Message> verbatim (callers
decide how to map roles → UI blocks; system messages are typically
dropped because they’re the prompt, not transcript).
Sourcepub async fn compact(&self) -> Result<()>
pub async fn compact(&self) -> Result<()>
Manually compact the current session’s context. Forces a one-shot
compaction (a zero-threshold ThresholdStrategy so should_compact
is always true), keeping the most recent few user turns. The
compaction marker is appended to the session jsonl like an
autocompact event.
Sourcepub async fn new_session(&self) -> Result<()>
pub async fn new_session(&self) -> Result<()>
Replace the live session with a brand-new empty one. An in-flight
turn (if any) keeps its own session snapshot and is unaffected; the
next send_user_message uses the new session.
Sourcepub async fn load_session(&self, id: &str) -> Result<()>
pub async fn load_session(&self, id: &str) -> Result<()>
Replace the live session with a stored session loaded by id. Errors if no session store is configured or the id is unknown.
Not turn-safe — see switch_model’s doc. Phase D2’s command
handler must gate this on no active turn.
Sourcepub async fn switch_model(&self, model: &ModelId) -> Result<()>
pub async fn switch_model(&self, model: &ModelId) -> Result<()>
Rebuild the live session with a different model, preserving the conversation. Requires a session store (the current session is resumed by id under the new model). Errors otherwise.
Not turn-safe. Like load_session, this resumes a session by
id. If a turn is still in flight on the old session when this is
called, that turn keeps writing entries under the same session_id
while the resumed session reads from it — a write/read interleaving
that the resumed session won’t observe until its next reload. The
App API does not expose a turn-in-progress flag, so the caller
(Phase D2’s /model / /resume command handlers in
forward_commands) MUST gate these calls on no active turn — the
active_turn bookkeeping already in forward_commands is exactly
that gate. D2’s plan must wire that guard; D1 documents the contract.
Sourcepub async fn disconnect_mcp(&self)
pub async fn disconnect_mcp(&self)
M4 Phase B: disconnect every registered MCP server (2s per-server timeout, best-effort). Call from the binary’s ctrl-C handler.