Skip to main content

agent_migrate_core/
agent.rs

1use std::fmt;
2use std::str::FromStr;
3
4use serde::{Deserialize, Serialize};
5use thiserror::Error;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
8#[serde(rename_all = "lowercase")]
9pub enum AgentKind {
10    Codex,
11    Pi,
12    Claude,
13}
14
15impl fmt::Display for AgentKind {
16    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
17        formatter.write_str(match self {
18            Self::Codex => "codex",
19            Self::Pi => "pi",
20            Self::Claude => "claude",
21        })
22    }
23}
24
25impl FromStr for AgentKind {
26    type Err = AgentParseError;
27
28    fn from_str(value: &str) -> Result<Self, Self::Err> {
29        match value {
30            "codex" => Ok(Self::Codex),
31            "pi" => Ok(Self::Pi),
32            "claude" => Ok(Self::Claude),
33            unknown => Err(AgentParseError::Unknown(unknown.to_owned())),
34        }
35    }
36}
37
38#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
39#[serde(rename_all = "lowercase")]
40pub enum Scope {
41    Global,
42    Project,
43}
44
45impl fmt::Display for Scope {
46    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
47        formatter.write_str(match self {
48            Self::Global => "global",
49            Self::Project => "project",
50        })
51    }
52}
53
54impl FromStr for Scope {
55    type Err = AgentParseError;
56
57    fn from_str(value: &str) -> Result<Self, Self::Err> {
58        match value {
59            "global" => Ok(Self::Global),
60            "project" => Ok(Self::Project),
61            unknown => Err(AgentParseError::UnknownScope(unknown.to_owned())),
62        }
63    }
64}
65
66#[derive(Debug, Error, PartialEq, Eq)]
67pub enum AgentParseError {
68    #[error("unknown agent: {0}")]
69    Unknown(String),
70    #[error("unknown scope: {0}")]
71    UnknownScope(String),
72}