بنقرة واحدة
refactor
Full-workspace code quality analysis and refactoring with validation
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Full-workspace code quality analysis and refactoring with validation
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
| name | refactor |
| description | Full-workspace code quality analysis and refactoring with validation |
| user-invocable | true |
| allowed-tools | Read, Grep, Glob, Bash(cargo check*), Bash(cargo clippy*), Bash(cargo test*), Bash(cargo fmt*), Bash(cargo tree*), Bash(cargo audit*), Bash(cargo outdated*), Bash(cargo machete*), Bash(cargo deny*), Bash(cargo mutants*), Bash(cargo tarpaulin*), Bash(cargo udeps*), Bash(git status*), Bash(git diff*), Bash(git stash*), Bash(git log*), Bash(wc *), Bash(grep*), Edit, Write, Task |
Full-workspace code quality analysis and incremental refactoring with continuous validation.
This skill is intended for periodic whole-codebase refactoring passes, not per-branch or per-diff cleanup. It does not accept --diff / --staged / --since arguments.
Platform note: agents that support frontmatter permissions may use allowed-tools and user-invocable. Other agents should ignore unsupported fields and follow the workflow below. When platform-specific orchestration or memory features are unavailable, degrade gracefully and continue with the equivalent local workflow.
Arguments (optional):
/refactor crates/app — limit scope to one directoryAGENTS.md, CLAUDE.md, and PRD.md. Also read any project or agent memory/notes files if present for intentional_placeholder_*, feedback_*, or similar notes that inform what to skip.cargo clippy --workspace --all-targets 2>&1 — warning count.cargo test --workspace 2>&1 — green baseline? If tests fail or code doesn't compile, report and stop.wc -l — LOC per crate, files > 400 LOC.cargo tree -d — duplicated dependencies.cargo audit — CVE list. If severity ≥ Medium, flag but continue.cargo outdated --root-deps-only — major-behind deps.cargo machete — unused [dependencies] entries.cargo udeps — unused deps (secondary, if machete absent).git log --numstat --since="6 months ago" → top-10 files by churn (hotspot candidates for splitting).grep -rn "TODO\|FIXME\|HACK\|XXX" --include="*.rs" — from repo root, not from crates/ (see Rules below).grep -c "match\|if\|for\|while" on the ten largest .rs files.Analyze code across the categories below. For large scope, use parallel subagents or parallel analysis passes if the platform supports them, ideally one per category or related group of categories.
Architecture (SOLID)
match on types that are expected to grow.Legitimate exceptions to "1 file = 1 type": Error+ErrorKind pairs, Builder+Target, small private helpers (< 30 LOC), related DTO families (Request/Response), typestate marker types, newtype wrapper collections.
Module coupling / cohesion
pub — types/functions public without need (downgrade to pub(crate) / pub(super)).Duplication (DRY)
match patterns across different files.Dead code
crates/. Binary crate in src/ is a legitimate caller (previous incident with check_git_available / ram_usage_percent was caused by grepping only crates/).use, functions, types, constants.HIGH — unused private / pub(crate) in leaf module, no callers.MEDIUM — pub in inner crate, no callers found via grep.LOW — enum variant, trait impl, or item with #[allow(dead_code)] nearby — likely intentional placeholder.ForceSave, dead enum variants in vfs_state.rs/keyboard.rs, format_bytes x3, ConflictResolution x3 across layers).Performance
.clone() / .to_string() / .to_owned() where a reference suffices.Error boundaries
From / thiserror).unwrap() / expect() in production code — replace with ? or explicit handling..map_err(|_| ...) without information).Security
cargo audit / cargo deny check licenses output here (do not split into a separate step).fs::*(user_input_path) without canonicalize() + starts_with() check — path traversal risk.Command::new(user_input) or shell-expansion of user input — command injection.Style and idioms
#[must_use] on pure / builder methods.Concurrency (Rust-specific)
Arc<Mutex<T>> where locked guard is used mostly for reads (grep the ratio of .lock() read accesses vs mutations) — Arc<RwLock<T>> candidate..await inside a .lock() guard — deadlock risk.tokio::spawn without an abort handle for long-running tasks (leaks on shutdown).Send / Sync markers where the compiler would accept them.API stability
pub enum without #[non_exhaustive] on a cross-crate boundary.pub in a child module re-exported via pub use only for one caller — downgrade candidate to pub(crate).pub API without a version bump.Allocations / hot path (TUI-specific)
.to_string() / format! / Vec::new() / vec![] inside render_*, tick_*, draw_*, update_* functions.Arc<Config> pattern is used.Cow<str> candidates: functions taking &str that sometimes need an owned String.Testing quality
std::env::set_var, global state mutation inside #[test].#[ignore] without a comment explaining why.assert_eq! on a large struct).cargo-tarpaulin is available, highlight files with < 50%).Observability
println! / eprintln! in production code (not #[test] / examples) — should be log::*.let _ = <Result> — errors swallowed without log::warn!.Each finding gets two tags:
Impact: HIGH / MED / LOW
HIGH — > 100 LOC reduction OR removes a bug class OR unblocks a perf fix
MED — 20–100 LOC reduction OR consolidates a recurring pattern
LOW — < 20 LOC OR stylistic
Risk: SAFE / CAREFUL / BREAKING
SAFE — private internals, no API surface change, covered by tests
CAREFUL — pub(crate) API, hot path, thread boundary
BREAKING — pub API, schema/config format, semantic change
Default execution order: HIGH-SAFE → MED-SAFE → HIGH-CAREFUL → LOW-SAFE → MED-CAREFUL. BREAKING findings are shown but never executed without explicit user approval.
Output format (terminal, do not create report files):
## Findings (ROI-sorted)
### 🟢 HIGH-SAFE (execute automatically)
1. **<short title>** — path/to/file.rs, path/to/other.rs
Why: <one-sentence justification + evidence>.
Effort: ~N min · Risk: SAFE (<reason>).
### 🟡 MED-CAREFUL (propose, require approval)
2. **<short title>** — path/to/file.rs
Why: …
Effort: ~N min · Risk: CAREFUL (<reason>).
### 🔴 BREAKING (report only, do not execute)
3. …
### 📦 Ecosystem
- cargo-audit: N advisories.
- cargo-outdated: N major-behind deps.
- cargo-machete: N unused crates.
- cargo-tarpaulin: workspace coverage X% (only if available).
## Category counts
| Category | Found | HIGH | MED | LOW |
|--------------|------:|-----:|----:|----:|
| Architecture | … | … | … | … |
| … | … | … | … | … |
Baseline: X clippy warnings, Y workspace LOC, Z tests passing.
Auto-mode:
HIGH-SAFE and MED-SAFE findings.CAREFUL and BREAKING in the report for the user to review.Non-auto:
SAFE findings preselected when supported.For each fix:
Edit.cargo check — still compiles?cargo test --workspace.On compilation or test failure — revert the change and move on.
Commit boundaries: do not auto-commit. Let the user review the final diff and commit.
cargo fmt --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace
Compare with baseline: warnings removed, LOC deleted/changed, tests still green.
crates/. Binary crate in src/ is a legitimate caller.intentional_placeholder_* entries and skip those silently.cargo-machete, cargo-mutants, cargo-audit, etc.) is not in PATH, emit an info line and continue — do not fail.BREAKING findings are reported but never executed without explicit user consent.SAFE actions.