@@ -68,14 +68,19 @@ claude --version || echo "Failed to get Claude version"
6868echo " Claude CLI help:"
6969claude --help || echo " Failed to get Claude help"
7070
71- # Create temp files with descriptive names for better debugging
72- RESPONSE_FILE= $( mktemp -t " claude_analysis_XXXXXX " )
73- FIX_DETAILS_FILE= $( mktemp -t " claude_fix_details_XXXXXX " )
71+ # Create a standard directory for output and debug files
72+ OUTPUT_DIR= " ./claude-output "
73+ mkdir -p " $OUTPUT_DIR "
7474
75- # Create a log file for debugging
76- LOG_FILE=$( mktemp -t " claude_issue_fix_log_XXXXXX" )
75+ # Create files with descriptive names for better debugging
76+ RESPONSE_FILE=" $OUTPUT_DIR /claude_analysis_$ISSUE_NUMBER .txt"
77+ FIX_DETAILS_FILE=" $OUTPUT_DIR /claude_fix_details_$ISSUE_NUMBER .txt"
78+ LOG_FILE=" $OUTPUT_DIR /claude_issue_fix_log_$ISSUE_NUMBER .txt"
79+
80+ # Set up logging
7781exec > >( tee -a " $LOG_FILE " ) 2>&1
7882echo " Starting issue-fix mode at $( date) "
83+ echo " Output directory: $OUTPUT_DIR "
7984echo " Log file: $LOG_FILE "
8085echo " Response file: $RESPONSE_FILE "
8186echo " Fix details file: $FIX_DETAILS_FILE "
@@ -187,42 +192,59 @@ EOF
187192# Run Claude CLI to analyze the issue
188193echo " Sending request to Claude for issue analysis..."
189194
190- # Create a temporary file for the prompt for debugging
191- PROMPT_FILE=$( mktemp )
195+ # Create a prompt file in the output directory
196+ PROMPT_FILE=" $OUTPUT_DIR /prompt_analysis_ $ISSUE_NUMBER .txt "
192197echo " $ANALYZE_PROMPT " > " $PROMPT_FILE "
193198echo " Prompt saved to $PROMPT_FILE for debugging"
194199
195200# Use claude with the -p flag (print) and -d (debug) and pipe input
196201echo " Running: cat prompt | claude -p -d"
197- if ! cat " $PROMPT_FILE " | claude -p -d > " $RESPONSE_FILE " 2> /tmp/claude_error_$ISSUE_NUMBER .log; then
202+ ERROR_LOG=" $OUTPUT_DIR /claude_error_$ISSUE_NUMBER .log"
203+ if ! cat " $PROMPT_FILE " | claude -p -d > " $RESPONSE_FILE " 2> " $ERROR_LOG " ; then
198204 echo " Error: Claude API request failed. Check your API key and connectivity."
199205 echo " Claude CLI version:"
200206 claude --version || echo " Failed to get version"
201207 echo " Error log (if available):"
202- cat /tmp/claude_error_ $ISSUE_NUMBER .log || echo " No error log available"
208+ cat " $ERROR_LOG " || echo " No error log available"
203209 echo " Prompt (first 20 lines):"
204210 cat " $PROMPT_FILE " | head -20
205211 exit 1
206212fi
207213
208- # Keep prompt file for debugging
209214echo " Prompt saved to $PROMPT_FILE for debugging"
210215echo " Response saved to $RESPONSE_FILE "
211216
212217# Parse Claude's response to extract files to examine
213- FILES_TO_EXAMINE=$( grep -Eo " Files Involved:.*" -A 20 " $RESPONSE_FILE " | grep -v " Proposed Changes:" | grep -v " Testing Plan:" | grep " /" | sed -E ' s/^[ -]*([^ ].*)/\1/' | sed -E ' s/ *$//' | grep -v " ^$" )
218+ echo " Extracting files to examine from Claude's response..."
219+ FILES_TO_EXAMINE=$( grep -Eo " Files Involved:.*" -A 20 " $RESPONSE_FILE " | grep -v " Proposed Changes:" | grep -v " Testing Plan:" | grep " /" | sed -E ' s/^[ -]*([^ ].*)/\1/' | sed -E ' s/ *$//' | grep -v " ^$" || echo " " )
220+
221+ # Check if no files were found
222+ if [ -z " $FILES_TO_EXAMINE " ]; then
223+ echo " No specific files identified in the Files Involved section."
224+ # Look for examples/calculator.js specifically since that's mentioned in the error logs
225+ if [ -f " examples/calculator.js" ]; then
226+ FILES_TO_EXAMINE=" examples/calculator.js"
227+ echo " Found examples/calculator.js, will use this file for analysis."
228+ fi
229+ fi
214230
215231# Get content of relevant files
216232EXAMINED_FILES=" "
217- for FILE in $FILES_TO_EXAMINE ; do
218- if [ -f " $FILE " ]; then
219- echo " Examining file: $FILE "
220- EXAMINED_FILES+=" File: $FILE \n\n\`\`\` \n$( cat " $FILE " ) \n\`\`\` \n\n"
221- else
222- echo " File not found: $FILE "
223- EXAMINED_FILES+=" File: $FILE \n\nNot found in repository\n\n"
224- fi
225- done
233+ if [ -z " $FILES_TO_EXAMINE " ]; then
234+ echo " Warning: No files to examine. Will proceed with implementation without file analysis."
235+ EXAMINED_FILES=" No specific files were identified for analysis.\n\n"
236+ else
237+ echo " Files to examine: $FILES_TO_EXAMINE "
238+ for FILE in $FILES_TO_EXAMINE ; do
239+ if [ -f " $FILE " ]; then
240+ echo " Examining file: $FILE "
241+ EXAMINED_FILES+=" File: $FILE \n\n\`\`\` \n$( cat " $FILE " ) \n\`\`\` \n\n"
242+ else
243+ echo " File not found: $FILE "
244+ EXAMINED_FILES+=" File: $FILE \n\nNot found in repository\n\n"
245+ fi
246+ done
247+ fi
226248
227249# Build a prompt for Claude to implement the fix
228250IMPLEMENT_PROMPT=$( cat << EOF
@@ -260,23 +282,23 @@ EOF
260282# Run Claude CLI to implement the fix
261283echo " Sending request to Claude for implementation details..."
262284
263- # Create a temporary file for the prompt for debugging
264- IMPL_PROMPT_FILE=$( mktemp )
285+ # Create an implementation prompt file in the output directory
286+ IMPL_PROMPT_FILE=" $OUTPUT_DIR /prompt_implementation_ $ISSUE_NUMBER .txt "
265287echo " $IMPLEMENT_PROMPT " > " $IMPL_PROMPT_FILE "
266288echo " Implementation prompt saved to $IMPL_PROMPT_FILE for debugging"
267289
268290# Use claude with the -p flag (print) and -d (debug) and pipe input
269291echo " Running: cat prompt | claude -p -d for implementation details"
270- if ! cat " $IMPL_PROMPT_FILE " | claude -p -d > " $FIX_DETAILS_FILE " 2> /tmp/claude_impl_error_$ISSUE_NUMBER .log; then
292+ IMPL_ERROR_LOG=" $OUTPUT_DIR /claude_impl_error_$ISSUE_NUMBER .log"
293+ if ! cat " $IMPL_PROMPT_FILE " | claude -p -d > " $FIX_DETAILS_FILE " 2> " $IMPL_ERROR_LOG " ; then
271294 echo " Error: Claude API request failed when generating implementation details."
272295 echo " Error log (if available):"
273- cat /tmp/claude_impl_error_ $ISSUE_NUMBER .log || echo " No implementation error log available"
296+ cat " $IMPL_ERROR_LOG " || echo " No implementation error log available"
274297 echo " Implementation prompt (first 20 lines):"
275298 cat " $IMPL_PROMPT_FILE " | head -20
276299 exit 1
277300fi
278301
279- # Keep prompt file for debugging
280302echo " Implementation prompt saved to $IMPL_PROMPT_FILE for debugging"
281303echo " Implementation response saved to $FIX_DETAILS_FILE "
282304
@@ -400,19 +422,11 @@ EOF
400422echo " Adding comment to issue # $ISSUE_NUMBER"
401423gh issue comment "$ISSUE_NUMBER" --repo "$FULL_REPO" --body "$ISSUE_COMMENT"
402424
403- # Keep log files for debugging but clean up other temp files
404- # Copy log files to a known location for debugging
405- cp "$RESPONSE_FILE" "/tmp/claude_analysis_$ISSUE_NUMBER.txt" || true
406- cp "$FIX_DETAILS_FILE" "/tmp/claude_fix_details_$ISSUE_NUMBER.txt" || true
407- cp "$LOG_FILE" "/tmp/claude_issue_fix_log_$ISSUE_NUMBER.txt" || true
408-
409- echo "Log files saved to /tmp/ for debugging"
410- echo "Analysis: /tmp/claude_analysis_$ISSUE_NUMBER.txt"
411- echo "Fix details: /tmp/claude_fix_details_$ISSUE_NUMBER.txt"
412- echo "Full log: /tmp/claude_issue_fix_log_$ISSUE_NUMBER.txt"
413-
414- # Clean up original temp files
415- rm -f "$RESPONSE_FILE" "$FIX_DETAILS_FILE"
425+ # All output files are already in the claude-output directory
426+ echo "All debug files have been saved to $OUTPUT_DIR"
427+ echo "Analysis: $RESPONSE_FILE"
428+ echo "Fix details: $FIX_DETAILS_FILE"
429+ echo "Full log: $LOG_FILE"
416430
417431echo "Claude Code has created a fix for issue #$ISSUE_NUMBER in PR: $PR_URL"
418432echo "Completed at $(date)"
0 commit comments