Build And Fix

Run the build process and automatically fix any errors encountered.

imehr updated 7mo ago
Claude CodeGeneric
View source ↗
# Build and Fix Command

Run the build process and automatically fix any errors encountered.

## Usage

/build-and-fix [options]


**Options:**
- No options: Auto-detect build system and run
- `--check-only`: Report errors without fixing
- `--max-iterations=N`: Limit fix attempts (default: 5)

## Process

1. **Detect Build System**
   Check for project files in order:
   - `Cargo.toml` → `cargo build`
   - `package.json` → `npm run build` or `npx tsc --noEmit`
   - `pyproject.toml` → `python -m py_compile` or configured build
   - `Makefile` → `make`
   - `go.mod` → `go build ./...`

2. **Run Build**
   Execute the detected build command and capture output.

3. **Parse Errors**
   Extract structured error information:
   - File path
   - Line number
   - Error code/type
   - Error message

4. **Fix Loop**
   For each error:
   a. Read the relevant file context
   b. Analyze the error type
   c. Apply appropriate fix
   d. Re-run build to verify fix
   e. Continue until all errors resolved or max iterations reached

5. **Report Results**

Build Results

Initial errors: 12 Fixed: 11 Remaining: 1

Fixed Issues

  • src/lib.rs:45 - Added missing lifetime parameter
  • src/main.rs:23 - Fixed type mismatch (String -> &str) ...

Remaining Issues

  • src/complex.rs:89 - Requires manual review (circular dependency)

Changes Made

  • src/lib.rs (3 edits)
  • src/main.rs (1 edit)

## Error Categories

### TypeScript/JavaScript
- Type mismatches
- Missing imports
- Undefined variables
- Invalid syntax

### Rust
- Lifetime errors
- Borrow checker issues
- Type mismatches
- Missing traits

### Python
- Import errors
- Type annotation issues (mypy)
- Syntax errors

## Example

/build-and-fix


Output:

Detected: Rust project (Cargo.toml) Running: cargo build

Found 5 errors:

[1/5] Fixing src/handlers/user.rs:34 Error: mismatched types - expected &str, found String Fix: Added .as_str() conversion Result: Fixed

[2/5] Fixing src/models/post.rs:56 Error: missing lifetime specifier Fix: Added lifetime parameter 'a Result: Fixed

...

Build successful after 3 iterations. All 5 errors have been resolved.


## Safety

- Creates a backup before making changes (stash or commit)
- Only modifies files with errors
- Stops if fix causes more errors than it solves
- Never modifies generated files or dependencies
- Respects `.gitignore` patterns

## Configuration

In CLAUDE.md:
```markdown
## Build Configuration
- Build command: cargo build --all-features
- Test after build: true
- Auto-commit fixes: false

Maintain Build And Fix?

Let people know it's listed here — add the badge (live metrics, light/dark aware) or a plain link to your README or docs.

[Build And Fix on getagentictools](https://getagentictools.com/loops/imehr-build-and-fix-command?ref=badge)