Skip to main content

claude_wrapper/
types.rs

1use serde::{Deserialize, Serialize};
2
3/// Output format for `--output-format`.
4#[derive(Debug, Clone, Copy, Default)]
5pub enum OutputFormat {
6    /// Plain text output (default).
7    #[default]
8    Text,
9    /// Single JSON result object.
10    Json,
11    /// Streaming NDJSON.
12    StreamJson,
13}
14
15impl OutputFormat {
16    pub(crate) fn as_arg(&self) -> &'static str {
17        match self {
18            Self::Text => "text",
19            Self::Json => "json",
20            Self::StreamJson => "stream-json",
21        }
22    }
23}
24
25/// Permission mode for `--permission-mode`.
26#[derive(Debug, Clone, Copy, Default)]
27pub enum PermissionMode {
28    /// Default interactive permissions.
29    #[default]
30    Default,
31    /// Auto-accept file edits.
32    AcceptEdits,
33    /// Bypass all permission checks.
34    BypassPermissions,
35    /// Don't ask for permissions (deny by default).
36    DontAsk,
37    /// Plan mode (read-only).
38    Plan,
39    /// Auto mode.
40    Auto,
41}
42
43impl PermissionMode {
44    pub(crate) fn as_arg(&self) -> &'static str {
45        match self {
46            Self::Default => "default",
47            Self::AcceptEdits => "acceptEdits",
48            Self::BypassPermissions => "bypassPermissions",
49            Self::DontAsk => "dontAsk",
50            Self::Plan => "plan",
51            Self::Auto => "auto",
52        }
53    }
54}
55
56/// Input format for `--input-format`.
57#[derive(Debug, Clone, Copy, Default)]
58pub enum InputFormat {
59    /// Plain text input (default).
60    #[default]
61    Text,
62    /// Streaming JSON input.
63    StreamJson,
64}
65
66impl InputFormat {
67    pub(crate) fn as_arg(&self) -> &'static str {
68        match self {
69            Self::Text => "text",
70            Self::StreamJson => "stream-json",
71        }
72    }
73}
74
75/// Effort level for `--effort`.
76#[derive(Debug, Clone, Copy)]
77pub enum Effort {
78    Low,
79    Medium,
80    High,
81}
82
83impl Effort {
84    pub(crate) fn as_arg(&self) -> &'static str {
85        match self {
86            Self::Low => "low",
87            Self::Medium => "medium",
88            Self::High => "high",
89        }
90    }
91}
92
93/// Scope for MCP and plugin commands.
94#[derive(Debug, Clone, Copy, Default)]
95pub enum Scope {
96    /// Local scope (current directory).
97    #[default]
98    Local,
99    /// User scope (global).
100    User,
101    /// Project scope.
102    Project,
103}
104
105impl Scope {
106    pub(crate) fn as_arg(&self) -> &'static str {
107        match self {
108            Self::Local => "local",
109            Self::User => "user",
110            Self::Project => "project",
111        }
112    }
113}
114
115/// Authentication status returned by `claude auth status --json`.
116#[cfg(feature = "json")]
117#[derive(Debug, Clone, Deserialize, Serialize)]
118pub struct AuthStatus {
119    #[serde(default)]
120    pub authenticated: bool,
121    #[serde(default)]
122    pub account_type: Option<String>,
123    #[serde(default)]
124    pub email: Option<String>,
125    // Capture any additional fields
126    #[serde(flatten)]
127    pub extra: std::collections::HashMap<String, serde_json::Value>,
128}
129
130/// A message in the query JSON output.
131#[cfg(feature = "json")]
132#[derive(Debug, Clone, Deserialize, Serialize)]
133pub struct QueryMessage {
134    #[serde(default)]
135    pub role: String,
136    #[serde(default)]
137    pub content: serde_json::Value,
138    #[serde(flatten)]
139    pub extra: std::collections::HashMap<String, serde_json::Value>,
140}
141
142/// Result from a query with `--output-format json`.
143#[cfg(feature = "json")]
144#[derive(Debug, Clone, Deserialize, Serialize)]
145pub struct QueryResult {
146    #[serde(default)]
147    pub result: String,
148    #[serde(default)]
149    pub session_id: String,
150    #[serde(default)]
151    pub cost_usd: Option<f64>,
152    #[serde(default)]
153    pub duration_ms: Option<u64>,
154    #[serde(default)]
155    pub is_error: bool,
156    #[serde(flatten)]
157    pub extra: std::collections::HashMap<String, serde_json::Value>,
158}