Skip to content

Commit 1e51d50

Browse files
committed
Filter CI logs and add Ctrl+C support
- Add filterCILogs() to extract only relevant error information - Show concise error summary instead of dumping raw logs - Truncate logs to 2000 chars to avoid context warnings - Simplify prompts to reduce token usage - Add SIGINT handlers to properly handle Ctrl+C - Add debug output showing Claude command flags
1 parent 38fbcec commit 1e51d50

File tree

1 file changed

+56
-42
lines changed

1 file changed

+56
-42
lines changed

scripts/claude.mjs

Lines changed: 56 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3309,9 +3309,23 @@ Let's work through this together to get CI passing.`
33093309
// Add newline after progress indicator before next output
33103310
console.log('')
33113311

3312+
// Filter and show summary of logs
3313+
const rawLogs = logsResult.stdout || 'No logs available'
3314+
const filteredLogs = filterCILogs(rawLogs)
3315+
3316+
const logLines = filteredLogs.split('\n').slice(0, 10)
3317+
log.substep('Error summary:')
3318+
for (const line of logLines) {
3319+
if (line.trim()) {
3320+
log.substep(` ${line.trim().substring(0, 100)}`)
3321+
}
3322+
}
3323+
if (filteredLogs.split('\n').length > 10) {
3324+
log.substep(` ... (${filteredLogs.split('\n').length - 10} more lines)`)
3325+
}
3326+
33123327
// Check if we've seen this CI error before
3313-
const ciErrorOutput = logsResult.stdout || 'No logs available'
3314-
const ciErrorHash = hashError(ciErrorOutput)
3328+
const ciErrorHash = hashError(filteredLogs)
33153329

33163330
if (ciErrorHistory.has(lastRunId)) {
33173331
log.error(`Already attempted fix for run ${lastRunId}`)
@@ -3334,29 +3348,18 @@ Let's work through this together to get CI passing.`
33343348

33353349
// Analyze and fix with Claude
33363350
log.progress('Analyzing CI failure with Claude')
3337-
const fixPrompt = `You are automatically fixing CI failures. The CI workflow failed for commit ${currentSha} in ${owner}/${repo}.
3338-
3339-
Failure logs:
3340-
${logsResult.stdout || 'No logs available'}
33413351

3342-
Your task:
3343-
1. Analyze these CI logs
3344-
2. Identify the root cause of failures
3345-
3. Apply fixes directly to resolve the issues
3352+
// Keep logs under 2000 chars to avoid context issues
3353+
const truncatedLogs = filteredLogs.length > 2000
3354+
? filteredLogs.substring(0, 2000) + '\n... (truncated)'
3355+
: filteredLogs
33463356

3347-
Focus on:
3348-
- Test failures: Update snapshots, fix test logic, or correct test data
3349-
- Lint errors: Fix code style and formatting issues
3350-
- Type checking: Fix type errors and missing type annotations
3351-
- Build problems: Fix import errors, missing pinned dependencies, or syntax issues
3357+
const fixPrompt = `Fix CI failures for commit ${currentSha.substring(0, 7)} in ${owner}/${repo}.
33523358
3353-
IMPORTANT:
3354-
- Be direct and apply fixes immediately
3355-
- Don't ask for clarification or permission
3356-
- Make all necessary file changes to fix the CI
3357-
- If multiple issues exist, fix them all
3359+
Error logs:
3360+
${truncatedLogs}
33583361
3359-
Fix all CI failures now by making the necessary changes.`
3362+
Fix all issues by making necessary file changes. Be direct, don't ask questions.`
33603363

33613364
// Run Claude non-interactively to apply fixes
33623365
log.substep('Applying CI fixes...')
@@ -3415,11 +3418,20 @@ Fix all CI failures now by making the necessary changes.`
34153418
shell: true,
34163419
})
34173420

3421+
// Handle Ctrl+C gracefully
3422+
const sigintHandler = () => {
3423+
child.kill('SIGINT')
3424+
resolve(130)
3425+
}
3426+
process.on('SIGINT', sigintHandler)
3427+
34183428
child.on('exit', code => {
3429+
process.off('SIGINT', sigintHandler)
34193430
resolve(code || 0)
34203431
})
34213432

34223433
child.on('error', () => {
3434+
process.off('SIGINT', sigintHandler)
34233435
resolve(1)
34243436
})
34253437
})
@@ -3583,32 +3595,20 @@ Fix all CI failures now by making the necessary changes.`
35833595

35843596
// Analyze and fix with Claude
35853597
log.progress(`Analyzing failure in ${job.name}`)
3586-
const fixPrompt = `You are automatically fixing CI failures. The job "${job.name}" failed in workflow run ${lastRunId} for commit ${currentSha} in ${owner}/${repo}.
35873598

3588-
Job: ${job.name}
3589-
Status: ${job.conclusion}
3590-
3591-
Failure logs:
3592-
${filteredLogs}
3599+
// Keep logs under 2000 chars to avoid context issues
3600+
const truncatedLogs = filteredLogs.length > 2000
3601+
? filteredLogs.substring(0, 2000) + '\n... (truncated)'
3602+
: filteredLogs
35933603

3594-
Your task:
3595-
1. Analyze these CI logs for the "${job.name}" job
3596-
2. Identify the root cause of the failure
3597-
3. Apply fixes directly to resolve the issue
3604+
const fixPrompt = `Fix CI failure in "${job.name}" (run ${lastRunId}, commit ${currentSha.substring(0, 7)}).
35983605
3599-
Focus on:
3600-
- Test failures: Update snapshots, fix test logic, or correct test data
3601-
- Lint errors: Fix code style and formatting issues
3602-
- Type checking: Fix type errors and missing type annotations
3603-
- Build problems: Fix import errors, missing pinned dependencies, or syntax issues
3606+
Status: ${job.conclusion}
36043607
3605-
IMPORTANT:
3606-
- Be direct and apply fixes immediately
3607-
- Don't ask for clarification or permission
3608-
- Make all necessary file changes to fix this specific failure
3609-
- Focus ONLY on fixing the "${job.name}" job
3608+
Error logs:
3609+
${truncatedLogs}
36103610
3611-
Fix the failure now by making the necessary changes.`
3611+
Fix the issue by making necessary file changes. Be direct, don't ask questions.`
36123612

36133613
// Run Claude non-interactively to apply fixes
36143614
log.substep(`Applying fix for ${job.name}...`)
@@ -3639,6 +3639,11 @@ Fix the failure now by making the necessary changes.`
36393639
? `${claudeCmd} ${claudeArgs}`
36403640
: claudeCmd
36413641

3642+
// Debug: Show command being run
3643+
if (claudeArgs) {
3644+
log.substep(`Running: claude ${claudeArgs}`)
3645+
}
3646+
36423647
// Use script command to create pseudo-TTY for Ink compatibility
36433648
// Platform-specific script command syntax
36443649
let scriptCmd
@@ -3663,11 +3668,20 @@ Fix the failure now by making the necessary changes.`
36633668
shell: true,
36643669
})
36653670

3671+
// Handle Ctrl+C gracefully
3672+
const sigintHandler = () => {
3673+
child.kill('SIGINT')
3674+
resolve(130)
3675+
}
3676+
process.on('SIGINT', sigintHandler)
3677+
36663678
child.on('exit', code => {
3679+
process.off('SIGINT', sigintHandler)
36673680
resolve(code || 0)
36683681
})
36693682

36703683
child.on('error', () => {
3684+
process.off('SIGINT', sigintHandler)
36713685
resolve(1)
36723686
})
36733687
})

0 commit comments

Comments
 (0)