Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/goose-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ shlex = "1.3.0"
async-trait = "0.1.86"
base64 = "0.22.1"
regex = "1.11.1"
minijinja = { version = "2.8.0", features = ["loader"] }
minijinja = { version = "2.10.2", features = ["loader"] }
nix = { version = "0.30.1", features = ["process", "signal"] }
tar = "0.4"
# Web server dependencies
Expand Down
9 changes: 8 additions & 1 deletion crates/goose-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ pub async fn cli() -> Result<()> {
scheduled_job_id: None,
interactive: true,
quiet: false,
sub_recipes: None,
})
.await;
setup_logging(
Expand Down Expand Up @@ -723,7 +724,7 @@ pub async fn cli() -> Result<()> {
scheduled_job_id,
quiet,
}) => {
let (input_config, session_settings) = match (
let (input_config, session_settings, sub_recipes) = match (
instructions,
input_text,
recipe,
Expand All @@ -743,6 +744,7 @@ pub async fn cli() -> Result<()> {
additional_system_prompt: system,
},
None,
None,
)
}
(Some(file), _, _, _, _) => {
Expand All @@ -760,6 +762,7 @@ pub async fn cli() -> Result<()> {
additional_system_prompt: None,
},
None,
None,
)
}
(_, Some(text), _, _, _) => (
Expand All @@ -769,6 +772,7 @@ pub async fn cli() -> Result<()> {
additional_system_prompt: system,
},
None,
None,
),
(_, _, Some(recipe_name), explain, render_recipe) => {
if explain {
Expand Down Expand Up @@ -800,6 +804,7 @@ pub async fn cli() -> Result<()> {
goose_model: s.goose_model,
temperature: s.temperature,
}),
recipe.sub_recipes,
)
}
(None, None, None, _, _) => {
Expand All @@ -823,6 +828,7 @@ pub async fn cli() -> Result<()> {
scheduled_job_id,
interactive, // Use the interactive flag from the Run command
quiet,
sub_recipes,
})
.await;

Expand Down Expand Up @@ -941,6 +947,7 @@ pub async fn cli() -> Result<()> {
scheduled_job_id: None,
interactive: true, // Default case is always interactive
quiet: false,
sub_recipes: None,
})
.await;
setup_logging(
Expand Down
1 change: 1 addition & 0 deletions crates/goose-cli/src/commands/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub async fn agent_generator(
interactive: false, // Benchmarking is non-interactive
scheduled_job_id: None,
quiet: false,
sub_recipes: None,
})
.await;

Expand Down
74 changes: 71 additions & 3 deletions crates/goose-cli/src/commands/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ pub fn handle_validate(recipe_name: &str) -> Result<()> {
/// # Returns
///
/// Result indicating success or failure
pub fn handle_deeplink(recipe_name: &str) -> Result<()> {
pub fn handle_deeplink(recipe_name: &str) -> Result<String> {
// Load the recipe file first to validate it
match load_recipe(recipe_name) {
Ok(recipe) => {
let mut full_url = String::new();
if let Ok(recipe_json) = serde_json::to_string(&recipe) {
let deeplink = base64::engine::general_purpose::STANDARD.encode(recipe_json);
println!(
Expand All @@ -48,13 +49,80 @@ pub fn handle_deeplink(recipe_name: &str) -> Result<()> {
recipe.title
);
let url_safe = urlencoding::encode(&deeplink);
println!("goose://recipe?config={}", url_safe);
full_url = format!("goose://recipe?config={}", url_safe);
println!("{}", full_url);
}
Ok(())
Ok(full_url)
}
Err(err) => {
println!("{} {}", style("✗").red().bold(), err);
Err(err)
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use std::fs;
use tempfile::TempDir;

fn create_test_recipe_file(dir: &TempDir, filename: &str, content: &str) -> String {
let file_path = dir.path().join(filename);
fs::write(&file_path, content).expect("Failed to write test recipe file");
file_path.to_string_lossy().into_owned()
}

const VALID_RECIPE_CONTENT: &str = r#"
title: "Test Recipe"
description: "A test recipe for deeplink generation"
prompt: "Test prompt content"
instructions: "Test instructions"
"#;

const INVALID_RECIPE_CONTENT: &str = r#"
title: "Test Recipe"
description: "A test recipe for deeplink generation"
prompt: "Test prompt content {{ name }}"
instructions: "Test instructions"
"#;

#[test]
fn test_handle_deeplink_valid_recipe() {
let temp_dir = TempDir::new().expect("Failed to create temp directory");
let recipe_path =
create_test_recipe_file(&temp_dir, "test_recipe.yaml", VALID_RECIPE_CONTENT);

let result = handle_deeplink(&recipe_path);
assert!(result.is_ok());
assert!(result.unwrap().contains("goose://recipe?config=eyJ2ZXJzaW9uIjoiMS4wLjAiLCJ0aXRsZSI6IlRlc3QgUmVjaXBlIiwiZGVzY3JpcHRpb24iOiJBIHRlc3QgcmVjaXBlIGZvciBkZWVwbGluayBnZW5lcmF0aW9uIiwiaW5zdHJ1Y3Rpb25zIjoiVGVzdCBpbnN0cnVjdGlvbnMiLCJwcm9tcHQiOiJUZXN0IHByb21wdCBjb250ZW50In0%3D"));
}

#[test]
fn test_handle_deeplink_invalid_recipe() {
let temp_dir = TempDir::new().expect("Failed to create temp directory");
let recipe_path =
create_test_recipe_file(&temp_dir, "test_recipe.yaml", INVALID_RECIPE_CONTENT);
let result = handle_deeplink(&recipe_path);
assert!(result.is_err());
}

#[test]
fn test_handle_validation_valid_recipe() {
let temp_dir = TempDir::new().expect("Failed to create temp directory");
let recipe_path =
create_test_recipe_file(&temp_dir, "test_recipe.yaml", VALID_RECIPE_CONTENT);

let result = handle_validate(&recipe_path);
assert!(result.is_ok());
}

#[test]
fn test_handle_validation_invalid_recipe() {
let temp_dir = TempDir::new().expect("Failed to create temp directory");
let recipe_path =
create_test_recipe_file(&temp_dir, "test_recipe.yaml", INVALID_RECIPE_CONTENT);
let result = handle_validate(&recipe_path);
assert!(result.is_err());
}
}
1 change: 1 addition & 0 deletions crates/goose-cli/src/recipes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pub mod github_recipe;
pub mod print_recipe;
pub mod recipe;
pub mod search_recipe;
pub mod template_recipe;
Loading
Loading