rustchain/cli/
help_examples.rs

1/// Enhanced CLI help text with detailed examples and usage patterns
2/// This module provides rich help content for all RustChain CLI commands
3pub struct CommandExamples;
4
5impl CommandExamples {
6    /// Get detailed help for the main rustchain command
7    pub fn main_help() -> &'static str {
8        r#"RustChain - Advanced AI Agent Framework
9
10USAGE:
11    rustchain <COMMAND>
12
13EXAMPLES:
14    # Quick start - run your first mission
15    rustchain run examples/hello_world.yaml
16
17    # Interactive mode (like Claude Code)
18    rustchain interactive
19
20    # Validate mission before execution
21    rustchain mission validate my_mission.yaml
22
23    # Validate mission before execution
24    rustchain mission validate my_mission.yaml
25
26    # List available missions
27    rustchain mission list
28
29COMMANDS:
30    interactive    Start conversational mode
31    run            Execute a mission file
32    mission        Mission management operations
33    Note: llm and tools commands require respective feature flags to be compiled in
34    safety         Security validation
35    policy         Policy enforcement
36    audit          Audit trail operations
37    config         Configuration management
38    features       Feature detection
39    enterprise     Enterprise features
40
41For detailed help on any command, use:
42    rustchain <COMMAND> --help"#
43    }
44
45    /// Get detailed help for the run command
46    pub fn run_help() -> &'static str {
47        r#"Execute a RustChain mission file
48
49USAGE:
50    rustchain run [OPTIONS] <MISSION>
51
52ARGUMENTS:
53    <MISSION>    Path to the YAML mission file to execute
54
55OPTIONS:
56    -d, --dry-run       Validate and plan execution without running tools
57    -s, --skip-safety   Skip safety validation (use with caution)
58    -h, --help          Print help
59
60EXAMPLES:
61    # Basic execution
62    rustchain run examples/hello_world.yaml
63
64    # Test mission without executing (recommended first)
65    rustchain run my_mission.yaml --dry-run
66
67    # Skip safety checks (only if you trust the mission)
68    rustchain run trusted_mission.yaml --skip-safety
69
70    # Combine options
71    rustchain run mission.yaml --dry-run --skip-safety
72
73MISSION FILE FORMAT:
74    name: "Mission Name"
75    description: "What this mission does"
76    version: "1.0"
77    steps:
78      - id: "step1"
79        step_type: "llm"
80        parameters:
81          provider: "openai"
82          model: "gpt-4"
83          prompt: "Your prompt here"
84
85For mission examples, see: examples/ directory
86For mission validation: rustchain mission validate <file>"#
87    }
88
89    /// Get detailed help for mission commands
90    pub fn mission_help() -> &'static str {
91        r#"Mission management operations
92
93USAGE:
94    rustchain mission <COMMAND>
95
96COMMANDS:
97    list        List available example missions
98    validate    Validate mission file syntax and structure
99    info        Show detailed mission information
100
101EXAMPLES:
102    # See all available example missions
103    rustchain mission list
104
105    # Validate before running (recommended)
106    rustchain mission validate my_mission.yaml
107
108    # Get detailed mission information
109    rustchain mission info examples/hello_world.yaml
110
111VALIDATION CHECKS:
112    CHECKS: YAML syntax correctness
113    CHECKS: Required fields present
114    CHECKS: Step type validity
115    CHECKS: Parameter requirements
116    CHECKS: Dependency resolution
117    CHECKS: Safety assessment
118
119For mission creation guide, see: docs/MISSION_GUIDE.md"#
120    }
121
122    /// Get detailed help for LLM commands
123    pub fn llm_help() -> &'static str {
124        r#"AI model interactions and management
125
126USAGE:
127    rustchain llm <COMMAND>
128
129COMMANDS:
130    models    List available models from providers
131    chat      Interactive chat with AI models
132    test      Test connectivity to LLM providers
133
134EXAMPLES:
135    # List all available models
136    rustchain llm models
137
138    # List models from specific provider
139    rustchain llm models --provider openai
140    rustchain llm models --provider anthropic
141
142    # Chat with default model
143    rustchain llm chat "What is Rust ownership?"
144
145    # Specify model and provider
146    rustchain llm chat "Explain async/await" --model gpt-4 --provider openai
147
148    # Adjust creativity (temperature)
149    rustchain llm chat "Write a story" --temperature 1.2
150
151    # Technical discussion (low temperature)
152    rustchain llm chat "Explain memory safety" --temperature 0.1
153
154    # Test provider connectivity
155    rustchain llm test
156    rustchain llm test openai
157
158SUPPORTED PROVIDERS:
159    • OpenAI (GPT-3.5, GPT-4, GPT-4 Turbo)
160    • Anthropic (Claude 3 family)
161    • Ollama (Local models)
162    • Custom providers via configuration
163
164TEMPERATURE GUIDE:
165    0.0-0.3  Factual, precise responses
166    0.4-0.7  Balanced creativity and accuracy
167    0.8-2.0  Creative, experimental responses
168
169Setup: Configure API keys in environment or config file"#
170    }
171
172    /// Get detailed help for tools commands
173    pub fn tools_help() -> &'static str {
174        r#"Tool management and execution
175
176USAGE:
177    rustchain tools <COMMAND>
178
179COMMANDS:
180    list      List all available tools
181    info      Get detailed information about a tool
182    execute   Execute a tool directly with parameters
183
184EXAMPLES:
185    # List all available tools
186    rustchain tools list
187
188    # Get tool documentation
189    rustchain tools info file_create
190    rustchain tools info http_request
191
192    # Execute tools directly
193    rustchain tools execute file_create --params '{
194        "path": "hello.txt",
195        "content": "Hello, World!"
196    }'
197
198    rustchain tools execute http_request --params '{
199        "url": "https://api.github.com",
200        "method": "GET"
201    }'
202
203    rustchain tools execute command_execute --params '{
204        "command": "ls",
205        "args": ["-la", "/tmp"]
206    }'
207
208AVAILABLE TOOL CATEGORIES:
209    FILE OPERATIONS:
210       • file_create, file_read, file_write
211       • file_delete, file_exists, directory_list
212
213    NETWORK OPERATIONS:
214       • http_request, websocket_connect
215       • api_call, webhook_trigger
216
217    SYSTEM OPERATIONS:
218       • command_execute, process_info
219       • environment_get, path_resolve
220
221    AI OPERATIONS:
222       • llm_call, embedding_generate
223       • text_summarize, sentiment_analyze
224
225PARAMETER FORMAT:
226    Use JSON format for --params option
227    Example: --params '{"key": "value", "number": 42}'
228
229SECURITY:
230    All tools run within safety policy constraints
231    Use 'rustchain policy status' to see current restrictions"#
232    }
233
234    /// Get detailed help for safety commands
235    pub fn safety_help() -> &'static str {
236        r#"Security validation and safety checks
237
238USAGE:
239    rustchain safety <COMMAND>
240
241COMMANDS:
242    validate    Validate mission file for security risks
243    check       Run comprehensive system safety checks
244    report      Generate detailed safety assessment
245
246EXAMPLES:
247    # Validate a mission file
248    rustchain safety validate mission.yaml
249
250    # Strict validation (fail on warnings)
251    rustchain safety validate mission.yaml --strict
252
253    # System-wide safety check
254    rustchain safety check
255
256    # Include policy validation
257    rustchain safety check --include-policies
258
259    # Generate safety report
260    rustchain safety report mission.yaml
261    rustchain safety report mission.yaml --format json
262
263SAFETY CHECKS:
264    MISSION ANALYSIS:
265       • Step type validation
266       • Parameter safety review
267       • Dependency security
268
269    RISK ASSESSMENT:
270       • File system access patterns
271       • Network communication review
272       • Command execution analysis
273
274    POLICY COMPLIANCE:
275       • Corporate policy adherence
276       • Security standard compliance
277       • Access control validation
278
279RISK LEVELS:
280    LOW: Safe to execute
281    MEDIUM: Review recommended
282    HIGH: Caution required
283    CRITICAL: Do not execute
284
285REPORT FORMATS:
286    • text (human-readable, default)
287    • json (machine-readable)
288    • yaml (structured format)
289
290Best Practice: Always validate missions before execution"#
291    }
292
293    /// Get detailed help for policy commands
294    pub fn policy_help() -> &'static str {
295        r#"Policy enforcement and compliance management
296
297USAGE:
298    rustchain policy <COMMAND>
299
300COMMANDS:
301    list        List all active security policies
302    validate    Validate policy configuration
303    status      Show policy enforcement status
304
305EXAMPLES:
306    # Show all active policies
307    rustchain policy list
308
309    # Validate policy configuration
310    rustchain policy validate
311
312    # Check enforcement status
313    rustchain policy status
314
315POLICY CATEGORIES:
316    FILE ACCESS POLICY:
317       • Allowed/blocked directories
318       • File operation restrictions
319       • Permission requirements
320
321    NETWORK POLICY:
322       • Allowed domains and IPs
323       • Port restrictions
324       • Protocol limitations
325
326    COMMAND EXECUTION POLICY:
327       • Allowed/blocked commands
328       • Parameter validation
329       • Privilege restrictions
330
331    LLM SAFETY POLICY:
332       • Content filtering
333       • Prompt injection detection
334       • Response validation
335
336POLICY STATUS INDICATORS:
337    ENFORCED: Policy active and blocking violations
338    WARNING: Policy active but only logging violations
339    DISABLED: Policy not enforced
340    CONFIGURING: Policy being set up
341
342CONFIGURATION:
343    Policies are configured in:
344    • System config: /etc/rustchain/policies/
345    • User config: ~/.rustchain/policies/
346    • Project config: ./rustchain/policies/"#
347    }
348
349    /// Get detailed help for interactive mode
350    pub fn interactive_help() -> &'static str {
351        r#"Start interactive conversational mode
352
353USAGE:
354    rustchain interactive
355
356DESCRIPTION:
357    Interactive mode provides a conversational interface similar to
358    Claude Code, allowing you to:
359
360    • Have natural conversations with AI models
361    • Create and execute missions dynamically
362    • Get real-time help and guidance
363    • Explore RustChain capabilities interactively
364
365EXAMPLES:
366    $ rustchain interactive
367    RustChain Interactive Mode - Type 'help' or 'exit'
368
369    > create a mission to analyze my Rust codebase
370    > run the generated mission
371    > show me performance metrics
372    > help with optimizing the analysis
373    > exit
374
375INTERACTIVE COMMANDS:
376    help           Show available commands
377    exit, quit     Exit interactive mode
378    clear          Clear screen
379    history        Show command history
380    save <file>    Save session to file
381    load <file>    Load previous session
382
383FEATURES:
384    • Intelligent conversation flow
385    • Context-aware suggestions
386    • Mission generation assistance
387    • Real-time execution feedback
388    • Error explanation and fixes
389    • Best practice recommendations
390
391Note: Interactive mode requires LLM provider configuration"#
392    }
393
394    /// Get detailed help for enterprise commands
395    pub fn enterprise_help() -> &'static str {
396        r#"Enterprise features and advanced capabilities
397
398USAGE:
399    rustchain enterprise <COMMAND>
400
401COMMANDS:
402    auth           Authentication and authorization
403    compliance     Compliance and auditing features
404    monitoring     Performance monitoring and metrics
405    multi-tenant   Multi-tenancy management
406
407ENTERPRISE FEATURES:
408    AUTHENTICATION & RBAC:
409       • JWT token management
410       • OAuth2 integration
411       • Role-based access control
412       • Multi-factor authentication
413
414    COMPLIANCE & AUDITING:
415       • GDPR compliance checking
416       • HIPAA compliance validation
417       • SOX audit trail requirements
418       • Custom compliance standards
419
420    MONITORING & PERFORMANCE:
421       • Real-time metrics collection
422       • Performance dashboards
423       • Alerting and notifications
424       • Resource usage tracking
425
426    MULTI-TENANCY:
427       • Tenant isolation
428       • Resource quotas
429       • Billing integration
430       • Custom branding
431
432EXAMPLES:
433    # Setup authentication
434    rustchain enterprise auth init-jwt
435    rustchain enterprise auth setup-oauth2 google --client-id <id>
436
437    # Compliance checking
438    rustchain enterprise compliance verify mission.yaml --standard GDPR
439    rustchain enterprise compliance audit
440
441    # Performance monitoring
442    rustchain enterprise monitoring dashboard
443    rustchain enterprise monitoring start-metrics
444
445    # Multi-tenancy
446    rustchain enterprise multi-tenant create-tenant acme "ACME Corp"
447
448LICENSING:
449    Enterprise features require RustChain Enterprise license
450    Contact: enterprise@rustchain.dev"#
451    }
452
453    /// Get comprehensive feature help
454    pub fn features_help() -> &'static str {
455        r#"Feature detection and capability management
456
457USAGE:
458    rustchain features <COMMAND>
459
460COMMANDS:
461    list      List all features and their availability
462    check     Check if a specific feature is available
463    summary   Show comprehensive feature overview
464    upgrade   Show upgrade recommendations
465
466EXAMPLES:
467    # List all features
468    rustchain features list
469
470    # Filter by category
471    rustchain features list --category llm
472    rustchain features list --category enterprise
473
474    # Show only available features
475    rustchain features list --available-only
476
477    # Check specific feature
478    rustchain features check agent
479    rustchain features check compliance
480
481    # Get feature summary
482    rustchain features summary
483
484    # See upgrade options
485    rustchain features upgrade
486
487FEATURE CATEGORIES:
488    CORE FEATURES (Always Available):
489       • Mission execution
490       • Safety validation
491       • Basic tool support
492
493    AI FEATURES (Require Configuration):
494       • LLM integration
495       • Agent reasoning
496       • RAG capabilities
497
498    ENTERPRISE FEATURES (License Required):
499       • RBAC authentication
500       • Compliance checking
501       • Multi-tenancy
502
503    OPTIONAL FEATURES (Compile-time):
504       • Server mode
505       • Sandbox isolation
506       • Advanced monitoring
507
508FEATURE STATUS:
509    AVAILABLE: Feature ready to use
510    CONFIGURABLE: Requires setup (API keys, etc.)
511    LICENSED: Requires enterprise license
512    UNAVAILABLE: Not compiled or not supported
513
514UPGRADE PATHS:
515    Community → Professional → Enterprise
516
517For licensing information: https://rustchain.dev/pricing"#
518    }
519}
520
521#[cfg(test)]
522mod tests {
523    use super::*;
524
525    #[test]
526    fn test_help_examples_content() {
527        // Test that all help content is non-empty and contains expected keywords
528        assert!(CommandExamples::main_help().contains("RustChain"));
529        assert!(CommandExamples::run_help().contains("Execute"));
530        assert!(CommandExamples::mission_help().contains("Mission"));
531        assert!(CommandExamples::llm_help().contains("AI model"));
532        assert!(CommandExamples::tools_help().contains("Tool management"));
533        assert!(CommandExamples::safety_help().contains("Security"));
534        assert!(CommandExamples::policy_help().contains("Policy"));
535        assert!(CommandExamples::interactive_help().contains("conversational"));
536        assert!(CommandExamples::enterprise_help().contains("Enterprise"));
537        assert!(CommandExamples::features_help().contains("Feature"));
538    }
539
540    #[test]
541    fn test_help_examples_structure() {
542        // Test that help content follows expected structure
543        let main_help = CommandExamples::main_help();
544        assert!(main_help.contains("USAGE:"));
545        assert!(main_help.contains("EXAMPLES:"));
546        assert!(main_help.contains("COMMANDS:"));
547
548        let run_help = CommandExamples::run_help();
549        assert!(run_help.contains("USAGE:"));
550        assert!(run_help.contains("ARGUMENTS:"));
551        assert!(run_help.contains("OPTIONS:"));
552        assert!(run_help.contains("EXAMPLES:"));
553    }
554
555    #[test]
556    fn test_help_examples_formatting() {
557        // Test that help content is properly formatted
558        for help_text in [
559            CommandExamples::main_help(),
560            CommandExamples::run_help(),
561            CommandExamples::mission_help(),
562            CommandExamples::llm_help(),
563            CommandExamples::tools_help(),
564            CommandExamples::safety_help(),
565        ] {
566            // Should not be empty
567            assert!(!help_text.is_empty());
568
569            // Should contain proper formatting
570            assert!(help_text.contains("USAGE:") || help_text.contains("DESCRIPTION:"));
571
572            // Should not have excessive trailing whitespace on lines
573            for line in help_text.lines() {
574                // Allow single trailing space for formatting, but not multiple
575                let trimmed = line.trim_end();
576                if line.len() > trimmed.len() + 1 {
577                    panic!("Line has excessive trailing whitespace: '{}'", line);
578                }
579            }
580        }
581    }
582}