refactor — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited refactor (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
Systematic workflow for safe, incremental code refactoring with continuous test validation.
1. ANALYZE Read files, identify issues
2. PLAN Create TodoWrite task list
3. EXECUTE Make changes one at a time
4. VALIDATE Run tests after each change
5. REPORT Summary of improvementsRead all files in scope. For a single file:
Read /path/to/target/file.tsFor a module/directory, use Glob first:
Glob pattern="**/*.ts" path="/path/to/module"Then read each relevant file.
Check for these common issues:
Structural Issues:
TypeScript/JavaScript Specific:
any types that should be specificReact Specific:
Python Specific:
General:
Identify which tests cover the target code:
# TypeScript/React (Vitest)
cd /path/to/project && npm run test -- --reporter=verbose --run
# Python (Pytest)
cd /path/to/project && pytest --collect-only -qNote: If no tests exist, create them first before refactoring.
Create granular, reversible tasks ordered by risk (lowest risk first):
TodoWrite:
- [ ] 1. Extract constants: Move magic strings to CONSTANTS object
- [ ] 2. Add types: Replace `any` with proper interfaces
- [ ] 3. Extract function: Move validation logic to validateInput()
- [ ] 4. Rename: userInfo -> currentUser for clarity
- [ ] 5. Split component: Extract UserAvatar from UserProfile
- [ ] 6. Add error boundary: Wrap async operations
- [ ] 7. Memoize: Add useMemo for filtered list computationTask Ordering Principles:
Determine the correct test command for validation:
# Dashboard (Vitest)
cd dashboard && npm run test
# MCP Server (Pytest)
cd mcp_server && pytest
# Scripts (tsx)
cd scripts && npx tsx --test
# Specific file tests
npm run test -- path/to/file.test.ts
pytest tests/test_specific.py -vExecute the first unchecked task using Edit tool:
Edit:
file_path: /path/to/file.ts
old_string: |
const x = "hardcoded-value";
new_string: |
const CONFIG = { API_URL: "hardcoded-value" } as const;
const x = CONFIG.API_URL;Edit Best Practices:
old_string to be uniquereplace_all: true only for rename operationsAfter EVERY change, run the test suite:
cd /path/to/project && npm run testIf tests pass:
If tests fail:
TodoWrite:
- [x] 1. Extract constants: Move magic strings to CONSTANTS object
- [ ] 2. Add types: Replace `any` with proper interfaces
...Continue Steps 3.1-3.3 for each task until all complete.
Run full test suite:
npm run test # Unit tests
npm run e2e # E2E tests (if available)
npm run lint # Linting
npm run typecheck # TypeScript (tsc --noEmit)Use git diff to review all changes:
git diff path/to/refactored/file.tsVerify:
Provide summary:
## Refactoring Complete
**File:** `/path/to/file.ts`
**Changes Made:**
1. Extracted 5 magic strings to CONFIG constant
2. Added TypeScript interfaces for API responses
3. Split 80-line function into 3 focused functions
4. Renamed variables for clarity (userInfo -> currentUser)
**Metrics:**
- Lines: 245 -> 198 (-19%)
- Functions: 3 -> 6 (smaller, focused)
- Type coverage: 60% -> 95%
- Cyclomatic complexity: Reduced
**Tests:** All passing (12 tests)User: "Refactor dashboard/src/hooks/useWallet.ts"
Step 1: Read the file
Read /mnt/z/ultravioleta/dao/execution-market/dashboard/src/hooks/useWallet.tsStep 2: Analyze and create tasks
TodoWrite:
- [ ] 1. Extract SUPPORTED_CHAINS constant
- [ ] 2. Add WalletState interface for return type
- [ ] 3. Extract connectWallet logic to separate function
- [ ] 4. Add proper error types (WalletError class)
- [ ] 5. Memoize chain switching logicStep 3: Execute first task
Edit file_path=/mnt/z/.../useWallet.ts
old_string="const chains = [1, 8453, ..."
new_string="const SUPPORTED_CHAINS = [1, 8453, ..."Step 4: Run tests
cd /mnt/z/ultravioleta/dao/execution-market/dashboard && npm run testStep 5: Mark complete, continue
TodoWrite:
- [x] 1. Extract SUPPORTED_CHAINS constant
- [ ] 2. Add WalletState interface...Repeat until all tasks complete.
STOP refactoring and consult user if:
Dashboard (React + TypeScript):
cd dashboard && npm run testcd dashboard && npx tsc --noEmitsrc/hooks/, services in src/services/MCP Server (Python + FastAPI):
cd mcp_server && pytestcd mcp_server && mypy .Scripts (TypeScript + viem):
cd scripts && npm run test (if available)~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.