brainstorming
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).
complexity-optimizerAnalyze a software codebase for algorithmic complexity and performance hotspots, then propose or implement safe optimizations without breaking behavior. Use when the user asks to scan many files, find inefficient loops, nested iteration, repeated scans, costly rendering/recomputation, N+1 queries, avoidable O(n^2) or O(n) operations, or reduce complexity su…
Independent GitHub snapshot · Automated classification · Original documentation governs
Find algorithmic complexity hotspots in a codebase and produce a structured report. Optionally implement low-risk optimizations after explicit consent.
Use this skill when the user asks to:
Do not use this skill for:
Baseline → Rank → Prove behavior → Optimize (opt-in) → Verify
↓ ↓ ↓
scanner prioritize hot rollback if
+ manual paths & large I/O tests regress
| Step | Action | Tool | Risk |
|---|---|---|---|
| 1 | Establish baseline: detect stack, test command, hot paths | scripts/analyze_complexity.py + manual inspection | read-only |
| 2 | Rank opportunities by impact, separating algorithmic wins from constant-factor cleanup | reasoning | read-only |
| 3 | Locate or add tests covering the function/component | Read + test framework | read-only |
| 4 | Apply optimization (ONLY when user explicitly requests) | Edit/Write | destructive |
| 5 | Run tests, lint, type-check, and a benchmark when warranted; report before/after complexity | Bash test commands | read-only |
Optimize only when current behavior is understood and can be preserved. Prefer a small, proven improvement with tests over a broad rewrite with unclear correctness.
When the user asks to analyze, scan, audit, review, or "give me a report" for a codebase, produce the full complexity report automatically. Do not require the user to specify report fields.
Default report contents (see references/report-template.md):
Only edit files when the user uses an explicit edit verb: implement, fix, optimize, apply, change, refactor. If the request is analysis-only or a report-only request, do not modify files.
python3 scripts/analyze_complexity.py <repo> for a first-pass hotspot list when scanning a repository.python3 scripts/analyze_complexity.py /path/to/repo --format markdown
python3 scripts/analyze_complexity.py /path/to/repo --format json
python3 scripts/analyze_complexity.py /path/to/repo --changed-only --base origin/main
--changed-only restricts the scan to files changed vs --base (default HEAD~1). Use it for PR-focused complexity review.
Language depth:
.py) — AST-based analysis. High precision: nested loops, sort/membership in loops, query/I/O in loops, all tracked per-function via the Python ast module..js, .ts, .jsx, .tsx, .java, .go, .rb, .php, .cs, .c, .cpp, .swift, .vue, .svelte, .kt, .rs, .dart, .scala) — regex-based pattern matching with indent + function-boundary heuristics. Treat findings as leads; verify by reading the surrounding code before recommending fixes.If the scanner reports nothing, still inspect known hot paths manually. Rendering churn, database query patterns, and framework lifecycle issues often need repository-specific context the scanner cannot see.
Exit codes: 0 = scanned successfully, 2 = bad input (non-existent path / file instead of directory / git error), 3 = zero files matched, 130 = interrupted.
Triage before reporting: consult references/false-positives.md to dismiss known noise patterns (single-call predicates, Redux selectors, SQL-builder fluent methods, render-derived work on small static arrays) before recommending fixes.
Testing the scanner: python3 scripts/test_analyze_complexity.py runs 13 regression tests that pin the false-positive fixes. Run after modifying the scanner.
Before editing:
After editing:
If the optimization breaks a test or changes observable behavior:
Revert the changed file(s) immediately:
git restore <file> # restore a single file
git restore -SW <file> # restore both index and working tree
If multiple files were modified: git restore -SW . (only within the affected directory).
Re-run the failing test to confirm restoration.
Report the failure to the user with:
Do not re-attempt the same optimization with a small tweak. If a transformation breaks behavior, either the data shape doesn't support it, or there's an unstated invariant — re-read the code before trying again.
references/optimization-playbook.md — common O(n^2) → O(n log n) / O(n) transformations, framework-specific patterns, and "What Not To Do".references/report-template.md — structure for the final analysis or audit output.references/false-positives.md — catalog of scanner findings that look real but aren't. Consult before recommending fixes.scripts/_sections.md — scanner invocation, flags, exit codes, and limitations.