xiaohongshu
xiaohongshu
audit-refactoring
Run a single-session refactoring audit on the codebase
Full skill instructions
Step 0: Episodic Memory Search (Session #128)
Before running refactoring audit, search for context from past sessions:
// Search for past refactoring audit findings
mcp__plugin_episodic -
memory_episodic -
memory__search({
query: ["refactoring audit", "god object", "complexity"],
limit: 5,
});
// Search for specific tech debt discussions
mcp__plugin_episodic -
memory_episodic -
memory__search({
query: ["cognitive complexity", "duplicate code", "circular"],
limit: 5,
});
Why this matters:
Step 1: Check Thresholds
Run npm run review:check and report results.
Step 2: Gather Current Baselines
Collect these metrics by running commands:
# SonarQube issues (if manifest exists)
cat docs/analysis/sonarqube-manifest.md 2>/dev/null | head -30 || echo "No SonarQube manifest"
# Circular dependencies
npm run deps:circular 2>&1
# Unused exports
npm run deps:unused 2>&1 | head -30
# Large files (potential god objects)
find app components lib -name "*.ts" -o -name "*.tsx" 2>/dev/null | xargs wc -l 2>/dev/null | sort -n | tail -20
# Duplicate code patterns
grep -rn "TODO\|FIXME\|HACK" --include="*.ts" --include="*.tsx" 2>/dev/null | wc -l
Step 2b: Query SonarCloud for Cognitive Complexity (if MCP available)
If mcp__sonarcloud__get_issues is available:
types: "CODE_SMELL" and severities: "CRITICAL" to get cognitive
complexity violationsThis provides real-time cognitive complexity data for targeted refactoring.
Step 3: Load False Positives Database
Read docs/audits/FALSE_POSITIVES.jsonl and filter findings matching:
refactoringexpires date passed)Note patterns to exclude from final findings.
Step 4: Check Template Currency
Read docs/templates/MULTI_AI_REFACTORING_PLAN_TEMPLATE.md and verify:
If outdated, note discrepancies but proceed with current values.
Focus Areas (5 Categories):
For each category:
Refactoring Targets:
Scope:
app/, components/, lib/, hooks/, functions/node_modules/, .next/, docs/All findings MUST include:
lib/utils.ts:45)Confidence Levels:
S0/S1 findings require:
Before finalizing findings, cross-reference with:
docs/audits/single-session/refactoring/ for
duplicate findingsFindings without tool validation should note: "cross_ref": "MANUAL_ONLY"
For all S0 (blocking) and S1 (major friction) findings:
Document dual-pass result in finding: "verified": "DUAL_PASS_CONFIRMED" or
"verified": "DOWNGRADED_TO_S2"
1. Markdown Summary (display to user):
## Refactoring Audit - [DATE]
### Baselines
- SonarQube CRITICAL: X issues
- Circular dependencies: X
- Unused exports: X
- Files > 300 lines: X
- TODO/FIXME/HACK markers: X
### Findings Summary
| Severity | Count | Category | Confidence |
| -------- | ----- | -------- | ----------- |
| S0 | X | ... | HIGH/MEDIUM |
| S1 | X | ... | HIGH/MEDIUM |
| S2 | X | ... | ... |
| S3 | X | ... | ... |
### Top Refactoring Candidates
1. [file] - X lines, Y responsibilities (S1/E2) - DUAL_PASS_CONFIRMED
2. ...
### False Positives Filtered
- X findings excluded (matched FALSE_POSITIVES.jsonl patterns)
### Quick Wins (E0-E1)
- ...
### Batch Fix Opportunities
- X instances of [pattern] can be auto-fixed
- ...
### Recommendations
- ...
2. JSONL Findings (save to file):
Create file: docs/audits/single-session/refactoring/audit-[YYYY-MM-DD].jsonl
CRITICAL - Use JSONL_SCHEMA_STANDARD.md format:
{
"category": "refactoring",
"title": "Short specific title",
"fingerprint": "refactoring::path/to/file.ts::identifier",
"severity": "S0|S1|S2|S3",
"effort": "E0|E1|E2|E3",
"confidence": 90,
"files": ["path/to/file.ts:123"],
"why_it_matters": "1-3 sentences explaining refactoring need",
"suggested_fix": "Concrete refactoring direction",
"acceptance_tests": ["Array of verification steps"],
"evidence": ["code structure info", "wc -l output", "deps:circular output"],
"symbols": ["ClassName", "functionName"],
"duplication_cluster": {
"is_cluster": true,
"cluster_summary": "Pattern description",
"instances": [{ "file": "path1.ts", "symbol": "name" }]
}
}
For S0/S1 findings, ALSO include verification_steps:
{
"verification_steps": {
"first_pass": {
"method": "grep|tool_output|file_read|code_search",
"evidence_collected": ["initial evidence"]
},
"second_pass": {
"method": "contextual_review|exploitation_test|manual_verification",
"confirmed": true,
"notes": "Confirmation notes"
},
"tool_confirmation": {
"tool": "sonarcloud|typescript|patterns_check|NONE",
"reference": "Tool output or NONE justification"
}
}
}
⚠️ REQUIRED FIELDS (per JSONL_SCHEMA_STANDARD.md):
category - MUST be refactoring (normalized from
GodObject/Duplication/etc.)fingerprint - Format: <category>::<primary_file>::<identifier>files - Array with file paths (include line as file.ts:123)confidence - Number 0-100 (not string)acceptance_tests - Non-empty array of verification steps3. Markdown Report (save to file):
Create file: docs/audits/single-session/refactoring/audit-[YYYY-MM-DD].md
Full markdown report with all findings, baselines, and refactoring plan.
Before finalizing the audit:
Run Validation Script:
node scripts/validate-audit.js docs/audits/single-session/refactoring/audit-[YYYY-MM-DD].jsonl
Validation Checks:
If validation fails:
docs/audits/single-session/refactoring/node scripts/validate-audit.js on the JSONL filenpm run validate:canon
Ensure all CANON files pass validation before committing.node scripts/debt/intake-audit.js docs/audits/single-session/refactoring/audit-[YYYY-MM-DD].jsonl --source "audit-refactoring-[DATE]"
This assigns DEBT-XXXX IDs and adds to
docs/technical-debt/MASTER_DEBT.jsonl. See
docs/technical-debt/PROCEDURE.md for the full TDMS workflow.This audit resets the refactoring category threshold in
docs/AUDIT_TRACKER.md (single-session audits reset their own category;
multi-AI audits reset all thresholds). Reset means the commit counter for this
category starts counting from zero after this audit.
Refactoring audit triggers (check AUDIT_TRACKER.md):
After 3 single-session refactoring audits, a full multi-AI Refactoring Audit is recommended. Track this in AUDIT_TRACKER.md "Single audits completed" counter.
If you encounter a pattern that should be excluded from future audits:
node scripts/add-false-positive.js \
--pattern "regex-pattern" \
--category "refactoring" \
--reason "Explanation of why this is intentional complexity" \
--source "AI_REVIEW_LEARNINGS_LOG.md#review-XXX"
Before running this audit, review:
node scripts/debt/intake-audit.js <output.jsonl> --source "audit-refactoring-<date>"xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience