OSS Refactor
Harden structure and style with the smallest credible set of changes. Preserve behavior, avoid vanity renames, and prefer extension of existing tooling over toolchain replacement.
Context: $ARGUMENTS
Input Contract
- Primary input:
OSS_PLAN.md or a selected subset of plan items.
- Secondary input: current repo manifests and existing formatter/linter/type-check configuration.
- Default: if no explicit scope is given, work on the highest-priority refactor items from
OSS_PLAN.md.
Output Contract
Produce:
- The requested code/config changes.
- Minimal tooling configuration additions or updates.
OSS_REFACTOR.md summarizing:
- selected scope
- tooling choices and why
- touched paths
- commands run
- rollback notes if any change should be reconsidered
The final summary in OSS_REFACTOR.md must include "Changed now" vs "Deferred intentionally".
Non-goals
- Do not rename files, functions, or modules just for style consistency.
- Do not reformat the entire repository if only a few files changed.
- Do not introduce multiple new tools when one lightweight tool is enough.
- Do not alter public behavior unless the plan explicitly calls for it.
Tool Selection Rules
Prefer existing repo choices first. If the repo has nothing yet, choose the lightest credible option:
- Python:
- Format/lint: prefer
ruff format + ruff check.
- Type check: add
mypy only if the repo already has meaningful annotations or the plan explicitly asks for it.
- If no external deps are acceptable, document the recommendation and limit code changes to structure only.
- TypeScript:
- Format:
prettier.
- Lint:
eslint.
- Type check:
tsc --noEmit.
- JavaScript:
- Reuse existing package scripts; avoid bolting on TypeScript just for hardening.
- Go:
- Rust:
cargo fmt --check, cargo clippy, cargo test.
- Shell:
- Prefer existing script style.
- If no toolchain exists, use
bash -n or sh -n validation before adding extra tools.
Workflow
Step 1: Confirm the minimum viable scope
- Read the relevant audit and plan items.
- Identify the exact files and boundaries touched by the refactor.
- If the request is vague, limit work to the smallest set that unlocks tests or CI.
Step 2: Detect current toolchain
- Reuse existing manifests, scripts, config files, and editor conventions.
- Extend existing commands before inventing new top-level entry points.
Step 3: Apply structural hardening
Examples of valid refactor targets:
- isolate side effects behind small functions
- split a monolithic script into one tiny reusable module plus a thin CLI
- centralize duplicated config/constants
- add explicit exit codes and error messages
- introduce a minimal formatter/linter config
Examples of invalid churn:
- wholesale file moves with no reliability gain
- blanket rename campaigns
- repo-wide style rewrites unrelated to changed code
Step 4: Verify locally
- Run the narrowest relevant commands after every meaningful change.
- Prefer touched-file formatting/linting when possible.
- Record commands and outcomes in
OSS_REFACTOR.md.
Anti-patterns
- Do not modify files outside the planned change list.
- Do not do repo-wide formatting, rename sweeps, or directory churn unrelated to the selected scope.
- Do not add multiple new tools when one light tool or existing tooling is enough.
- Do not allow behavior changes to slip in under the label of "refactor".
Self-check
Before declaring this stage complete, verify:
Failure Handling
- If tooling installation is heavy or conflicts with the repo, stop after documenting the recommendation and keep code changes minimal.
- If a proposed refactor changes behavior, pause and either add tests first or roll back to the last safe structure.
- If hidden scope appears, update
OSS_REFACTOR.md and hand control back to /oss-plan instead of expanding silently.
Done Criteria
OSS_REFACTOR.md exists and lists selected scope, tooling choices, touched paths, commands run, and rollback notes.
- The artifact includes a
Changed now section and a Deferred intentionally section.
- All new tooling or config additions are minimal and explicitly justified.
1---2name: oss-refactor3description: Apply careful structure and style hardening to a repository without unnecessary churn. Use when the user says "refactor for maintainability", "set up linting/formatting/types", "clean up this repo", or wants the minimum structural changes needed to make a project easier to maintain.4---56# OSS Refactor78Harden structure and style with the smallest credible set of changes. Preserve behavior, avoid vanity renames, and prefer extension of existing tooling over toolchain replacement.910## Context: $ARGUMENTS1112## Input Contract1314- Primary input: `OSS_PLAN.md` or a selected subset of plan items.15- Secondary input: current repo manifests and existing formatter/linter/type-check configuration.16- Default: if no explicit scope is given, work on the highest-priority refactor items from `OSS_PLAN.md`.1718## Output Contract1920Produce:21221. The requested code/config changes.232. Minimal tooling configuration additions or updates.243. `OSS_REFACTOR.md` summarizing:25 - selected scope26 - tooling choices and why27 - touched paths28 - commands run29 - rollback notes if any change should be reconsidered3031The final summary in `OSS_REFACTOR.md` must include "Changed now" vs "Deferred intentionally".3233## Non-goals3435- Do not rename files, functions, or modules just for style consistency.36- Do not reformat the entire repository if only a few files changed.37- Do not introduce multiple new tools when one lightweight tool is enough.38- Do not alter public behavior unless the plan explicitly calls for it.3940## Tool Selection Rules4142Prefer existing repo choices first. If the repo has nothing yet, choose the lightest credible option:4344- Python:45 - Format/lint: prefer `ruff format` + `ruff check`.46 - Type check: add `mypy` only if the repo already has meaningful annotations or the plan explicitly asks for it.47 - If no external deps are acceptable, document the recommendation and limit code changes to structure only.48- TypeScript:49 - Format: `prettier`.50 - Lint: `eslint`.51 - Type check: `tsc --noEmit`.52- JavaScript:53 - Reuse existing package scripts; avoid bolting on TypeScript just for hardening.54- Go:55 - `gofmt`, `go vet`, `go test`.56- Rust:57 - `cargo fmt --check`, `cargo clippy`, `cargo test`.58- Shell:59 - Prefer existing script style.60 - If no toolchain exists, use `bash -n` or `sh -n` validation before adding extra tools.6162## Workflow6364### Step 1: Confirm the minimum viable scope6566- Read the relevant audit and plan items.67- Identify the exact files and boundaries touched by the refactor.68- If the request is vague, limit work to the smallest set that unlocks tests or CI.6970### Step 2: Detect current toolchain7172- Reuse existing manifests, scripts, config files, and editor conventions.73- Extend existing commands before inventing new top-level entry points.7475### Step 3: Apply structural hardening7677Examples of valid refactor targets:7879- isolate side effects behind small functions80- split a monolithic script into one tiny reusable module plus a thin CLI81- centralize duplicated config/constants82- add explicit exit codes and error messages83- introduce a minimal formatter/linter config8485Examples of invalid churn:8687- wholesale file moves with no reliability gain88- blanket rename campaigns89- repo-wide style rewrites unrelated to changed code9091### Step 4: Verify locally9293- Run the narrowest relevant commands after every meaningful change.94- Prefer touched-file formatting/linting when possible.95- Record commands and outcomes in `OSS_REFACTOR.md`.9697## Anti-patterns9899- Do not modify files outside the planned change list.100- Do not do repo-wide formatting, rename sweeps, or directory churn unrelated to the selected scope.101- Do not add multiple new tools when one light tool or existing tooling is enough.102- Do not allow behavior changes to slip in under the label of "refactor".103104## Self-check105106Before declaring this stage complete, verify:107108- [ ] `OSS_REFACTOR.md` exists and records selected scope, tooling choices, touched paths, commands run, and rollback notes if any.109- [ ] The artifact includes a `Changed now` section and a `Deferred intentionally` section.110- [ ] Any new tool or config added is explicitly justified in the artifact.111- [ ] Verification commands and outcomes are recorded after the final change set.112113## Failure Handling114115- If tooling installation is heavy or conflicts with the repo, stop after documenting the recommendation and keep code changes minimal.116- If a proposed refactor changes behavior, pause and either add tests first or roll back to the last safe structure.117- If hidden scope appears, update `OSS_REFACTOR.md` and hand control back to `/oss-plan` instead of expanding silently.118119## Done Criteria120121- `OSS_REFACTOR.md` exists and lists selected scope, tooling choices, touched paths, commands run, and rollback notes.122- The artifact includes a `Changed now` section and a `Deferred intentionally` section.123- All new tooling or config additions are minimal and explicitly justified.