| name | bug-fixer |
| description | Diagnose a bug, identify root cause, implement a targeted fix, and verify it |
bug-fixer
Systematically diagnose and fix a reported bug without introducing regressions.
Steps
1. Reproduce the bug (in your head / via analysis)
context.emit({ type: 'progress', message: 'Step 1: Understanding the bug...' });
const buggyFile = context.vfs.read('/src/path/to/file.js');
if (!buggyFile) {
context.emit({ type: 'done', message: 'Error: file not found in VFS' });
return;
}
context.emit({ type: 'file_read', path: '/src/path/to/file.js' });
2. Trace the root cause
Do NOT fix symptoms. Find the root cause:
context.emit({ type: 'progress', message: 'Root cause: <describe what you found>' });
3. Write the minimal fix
Fix ONLY what is broken. Do not refactor surrounding code:
const original = context.vfs.read('/src/path/to/file.js');
const fixed = original.replace(
/buggy pattern/,
'correct replacement'
);
context.vfs.write('/src/path/to/file.js', fixed);
context.emit({ type: 'file_write', path: '/src/path/to/file.js' });
4. Verify the fix
Check the fix is logically correct:
context.emit({ type: 'progress', message: 'Verifying fix...' });
const verified = context.vfs.read('/src/path/to/file.js');
if (!verified.includes('expected fixed pattern')) {
context.emit({ type: 'progress', message: 'Warning: fix may not have applied correctly' });
}
5. Document what changed
context.emit({ type: 'result', value: {
file: '/src/path/to/file.js',
root_cause: '<description>',
fix: '<description of change>',
verification: 'logic check passed',
}});
context.emit({ type: 'done', message: 'Bug fixed: <one-liner>' });
Anti-patterns to avoid
- Symptom masking: don't add
try/catch to suppress an error without fixing it
- Over-fixing: don't refactor code that isn't broken
- Assumption-driven fixes: always READ the file before fixing it
- Missing edge cases: null inputs, empty arrays, 0 values, concurrent calls
Common fix patterns
const value = obj?.field ?? defaultValue;
const idx = Math.min(index, array.length - 1);
const result = await asyncFn();
const copy = { ...shared };
copy.field = newValue;