@@ -26,10 +26,10 @@ const (
2626 modelGemini = "gemini-2.5-pro"
2727
2828 providerCodex = "codex"
29- modelCodex = "gpt-5-nano "
29+ modelCodex = "gpt-5"
3030)
3131
32- //go:embed analyse .md
32+ //go:embed analyser .md
3333var analysePrompt string
3434
3535type analyser struct {
@@ -49,14 +49,6 @@ func (a *analyser) Run(ctx context.Context, provider string, model string) error
4949 return fmt .Errorf ("provider tool '%s' not found in PATH" , provider )
5050 }
5151
52- outputFile := filepath .Join (a .outputDir , analysisFileName )
53- stdoutLogFile := filepath .Join (a .outputDir , "analyse.stdout.log" )
54- stderrLogFile := filepath .Join (a .outputDir , "analyse.stderr.log" )
55-
56- if err := os .MkdirAll (filepath .Dir (a .outputDir ), 0755 ); err != nil {
57- return fmt .Errorf ("failed to create output directory: %w" , err )
58- }
59-
6052 var cmd * exec.Cmd
6153
6254 switch provider {
@@ -83,7 +75,11 @@ func (a *analyser) Run(ctx context.Context, provider string, model string) error
8375 return fmt .Errorf ("failed to build command for provider: %s" , provider )
8476 }
8577
86- a .logger .Info ("Running analysis" )
78+ a .logger .Info ("Running analysis" ,
79+ "provider" , provider ,
80+ "model" , model ,
81+ "dir" , a .outputDir ,
82+ )
8783
8884 var stdout , stderr bytes.Buffer
8985 cmd .Stdout = & stdout
@@ -93,44 +89,17 @@ func (a *analyser) Run(ctx context.Context, provider string, model string) error
9389 output := stdout .String ()
9490 errorOutput := stderr .String ()
9591
96- // Save stdout log
97- if err := os .WriteFile (stdoutLogFile , stdout .Bytes (), 0644 ); err != nil {
98- a .logger .Warn ("Failed to save stdout log" , "error" , err )
99- } else {
100- a .logger .Info ("Stdout log saved" , "file" , stdoutLogFile )
101- }
102-
103- // Save stderr log
104- if err := os .WriteFile (stderrLogFile , stderr .Bytes (), 0644 ); err != nil {
105- a .logger .Warn ("Failed to save stderr log" , "error" , err )
106- } else {
107- a .logger .Info ("Stderr log saved" , "file" , stderrLogFile )
108- }
109-
11092 if err != nil {
11193 a .logger .Error ("Analysis command failed" , "error" , err , "stderr" , errorOutput )
112- errorDetails := fmt .Sprintf (
113- "# Analysis Failed\n \n ## Command Error\n %v\n \n ## Standard Error Output\n %s\n \n ## Standard Output\n %s\n " ,
114- err ,
115- errorOutput ,
116- output ,
117- )
118- if output == "" {
119- output = errorDetails
120- } else {
121- output = errorDetails + "\n \n ## Original Output\n " + output
122- }
123- }
124-
125- if output == "" {
126- output = fmt .Sprintf (
127- "# Analysis Failed\n \n No output generated from the analysis command.\n Command: %s\n Error: %v\n " ,
128- cmd .String (),
129- err ,
130- )
94+ return err
13195 }
13296
13397 output = a .extractAnalysis (output )
98+ outputFile := filepath .Join (a .outputDir , analysisFileName )
99+
100+ if err := os .MkdirAll (a .outputDir , 0755 ); err != nil {
101+ return fmt .Errorf ("failed to create output directory: %w" , err )
102+ }
134103
135104 if err := os .WriteFile (outputFile , []byte (output ), 0644 ); err != nil {
136105 return fmt .Errorf ("failed to write analysis: %w" , err )
@@ -144,6 +113,7 @@ func (a *analyser) Run(ctx context.Context, provider string, model string) error
144113func (a * analyser ) buildClaudeCommand (ctx context.Context , model string , prompt string ) * exec.Cmd {
145114 args := []string {
146115 "--model" , model ,
116+ "-p" ,
147117 prompt ,
148118 }
149119 return exec .CommandContext (ctx , "claude" , args ... )
@@ -159,6 +129,7 @@ func (a *analyser) buildGeminiCommand(ctx context.Context, model string, prompt
159129
160130func (a * analyser ) buildCodexCommand (ctx context.Context , model string , prompt string ) * exec.Cmd {
161131 args := []string {
132+ "exec" ,
162133 "--model" , model ,
163134 "--full-auto" ,
164135 prompt ,
@@ -173,12 +144,12 @@ func (a *analyser) checkToolAvailable(tool string) bool {
173144
174145// extractAnalysis extract text between specific markers from the analysis file.
175146func (a * analyser ) extractAnalysis (input string ) string {
176- beginIdx := bytes .Index ([]byte (input ), []byte (beginMarker ))
147+ beginIdx := bytes .LastIndex ([]byte (input ), []byte (beginMarker ))
177148 if beginIdx == - 1 {
178149 a .logger .Warn ("Begin marker not found in analysis output" )
179150 return input
180151 }
181- endIdx := bytes .Index ([]byte (input ), []byte (endMarker ))
152+ endIdx := bytes .LastIndex ([]byte (input ), []byte (endMarker ))
182153 if endIdx == - 1 || endIdx <= beginIdx {
183154 a .logger .Warn ("End marker not found or invalid in analysis output" )
184155 return input
0 commit comments