-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Expand file tree
/
Copy pathcli.rs
More file actions
1873 lines (1693 loc) · 63 KB
/
cli.rs
File metadata and controls
1873 lines (1693 loc) · 63 KB
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
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
use anyhow::Result;
use clap::{Args, CommandFactory, Parser, Subcommand};
use clap_complete::{generate, Shell as ClapShell};
use goose::agents::GoosePlatform;
use goose::builtin_extension::register_builtin_extensions;
use goose::config::{Config, GooseMode};
#[cfg(feature = "telemetry")]
use goose::posthog::get_telemetry_choice;
use goose::recipe::Recipe;
use goose_mcp::mcp_server_runner::{serve, McpCommand};
use goose_mcp::{AutoVisualiserRouter, ComputerControllerServer, MemoryServer, TutorialServer};
#[cfg(feature = "telemetry")]
use crate::commands::configure::configure_telemetry_consent_dialog;
use crate::commands::configure::handle_configure;
use crate::commands::info::handle_info;
use crate::commands::project::{handle_project_default, handle_projects_interactive};
use crate::commands::recipe::{handle_deeplink, handle_list, handle_open, handle_validate};
use crate::commands::term::{
handle_term_info, handle_term_init, handle_term_log, handle_term_run, Shell,
};
use crate::commands::schedule::{
handle_schedule_add, handle_schedule_cron_help, handle_schedule_list, handle_schedule_remove,
handle_schedule_run_now, handle_schedule_services_status, handle_schedule_services_stop,
handle_schedule_sessions,
};
use crate::commands::session::{handle_session_list, handle_session_remove};
use crate::recipes::extract_from_cli::extract_recipe_info_from_cli;
use crate::recipes::recipe::{explain_recipe, render_recipe_as_yaml};
use crate::session::{build_session, SessionBuilderConfig};
use goose::agents::Container;
use goose::session::session_manager::SessionType;
use goose::session::SessionManager;
use std::io::Read;
use std::path::PathBuf;
use tracing::warn;
fn generate_serve_secret_key() -> String {
use rand::distributions::{Alphanumeric, DistString};
format!(
"goose-acp-{}",
Alphanumeric.sample_string(&mut rand::thread_rng(), 32)
)
}
#[derive(Parser)]
#[command(name = "goose", author, version, display_name = "", about, long_about = None)]
pub struct Cli {
#[command(subcommand)]
command: Option<Command>,
}
#[derive(Args, Debug, Clone)]
#[group(required = false, multiple = false)]
pub struct Identifier {
#[arg(
short = 'n',
long,
value_name = "NAME",
help = "Name for the chat session (e.g., 'project-x')",
long_help = "Specify a name for your chat session. When used with --resume, will resume this specific session if it exists."
)]
pub name: Option<String>,
#[arg(
long = "session-id",
alias = "id",
value_name = "SESSION_ID",
help = "Session ID (e.g., '20250921_143022')",
long_help = "Specify a session ID directly. When used with --resume, will resume this specific session if it exists."
)]
pub session_id: Option<String>,
#[arg(
long,
value_name = "PATH",
help = "Legacy: Path for the chat session",
long_help = "Legacy parameter for backward compatibility. Extracts session ID from the file path (e.g., '/path/to/20250325_200615.
jsonl' -> '20250325_200615')."
)]
pub path: Option<PathBuf>,
}
/// Session behavior options shared between Session and Run commands
#[derive(Args, Debug, Clone, Default)]
pub struct SessionOptions {
#[arg(
long,
help = "Enable debug output mode with full content and no truncation",
long_help = "When enabled, shows complete tool responses without truncation and full paths."
)]
pub debug: bool,
#[arg(
long = "max-tool-repetitions",
value_name = "NUMBER",
help = "Maximum number of consecutive identical tool calls allowed",
long_help = "Set a limit on how many times the same tool can be called consecutively with identical parameters. Helps prevent infinite loops."
)]
pub max_tool_repetitions: Option<u32>,
#[arg(
long = "max-turns",
value_name = "NUMBER",
help = "Maximum number of turns allowed without user input (default: 1000)",
long_help = "Set a limit on how many turns (iterations) the agent can take without asking for user input to continue."
)]
pub max_turns: Option<u32>,
#[arg(
long = "container",
value_name = "CONTAINER_ID",
help = "Docker container ID to run extensions inside",
long_help = "Run extensions (stdio and built-in) inside the specified container. The extension must exist in the container. For built-in extensions, goose must be installed inside the container."
)]
pub container: Option<String>,
}
#[derive(Debug, Clone)]
pub struct StreamableHttpOptions {
pub url: String,
pub timeout: u64,
}
fn parse_streamable_http_extension(input: &str) -> Result<StreamableHttpOptions, String> {
let mut input_iter = input.split_whitespace();
let (mut url, mut timeout) = (String::new(), goose::config::DEFAULT_EXTENSION_TIMEOUT);
if let Some(url_str) = input_iter.next() {
url.push_str(url_str);
}
for kv_pair in input_iter {
if !kv_pair.contains('=') {
continue;
}
let (key, value) = kv_pair.split_once('=').unwrap();
// We Can have more keys here for setting other properties
if key == "timeout" {
if let Ok(seconds) = value.parse::<u64>() {
timeout = seconds;
}
}
}
Ok(StreamableHttpOptions { url, timeout })
}
/// Extension configuration options shared between Session and Run commands
#[derive(Args, Debug, Clone, Default)]
pub struct ExtensionOptions {
#[arg(
long = "with-extension",
value_name = "COMMAND",
help = "Add stdio extensions (can be specified multiple times)",
long_help = "Add stdio extensions from full commands with environment variables. Can be specified multiple times. Format: 'ENV1=val1 ENV2=val2 command args...'",
action = clap::ArgAction::Append
)]
pub extensions: Vec<String>,
#[arg(
long = "with-streamable-http-extension",
value_name = "URL",
help = "Add streamable HTTP extensions (can be specified multiple times)",
long_help = "Add streamable HTTP extensions from a URL. Can be specified multiple times. Format: 'url...' or 'url... timeout=100' to set up timeout other than default",
action = clap::ArgAction::Append,
value_parser = parse_streamable_http_extension
)]
pub streamable_http_extensions: Vec<StreamableHttpOptions>,
#[arg(
long = "with-builtin",
value_name = "NAME",
help = "Add builtin extensions by name (e.g., 'developer' or multiple: 'developer,github')",
long_help = "Add one or more builtin extensions that are bundled with goose by specifying their names, comma-separated",
value_delimiter = ','
)]
pub builtins: Vec<String>,
#[arg(
long = "no-profile",
help = "Don't load your default extensions, only use CLI-specified extensions"
)]
pub no_profile: bool,
}
/// Input source and recipe options for the run command
#[derive(Args, Debug, Clone, Default)]
pub struct InputOptions {
/// Path to instruction file containing commands
#[arg(
short,
long,
value_name = "FILE",
help = "Path to instruction file containing commands. Use - for stdin.",
conflicts_with = "input_text",
conflicts_with = "recipe"
)]
pub instructions: Option<String>,
/// Input text containing commands
#[arg(
short = 't',
long = "text",
value_name = "TEXT",
help = "Input text to provide to goose directly",
long_help = "Input text containing commands for goose. Use this in lieu of the instructions argument.",
conflicts_with = "instructions",
conflicts_with = "recipe"
)]
pub input_text: Option<String>,
/// Recipe name or full path to the recipe file
#[arg(
short = None,
long = "recipe",
value_name = "RECIPE_NAME or FULL_PATH_TO_RECIPE_FILE",
help = "Recipe name to get recipe file or the full path of the recipe file (use --explain to see recipe details)",
long_help = "Recipe name to get recipe file or the full path of the recipe file that defines a custom agent configuration. Use --explain to see the recipe's title, description, and parameters.",
conflicts_with = "instructions",
conflicts_with = "input_text"
)]
pub recipe: Option<String>,
/// Additional system prompt to customize agent behavior
#[arg(
long = "system",
value_name = "TEXT",
help = "Additional system prompt to customize agent behavior",
long_help = "Provide additional system instructions to customize the agent's behavior",
conflicts_with = "recipe"
)]
pub system: Option<String>,
#[arg(
long,
value_name = "KEY=VALUE",
help = "Dynamic parameters (e.g., --params username=alice --params channel_name=goose-channel)",
long_help = "Key-value parameters to pass to the recipe file. Can be specified multiple times.",
action = clap::ArgAction::Append,
value_parser = parse_key_val,
)]
pub params: Vec<(String, String)>,
/// Additional sub-recipe file paths
#[arg(
long = "sub-recipe",
value_name = "RECIPE",
help = "Sub-recipe name or file path (can be specified multiple times)",
long_help = "Specify sub-recipes to include alongside the main recipe. Can be:\n - Recipe names from GitHub (if GOOSE_RECIPE_GITHUB_REPO is configured)\n - Local file paths to YAML files\nCan be specified multiple times to include multiple sub-recipes.",
action = clap::ArgAction::Append
)]
pub additional_sub_recipes: Vec<String>,
/// Show the recipe title, description, and parameters
#[arg(
long = "explain",
help = "Show the recipe title, description, and parameters"
)]
pub explain: bool,
/// Print the rendered recipe instead of running it
#[arg(
long = "render-recipe",
help = "Print the rendered recipe instead of running it."
)]
pub render_recipe: bool,
}
/// Output configuration options for the run command
#[derive(Args, Debug, Clone)]
pub struct OutputOptions {
/// Quiet mode - suppress non-response output
#[arg(
short = 'q',
long = "quiet",
help = "Quiet mode. Suppress non-response output, printing only the model response to stdout"
)]
pub quiet: bool,
/// Output format (text, json, stream-json)
#[arg(
long = "output-format",
value_name = "FORMAT",
help = "Output format (text, json, stream-json)",
default_value = "text",
value_parser = clap::builder::PossibleValuesParser::new(["text", "json", "stream-json"])
)]
pub output_format: String,
}
impl Default for OutputOptions {
fn default() -> Self {
Self {
quiet: false,
output_format: "text".to_string(),
}
}
}
/// Model/provider override options for the run command
#[derive(Args, Debug, Clone, Default)]
pub struct ModelOptions {
/// Provider to use for this run (overrides environment variable)
#[arg(
long = "provider",
value_name = "PROVIDER",
help = "Specify the LLM provider to use (e.g., 'openai', 'anthropic')",
long_help = "Override the GOOSE_PROVIDER environment variable for this run. Available providers include openai, anthropic, ollama, databricks, gemini-cli, claude-code, and others."
)]
pub provider: Option<String>,
/// Model to use for this run (overrides environment variable)
#[arg(
long = "model",
value_name = "MODEL",
help = "Specify the model to use (e.g., 'gpt-4o', 'claude-sonnet-4-20250514')",
long_help = "Override the GOOSE_MODEL environment variable for this run. The model must be supported by the specified provider."
)]
pub model: Option<String>,
}
/// Run execution behavior options
#[derive(Args, Debug, Clone, Default)]
pub struct RunBehavior {
/// Continue in interactive mode after processing input
#[arg(
short = 's',
long = "interactive",
help = "Continue in interactive mode after processing initial input"
)]
pub interactive: bool,
/// Run without storing a session file
#[arg(
long = "no-session",
help = "Run without storing a session file",
long_help = "Execute commands without creating or using a session file. Useful for automated runs.",
conflicts_with_all = ["resume", "name", "path"]
)]
pub no_session: bool,
/// Resume a previous run
#[arg(
short,
long,
action = clap::ArgAction::SetTrue,
help = "Resume from a previous run",
long_help = "Continue from a previous run, maintaining the execution state and context."
)]
pub resume: bool,
/// Scheduled job ID (used internally for scheduled executions)
#[arg(
long = "scheduled-job-id",
value_name = "ID",
help = "ID of the scheduled job that triggered this execution (internal use)",
long_help = "Internal parameter used when this run command is executed by a scheduled job. This associates the session with the schedule for tracking purposes.",
hide = true
)]
pub scheduled_job_id: Option<String>,
}
async fn get_or_create_session_id(
identifier: Option<Identifier>,
resume: bool,
no_session: bool,
goose_mode: GooseMode,
) -> Result<Option<String>> {
if no_session {
return Ok(None);
}
let session_manager = SessionManager::instance();
let resolved_id = if resume {
let Some(id) = identifier else {
let sessions = session_manager.list_sessions().await?;
let session_id = sessions
.first()
.map(|s| s.id.clone())
.ok_or_else(|| anyhow::anyhow!("No session found to resume"))?;
return Ok(Some(session_id));
};
if let Some(session_id) = id.session_id {
session_id
} else if let Some(name) = id.name {
let sessions = session_manager.list_sessions().await?;
sessions
.into_iter()
.find(|s| s.name == name || s.id == name)
.map(|s| s.id)
.ok_or_else(|| anyhow::anyhow!("No session found with name '{}'", name))?
} else if let Some(path) = id.path {
path.file_stem()
.and_then(|s| s.to_str())
.map(|s| s.to_string())
.ok_or_else(|| {
anyhow::anyhow!("Could not extract session ID from path: {:?}", path)
})?
} else {
return Err(anyhow::anyhow!("Invalid identifier"));
}
} else {
let Some(id) = identifier else {
let session = session_manager
.create_session(
std::env::current_dir()?,
"CLI Session".to_string(),
SessionType::User,
goose_mode,
)
.await?;
return Ok(Some(session.id));
};
if id.session_id.is_some() {
return Err(anyhow::anyhow!("Cannot use --session-id without --resume"));
}
let has_user_provided_name = id.name.is_some();
let name = id.name.unwrap_or_else(|| "CLI Session".to_string());
let session = session_manager
.create_session(
std::env::current_dir()?,
name.clone(),
SessionType::User,
goose_mode,
)
.await?;
if has_user_provided_name {
session_manager
.update(&session.id)
.user_provided_name(name)
.apply()
.await?;
}
return Ok(Some(session.id));
};
Ok(Some(resolved_id))
}
async fn lookup_session_id(identifier: Identifier) -> Result<String> {
let session_manager = SessionManager::instance();
if let Some(session_id) = identifier.session_id {
Ok(session_id)
} else if let Some(name) = identifier.name {
let sessions = session_manager.list_sessions().await?;
sessions
.into_iter()
.find(|s| s.name == name || s.id == name)
.map(|s| s.id)
.ok_or_else(|| anyhow::anyhow!("No session found with name '{}'", name))
} else if let Some(path) = identifier.path {
path.file_stem()
.and_then(|s| s.to_str())
.map(|s| s.to_string())
.ok_or_else(|| anyhow::anyhow!("Could not extract session ID from path: {:?}", path))
} else {
Err(anyhow::anyhow!("No identifier provided"))
}
}
fn parse_key_val(s: &str) -> Result<(String, String), String> {
match s.split_once('=') {
Some((key, value)) => Ok((key.to_string(), value.to_string())),
None => Err(format!("invalid KEY=VALUE: {}", s)),
}
}
#[derive(Subcommand)]
enum SessionCommand {
#[command(about = "List all available sessions")]
List {
#[arg(
short,
long,
help = "Output format (text, json)",
default_value = "text"
)]
format: String,
#[arg(
long = "ascending",
help = "Sort by date in ascending order (oldest first)",
long_help = "Sort sessions by date in ascending order (oldest first). Default is descending order (newest first)."
)]
ascending: bool,
#[arg(
short = 'w',
short_alias = 'p',
long = "working_dir",
help = "Filter sessions by working directory"
)]
working_dir: Option<PathBuf>,
#[arg(short = 'l', long = "limit", help = "Limit the number of results")]
limit: Option<usize>,
},
#[command(about = "Remove sessions. Runs interactively if no ID, name, or regex is provided.")]
Remove {
#[command(flatten)]
identifier: Option<Identifier>,
#[arg(
short = 'r',
long,
help = "Regex for removing matched sessions (optional)"
)]
regex: Option<String>,
},
#[command(about = "Export a session")]
Export {
#[command(flatten)]
identifier: Option<Identifier>,
#[arg(
short,
long,
help = "Output file path (default: stdout)",
long_help = "Path to save the exported Markdown. If not provided, output will be sent to stdout"
)]
output: Option<PathBuf>,
#[arg(
long = "format",
value_name = "FORMAT",
help = "Output format (markdown, json, yaml)",
default_value = "markdown"
)]
format: String,
},
#[command(name = "diagnostics")]
Diagnostics {
/// Session identifier for generating diagnostics
#[command(flatten)]
identifier: Option<Identifier>,
/// Output path for the diagnostics zip file (optional, defaults to current directory)
#[arg(short = 'o', long)]
output: Option<PathBuf>,
},
}
#[derive(Subcommand, Debug)]
enum SchedulerCommand {
#[command(about = "Add a new scheduled job")]
Add {
#[arg(
long = "schedule-id",
alias = "id",
help = "Unique ID for the recurring scheduled job"
)]
schedule_id: String,
#[arg(
long,
help = "Cron expression for the schedule",
long_help = "Cron expression for when to run the job. Examples:\n '0 * * * *' - Every hour at minute 0\n '0 */2 * * *' - Every 2 hours\n '@hourly' - Every hour (shorthand)\n '0 9 * * *' - Every day at 9:00 AM\n '0 9 * * 1' - Every Monday at 9:00 AM\n '0 0 1 * *' - First day of every month at midnight"
)]
cron: String,
#[arg(
long,
help = "Recipe source (path to file, or base64 encoded recipe string)"
)]
recipe_source: String,
},
#[command(about = "List all scheduled jobs")]
List {},
#[command(about = "Remove a scheduled job by ID")]
Remove {
#[arg(
long = "schedule-id",
alias = "id",
help = "ID of the scheduled job to remove (removes the recurring schedule)"
)]
schedule_id: String,
},
/// List sessions created by a specific schedule
#[command(about = "List sessions created by a specific schedule")]
Sessions {
/// ID of the schedule
#[arg(long = "schedule-id", alias = "id", help = "ID of the schedule")]
schedule_id: String,
#[arg(short = 'l', long, help = "Maximum number of sessions to return")]
limit: Option<usize>,
},
#[command(about = "Run a scheduled job immediately")]
RunNow {
/// ID of the schedule to run
#[arg(long = "schedule-id", alias = "id", help = "ID of the schedule to run")]
schedule_id: String,
},
/// Check status of scheduler services (deprecated - no external services needed)
#[command(about = "[Deprecated] Check status of scheduler services")]
ServicesStatus {},
/// Stop scheduler services (deprecated - no external services needed)
#[command(about = "[Deprecated] Stop scheduler services")]
ServicesStop {},
/// Show cron expression examples and help
#[command(about = "Show cron expression examples and help")]
CronHelp {},
}
#[derive(Subcommand)]
enum GatewayCommand {
#[command(about = "Show gateway status")]
Status {},
#[command(about = "Start a gateway")]
Start {
#[arg(help = "Gateway type (e.g., 'telegram')")]
gateway_type: String,
#[arg(
long = "bot-token",
help = "Bot token for the gateway platform",
long_help = "Authentication token for the gateway platform (e.g., Telegram bot token)"
)]
bot_token: String,
},
#[command(about = "Stop a running gateway")]
Stop {
#[arg(help = "Gateway type to stop (e.g., 'telegram')")]
gateway_type: String,
},
#[command(about = "Generate a pairing code for a gateway")]
Pair {
#[arg(help = "Gateway type to generate pairing code for")]
gateway_type: String,
},
}
#[derive(Subcommand)]
enum RecipeCommand {
/// Validate a recipe file
#[command(about = "Validate a recipe")]
Validate {
/// Recipe name to get recipe file to validate
#[arg(help = "recipe name to get recipe file or full path to the recipe file to validate")]
recipe_name: String,
},
/// Generate a deeplink for a recipe file
#[command(about = "Generate a deeplink for a recipe")]
Deeplink {
/// Recipe name to get recipe file to generate deeplink
#[arg(
help = "recipe name to get recipe file or full path to the recipe file to generate deeplink"
)]
recipe_name: String,
/// Recipe parameters in key=value format (can be specified multiple times)
#[arg(
short = 'p',
long = "param",
value_name = "KEY=VALUE",
help = "Recipe parameter in key=value format (can be specified multiple times)"
)]
params: Vec<String>,
},
/// Open a recipe in Goose Desktop
#[command(about = "Open a recipe in Goose Desktop")]
Open {
/// Recipe name to get recipe file to open
#[arg(help = "recipe name or full path to the recipe file")]
recipe_name: String,
/// Recipe parameters in key=value format (can be specified multiple times)
#[arg(
short = 'p',
long = "param",
value_name = "KEY=VALUE",
help = "Recipe parameter in key=value format (can be specified multiple times)"
)]
params: Vec<String>,
},
/// List available recipes
#[command(about = "List available recipes")]
List {
/// Output format (text, json)
#[arg(
long = "format",
value_name = "FORMAT",
help = "Output format (text, json)",
default_value = "text"
)]
format: String,
/// Show verbose information including recipe descriptions
#[arg(
short,
long,
help = "Show verbose information including recipe descriptions"
)]
verbose: bool,
},
}
#[derive(Subcommand)]
enum Command {
/// Configure goose settings
#[command(about = "Configure goose settings")]
Configure {},
/// Display goose configuration information
#[command(about = "Display goose information")]
Info {
/// Show verbose information including current configuration
#[arg(short, long, help = "Show verbose information including config.yaml")]
verbose: bool,
#[arg(long, help = "Test provider connection and show status")]
check: bool,
},
#[command(about = "Check that your Goose setup is working")]
Doctor {},
/// Manage system prompts and behaviors
#[command(about = "Run one of the mcp servers bundled with goose")]
Mcp {
#[arg(value_parser = clap::value_parser!(McpCommand))]
server: McpCommand,
},
/// Run goose as an ACP (Agent Client Protocol) agent
#[command(about = "Run goose as an ACP agent server on stdio")]
Acp {
/// Add builtin extensions by name
#[arg(
long = "with-builtin",
value_name = "NAME",
help = "Add builtin extensions by name (e.g., 'developer' or multiple: 'developer,github')",
long_help = "Add one or more builtin extensions that are bundled with goose by specifying their names, comma-separated",
value_delimiter = ','
)]
builtins: Vec<String>,
},
/// Start ACP server over HTTP and WebSocket
#[command(about = "Start ACP server over HTTP and WebSocket")]
Serve {
#[arg(long, default_value = "127.0.0.1")]
host: String,
#[arg(long, default_value = "3284")]
port: u16,
#[arg(
long = "with-builtin",
value_name = "NAME",
help = "Add builtin extensions by name (e.g., 'developer' or multiple: 'developer,github')",
long_help = "Add one or more builtin extensions that are bundled with goose by specifying their names, comma-separated",
value_delimiter = ',',
action = clap::ArgAction::Append
)]
builtins: Vec<String>,
},
/// Start or resume interactive chat sessions
#[command(
about = "Start or resume interactive chat sessions",
visible_alias = "s"
)]
Session {
#[command(subcommand)]
command: Option<SessionCommand>,
#[command(flatten)]
identifier: Option<Identifier>,
/// Resume a previous session
#[arg(
short,
long,
help = "Resume a previous session (last used or specified by --name/--session-id)",
long_help = "Continue from a previous session. If --name or --session-id is provided, resumes that specific session. Otherwise, resumes the most recently used session."
)]
resume: bool,
/// Fork a previous session (creates new session with copied history)
#[arg(
long,
requires = "resume",
help = "Fork a previous session (creates new session with copied history)",
long_help = "Create a new session by copying all messages from a previous session. Must be used with --resume. If --name or --session-id is provided, forks that specific session. Otherwise, forks the most recently used session."
)]
fork: bool,
/// Show message history when resuming
#[arg(
long,
help = "Show previous messages when resuming a session",
requires = "resume"
)]
history: bool,
#[command(flatten)]
session_opts: SessionOptions,
#[command(flatten)]
extension_opts: ExtensionOptions,
},
/// Open the last project directory
#[command(about = "Open the last project directory", visible_alias = "p")]
Project {},
/// List recent project directories
#[command(about = "List recent project directories", visible_alias = "ps")]
Projects,
/// Execute commands from an instruction file
#[command(about = "Execute commands from an instruction file or stdin")]
Run {
#[command(flatten)]
input_opts: InputOptions,
#[command(flatten)]
identifier: Option<Identifier>,
#[command(flatten)]
run_behavior: RunBehavior,
#[command(flatten)]
session_opts: SessionOptions,
#[command(flatten)]
extension_opts: ExtensionOptions,
#[command(flatten)]
output_opts: OutputOptions,
#[command(flatten)]
model_opts: ModelOptions,
},
/// Recipe utilities for validation and deeplinking
#[command(about = "Recipe utilities for validation and deeplinking")]
Recipe {
#[command(subcommand)]
command: RecipeCommand,
},
/// Manage scheduled jobs
#[command(about = "Manage scheduled jobs", visible_alias = "sched")]
Schedule {
#[command(subcommand)]
command: SchedulerCommand,
},
/// Manage gateways for external platform integrations (e.g., Telegram)
#[command(
about = "Manage gateways for external platform integrations",
visible_alias = "gw"
)]
Gateway {
#[command(subcommand)]
command: GatewayCommand,
},
/// Update the goose CLI version
#[command(about = "Update the goose CLI version")]
Update {
/// Update to canary version
#[arg(
short,
long,
help = "Update to canary version",
long_help = "Update to the latest canary version of the goose CLI, otherwise updates to the latest stable version."
)]
canary: bool,
/// Enforce to re-configure goose during update
#[arg(short, long, help = "Enforce to re-configure goose during update")]
reconfigure: bool,
},
/// Terminal-integrated session (one session per terminal)
#[command(
about = "Terminal-integrated goose session",
long_about = "Runs a goose session tied to your terminal window.\n\
Each terminal maintains its own persistent session that resumes automatically.\n\n\
Setup:\n \
eval \"$(goose term init zsh)\" # Add to ~/.zshrc\n\n\
Usage:\n \
goose term run \"list files in this directory\"\n \
@goose \"create a python script\" # using alias\n \
@g \"quick question\" # short alias"
)]
Term {
#[command(subcommand)]
command: TermCommand,
},
/// Manage local inference models
#[cfg(feature = "local-inference")]
#[command(about = "Manage local inference models", visible_alias = "lm")]
LocalModels {
#[command(subcommand)]
command: LocalModelsCommand,
},
/// Generate completions for various shells
#[command(about = "Generate the autocompletion script for the specified shell")]
Completion {
#[arg(value_enum)]
shell: ClapShell,
#[arg(long, default_value = "goose", help = "Provide a custom binary name")]
bin_name: String,
},
#[command(
name = "validate-extensions",
about = "Validate a bundled-extensions.json file",
hide = true
)]
ValidateExtensions {
#[arg(help = "Path to the bundled-extensions.json file")]
file: PathBuf,
},
}
#[cfg(feature = "local-inference")]
#[derive(Subcommand)]
enum LocalModelsCommand {
/// Search HuggingFace for GGUF models
#[command(about = "Search HuggingFace for GGUF models")]
Search {
/// Search query
query: String,
/// Maximum number of results
#[arg(short, long, default_value = "10")]
limit: usize,
},
/// Download a model from HuggingFace
#[command(about = "Download a GGUF model (e.g. bartowski/Llama-3.2-1B-Instruct-GGUF:Q4_K_M)")]
Download {
/// Model spec in user/repo:quantization format
spec: String,
},
/// List downloaded local models
#[command(about = "List downloaded local models")]
List,
/// Delete a downloaded model
#[command(about = "Delete a downloaded local model")]
Delete {
/// Model ID to delete
id: String,
},
}
#[derive(Subcommand)]
enum TermCommand {
/// Print shell initialization script
#[command(
about = "Print shell initialization script",
long_about = "Prints shell configuration to set up terminal-integrated sessions.\n\
Each terminal gets a persistent goose session that automatically resumes.\n\n\
Setup:\n \
echo 'eval \"$(goose term init zsh)\"' >> ~/.zshrc\n \
source ~/.zshrc\n\n\
With --default (anything typed that isn't a command goes to goose):\n \
echo 'eval \"$(goose term init zsh --default)\"' >> ~/.zshrc"
)]
Init {
/// Shell type (bash, zsh, fish, powershell)
#[arg(value_enum)]
shell: Shell,
#[arg(short, long, help = "Name for the terminal session")]
name: Option<String>,
/// Make goose the default handler for unknown commands
#[arg(
long = "default",
help = "Make goose the default handler for unknown commands",
long_help = "When enabled, anything you type that isn't a valid command will be sent to goose. Only supported for zsh and bash."
)]
default: bool,
},
/// Log a shell command (called by shell hook)
#[command(about = "Log a shell command to the session", hide = true)]
Log {
/// The command that was executed