---
name: development-testing-fix-build
description: >
  Auto-correct a SINGLE compilation error surfaced by the Studio's Dev Runner
  (dotnet CS####, tsc TS####, vite resolve). The caller provides one
  `BuildError` with file/line/column/code/message. Your job is to apply the
  MINIMUM patch to make that specific error go away, without refactoring
  surrounding code. Invoked by `build-fix-runner.ts` in a retry loop (max 15
  iterations, convergence guard, rebuild-and-reparse after each attempt).
phase: development/testing
allowed-tools: [Read, Edit, Write, Glob, Grep, Bash]  # Bash: diagnostic commands
---

# Fix-Build — targeted single-error remediation

You receive ONE compilation error from the Studio's Dev Runner. The goal is a
precise patch, not a refactor.

## Input contract

The caller ships a `BUILD_ERROR_CONTEXT` block containing:

```
SOURCE: dotnet | tsc | vite
CODE: CS0103 (or TS2322, VITE_IMPORT, ESBUILD, ...)
FILE: <absolute path>
LINE: <1-based>
COLUMN: <1-based>
MESSAGE: <raw compiler diagnostic>
PREVIOUS_ATTEMPTS: <N>
```

Plus the current contents of the faulty file (or an excerpt around the error
line) already loaded into your context.

## Process

1. **Read** the faulty file in full. Inspect the line reported + ±10 lines of
   context.
2. **Diagnose** — resolve the diagnostic into one of the usual suspects:
   - `CS0103` (name not found) → missing using, typo, out-of-scope
   - `CS1061` (missing member) → wrong type, missing property on DTO
   - `CS0246` (type not found) → missing namespace/package reference
   - `TS2322` (type mismatch) → narrow the value, adjust the destination type
   - `TS2339` (property missing) → extend the interface OR use the correct property
   - `VITE_IMPORT` / `ESBUILD` (resolve failure) → fix import path or create the missing file
3. **Patch minimum** — touch only what's strictly necessary. Do NOT reformat,
   reorder usings, rename variables, or fix adjacent unrelated warnings.
4. **Do not add** new abstractions, base classes, or "cleaner" versions.
5. **Commit** the change with a one-line message: `fix(build): <CODE> in <file>:<line>`.
6. Emit a JSON envelope on stdout when done:

   ```json
   { "applied": true, "summary": "<one-liner>", "touched": ["<path>"] }
   ```

## Guardrails

- If the error cannot be fixed in the target file alone (e.g. it requires
  creating a new file or editing a dependency), say so in the JSON:
  ```json
  { "applied": false, "reason": "requires cross-file change not in scope" }
  ```
  and do NOT commit. The caller will escalate to a broader fix loop or
  surface a `StudioBug`.
- Never bypass compiler errors by casting to `any`, adding `#pragma warning
  disable`, or commenting-out the faulty code. The patch must address the
  root cause.
- If the previous attempt count is ≥3, prefer a different approach than the
  last one — re-reading the error message is a useful reset.

## Tools allowed

Read, Edit, Write, Glob, Grep, Bash (for `git add` + `git commit` only).

## Not allowed

- AskUserQuestion (fully autonomous loop)
- Skill (don't recurse into other skills)
- Background tasks
