sprit-mutilagent 0.3.2

A robust command-line toolkit for managing multiple AI coding agents in isolated tmux sessions with comprehensive workspace management and health monitoring
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
//! Help command - Comprehensive help system for Sprite

use crate::cli::HelpCategory;
use crate::utils::help::{
    get_help_system, search_help, show_accessible_help, show_help, show_usage_patterns,
    UsageCategory,
};
use anyhow::Result;

/// Command-line arguments for the help command.
#[derive(Debug)]
pub struct HelpArgs {
    /// Command to get help for
    pub command: Option<String>,

    /// Search help content
    pub search: Option<String>,

    /// Show usage patterns
    pub patterns: bool,

    /// Show troubleshooting guides
    pub troubleshooting: bool,

    /// Show quick reference
    pub quick: bool,

    /// Show accessible help (screen reader friendly)
    pub accessible: bool,

    /// Show usage patterns for specific category
    pub category: Option<HelpCategory>,
}

impl From<HelpCategory> for UsageCategory {
    fn from(category: HelpCategory) -> Self {
        match category {
            HelpCategory::GettingStarted => UsageCategory::GettingStarted,
            HelpCategory::DailyWorkflow => UsageCategory::DailyWorkflow,
            HelpCategory::Troubleshooting => UsageCategory::Troubleshooting,
            HelpCategory::Advanced => UsageCategory::Advanced,
            HelpCategory::Collaboration => UsageCategory::Collaboration,
        }
    }
}

/// Execute the help command with the given arguments.
pub fn execute(args: HelpArgs) -> Result<()> {
    // Handle accessible help request
    if args.accessible {
        return show_accessible_help(args.command.as_deref());
    }

    // Handle search request
    if let Some(query) = args.search {
        return search_help(&query);
    }

    // Handle usage patterns request
    if args.patterns {
        let category = args.category.map(|c| c.into());
        return show_usage_patterns(category);
    }

    // Handle troubleshooting request
    if args.troubleshooting {
        return show_troubleshooting();
    }

    // Handle quick reference request
    if args.quick {
        return show_quick_reference();
    }

    // Default help for specific command or general help
    show_help(args.command.as_deref())
}

/// Show troubleshooting guides.
fn show_troubleshooting() -> Result<()> {
    let help_system = get_help_system();
    let guides = help_system.get_troubleshooting();

    if guides.is_empty() {
        println!("🔧 No troubleshooting guides available.");
        return Ok(());
    }

    println!("🔧 Troubleshooting Guides\n");
    for guide in guides {
        println!("❓ Problem: {}", guide.problem);

        if !guide.symptoms.is_empty() {
            println!("🔍 Symptoms:");
            for symptom in &guide.symptoms {
                println!("  • {}", symptom);
            }
        }

        if !guide.causes.is_empty() {
            println!("🤔 Possible Causes:");
            for cause in &guide.causes {
                println!("  • {}", cause);
            }
        }

        if !guide.solutions.is_empty() {
            println!("💡 Solutions:");
            for solution in &guide.solutions {
                println!("  → {}", solution);
            }
        }

        if !guide.prevention.is_empty() {
            println!("🛡️  Prevention:");
            for prevention in &guide.prevention {
                println!("  • {}", prevention);
            }
        }

        if !guide.related_commands.is_empty() {
            println!("🔗 Related Commands: {}", guide.related_commands.join(", "));
        }

        println!();
    }

    Ok(())
}

/// Show quick reference.
fn show_quick_reference() -> Result<()> {
    let help_system = get_help_system();
    let quick_ref = help_system.get_quick_reference();

    println!("⚡ Quick Reference\n");

    // Common commands
    println!("🔥 Most Common Commands:");
    for (i, cmd) in quick_ref.common_commands.iter().enumerate() {
        println!("  {}. {}", i + 1, cmd);
    }

    println!();

    // Keyboard shortcuts
    if !quick_ref.shortcuts.is_empty() {
        println!("⌨️  Keyboard Shortcuts:");
        for shortcut in &quick_ref.shortcuts {
            println!("  {} - {}", shortcut.keys, shortcut.description);
            println!("     Context: {}", shortcut.context);
        }
        println!();
    }

    // FAQ
    if !quick_ref.faq.is_empty() {
        println!("❓ Frequently Asked Questions:");
        for faq in &quick_ref.faq {
            println!("  Q: {}", faq.question);
            println!("  A: {}", faq.answer);
            if !faq.related_commands.is_empty() {
                println!("  Related: {}", faq.related_commands.join(", "));
            }
            println!();
        }
    }

    println!("💡 For detailed help: sprite help <command>");
    println!("🔍 For search: sprite help --search <query>");

    Ok(())
}

/// Show comprehensive help overview.
#[allow(dead_code)]
pub fn show_help_overview() -> Result<()> {
    println!("🚀 Sprite - Multi-Agent Workflow Toolkit\n");
    println!("Sprite helps you manage multiple AI coding agents in isolated tmux sessions\n");
    println!("with comprehensive workspace management and health monitoring.\n");

    println!("📋 Quick Start Guide:");
    println!("  1️⃣  Initialize your project");
    println!("     sprite init --agents 3");
    println!();
    println!("  2️⃣  Start your first session");
    println!("     sprite start");
    println!();
    println!("  3️⃣  Work with agents");
    println!("     sprite hey 1 'npm install'");
    println!("     sprite hey 2 'cargo build'");
    println!();
    println!("  4️⃣  Navigate workspaces");
    println!("     cd $(sprite warp --print 1)");
    println!();
    println!("  5️⃣  Check status");
    println!("     sprite status");
    println!();

    println!("🔧 Core Commands Overview:\n");

    let help_system = get_help_system();
    let core_commands = [
        "init", "start", "agents", "warp", "hey", "send", "sync", "status",
    ];

    for cmd in &core_commands {
        if let Some(help) = help_system.get_command_help(cmd) {
            println!("  {} - {}", cmd, help.description);
        }
    }

    println!();
    println!("📚 Getting More Help:");
    println!("  sprite help <command>           # Detailed command help");
    println!("  sprite help --search <query>    # Search help content");
    println!("  sprite help --patterns          # Show usage patterns");
    println!("  sprite help --troubleshooting   # Troubleshooting guides");
    println!("  sprite help --quick             # Quick reference");
    println!("  sprite help --accessible       # Screen reader friendly");

    println!();
    println!("🎯 Common Workflows:");
    println!("  First Time Setup → sprite help --patterns --category getting-started");
    println!("  Daily Workflow → sprite help --patterns --category daily-workflow");
    println!("  Team Collaboration → sprite help --patterns --category collaboration");

    println!();
    println!("🔗 Resources:");
    println!("  Documentation: https://docs.rs/sprite");
    println!("  Repository: https://github.com/hotaq/Sprit-mutil");
    println!("  Issues: https://github.com/hotaq/Sprit-mutil/issues");

    Ok(())
}

/// Show command examples in a structured way.
#[allow(dead_code)]
pub fn show_examples(command: Option<&str>) -> Result<()> {
    let help_system = get_help_system();

    if let Some(cmd) = command {
        if let Some(help) = help_system.get_command_help(cmd) {
            println!("💡 Examples for '{}'\n", cmd);

            if help.examples.is_empty() {
                println!("No examples available for this command.");
                return Ok(());
            }

            for (i, example) in help.examples.iter().enumerate() {
                println!("  {}. {}", i + 1, example);
            }

            println!();
            println!("💡 Tips:");
            for tip in &help.tips {
                println!("  • {}", tip);
            }
        } else {
            println!("❌ Command '{}' not found.", cmd);
            println!(
                "Available commands: {}",
                help_system.list_commands().join(", ")
            );
        }
    } else {
        println!("💡 Common Examples\n");

        let common_examples = [
            ("Initialize Project", "sprite init --agents 3"),
            ("Start Session", "sprite start --session-name dev"),
            ("List Agents", "sprite agents list"),
            ("Send Command to Agent", "sprite hey 1 'npm test'"),
            ("Broadcast to All", "sprite send 'git pull'"),
            ("Navigate Workspace", "cd $(sprite warp --print 1)"),
            ("Check Status", "sprite status --detailed"),
            ("Sync Workspaces", "sprite sync --agent 2"),
            ("Focus Agent", "sprite zoom 1"),
            ("End Session", "sprite kill --all"),
        ];

        for (description, command) in &common_examples {
            println!("  {} → {}", description, command);
        }

        println!();
        println!("For command-specific examples: sprite help --examples <command>");
    }

    Ok(())
}

