clawgarden-cli 0.1.6

ClawGarden CLI - Multi-bot/multi-agent Garden management tool
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
//! ClawGarden CLI — UI theming & shared display primitives
//!
//! Every public function writes directly to stdout using ANSI escape codes.
//! No external TUI crate needed; keeps the binary lean.

// (no unused imports)

// ── ANSI helpers ─────────────────────────────────────────────────────────────

pub const RESET: &str = "\x1b[0m";
const BOLD: &str = "\x1b[1m";
pub const DIM: &str = "\x1b[2m";
pub const ITALIC: &str = "\x1b[3m";
#[allow(dead_code)]
const UNDERLINE: &str = "\x1b[4m";
const CLEAR_LINE: &str = "\x1b[2K\r";

// ClawGarden brand palette (256-color for broad terminal support)
pub const GREEN: &str = "\x1b[38;5;77m"; // lush leaf green
const DARK_GREEN: &str = "\x1b[38;5;28m";
const TEAL: &str = "\x1b[38;5;37m"; // garden pond
const AMBER: &str = "\x1b[38;5;214m"; // warm lantern glow
const ROSE: &str = "\x1b[38;5;204m"; // flower petals
const SKY: &str = "\x1b[38;5;117m"; // morning sky
const SILVER: &str = "\x1b[38;5;252m"; // moonlight
const LAVENDER: &str = "\x1b[38;5;183m"; // lavender
const PEACH: &str = "\x1b[38;5;216m"; // warm peach
const RED: &str = "\x1b[38;5;203m";
const WHITE: &str = "\x1b[38;5;255m";

// ── Public API ───────────────────────────────────────────────────────────────

/// Print the ClawGarden ASCII banner with brand colors.
pub fn print_banner() {
    let version = env!("CARGO_PKG_VERSION");
    let banner = format!(
        r#"
{g}   ┌───┐ ╻  {dg}╻ ╻   {t}┏━━━┓
{g}   │   │ ┃  {dg}┃ ┃   {t}┃   ┃   {a}🌿 {w}C L A W G A R D E N
{g}   │   │ ┃  {dg}┃ ┃   {t}┃   ┃   {dim}Multi-Agent Garden · v{ver}
{g}   └───┘ ╹  {dg}╹ ╹   {t}┗━━━┛
{reset}"#,
        g = GREEN,
        dg = DARK_GREEN,
        t = TEAL,
        a = AMBER,
        w = WHITE,
        dim = DIM,
        ver = version,
        reset = RESET,
    );
    print!("{banner}");
}

/// Print a section header with step number and title.
///
/// ```text
///  ┌─────────────────────────────────────────────────┐
///  │  🌱  Step 1 · Dependency Garden Bed             │
///  └─────────────────────────────────────────────────┘
/// ```
pub fn section_header(step: usize, _total: usize, icon: &str, title: &str) {
    let inner = format!("  {}  Step {} · {}", icon, step, title);
    let width = strip_ansi(&inner).len().max(42);
    let top = "".to_string() + &"".repeat(width + 2) + "";
    let bot = "".to_string() + &"".repeat(width + 2) + "";
    let mid = format!(
        "{}{}",
        inner,
        " ".repeat(width - strip_ansi(&inner).len() + 1)
    );

    println!("\n{teal}{top}", teal = TEAL);
    println!("{green}{mid}", green = GREEN);
    println!("{teal}{bot}{reset}", teal = TEAL, reset = RESET);
    println!();
}

/// Print a section header without a step number (for sub-commands like status, config).
pub fn section_header_no_step(icon: &str, title: &str) {
    let inner = format!("  {}  {}", icon, title);
    let width = strip_ansi(&inner).len().max(42);
    let top = "".to_string() + &"".repeat(width + 2) + "";
    let bot = "".to_string() + &"".repeat(width + 2) + "";
    let mid = format!(
        "{}{}",
        inner,
        " ".repeat(width - strip_ansi(&inner).len() + 1)
    );

    println!("\n{teal}{top}", teal = TEAL);
    println!("{green}{mid}", green = GREEN);
    println!("{teal}{bot}{reset}", teal = TEAL, reset = RESET);
    println!();
}

