agentty 0.8.2

Agentty is an ADE (Agentic Development Environment) for structured, controllable AI-assisted software development.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
//! Theme-aware semantic color helpers for Agentty's terminal UI.

use std::sync::atomic::{AtomicU8, Ordering};

use ratatui::style::Color;

use super::icon::Icon;
use crate::domain::session::{ReviewRequestState, Status};
use crate::domain::theme::ColorTheme;

static ACTIVE_THEME: AtomicU8 = AtomicU8::new(theme_index(ColorTheme::Current));

/// Shared semantic color tokens for the terminal UI.
pub mod palette {
    use ratatui::style::Color;

    use super::{active_palette, token_color};

    /// Primary accent color used for focused UI elements and titles.
    #[must_use]
    pub fn accent() -> Color {
        token_color(|palette| palette.accent)
    }

    /// Brighter accent used for secondary emphasis.
    #[must_use]
    pub fn accent_soft() -> Color {
        token_color(|palette| palette.accent_soft)
    }

    /// Subtle border and separator color.
    #[must_use]
    pub fn border() -> Color {
        token_color(|palette| palette.border)
    }

    /// Error/danger color for destructive or failed states.
    #[must_use]
    pub fn danger() -> Color {
        token_color(|palette| palette.danger)
    }

    /// Softer danger tone used for graded severity scales.
    #[must_use]
    pub fn danger_soft() -> Color {
        token_color(|palette| palette.danger_soft)
    }

    /// Informational color used for neutral-highlight states.
    #[must_use]
    pub fn info() -> Color {
        token_color(|palette| palette.info)
    }

    /// Color used for question-status emphasis.
    #[must_use]
    pub fn question() -> Color {
        token_color(|palette| palette.question)
    }

    /// Base surface color for bars and selected rows.
    #[must_use]
    pub fn surface() -> Color {
        token_color(|palette| palette.surface)
    }

    /// Subtle blue-gray surface used behind clarification prompt blocks so the
    /// block reads as a recessed inset rather than an elevated panel.
    #[must_use]
    pub fn surface_clarification() -> Color {
        token_color(|palette| palette.surface_clarification)
    }

    /// Subtle danger-tinted surface used behind removed diff lines.
    #[must_use]
    pub fn surface_danger() -> Color {
        token_color(|palette| palette.surface_danger)
    }

    /// Elevated surface color for table headers.
    #[must_use]
    pub fn surface_elevated() -> Color {
        token_color(|palette| palette.surface_elevated)
    }

    /// Subtle success-tinted surface used behind added diff lines.
    #[must_use]
    pub fn surface_success() -> Color {
        token_color(|palette| palette.surface_success)
    }

    /// Dark surface used to dim background content behind modal overlays.
    #[must_use]
    pub fn surface_overlay() -> Color {
        token_color(|palette| palette.surface_overlay)
    }

    /// Primary readable text color.
    #[must_use]
    pub fn text() -> Color {
        token_color(|palette| palette.text)
    }

    /// Muted text color for secondary copy.
    #[must_use]
    pub fn text_muted() -> Color {
        token_color(|palette| palette.text_muted)
    }

    /// Extra-muted text color for placeholders and hints.
    #[must_use]
    pub fn text_subtle() -> Color {
        token_color(|palette| palette.text_subtle)
    }

    /// Success color for positive states.
    #[must_use]
    pub fn success() -> Color {
        token_color(|palette| palette.success)
    }

    /// Softer success tone used for graded severity scales.
    #[must_use]
    pub fn success_soft() -> Color {
        token_color(|palette| palette.success_soft)
    }

    /// Warning color for in-progress and caution states.
    #[must_use]
    pub fn warning() -> Color {
        token_color(|palette| palette.warning)
    }

    /// Softer warning tone used for graded severity scales.
    #[must_use]
    pub fn warning_soft() -> Color {
        token_color(|palette| palette.warning_soft)
    }

    /// Returns the active theme's complete palette for tests and diagnostics.
    #[must_use]
    pub fn active() -> super::ThemePalette {
        active_palette()
    }
}

/// Complete set of semantic colors resolved for one UI theme.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ThemePalette {
    /// Primary accent color used for focused UI elements and titles.
    pub accent: Color,
    /// Brighter accent used for secondary emphasis.
    pub accent_soft: Color,
    /// Subtle border and separator color.
    pub border: Color,
    /// Error/danger color for destructive or failed states.
    pub danger: Color,
    /// Softer danger tone used for graded severity scales.
    pub danger_soft: Color,
    /// Informational color used for neutral-highlight states.
    pub info: Color,
    /// Color used for question-status emphasis.
    pub question: Color,
    /// Base surface color for bars and selected rows.
    pub surface: Color,
    /// Subtle blue-gray surface used behind clarification prompt blocks.
    pub surface_clarification: Color,
    /// Subtle danger-tinted surface used behind removed diff lines.
    pub surface_danger: Color,
    /// Elevated surface color for table headers.
    pub surface_elevated: Color,
    /// Subtle success-tinted surface used behind added diff lines.
    pub surface_success: Color,
    /// Dark surface used to dim background content behind modal overlays.
    pub surface_overlay: Color,
    /// Primary readable text color.
    pub text: Color,
    /// Muted text color for secondary copy.
    pub text_muted: Color,
    /// Extra-muted text color for placeholders and hints.
    pub text_subtle: Color,
    /// Success color for positive states.
    pub success: Color,
    /// Softer success tone used for graded severity scales.
    pub success_soft: Color,
    /// Warning color for in-progress and caution states.
    pub warning: Color,
    /// Softer warning tone used for graded severity scales.
    pub warning_soft: Color,
}

const CURRENT_PALETTE: ThemePalette = ThemePalette {
    accent: Color::Cyan,
    accent_soft: Color::LightCyan,
    border: Color::DarkGray,
    danger: Color::Red,
    danger_soft: Color::LightRed,
    info: Color::LightBlue,
    question: Color::LightMagenta,
    surface: Color::DarkGray,
    surface_clarification: Color::Rgb(28, 38, 48),
    surface_danger: Color::Rgb(48, 24, 24),
    surface_elevated: Color::Gray,
    surface_success: Color::Rgb(18, 44, 26),
    surface_overlay: Color::Black,
    text: Color::White,
    text_muted: Color::Gray,
    text_subtle: Color::DarkGray,
    success: Color::Green,
    success_soft: Color::LightGreen,
    warning: Color::Yellow,
    warning_soft: Color::LightYellow,
};

const HACKER_PALETTE: ThemePalette = ThemePalette {
    accent: Color::Rgb(61, 221, 106),
    accent_soft: Color::Rgb(42, 179, 85),
    border: Color::Rgb(27, 61, 32),
    danger: Color::Rgb(255, 94, 94),
    danger_soft: Color::Rgb(214, 88, 88),
    info: Color::Rgb(80, 122, 92),
    question: Color::Rgb(184, 255, 198),
    surface: Color::Rgb(13, 22, 13),
    surface_clarification: Color::Rgb(20, 34, 22),
    surface_danger: Color::Rgb(48, 20, 20),
    surface_elevated: Color::Rgb(27, 61, 32),
    surface_success: Color::Rgb(18, 44, 26),
    surface_overlay: Color::Black,
    text: Color::Rgb(224, 255, 230),
    text_muted: Color::Rgb(80, 122, 92),
    text_subtle: Color::Rgb(42, 89, 53),
    success: Color::Rgb(61, 221, 106),
    success_soft: Color::Rgb(42, 179, 85),
    warning: Color::Rgb(230, 219, 116),
    warning_soft: Color::Rgb(250, 245, 160),
};

/// Sets the process-wide active color theme used by semantic palette tokens.
pub fn set_active_theme(theme: ColorTheme) {
    ACTIVE_THEME.store(theme_index(theme), Ordering::Relaxed);
}

/// Returns a stable cache discriminator for the active color theme.
#[must_use]
pub(crate) fn active_theme_cache_version() -> u64 {
    u64::from(ACTIVE_THEME.load(Ordering::Relaxed))
}

/// Returns the terminal color used for one session status label.
#[must_use]
pub fn status_color(status: Status) -> Color {
    match status {
        Status::New => palette::text_muted(),
        Status::InProgress => palette::warning(),
        Status::Review | Status::AgentReview => palette::info(),
        Status::Question => palette::question(),
        Status::Queued => palette::accent_soft(),
        Status::Rebasing | Status::Merging => palette::accent(),
        Status::Done => palette::success(),
        Status::Canceled => palette::danger(),
    }
}

/// Returns the icon used for one session status indicator.
#[must_use]
pub fn status_icon(status: Status) -> Icon {
    match status {
        Status::New | Status::Review | Status::Question | Status::Queued => Icon::Pending,
        Status::InProgress | Status::AgentReview | Status::Rebasing | Status::Merging => {
            Icon::current_spinner()
        }
        Status::Done => Icon::Check,
        Status::Canceled => Icon::Cross,
    }
}

/// Returns the terminal color for a forge indicator suffix.
///
/// The color reflects the review-request lifecycle state when one is linked,
/// or a soft accent when only a published branch exists (`None`).
#[must_use]
pub fn forge_indicator_color(state: Option<ReviewRequestState>) -> Color {
    match state {
        Some(ReviewRequestState::Open) => palette::warning(),
        Some(ReviewRequestState::Merged) => palette::success(),
        Some(ReviewRequestState::Closed) => palette::danger(),
        None => palette::accent_soft(),
    }
}

/// Returns the complete color palette for the active theme.
#[must_use]
fn active_palette() -> ThemePalette {
    match ACTIVE_THEME.load(Ordering::Relaxed) {
        1 => HACKER_PALETTE,
        _ => CURRENT_PALETTE,
    }
}

/// Applies one semantic color selector to the active palette.
#[must_use]
fn token_color(selector: impl FnOnce(ThemePalette) -> Color) -> Color {
    selector(active_palette())
}

/// Returns the stable numeric storage for one theme in the active-theme atom.
const fn theme_index(theme: ColorTheme) -> u8 {
    match theme {
        ColorTheme::Current => 0,
        ColorTheme::Hacker => 1,
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn status_color_returns_muted_text_for_new() {
        // Arrange
        set_active_theme(ColorTheme::Current);

        // Act
        let color = status_color(Status::New);

        // Assert
        assert_eq!(color, palette::text_muted());
    }

    #[test]
    fn status_color_returns_success_for_done() {
        // Arrange
        set_active_theme(ColorTheme::Current);

        // Act
        let color = status_color(Status::Done);

        // Assert
        assert_eq!(color, palette::success());
    }

    #[test]
    fn status_color_returns_danger_for_canceled() {
        // Arrange
        set_active_theme(ColorTheme::Current);

        // Act
        let color = status_color(Status::Canceled);

        // Assert
        assert_eq!(color, palette::danger());
    }

    #[test]
    fn status_color_returns_warning_for_in_progress() {
        // Arrange
        set_active_theme(ColorTheme::Current);

        // Act
        let color = status_color(Status::InProgress);

        // Assert
        assert_eq!(color, palette::warning());
    }

    #[test]
    fn status_color_returns_info_for_review() {
        // Arrange
        set_active_theme(ColorTheme::Current);

        // Act
        let color = status_color(Status::Review);

        // Assert
        assert_eq!(color, palette::info());
    }

    #[test]
    fn status_color_returns_accent_for_merging() {
        // Arrange
        set_active_theme(ColorTheme::Current);

        // Act
        let color = status_color(Status::Merging);

        // Assert
        assert_eq!(color, palette::accent());
    }

    #[test]
    fn status_color_uses_hacker_palette_when_active() {
        // Arrange
        set_active_theme(ColorTheme::Hacker);

        // Act
        let color = status_color(Status::Merging);

        // Assert
        assert_eq!(color, HACKER_PALETTE.accent);

        set_active_theme(ColorTheme::Current);
    }

    #[test]
    fn status_icon_returns_check_for_done() {
        // Arrange / Act
        let icon = status_icon(Status::Done);

        // Assert
        assert!(matches!(icon, Icon::Check));
    }

    #[test]
    fn status_icon_returns_cross_for_canceled() {
        // Arrange / Act
        let icon = status_icon(Status::Canceled);

        // Assert
        assert!(matches!(icon, Icon::Cross));
    }

    #[test]
    fn status_icon_returns_pending_for_new() {
        // Arrange / Act
        let icon = status_icon(Status::New);

        // Assert
        assert!(matches!(icon, Icon::Pending));
    }

    #[test]
    fn forge_indicator_color_returns_warning_for_open() {
        // Arrange
        set_active_theme(ColorTheme::Current);

        // Act
        let color = forge_indicator_color(Some(ReviewRequestState::Open));

        // Assert
        assert_eq!(color, palette::warning());
    }

    #[test]
    fn forge_indicator_color_returns_success_for_merged() {
        // Arrange
        set_active_theme(ColorTheme::Current);

        // Act
        let color = forge_indicator_color(Some(ReviewRequestState::Merged));

        // Assert
        assert_eq!(color, palette::success());
    }

    #[test]
    fn forge_indicator_color_returns_danger_for_closed() {
        // Arrange
        set_active_theme(ColorTheme::Current);

        // Act
        let color = forge_indicator_color(Some(ReviewRequestState::Closed));

        // Assert
        assert_eq!(color, palette::danger());
    }

    #[test]
    fn forge_indicator_color_returns_accent_soft_for_published_only() {
        // Arrange
        set_active_theme(ColorTheme::Current);

        // Act
        let color = forge_indicator_color(None);

        // Assert
        assert_eq!(color, palette::accent_soft());
    }
}