Skip to content

Code health with ai-health: strict profile, delta gate, ruff - #3

Merged
ditschi merged 15 commits into
mainfrom
code-health
Nov 26, 2026
Merged

ditschi merged 15 commits into
mainfrom
code-health

Conversation

@ditschi

@ditschi ditschi commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

First of two PRs for the OpenSpec change code-health (openspec/changes/code-health/). The refactorings toward score 10 follow in a second PR.

What

  • ai-health (MIT, deterministic) pinned to commit 033d186 (v0.4.0). scripts/aihealth is the only place with the pin and passes every argument through (exec uvx ...).
  • Components: python-cli and shell with .aihealth.toml (profile strict: CodeScene thresholds, file 600 lines, primitive obsession 30 %, decay 8, density_loc 100000, tolerance 0), python-tests with .aihealth-tests.toml (same profile; excess arguments, primitive obsession and low cohesion off). tests/unit/test_aihealth_config.py keeps the shared sections equal.
  • Gate: pre-commit aihealth-delta and aihealth-delta-tests (delta --staged per component) and aihealth-suppression-reason (pygrep: # aihealth: disable=<smell> -- <reason>). CI job code-health: delta per component against the merge base, component score comparison, scan report, uv and grammar cache. The CI pre-commit job skips the two delta hooks (no uv there; --staged checks nothing in CI).
  • Not scored, documented in docs/code-health.md: Ansible (ansible-lint only), Python scripts without extension (Detect extensionless Python scripts by shebang (like shell scripts) epatel/ai-health#3), test smells, third-party skills.
  • ruff replaces black and flake8 (separate commits: config, then a 5-file reformat). Format line length 88 as black, lint E/F/W at 120 as flake8, no structure rules.
  • The own checker built first in this change (code_health/) is removed, following the owner rule "no own logic where a tool exists"; its measurements are kept in design.md and the Steckbrief.
  • Seven project-local skills from skills.sh (SKILL.md reviewed, pinned in skills-lock.json, excluded from pre-commit and ai-health).
  • AGENTS.md section (incl. "never weaken type hints to silence a smell"), docs/code-health.md with the Steckbrief, CI unit jobs install the Ansible collections before pytest.

Own logic that remains, and why

  • scripts/aihealth (one exec line): the single pin for hook, CI and nox.
  • scripts/aihealth_components.py (~95 LoC + tests): ai-health has no language filter and no comparison between two revisions; the script splits the scan JSON into components and compares merge base and head (owner decision Q6).
  • tests/unit/test_aihealth_config.py: ai-health reads exactly one config per call (no include), so the duplicated profile sections are guarded.

Reviews

Two independent reviews (fresh reviewer, only diff, repo and AGENTS.md).

  • First review, 11 findings: 10 fixed; scan --report writing one report per component is intended. machine_cli/machine is not seen by ruff (its uv run --script shebang is not tagged as Python) - pre-existing, black did not see it either.
  • Second review, 7 findings: Steckbrief worst files, spec hook list, merge-base wording, history labels in tasks, a type hint and this description are fixed. Not changed: uvx nox -s code-health scans four times (text report plus the component JSON) - acceptable for a manual command. 'The component comparison failed when a healthy file was deleted; fixed in dfd82b8 by comparing only files present in both revisions (owner decision Q6).'

Validation

  • pytest tests/unit/test_aihealth_config.py tests/unit/test_aihealth_components.py -q: green; full pytest tests/unit -q green except pre-existing test_device_tunnel.py and load-dependent pty flakes in test_command_prefix.py.
  • Hooks verified on scratch changes: both delta hooks fail on a new complex function, the pygrep hook on a suppression without a reason.
  • scripts/aihealth delta --base "$(git merge-base origin/main HEAD)" --head HEAD --config ... for both components and scripts/aihealth_components.py --compare ...: pass.
  • openspec validate code-health --strict: valid.
  • CI: apt-rpi-zero (26.04) and apt-home-laptop fail exactly as on main (zsh health check sees git-credential-env: GITHUB_TOKEN is not set); 'not caused by this PR. Owner decision: this PR waits until that zsh startup error is fixed in its own change, then merges on fully green CI.'

🤖 Generated with Claude Code

Christian Ditscher added 10 commits November 23, 2026 21:14
Own 1-10 score per file and per part (python-cli, python-tests, shell,
ansible), modelled on CodeScene Code Health with the published Python
defaults; standard library plus PyYAML. `python3 -m code_health` /
`uvx nox -s code-health` with --json and --changed; --gate in the
pre-commit hook and the CI unit job; code-health-baseline.json as the
ratchet below 9.5. Docs in docs/code-health.md, AGENTS.md section, two
reviewed skills from skills.sh. OpenSpec change code-health.
Owner decision Q9: at CodeScene's 30 % the rule fired for 26 of 33 judged
python-cli files; at 50 % it flags files where most arguments are
primitives.
…mponent check

Owner decision 2026-11-23: ai-health (pinned commit in scripts/aihealth)
replaces the own checker, which stays as a cross-check for now. OpenSpec
change updated accordingly.
Owner decision 2026-11-23 (Q8, Q9): one Python linter and formatter in all
repositories; black's formatting and flake8's rules and line length kept,
structure rules off because ai-health is the only source for those findings.
docs/code-health.md and its Steckbrief describe the ai-health setup; the
own checker no longer gates (hook and CI step removed) and stays as a
report until its removal. Skills approved by the owner on 2026-11-24.
- CI pre-commit job skips aihealth-delta (no uv there; the code-health
  job gates the delta), uv pinned, merge base in its own step
- wrapper: paths go only to their component, ROOT from the script's
  location, usage errors exit 2, clear hint without uvx
- component check: a drop of exactly 0.01 passes (rounding)
- docs, spec and design name the excludes and the final measurements
test_homelab_node_role needs ansible.posix; the unit jobs installed the
collections only after pytest (failing on main as well). Also drops the
full fetch depth the unit job no longer needs.
@ditschi
ditschi marked this pull request as ready for review November 24, 2026 00:24
Christian Ditscher added 5 commits November 24, 2026 01:37
… pin

Owner rule 2026-11-24: no own logic where ai-health can do it. Hooks, CI
and nox call ai-health per component with --config; the component score
comparison stays because ai-health has none. No cosmetic type aliases;
AGENTS.md says type hints are never weakened to silence a smell.
…raw subcommand

Covered by a test of the exact ai-health calls.
Steckbrief worst files from main, merge-base wording, the tests delta
hook in the pre-commit-checks spec, history labels in tasks.md, an exact
type hint for the component totals.
Owner decision Q6 (2026-11-26): deleting a healthy file lowered the
LoC-weighted mean and failed the CI check; new and changed files are
judged per file by aihealth delta.
…/ai-health#4)

Owner decision Q18.1 (2026-11-26): two configs in all repositories until
ai-health supports overrides per path; no primitive-obsession
suppressions in test code.
@ditschi
ditschi merged commit 02dfb30 into main Nov 26, 2026
23 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant