gptengage 1.2.1

Multi-AI CLI orchestrator for Claude Code, Codex, and Gemini
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
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
//! CLI argument parsing and command dispatching

use clap::{Parser, Subcommand, ValueEnum};

#[derive(Parser)]
#[command(name = "gptengage")]
#[command(
    about = "Multi-AI CLI Orchestrator - Debate, Ideate & Invoke across Claude Code, Codex, and Gemini",
    long_about = "Multi-AI CLI Orchestrator - Debate, Ideate & Invoke across Claude Code, Codex, and Gemini

gptengage enables orchestration of multiple AI CLI tools (Claude Code, Codex, Gemini)
for debates, ideation, code reviews, and interactive sessions.

DEFAULT TIMEOUT:
    120 seconds per CLI invocation. Override with --timeout or config defaultTimeout.

QUICK START:
    gptengage status                    Check available CLIs
    gptengage invoke claude \"Hello\"     Simple invocation
    gptengage debate \"Topic here\"       Multi-AI debate
    gptengage ideate \"Seed idea\"        Divergent idea generation

EXAMPLES:
    # Check which AI CLIs are available
    gptengage status

    # Invoke a single AI
    gptengage invoke claude \"Explain this code\" --context-file src/main.rs

    # Run a debate between all available AIs
    gptengage debate \"Should we use microservices?\" --rounds 5

    # Run a debate with specific personas
    gptengage debate \"Tech stack\" -p \"claude:CTO,codex:Architect\"

    # Generate a tree of divergent ideas from a seed
    gptengage ideate \"Build a social app for pet owners\" --sigma 1.5 --select

    # Generate agent definitions for programmatic use
    gptengage generate-agents --topic \"API design\" --roles \"Lead,PM\" -o agents.json
    gptengage debate \"API design\" --agent-file agents.json

For detailed help on any command, use: gptengage <command> --help"
)]
#[command(version)]
#[command(author)]
pub struct Cli {
    #[command(subcommand)]
    pub command: Commands,
}

#[derive(Subcommand)]
pub enum Commands {
    /// Run a multi-AI debate (Claude + Codex + Gemini)
    ///
    /// TERMINOLOGY NOTE:
    ///   --agent       Selects a CLI/model (claude, codex, gemini), not an AI agent.
    ///                 Use with --instances to spawn multiple participants of the same CLI.
    ///   --agent-file  Structured participant definitions (JSON) for AI agents consuming
    ///                 this tool programmatically. Generate with 'generate-agents' command.
    ///
    /// Examples:
    ///   # Default debate (Claude, Codex, Gemini without personas)
    ///   gptengage debate "Should we migrate to microservices?"
    ///
    ///   # Multi-instance: 3 Claude instances (leverages nondeterminism)
    ///   gptengage debate "Code review strategy" --agent claude --instances 3
    ///
    ///   # With personas (human-friendly format)
    ///   gptengage debate "Tech stack decision" -p "claude:CTO,claude:Architect,codex:Engineer"
    ///
    ///   # With agent definition file (for programmatic/agent use)
    ///   gptengage debate "API design strategy" --agent-file agents.json
    ///
    ///   # 5 rounds with JSON output
    ///   gptengage debate "REST vs GraphQL" --rounds 5 --output json
    #[command(verbatim_doc_comment)]
    Debate {
        /// The topic to debate (optional if piping via stdin)
        ///
        /// Can be omitted when piping input via stdin.
        /// Example: echo "topic" | gptengage debate
        #[arg(default_value = "", verbatim_doc_comment)]
        topic: String,

        /// Select a single CLI to use for all participants
        ///
        /// Values: claude, codex, gemini
        ///
        /// Use with --instances to create multi-instance debates where the same
        /// LLM debates itself (leveraging nondeterminism and debate dynamics).
        ///
        /// Examples:
        ///   --agent claude --instances 3 (3 Claude instances)
        ///   --agent gemini --instances 2 (2 Gemini instances)
        ///
        /// Cannot be used with --participants or --agent-file
        #[arg(long, conflicts_with_all = ["participants", "agent_file"], verbatim_doc_comment)]
        agent: Option<String>,

        /// Number of instances to spawn when using --agent
        ///
        /// Creates multiple independent instances of the same CLI. Each instance
        /// will produce different outputs due to LLM nondeterminism and respond
        /// to other participants' inputs during the debate.
        ///
        /// Default: 3 when --agent is specified
        ///
        /// Example: --agent claude --instances 5
        ///
        /// Requires --agent to be specified
        #[arg(long, requires = "agent", verbatim_doc_comment)]
        instances: Option<usize>,

        /// Model to use when --agent is specified
        ///
        /// Specifies which model to use for all instances. If not provided,
        /// the CLI uses its default model.
        ///
        /// Examples:
        ///   --agent claude --model claude-sonnet-4-20250514
        ///   --agent codex --model gpt-4o
        ///   --agent gemini --model gemini-2.5-pro
        ///
        /// Requires --agent to be specified
        #[arg(long, short = 'm', requires = "agent", verbatim_doc_comment)]
        model: Option<String>,

        /// Participants with optional persona and model
        ///
        /// Format: "cli:persona,cli:persona,..." or "cli:persona:model,..."
        ///
        /// Examples:
        ///   -p "claude:CEO,claude:Architect,codex:PM"
        ///   -p "claude:Security Expert,gemini:UX Designer"
        ///   -p "claude:CEO:claude-sonnet-4-20250514,codex:CTO:gpt-4o"
        ///
        /// Cannot be used with --agent-file or --agent
        #[arg(long, short = 'p', conflicts_with_all = ["agent_file", "agent"], verbatim_doc_comment)]
        participants: Option<String>,

        /// Path to agent definition file (JSON) with full agent specifications
        ///
        /// Agent files require structured definitions with persona, instructions,
        /// expertise, and communication_style. Use 'generate-agents' to create.
        ///
        /// Example: --agent-file agents.json
        ///
        /// Cannot be used with --participants or --agent
        #[arg(long, conflicts_with_all = ["participants", "agent", "template"], verbatim_doc_comment)]
        agent_file: Option<String>,

        /// Use a predefined debate template
        ///
        /// Templates provide pre-configured participants with personas and instructions.
        /// Use 'gptengage template list' to see available templates.
        ///
        /// Examples:
        ///   --template code-review
        ///   --template security-audit
        ///   --template architecture-decision
        ///
        /// Cannot be used with --participants, --agent, or --agent-file
        #[arg(long, conflicts_with_all = ["participants", "agent", "agent_file"], verbatim_doc_comment)]
        template: Option<String>,

        /// Number of debate rounds (default: 3, or template default if using --template)
        #[arg(long, short = 'r')]
        rounds: Option<usize>,

        /// Output format: text, json, markdown
        #[arg(long, short = 'o', default_value = "text")]
        output: String,

        /// Timeout per CLI invocation in seconds
        ///
        /// The CLI process is terminated if it exceeds this duration.
        /// Default: 120 seconds (2 minutes)
        #[arg(long, short = 't', default_value = "120", verbatim_doc_comment)]
        timeout: u64,

        /// Allow write access within the current directory (default: read-only)
        #[arg(long, verbatim_doc_comment)]
        write: bool,

        /// How to interpret stdin when input is piped
        ///
        /// Controls behavior when data is piped to gptengage:
        ///   auto    - Use stdin as topic if no topic provided, otherwise as context
        ///   context - Always use stdin as additional context
        ///   ignore  - Ignore stdin input
        ///
        /// Examples:
        ///   echo "topic" | gptengage debate                    # stdin becomes topic
        ///   cat code.rs | gptengage debate "Review" --stdin-as context  # stdin is context
        ///   gptengage debate "topic" --stdin-as ignore         # ignore any piped input
        #[arg(long, value_enum, default_value = "auto", verbatim_doc_comment)]
        stdin_as: StdinMode,

        /// Generate a synthesis after the debate completes
        ///
        /// Produces a structured summary including:
        /// - Key points of consensus
        /// - Points of disagreement
        /// - Key insights
        /// - Recommendation (if applicable)
        ///
        /// Example: gptengage debate "topic" --synthesize
        #[arg(long, verbatim_doc_comment)]
        synthesize: bool,

        /// CLI to use for synthesis generation (default: claude)
        ///
        /// Only used when --synthesize is specified.
        /// Example: gptengage debate "topic" --synthesize --synthesizer codex
        #[arg(
            long,
            default_value = "claude",
            requires = "synthesize",
            verbatim_doc_comment
        )]
        synthesizer: String,
    },

    /// Invoke a specific CLI with a prompt
    ///
    /// Examples:
    ///   # Simple invocation
    ///   gptengage invoke claude "Explain quantum computing"
    ///
    ///   # With specific model
    ///   gptengage invoke claude "Explain this" --model claude-sonnet-4-20250514
    ///   gptengage invoke codex "Review code" --model gpt-4o
    ///   gptengage invoke gemini "Analyze" --model gemini-2.5-pro
    ///
    ///   # With session (maintains conversation history)
    ///   gptengage invoke claude "Review my auth code" --session auth-review
    ///   gptengage invoke claude "Fix the JWT bug" --session auth-review
    ///
    ///   # With context file
    ///   gptengage invoke claude "Review this code" --context-file src/main.rs
    ///
    ///   # With custom topic and timeout
    ///   gptengage invoke gemini "Complex analysis" --session analysis --topic "Performance Review" --timeout 180
    #[command(verbatim_doc_comment)]
    Invoke {
        /// Which CLI to invoke: claude, codex, gemini, or a plugin name
        cli: String,

        /// The prompt to send (optional if piping via stdin)
        ///
        /// Can be omitted when piping input via stdin.
        /// Example: echo "question" | gptengage invoke claude
        #[arg(default_value = "", verbatim_doc_comment)]
        prompt: String,

        /// Model to use for the CLI
        ///
        /// Specifies which model the CLI should use. If not provided,
        /// the CLI uses its default model.
        ///
        /// Examples:
        ///   --model claude-sonnet-4-20250514   (Claude)
        ///   --model gpt-4o                      (Codex)
        ///   --model gemini-2.5-pro              (Gemini)
        #[arg(long, short = 'm', verbatim_doc_comment)]
        model: Option<String>,

        /// Session name for persistent conversation
        ///
        /// Sessions maintain full conversation history. Each turn is
        /// injected into subsequent prompts for context continuity.
        ///
        /// Example: --session my-session
        #[arg(long, short = 's', verbatim_doc_comment)]
        session: Option<String>,

        /// Session topic description
        ///
        /// Auto-generated from first prompt if omitted.
        /// Example: --topic "Code review session"
        #[arg(long, verbatim_doc_comment)]
        topic: Option<String>,

        /// File to include as context
        ///
        /// File contents are prepended to the prompt.
        /// Example: --context-file src/auth.rs
        #[arg(long, short = 'c', verbatim_doc_comment)]
        context_file: Option<String>,

        /// Image file(s) to attach for vision models (repeatable)
        ///
        /// Each image is validated and referenced in the prompt so the
        /// underlying CLI can analyze it as a visual input.
        /// Currently supported: claude (uses native @-path image refs).
        /// Codex and Gemini will return a clear error until their invokers
        /// implement image passthrough.
        ///
        /// Example: --image screenshot.png --image hero.jpg
        #[arg(long, short = 'i', verbatim_doc_comment)]
        image: Vec<String>,

        /// Timeout in seconds
        ///
        /// The CLI process is terminated if it exceeds this duration.
        /// Default: 120 seconds (2 minutes)
        #[arg(long, short = 't', default_value = "120", verbatim_doc_comment)]
        timeout: u64,

        /// Allow write access within the current directory (default: read-only)
        #[arg(long, verbatim_doc_comment)]
        write: bool,

        /// How to interpret stdin when input is piped
        ///
        /// Controls behavior when data is piped to gptengage:
        ///   auto    - Use stdin as prompt if no prompt provided, otherwise as context
        ///   context - Always use stdin as additional context
        ///   ignore  - Ignore stdin input
        ///
        /// Examples:
        ///   echo "question" | gptengage invoke claude           # stdin becomes prompt
        ///   cat code.rs | gptengage invoke claude "Review" --stdin-as context
        ///   gptengage invoke claude "prompt" --stdin-as ignore  # ignore any piped input
        #[arg(long, value_enum, default_value = "auto", verbatim_doc_comment)]
        stdin_as: StdinMode,
    },

    /// Manage sessions
    #[command(subcommand)]
    Session(SessionCommands),

    /// Show status of detected CLIs and active sessions
    Status,

    /// Manage CLI plugins
    ///
    /// Plugins allow adding custom LLM CLIs without modifying GPT Engage source code.
    /// Plugin files are TOML configurations stored in ~/.gptengage/plugins/
    ///
    /// Examples:
    ///   # List installed plugins
    ///   gptengage plugin list
    ///
    ///   # Validate a plugin file
    ///   gptengage plugin validate ~/.gptengage/plugins/ollama.toml
    #[command(subcommand, verbatim_doc_comment)]
    Plugin(PluginCommands),

    /// Manage debate templates
    ///
    /// Templates provide pre-configured debate scenarios with defined participants,
    /// personas, and context settings for common use cases.
    ///
    /// Examples:
    ///   # List available templates
    ///   gptengage template list
    ///
    ///   # Show template details
    ///   gptengage template show code-review
    ///
    ///   # Use a template in a debate
    ///   gptengage debate "Review my auth code" --template code-review
    #[command(subcommand, verbatim_doc_comment)]
    Template(TemplateCommands),

    /// Manage configuration
    #[command(subcommand)]
    Config(ConfigCommands),

    /// Generate divergent ideas from a seed (evolutionary ideation)
    ///
    /// Uses sigma-based creativity levels to generate a tree of divergent ideas.
    /// Level 1 produces 3 orthogonal ideas; Level 2 expands each into 3 more.
    /// Use --select for human-in-the-loop selection of which L1 ideas to expand.
    ///
    /// Examples:
    ///   # Quick brainstorm (depth 1, 3 ideas)
    ///   gptengage ideate "Build a social app for pet owners" --sigma 1.0 --depth 1
    ///
    ///   # Full tree (depth 2, up to 12 ideas)
    ///   gptengage ideate "Build a social app for pet owners" --sigma 1.5
    ///
    ///   # Deep tree (depth 4, 120 ideas)
    ///   gptengage ideate "AI tutoring platform" --sigma 1.0 --depth 4
    ///
    ///   # Extreme creativity with custom sigma
    ///   gptengage ideate "Marketplace for freelancers" --sigma 2.7
    ///
    ///   # Beyond limits with --force
    ///   gptengage ideate "Space tourism" --sigma 5.0 --depth 7 --force
    ///
    ///   # Interactive selection of which L1 ideas to expand
    ///   gptengage ideate "AI tutoring platform" --sigma 2.0 --select
    ///
    ///   # JSON output for programmatic use
    ///   gptengage ideate "Marketplace for freelancers" --sigma 1.0 --output json
    ///
    ///   # Truecolor tree output
    ///   gptengage ideate "Build an app" --color truecolor
    #[command(verbatim_doc_comment)]
    Ideate {
        /// The seed idea to diverge from
        #[arg(verbatim_doc_comment)]
        seed: String,

        /// Creativity level (0.0-3.0). Presets: 0.5 (conservative) | 1.0 (notable) | 1.5 (reimagining) | 2.0 (radical)
        ///
        /// Values above 3.0 require --force.
        #[arg(long, default_value = "1.0", verbatim_doc_comment)]
        sigma: f32,

        /// Interactively select which L1 ideas to expand to L2
        #[arg(long, verbatim_doc_comment)]
        select: bool,

        /// Depth of idea tree (1-5). Each level expands every leaf into 3 sub-ideas.
        ///
        /// Values above 5 require --force (exponential cost: 3^depth invocations).
        #[arg(long, default_value = "2", verbatim_doc_comment)]
        depth: u8,

        /// Bypass sigma (>3.0) and depth (>5) safety limits
        #[arg(long, verbatim_doc_comment)]
        force: bool,

        /// Which CLI to use for generation
        #[arg(long, default_value = "claude", verbatim_doc_comment)]
        cli: String,

        /// Output format: text | json
        #[arg(long, short = 'o', default_value = "text", verbatim_doc_comment)]
        output: String,

        /// Timeout per CLI invocation in seconds
        #[arg(long, short = 't', default_value = "120", verbatim_doc_comment)]
        timeout: u64,

        /// Color mode: auto | truecolor | 256 | none
        ///
        /// Controls how the idea tree is colorized:
        ///   auto      - Detect terminal capabilities (default)
        ///   truecolor - Force 24-bit RGB colors with background overlays
        ///   256       - Force 256-color palette
        ///   none      - Plain text, no ANSI escape codes
        #[arg(long, default_value = "auto", verbatim_doc_comment)]
        color: String,

        /// Display output in a scrollable pager (alternate screen)
        ///
        /// Opens the rendered idea tree in a built-in pager with keyboard
        /// navigation: ↑/↓/j/k to scroll, PgUp/PgDn for pages, q to quit.
        /// Has no effect with --output json.
        #[arg(long, verbatim_doc_comment)]
        pager: bool,
    },

    /// Generate agent definitions for debate participants
    ///
    /// Uses AI to create detailed agent definitions with personas, instructions,
    /// expertise areas, and communication styles. Validates all fields before saving.
    ///
    /// Examples:
    ///   # Generate 3 agents for a microservices debate
    ///   gptengage generate-agents \
    ///     --topic "Should we migrate to microservices?" \
    ///     --roles "CEO,Principal Architect,Product Manager" \
    ///     --output agents.json
    ///
    ///   # Use Codex instead of Claude for generation
    ///   gptengage generate-agents \
    ///     --topic "API design strategy" \
    ///     --roles "Backend Lead,Frontend Lead,DBA" \
    ///     --output api-agents.json \
    ///     --use-cli codex
    ///
    ///   # Then use the generated file in a debate
    ///   gptengage debate "Should we migrate to microservices?" --agent-file agents.json
    ///
    /// Generated file format (schema version 1.0):
    ///   {
    ///     "schema_version": "1.0",
    ///     "generated_by": "gptengage-claude",
    ///     "participants": [
    ///       {
    ///         "cli": "claude",
    ///         "persona": "CEO",
    ///         "instructions": "Focus on business impact, ROI, and strategic alignment...",
    ///         "expertise": ["business strategy", "finance", "leadership"],
    ///         "communication_style": "Executive - concise and action-oriented"
    ///       }
    ///     ]
    ///   }
    #[command(verbatim_doc_comment)]
    GenerateAgents {
        /// The debate topic (used to generate relevant agent personas)
        ///
        /// This helps the AI create contextually appropriate agent definitions.
        /// Example: --topic "Should we adopt Kubernetes?"
        #[arg(long, verbatim_doc_comment)]
        topic: String,

        /// Comma-separated list of roles to generate
        ///
        /// Format: "Role1,Role2,Role3"
        /// Examples:
        ///   --roles "CEO,CTO,CFO"
        ///   --roles "Senior Engineer,Product Manager,Designer"
        ///   --roles "Security Expert,Compliance Officer,Legal Counsel"
        #[arg(long, verbatim_doc_comment)]
        roles: String,

        /// Output file path for generated agent definitions
        ///
        /// File will contain validated JSON with schema version 1.0
        /// Example: --output agents.json
        #[arg(long, short = 'o', verbatim_doc_comment)]
        output: String,

        /// CLI to use for generation (default: claude)
        ///
        /// Available: claude, codex, gemini
        /// Example: --use-cli codex
        #[arg(long, default_value = "claude", verbatim_doc_comment)]
        use_cli: String,

        /// Timeout in seconds
        ///
        /// The CLI process is terminated if it exceeds this duration.
        /// Default: 120 seconds (2 minutes)
        #[arg(long, short = 't', default_value = "120", verbatim_doc_comment)]
        timeout: u64,

        /// Allow write access within the current directory (default: read-only)
        #[arg(long, verbatim_doc_comment)]
        write: bool,
    },
}

/// How to interpret stdin input when piped
#[derive(Clone, Copy, Debug, Default, ValueEnum)]
pub enum StdinMode {
    /// Use stdin as the topic (debate) or prompt (invoke)
    #[default]
    Auto,
    /// Use stdin as additional context prepended to the topic/prompt
    Context,
    /// Ignore stdin input
    Ignore,
}

#[derive(Subcommand)]
pub enum SessionCommands {
    /// List all active sessions
    List,

    /// Show session details and history
    Show {
        /// Session name
        name: String,
    },

    /// End a session
    End {
        /// Session name (or --all for all sessions)
        name: Option<String>,

        /// End all sessions
        #[arg(long)]
        all: bool,
    },
}

/// Plugin management commands
#[derive(Subcommand)]
pub enum PluginCommands {
    /// List all installed plugins
    List,

    /// Validate a plugin file without installing
    Validate {
        /// Path to the plugin TOML file
        path: String,
    },
}

/// Template management commands
#[derive(Subcommand)]
pub enum TemplateCommands {
    /// List all available templates
    List,

    /// Show template details
    Show {
        /// Template name
        name: String,
    },
}

#[derive(Subcommand)]
pub enum ConfigCommands {
    /// Get a config value
    Get {
        /// Config key
        key: String,
    },

