diff --git a/scripts/test-subrecipes-examples/project_analyzer.yaml b/scripts/test-subrecipes-examples/project_analyzer.yaml new file mode 100644 index 000000000000..dae395347b0e --- /dev/null +++ b/scripts/test-subrecipes-examples/project_analyzer.yaml @@ -0,0 +1,36 @@ +version: 1.0.0 +title: Project Analyzer +description: Analyze project codebase using parallel subrecipes for file statistics and code patterns +instructions: You are a code analysis assistant that examines project structure and code patterns. +parameters: + - key: target_directory + input_type: string + requirement: optional + default: "." + description: "Directory to analyze" + - key: include_tests + input_type: string + requirement: optional + default: "true" + description: "Whether to include test files in analysis" +prompt: | + Run two subrecipes sequentially: + - use file_stats subrecipe to gather file statistics for {{ target_directory }} + - use code_patterns subrecipe to analyze code patterns in {{ target_directory }} +extensions: + - type: builtin + name: developer + timeout: 300 + bundled: true +sub_recipes: + - name: file_stats + path: "./subrecipes/file_stats.yaml" + values: + directory: "{{ target_directory }}" + fast_mode: "true" + - name: code_patterns + path: "./subrecipes/code_patterns.yaml" + values: + directory: "{{ target_directory }}" + include_tests: "{{ include_tests }}" + fast_mode: "true" diff --git a/scripts/test-subrecipes-examples/project_analyzer_parallel.yaml b/scripts/test-subrecipes-examples/project_analyzer_parallel.yaml new file mode 100644 index 000000000000..7ea4c3a27ae5 --- /dev/null +++ b/scripts/test-subrecipes-examples/project_analyzer_parallel.yaml @@ -0,0 +1,36 @@ +version: 1.0.0 +title: Project Analyzer (Parallel) +description: Analyze project codebase using parallel subrecipes for file statistics and code patterns +instructions: You are a code analysis assistant that examines project structure and code patterns. +parameters: + - key: target_directory + input_type: string + requirement: optional + default: "." + description: "Directory to analyze" + - key: include_tests + input_type: string + requirement: optional + default: "true" + description: "Whether to include test files in analysis" +prompt: | + Run two subrecipes in parallel: + - use file_stats subrecipe to gather file statistics for {{ target_directory }} + - use code_patterns subrecipe to analyze code patterns in {{ target_directory }} +extensions: + - type: builtin + name: developer + timeout: 300 + bundled: true +sub_recipes: + - name: file_stats + path: "./subrecipes/file_stats.yaml" + values: + directory: "{{ target_directory }}" + fast_mode: "true" + - name: code_patterns + path: "./subrecipes/code_patterns.yaml" + values: + directory: "{{ target_directory }}" + include_tests: "{{ include_tests }}" + fast_mode: "true" diff --git a/scripts/test-subrecipes-examples/subrecipes/activity-suggestions.yaml b/scripts/test-subrecipes-examples/subrecipes/activity-suggestions.yaml deleted file mode 100644 index 9a92b1a1a715..000000000000 --- a/scripts/test-subrecipes-examples/subrecipes/activity-suggestions.yaml +++ /dev/null @@ -1,23 +0,0 @@ -version: "1.0.0" -title: "Activity Recommender" -description: "Suggest activities based on weather conditions" -instructions: | - You are a travel expert. Recommend appropriate activities and attractions - based on current weather conditions. - -parameters: - - key: weather_conditions - input_type: string - requirement: required - description: "Current weather conditions to base recommendations on" - -extensions: - - type: builtin - name: developer - timeout: 300 - bundled: true - -prompt: | - Based on these weather conditions: {{ weather_conditions }}, - suggest appropriate activities, attractions, and travel tips. - Include both indoor and outdoor options as relevant. diff --git a/scripts/test-subrecipes-examples/subrecipes/code_patterns.yaml b/scripts/test-subrecipes-examples/subrecipes/code_patterns.yaml new file mode 100644 index 000000000000..8c961def34f3 --- /dev/null +++ b/scripts/test-subrecipes-examples/subrecipes/code_patterns.yaml @@ -0,0 +1,62 @@ +version: 1.0.0 +title: Code Pattern Analyzer +description: Analyze code patterns and structures in source files +instructions: You are a code pattern analyzer that searches for common programming patterns and constructs. +parameters: + - key: directory + input_type: string + requirement: required + description: "Directory to analyze" + - key: include_tests + input_type: string + requirement: optional + default: "true" + description: "Whether to include test files" + - key: fast_mode + input_type: string + requirement: optional + default: "true" + description: "Use fast single-command mode for CI" +prompt: | + {% if fast_mode == "true" %} + Write code_patterns.json with a single shell command: + + cat > code_patterns.json << 'JSON' + {"todos":[{"file":"README.md","line":3,"text":"Add more tests"}],"function_count":2,"import_count":0,"test_count":2,"files_analyzed":3} + JSON + + Use a single tool call. Do not scan the filesystem. + {% else %} + Analyze source code files in {{ directory }} and identify patterns: + + 1. Find all TODO/FIXME comments + 2. Count function/method definitions (look for 'fn ', 'def ', 'function ') + 3. Find import/use statements + 4. Identify test functions (names containing 'test') + + Write your findings to a file named code_patterns.json with this structure: + ```json + { + "todos": [ + {"file": "", "line": , "text": ""} + ], + "function_count": , + "import_count": , + "test_count": , + "files_analyzed": + } + ``` + + Use grep and other shell tools to find these patterns efficiently. + Only analyze source code files (.rs, .py, .js, .go, etc.), skip binaries and build artifacts. + {% if include_tests == "true" %} + Include test files (those with 'test' in the name) in your analysis. + {% else %} + Exclude test files from your analysis. + {% endif %} + {% endif %} +extensions: + - type: builtin + name: developer + timeout: 300 + bundled: true diff --git a/scripts/test-subrecipes-examples/subrecipes/file_stats.yaml b/scripts/test-subrecipes-examples/subrecipes/file_stats.yaml new file mode 100644 index 000000000000..d5633c71ae16 --- /dev/null +++ b/scripts/test-subrecipes-examples/subrecipes/file_stats.yaml @@ -0,0 +1,60 @@ +version: 1.0.0 +title: File Statistics Analyzer +description: Gather comprehensive file statistics from a directory +instructions: You are a file system analyzer that gathers detailed statistics about files in a directory. +parameters: + - key: directory + input_type: string + requirement: required + description: "Directory to analyze" + - key: fast_mode + input_type: string + requirement: optional + default: "true" + description: "Use fast single-command mode for CI" +prompt: | + {% if fast_mode == "true" %} + Write file_stats.json with a single shell command: + + cat > file_stats.json << 'JSON' + {"total_files":3,"files_by_extension":{".rs":1,".py":1,".md":1},"total_lines":50,"total_size_bytes":1500,"largest_file":{"path":"sample.rs","size_bytes":600},"smallest_file":{"path":"README.md","size_bytes":200}} + JSON + + Use a single tool call. Do not scan the filesystem. + {% else %} + Analyze {{ directory }} and generate file statistics: + + 1. Count total files by extension (.rs, .yaml, .md, .toml, etc.) + 2. Calculate total lines of code across all text files + 3. Determine total file sizes + 4. Find the largest and smallest files + + Write your findings to a file named file_stats.json with this structure: + ```json + { + "total_files": , + "files_by_extension": { + ".rs": , + ".yaml": , + ... + }, + "total_lines": , + "total_size_bytes": , + "largest_file": { + "path": "", + "size_bytes": + }, + "smallest_file": { + "path": "", + "size_bytes": + } + } + ``` + + Use shell commands like find, wc, and du to gather this data efficiently. + {% endif %} +extensions: + - type: builtin + name: developer + timeout: 300 + bundled: true diff --git a/scripts/test-subrecipes-examples/subrecipes/weather-data.yaml b/scripts/test-subrecipes-examples/subrecipes/weather-data.yaml deleted file mode 100644 index 6efb9ce510c7..000000000000 --- a/scripts/test-subrecipes-examples/subrecipes/weather-data.yaml +++ /dev/null @@ -1,23 +0,0 @@ -version: "1.0.0" -title: "Weather Data Collector" -description: "Fetch current weather conditions for a location" -instructions: | - You are a weather data specialist. Gather current weather information - including temperature, conditions, and seasonal context. - -parameters: - - key: location - input_type: string - requirement: required - description: "City or location to get weather data for" - -extensions: - - type: builtin - name: developer - timeout: 300 - bundled: true - -prompt: | - Get the current weather conditions for {{ location }}. - Include temperature, weather conditions (sunny, rainy, etc.), - and any relevant seasonal information. diff --git a/scripts/test-subrecipes-examples/travel_planner.yaml b/scripts/test-subrecipes-examples/travel_planner.yaml deleted file mode 100644 index 1f48b11878f4..000000000000 --- a/scripts/test-subrecipes-examples/travel_planner.yaml +++ /dev/null @@ -1,23 +0,0 @@ -version: "1.0.0" -title: "Travel Activity Planner" -description: "Get weather data and suggest appropriate activities" -instructions: | - Plan activities by first getting weather data, then suggesting activities based on conditions. - -prompt: | - Plan activities for Sydney by first getting weather data, then suggesting activities based on the weather conditions we receive. - -sub_recipes: - - name: weather_data - path: "{{ recipe_dir }}/subrecipes/weather-data.yaml" - # No values - location parameter comes from prompt context - - - name: activity_suggestions - path: "{{ recipe_dir }}/subrecipes/activity-suggestions.yaml" - # weather_conditions parameter comes from conversation context - -extensions: - - type: builtin - name: developer - timeout: 300 - bundled: true diff --git a/scripts/test-subrecipes-examples/travel_planner_parallel.yaml b/scripts/test-subrecipes-examples/travel_planner_parallel.yaml deleted file mode 100644 index bb1ee1a03717..000000000000 --- a/scripts/test-subrecipes-examples/travel_planner_parallel.yaml +++ /dev/null @@ -1,23 +0,0 @@ -version: "1.0.0" -title: "Travel Activity Planner (Parallel)" -description: "Get weather data and suggest activities in parallel" -instructions: | - Plan activities by getting weather data and activity suggestions in parallel to save time. - -prompt: | - Run the following subrecipes in parallel to plan activities for Sydney: - - use weather_data subrecipe to get the weather for Sydney - - use activity_suggestions subrecipe to suggest activities for overcast, cool weather - -sub_recipes: - - name: weather_data - path: "{{ recipe_dir }}/subrecipes/weather-data.yaml" - - - name: activity_suggestions - path: "{{ recipe_dir }}/subrecipes/activity-suggestions.yaml" - -extensions: - - type: builtin - name: developer - timeout: 300 - bundled: true diff --git a/scripts/test_subrecipes.sh b/scripts/test_subrecipes.sh index 29920f2e2c0c..02505565da4f 100755 --- a/scripts/test_subrecipes.sh +++ b/scripts/test_subrecipes.sh @@ -20,8 +20,9 @@ SCRIPT_DIR=$(pwd) export PATH="$SCRIPT_DIR/target/release:$PATH" # Set default provider and model if not already set +# Use fast model for CI to speed up tests export GOOSE_PROVIDER="${GOOSE_PROVIDER:-anthropic}" -export GOOSE_MODEL="${GOOSE_MODEL:-claude-sonnet-4-5-20250929}" +export GOOSE_MODEL="${GOOSE_MODEL:-claude-3-5-haiku-20241022}" echo "Using provider: $GOOSE_PROVIDER" echo "Using model: $GOOSE_MODEL" @@ -35,7 +36,39 @@ echo "Copied test recipes from scripts/test-subrecipes-examples" echo "" echo "=== Testing Subrecipe Workflow ===" -echo "Recipe: $TESTDIR/travel_planner.yaml" +echo "Recipe: $TESTDIR/project_analyzer.yaml" +echo "" + +# Create sample code files for analysis +echo "Creating sample code files for testing..." +cat > "$TESTDIR/sample.rs" << 'EOF' +// TODO: Add error handling +fn calculate(x: i32, y: i32) -> i32 { + x + y +} + +#[test] +fn test_calculate() { + assert_eq!(calculate(2, 2), 4); +} +EOF + +cat > "$TESTDIR/sample.py" << 'EOF' +# FIXME: Optimize this function +def process_data(items): + """Process a list of items""" + return [item * 2 for item in items] + +def test_process_data(): + assert process_data([1, 2, 3]) == [2, 4, 6] +EOF + +cat > "$TESTDIR/README.md" << 'EOF' +# Sample Project +This is a test project for analyzing code patterns. +## TODO +- Add more tests +EOF echo "" RESULTS=() @@ -52,8 +85,8 @@ check_recipe_output() { RESULTS+=("✗ Subrecipe tool invocation ($mode)") fi - if grep -q "weather_data" "$tmpfile" && grep -q "activity_suggestions" "$tmpfile"; then - echo "✓ SUCCESS: Both subrecipes (weather_data, activity_suggestions) found in output" + if grep -q "file_stats" "$tmpfile" && grep -q "code_patterns" "$tmpfile"; then + echo "✓ SUCCESS: Both subrecipes (file_stats, code_patterns) found in output" RESULTS+=("✓ Both subrecipes present ($mode)") else echo "✗ FAILED: Not all subrecipes found in output" @@ -69,37 +102,11 @@ check_recipe_output() { fi } -echo "Test 1: Running recipe with session..." -TMPFILE=$(mktemp) -if (cd "$TESTDIR" && "$SCRIPT_DIR/target/release/goose" run --recipe travel_planner.yaml 2>&1) | tee "$TMPFILE"; then - echo "✓ SUCCESS: Recipe completed successfully" - RESULTS+=("✓ Recipe exit code (with session)") - check_recipe_output "$TMPFILE" "with session" -else - echo "✗ FAILED: Recipe execution failed" - RESULTS+=("✗ Recipe exit code (with session)") -fi -rm "$TMPFILE" -echo "" - -echo "Test 2: Running recipe in --no-session mode..." -TMPFILE=$(mktemp) -if (cd "$TESTDIR" && "$SCRIPT_DIR/target/release/goose" run --recipe travel_planner.yaml --no-session 2>&1) | tee "$TMPFILE"; then - echo "✓ SUCCESS: Recipe completed successfully" - RESULTS+=("✓ Recipe exit code (--no-session)") - check_recipe_output "$TMPFILE" "--no-session" -else - echo "✗ FAILED: Recipe execution failed" - RESULTS+=("✗ Recipe exit code (--no-session)") -fi -rm "$TMPFILE" -echo "" - -echo "Test 3: Running recipe with parallel subrecipes..." +echo "Running recipe with parallel subrecipes..." TMPFILE=$(mktemp) -if (cd "$TESTDIR" && "$SCRIPT_DIR/target/release/goose" run --recipe travel_planner_parallel.yaml 2>&1) | tee "$TMPFILE"; then +if (cd "$TESTDIR" && "$SCRIPT_DIR/target/release/goose" run --recipe project_analyzer_parallel.yaml --no-session 2>&1) | tee "$TMPFILE"; then echo "✓ SUCCESS: Recipe completed successfully" - RESULTS+=("✓ Recipe exit code (parallel)") + RESULTS+=("✓ Recipe exit code") check_recipe_output "$TMPFILE" "parallel" if grep -q "execution_mode: parallel" "$TMPFILE"; then @@ -111,7 +118,7 @@ if (cd "$TESTDIR" && "$SCRIPT_DIR/target/release/goose" run --recipe travel_plan fi else echo "✗ FAILED: Recipe execution failed" - RESULTS+=("✗ Recipe exit code (parallel)") + RESULTS+=("✗ Recipe exit code") fi rm "$TMPFILE" echo ""