원클릭으로
refactor-guide
Refactor safely — keep tests green, change structure without behavior change, no public API breakage. Use for code maintenance.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Refactor safely — keep tests green, change structure without behavior change, no public API breakage. Use for code maintenance.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Optimize token usage and context window discipline. Reduce costs and improve response quality through smart context management.
Unified context lifecycle for FlowDeck sessions — ingest, filter, prune, protect, summarize, and persist with telemetry.
Predict affected files, modules, APIs, tests, and DB paths before changes. Returns an impact map for human review.
Map architecture, conventions, and file structure into `.codebase/`. Use when onboarding or before deep feature work.
Plan differently when the agent has low certainty — ask for clarification or narrow scope instead of pretending full understanding.
Protect critical context from pruning during compaction. Preserve active plans, safety files, pending operations, and user intent anchors.
| name | refactor-guide |
| description | Refactor safely — keep tests green, change structure without behavior change, no public API breakage. Use for code maintenance. |
| origin | FlowDeck |
Changes structure without changing behavior. One transformation at a time. Tests must stay green throughout.
Activate when:
1. npm test → must be GREEN before starting
2. Apply ONE transformation
(extract function, rename, move module — one thing only)
3. npm test → must still be GREEN
4. git commit -m "refactor: [description]"
5. Repeat from step 2
// ❌ Before — inline, hard to test independently
function createOrder(items: Item[], userId: string) {
if (!items || items.length === 0) {
throw new Error('Order must have items');
}
const total = items.reduce((s, i) => s + i.price * i.qty, 0);
if (total > 10000) {
throw new Error('Order total exceeds limit');
}
// ... save to DB
}
// ✅ After — each function has a single responsibility
function validateOrderItems(items: Item[]): void {
if (!items || items.length === 0) {
throw new Error('Order must have items');
}
}
function calculateOrderTotal(items: Item[]): number {
return items.reduce((s, i) => s + i.price * i.qty, 0);
}
function assertTotalWithinLimit(total: number): void {
if (total > 10000) throw new Error('Order total exceeds limit');
}
function createOrder(items: Item[], userId: string) {
validateOrderItems(items);
const total = calculateOrderTotal(items);
assertTotalWithinLimit(total);
// ... save to DB
}
// ❌ Before — magic numbers and complex expression
if (user.createdAt < Date.now() - 30 * 24 * 60 * 60 * 1000) { ... }
// ✅ After — named intent
const THIRTY_DAYS_MS = 30 * 24 * 60 * 60 * 1000;
const accountAge = Date.now() - user.createdAt;
const isNewUser = accountAge < THIRTY_DAYS_MS;
if (isNewUser) { ... }
## Refactor Summary
### Transformations (in order applied)
1. Extracted `validateOrderItems()` — order.ts:23-28
2. Extracted `calculateOrderTotal()` — order.ts:29-31
3. Renamed `getData()` → `fetchUserProfile()` — 4 files
### Before/After
- order.ts: 180 lines → 120 lines
- 2 new unit tests for extracted functions
### Test Results
- Before: 45 tests passing
- After: 47 tests passing