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
2 changes: 1 addition & 1 deletion crates/goose-cli/src/recipes/extract_from_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn extract_recipe_info_from_cli(
}
Ok((
InputConfig {
contents: recipe.prompt,
contents: recipe.prompt.filter(|s| !s.trim().is_empty()),
extensions_override: recipe.extensions,
additional_system_prompt: recipe.instructions,
},
Expand Down
1 change: 0 additions & 1 deletion crates/goose-cli/src/recipes/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ pub fn load_recipe_content_as_template(
missing_parameters_command_line(missing_params)
));
}

render_recipe_content_with_params(&recipe_file_content, &params_for_template)
}

Expand Down
1 change: 0 additions & 1 deletion crates/goose-cli/src/recipes/search_recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ fn read_recipe_file<P: AsRef<Path>>(recipe_path: P) -> Result<RecipeFile> {

let content = fs::read_to_string(&path)
.map_err(|e| anyhow!("Failed to read recipe file {}: {}", path.display(), e))?;

let canonical = path.canonicalize().map_err(|e| {
anyhow!(
"Failed to resolve absolute path for {}: {}",
Expand Down
24 changes: 23 additions & 1 deletion crates/goose-cli/src/recipes/template_recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{
use anyhow::Result;
use goose::recipe::Recipe;
use minijinja::{Environment, UndefinedBehavior};
use regex::Regex;

use crate::recipes::recipe::BUILT_IN_RECIPE_DIR_PARAM;

Expand All @@ -15,8 +16,13 @@ pub fn render_recipe_content_with_params(
content: &str,
params: &HashMap<String, String>,
) -> Result<String> {
// Pre-process content to replace empty double quotes with single quotes
// This prevents MiniJinja from escaping "" to "\"\"" which would break YAML parsing
let re = Regex::new(r#":\s*"""#).unwrap();
let processed_content = re.replace_all(content, ": ''");

let env = add_template_in_env(
content,
&processed_content,
params.get(BUILT_IN_RECIPE_DIR_PARAM).unwrap().clone(),
UndefinedBehavior::Strict,
)?;
Expand Down Expand Up @@ -168,5 +174,21 @@ mod tests {
let err = render_recipe_content_with_params(content, &params).unwrap_err();
assert!(err.to_string().contains("unexpected end of input"));
}

#[test]
fn test_empty_prompt() {
let content = r#"
prompt: ""
name: "Simple Recipe"
description: "A test recipe"
"#;
let params = HashMap::from([("recipe_dir".to_string(), "test_dir".to_string())]);
let result = render_recipe_content_with_params(content, &params).unwrap();

assert!(result.contains("prompt: ''"));
assert!(!result.contains(r#"prompt: "\"\"""#)); // Should not contain escaped quotes

assert!(result.contains(r#"name: "Simple Recipe""#));
}
}
}
Loading