rsi
Runs a loop that improves existing code (bugs, performance, consistency, tests, DRY) without adding features. Use when the user says 'rsi', or asks to improve, clean up or harden a codebase. For one refactor use refactoring-protocol.
- License 许可
- MIT
- 最近更新
- 2026-11-04
- Stars
- ★ 4
- Forks
- 2
01 前言 Front Matter
- name
- rsi
- group
- process
- description
- Runs a loop that improves existing code (bugs, performance, consistency, tests, DRY) without adding features. Use when the user says 'rsi', or asks to improve, clean up or harden a codebase. For one refactor use refactoring-protocol.
- argument-hint
- [path or scope, optional]
- disable-model-invocation
- true
03 SKILL.md 正文
RSI — Recursive Self-Improvement (Code)
Iteratively improve existing code until it stops yielding improvements. The main session orchestrates; specialized agents do the work. This is a quality loop, not a feature loop.
Prime invariant
- Behaviour-preserving except for defect fixes, each in its own commit with a regression test. Never add functionality, new features, new public API, or new config. A change that adds capability is out of scope: reject it.
- Tests green before a pass and after every change. If the target has no test coverage, write a characterization test first, then improve.
- One change = one concern. Structure OR behavior, never both in the same change.
The loop (orchestrated by the main session, loop-until-dry)
-
Scope. Resolve the target (arg path, or whole project). Identify the test command and confirm the suite is green. If it is red, stop and report — fix the suite before improving. Don't run the loop on code that lacks meaningful test coverage — write characterization tests first. Ask the user once, before the first change: "Commit each step as I go?" Yes → commit each step locally; No → leave the changes uncommitted and list them in the report. Never push.
-
Scan — one dimension at a time. Scan inline when the scope is a few files; dispatch scanners only for scopes a handful of tool calls can't cover, at most 3 at once. Scanners are read-only and produce a ranked list of concrete opportunities:
reviewer/security-auditor→ bugs, correctness, vulnerabilitiesperformance-profiler→ hot paths, N+1, redundant worksystem-auditor→ duplication, dead code, coupling, inconsistent implementations of one conceptreviewer→ readability, naming, pattern & consistency adherenceexplorer/reviewer→ coverage gaps
Each opportunity is a finding record:
file·line·dimension·severity(blocker | major | minor) ·why·fix(one-line proposed change). When a downstream agent consumes the scan, emit findings as JSON objects with exactly those keys; otherwise the dashed formfile:line — dimension/severity — why — fixis fine. -
Prioritize. Order: correctness/safety > missing tests on touched code > DRY/duplication > consistency/homogeneity > pattern & convention fit > performance > clarity/naming. Drop anything that changes behavior or adds capability.
-
Apply one atomic, independent change. Dispatch
coder(bugfix) orrefactorer(behavior-preserving cleanup). Smallest viable diff. Tell the agent not to commit; the main session commits. Sub-agents don't inherit skills, so paste into each brief: the finding record, the prime invariant, the fail-first rule and, forreviewerorrefactorer, the content ofcode-review/SMELLS.md(sibling skill directory). -
Verify. Run affected tests — must stay green. After a batch of atomic changes,
reviewerconfirms: no behavior change, fits conventions, genuinely improves the dimension; mechanical changes rely on green tests. On regression → revert and re-plan. Escalate real logic bugs todebuggerrather than re-looping. -
Commit (only if the user said yes at the start). One concern per commit, independent and revertable. Use the
gitskill's message format. If the user said no, leave the change uncommitted. Then take the next opportunity. -
Repeat passes. Stop after two consecutive dry passes or 5 passes total, whichever comes first. Then report.
Dimensions rubric
Each dimension: what to hunt, what to fix, what to leave alone.
- Bugs & correctness — off-by-one, nil/None, races, missing error handling, unhandled edge cases. Fix minimally + add a regression test. Don't redesign.
- Performance — measured hot paths, N+1 queries, redundant work, bad complexity, unbounded growth. Don't micro-optimize cold paths or trade clarity for guesswork.
- Code quality — the smells in
code-review/SMELLS.md(sibling skill directory), plus deep nesting and magic values. Extract, apply guard clauses, rename. Don't gold-plate. - Consistency / homogeneity — the same kind of thing implemented multiple different ways: mixed styles for one object type, divergent shapes for one concept, inconsistent signatures or return types. Converge on one canonical form and reduce needless variation. Distinct from DRY — this targets divergent expression of one concept, not duplicated logic. Don't force genuinely different things into a false-common shape.
- Pattern adherence — match the project's dominant idioms, structure, and conventions. Align outliers. Don't invent new patterns.
- Tests — cover changed or risky code, fix flaky/slow tests, add missing edge cases. Don't test trivial getters.
- Atomicity — split god-functions and god-classes into single-responsibility units. Don't over-fragment.
- Independence — reduce coupling, remove hidden global state, narrow interfaces. Don't add abstraction layers nobody needs.
- DRY — collapse genuine duplication into one source of truth. Don't DRY accidental similarity (premature abstraction is worse than duplication).
- Dead code — unused functions, variables, imports, branches. Delete after confirming no external use.
Gates (hard)
- No-redesign gate. If the change needs a module or interface redesign, stop and suggest the user run
/improve-codebase-architecture. - Revert on regression. On regression, if the change was committed, revert it with
git revert; if it is uncommitted, discard that one change instead. Neverreset --hardor force-push. - Max 2 review rounds per batch, then accept or drop the change.
- Fail-first, anti-gaming. Every regression test must be shown to FAIL on the unfixed code (it must actually reproduce the bug) BEFORE the fix lands; a characterization test must pass on current code and fail when the pinned behaviour is mutated. Reject any "fix" that games the test rather than addressing root cause — hardcoded expected values, weakened/removed assertions, special-casing the asserted inputs, or operator/equality overloading. A test that passes regardless of the fix proves nothing. The reviewer confirms the test genuinely falsifies the bug.
Done
Report: improvements grouped by dimension, commits made (or the uncommitted changes, if the user said no), tests added, deferrals (with reasons), and anything skipped as out-of-scope (new functionality).
04 同仓库更多 Skills
security-audit
Audits a codebase for security vulnerabilities, independently verifies each one, and writes a report. Use when asked for a full, multi-phase codebase security audit or pen test, or for focused security guidance on code.
wayfinder
Charts a map of investigation tickets on the issue tracker for work too big for one agent session, then resolves them one per session. Use when the user wants to wayfind a large loose idea or continue an existing wayfinder map.
triage
Triages issues and external PRs: categorises, verifies, grills if needed, and writes agent-ready briefs. Use when the user wants to triage the backlog or a specific issue or PR.
to-tickets
Breaks a plan, spec or conversation into tracer-bullet tickets, each declaring its blocking edges, and publishes them to the configured tracker. Use when the user wants a spec or plan turned into tickets or issues.
to-spec
Turns the current conversation into a spec and publishes it to the project issue tracker, with no interview, only synthesis of what was discussed. Use when the user wants the discussion written up as a spec.
setup-agent-tracker
Configures a repo's issue tracker, triage label vocabulary and domain doc layout for the agent-notes workflow skills. Use when starting in a new repo, once, before triage, to-spec, to-tickets or wayfinder.