---
name: wip-triage
description: Use when auditing or cleaning Git worktrees, stale branches, merged or squash-landed work, dirty or untracked WIP, stashes, overlapping implementation lanes, or deciding what may be recovered, consolidated, retained, or safely removed.
argument-hint: "<repo-path> [--audit|--preserve|--consolidate|--execute-safe-retirements]"
---

# WIP Triage

Audience: AI coding agents first.

Inventory every work carrier. Prove what landed. Preserve recoverable work. NEVER convert uncertainty into deletion.

## Operating modes

Accept exactly one mode:

| Mode | Allowed mutation |
|---|---|
| `--audit` | None. Inventory, classify, recommend. |
| `--preserve` | Create and verify recovery refs/snapshots. NEVER remove worktrees or branches. |
| `--consolidate` | Preserve first; prepare canonical recovery/landing lanes. NEVER delete uncertain work. |
| `--execute-safe-retirements` | Preserve and verify first; remove only proven retirement candidates passing every deletion condition. |

Default when no mode is supplied: `--audit`.

Request for audit, review, recommendation, or triage does NOT authorize mutation. Explicit cleanup request authorizes `--execute-safe-retirements`; continue through safe reversible cleanup without asking again. Stop on uncertainty, failed preservation, irreversible risk, or external blocker.

## Classification model

Assign exactly one primary disposition:

| Disposition | Meaning | Action |
|---|---|---|
| **RETIRE — LANDED** | Unique work provably exists in canonical baseline, including squash-equivalent or rewritten implementation | Preserve evidence and recovery refs; remove only after deletion gate passes |
| **RETIRE — REDUNDANT** | Superseded, duplicated, obsolete, or no unique valuable work remains | Preserve evidence and recovery refs; remove only after deletion gate passes |
| **RECOVER** | Valuable unlanded committed, staged, dirty, untracked, ignored-important, or stashed work exists | Snapshot all valuable state; reimplement or selectively transplant onto current baseline |
| **KEEP — ACTIVE** | Relevant work has current activity and credible completion path | Keep; record progress and next executable action |
| **UNKNOWN** | Evidence is missing, incomplete, or contradictory | NEVER delete; investigate |

Add zero or more independent flags:

- `CONSOLIDATE`
- `BLOCKED`
- `HIGH-CONFLICT`
- `DIRTY`
- `UNTRACKED-WIP`
- `IGNORED-WIP`
- `STASHED-WIP`
- `STALE-BASE`
- `MISSING-SPEC`
- `TEST-UNKNOWN`
- `TEST-FAILING`

Flags are not dispositions. `RECOVER + CONSOLIDATE + BLOCKED` is valid. DO NOT force `BLOCKED` and `CONSOLIDATE` into mutually exclusive states.

“Fully merged” and “already landed” both map to `RETIRE — LANDED`. Git ancestry alone cannot prove landing: squash, cherry-pick, rewrite, and reimplementation break ancestry.

## Evidence confidence

Assign one level:

- `HIGH`: At least two independent strong signals agree.
- `MEDIUM`: Likely, but one material uncertainty remains.
- `LOW`: Names, dates, status, filesystem timestamps, or incomplete documentation provide most evidence.

Strong pairs:

- ancestry + tree/patch equivalence;
- patch equivalence + implementation comparison;
- implementation comparison + passing acceptance tests;
- explicit supersession + proof no unique work remains.

Deletion requires `HIGH` confidence.

## Audit sequence

### 1. Establish context

1. Resolve repository root.
2. Read applicable repository instructions, plan indexes, linked plans/specs, and worktree-management rules.
3. Read `~/Projects/0 DOCS/GIT_FATIGUE.md` when present. NEVER modify it.
4. Identify canonical remote and default branch from complete Git configuration—not names or assumptions.
5. Fetch/prune canonical remote before measuring divergence when network is available.
6. Record remote URL, default branch, baseline SHA, fetch timestamp, and fetch result.
7. Identify shared/default checkout. NEVER mutate shared/default checkout.
8. Follow repository-specific worktree, preservation, landing, and deployment contracts.

Canonical baseline unverified → remain read-only; classify deletion candidates `UNKNOWN`.

