zeph_config/autonomous.rs
1// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! State types shared between the autonomous goal subsystem and command handlers.
5
6use serde::{Deserialize, Serialize};
7
8/// FSM states for an autonomous goal session.
9///
10/// Valid transitions:
11/// - `Running` → `Verifying` (supervisor check triggered)
12/// - `Verifying` → `Running` (supervisor: not yet achieved)
13/// - `Verifying` → `Achieved` (supervisor: goal met)
14/// - `Running` / `Verifying` → `Stuck` (stuck counter exhausted or supervisor failures)
15/// - `Running` / `Verifying` → `Aborted` (user cancel or turn limit reached)
16/// - `Running` / `Verifying` → `Failed` (unrecoverable error)
17#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
18#[serde(rename_all = "snake_case")]
19#[non_exhaustive]
20pub enum AutonomousState {
21 /// The agent is actively running multi-turn execution.
22 Running,
23 /// The supervisor is verifying whether the goal condition is satisfied.
24 Verifying,
25 /// Goal achieved and confirmed by the supervisor.
26 Achieved,
27 /// No progress detected across the configured number of consecutive turns.
28 Stuck,
29 /// Session aborted by the user or turn limit reached.
30 Aborted,
31 /// Unrecoverable error during execution.
32 Failed,
33}
34
35impl std::fmt::Display for AutonomousState {
36 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37 match self {
38 Self::Running => f.write_str("running"),
39 Self::Verifying => f.write_str("verifying"),
40 Self::Achieved => f.write_str("achieved"),
41 Self::Stuck => f.write_str("stuck"),
42 Self::Aborted => f.write_str("aborted"),
43 Self::Failed => f.write_str("failed"),
44 }
45 }
46}