Code Health Audit
Overview
Scores Python and .NET problems 0 to 10, reports them by severity, and offers each fix one at a time. Nothing is staged or committed.
Audit Sequence
- Scope:
git ls-files, or the path given. Leave out tests/, .specify/, wwwroot/lib/, node_modules/, Migrations/, .venv/, venv/ and generated or minified files.
- Working tree: if
git status --short shows modified files, ask You have uncommitted changes in <n> files; fixes will mix with them in the diff. Continue? [yes / no]
- Stacks: Python when
requirements*.txt, pyproject.toml or .py files exist; .NET when *.csproj, *.sln or *.slnx exist. Neither: reply No Python or .NET code found. This audit covers those two stacks. and stop.
- Baseline: run the CI workflow's lint, build and test commands, as
python -m .... No workflow: python -m flake8 . --count --select=E9,F63,F7,F82 --statistics; python -m pytest tests -q if tests/conftest.py exists or tests import pytest, else python -m unittest discover -s tests -t .; dotnet build; dotnet test. Record counts. If the .NET build fails, ask before continuing.
- Detection: in parallel, run
python "<skill base directory>/scripts/py_checks.py" <repo root> [path] and each module's Data Collection for the detected stacks. Missing tools, unreachable NuGet and py_checks NOT-CHECKED files go under Not checked.
- Reading: quick mode reads flagged lines, entry points (
bot.py, main.py, Program.cs) and config (config.py, appsettings.json). For "deep audit", first ask Deep audit reads <n> files (~<lines> lines). Continue? [yes / no], then read every file in scope.
- Findings: a hit becomes a finding only when reading confirms a Risk Indicator. Dead-code and comments findings are one per file.
| Module |
Fixes |
modules/bugs.md |
remediation/bugs-fixes.md |
modules/error-handling.md |
remediation/error-handling-fixes.md |
modules/concurrency.md |
remediation/concurrency-fixes.md |
modules/performance.md |
remediation/performance-fixes.md |
modules/duplication.md |
remediation/duplication-fixes.md |
modules/dead-code.md |
remediation/dead-code-fixes.md |
modules/dependencies.md |
remediation/dependencies-fixes.md |
modules/comments.md |
remediation/comments-fixes.md |
Scoring
| Factor |
Values |
| Impact |
outage, data loss or data exposure 1.0 · breaks 0.7 · degrades 0.4 · maintainability 0.1 |
| Likelihood |
normal use 1.0 · conditions 0.6 · rare 0.3 · future change 0.1 |
| Reach |
whole app 1.0 · one feature 0.7 · one user 0.4 |
Score = 10 × Impact × (0.5 + 0.5 × Likelihood) × (0.6 + 0.4 × Reach), one decimal. 9.0+ Critical · 7.0+ High · 4.0+ Medium · else Low. Vulnerable packages use the advisory: Critical 9.5, High 8.0, Moderate 5.5, Low 2.0.
Report Format
═══════════════════════════════════════════════════
CODE HEALTH AUDIT: <repo>
<date> | Mode: <quick|deep> | Modules: 8 | Findings: <n>
═══════════════════════════════════════════════════
BASELINE tests <n> passed · flake8 blocking <n> · build <result>
EXECUTIVE SUMMARY
Critical : <n> High : <n> Medium : <n> Low : <n>
Total risk score: <sum>
Not checked: <tools or files, when any>
─── <BAND> ──────────────────────────────────────────
[<score>] <title> (<module>)
<file>:<line> <one-line description>
Vector: <impact> / <likelihood> / <reach>
Fix available: <yes|no> <⚠ BEHAVIOR CHANGE when tagged>
Highest score first. Vulnerable packages show Vector: advisory: <severity>.
Fix Loop
Work down the report; skip findings with Fix available: no.
[<score>] <title> (<module>)
<file>:<line>
Change: <one sentence>
Files: <every file the fix touches>
Test: <test id> (fails now, passes after)
Apply this fix? [yes / no / skip-severity / stop]
yes: if Impact is 0.7+ and the baseline ran a test, write the test and confirm it fails (otherwise omit the Test line). Apply the remediation recipe, then run the test and python -m py_compile <files> or dotnet build.
no skips the finding, skip-severity skips the rest of the band, stop goes to the summary.
- For a ⚠ BEHAVIOR CHANGE fix, after
yes ask ⚠ <what changes>. Confirm? [yes / no]
- Failed check: undo that fix's own edits newest first, including its test, report the error, continue. Never retry,
git checkout or git stash.
- Change only what the finding covers; read only needed lines; comments follow
modules/comments.md; no helper scripts; never stage or commit.
Verification
Rerun the baseline commands, then print:
Remediation complete.
Fixed : <n> (risk reduced by <x> pts)
Skipped : <n> (still open: <scores>)
Failed : <n> (see errors above)
Tests : <n> added · <n> passed (baseline <n>)
Lint : flake8 blocking <n> (baseline <n>)
Build : <result> (baseline <result>)
Remaining risk score: <sum>
Changes are unstaged and uncommitted.
If a check that passed at baseline now fails, name the fixes that touched those files and ask Undo those fixes? [yes / no]. Note fixes without a test, or that no test suite exists.
1---2name: code-health-audit3description: Use when asked to run a code audit, code health check, code cleanup review, or a scan for improvements on the current repository4---56# Code Health Audit78## Overview910Scores Python and .NET problems 0 to 10, reports them by severity, and offers each fix one at a time. Nothing is staged or committed.1112## Audit Sequence13141. **Scope:** `git ls-files`, or the path given. Leave out `tests/`, `.specify/`, `wwwroot/lib/`, `node_modules/`, `Migrations/`, `.venv/`, `venv/` and generated or minified files.152. **Working tree:** if `git status --short` shows modified files, ask `You have uncommitted changes in <n> files; fixes will mix with them in the diff. Continue? [yes / no]`163. **Stacks:** Python when `requirements*.txt`, `pyproject.toml` or `.py` files exist; .NET when `*.csproj`, `*.sln` or `*.slnx` exist. Neither: reply `No Python or .NET code found. This audit covers those two stacks.` and stop.174. **Baseline:** run the CI workflow's lint, build and test commands, as `python -m ...`. No workflow: `python -m flake8 . --count --select=E9,F63,F7,F82 --statistics`; `python -m pytest tests -q` if `tests/conftest.py` exists or tests import pytest, else `python -m unittest discover -s tests -t .`; `dotnet build`; `dotnet test`. Record counts. If the .NET build fails, ask before continuing.185. **Detection:** in parallel, run `python "<skill base directory>/scripts/py_checks.py" <repo root> [path]` and each module's Data Collection for the detected stacks. Missing tools, unreachable NuGet and py_checks `NOT-CHECKED` files go under Not checked.196. **Reading:** quick mode reads flagged lines, entry points (`bot.py`, `main.py`, `Program.cs`) and config (`config.py`, `appsettings.json`). For "deep audit", first ask `Deep audit reads <n> files (~<lines> lines). Continue? [yes / no]`, then read every file in scope.207. **Findings:** a hit becomes a finding only when reading confirms a Risk Indicator. Dead-code and comments findings are one per file.2122| Module | Fixes |23|---|---|24| `modules/bugs.md` | `remediation/bugs-fixes.md` |25| `modules/error-handling.md` | `remediation/error-handling-fixes.md` |26| `modules/concurrency.md` | `remediation/concurrency-fixes.md` |27| `modules/performance.md` | `remediation/performance-fixes.md` |28| `modules/duplication.md` | `remediation/duplication-fixes.md` |29| `modules/dead-code.md` | `remediation/dead-code-fixes.md` |30| `modules/dependencies.md` | `remediation/dependencies-fixes.md` |31| `modules/comments.md` | `remediation/comments-fixes.md` |3233## Scoring3435| Factor | Values |36|---|---|37| Impact | outage, data loss or data exposure 1.0 · breaks 0.7 · degrades 0.4 · maintainability 0.1 |38| Likelihood | normal use 1.0 · conditions 0.6 · rare 0.3 · future change 0.1 |39| Reach | whole app 1.0 · one feature 0.7 · one user 0.4 |4041Score = 10 × Impact × (0.5 + 0.5 × Likelihood) × (0.6 + 0.4 × Reach), one decimal. 9.0+ Critical · 7.0+ High · 4.0+ Medium · else Low. Vulnerable packages use the advisory: Critical 9.5, High 8.0, Moderate 5.5, Low 2.0.4243## Report Format4445```46═══════════════════════════════════════════════════47 CODE HEALTH AUDIT: <repo>48 <date> | Mode: <quick|deep> | Modules: 8 | Findings: <n>49═══════════════════════════════════════════════════50BASELINE tests <n> passed · flake8 blocking <n> · build <result>51EXECUTIVE SUMMARY52 Critical : <n> High : <n> Medium : <n> Low : <n>53 Total risk score: <sum>54 Not checked: <tools or files, when any>5556─── <BAND> ──────────────────────────────────────────57[<score>] <title> (<module>)58 <file>:<line> <one-line description>59 Vector: <impact> / <likelihood> / <reach>60 Fix available: <yes|no> <⚠ BEHAVIOR CHANGE when tagged>61```6263Highest score first. Vulnerable packages show `Vector: advisory: <severity>`.6465## Fix Loop6667Work down the report; skip findings with `Fix available: no`.6869```70[<score>] <title> (<module>)71 <file>:<line>72 Change: <one sentence>73 Files: <every file the fix touches>74 Test: <test id> (fails now, passes after)75Apply this fix? [yes / no / skip-severity / stop]76```7778- `yes`: if Impact is 0.7+ and the baseline ran a test, write the test and confirm it fails (otherwise omit the Test line). Apply the remediation recipe, then run the test and `python -m py_compile <files>` or `dotnet build`.79- `no` skips the finding, `skip-severity` skips the rest of the band, `stop` goes to the summary.80- For a **⚠ BEHAVIOR CHANGE** fix, after `yes` ask `⚠ <what changes>. Confirm? [yes / no]`81- Failed check: undo that fix's own edits newest first, including its test, report the error, continue. Never retry, `git checkout` or `git stash`.82- Change only what the finding covers; read only needed lines; comments follow `modules/comments.md`; no helper scripts; never stage or commit.8384## Verification8586Rerun the baseline commands, then print:8788```89Remediation complete.90 Fixed : <n> (risk reduced by <x> pts)91 Skipped : <n> (still open: <scores>)92 Failed : <n> (see errors above)93 Tests : <n> added · <n> passed (baseline <n>)94 Lint : flake8 blocking <n> (baseline <n>)95 Build : <result> (baseline <result>)96 Remaining risk score: <sum>97Changes are unstaged and uncommitted.98```99100If a check that passed at baseline now fails, name the fixes that touched those files and ask `Undo those fixes? [yes / no]`. Note fixes without a test, or that no test suite exists.