/// Print a progress bar showing overall wizard progress.
pub fn progress_bar(current: usize, total: usize) {
    let width = 30;
    let filled = if total > 0 {
        (current * width) / total
    } else {
        0
    };
    let empty = width - filled;

    let bar: String = "".repeat(filled);
    let bg: String = "".repeat(empty);
    let pct = if total > 0 {
        (current * 100) / total
    } else {
        0
    };

    println!(
        "{dim}  {bar}{bg} {pct}%  ({cur}/{tot}){reset}",
        dim = DIM,
        bar = format!("{green}{bar}{reset}", green = GREEN, reset = RESET),
        bg = format!("{dark}{bg}{reset}", dark = "\x1b[38;5;236m", reset = RESET),
        pct = pct,
        cur = current,
        tot = total,
        reset = RESET,
    );
    println!();
}

/// Print a styled info/hint line (dim + italic).
pub fn hint(text: &str) {
    println!(
        "  {dim}{italic}{text}{reset}",
        dim = DIM,
        italic = ITALIC,
        text = text,
        reset = RESET
    );
}

/// Print a styled "tip" box.
pub fn tip(text: &str) {
    println!(
        "  {amber}💡 Tip:{reset} {dim}{text}{reset}",
        amber = AMBER,
        dim = DIM,
        text = text,
        reset = RESET
    );
}

/// Print a success check with green tick.
pub fn success(text: &str) {
    println!(
        "  {green}{reset} {text}",
        green = GREEN,
        reset = RESET,
        text = text
    );
}

/// Print a warning message.
pub fn warn(text: &str) {
    println!(
        "  {amber}{reset} {text}",
        amber = AMBER,
        reset = RESET,
        text = text
    );
}

/// Print an error message.
pub fn error(text: &str) {
    println!(
        "  {red}{reset} {text}",
        red = RED,
        reset = RESET,
        text = text
    );
}

/// Print a subtle divider.
pub fn divider() {
    println!("  {dim}{}{reset}", "".repeat(50), dim = DIM, reset = RESET);
}

/// Print an indented key=value pair for summary screens.
#[allow(dead_code)]
pub fn kv(indent: usize, key: &str, value: &str) {
    let pad = " ".repeat(indent);
    println!(
        "{pad}{dim}{key}:{reset} {value}",
        pad = pad,
        dim = DIM,
        key = key,
        reset = RESET,
        value = value,
    );
}

/// Print a decorative flower separator.
pub fn flower_separator() {
    println!(
        "\n  {dg}· • {g}{dg}• ·   {dim}{}   {dg}· • {g}{dg}• ·{reset}",
        "".repeat(26),
        dg = DARK_GREEN,
        g = GREEN,
        dim = DIM,
        reset = RESET,
    );
    println!();
}

/// Print a "box" summary — takes lines of (icon, label, detail).
pub fn summary_box(title: &str, rows: &[(String, String, String)]) {
    let label_width = rows.iter().map(|r| r.1.len()).max().unwrap_or(10).max(10);
    let detail_display_width = rows
        .iter()
        .map(|r| strip_ansi(&r.2).len())
        .max()
        .unwrap_or(10);
    let inner = label_width + detail_display_width + 8;
    let full = inner.max(strip_ansi(title).len() + 4);

    let top = format!("{}", "".repeat(full + 2));
    let bot = format!("{}", "".repeat(full + 2));
    let title_line = format!(
        "{bold}{t}{}{reset}",
        title,
        bold = BOLD,
        t = WHITE,
        reset = RESET,
    );
    // Pad title_line correctly
    let title_inner_len = strip_ansi(&title_line).len();
    let title_pad = if (full + 4) > title_inner_len {
        " ".repeat(full + 4 - title_inner_len)
    } else {
        "".to_string()
    };
    let title_line = title_line.replace("", &format!("{}", title_pad));

    println!("\n{teal}{top}", teal = TEAL);
    println!("{title_line}");
    println!("{}", "".repeat(full + 2));

    for (icon, label, detail) in rows {
        let detail_visible = strip_ansi(detail).len();
        let pad = full.saturating_sub(label_width + detail_visible + 4);
        println!(
            "{icon} {dim}{label:<lw$}{reset} {detail}{pad_spaces}",
            icon = icon,
            dim = DIM,
            label = label,
            lw = label_width,
            reset = RESET,
            detail = detail,
            pad_spaces = " ".repeat(pad),
        );
    }

    println!("{teal}{bot}{reset}", teal = TEAL, reset = RESET);
}

/// Print the final celebration screen.
pub fn celebration(garden_name: &str) {
    let name_display = format!("{w}{garden_name}{g}", w = WHITE, g = GREEN);
    println!();
    println!(
        "{grn}{bld}
       🌿 · · · · · · · · · · · · · · · · · 🌿
       ║                                   ║
       ║    🎉  Garden Created!  🎉        ║
       ║                                   ║
       ║    '{name}' is ready to bloom.    ║
       ║                                   ║
       🌿 · · · · · · · · · · · · · · · · · 🌿
{reset}",
        grn = GREEN,
        bld = BOLD,
        name = name_display,
        reset = RESET,
    );
}

