Code Polish
Resolve scope once, make only high-confidence simplifications, fix evidenced defects by risk, and verify the final
state.
Modes
--simplify: simplify only.
--review: review and fix only.
- Neither or both: simplify, then review the simplified result.
--with-profile <name> / --skip-profile <name>: add or suppress review profiles; skip wins.
Fixed Scope
- Require a Git repository.
- Use explicit paths, patterns, ranges, natural-language targets, or a supplied
resolved-scope block when present.
Otherwise use only files modified in this session; if session history is unavailable, use all uncommitted tracked and
untracked files.
- Exclude lockfiles, generated outputs, vendored code, minified bundles, and large data snapshots from manual review
unless explicitly requested. Validate relevant excluded outputs through their generator, schema, or invariants.
- Resolve and retain one authoritative scope set and optional exclusions for execution. Do not broaden or recompute
scope later. Stop if it is empty.
Simplify
Preserve public contracts, inputs, outputs, side effects, error behavior, performance-sensitive characteristics,
telemetry, and operational guards. Apply only changes with a concrete comprehension or defect-risk benefit:
- flatten avoidable control-flow nesting;
- clarify misleading names or dense transforms;
- remove real duplication when the abstraction reduces total complexity;
- tighten local types and contracts without broad churn;
- remove only dead code caused by this session's edits.
Do not split by line count, perform architecture cleanup, convert sync/async APIs, add speculative configurability, or
replace readable duplication with a one-use abstraction. A no-op is a valid result.
Review and Fix
Judge the diff against the user's request. Prioritize CRITICAL → HIGH → MEDIUM → LOW:
- CRITICAL: exploitable security, data loss, or critical outage path.
- HIGH: behavior, error-path, boundary, or performance defect affecting core behavior.
- MEDIUM: resource leak, complexity hotspot, test gap, over-scoped change, speculative complexity, or weak success
criterion likely to cause defects.
- LOW: localized clarity or style issue with a real maintenance cost.
Every finding must cite a verified location, triggering input/state, failure mode, blast radius, and evidence in the
changed code. Merge duplicates and apply the smallest defensible fix. When intent is ambiguous, stop or record the
assumption instead of guessing.
Select every applicable profile and read it once:
| Surface |
Profile |
| auth, secrets, crypto, external input/network, unsafe parsing |
security |
| env, config, timeouts, retries, pools, limits |
configuration |
| Go behavior, concurrency, context, errors |
go |
| Rust, Cargo/workspaces, async/concurrency, unsafe/FFI |
rust |
| TypeScript types, modules, packages, async behavior |
typescript |
| Python services, scripts, async, packaging, data IO |
python |
| shell, CI, deploy, installers, quoting |
shell |
| CSV/JSON/YAML/binary, schemas, migrations, generated data |
data-formats |
| naming and intent clarity |
naming unless skipped |
Profiles live at references/profiles/<name>.md. Missing selected profiles are a stop condition.
Verification and Report
Run the narrowest formatter/lint, targeted tests, typecheck, and invariant checks that prove the final touched behavior.
Broaden only for shared contracts. Name skipped checks and why.
Report Scope, Simplifications when run, Review Findings and Fixes when run, Verification, and Residual Risks.
Summarize scope with the file count and smallest useful repository-relative roots, globs, ranges, or user-supplied
targets. Do not enumerate every file merely to prove scope; name individual paths only for a small explicit scope or to
clarify exceptions and findings. Findings include severity, location, impact, evidence, fix, and confidence. A residual
risk states the assumption, consequence if wrong, and how to check it. Completion requires fixed scope, traceable
edits/findings, and validation evidence.
Render a successful report as ### ✨ Code polish — ✅ complete, a small summary-count table, a compact Scope
summary, ### ✨ Simplifications, ### 🔎 Review findings and fixes, ### 🧪 Verification, and
### ⚠️ Residual risks, omitting inapplicable sections. When review is clean, state ✅ No verified review findings.
If a stop condition below prevents completion, lead with ### ✨ Code polish — ⛔ blocked and report the evidence and
required decision. Keep severity tokens, profile IDs, commands, locations, reproduction inputs, and security evidence
exact and undecorated.
Stop when behavior parity or required high-risk validation cannot be established, or a fix requires an unrequested
public-contract change or larger redesign.
1---
2argument-hint: "[paths] [--simplify] [--review] [--with-profile <name>] [--skip-profile <name>]"
3name: code-polish
4description:
5 "Polish changed code when the user explicitly asks, or when an active workflow requests post-implementation
6 simplification and risk-profiled review over a fixed file scope."
7---
8
9# Code Polish
10
11Resolve scope once, make only high-confidence simplifications, fix evidenced defects by risk, and verify the final
12state.
13
14## Modes
15
16- `--simplify`: simplify only.
17- `--review`: review and fix only.
18- Neither or both: simplify, then review the simplified result.
19- `--with-profile <name>` / `--skip-profile <name>`: add or suppress review profiles; skip wins.
20
21## Fixed Scope
22
231. Require a Git repository.
242. Use explicit paths, patterns, ranges, natural-language targets, or a supplied `resolved-scope` block when present.
25 Otherwise use only files modified in this session; if session history is unavailable, use all uncommitted tracked and
26 untracked files.
273. Exclude lockfiles, generated outputs, vendored code, minified bundles, and large data snapshots from manual review
28 unless explicitly requested. Validate relevant excluded outputs through their generator, schema, or invariants.
294. Resolve and retain one authoritative scope set and optional exclusions for execution. Do not broaden or recompute
30 scope later. Stop if it is empty.
31
32## Simplify
33
34Preserve public contracts, inputs, outputs, side effects, error behavior, performance-sensitive characteristics,
35telemetry, and operational guards. Apply only changes with a concrete comprehension or defect-risk benefit:
36
37- flatten avoidable control-flow nesting;
38- clarify misleading names or dense transforms;
39- remove real duplication when the abstraction reduces total complexity;
40- tighten local types and contracts without broad churn;
41- remove only dead code caused by this session's edits.
42
43Do not split by line count, perform architecture cleanup, convert sync/async APIs, add speculative configurability, or
44replace readable duplication with a one-use abstraction. A no-op is a valid result.
45
46## Review and Fix
47
48Judge the diff against the user's request. Prioritize `CRITICAL → HIGH → MEDIUM → LOW`:
49
50- **CRITICAL**: exploitable security, data loss, or critical outage path.
51- **HIGH**: behavior, error-path, boundary, or performance defect affecting core behavior.
52- **MEDIUM**: resource leak, complexity hotspot, test gap, over-scoped change, speculative complexity, or weak success
53 criterion likely to cause defects.
54- **LOW**: localized clarity or style issue with a real maintenance cost.
55
56Every finding must cite a verified location, triggering input/state, failure mode, blast radius, and evidence in the
57changed code. Merge duplicates and apply the smallest defensible fix. When intent is ambiguous, stop or record the
58assumption instead of guessing.
59
60Select every applicable profile and read it once:
61
62| Surface | Profile |
63| ------------------------------------------------------------- | ----------------------- |
64| auth, secrets, crypto, external input/network, unsafe parsing | `security` |
65| env, config, timeouts, retries, pools, limits | `configuration` |
66| Go behavior, concurrency, context, errors | `go` |
67| Rust, Cargo/workspaces, async/concurrency, unsafe/FFI | `rust` |
68| TypeScript types, modules, packages, async behavior | `typescript` |
69| Python services, scripts, async, packaging, data IO | `python` |
70| shell, CI, deploy, installers, quoting | `shell` |
71| CSV/JSON/YAML/binary, schemas, migrations, generated data | `data-formats` |
72| naming and intent clarity | `naming` unless skipped |
73
74Profiles live at `references/profiles/<name>.md`. Missing selected profiles are a stop condition.
75
76## Verification and Report
77
78Run the narrowest formatter/lint, targeted tests, typecheck, and invariant checks that prove the final touched behavior.
79Broaden only for shared contracts. Name skipped checks and why.
80
81Report `Scope`, `Simplifications` when run, `Review Findings and Fixes` when run, `Verification`, and `Residual Risks`.
82Summarize scope with the file count and smallest useful repository-relative roots, globs, ranges, or user-supplied
83targets. Do not enumerate every file merely to prove scope; name individual paths only for a small explicit scope or to
84clarify exceptions and findings. Findings include severity, location, impact, evidence, fix, and confidence. A residual
85risk states the assumption, consequence if wrong, and how to check it. Completion requires fixed scope, traceable
86edits/findings, and validation evidence.
87
88Render a successful report as `### ✨ Code polish — ✅ complete`, a small summary-count table, a compact `Scope`
89summary, `### ✨ Simplifications`, `### 🔎 Review findings and fixes`, `### 🧪 Verification`, and
90`### ⚠️ Residual risks`, omitting inapplicable sections. When review is clean, state `✅ No verified review findings.`
91If a stop condition below prevents completion, lead with `### ✨ Code polish — ⛔ blocked` and report the evidence and
92required decision. Keep severity tokens, profile IDs, commands, locations, reproduction inputs, and security evidence
93exact and undecorated.
94
95Stop when behavior parity or required high-risk validation cannot be established, or a fix requires an unrequested
96public-contract change or larger redesign.