/// Show command aliases and shortcuts.
#[allow(dead_code)]
pub fn show_aliases() -> Result<()> {
    println!("🔗 Command Aliases & Shortcuts\n");

    println!("Common Aliases (add to your shell configuration):");
    println!("  alias si='sprite init'");
    println!("  alias ss='sprite start'");
    println!("  alias sk='sprite kill'");
    println!("  alias sa='sprite agents'");
    println!("  alias sw='cd $(sprite warp --print \"$1\")'");
    println!("  alias sh='sprite hey'");
    println!();

    println!("Shell Functions:");
    println!("  # Function to quickly switch agent workspaces");
    println!("  sw() {{");
    println!("    if [ $# -eq 0 ]; then");
    println!("      sprite warp --list");
    println!("    else");
    println!("      cd \"$(sprite warp --print \"$1\")\"");
    println!("    fi");
    println!("  }}");
    println!();

    println!("Tmux Shortcuts (when in a sprite session):");
    println!("  Ctrl+B, d    → Detach from session");
    println!("  Ctrl+B, %    → Split pane horizontally");
    println!("  Ctrl+B, \"    → Split pane vertically");
    println!("  Ctrl+B, ←→↑↓ → Navigate panes");
    println!("  Ctrl+B, z    → Zoom current pane");
    println!();

    println!("🔧 Integration:");
    println!("  sprite help --generate-shell-integration  # Generate full integration script");

    Ok(())
}

/// Generate shell integration script.
#[allow(dead_code)]
pub fn generate_shell_integration() -> Result<()> {
    let script = r#"#!/bin/bash
# Sprite workspace integration script
# Add this to your ~/.bashrc or ~/.zshrc

# Tab completion for sprite commands
_sprite_completion() {
  local cur prev words
  cur="${COMP_WORDS[COMP_CWORD]}"
  prev="${COMP_WORDS[COMP_CWORD-1]}"
  words=("${COMP_WORDS[@]}")

  case "$prev" in
    sprite)
      COMPREPLY=($(compgen -W "init start agents attach kill send hey sync remove warp zoom status config help" -- "$cur"))
      ;;
    warp)
      COMPREPLY=($(compgen -W "$(sprite warp --list 2>/dev/null | grep '📁' | awk '{print $3}' | sed 's/://')" -- "$cur"))
      ;;
    hey|send)
      COMPREPLY=($(compgen -W "$(sprite agents list 2>/dev/null | grep -E '^[0-9]+' | awk '{print $1}')" -- "$cur"))
      ;;
  esac
}

complete -F _sprite_completion sprite

# Quick workspace navigation
sw() {
  if [ $# -eq 0 ]; then
    sprite warp --list
  else
    cd "$(sprite warp --print "$1")"
  fi
}

# Quick agent commands
sh() {
  local agent="$1"
  shift
  sprite hey "$agent" "$@"
}

# Sprite session management
ss() { sprite start "$@"; }
sk() { sprite kill "$@"; }
sa() { sprite attach "$@"; }
"#;

    println!("🔧 Shell Integration Script\n");
    println!("{}", script);

    println!("💡 Save this as ~/.sprite_completion.sh and add:");
    println!("   source ~/.sprite_completion.sh");
    println!("   to your shell configuration file.");

    Ok(())
}

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

    #[test]
    fn test_help_args_parsing() {
        // Test basic parsing
        let args = HelpArgs {
            command: Some("init".to_string()),
            search: None,
            patterns: false,
            troubleshooting: false,
            quick: false,
            accessible: false,
            category: None,
        };

        assert_eq!(args.command, Some("init".to_string()));
        assert!(!args.patterns);
    }

    #[test]
    fn test_category_conversion() {
        let help_cat = HelpCategory::GettingStarted;
        let usage_cat: UsageCategory = help_cat.into();
        assert_eq!(usage_cat, UsageCategory::GettingStarted);
    }
}