code-structure-cleanup
Use when a working feature has duplicated mechanics, repeated API calls, inconsistent parsing or validation, messy helpers, or structure that will make review or future agent work harder.
- License 许可
- MIT
- 最近更新
- 2026-08-24
- Stars
- ★ 17
- Forks
- 1
01 前言 Front Matter
- name
- code-structure-cleanup
- description
- Use when a working feature has duplicated mechanics, repeated API calls, inconsistent parsing or validation, messy helpers, or structure that will make review or future agent work harder.
02 资源文件 7
- 资产文件assets/poster_html_template.html5.5 KB
- 资产文件assets/poster_quality_checklist.md10.9 KB
- 参考文档references/poster_content_guide.md19.9 KB
- 参考文档references/poster_design_principles.md22.4 KB
- 参考文档references/poster_layout_design.md21.8 KB
- 脚本scripts/generate_schematic_ai.py31.0 KB
- 脚本scripts/generate_schematic.py5.0 KB
03 SKILL.md 正文
Code Structure Cleanup
Overview
Run this after a feature works, before review. The goal is a behavior-preserving cleanup pass that reduces duplicated runtime mechanics and makes the changed area easier for humans and agents to understand.
This is not a redesign pass. Keep the scope tied to the feature and keep the diff small.
When to Use
Use when:
- A feature works locally but the code feels duplicated, messy, or hard to review.
- Similar helper functions, API calls, parsing, validation, or transformations were added in multiple places.
- Calling files contain mechanics that would be clearer behind a reusable module.
- Future agents are likely to copy the messy pattern because it is now the easiest thing to find.
Do not use when:
- The feature does not work yet.
- The requested change is a new feature, not cleanup.
- The only issue is formatting.
- The cleanup would require redesigning unrelated parts of the app.
Core Rule
This is a behavior-preserving cleanup pass.
Do not add features, change UX, alter API contracts, change data shapes, move business decisions, or modify user-facing behavior. If preserving behavior is uncertain, stop and investigate before editing.
Service Layer Boundary
A service layer is a place for reusable mechanics:
- sending an email,
- streaming an AI response,
- creating a sandbox,
- validating a webhook,
- calling an external API,
- transforming a payload,
- parsing or normalizing data.
The route, action, component, command, or job decides what should happen. The service handles how it happens.
Services should not decide permissions, pricing, workflow branching, feature flags, product policy, or user-facing business rules unless the existing architecture already puts that policy in a service.
Cleanup Process
Before editing, identify the duplication inventory:
- repeated mechanic,
- files involved,
- proposed extraction,
- why this extraction is smaller and clearer than leaving the duplication,
- validation command that will prove behavior was preserved.
Then:
- Inspect only the feature-touched area plus directly related shared modules.
- Name the repeated mechanic clearly.
- Extract the smallest reusable function or module that removes the repetition.
- Keep domain policy in the caller.
- Update callers without renaming unrelated concepts.
- Run the narrowest relevant tests, typecheck, lint, or build.
- Summarize exactly what got simpler.
Extraction Test
Do not extract code just because two snippets look similar. Extract only when the repeated logic represents the same runtime mechanic and has the same reason to change.
Good extraction:
- Four routes each build and send the same email payload with minor drift. Create one email service and keep each route's decision to send the email in the route.
Bad extraction:
- Two flows both check
status === "active", but one is billing policy and the other is UI display logic. The snippets look similar, but they do not have the same reason to change.
Common Pitfalls
| Pitfall | Correction |
|---|---|
| Refactoring the whole app | Stay inside the feature area. |
| Renaming everything | Avoid naming churn unless a name blocks understanding. |
| Mixing cleanup with new behavior | Make cleanup a separate pass. |
| Only formatting code | Reduce duplicated mechanics, not just whitespace. |
| Moving policy into services | Keep business decisions in the caller unless the existing architecture says otherwise. |
| Creating a vague abstraction | Prefer a concrete, searchable service name tied to the mechanic. |
Final Response Format
Report:
- Repeated mechanics removed:
- New or changed service modules:
- Calling files simplified:
- Behavior-preservation evidence:
- Validation run:
- Risks or follow-up:
If no safe extraction exists, say so and explain why duplication is preferable for now.
Verification Checklist
- [ ] User-facing behavior stayed the same.
- [ ] Repeated mechanics were actually reduced.
- [ ] Calling files became simpler.
- [ ] Domain policy stayed in the caller.
- [ ] The diff stayed focused on the feature area.
- [ ] Relevant tests, typechecks, linters, or builds ran.
- [ ] Missing test coverage or residual risk was reported clearly.
04 同仓库更多 Skills
1password-developer
Work with 1Password developer features including SSH key management, the SSH agent, 1Password Environments for secrets injection, and the op CLI. Use this skill whenever the user mentions 1Password, op CLI, 1Password SSH agent, 1Password Environments, secret references, op run, op inject, or wants to manage SSH keys through 1Password, secure .env files with 1Password, or inject secrets at runtime. Also trigger when the user wants to stop storing plaintext secrets on disk or asks about securing developer credentials.
plan-reviewer
Use when creating, refining, or reviewing implementation plans, migration plans, refactoring proposals, feature plans, implementation trackers, or committable phase plans; especially when turning a rough plan into executable phases or checking whether a plan is concrete, testable, safe, dependency-aware, and suitable for parallel work.
brainstorm
Interview the user relentlessly about a plan or design until reaching shared understanding, resolving each branch of the decision tree. Use when user wants to stress-test a plan, get grilled on their design, or mentions "brainstorm".
youtube-video-context
Use this skill whenever the user gives a YouTube URL and asks to summarize, digest, analyze, extract transcript/context, decide whether a video is worth watching, or understand what a video is about. Prefer the summarize CLI for YouTube/video context instead of web search. Use Codex as the default summarize backend when possible, and use the local Whisper large-v3 model for transcription fallback. Do not use this for ordinary web pages; use the installed web-access tools for webpage research.
thermos
Launch both thermo-nuclear review subagents in parallel. Use for thermos, double thermo review, or combined bug/security and code-quality branch audits.
thermo-nuclear-review
Comprehensive security and correctness audit of a branch's changes. Use for thermo nuclear, thermonuclear, or deep review requests, or branch/PR diff audits focused on bugs, breaking changes, security issues, devex regressions, and feature-gate leaks.