    /// Set a config value
    Set {
        /// Config key
        key: String,

        /// Config value
        value: String,
    },

    /// List all configuration
    List,
}

impl Cli {
    pub async fn execute(self) -> anyhow::Result<()> {
        use crate::commands::*;
        use crate::invokers::AccessMode;

        match self.command {
            Commands::Debate {
                topic,
                agent,
                instances,
                model,
                participants,
                agent_file,
                template,
                rounds,
                output,
                timeout,
                write,
                stdin_as,
                synthesize,
                synthesizer,
            } => {
                debate::run_debate(debate::DebateOptions {
                    topic,
                    agent,
                    instances,
                    model,
                    participants,
                    agent_file,
                    template,
                    rounds,
                    output,
                    timeout,
                    access_mode: AccessMode::from_write_flag(write),
                    stdin_as,
                    synthesize,
                    synthesizer,
                })
                .await
            }

            Commands::Invoke {
                cli,
                prompt,
                model,
                session,
                topic,
                context_file,
                image,
                timeout,
                write,
                stdin_as,
            } => {
                invoke::run_invoke(
                    cli,
                    model,
                    prompt,
                    session,
                    topic,
                    context_file,
                    image,
                    timeout,
                    AccessMode::from_write_flag(write),
                    stdin_as,
                )
                .await
            }

            Commands::Session(session_cmd) => match session_cmd {
                SessionCommands::List => session::list_sessions().await,
                SessionCommands::Show { name } => session::show_session(name).await,
                SessionCommands::End { name, all } => session::end_session(name, all).await,
            },

            Commands::Status => status::show_status().await,

            Commands::Plugin(plugin_cmd) => match plugin_cmd {
                PluginCommands::List => plugin::list_plugins().await,
                PluginCommands::Validate { path } => plugin::validate_plugin(path).await,
            },

            Commands::Template(template_cmd) => match template_cmd {
                TemplateCommands::List => template::list_templates().await,
                TemplateCommands::Show { name } => template::show_template(name).await,
            },

            Commands::Config(config_cmd) => match config_cmd {
                ConfigCommands::Get { key } => {
                    let config = crate::config::ConfigManager::new()?;
                    match config.get(&key) {
                        Some(value) => println!("{}: {}", key, value),
                        None => println!("Config key '{}' not found", key),
                    }
                    Ok(())
                }
                ConfigCommands::Set { key, value } => {
                    let mut config = crate::config::ConfigManager::new()?;
                    config.set(&key, &value)?;
                    println!("Set {} = {}", key, value);
                    Ok(())
                }
                ConfigCommands::List => {
                    let config = crate::config::ConfigManager::new()?;
                    println!("Configuration:");
                    println!("  default_timeout: {}", config.default_timeout);
                    println!("  default_debate_rounds: {}", config.default_debate_rounds);
                    Ok(())
                }
            },

            Commands::Ideate {
                seed,
                sigma,
                select,
                depth,
                cli,
                output,
                timeout,
                color,
                pager,
                force,
            } => {
                ideate::run_ideate(ideate::IdeateOptions {
                    seed,
                    sigma,
                    select,
                    depth,
                    cli,
                    output,
                    timeout,
                    access_mode: AccessMode::ReadOnly,
                    color,
                    pager,
                    force,
                })
                .await
            }

            Commands::GenerateAgents {
                topic,
                roles,
                output,
                use_cli,
                timeout,
                write,
            } => {
                generate_agents::run_generate_agents(
                    topic,
                    roles,
                    output,
                    use_cli,
                    timeout,
                    AccessMode::from_write_flag(write),
                )
                .await
            }
        }
    }
}