fix: subrecipe relative path with summon (#7295)

This commit is contained in:
Lifei Zhou
2026-02-18 17:01:47 +11:00
committed by GitHub
parent e30382066f
commit cc51ec0941
2 changed files with 29 additions and 5 deletions
+28 -4
View File
@@ -10,7 +10,9 @@ use crate::state::AppState;
use anyhow::Result;
use axum::http::StatusCode;
use goose::agents::Agent;
use goose::recipe::build_recipe::{build_recipe_from_template, RecipeError};
use goose::recipe::build_recipe::{
build_recipe_from_template, resolve_sub_recipe_path, RecipeError,
};
use goose::recipe::local_recipes::{get_recipe_library_dir, list_local_recipes};
use goose::recipe::validate_recipe::validate_recipe_template_from_content;
use goose::recipe::Recipe;
@@ -44,13 +46,23 @@ pub fn short_id_from_path(path: &str) -> String {
pub fn get_all_recipes_manifests() -> Result<Vec<RecipeManifest>> {
let recipes_with_path = list_local_recipes()?;
let mut recipe_manifests_with_path = Vec::new();
for (file_path, recipe) in recipes_with_path {
for (file_path, mut recipe) in recipes_with_path {
let Ok(last_modified) = fs::metadata(file_path.clone())
.map(|m| chrono::DateTime::<chrono::Utc>::from(m.modified().unwrap()).to_rfc3339())
else {
continue;
};
if let Some(recipe_dir) = file_path.parent() {
if let Some(ref mut sub_recipes) = recipe.sub_recipes {
for sr in sub_recipes.iter_mut() {
if let Ok(resolved) = resolve_sub_recipe_path(&sr.path, recipe_dir) {
sr.path = resolved;
}
}
}
}
let manifest_with_path = RecipeManifest {
id: short_id_from_path(file_path.to_string_lossy().as_ref()),
recipe,
@@ -126,10 +138,22 @@ pub async fn get_recipe_file_path_by_id(
pub async fn load_recipe_by_id(state: &AppState, id: &str) -> Result<Recipe, ErrorResponse> {
let path = get_recipe_file_path_by_id(state, id).await?;
Recipe::from_file_path(&path).map_err(|err| ErrorResponse {
let mut recipe = Recipe::from_file_path(&path).map_err(|err| ErrorResponse {
message: format!("Failed to load recipe: {}", err),
status: StatusCode::INTERNAL_SERVER_ERROR,
})
})?;
if let Some(recipe_dir) = path.parent() {
if let Some(ref mut sub_recipes) = recipe.sub_recipes {
for sr in sub_recipes.iter_mut() {
if let Ok(resolved) = resolve_sub_recipe_path(&sr.path, recipe_dir) {
sr.path = resolved;
}
}
}
}
Ok(recipe)
}
pub async fn build_recipe_with_parameter_values(
+1 -1
View File
@@ -153,7 +153,7 @@ where
Ok((param_map, missing_params))
}
fn resolve_sub_recipe_path(
pub fn resolve_sub_recipe_path(
sub_recipe_path: &str,
parent_recipe_dir: &Path,
) -> Result<String, RecipeError> {