### 2. Inventory every state carrier

Inventory:

- registered and detached worktrees;
- local and remote-tracking branches;
- committed and staged changes;
- dirty tracked files;
- untracked files;
- potentially valuable ignored files;
- stashes;
- WIP refs, snapshots, and retirement tags;
- plans, specs, tasks, and acceptance criteria.

Record for each workstream:

- worktree path, branch/ref, HEAD, and upstream;
- clean, staged, dirty, untracked, ignored-important, and stashed state;
- ahead/behind divergence and unique commits;
- first/latest unique commit dates and latest meaningful activity;
- purpose and linked plan/spec/task;
- changed subsystems and overlap;
- build/test status;
- verifiable owner or active process;
- progress, remaining work, blockers, conflict level, time-to-land;
- disposition, flags, confidence, evidence, and next action.

Use **inactive since**, not **abandoned on**, unless abandonment is explicitly documented. Filesystem timestamps are weak evidence only.

### 3. Handle ignored files safely

1. Inventory ignored paths without indiscriminately reading or packaging contents.
2. Exclude dependencies, caches, generated output, logs, credentials, and secret files unless repository rules explicitly classify them as source.
3. Inspect content only when necessary, authorized, and safe.
4. NEVER print, commit, archive, or expose secrets.
5. Mark confirmed valuable ignored source `IGNORED-WIP`.
6. Uncertain ignored state blocks deletion.

### 4. Link intent

Search branch names, commits, changed files, plan indexes, specs, task IDs, and acceptance criteria. Distinguish:

- plan + spec;
- plan only;
- spec only;
- implementation without authoritative documentation;
- verification-only work;
- generated/incidental changes.

Apply `MISSING-SPEC` when purpose or acceptance criteria remain unclear. NEVER infer purpose solely from branch name.

### 5. Prove landing or redundancy

Use applicable evidence:

1. Direct ancestry.
2. Tree/content equivalence.
3. Patch or cherry-pick equivalence.
4. Squash-equivalent implementation comparison.
5. Acceptance criteria satisfied in canonical baseline.
6. Current tests proving equivalent behavior.
7. Explicit supersession/replacement record.
8. Proof no unique valuable files or behavior remain.

`git branch --merged` alone NEVER proves retirement safety. A merged branch may still carry dirty, untracked, ignored, or stashed WIP. Incomplete or contradictory proof → `UNKNOWN` or `RECOVER`.

### 6. Measure progress and conflict

Use satisfied criteria, completed subsystems, missing behavior, current gates, baseline divergence, overlapping edits, and architecture drift.

| Conflict | Evidence |
|---|---|
| `LOW` | Isolated files; clean integration expected |
| `MEDIUM` | Limited overlapping edits requiring review |
| `HIGH` | Broad overlap, stale architecture, migrations, auth, data model, generated assets, or cross-project changes |
| `UNKNOWN` | Evidence insufficient |

Do not invent precise completion percentages.

### 7. Estimate time-to-land

Use ranges only:

- **<1 hour:** landing and verification only.
- **Half day:** small conflicts, focused repair, or missing tests.
- **1–2 days:** meaningful implementation or integration remains.
- **Several days:** cross-cutting, migration, security-sensitive, or high-conflict work.
- **Needs redesign:** stale architecture or unclear acceptance criteria.
- **Blocked:** genuine external dependency.
- **Unknown:** insufficient evidence.

State assumptions. NEVER invent exact ETAs.

## Preservation contract

Before any consolidation, retirement, or removal:

1. Preserve every relevant committed tip under a durable descriptive ref.
2. Snapshot staged, dirty, and untracked work—not only committed history.
3. Preserve relevant stashes under durable refs.
4. Preserve confirmed ignored-important source without secrets or generated noise.
5. Create recovery manifest mapping original path/ref/HEAD and every WIP type to snapshot/tag refs.
6. Verify every recovery ref resolves.
7. Verify each snapshot contains expected files.
8. Verify recovery does not depend solely on reflogs or expiring stash entries.

Tags preserve committed history only. Tags do NOT preserve staged, dirty, untracked, ignored, or stashed work.

## Deletion gate

