simplify
Use when the user says "simplify this diff" or asks for a compression pass over a change-set. Not for dead-code sweeps: use deslop.
Install
npx skills add https://github.com/OutlineDriven/odin-claude-plugin/tree/main/plugins/odin-code/skills/simplify
claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install outlinedriven-odin-claude-plugin@llmmart
git clone https://github.com/OutlineDriven/odin-claude-plugin.git
The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole outlinedriven/odin-claude-plugin collection as a plugin from our marketplace. Git is the plain clone.
Skill manifest
Simplify: axis-decomposed compression pass on a diff
Contract
| Field | Bound contract |
|---|---|
| Trigger | User asks to simplify a diff, PR, or branch: "simplify this diff", "tighten up", or "compress a change-set" |
| Authority | Reversible local: writes only named local artifacts (working-tree and VCS commits); rollback is version control (git revert HEAD --no-edit). No remote mutation. |
| Side effect | Applies simplification survivors as atomic issue-class commits to the working change-set; auto-reverts any commit that regresses |
| Done | Exit 0: simplification landed as issue-class commits, every fix commit is green, and no new bloat was introduced |
Inputs
Must be supplied:
- An explicit diff scope or a base ref resolvable from HEAD
Optional:
- User-named files when no git context exists (unborn HEAD or no
.git/)
Derived from the diff:
- Three parallel read-only review agents (reuse / quality / efficiency), each scoped to the diff
Procedure
Phase 1: Detect diff scope. Capture every commit since the branch diverged from its base, including staged and unstaged changes. Do not guess the base. Resolve via the first base ref that exists, then run
git diff <base>:git merge-base HEAD origin/maingit merge-base HEAD origin/mastergit merge-base HEAD maingit merge-base HEAD master@{upstream}
If none of the five resolve, gate on two ordered checks:
- Check A:
git rev-parse --verify HEAD 2>/dev/null. If it fails, HEAD is unborn. Skipgit diff; fall through to user-named files or no-git-context path. - Check B: only if Check A succeeded,
git rev-parse --verify HEAD^ 2>/dev/null. If it fails, HEAD is the root commit. Usegit diff HEAD. Surface: "scope: working-tree only, on root commit". - Otherwise: committed history exists but no base ref resolves. Print an explicit error and abort. Do not fall back to
git diff HEAD; that would silently drop committed work.
If no git context or HEAD is unborn, use user-named files supplied in the invocation. Empty after all valid resolutions → exit 11.
Explicit-base override:
simplify against <ref>bypasses the resolution above and runsgit --no-pager diff "<ref>"directly.Done when: the diff is captured or an exit code is returned.
Phase 2: Dispatch three review agents in one
taskcall. Issue a singletasktool call with atasksarray of three items, never three sequential messages. Each agent receives<axis-prompt from references/> + "\n\n---\n\nDIFF:\n" + <captured diff>. All three agents are read-only; disjoint axes; independence asserted in the spawn message:"Three agents dispatched in parallel. Axes are disjoint by construction: reuse-axis owns Graft (existing-utility detection), quality-axis owns Excess + Sprawl on code shape, efficiency-axis owns Excess + Sprawl on execution cost. All three agents are read-only; none edits files; none reads or writes shared mutable state."
Agent type:
Explore(read-only).Axes:
- reuse (Agent 1): four rules (REPLACE, DUPLICATE, INLINE-COULD-USE-UTILITY, STDLIB-REIMPLEMENT). Detects new code written where a utility already exists.
- quality (Agent 2): nine patterns (redundant-state, parameter-sprawl, copy-paste-variation, leaky-abstractions, stringly-typed, redundant-structural-nesting, nested-conditionals, unnecessary-comments, dead-code-unused-imports-exports). Detects unnecessary surface and structure without functional cause.
- efficiency (Agent 3): seven patterns (unnecessary-work, missed-concurrency, hot-path-bloat, recurring-no-op-updates, unnecessary-existence-checks, memory-listener-leaks, overly-broad-operations). Detects work that need not happen and structure that bloats hot paths.
See
references/orchestration.mdfor the concrete dispatch shape and shell snippet.Done when: all three agents return their findings.
Phase 3: Audit, then apply. Wait for all three agents. Aggregate findings by
{axis, file, line, issue-class}. Deduplicate identical cross-axis findings: keep each once, attribute it to the first reporter, and note the second axis as a co-signer. Dispatch a Reviewer agent (alsoExplore-typed and read-only) to audit the composed list for completeness, consistency, accuracy, and scope. The Reviewer's output is the validated survivor set. The orchestrator applies survivors directly, one issue class per atomic commit, and drops non-survivors without comment or re-adjudication. After each commit, run repo-native tests. On red, auto-revert viagit revert HEAD --no-editand stop that class's run.Commit sequencing by class:
- Duplicate commit: reuse-axis survivors + any other axis flagged
issue-class: duplicate - Excess-surface commit: quality-axis + efficiency-axis survivors flagged
issue-class: excess-surface - Structure commit: quality-axis + efficiency-axis survivors flagged
issue-class: structure
Commit message format: capitalized imperative subject, ≤50 chars target, ≤72 hard, no trailing period.
After the final commit, audit the simplify patch itself for unneeded surface, duplicated logic, structure without cause, or a broken consumer contract. If the audit finds any, revert the entire simplify chain via
git revert <first-simplify-commit>^..HEAD --no-editand exit 14.Done when: all survivor commits are applied and green, or an exit code is returned.
- Duplicate commit: reuse-axis survivors + any other axis flagged
Failure and recovery
| Exit code | Trigger | Recovery |
|---|---|---|
| 0 | Clean | none |
| 11 | Empty diff after all fallbacks | Pass-through, no work to do |
| 12 | Findings emitted but survivor set empty after Reviewer audit | Report attached, no patch applied |
| 13 | Behavior regression on a fix commit | Offending commit auto-reverted; stop simplify run for that class; already-landed commits remain |
| 14 | Post-fix audit caught new bloat in the simplify patch | Entire simplify chain reverted; orchestrator may re-plan and re-invoke |
| 15 | Mixed-concern commit (bundles more than one issue-class) | Must split before merging |
Partial-result rule: commits already landed before a failure remain. A rollback does not revert previously successful class commits.
Non-mutation rule: sequential dispatch (not a single task call with a tasks array of three items) is rejected at the validation gate before any agent runs.
Output
Terminal classification with an exit code. On exit 0: the change-set is compressed along reuse / quality / efficiency axes with one atomic commit per issue class, every fix commit green, and no new bloat introduced.
Files (odin-claude-plugin)
-
agents
-
openai.yaml 157 B
interface: display_name: "Simplify" short_description: "Use when the user says \"simplify this diff\" or asks for a compression pass over a change-set."
-
-
references
-
efficiency.md 4.7 KB
# `simplify`: efficiency axis agent prompt Verbatim prompt for the efficiency-axis review agent. The orchestrator dispatches this prompt with the captured diff appended after the `DIFF:` marker. ## Table of contents - Seven patterns: unnecessary work · missed concurrency · hot-path bloat · recurring no-op updates · unnecessary existence checks · memory/listener leaks · overly broad operations - Tool order (fd → ast-grep → grep/rg) - Output schema (finding fields, pattern enum) - Hard limits --- ``` ROLE: You are the efficiency-axis review agent for ODIN's `simplify` skill. AXIS: Cost of execution. PRIMARY ISSUE CLASSES: excess-surface (work that need not happen), structure (structure that bloats hot paths). You receive a diff at the end of this message. Read it. Flag instances of the seven patterns below — these seven are the universe; do not invent an eighth. SEVEN PATTERNS: 1. UNNECESSARY WORK [Excess] Redundant computations, repeated file reads, duplicate API/network calls, N+1 patterns. Detector: same value recomputed within one scope; a loop that calls a network/DB function with a stable key. 2. MISSED CONCURRENCY [Excess] Independent operations executed sequentially when they could run concurrently. Detector: two `await`s in a row whose inputs are independent; two sequential file reads with no data dependency. 3. HOT-PATH BLOAT [Sprawl] New blocking work added to startup, per-request, or per-render paths. Detector: a synchronous heavy operation added to a function known to be hot — file I/O, a deserialize call on a large payload (JS/TS `JSON.parse`, Python `json.loads`), regex compile. 4. RECURRING NO-OP UPDATES [Excess] State or store updates inside a polling loop, interval, or event handler that fire unconditionally. Fix: add a change-detection guard so downstream consumers are not notified when nothing changed. Also: if a wrapper takes an updater/reducer callback, verify it honors a same-reference ("no change") return — otherwise a callback's own early-return no-op is silently defeated by the wrapper. Detector: a state write inside a timer or loop with no preceding equality check (JS/TS `setState` inside `setInterval`, Rust a `loop` writing a shared `Mutex` every tick); a reducer/updater that always returns a new object even when the payload is structurally equal. 5. UNNECESSARY EXISTENCE CHECKS [Excess] An existence check followed by the operation that would fail anyway if the resource were gone — classic TOCTOU. Fix: operate directly and handle the error. Detector: `fs.exists` / `os.path.exists` / `Path.exists` followed by a read/write of the same path. 6. MEMORY / LISTENER LEAKS [Excess] Unbounded structures, missing cleanup, or a subscription/handle acquired with no paired release. Detector: a registration with no teardown before the owning scope ends — JS/TS `addEventListener`/`subscribe`/`setInterval` without `removeEventListener`/`unsubscribe`/`clearInterval`; Python a handle opened with no matching `close()`. 7. OVERLY BROAD OPERATIONS [Excess] Reading or processing the entire file / record / collection when a portion suffices — over-fetch then discard. Detector: `read_file(...)` followed by slicing into the result (non-SQL case); a SQL `SELECT *` followed by use of one column (SQL case); loading all items when filtering for one. TOOL ORDER (ODIN `fd-First [MANDATORY]`): 1. `fd -e <ext> -E <noise>` to scope candidate files for hot-path cross-checks (rendering entry points, request handlers, startup bootstraps). 2. `ast-grep run -p '<pattern>' -l <lang>` for structural detection of patterns 1 (recomputation in scope), 2 (sequential awaits), 4 (state write in a timer/loop), 5 (exists-then-operate), 6 (registration without teardown). 3. `git --no-pager grep -n -F 'literal'` or `rg -nF 'literal'` for literal-text fallback when structural patterns do not match. OUTPUT — one finding per object, nothing else: findings: - file: <path> line: <number> pattern: unnecessary-work | missed-concurrency | hot-path-bloat | recurring-no-op-updates | unnecessary-existence-checks | memory-listener-leaks | overly-broad-operations issue-class: excess-surface | structure fix-sketch: <2-3 line description> confidence: high | med | low HARD LIMITS: - You do not edit files. Findings only. - The seven patterns above are the universe. Do not flag an eighth. - Do not propose micro-optimizations without a clearly hot site. - Do not flag readability cost as efficiency cost. - Do not pad with low-confidence findings. --- DIFF: <orchestrator appends the captured diff here> ``` -
orchestration.md 5.9 KB
# `simplify`: orchestration recipe Dispatch shape, composition rule, Reviewer audit contract, fix sequencing, and behavior gate for the `simplify` skill. Read alongside `../SKILL.md` Phase 1 / 2 / 3. ## Phase 1: diff scope resolution (shell snippet) ```bash # Resolve a base ref. Print "" and exit 1 if none resolves. resolve_base() { for candidate in \ "$(git merge-base HEAD origin/main 2>/dev/null)" \ "$(git merge-base HEAD origin/master 2>/dev/null)" \ "$(git merge-base HEAD main 2>/dev/null)" \ "$(git merge-base HEAD master 2>/dev/null)" \ "$(git rev-parse '@{upstream}' 2>/dev/null)"; do if [ -n "$candidate" ]; then printf '%s\n' "$candidate" return 0 fi done return 1 } # Primary path. if base="$(resolve_base)"; then diff="$(git --no-pager diff "$base")" elif git rev-parse --verify HEAD >/dev/null 2>&1; then if git rev-parse --verify 'HEAD^' >/dev/null 2>&1; then # Committed history exists, no base resolves -> abort. printf 'simplify: committed history exists but no base ref resolves\n' >&2 printf ' re-invoke with explicit base: simplify against <ref>\n' >&2 exit 2 else # HEAD is the root commit -> working tree only is the full scope. printf 'simplify: scope: working-tree only, on root commit\n' >&2 diff="$(git --no-pager diff HEAD)" fi else # Unborn HEAD or no git context -> caller supplies files. diff="" fi # Empty diff after all valid resolutions -> exit 11. [ -z "$diff" ] && exit 11 ``` **Explicit-base override**: when the user invokes `simplify against <ref>`, the orchestrator bypasses `resolve_base` and runs `git --no-pager diff "<ref>"` directly. The `<ref>` is any revision spec git accepts (`HEAD~5`, a SHA, a branch name, a tag). ## Phase 2: single `task` call dispatch shape The orchestrator issues a single `task` tool call with a `tasks` array of three items, never three sequential messages. Each item receives a prompt built as: ``` <axis prompt from references/<axis>.md, verbatim> --- DIFF: <captured diff from Phase 1> ``` Independence argument the orchestrator must include in the spawn message: > "Three agents dispatched in parallel. Axes are disjoint by construction: reuse-axis owns Graft (existing-utility detection), quality-axis owns Excess + Sprawl on code shape, efficiency-axis owns Excess + Sprawl on execution cost. All three agents are read-only; none edits files; none reads or writes shared mutable state." Agent type for each invocation: `Explore` (read-only). ## Phase 3: composition, audit, fix ### Composition After all three findings lists return, merge by `{file, line}`. Tag each finding with its axis. When two axes report the same `{file, line}` with structurally identical patterns, deduplicate: keep the finding once, attribute to the first reporter, note the second axis as a co-signer. ### Reviewer audit (single adjudication authority) Dispatch a Reviewer agent (also `Explore`-typed, read-only) with: - the composed findings list, - the original diff, - the axis prompts from `references/{reuse,quality,efficiency}.md`. Reviewer audit charter (four checks): 1. **Completeness**: did the three axes between them cover every diff hunk that warrants attention? Flag systematic blind spots. 2. **Consistency**: do any findings contradict each other (e.g., "extract this into a helper" vs "inline this helper")? Flag and resolve. 3. **Accuracy**: for each finding, verify the citation. Discard findings whose `path:line` does not match the diff or whose `existing-utility` does not exist. 4. **Scope**: flag findings that propose changes outside the diff's blast radius. Discard. The Reviewer's output is the **validated survivor set**. The orchestrator applies survivors and drops non-survivors; no re-litigation in either direction. If the survivor set is empty after a non-empty raw findings list, exit 12. ### Fix sequencing Group survivors by `issue-class`. Apply in this order, one atomic commit per class: 1. **Duplicate commit**: apply all reuse-axis survivors (and any other axis survivors flagged `issue-class: duplicate`). 2. **Excess-surface commit**: apply all quality-axis + efficiency-axis survivors flagged `issue-class: excess-surface`. 3. **Structure commit**: apply all quality-axis + efficiency-axis survivors flagged `issue-class: structure`. Commit message format follows the baseline `<git>` charter (capitalized imperative subject, 50 chars target and 72 hard, no trailing period); recommended: ``` Remove <class> from <scope> <2-4 lines describing the survivors applied in this commit, citing file:line pairs> ``` A commit that would bundle survivors from more than one class is split before merge (exit 15). ## Behavior gate (after every commit) After each fix commit, run the repo-native verifier per the matrix derived from the project's manifest in this order: a task-runner target (`just test`, `make test`), then the ecosystem's own test command (`cargo test`, `pytest`, `npm test`, `dune runtest`, `go test ./...`), or the equivalent for the current language. On red: ```bash git revert HEAD --no-edit ``` Surface the failure mode (exit 13) and stop the simplify run for the affected commit. Other class commits already landed remain. ## Post-fix audit (no new bloat) After the final commit, audit the simplify patch itself for unneeded surface, duplicated logic, structure without cause, or a broken consumer contract. Any hit → revert the entire simplify chain via `git revert <first-simplify-commit>^..HEAD --no-edit` and exit 14. The orchestrator may re-plan and re-invoke. ## Exit code summary (matches SKILL.md) | Code | Trigger | |---|---| | 0 | Survivors applied, behavior gate green, no new bloat | | 11 | Empty diff after all Phase 1 resolutions | | 12 | Survivor set empty after Reviewer audit | | 13 | Behavior gate red on a fix commit; that commit reverted | | 14 | Post-fix audit caught new bloat; chain reverted | | 15 | Mixed-class commit detected; split required before merge | -
quality.md 7 KB
# `simplify`: quality axis agent prompt Verbatim prompt for the quality-axis review agent. The orchestrator dispatches this prompt with the captured diff appended after the `DIFF:` marker. ## Table of contents - Nine patterns: redundant state · parameter sprawl · copy-paste variation · leaky abstractions · stringly-typed code · redundant structural nesting · nested conditionals · unnecessary comments · dead code / unused imports / unused exports - Tool order (fd → ast-grep → grep/rg) - Output schema (finding fields, pattern enum) - Hard limits - Balance: avoid over-simplification - Never simplify away a safety check --- ``` ROLE: You are the quality-axis review agent for ODIN's `simplify` skill. AXIS: Code quality / shape. PRIMARY ISSUE CLASSES: excess-surface (unnecessary surface), structure (structure without functional cause). You receive a diff at the end of this message. Read it. Flag instances of the nine patterns below — these nine are the universe; do not invent a tenth. NINE PATTERNS: 1. REDUNDANT STATE [Excess] Duplicated state, cached values that could be derived on read, observers/effects that could be direct calls. Detector: a variable that mirrors another variable; an effect whose entire body is one `set(...)` of a value computable from the deps. 2. PARAMETER SPRAWL [Excess] A function adds new parameters instead of generalizing or restructuring. Detector: same function gained ≥ 2 params in the diff; or a param is used in exactly one call site and could be a constant there. 3. COPY-PASTE WITH SLIGHT VARIATION [Sprawl] Near-duplicate blocks (two branches, two functions, two cases) that differ only in a constant, a key, or a type. Detector: two diff hunks with structural similarity > ~70%. 4. LEAKY ABSTRACTIONS [Sprawl] Internal details exposed across a boundary the rest of the code respects. Detector: a public function returns an internal type; a module's caller reaches through to a private collaborator. 5. STRINGLY-TYPED CODE [Excess] Raw strings used where a constant, enum, or a closed/nominal type already exists nearby. Detector: a literal string appears ≥ 2 times in the diff or matches an existing enum value verbatim. 6. REDUNDANT STRUCTURAL NESTING [Sprawl] A container node (wrapper component, layout element, grouping construct) that adds no layout, semantic, or behavioral value over its single child. Detector: a container with exactly one child and no style/role/handler of its own — check whether the child's own props already cover it before flattening. Instances: JSX `<Box>`/`<div>`/ `<Fragment>` with one child and no layout prop (`flexShrink`, `alignItems`) the child doesn't already carry; SwiftUI `Group`/ `VStack` wrapping one child with no `.frame()`/`.padding()` applied. 7. NESTED CONDITIONALS [Sprawl] Conditional branches nested 3+ levels deep, regardless of surface syntax — ternary chains (`a ? x : b ? y : ...`), if/else trees, match/ switch blocks. Fix shape: early returns, guard clauses, a lookup table, or a flat if/else-if (or match/when) cascade. Detector: conditional nesting depth ≥ 3 in any diff hunk (C-family `?:` chains, Python `if`/`else` expressions, and Rust `match` arms all count). 8. UNNECESSARY COMMENTS [Excess] Comments explaining WHAT the code does (well-named identifiers already say that), narrating the change, or referencing the task/caller. Keep only non-obvious WHY (hidden constraints, subtle invariants, workarounds). Detector: the comment paraphrases the immediately-following expression. 9. DEAD CODE / UNUSED IMPORTS / UNUSED EXPORTS [Excess] Code paths no longer reachable, imports not referenced by the changed file, exports no longer consumed by any caller in the codebase. To verify "unused" across the codebase, derive the check from the project's configuration, in this order: a manifest-declared lint script (`package.json` "lint", `pyproject.toml` tool config), then the ecosystem's own unused-code checker (JS/TS ESLint `no-unused-vars`/`unused-imports`, `knip`, `tsc --noEmit --noUnusedLocals`, Python `ruff` F401, Go `golangci-lint unused`), or the project's documented command. Otherwise prefer a structural search like `ast-grep` over plain text grep — grep produces false positives from string literals, comments, and substring matches in unrelated identifiers. Account for indirect re-exports (barrel files/`export * from`, Rust `pub use`), dynamically resolved imports (`import()`/`require()`, template-string imports, Python `importlib.import_module`), and framework- or runtime-reserved exports a linter can't see a caller for (Next.js/RSC exports, decorators, Rust FFI exports). False positives here are higher-cost than missed catches; if uncertain, skip. TOOL ORDER (ODIN `fd-First [MANDATORY]`): 1. `fd -e <ext> -E <noise>` to scope candidate files when cross-checking that a "similar block" or "existing enum" actually exists elsewhere. 2. `ast-grep run -p '<pattern>' -l <lang>` for structural detection of patterns 3 (copy-paste), 6 (redundant nesting), 7 (nested conditionals). 3. `git --no-pager grep -n -F 'literal'` or `rg -nF 'literal'` for pattern 5 (stringly-typed) cross-references and pattern 8 (comment pattern matching). OUTPUT — one finding per object, nothing else: findings: - file: <path> line: <number> pattern: redundant-state | parameter-sprawl | copy-paste-variation | leaky-abstraction | stringly-typed | redundant-structural-nesting | nested-conditionals | unnecessary-comments | dead-code-unused-imports-exports issue-class: excess-surface | structure fix-sketch: <2-3 line description of the simplification> confidence: high | med | low HARD LIMITS: - You do not edit files. Findings only. - The nine patterns above are the universe. Do not flag a tenth. - Do not flag style or naming preferences. - Comments-of-WHAT only — never flag comments that explain WHY. - Do not pad with low-confidence findings. BALANCE — avoid over-simplification: Every flag above has a failure mode in the opposite direction; fewer lines is not the goal, faster comprehension is. Do not inline a helper that gives a concept a name, merge unrelated logic into one function, or remove an abstraction that exists for testability/extensibility or whose purpose you haven't confirmed is obsolete (check `git blame` for the original intent). If a proposed change would be longer or harder to follow than the original, don't flag it. Do not simplify away a safety check: Input validation at trust boundaries, error handling that prevents data loss, security checks (authorization, escaping, sanitization), and accessibility affordances are not removable boilerplate — preserve them even when a finding frames them as redundant or inline-able. Code that drops one of these is not simpler, it is unfinished. If a proposed simplification would thin or remove one, skip it. --- DIFF: <orchestrator appends the captured diff here> ``` -
reuse.md 4 KB
# `simplify`: reuse axis agent prompt Verbatim prompt for the reuse-axis review agent. The orchestrator dispatches this prompt with the captured diff appended after the `DIFF:` marker. --- ``` ROLE: You are the reuse-axis review agent for ODIN's `simplify` skill. AXIS: Code reuse. PRIMARY ISSUE CLASS: duplicate — new code written where an existing utility belongs. You receive a diff at the end of this message. Read it. Then search the rest of the repository for existing utilities, helpers, or shared modules that the new code in the diff could have used instead. FOUR RULES — apply each, report what you find: 1. REPLACE: For each new function in the diff, search the codebase for an existing function with substantively equivalent behavior. If one exists, the new function is a Graft — name the existing function and its location. 2. DUPLICATE: For each new logic block in the diff (≥ 5 lines, not boilerplate), search for near-identical blocks already in the codebase. If found, the new block should call (or be unified with) the existing block. 3. INLINE-COULD-USE-UTILITY: For each piece of inline logic in the diff that hand-rolls a common operation — string manipulation, path joining, environment lookup, a narrowing construct (Rust `matches!`, Python `TypeGuard`, Go comma-ok, TS type guard), date math, URL parsing — search for an existing utility (in-repo or stdlib) that already does it. If one exists, the inline logic is Graft. 4. STDLIB-REIMPLEMENT: For each piece of inline logic or new function in the diff that reimplements a language standard-library or runtime primitive — a hand-written routine the built-in stdlib/runtime API already provides (e.g., a manual array-dedup loop where the language ships a set-based idiom, a hand-rolled deep-clone/deep-merge where the runtime has one) — flag it. Suggest the built-in only when it is behavior-equivalent for the inputs actually in play. Do not propose swaps that change behavior or UX: native UI controls, locale-dependent formatting, sort-stability assumptions, and serialization edge cases differ from their hand-rolled versions and are out of scope for a behavior-preserving pass. SEARCH SCOPE — actually search, do not speculate: - `utils/`, `helpers/`, `lib/`, `shared/`, `common/`, `internal/` directories (Go's `internal/` is compiler-enforced import visibility, not a naming habit — only code within the directory tree rooted at `internal/`'s parent can import it; anything outside that tree cannot, regardless of package name) - Adjacent files in the same module as each diff hunk - Top-level barrel exports (`index.ts`, `mod.rs`, `__init__.py`) - Language stdlib for the common operations in rule 3 and stdlib/runtime primitives in rule 4 TOOL ORDER (ODIN `fd-First [MANDATORY]`): 1. `fd -e <ext> -E <noise>` to discover candidate files. Validate count stays under ~50; narrow the scope (`-E node_modules -E vendor -E dist`) if the result set is larger. 2. `ast-grep run -p '<pattern>' -l <lang> -C 3` for structural matches — prefer this for function-signature or call-site discovery. 3. `git --no-pager grep -n -F 'literal'` or `rg -nF 'literal'` for literal text matches when structural patterns do not apply. 4. Cite the exact `path:line` found. Do not claim a utility exists without pointing at it. OUTPUT — JSON-style, one finding per object, nothing else: findings: - file: <path> line: <number> kind: replace | duplicate | inline-could-use-utility | stdlib-reimplement existing-utility: <path>:<symbol> # the thing the new code should use suggested-replacement: <one-line description of the fix> confidence: high | med | low HARD LIMITS: - You do not edit files. You produce findings only. - Do not pad with low-confidence findings. Empty findings list is a valid output; the orchestrator handles it. - Do not flag style or naming. Only the four rules above. - Do not claim an existing utility without an exact `path:line` citation. --- DIFF: <orchestrator appends the captured diff here> ```
-
-
SKILL.md 6.6 KB
--- name: simplify description: 'Use when the user says "simplify this diff" or asks for a compression pass over a change-set. Not for dead-code sweeps: use deslop.' --- # Simplify: axis-decomposed compression pass on a diff ## Contract | Field | Bound contract | |---|---| | Trigger | User asks to simplify a diff, PR, or branch: "simplify this diff", "tighten up", or "compress a change-set" | | Authority | Reversible local: writes only named local artifacts (working-tree and VCS commits); rollback is version control (`git revert HEAD --no-edit`). No remote mutation. | | Side effect | Applies simplification survivors as atomic issue-class commits to the working change-set; auto-reverts any commit that regresses | | Done | Exit 0: simplification landed as issue-class commits, every fix commit is green, and no new bloat was introduced | ## Inputs Must be supplied: - An explicit diff scope or a base ref resolvable from HEAD Optional: - User-named files when no git context exists (unborn HEAD or no `.git/`) Derived from the diff: - Three parallel read-only review agents (reuse / quality / efficiency), each scoped to the diff ## Procedure 1. **Phase 1: Detect diff scope.** Capture every commit since the branch diverged from its base, including staged and unstaged changes. Do not guess the base. Resolve via the first base ref that exists, then run `git diff <base>`: 1. `git merge-base HEAD origin/main` 2. `git merge-base HEAD origin/master` 3. `git merge-base HEAD main` 4. `git merge-base HEAD master` 5. `@{upstream}` If none of the five resolve, gate on two ordered checks: - Check A: `git rev-parse --verify HEAD 2>/dev/null`. If it fails, HEAD is unborn. Skip `git diff`; fall through to user-named files or no-git-context path. - Check B: only if Check A succeeded, `git rev-parse --verify HEAD^ 2>/dev/null`. If it fails, HEAD is the root commit. Use `git diff HEAD`. Surface: "scope: working-tree only, on root commit". - Otherwise: committed history exists but no base ref resolves. Print an explicit error and abort. Do not fall back to `git diff HEAD`; that would silently drop committed work. If no git context or HEAD is unborn, use user-named files supplied in the invocation. Empty after all valid resolutions → exit 11. **Explicit-base override:** `simplify against <ref>` bypasses the resolution above and runs `git --no-pager diff "<ref>"` directly. Done when: the diff is captured or an exit code is returned. 2. **Phase 2: Dispatch three review agents in one `task` call.** Issue a single `task` tool call with a `tasks` array of three items, never three sequential messages. Each agent receives `<axis-prompt from references/> + "\n\n---\n\nDIFF:\n" + <captured diff>`. All three agents are read-only; disjoint axes; independence asserted in the spawn message: > "Three agents dispatched in parallel. Axes are disjoint by construction: reuse-axis owns Graft (existing-utility detection), quality-axis owns Excess + Sprawl on code shape, efficiency-axis owns Excess + Sprawl on execution cost. All three agents are read-only; none edits files; none reads or writes shared mutable state." Agent type: `Explore` (read-only). Axes: - reuse (Agent 1): four rules (REPLACE, DUPLICATE, INLINE-COULD-USE-UTILITY, STDLIB-REIMPLEMENT). Detects new code written where a utility already exists. - quality (Agent 2): nine patterns (redundant-state, parameter-sprawl, copy-paste-variation, leaky-abstractions, stringly-typed, redundant-structural-nesting, nested-conditionals, unnecessary-comments, dead-code-unused-imports-exports). Detects unnecessary surface and structure without functional cause. - efficiency (Agent 3): seven patterns (unnecessary-work, missed-concurrency, hot-path-bloat, recurring-no-op-updates, unnecessary-existence-checks, memory-listener-leaks, overly-broad-operations). Detects work that need not happen and structure that bloats hot paths. See `references/orchestration.md` for the concrete dispatch shape and shell snippet. Done when: all three agents return their findings. 3. **Phase 3: Audit, then apply.** Wait for all three agents. Aggregate findings by `{axis, file, line, issue-class}`. Deduplicate identical cross-axis findings: keep each once, attribute it to the first reporter, and note the second axis as a co-signer. Dispatch a Reviewer agent (also `Explore`-typed and read-only) to audit the composed list for completeness, consistency, accuracy, and scope. The Reviewer's output is the **validated survivor set**. The orchestrator applies survivors directly, one issue class per atomic commit, and drops non-survivors without comment or re-adjudication. After each commit, run repo-native tests. On red, auto-revert via `git revert HEAD --no-edit` and stop that class's run. Commit sequencing by class: 1. Duplicate commit: reuse-axis survivors + any other axis flagged `issue-class: duplicate` 2. Excess-surface commit: quality-axis + efficiency-axis survivors flagged `issue-class: excess-surface` 3. Structure commit: quality-axis + efficiency-axis survivors flagged `issue-class: structure` Commit message format: capitalized imperative subject, ≤50 chars target, ≤72 hard, no trailing period. After the final commit, audit the simplify patch itself for unneeded surface, duplicated logic, structure without cause, or a broken consumer contract. If the audit finds any, revert the entire simplify chain via `git revert <first-simplify-commit>^..HEAD --no-edit` and exit 14. Done when: all survivor commits are applied and green, or an exit code is returned. ## Failure and recovery | Exit code | Trigger | Recovery | |---|---|---| | 0 | Clean | none | | 11 | Empty diff after all fallbacks | Pass-through, no work to do | | 12 | Findings emitted but survivor set empty after Reviewer audit | Report attached, no patch applied | | 13 | Behavior regression on a fix commit | Offending commit auto-reverted; stop simplify run for that class; already-landed commits remain | | 14 | Post-fix audit caught new bloat in the simplify patch | Entire simplify chain reverted; orchestrator may re-plan and re-invoke | | 15 | Mixed-concern commit (bundles more than one issue-class) | Must split before merging | Partial-result rule: commits already landed before a failure remain. A rollback does not revert previously successful class commits. Non-mutation rule: sequential dispatch (not a single `task` call with a `tasks` array of three items) is rejected at the validation gate before any agent runs. ## Output Terminal classification with an exit code. On exit 0: the change-set is compressed along reuse / quality / efficiency axes with one atomic commit per issue class, every fix commit green, and no new bloat introduced.
Comments (0)
Sign in to join the conversation.
Reviews (0)
No reviews yet.
No comments yet.