-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcode_optimization.yaml
More file actions
127 lines (103 loc) · 3.73 KB
/
Copy pathcode_optimization.yaml
File metadata and controls
127 lines (103 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
id: code-optimization
name: Code Optimization Pipeline
description: Analyze and optimize code for performance and best practices
parameters:
code_file:
type: string
required: true
description: Path to the code file to optimize
language:
type: string
default: python
description: Programming language
steps:
- id: read_code
tool: filesystem
action: read
parameters:
path: "{{code_file}}"
- id: analyze_code
action: analyze_text
parameters:
text: |
Analyze this {{language}} code for optimization opportunities:
```{{language}}
{{read_code.result.content}}
```
Identify:
1. Performance bottlenecks
2. Code quality issues
3. Best practice violations
model: "gpt-5-mini"
analysis_type: "code_quality"
dependencies:
- read_code
- id: optimize_code
action: generate_text
parameters:
prompt: |
Based on this analysis:
{{analyze_code.result}}
Provide an optimized version of the {{language}} code that addresses the identified issues.
IMPORTANT:
- Return ONLY valid {{language}} code syntax
- Use {{language}}-specific best practices and conventions
- Do not include any markdown formatting or explanations
- Do not include ```{{language}}``` or any markdown blocks
- The output must be pure, executable {{language}} code
Language: {{language}}
model: "gpt-5-mini"
max_tokens: 2000
dependencies:
- analyze_code
- id: clean_optimized_code
action: generate_text
parameters:
prompt: |
Extract ONLY the {{language}} code from the following text, removing any markdown formatting or explanations:
{{optimize_code.result}}
Return ONLY the pure {{language}} code without any ```{{language}}``` blocks, explanations, or formatting.
The output must be valid, executable {{language}} code with proper {{language}} syntax.
Target Language: {{language}}
model: "gpt-5-mini"
max_tokens: 2000
dependencies:
- optimize_code
- id: save_optimized_code
tool: filesystem
action: write
parameters:
path: "examples/outputs/code_optimization/optimized_{{code_file | basename}}"
content: "{{clean_optimized_code.result}}"
dependencies:
- clean_optimized_code
- id: save_analysis_report
tool: filesystem
action: write
parameters:
path: "examples/outputs/code_optimization/code_optimization_report_{{ execution.timestamp | slugify }}.md"
content: |
# Code Optimization Report
**File:** {{code_file}}
**Language:** {{language}}
**Date:** {{ execution.timestamp | date('%Y-%m-%d %H:%M:%S') }}
## Analysis Results
{{analyze_code.result}}
## Optimization Summary
The optimized code has been saved to: examples/outputs/code_optimization/optimized_{{code_file | basename}}
## Original vs Optimized
### Original Code Issues Identified:
See analysis above for detailed breakdown.
### Optimized Code Benefits:
- Improved performance through algorithmic optimizations
- Enhanced code quality and maintainability
- Better error handling and validation
- Adherence to best practices and conventions
dependencies:
- analyze_code
- optimize_code
outputs:
analysis: "{{analyze_code.result}}"
optimized_code: "{{clean_optimized_code.result}}"
optimized_file: "optimized_{{code_file | basename}}"
report_file: "{{save_analysis_report.filepath}}"