---
name: rloop-code-fix3
description: Manual-only custom skill. Use only when explicitly requested as $rloop-code-fix3 or named directly.
---

# AI Slop Fix Loop

Run a bounded parent-owned loop that applies `ai-slop-cleaner` until the target is clean, blocked, converged, or the hard iteration cap is reached.

## Core Principle

Do not recursively invoke this skill. This skill owns the lifecycle. `ai-slop-cleaner` is the child cleaner/reviewer that returns structured results; this parent decides whether to stop, fix, or rerun.

## Inputs

Accept a target and optional context from the user, for example:

- `PR 14178`
- `PR 14178, changed files only`
- `current branch`
- `uncommitted diff`
- explicit file or directory paths

If a PR is named, carry that PR identifier into every child pass as context. When possible, collect local PR context before the first pass:

- PR title and summary
- changed files
- current branch or diff target
- any user constraints from the request

Do not fetch secrets or include sensitive local artifacts in child prompts.

## Loop Contract

Max iterations: 3.

Each iteration:

1. Run `ai-slop-cleaner` on the target with the PR/context payload.
2. Ask the child pass to return a single JSON object on the last line:

```json
{
  "status": "clean",
  "issues": [],
  "changed_files": [],
  "verification": [],
  "confidence": 0.9
}
```

Allowed `status` values:

- `clean` - no remaining AI slop found
- `issues_found` - fixable slop remains or was found during review
- `blocked` - cleanup is unsafe, ambiguous, or cannot be verified

Each issue must include:

```json
{
  "id": "stable-fingerprint",
  "severity": "critical|important|minor",
  "summary": "short finding",
  "fix": "specific next action"
}
```

Stop immediately when:

- `status == "clean"` and no files changed during that pass
- `status == "blocked"`
- the same issue fingerprints appear twice in a row
- max iterations is reached

If a cleaner pass returns `clean` after changing files, run one review pass before declaring the target clean.

After stopping with unresolved issues, report them as reviewer concerns instead of continuing to churn.

## Child Invocation

Prefer a fresh child agent only when the environment supports it and the user explicitly asked for subagents, delegation, or parallel agent work. Otherwise run the child workflow inline, but preserve the same structured-result contract.

Use this child prompt shape:

```text
You are executing the ai-slop-cleaner workflow.

Read and follow:
The sibling `ai-slop-cleaner` skill at `.agents/skills/ai-slop-cleaner/SKILL.md`, resolved from the current repo/worktree root.

Target:
<target>

Context:
<PR/context payload, for example "PR 14178">

Required final line:
Return exactly one JSON object on the last line:
{
  "status": "clean",
  "issues": [],
  "changed_files": [],
  "verification": [],
  "confidence": 0.9
}

Allowed status values are `clean`, `issues_found`, and `blocked`.
When `issues` is non-empty, each issue must include `id`, `severity`, `summary`, and `fix`.

Constraints:
- Preserve behavior unless explicitly instructed otherwise.
- Prefer deletion and simplification over new abstraction.
- Keep scope to the target and PR context.
- Do not commit or push.
- Keep all changes local so the parent can decide how to group or ship them.
- Run relevant verification for touched files when practical.
- Do not add prose after the final JSON object.
```

## Iteration Flow

1. **Preflight**
   - Confirm `ai-slop-cleaner/SKILL.md` exists.
   - Resolve the requested target.
   - Capture baseline changed files with `git status --short`.
   - If the target is a PR such as `PR 14178`, resolve the local diff or changed-file list before cleaning.

2. **Cleaner pass**
   - Run `ai-slop-cleaner` in normal mode for the target.
   - Let it make cleanup changes when safe.
   - Require the JSON result.
   - If the final JSON is missing or malformed, rerun the same child prompt once with a reminder to return only the required JSON object on the last line.
   - If the retry still misses the JSON contract, stop as `blocked`.

3. **Review pass**
   - If the cleaner reports changes or possible remaining slop, run `ai-slop-cleaner --review` against the same target and context.
   - Treat review findings as the next iteration's issue list.

4. **Decision**
   - Clean review: stop.
   - New fixable issues: repeat.
   - Same issue IDs as previous iteration: stop with `needs_user_decision`.
   - Blocked result: stop with the blocker.

5. **Closeout**
   - Report changed files, simplifications, verification, final status, and unresolved concerns.
   - Confirm changes remain local and uncommitted for the parent workflow to group or ship.
   - Do not claim clean unless the latest cleaner/reviewer result is `clean`.

## Status Mapping

| Child result | Parent status | Parent action |
|---|---|---|
| `clean` with no changed files | `completed` | Stop and summarize evidence |
| `clean` with changed files | `running` | Run one review pass before declaring clean |
| `issues_found` with new IDs | `running` | Apply next pass if below cap |
| `issues_found` with repeated IDs | `needs_user_decision` | Stop and surface concerns |
| `blocked` | `blocked` | Stop and explain blocker |
| malformed or missing JSON after one retry | `blocked` | Stop; do not infer status or issue IDs from prose |

## Hard Rules

- Parent owns the loop and stop decision.
- Never call `rloop-code-fix3` from inside itself.
- Never exceed 3 iterations.
- Never expand from PR/chosen files into broad repository cleanup without user approval.
- Never treat formatting-only changes as slop cleanup unless the user asked for formatting.
- Never commit, push, or rewrite history.
- Keep changed files local for the parent workflow to group or ship.
- Never end with "probably clean"; require a clean child verdict.

## Common Mistakes

- Letting `ai-slop-cleaner` decide whether the whole run is done without parent inspection.
- Running endless cleanup because minor style preferences keep appearing.
- Dropping PR context after the first pass.
- Committing one loop's cleanup instead of leaving it local for the parent workflow.
- Mixing feature work into slop cleanup.
- Expanding from `PR 14178` to unrelated repo-wide cleanup.
