Fix Pre-commit Failures
Purpose
Resolve pre-commit hook failures that block a git commit, one hook failure at a time, stopping when the commit is clean, when the loop stops converging, or after at most 5 fix-and-retry iterations.
Use When
git commit triggered pre-commit and the hooks failed.
pre-commit rewrote files and the user wants to continue safely.
- The task requires inspecting hook output and fixing the remaining blockers before retrying commit.
Do Not Use When
- The task is only to run the repository validation flow before commit.
- The task is to fix normal checks or tests that failed outside the
git commit hook run.
- The task is to create or update a pull request.
- The task is to ignore or bypass hook failures.
Inputs
- The failed
pre-commit hook output from the attempted git commit.
- Current repository diff, including any hook-generated file changes.
- Repository validation rules from repo docs.
- Installed shared package root:
${MPT_EXTENSION_SKILLS_HOME:-$HOME/.mpt-extension-skills}/current
Assumptions
- The target repository is available locally and Git commands can be executed.
- Repository-required hook tooling is installed or otherwise available in the current environment.
- The failed
pre-commit output being handled matches the current repository state.
Workflow
- Build repository context first.
- Read the target repository
AGENTS.md once per session. If you already loaded it earlier in this session and still have its full contents, reuse them instead of re-reading; if the context was summarized or you are unsure it is complete, read it again. Do not pre-load shared docs in this step; read them lazily only when the repository points to them.
- Read repository-specific docs when they exist, because they may extend or override shared guidance.
- Read shared docs only when the repository explicitly points to them. Resolve those shared docs from
${MPT_EXTENSION_SKILLS_HOME:-$HOME/.mpt-extension-skills}/current when available; otherwise read them from the main branch of the shared GitHub repository.
- Confirm the pre-commit requirement.
- Use repository commit and validation docs as the source of truth for commit-time hooks.
- For repositories that follow this shared package guidance, read
knowledge/build-and-checks.md using the shared-doc resolution rule from the repository context step instead of restating the policy in this skill.
- Read the failed hook output.
- Identify which hook failed and whether any hooks rewrote files automatically.
- Inspect hook-generated file changes before making more edits.
- Keep hook-generated fixes unless there is a clear reason they are incorrect.
- Fix one remaining hook blocker at a time.
- Apply the smallest change needed to satisfy the currently failing hook.
- If a hook failure reflects a broader repository check failure, run the relevant underlying validation command before retrying the commit.
- Avoid speculative edits unrelated to the failing hook.
- Revalidate and retry the commit.
- One iteration = one scoped hook fix + one commit retry. Confirming a clean automatic
pre-commit run after the loop is not a separate iteration.
- Before each attempt, state the iteration explicitly:
Iteration N/5 — failing hook: <hook>.
- Rerun the narrowest safe validation needed to confirm the hook-related fix.
- Retry the commit only after the current hook blockers are addressed.
- Confirm that the automatic
pre-commit run triggered by the retried commit passes cleanly.
- Stop early, without consuming the remaining iterations, when there is no progress: the same hook fails the same way after a fix attempt, or a fix re-introduces a previously-passing hook. Report it as a non-converging blocker.
- Stop when the commit is still blocked after 5 fix-and-retry iterations, and report the remaining hook output as the blocker.
- Report the result clearly.
- State which hooks failed and which were fixed.
- State whether hook-generated file changes were kept.
- State whether the commit is now unblocked or what blocker remains.
- End with exactly one classified outcome the caller can act on, chosen by this precedence (success first):
committed — the commit completed with a clean automatic pre-commit run, even when reached on the final allowed iteration.
needs-user-input — a remaining hook failure needs user direction or a broader design decision.
environment-blocker — the remaining failure is environment or hook-setup related, not product code.
non-converging — the same hook failed the same way after a fix, or a fix reintroduced a previously-passing hook.
iteration-limit-reached — 5 fix-and-retry iterations were spent without reaching any of the above.
Guardrails
- Never ignore a failed
pre-commit run and pretend the commit succeeded.
- Never discard hook-generated file rewrites without inspecting them first.
- Never retry commits blindly without addressing the current hook failures.
- Never run more than 5 pre-commit fix-and-retry iterations before stopping with a blocker, and stop sooner when the loop stops converging.
- Never let the caller re-loop this task; this task owns the bounded fix-and-retry loop and returns a single classified outcome.
- Never mix PR creation or Jira transitions into this task.
- Never bypass repository-required hooks unless the user explicitly directs that and repository policy allows it.
Expected Outcome
The pre-commit failures triggered by git commit are resolved step by step, hook-generated fixes are handled safely, and the commit is retried only when the automatic hook run is expected to pass cleanly, up to the 5-iteration limit or until the loop stops converging, and the task returns a single classified outcome (committed, needs-user-input, environment-blocker, non-converging, or iteration-limit-reached) for the caller to act on.
1---2name: mpt-ext-task-fix-pre-commit-failures3description: Fix failures raised by the pre-commit hook during `git commit` (not standalone make/test runs). Reads hook output, fixes one failure at a time, reruns, and retries the commit; max 5 iterations.4---56# Fix Pre-commit Failures78## Purpose910Resolve `pre-commit` hook failures that block a `git commit`, one hook failure at a time, stopping when the commit is clean, when the loop stops converging, or after at most 5 fix-and-retry iterations.1112## Use When1314- `git commit` triggered `pre-commit` and the hooks failed.15- `pre-commit` rewrote files and the user wants to continue safely.16- The task requires inspecting hook output and fixing the remaining blockers before retrying commit.1718## Do Not Use When1920- The task is only to run the repository validation flow before commit.21- The task is to fix normal checks or tests that failed outside the `git commit` hook run.22- The task is to create or update a pull request.23- The task is to ignore or bypass hook failures.2425## Inputs2627- The failed `pre-commit` hook output from the attempted `git commit`.28- Current repository diff, including any hook-generated file changes.29- Repository validation rules from repo docs.30- Installed shared package root:3132```text33${MPT_EXTENSION_SKILLS_HOME:-$HOME/.mpt-extension-skills}/current34```3536## Assumptions3738- The target repository is available locally and Git commands can be executed.39- Repository-required hook tooling is installed or otherwise available in the current environment.40- The failed `pre-commit` output being handled matches the current repository state.4142## Workflow43441. Build repository context first.45- Read the target repository `AGENTS.md` once per session. If you already loaded it earlier in this session and still have its full contents, reuse them instead of re-reading; if the context was summarized or you are unsure it is complete, read it again. Do not pre-load shared docs in this step; read them lazily only when the repository points to them.46- Read repository-specific docs when they exist, because they may extend or override shared guidance.47- Read shared docs only when the repository explicitly points to them. Resolve those shared docs from `${MPT_EXTENSION_SKILLS_HOME:-$HOME/.mpt-extension-skills}/current` when available; otherwise read them from the `main` branch of the shared GitHub repository.48492. Confirm the pre-commit requirement.50- Use repository commit and validation docs as the source of truth for commit-time hooks.51- For repositories that follow this shared package guidance, read `knowledge/build-and-checks.md` using the shared-doc resolution rule from the repository context step instead of restating the policy in this skill.52533. Read the failed hook output.54- Identify which hook failed and whether any hooks rewrote files automatically.55- Inspect hook-generated file changes before making more edits.56- Keep hook-generated fixes unless there is a clear reason they are incorrect.57584. Fix one remaining hook blocker at a time.59- Apply the smallest change needed to satisfy the currently failing hook.60- If a hook failure reflects a broader repository check failure, run the relevant underlying validation command before retrying the commit.61- Avoid speculative edits unrelated to the failing hook.62635. Revalidate and retry the commit.64- One iteration = one scoped hook fix + one commit retry. Confirming a clean automatic `pre-commit` run after the loop is not a separate iteration.65- Before each attempt, state the iteration explicitly: `Iteration N/5 — failing hook: <hook>`.66- Rerun the narrowest safe validation needed to confirm the hook-related fix.67- Retry the commit only after the current hook blockers are addressed.68- Confirm that the automatic `pre-commit` run triggered by the retried commit passes cleanly.69- Stop early, without consuming the remaining iterations, when there is no progress: the same hook fails the same way after a fix attempt, or a fix re-introduces a previously-passing hook. Report it as a non-converging blocker.70- Stop when the commit is still blocked after 5 fix-and-retry iterations, and report the remaining hook output as the blocker.71726. Report the result clearly.73- State which hooks failed and which were fixed.74- State whether hook-generated file changes were kept.75- State whether the commit is now unblocked or what blocker remains.76- End with exactly one classified outcome the caller can act on, chosen by this precedence (success first):77 - `committed` — the commit completed with a clean automatic `pre-commit` run, even when reached on the final allowed iteration.78 - `needs-user-input` — a remaining hook failure needs user direction or a broader design decision.79 - `environment-blocker` — the remaining failure is environment or hook-setup related, not product code.80 - `non-converging` — the same hook failed the same way after a fix, or a fix reintroduced a previously-passing hook.81 - `iteration-limit-reached` — 5 fix-and-retry iterations were spent without reaching any of the above.8283## Guardrails8485- Never ignore a failed `pre-commit` run and pretend the commit succeeded.86- Never discard hook-generated file rewrites without inspecting them first.87- Never retry commits blindly without addressing the current hook failures.88- Never run more than 5 pre-commit fix-and-retry iterations before stopping with a blocker, and stop sooner when the loop stops converging.89- Never let the caller re-loop this task; this task owns the bounded fix-and-retry loop and returns a single classified outcome.90- Never mix PR creation or Jira transitions into this task.91- Never bypass repository-required hooks unless the user explicitly directs that and repository policy allows it.9293## Expected Outcome9495The `pre-commit` failures triggered by `git commit` are resolved step by step, hook-generated fixes are handled safely, and the commit is retried only when the automatic hook run is expected to pass cleanly, up to the 5-iteration limit or until the loop stops converging, and the task returns a single classified outcome (`committed`, `needs-user-input`, `environment-blocker`, `non-converging`, or `iteration-limit-reached`) for the caller to act on.