用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/joshsymonds/gambit --skill refactoring命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
Turns a rough idea into an approved epic contract with immutable requirements, anti-patterns, and a first wave of executable tasks.
Turns a rough idea into an approved epic contract with immutable requirements, anti-patterns, and a first wave of executable tasks.
Executes an approved epic one wave at a time, dispatching a worker per task and stopping at a checkpoint after each wave. Use when an approved epic contract and native wave plan exist in the current root session, when resuming work after a previous checkpoint, or when iteratively building a feature and execution learnings require a later wave. User phrases like "continue the plan", "next wave", "resume where we left off", "pick up the epic".
| name | refactoring |
| description | Restructures code that already has a green test suite, without changing behavior. |
| when_to_use | Use this implementation mechanic to restructure covered code without changing behavior only when explicitly invoked by name or called by an active Gambit workflow owner; do not select it implicitly as a peer workflow. |
Freedom: MEDIUM — adapt refactoring patterns to the language and codebase. Fixed: the change→test→commit cycle, and never proceed with failing tests.
Refactoring changes code structure without changing behavior. Tests must stay green throughout, or you're rewriting, not refactoring.
Core principle: Change → Test → Commit. Repeat until complete. Tests green at every step.
Iron Law: NO changes without passing tests BEFORE and AFTER. Tests fail? STOP. Undo. Make a smaller change. "I'll test at the end" = you're not refactoring. No exceptions.
| Step | Action | STOP If |
|---|---|---|
| 1 | Verify tests pass BEFORE starting | Any test fails |
| 2 | Create refactoring Task | - |
| 2 | Present complete refactoring workflow brief in root transcript | - |
| 3 | Make ONE small change | Doesn't compile | | 4 | Run tests immediately | Any test fails | | 5 | Commit with descriptive message | - | | 6 | Repeat 3-5 until complete | Tests fail → undo | | 7 | Final verification | - | | 8 | Mandatory review | Review fails |
| 9 | Close Task | - |
| 9 | Record checkpoint result and complete the wave | - |
Core cycle: Change → Test → Commit (repeat)
If tests fail: STOP. Undo change. Make smaller change. Try again.
Don't use for:
gambit:executing-plans)gambit:debugging)gambit:test-driven-development)Before the first test dispatch, Resolve the test-runner role through contracts/models.md to its
rung, and retain that rung for every test-runner call in this refactoring. A model rung uses the
general-purpose dispatch examples below with model: set to the rung's alias; an agent rung uses
the rung's agent and passes no model: at all. The command, the report requirement, and the
no-edits rule are the same on either shape.
Use the native test-runner class for every test dispatch below.
BEFORE any refactoring:
Agent
subagent_type: "general-purpose" # model rung; an agent rung uses the rung's agent
model: "<test-runner rung alias — contracts/models.md>" # omit entirely on an agent rung
description: "Run test suite"
prompt: "Run: [test command for this project]. Report pass/fail counts and any failures. Make no edits."
Agent
subagent_type: "general-purpose"
model: "<test-runner tier — see contracts/models.md>"
description: "Run test suite"
prompt: "Run: [test command for this project]. Report pass/fail counts and any failures. Make no edits."
ALL tests must pass.
Failing tests mean you can't detect if refactoring breaks things.
<!-- gambit-backend:claude -->
TaskCreate
subject: "Refactor: [specific goal]"
description: |
<!-- /gambit-backend -->
<!-- gambit-backend:codex -->
Present in the root transcript as "Workflow Brief: Refactor [specific goal]":
<!-- /gambit-backend -->
## Goal
[What structure change you're making]
## Why
- [Reason: duplication, complexity, etc.]
## Approach
1. [Transformation 1]
2. [Transformation 2]
3. [Transformation 3]
## Success Criteria
- [ ] All existing tests still pass
- [ ] No behavior changes
- [ ] Code is cleaner/simpler
- [ ] Each commit is small and safe
<!-- gambit-backend:claude -->
activeForm: "Refactoring code"
<!-- /gambit-backend -->
Then: TaskUpdate taskId: "[id]" status: "in_progress"
Keep the complete workflow brief in the root transcript. If this refactoring is already a worker inside the current wave, do not create another plan step. Otherwise use SessionPlanWrite only as a complete-list replacement that preserves every existing step and marks one concise refactoring wave in_progress.
The smallest transformation that compiles.
Examples of "small":
NOT small:
The test: If you can't describe the change in one sentence, it's too big. Split it.
After EVERY small change:
Agent
subagent_type: "general-purpose" # model rung; an agent rung uses the rung's agent
model: "<test-runner rung alias — contracts/models.md>" # omit entirely on an agent rung
description: "Run test suite"
prompt: "Run: [test command for this project]. Report pass/fail counts and any failures. Make no edits."
Agent
subagent_type: "general-purpose"
model: "<test-runner tier — see contracts/models.md>"
description: "Run test suite"
prompt: "Run: [test command for this project]. Report pass/fail counts and any failures. Make no edits."
ALL tests must still pass.
If tests fail: undo only what this step changed, never the whole tree.
This only works from a clean baseline. Step 1 requires green tests and Step 5 commits after every
green change, so at the start of each step HEAD matches the worktree and is your floor. If the
tree was already dirty when the step began, stop and report — you cannot separate your edits
from the pre-existing ones.
HEAD):
git restore --source=HEAD --worktree -- path/one path/twoHEAD entry, so restore will not remove
them and will fail the whole command if you list one. Delete them individually instead.Name every path explicitly. git checkout -- . and git restore . discard every uncommitted
change in the worktree — including a concurrent worker's output when this refactoring runs inside
an executing-plans wave — and are unrecoverable.
Then:
Never proceed with failing tests.
Commit each safe transformation:
git add [changed files]
git commit -m "refactor: [one-sentence description of transformation]"
Why commit so often:
Repeat steps 3-5 for each small transformation. Track progress:
1. Extract validateEmail() → test → commit ✓
2. Extract validateName() → test → commit ✓
3. Move validations to new file → test → commit ✓
Pattern: change → test → commit (repeat)
After all transformations complete:
Agent
subagent_type: "general-purpose" # model rung; an agent rung uses the rung's agent
model: "<test-runner rung alias — contracts/models.md>" # omit entirely on an agent rung
description: "Run full test suite and linter"
prompt: "Run: [test command] && [lint command]. Report all results. Make no edits."
Agent
subagent_type: "general-purpose"
model: "<test-runner tier — see contracts/models.md>"
description: "Run full test suite and linter"
prompt: "Run: [test command] && [lint command]. Report all results. Make no edits."
Checklist:
Review the changes:
git log --oneline | head -10
git diff [start-sha]..HEAD
After final verification passes, invoke gambit:review:
Skill skill="gambit:review"
Do not skip review for "simple" refactorings. Do not tell the user to run it manually — invoke it and follow its process immediately. Review validates the refactoring didn't introduce regressions, security issues, or quality problems.
After review passes:
<!-- gambit-backend:claude -->
TaskUpdate
taskId: "[task-id]"
description: |
<!-- /gambit-backend -->
<!-- gambit-backend:codex -->
Present in the root checkpoint as the complete refactoring result:
<!-- /gambit-backend -->
## Completed
- [List of transformations made]
- All tests pass (verified)
- No behavior changes
- N small transformations, each tested
- Review: APPROVED
<!-- gambit-backend:claude -->
status: "completed"
<!-- /gambit-backend -->
After the checkpoint result and review evidence are present, use SessionPlanWrite only to replace the complete ordered plan and mark the single refactoring wave completed. Individual transformations are not plan steps.
Rule: If you need to change test assertions (not just add tests), you're rewriting, not refactoring.
If the user explicitly asks to batch changes or skip steps:
See REFERENCE.md for detailed good/bad examples including:
This skill requires:
gambit:test-driven-development to write tests first if none exist)gambit:verification (for final verification)contracts/models.md) for running testscontracts/executors.md and contracts/models.md) for running testsCalled by:
Calls:
gambit:test-driven-development (if tests need writing first)gambit:verification (final check)gambit:review (mandatory, after final verification passes)Workflow:
Want to improve code structure
↓
Step 1: Verify tests pass
↓
<!-- gambit-backend:claude -->
Step 2: Create Task
<!-- /gambit-backend -->
<!-- gambit-backend:codex -->
Step 2: Present complete workflow brief
<!-- /gambit-backend -->
↓