Remove a worktree or branch only when ALL conditions hold:

1. Mode is `--execute-safe-retirements`.
2. Disposition is `RETIRE — LANDED` or `RETIRE — REDUNDANT`.
3. Confidence is `HIGH`.
4. Canonical remote/default branch and fresh baseline are verified.
5. Unique committed, staged, dirty, untracked, ignored-important, and stashed state was inventoried.
6. Every valuable state carrier was preserved.
7. Required snapshots/tags exist, resolve, and contain expected data.
8. Recovery manifest is complete.
9. Landed/redundant evidence is recorded.
10. Target is not shared/default checkout.
11. No active process or verifiable owner uses target.
12. Exact reviewed path and branch match removal target.
13. Repository-specific removal rules permit removal.
14. Removal needs no force to hide unresolved state.
15. Recovery refs still resolve after removal.

Any failed condition → do not delete; classify `UNKNOWN` or `RECOVER`, record failed condition, and record next investigation action.

NEVER delete `RECOVER`, `KEEP — ACTIVE`, or `UNKNOWN`.

Resolve `BLOCKED`, `DIRTY`, `UNTRACKED-WIP`, `IGNORED-WIP`, and `STASHED-WIP` before deletion. Retire `CONSOLIDATE` work only after consolidation completes and reassessment yields a retirement disposition with `HIGH` confidence.

## Consolidation order

1. Establish fresh canonical baseline.
2. Preserve every recoverable state carrier.
3. Land clean, independent, low-conflict work.
4. Land authoritative plans/specs separately when appropriate.
5. Collapse duplicate implementations into one canonical lane.
6. Reimplement stale valuable work against current code when replaying commits creates avoidable conflicts.
7. Resolve medium-conflict work.
8. Handle cross-cutting/high-conflict work last.
9. Refresh each lane immediately before landing.
10. Run repository gates after every landing.
11. Recalculate remaining conflicts after each landing.

## Report structure

ALWAYS produce both owner view and evidence ledger.

### Executive recommendation

- Safe to remove now
- Preserve and recover
- Keep active
- Consolidate
- Blocked
- Needs investigation
- Recommended landing order
- Risks
- Immediate next actions

For every removal candidate, state safety proof, confidence, recovery ref, and whether current mode authorizes removal.

### Worktree ledger

| Worktree | Branch | Purpose | Plan/spec | Activity | Progress | Remaining work | Conflict | Time-to-land | Disposition | Flags | Confidence | Recommendation | Evidence | Recovery ref |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|

Every row MUST include one concrete next action. Report branches without worktrees separately under identical rules.

### Recovery manifest

| Original worktree | Original branch | Original HEAD | WIP types | Snapshot/tag refs | Verification | Recovery method |
|---|---|---|---|---|---|---|

### Execution receipt

When mutation is authorized, report:

- recovery refs created and verified;
- worktrees and branches removed;
- retained work and reason;
- failed gates;
- skipped actions and reason;
- canonical baseline after execution.

NEVER claim cleanup succeeded when preservation or verification failed.

## Example

Input:

```text
Branch feature/search is not merged by ancestry. Main contains equivalent search behavior after a squash merge; acceptance tests pass. Worktree is dirty and has one untracked migration note. Audit only.
```

Output:

```text
Disposition: RECOVER
Flags: DIRTY, UNTRACKED-WIP, CONSOLIDATE
Confidence: HIGH that committed feature behavior landed; HIGH that unique uncommitted WIP remains
Recommendation: Keep. Snapshot dirty and untracked work, then compare it with current main. Audit mode forbids removal.
Evidence: implementation equivalence + passing acceptance tests prove committed behavior; dirty status + untracked note prove unique state remains.
Next action: preserve the uncommitted state and reassess whether it is redundant or needs transplant.
```

## Red flags

Stop deletion when reasoning contains any of these:

- “It is old.”
- “The branch name says merged.”
- “The worktree is clean.”
- “Git reports it merged.”
- “The files probably are generated.”
- “The stash probably belongs elsewhere.”
- “We can recover it from reflog later.”
- “Force removal is faster.”

Age, names, clean status, ancestry, and convenience are weak evidence—not deletion proof.
