بنقرة واحدة
refactor
Restructure code without changing external behavior — extract, rename, split, move
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Restructure code without changing external behavior — extract, rename, split, move
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
Evaluate workflow run quality by analyzing artifacts and scratch outputs, identify gaps and root causes, and write a structured assessment with actionable recommendations.
Write an Architecture Decision Record (ADR) for a technical decision
Diagnose a bug, identify root cause, implement a targeted fix, and verify it
Analyze requirements and produce a detailed implementation plan before writing code
Create a GitHub branch, commit changes to it, and open a pull request
Explore a newly-loaded workspace, map its structure, and write project notes to memory
استنادا إلى تصنيف SOC المهني
| name | refactor |
| description | Restructure code without changing external behavior — extract, rename, split, move |
Core discipline: Change structure. Never change behavior. Prove the contract is unchanged after every transform.
| Transform | What changes | What must NOT change |
|---|---|---|
| Extract function | A block of code becomes a named function | Return value, side effects |
| Inline variable | A single-use variable replaced by its value | Readability, behavior |
| Rename symbol | Name of a function/variable/file | All call sites updated consistently |
| Split file | One file becomes two or more modules | All exports still reachable from original path |
| Move to module | Code relocated to a different file | Import paths updated everywhere |
| Extract constant | Magic literal becomes a named constant | Same value used everywhere |
const filePath = '/src/path/to/file.js';
const source = context.vfs.read(filePath);
if (!source) {
context.emit({ type: 'blocked', reason: `${filePath} not found` });
return;
}
context.emit({ type: 'file_read', path: filePath });
// Capture current public surface before touching anything
const exportsBefore = (source.match(/^export\s+/gm) ?? []).length;
context.emit({ type: 'progress', message: `${exportsBefore} exports before refactor` });
Do not combine transforms in one turn. One change, fully applied, fully verified.
// Example: extract a function
const refactored = source
// Remove the inline block
.replace(/\/\/ <target block start>[\s\S]*?\/\/ <target block end>/,
'return extractedFn(args);')
// This is illustrative — always do the real substitution carefully
;
// Prepend the new function above the call site
const withExtracted = 'function extractedFn(args) {\n // extracted body\n}\n\n' + refactored;
const exportsAfter = (withExtracted.match(/^export\s+/gm) ?? []).length;
if (exportsAfter !== exportsBefore) {
context.emit({ type: 'blocked',
reason: `Export count changed: ${exportsBefore} → ${exportsAfter}. Aborting.` });
return;
}
// Check all existing export names are still present
const exportNamesBefore = [...source.matchAll(/^export\s+(?:function|const|class|async function)\s+(\w+)/gm)]
.map(m => m[1]);
for (const name of exportNamesBefore) {
if (!withExtracted.includes(name)) {
context.emit({ type: 'blocked', reason: `Export "${name}" missing after refactor. Aborting.` });
return;
}
}
context.vfs.write(filePath, withExtracted);
context.emit({ type: 'file_write', path: filePath });
context.emit({ type: 'result', value: {
transform: 'extract-function',
file: filePath,
exports_before: exportsBefore,
exports_after: exportsAfter,
contract_preserved: true,
}});
context.emit({ type: 'done', message: `Refactor complete: extracted function in ${filePath}` });
done if the export contract changed// Find all files that import the symbol being changed
const allFiles = context.vfs.list().filter(p => p.startsWith('/src/') && p.endsWith('.js'));
const affected = allFiles.filter(p => {
const content = context.vfs.read(p);
return content && content.includes('oldName');
});
context.emit({ type: 'progress', message: `${affected.length} files import 'oldName'` });
// Update each one
for (const p of affected) {
const updated = context.vfs.read(p).replaceAll('oldName', 'newName');
context.vfs.write(p, updated);
context.emit({ type: 'file_write', path: p });
}