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:
@ -73,6 +73,36 @@ pub enum AppError {
|
||||
node_id: NodeId,
|
||||
},
|
||||
|
||||
/// No live runtime can be restarted for the requested agent.
|
||||
#[error("runtime not found for agent {agent_id}")]
|
||||
RestartRuntimeNotFound {
|
||||
/// Agent whose runtime was requested.
|
||||
agent_id: AgentId,
|
||||
},
|
||||
|
||||
/// The requested cell does not host the requested live agent runtime.
|
||||
#[error("agent {agent_id} is not bound to cell {node_id}")]
|
||||
AgentNotBoundToCell {
|
||||
/// Agent supplied by the caller.
|
||||
agent_id: AgentId,
|
||||
/// Cell supplied by the caller.
|
||||
node_id: NodeId,
|
||||
},
|
||||
|
||||
/// More than one live runtime/cell currently represents the same agent.
|
||||
#[error("agent {agent_id} is visible in more than one live cell")]
|
||||
ConflictAgentVisibleElsewhere {
|
||||
/// Ambiguous agent.
|
||||
agent_id: AgentId,
|
||||
},
|
||||
|
||||
/// Runtime teardown did not reach its terminal boundary in time.
|
||||
#[error("timed out while stopping agent {agent_id} for restart")]
|
||||
RestartStopTimeout {
|
||||
/// Agent whose old runtime could not be stopped conclusively.
|
||||
agent_id: AgentId,
|
||||
},
|
||||
|
||||
/// The delegation target finished its structured/headless turn without producing
|
||||
/// a [`ReplyEvent::Final`](domain::ports::ReplyEvent::Final), so the rendezvous
|
||||
/// could not capture an inline answer. Surfaced promptly instead of blocking the
|
||||
@ -120,6 +150,10 @@ impl AppError {
|
||||
Self::Git(_) => "GIT",
|
||||
Self::Remote(_) => "REMOTE",
|
||||
Self::AgentAlreadyRunning { .. } => "AGENT_ALREADY_RUNNING",
|
||||
Self::RestartRuntimeNotFound { .. } => "RUNTIME_NOT_FOUND",
|
||||
Self::AgentNotBoundToCell { .. } => "AGENT_NOT_BOUND_TO_CELL",
|
||||
Self::ConflictAgentVisibleElsewhere { .. } => "CONFLICT_AGENT_VISIBLE_ELSEWHERE",
|
||||
Self::RestartStopTimeout { .. } => "STOP_TIMEOUT",
|
||||
Self::TargetReturnedNoReply(_) => "TARGET_RETURNED_NO_REPLY",
|
||||
Self::TargetCeilingActive(_) => "RENDEZVOUS_CEILING_ACTIVE",
|
||||
Self::Internal(_) => "INTERNAL",
|
||||
|
||||
@ -280,11 +280,13 @@ pub use window::{
|
||||
pub use workstate::{
|
||||
AgentBackgroundTaskState, AgentTicketState, AgentWorkState, AppExitWorkGuardDetail,
|
||||
AppExitWorkGuardState, AttachLiveAgent, AttachLiveAgentInput, AttachLiveAgentOutput,
|
||||
BackgroundTaskKindLabel, ConversationLogProvider, ConversationPreviewStatus,
|
||||
ConversationTurnWorkPreview, ConversationWorkSummary, GetAppExitWorkGuardState,
|
||||
GetAppExitWorkGuardStateInput, GetLiveStateLean, GetProjectWorkState, GetProjectWorkStateInput,
|
||||
LeanLiveEntry, LeanLiveState, LiveWorkSession, ProjectWorkState, ReconcileLiveState,
|
||||
ReconcileLiveStateInput, StopAgentExecutionCascade, StopAgentRuntime, StopLiveAgent,
|
||||
StopLiveAgentInput, StopLiveAgentOutput, TicketWorkSource, TicketWorkStatus, UpdateLiveState,
|
||||
UpdateLiveStateInput, LIVE_STATE_MAX_ENTRIES, LIVE_STATE_TTL_MS,
|
||||
BackgroundTaskKindLabel, CellAgentPresentation, ConversationLogProvider,
|
||||
ConversationPreviewStatus, ConversationTurnWorkPreview, ConversationWorkSummary,
|
||||
GetAppExitWorkGuardState, GetAppExitWorkGuardStateInput, GetLiveStateLean, GetProjectWorkState,
|
||||
GetProjectWorkStateInput, LeanLiveEntry, LeanLiveState, LiveWorkSession, ProjectWorkState,
|
||||
ReconcileLiveState, ReconcileLiveStateInput, RestartCellAgentRuntime,
|
||||
RestartCellAgentRuntimeInput, RestartCellAgentRuntimeOutput, StopAgentExecutionCascade,
|
||||
StopAgentRuntime, StopLiveAgent, StopLiveAgentInput, StopLiveAgentOutput, TicketWorkSource,
|
||||
TicketWorkStatus, UpdateLiveState, UpdateLiveStateInput, LIVE_STATE_MAX_ENTRIES,
|
||||
LIVE_STATE_TTL_MS,
|
||||
};
|
||||
|
||||
@ -32,7 +32,7 @@ use domain::ports::{
|
||||
use domain::project::ProjectPath;
|
||||
use domain::{
|
||||
AgentId, AgentProfile, BackgroundTask, BackgroundTaskKind, BackgroundTaskRendezvousLink,
|
||||
BackgroundTaskResult, BackgroundTaskState, BackgroundTaskWakePolicy, DomainEvent,
|
||||
BackgroundTaskResult, BackgroundTaskState, BackgroundTaskWakePolicy, DomainEvent, NodeId,
|
||||
OrchestratorCommand, OrchestratorVisibility, ProfileId, Project, RendezvousId, RuntimeAgentKey,
|
||||
TaskId,
|
||||
};
|
||||
@ -83,6 +83,20 @@ pub trait AgentSelfRestartScheduler: Send + Sync {
|
||||
agent: AgentId,
|
||||
reason: Option<String>,
|
||||
) -> Result<AgentRestartScheduled, AppError>;
|
||||
|
||||
/// Schedules the same restart while pinning it to a caller-validated cell.
|
||||
/// Implementations must revalidate the binding atomically with their
|
||||
/// concurrency guard before accepting the request.
|
||||
fn schedule_cell(
|
||||
&self,
|
||||
project: &Project,
|
||||
agent: AgentId,
|
||||
node: NodeId,
|
||||
reason: Option<String>,
|
||||
) -> Result<AgentRestartScheduled, AppError> {
|
||||
let _ = node;
|
||||
self.schedule(project, agent, reason)
|
||||
}
|
||||
}
|
||||
|
||||
/// Internal continuation prompt used when a self-restart is handed back to the
|
||||
|
||||
@ -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