Skip to main content

taskfast_cli/
exit.rs

1// SPDX-License-Identifier: MIT
2//! Deterministic exit-code taxonomy — stable contract for agent orchestrators.
3//!
4//! Orchestrators (systemd timers, CI runners, other agents) branch on exit
5//! code alone: `0` = go, `4` = sleep and retry, `3`/`7` = fix config. Changing
6//! a code is a breaking change, so the numeric values are pinned and the
7//! mapping from [`crate::cmd::CmdError`] is exercised by tests.
8//!
9//! Mirrors the plan's taxonomy:
10//!
11//! | Code | Class                                       |
12//! |------|---------------------------------------------|
13//! | 0    | success                                     |
14//! | 2    | usage / argument error (clap emits this)    |
15//! | 3    | auth (401/403)                              |
16//! | 4    | rate-limited (429)                          |
17//! | 5    | wallet / chain / signing                    |
18//! | 6    | server (5xx after retries) / network        |
19//! | 7    | validation (422, 4xx other)                 |
20//! | 70   | unimplemented (transitional, scaffold-only) |
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23pub enum ExitCode {
24    Success = 0,
25    Usage = 2,
26    Auth = 3,
27    RateLimited = 4,
28    Wallet = 5,
29    Server = 6,
30    Validation = 7,
31    Unimplemented = 70,
32}
33
34impl From<ExitCode> for std::process::ExitCode {
35    fn from(code: ExitCode) -> Self {
36        std::process::ExitCode::from(code as u8)
37    }
38}
39
40impl ExitCode {
41    pub fn as_u8(self) -> u8 {
42        self as u8
43    }
44}