Solidifie le cycle stop/restart d'un agent visible en cellule: - terminal/registry: kill effectif de la TUI native et de la CLI custom, arrêt idempotent du live runtime (PTY + structuré), distinction nette « agent stoppé » vs « pas de session ». - workstate + lifecycle: projection d'un état runtime explicite « stopped » (AgentRuntimeState: running/stopping/stopped/failedStart), réconcilié avec le live state; traitement des courses « agent not found ». - relance froide via freshStart: repart de zéro sans réattacher une session morte et recharge la configuration courante de l'agent (y compris changement de modèle). - contrat projeté côté adapters frontend (ports/domain/normalization/mock) pour la consommation UI future (#197/#198), sans surface UI ici. Tests QA verts: workstate_actions, orchestrator_service stop_agent, agent_lifecycle (reopen/fresh_start), workstate stopped runtime state, vitest adapter stop_live_agent.
40 lines
2.0 KiB
Rust
40 lines
2.0 KiB
Rust
//! Terminal use cases (ARCHITECTURE §6, L3).
|
|
//!
|
|
//! Each use case is a struct carrying its ports as `Arc<dyn Port>` and exposing a
|
|
//! single `execute(input) -> Result<output, AppError>` method (**Single
|
|
//! Responsibility**). They talk **only** to the [`domain::ports::PtyPort`] (plus
|
|
//! the [`domain::ports::EventBus`] for `OpenTerminal`); the composition root
|
|
//! injects the concrete [`infrastructure::PortablePtyAdapter`].
|
|
//!
|
|
//! - [`OpenTerminal`] — resolve the cwd, spawn a PTY, create a
|
|
//! [`domain::TerminalSession`], register the live handle, publish an event.
|
|
//! - [`WriteToTerminal`] — forward bytes (keystrokes) to a PTY.
|
|
//! - [`ResizeTerminal`] — resize a PTY.
|
|
//! - [`CloseTerminal`] — kill a PTY and forget its handle.
|
|
//!
|
|
//! # Where the active-session registry lives, and why
|
|
//!
|
|
//! The domain [`PtyPort`] is *handle-oriented*: `spawn` returns a
|
|
//! [`domain::ports::PtyHandle`] that every later call (`write`/`resize`/`kill`)
|
|
//! must reference. Something has to remember, per [`SessionId`], the live
|
|
//! `PtyHandle` (and the `TerminalSession` snapshot) between IPC calls. That state
|
|
//! is **not domain state** (it is the in-flight wiring of an I/O resource), and
|
|
//! it must not live in the adapter alone (other use cases need to address a
|
|
//! session by id). It therefore lives in [`TerminalSessions`], an **application
|
|
//! service** injected into the terminal use cases (and held in the composition
|
|
//! root behind an `Arc`). This keeps the domain pure and the registry shared,
|
|
//! testable, and transport-agnostic.
|
|
|
|
mod registry;
|
|
mod usecases;
|
|
|
|
pub use registry::{
|
|
LiveAgentRegistry, LiveRuntimeState, LiveRuntimeStatus, LiveSessionKind, LiveSessionSnapshot,
|
|
LiveSessions, StructuredSessions, TerminalSessions,
|
|
};
|
|
pub use usecases::{
|
|
stop_live_agent_runtime_in_project, CloseTerminal, CloseTerminalInput, CloseTerminalOutput,
|
|
OpenTerminal, OpenTerminalInput, OpenTerminalOutput, ResizeTerminal, ResizeTerminalInput,
|
|
StoppedAgentRuntime, WriteToTerminal, WriteToTerminalInput,
|
|
};
|