Douwe/fix include for recipes (#2914)

Co-authored-by: Douwe Osinga <douwe@squareup.com>
Co-authored-by: Michael Neale <michael.neale@gmail.com>
This commit is contained in:
Douwe Osinga
2025-06-20 11:44:53 -04:00
committed by GitHub
parent 1753a51043
commit 2aede8b754
4 changed files with 187 additions and 95 deletions
+33 -8
View File
@@ -17,7 +17,9 @@ use crate::commands::schedule::{
};
use crate::commands::session::{handle_session_list, handle_session_remove};
use crate::logging::setup_logging;
use crate::recipes::recipe::{explain_recipe_with_parameters, load_recipe_as_template};
use crate::recipes::recipe::{
explain_recipe_with_parameters, load_recipe_as_template, load_recipe_content_as_template,
};
use crate::session;
use crate::session::{build_session, SessionBuilderConfig, SessionSettings};
use goose_bench::bench_config::BenchRunConfig;
@@ -431,6 +433,13 @@ enum Command {
)]
explain: bool,
/// Print the rendered recipe instead of running it
#[arg(
long = "render-recipe",
help = "Print the rendered recipe instead of running it."
)]
render_recipe: bool,
/// Maximum number of consecutive identical tool calls allowed
#[arg(
long = "max-tool-repetitions",
@@ -681,6 +690,7 @@ pub async fn cli() -> Result<()> {
handle_projects_interactive()?;
return Ok(());
}
Some(Command::Run {
instructions,
input_text,
@@ -697,11 +707,17 @@ pub async fn cli() -> Result<()> {
builtins,
params,
explain,
render_recipe,
quiet,
}) => {
let (input_config, session_settings) = match (instructions, input_text, recipe, explain)
{
(Some(file), _, _, _) if file == "-" => {
let (input_config, session_settings) = match (
instructions,
input_text,
recipe,
explain,
render_recipe,
) {
(Some(file), _, _, _, _) if file == "-" => {
let mut input = String::new();
std::io::stdin()
.read_to_string(&mut input)
@@ -716,7 +732,7 @@ pub async fn cli() -> Result<()> {
None,
)
}
(Some(file), _, _, _) => {
(Some(file), _, _, _, _) => {
let contents = std::fs::read_to_string(&file).unwrap_or_else(|err| {
eprintln!(
"Instruction file not found — did you mean to use goose run --text?\n{}",
@@ -733,7 +749,7 @@ pub async fn cli() -> Result<()> {
None,
)
}
(_, Some(text), _, _) => (
(_, Some(text), _, _, _) => (
InputConfig {
contents: Some(text),
extensions_override: None,
@@ -741,11 +757,20 @@ pub async fn cli() -> Result<()> {
},
None,
),
(_, _, Some(recipe_name), explain) => {
(_, _, Some(recipe_name), explain, render_recipe) => {
if explain {
explain_recipe_with_parameters(&recipe_name, params)?;
return Ok(());
}
if render_recipe {
let recipe = load_recipe_content_as_template(&recipe_name, params)
.unwrap_or_else(|err| {
eprintln!("{}: {}", console::style("Error").red().bold(), err);
std::process::exit(1);
});
println!("{}", recipe);
return Ok(());
}
let recipe =
load_recipe_as_template(&recipe_name, params).unwrap_or_else(|err| {
eprintln!("{}: {}", console::style("Error").red().bold(), err);
@@ -764,7 +789,7 @@ pub async fn cli() -> Result<()> {
}),
)
}
(None, None, None, _) => {
(None, None, None, _, _) => {
eprintln!("Error: Must provide either --instructions (-i), --text (-t), or --recipe. Use -i - for stdin.");
std::process::exit(1);
}