- Implement internal maintenance suite: repo-maintainer agent and automated audit/sync scripts. - Add "Opencode Configurator" suite: agent-architect, command-creator, and skill-creator. - Refactor core commands (/improve, /refactor, /rmslop) to RFC 2119 + XML standards. - Standardize all agent metadata and structural tagging across the repository. - Introduce utility commands: /npm for package management and /create-pack for bundling. - Overhaul README.md and documentation to reflect new workflow patterns.
3.0 KiB
description
| description |
|---|
| Refactor code and structure |
Refactor the following targets: $ARGUMENTS
<question_tool>
Batching Rule: Use only for 2+ related questions; single questions use plain text.
Syntax Constraints: header max 12 chars, labels 1-5 words, mark defaults with (Recommended).
Purpose: Clarify targets (session files/largest/specific) and priority (modularity/hygiene/both) when $ARGUMENTS is empty or ambiguous.
</question_tool>
Initial Clarification (if targets unclear)
If $ARGUMENTS is empty or ambiguous, use the question tool:
{
"questions": [
{ "question": "What should I refactor?", "header": "Targets", "options": [
{ "label": "Files from this session", "description": "Refactor code created/modified recently" },
{ "label": "Largest files (Recommended)", "description": "Find and refactor 250+ line files" },
{ "label": "Let me specify", "description": "I'll provide specific file paths" }
]},
{ "question": "What's the priority?", "header": "Focus", "options": [
{ "label": "Modularity", "description": "Split large files, improve structure" },
{ "label": "Code hygiene", "description": "Remove slop, fix types, clean comments" },
{ "label": "Both (Recommended)", "description": "Full refactor treatment" }
]}
]
}
If user provided specific file paths, proceed directly.
Context: If no targets are specified above, identify and refactor files created within this session, or scan for worst offenders in the codebase - normally, it's the files with 250+ lines of code.
Objective: Modularise and clean up the code according to these strict standards.
1. File Structure & Modularity
- Small Files: Break large files into focused, single-purpose modules.
- Barrel Exports: Use
index.tsfiles to cleanly expose public APIs from directories. - File Headers: Every file MUST start with a non-verbose 2-3 sentence block comment explaining its specific purpose - no generic headers allowed.
/** * utils/formatting.ts * Provides currency and date formatting utilities for the billing dashboard. * Handles locale detection and fallback states. */
2. Code Hygiene ("No Slop")
- Remove Emojis: Delete ALL emojis from comments, strings, and UI text unless strictly necessary for the feature.
- Concise Comments: Remove "chatty" or redundant comments. Comment ONLY major sections or complex logic.
- No Defensive Clutter: Remove excessive
try/catchor defensive checks (likeif (obj && obj.prop)) if the data path is trusted or already validated. - Type Safety: Strictly no
anycasts. Fix the types.
3. Core Principles
- DRY: If you see a pattern twice, abstract it.
- Fail Fast: Throw errors clearly; do not hide them.
- No Console Logs: Remove
console.logentirely.
Execution:
- Analyze the files against these rules.
- Refactor to improve structure (splitting files if needed).
- Clean up the code (remove slop, add headers, fix types).