Simplify

From s-smits/anabasis · View interactive version

Simplify is an AI agent skill from the GitHub repository s-smits/anabasis. Use before committing source changes (as /simplify) or when asked whether code is simple enough, why a mechanism exists, to move a fix one layer higher, to remove something and find a cleaner alternative, or to audit `not-slop.tsv`. Routes invocations (escalating structural rewrites to `commit-r`),

How to use this skill

Skill file

Simplify

Repository /simplify workflow (reduce-complexity owns complexity scripts; commit-r owns compartment rewrites; stack-pr owns stack placement; tools/oxlint/HABITS.md owns lint rules). Work inline without touching another session's PR. Fix any correctness bug uncovered along the way under task authority and report it separately.

1. Route the invocation (and escalate early to `commit-r`)

Scope defaults to named arguments (code, worktree, PR, commit, range, paths) or the working diff against the PR's base branch. Match the procedure to the request:

| Request or trigger | Procedure |

| --- | --- |

| "remove X" / "sloppy, find another way" | Deletion is decided: cut the entire strand (step 5); never return a smaller X or a replacement wrapper |

| "too sloppy" / "rewrite from scratch" / "overkill" | Route directly to commit-r (no separate /simplify pass after commit-r squash; these shapes inform commit-r step 5) |

| "why do we even need X?" / "one layer higher" | Name the owning abstraction or root cause before editing; revert leaf patches and fix the single layer every path traverses |

| "is it simple enough?" / "what looks most bloated?" | Read-only verdict first (or rank by concepts a reader must learn from measure.py and the census) |

| Bare /simplify on own diff or PR | Read the diff as if a colleague wrote it; apply steps 2–6 |

Self-escalate to commit-r instead of nibbling with local edits whenever: (a) a diff or file carries ≥3 interacting local patches/workarounds, (b) you are simplifying a hand-rolled adapter, rewriter, or implicit state machine, or (c) local cuts leave total concepts or branch count flat because the compartment's boundary itself is wrong. A named external boundary holds (a renamed shim breaks it); if it blocks the only clean cut, say so once and stop.

2. Run deterministic checks and audit the ledger first

Never audit manually what static tools already catch, and measure before touching code:

```sh

python3 .claude/skills/reduce-complexity/scripts/measure.py --base <ref> [-C <worktree>]

```

(Use .claude/skills/reduce-complexity/scripts/scope.sh <target> -o <diff> + measure.py --diff <diff> --base <ref> for a PR number or commit range.) Read budget, repeats, ranked function complexity, and UNUSED/one-caller exports first.

3. Concept map, altitude, and structural shapes (H1–H11)

Before editing, read outside the diff: every caller, the module head comment, sibling owners, and git log origin/main..HEAD -- <files> (when patching code introduced by an earlier PR in your own stack, fold into that owning PR rather than stacking a compensating layer). Then run three quick probes:

  1. Concept inventory: list every added or kept concept (types, functions, exports, flags, env knobs, files, branches, fallback paths, prose blocks).
  2. Revert-to-Minimal Probe: starting from <base>, what is the smallest edit that makes every behavioural test pass? Every line beyond that minimal diff must name the failure mode or invariant it prevents.
  3. Upstream / platform check: before keeping any custom rewriter, parser, lock/copy/retry shim, or hardcoded constant wrapping an external tool, CLI, dependency, or OS interface (uv, rsync, git, ssh, bwrap, oxlint, biome, Bun, installed packages), check upstream flags, env vars, or exported constants (--help, node_modules, docs). One native flag beats fifty lines of glue.

Evaluate structural shapes static scans miss, from largest removal to smallest:

| # | Shape | Resolution |

| --- | --- | --- |

| H1 | Unused or invariant in practice (option never varies or branch never reached) | Count across callers and archived logs/receipts (data/runs/); delete if invariant while preserving historical EVENT_KINDS |

| H2 | Generational accretion (two generations side by side, incident date-branch, or controller patch for a weak seat) | Delete the superseded stratum or fix the defect at the seat |

| H3 | Missing upstream or platform primitive (custom glue where native tool flag/env var, Bun/OS primitive, dependency export, or src/meta suffices) | Verify upstream docs/exports and delegate natively (tools/oxlint/HABITS.md 12.8); never add a dependency for a few lines |

| H4 | Instance-level or low-altitude patch (fixes one trigger/caller while leaving the defect class open) | Revert the leaf edit and fix the single owning abstraction every path traverses |

| H5 | Prose compensating for fixable code (prompt warning, skill nudge, or manual flag guarding a trap code can prevent) | Auto-detect, default safely, or make the invalid state unrepresentable in code and delete the prose |

| H6 | Duplicate reader or scattered implicit state (second fold of one fact, or coupled booleans / parallel maps / parsed names) | Call the authoritative production fold (AGENTS.md §5, rule 12) or collapse into one discriminated union (tools/oxlint/HABITS.md 12.14) |

| H7 | Guard for an unreachable state (null check, ?? [], or fallback ruled out upstream or by the OS primitive) | Cite the upstream refusal, type invariant, or primitive error and hostile test, then delete the guard |

| H8 | Wrapper reflex & abstraction laundering (new helper, wrapper, or sibling module added just to pass a line ceiling or import cap) | Export/call the existing owner directly, inline, or cut branches in the owner so total concepts actually drop |

| H9 | Redundant I/O, repeated work, or excess transfer/memory (re-reading files/processes in a loop, loading whole append-only logs, re-scanning unchanged items) | Stream, hoist, or compute once at the common caller and pass forward |

| H10 | Test & fixture bloat (copy-pasted example tests, duplicated fixture builders, or implementation-pinning assertions) | Consolidate into bounded exhaustive checks or deterministic LCG properties over observable outcomes (AGENTS.md §12, tools/oxlint/HABITS.md 12.12; use commit-r mutation testing when replacing existing suites) |

| H11 | Prose & comment bloat (essay comments restating code, drifted notes, or facts stated twice across docs/skills) | State once in the authoritative owner and cross-reference elsewhere |

Simplification ladder (stop at the first rung that holds): (1) broken rule-13 chain (owner → live reader → decision it changes → evidence → hostile test: delete); (2) handled one layer higher; (3) already owned in this repository; (4) provided natively by upstream tool, runtime, or dependency; (5) collapses into one expression (ana/no-arms-differing-in-one-term, table-driven fold); (6) minimal implementation inside its owner — preferring roughly half the machinery for nearly all of the outcome when both mechanism and outcome are measured.

4. Disagreement test, invariants, and budgets

5. Follow the strand and run the mandatory hostile full-diff audit

1. Did this pass invent any new wrapper, helper, flag, or import (H8)?

2. Does every surviving hunk survive the Revert-to-Minimal Probe and one-sentence Disagreement Test?

3. Did total concepts, branches, and net production lines actually decrease rather than relocate?

4. Is any removed strand half-cleaned (orphaned fields, guards, tests, comments, or ledger rows)?

5. If patch-on-patch layers still remain, stop patching and escalate to commit-r.

6. Verify, report, and feed the census

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.