Skip to main content

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")]
19pub enum AutonomousState {
20    /// The agent is actively running multi-turn execution.
21    Running,
22    /// The supervisor is verifying whether the goal condition is satisfied.
23    Verifying,
24    /// Goal achieved and confirmed by the supervisor.
25    Achieved,
26    /// No progress detected across the configured number of consecutive turns.
27    Stuck,
28    /// Session aborted by the user or turn limit reached.
29    Aborted,
30    /// Unrecoverable error during execution.
31    Failed,
32}
33
34impl std::fmt::Display for AutonomousState {
35    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36        match self {
37            Self::Running => f.write_str("running"),
38            Self::Verifying => f.write_str("verifying"),
39            Self::Achieved => f.write_str("achieved"),
40            Self::Stuck => f.write_str("stuck"),
41            Self::Aborted => f.write_str("aborted"),
42            Self::Failed => f.write_str("failed"),
43        }
44    }
45}