fix(runtime): stop/restart d'agent visible robuste — kill réel, état stopped, relance froide (#196, QA verte)

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.
This commit is contained in:
2026-08-12 14:56:02 +02:00
parent 4e93fa2f20
commit bad7b4c2f3
23 changed files with 440 additions and 46 deletions

View File

@ -150,11 +150,19 @@ function normalizeAgent(value: unknown, index: number): AgentWorkState {
const agent = isRecord(value) ? value : {};
const liveKind: "pty" | "structured" =
isRecord(agent.live) && agent.live.kind === "structured" ? "structured" : "pty";
const runtimeState = normalizeRuntimeState(agent.runtimeState ?? agent.runtime_state);
const live = isRecord(agent.live)
? {
nodeId: stringValue(agent.live.nodeId),
sessionId: stringValue(agent.live.sessionId),
kind: liveKind,
...(normalizeRuntimeState(agent.live.runtimeState ?? agent.live.runtime_state)
? {
runtimeState: normalizeRuntimeState(
agent.live.runtimeState ?? agent.live.runtime_state,
),
}
: {}),
}
: undefined;
@ -173,6 +181,7 @@ function normalizeAgent(value: unknown, index: number): AgentWorkState {
name: stringValue(agent.name, "Unnamed agent"),
profileId: stringValue(agent.profileId, "unknown"),
...(live ? { live } : {}),
...(runtimeState ? { runtimeState } : {}),
busy: normalizeBusy(agent.busy),
tickets: arrayValue(agent.tickets).map(normalizeTicket),
inboxDepth: numberValue(agent.inboxDepth, inbox.length),
@ -181,6 +190,18 @@ function normalizeAgent(value: unknown, index: number): AgentWorkState {
};
}
function normalizeRuntimeState(value: unknown): AgentWorkState["runtimeState"] {
if (
value === "running" ||
value === "stopping" ||
value === "stopped" ||
value === "failedStart"
) {
return value;
}
return undefined;
}
function normalizeSummaryStatus(value: unknown): ConversationPreviewStatus {
if (
value === "ready" ||