write_fix
Applies a single-file unified diff, optionally runs an allowlisted test command, and rolls the file back if tests fail. Returns test output, error and git state; no commit is created.
Instructions
Apply a unified diff to one file, optionally run tests, and attempt rollback on failure. Use when: you have reviewed the source and prepared a specific patch. Don't use when: you only need to record existing edits in Git (use git_commit instead).
Returns {success, test_output, error, rolled_back}. Successful patches also return git_state (clean, modified, untracked or no_repo) and backup (null when Git holds the original, otherwise a retained .reforge-bak path). Tests are optional; success without test_command does not mean tests ran. No commit is created. Reapplying the same diff is not idempotent.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| diff_str | Yes | Single-file unified diff with @@ -old_start,old_count +new_start,new_count @@ hunks (1-indexed lines). Context and removed lines must match the file at the stated positions; a mismatched patch is rejected. | |
| file_path | Yes | Existing file to patch, e.g. /work/app/src/main.py; must remain within repo_root. Relative paths resolve from the server working directory. | |
| repo_root | No | Repository boundary and test-command working directory; default null uses the server working directory. Prefer an absolute path. | |
| test_command | No | Optional allowlisted test command, e.g. pytest or npm test. Default null skips tests. Runs without a shell from repo_root, with closed stdin and a 120-second timeout; test failure triggers file rollback. | |
| allowed_test_commands | No | Command-prefix allowlist; a nonempty list replaces the built-in list. Default null (or []) uses built-ins such as pytest, python -m pytest, npm test and go test. Prefixes match complete shell-split tokens; command chaining remains rejected. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| error | Yes | ||
| backup | No | ||
| success | Yes | ||
| git_state | No | ||
| rolled_back | Yes | ||
| test_output | Yes |