feat(backend,application,frontend,domain,web-server,app-tauri): bouton Redémarrer l'agent dans la barre supérieure des cellules — #317 (QA verte)
La cellule expose un bouton Redémarrer l'agent valable pour les trois modes de présentation (headless, TUI native, CLI custom), sans jamais prendre la présentation pour vérité runtime. - Application: use case RestartCellAgentRuntime validant le binding exact cellule/runtime via les snapshots live (RestartRuntimeNotFound, ConflictAgentVisibleElsewhere, AgentNotBoundToCell) puis déléguant au scheduler self-restart existant (schedule_cell); CellAgentPresentation purement informationnelle. - Backend/app-tauri/web-server: commande restart_cell_agent sur contrat DTO identique Tauri/HTTP, stop borné par timeout typé (RestartStopTimeout), relance préservant routage TUI natif, géométrie de cellule (node/rows/cols) et conversation; évenements domaine enrichis. - Frontend: bouton dans la barre de cellule avec confirmation, overlay d'état Redémarrage…/échec (libellés par code d'erreur, Fermer/ Réessayer), gardes d'identité de cellule et de restarts externes, gateway/mock/http adapters et ports alignés. - Tests: dto_agents, workstate_actions, contrats web-server, LayoutGrid.cellControlsLayering, adapters agent/mock/http. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -12,10 +12,10 @@ use std::sync::Arc;
|
||||
use async_trait::async_trait;
|
||||
use domain::input::InputMediator;
|
||||
use domain::live_state::WorkStatus;
|
||||
use domain::{AgentId, NodeId, Project, RuntimeAgentKey, SessionId};
|
||||
use domain::{AgentId, LayoutId, NodeId, Project, RuntimeAgentKey, SessionId};
|
||||
|
||||
use crate::error::AppError;
|
||||
use crate::orchestrator::{LiveStateProvider, OrchestratorService};
|
||||
use crate::orchestrator::{AgentSelfRestartScheduler, LiveStateProvider, OrchestratorService};
|
||||
use crate::terminal::{
|
||||
stop_live_agent_runtime_in_project, CloseTerminal, LiveSessionKind, LiveSessions,
|
||||
};
|
||||
@ -122,6 +122,113 @@ pub struct StopLiveAgentOutput {
|
||||
pub already_stopped: bool,
|
||||
}
|
||||
|
||||
/// Caller-side indication of how the hosting cell presents the agent.
|
||||
///
|
||||
/// This value is never trusted to select the runtime: the live registries and
|
||||
/// the launch context remain authoritative.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum CellAgentPresentation {
|
||||
/// Agent driven without an interactive human surface.
|
||||
Headless,
|
||||
/// Native provider terminal/TUI.
|
||||
Tui,
|
||||
/// IdeA structured/custom CLI chat.
|
||||
CustomCli,
|
||||
/// Older caller that cannot identify its presentation.
|
||||
Unknown,
|
||||
}
|
||||
|
||||
/// Input for [`RestartCellAgentRuntime::execute`].
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct RestartCellAgentRuntimeInput {
|
||||
/// Owning project resolved by the driving adapter.
|
||||
pub project: Project,
|
||||
/// Exact leaf whose runtime is being restarted.
|
||||
pub node_id: NodeId,
|
||||
/// Agent expected to be bound to `node_id`.
|
||||
pub agent_id: AgentId,
|
||||
/// Informational UI presentation; never used as runtime truth.
|
||||
pub presentation: CellAgentPresentation,
|
||||
/// Optional layout identity supplied by clients that already have it.
|
||||
pub layout_id: Option<LayoutId>,
|
||||
}
|
||||
|
||||
/// Immediate acknowledgement for an accepted atomic cell restart.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct RestartCellAgentRuntimeOutput {
|
||||
/// Restart correlation id used by the existing restart event stream.
|
||||
pub restart_id: String,
|
||||
/// Validated agent identity.
|
||||
pub agent_id: AgentId,
|
||||
/// Validated hosting node.
|
||||
pub node_id: NodeId,
|
||||
/// Actual runtime family resolved from the live registry.
|
||||
pub kind: LiveSessionKind,
|
||||
/// Informational presentation echoed for caller correlation.
|
||||
pub presentation: CellAgentPresentation,
|
||||
/// Optional layout identity echoed for caller correlation.
|
||||
pub layout_id: Option<LayoutId>,
|
||||
}
|
||||
|
||||
/// Atomically validates a cell/runtime binding and schedules its replacement
|
||||
/// through IdeA's existing restart coordinator.
|
||||
pub struct RestartCellAgentRuntime {
|
||||
live: Arc<LiveSessions>,
|
||||
scheduler: Arc<dyn AgentSelfRestartScheduler>,
|
||||
}
|
||||
|
||||
impl RestartCellAgentRuntime {
|
||||
/// Builds the use case over the authoritative runtime registry and restart seam.
|
||||
#[must_use]
|
||||
pub fn new(live: Arc<LiveSessions>, scheduler: Arc<dyn AgentSelfRestartScheduler>) -> Self {
|
||||
Self { live, scheduler }
|
||||
}
|
||||
|
||||
/// Validates the exact live binding before the scheduler repeats that check
|
||||
/// under its per-agent concurrency guard and accepts the detached restart.
|
||||
pub fn execute(
|
||||
&self,
|
||||
input: RestartCellAgentRuntimeInput,
|
||||
) -> Result<RestartCellAgentRuntimeOutput, AppError> {
|
||||
let snapshots = self
|
||||
.live
|
||||
.live_agent_snapshots_for(input.project.id, &input.agent_id);
|
||||
let snapshot = match snapshots.as_slice() {
|
||||
[] => {
|
||||
return Err(AppError::RestartRuntimeNotFound {
|
||||
agent_id: input.agent_id,
|
||||
});
|
||||
}
|
||||
[snapshot] => *snapshot,
|
||||
_ => {
|
||||
return Err(AppError::ConflictAgentVisibleElsewhere {
|
||||
agent_id: input.agent_id,
|
||||
});
|
||||
}
|
||||
};
|
||||
if snapshot.node_id != input.node_id {
|
||||
return Err(AppError::AgentNotBoundToCell {
|
||||
agent_id: input.agent_id,
|
||||
node_id: input.node_id,
|
||||
});
|
||||
}
|
||||
let scheduled = self.scheduler.schedule_cell(
|
||||
&input.project,
|
||||
input.agent_id,
|
||||
input.node_id,
|
||||
Some("redémarrage demandé depuis la cellule".to_owned()),
|
||||
)?;
|
||||
Ok(RestartCellAgentRuntimeOutput {
|
||||
restart_id: scheduled.restart_id,
|
||||
agent_id: input.agent_id,
|
||||
node_id: input.node_id,
|
||||
kind: snapshot.kind,
|
||||
presentation: input.presentation,
|
||||
layout_id: input.layout_id,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Best-effort stopper for execution resources owned by one live agent turn.
|
||||
///
|
||||
/// Implementations must be idempotent: a missing, already-finished or already-stopped
|
||||
|
||||
@ -10,8 +10,10 @@ mod live;
|
||||
mod reconcile;
|
||||
|
||||
pub use actions::{
|
||||
AttachLiveAgent, AttachLiveAgentInput, AttachLiveAgentOutput, StopAgentExecutionCascade,
|
||||
StopAgentRuntime, StopLiveAgent, StopLiveAgentInput, StopLiveAgentOutput,
|
||||
AttachLiveAgent, AttachLiveAgentInput, AttachLiveAgentOutput, CellAgentPresentation,
|
||||
RestartCellAgentRuntime, RestartCellAgentRuntimeInput, RestartCellAgentRuntimeOutput,
|
||||
StopAgentExecutionCascade, StopAgentRuntime, StopLiveAgent, StopLiveAgentInput,
|
||||
StopLiveAgentOutput,
|
||||
};
|
||||
pub use live::{
|
||||
GetLiveStateLean, LeanLiveEntry, LeanLiveState, UpdateLiveState, UpdateLiveStateInput,
|
||||
|
||||
Reference in New Issue
Block a user