/// Print the next-steps help box after garden creation.
pub fn next_steps(garden_name: &str) {
    println!(
        "\n  {bold}{sky}▶ Next Steps{reset}",
        bold = BOLD,
        sky = SKY,
        reset = RESET
    );
    println!();
    println!(
        "  {dim}1.{reset}  Start your garden:",
        dim = DIM,
        reset = RESET
    );
    println!(
        "      {green}garden up --name {name}{reset}",
        green = GREEN,
        name = garden_name,
        reset = RESET
    );
    println!();
    println!(
        "  {dim}2.{reset}  Check if it's healthy:",
        dim = DIM,
        reset = RESET
    );
    println!(
        "      {green}garden logs --name {name} --follow{reset}",
        green = GREEN,
        name = garden_name,
        reset = RESET
    );
    println!();
    println!(
        "  {dim}3.{reset}  Modify configuration:",
        dim = DIM,
        reset = RESET
    );
    println!(
        "      {green}garden config --name {name}{reset}",
        green = GREEN,
        name = garden_name,
        reset = RESET
    );
    println!();
    println!(
        "  {dim}4.{reset}  Add more agents later:",
        dim = DIM,
        reset = RESET
    );
    println!(
        "      {green}garden config --name {gname}{reset}  {dim}→ Add an agent{reset}",
        green = GREEN,
        gname = garden_name,
        dim = DIM,
        reset = RESET
    );
    println!();
}

/// Print a loading spinner animation (blocking, runs for `ms` milliseconds).
pub fn spinner(text: &str, ms: u64) {
    let frames = ["", "", "", "", "", "", "", "", "", ""];
    let iterations = (ms / 80).max(1);
    for (i, frame) in frames.iter().cycle().take(iterations as usize).enumerate() {
        if i > 0 {
            eprint!("{}", CLEAR_LINE);
        }
        eprint!(
            "  {green}{frame} {text}{reset}",
            green = GREEN,
            frame = frame,
            text = text,
            reset = RESET
        );
        std::thread::sleep(std::time::Duration::from_millis(80));
    }
    eprint!("{}\n", CLEAR_LINE);
}

/// Print a "typing" animation — reveals text character by character.
#[allow(dead_code)]
pub fn typewriter(text: &str, ms_per_char: u64) {
    for ch in text.chars() {
        eprint!("{}", ch);
        std::thread::sleep(std::time::Duration::from_millis(ms_per_char));
    }
    eprint!("\n");
}

// ── Internal ─────────────────────────────────────────────────────────────────

/// Very rough ANSI-stripping for width calculation (not for security use).
fn strip_ansi(s: &str) -> String {
    let mut out = String::with_capacity(s.len());
    let mut in_escape = false;
    for ch in s.chars() {
        if ch == '\x1b' {
            in_escape = true;
        } else if in_escape {
            if ch.is_ascii_alphabetic() {
                in_escape = false;
            }
        } else {
            out.push(ch);
        }
    }
    out
}

/// Build a "role badge" string with color coding.
pub fn role_badge(role: &str) -> String {
    let color = match role.to_uppercase().as_str() {
        "PM" => AMBER,
        "DEV" => GREEN,
        "CRITIC" => ROSE,
        "DESIGNER" => LAVENDER,
        "RESEARCHER" => SKY,
        "TESTER" => TEAL,
        "OPS" => PEACH,
        "ANALYST" => SILVER,
        _ => WHITE,
    };
    format!(
        "{color}[{role}]{reset}",
        color = color,
        role = role,
        reset = RESET
    )
}

/// Role description for onboarding hints.
#[allow(dead_code)]
pub fn role_description(role: &str) -> &'static str {
    match role.to_uppercase().as_str() {
        "PM" => "Coordinates tasks & keeps the team on track",
        "DEV" => "Writes and reviews code, implements features",
        "CRITIC" => "Reviews output, catches issues & blind spots",
        "DESIGNER" => "UI/UX design, system architecture thinking",
        "RESEARCHER" => "Investigates, documents, and gathers context",
        "TESTER" => "Quality assurance, edge-case explorer",
        "OPS" => "Deployment, DevOps, infrastructure management",
        "ANALYST" => "Data analysis, metrics, insights",
        "OTHER" => "Custom role — define your own specialty",
        _ => "Unknown role",
    }
}