Skip to content

Commit b843c91

Browse files
committed
Fix issue-fix mode by using local claude-output directory and improving file extraction handling
1 parent b9b07f6 commit b843c91

2 files changed

Lines changed: 55 additions & 49 deletions

File tree

.github/workflows/claude-issue-fix.yml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,9 @@ jobs:
4141
anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }}
4242
github-token: ${{ secrets.GITHUB_TOKEN }}
4343

44-
- name: Collect debug information
45-
if: always()
46-
run: |
47-
echo "Collecting debug information..."
48-
mkdir -p /tmp/claude-debug
49-
cp /tmp/claude_* /tmp/claude-debug/ || echo "No claude debug files found"
50-
find /tmp -name "claude_*" -type f -exec ls -la {} \; || echo "No claude files found"
51-
52-
- name: Upload debug artifacts
44+
- name: Upload claude output artifacts
5345
if: always()
5446
uses: actions/upload-artifact@v4
5547
with:
56-
name: claude-debug-${{ github.event.issue.number }}
57-
path: /tmp/claude-debug/
48+
name: claude-output-issue-${{ github.event.issue.number }}
49+
path: claude-output/

scripts/issue-fix-mode.sh

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,19 @@ claude --version || echo "Failed to get Claude version"
6868
echo "Claude CLI help:"
6969
claude --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
7781
exec > >(tee -a "$LOG_FILE") 2>&1
7882
echo "Starting issue-fix mode at $(date)"
83+
echo "Output directory: $OUTPUT_DIR"
7984
echo "Log file: $LOG_FILE"
8085
echo "Response file: $RESPONSE_FILE"
8186
echo "Fix details file: $FIX_DETAILS_FILE"
@@ -187,42 +192,59 @@ EOF
187192
# Run Claude CLI to analyze the issue
188193
echo "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"
192197
echo "$ANALYZE_PROMPT" > "$PROMPT_FILE"
193198
echo "Prompt saved to $PROMPT_FILE for debugging"
194199

195200
# Use claude with the -p flag (print) and -d (debug) and pipe input
196201
echo "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
206212
fi
207213

208-
# Keep prompt file for debugging
209214
echo "Prompt saved to $PROMPT_FILE for debugging"
210215
echo "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
216232
EXAMINED_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
228250
IMPLEMENT_PROMPT=$(cat <<EOF
@@ -260,23 +282,23 @@ EOF
260282
# Run Claude CLI to implement the fix
261283
echo "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"
265287
echo "$IMPLEMENT_PROMPT" > "$IMPL_PROMPT_FILE"
266288
echo "Implementation prompt saved to $IMPL_PROMPT_FILE for debugging"
267289

268290
# Use claude with the -p flag (print) and -d (debug) and pipe input
269291
echo "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
277300
fi
278301

279-
# Keep prompt file for debugging
280302
echo "Implementation prompt saved to $IMPL_PROMPT_FILE for debugging"
281303
echo "Implementation response saved to $FIX_DETAILS_FILE"
282304

@@ -400,19 +422,11 @@ EOF
400422
echo "Adding comment to issue #$ISSUE_NUMBER"
401423
gh 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
417431
echo "Claude Code has created a fix for issue #$ISSUE_NUMBER in PR: $PR_URL"
418432
echo "Completed at $(date)"

0 commit comments

Comments
 (0)