1use std::fmt;
4use std::str::FromStr;
5
6#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
8pub enum ResponseStyle {
9 Concise,
11 #[default]
13 Balanced,
14 Detailed,
16}
17
18impl ResponseStyle {
19 pub const ALL: [Self; 3] = [Self::Concise, Self::Balanced, Self::Detailed];
21
22 pub const fn as_str(self) -> &'static str {
24 match self {
25 Self::Concise => "concise",
26 Self::Balanced => "balanced",
27 Self::Detailed => "detailed",
28 }
29 }
30
31 pub const fn name(self) -> &'static str {
33 match self {
34 Self::Concise => "Concise",
35 Self::Balanced => "Balanced",
36 Self::Detailed => "Detailed",
37 }
38 }
39
40 pub const fn description(self) -> &'static str {
42 match self {
43 Self::Concise => "Compact answers with essential results, caveats, and verification.",
44 Self::Balanced => "Enough context to understand and verify without exhaustive detail.",
45 Self::Detailed => "Thorough decisions, trade-offs, effects, and verification.",
46 }
47 }
48
49 pub const fn prompt_instruction(self) -> &'static str {
51 match self {
52 Self::Concise => {
53 "Lead with the outcome. Keep the final answer compact, omit routine narration, and \
54 retain essential caveats and verification."
55 }
56 Self::Balanced => {
57 "Lead with the outcome. Provide enough context to understand decisions and verify \
58 the result without exhaustive detail."
59 }
60 Self::Detailed => {
61 "Lead with the outcome. Explain decisions, trade-offs, affected behavior, and \
62 verification thoroughly without repetition."
63 }
64 }
65 }
66}
67
68impl fmt::Display for ResponseStyle {
69 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
70 formatter.write_str(self.as_str())
71 }
72}
73
74impl FromStr for ResponseStyle {
75 type Err = String;
76
77 fn from_str(value: &str) -> Result<Self, Self::Err> {
78 match value {
79 "concise" => Ok(Self::Concise),
80 "balanced" => Ok(Self::Balanced),
81 "detailed" => Ok(Self::Detailed),
82 _ => Err(format!("Unknown response style: {value}")),
83 }
84 }
85}
86
87#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
89pub enum SpeedMode {
90 #[default]
92 Normal,
93 Fast,
95}
96
97impl SpeedMode {
98 pub const ALL: [Self; 2] = [Self::Normal, Self::Fast];
100
101 pub const fn as_str(self) -> &'static str {
103 match self {
104 Self::Normal => "normal",
105 Self::Fast => "fast",
106 }
107 }
108
109 pub const fn name(self) -> &'static str {
111 match self {
112 Self::Normal => "Normal",
113 Self::Fast => "Fast",
114 }
115 }
116
117 pub const fn description(self) -> &'static str {
119 match self {
120 Self::Normal => "Standard response speed and provider pricing.",
121 Self::Fast => "Faster responses at a higher provider cost.",
122 }
123 }
124}
125
126impl fmt::Display for SpeedMode {
127 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
128 formatter.write_str(self.as_str())
129 }
130}
131
132impl FromStr for SpeedMode {
133 type Err = String;
134
135 fn from_str(value: &str) -> Result<Self, Self::Err> {
136 match value {
137 "normal" => Ok(Self::Normal),
138 "fast" => Ok(Self::Fast),
139 _ => Err(format!("Unknown speed mode: {value}")),
140 }
141 }
142}
143
144#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
146pub enum SessionDiffState {
147 #[default]
150 Unknown,
151 Empty,
153 Present,
155}
156
157#[derive(Clone, PartialEq, Eq, Debug, Default)]
160pub struct SessionStats {
161 pub added_lines: u64,
163 pub deleted_lines: u64,
165 pub diff_state: SessionDiffState,
167 pub input_tokens: u64,
169 pub output_tokens: u64,
171}
172
173impl SessionStats {
174 pub fn should_show_diff(&self) -> bool {
179 self.diff_state != SessionDiffState::Empty
180 }
181
182 pub fn line_change_counts(diff: &str) -> (u64, u64) {
185 diff.lines()
186 .fold((0_u64, 0_u64), |(added_lines, deleted_lines), line| {
187 if line.starts_with('+') && !line.starts_with("+++") {
188 return (added_lines.saturating_add(1), deleted_lines);
189 }
190
191 if line.starts_with('-') && !line.starts_with("---") {
192 return (added_lines, deleted_lines.saturating_add(1));
193 }
194
195 (added_lines, deleted_lines)
196 })
197 }
198}
199
200#[cfg(test)]
201#[path = "session_test.rs"]
202mod tests;