Guidelines & architecture compliance — whole project
Enforces the rules written in the project's API_GUIDELINES.md and ARCHITECTURE.md
the same way clang-tidy enforces its checks: a generated check_guidelines.py finds
violations, a generated fix_guidelines.py auto-fixes the mechanical ones, and the AI
fixes the rest. Everything derived from the docs is cached in
<repo-root>/.guidelines-cache/ and reused verbatim until the guidelines-clear skill
deletes it. The cache is shared with the sibling skill guidelines-check-diff
(same scripts, run with --diff); whichever skill runs first builds it.
Token economy — follow strictly: if the cache exists, NEVER read the original
guideline documents. Read only GUIDELINES_COMPACT.md and the checker output.
0. Decide cold vs warm
ROOT=$(git rev-parse --show-toplevel); cache dir is $ROOT/.guidelines-cache/.
If GUIDELINES_COMPACT.md, check_guidelines.py and fix_guidelines.py all exist
there → go to Warm run. Otherwise do First run once, then continue with Warm.
First run (cache build — the only expensive run)
- Find the docs (skip
.git, build dirs, external/, third_party/, vendor/):
find "$ROOT" -maxdepth 4 \( -iname 'API_GUIDELINES.md' -o -iname 'ARCHITECTURE.md' \) -not -path '*/.git/*' -not -path '*/build*' -not -path '*/external/*' -not -path '*/third_party/*'
If none exist, tell the user and stop. If only one exists, proceed with that one.
- Read the found docs in full — this is the only time they are ever read.
- Write
$ROOT/.guidelines-cache/GUIDELINES_COMPACT.md: every enforceable rule as one
entry — stable ID (API-1…, ARC-1…), rule statement (≤2 lines), and a tag:
[fix] — mechanically detectable AND mechanically fixable
[check] — mechanically detectable, needs judgment to fix
[ai] — needs judgment even to detect (design/layering intent)
Also record the source-scope globs (which dirs/extensions the rules apply to).
Drop prose that isn't a rule (motivation, history, diagrams).
- Write
$ROOT/.guidelines-cache/check_guidelines.py — Python 3, stdlib only:
- Config block at the top:
SOURCE_GLOBS, EXCLUDE_DIRS, SUPPRESSIONS (list of
path:RuleID accepted exceptions).
- CLI: no args = scan all files matching
SOURCE_GLOBS; --diff = scan only
git-changed files (working tree + staged vs HEAD; if clean, merge-base vs
origin/main|origin/master|main|master) intersected with SOURCE_GLOBS.
- One function per
[check]/[fix] rule, named after the rule ID, with the rule
text as its docstring.
- Output one line per violation:
path:line: [RULE-ID] message; then a summary of
counts per rule. Exit 0 when clean, 1 when violations exist.
- Prefer precise-but-simple detection (regex / light parsing). A rule that cannot be
detected reliably stays
[ai]-tagged and is NOT implemented — no noisy guessing.
- Write
$ROOT/.guidelines-cache/fix_guidelines.py — same config block and same
--diff flag; implements only the [fix] rules with safe, idempotent textual edits;
prints each file it modifies; never touches EXCLUDE_DIRS.
- Write
$ROOT/.guidelines-cache/manifest.json: source doc paths, their sha256, and
the generation date.
- Sanity-check: run the checker once. If a rule produces an obvious flood of false
positives, refine that rule's function (or demote it to
[ai] in the compact file)
before continuing.
Warm run (every time)
- Optional staleness note: if
shasum -a 256 of the source docs differs from
manifest.json, warn the user that the docs changed and that guidelines-clear
would rebuild the cache — but continue with the cache (only an explicit clear
rebuilds).
- Reuse a fresh report if one exists: if
$ROOT/guidelines_report.md (or .xml)
from guidelines-check-report exists, covers the whole project (not --diff scope),
and is newer than both manifest.json and the latest local change (git status
clean since, or the report postdates the last commit/uncommitted edit), read its
violations instead of re-running the checker and skip straight to step 3. Otherwise:
python3 $ROOT/.guidelines-cache/check_guidelines.py
(If the script itself crashes, repair it in place — it is cache, editable.)
- If violations:
python3 $ROOT/.guidelines-cache/fix_guidelines.py, then re-run the
checker.
- Read the remaining checker output and
GUIDELINES_COMPACT.md. Fix the remaining
[check] violations by editing code, opening only the reported regions. For genuine,
justified exceptions, add a SUPPRESSIONS entry with a comment instead of weakening
the rule. If the count is very large, fix the highest-count rules first and give the
user a prioritized summary of what remains.
[ai] rules: review the files the checker flagged (plus any the user named) against
the [ai]-tagged entries of the compact file; fix what violates them. A full-repo
[ai] review is expensive — do it only if the user explicitly asked for a deep
audit, and summarize findings per rule rather than per file.
- Re-run the checker to confirm exit 0, then report: violations auto-fixed, fixed by
AI, suppressed (with reasons), and any
[ai] findings.
Notes
- The cache may be committed to git so teammates/other agents skip the first run too;
follow the project's existing convention if one is visible.
- Portable: copy this folder (with
guidelines-check-diff and guidelines-clear) into
any project that has an API_GUIDELINES.md and/or ARCHITECTURE.md; the cache is
regenerated per project.
1---2name: guidelines-check-all3description: Check and fix the WHOLE codebase against the project's API_GUIDELINES.md and ARCHITECTURE.md. First run distills the docs into cached checker/fixer scripts; later runs use only the cache (cheap). Use when asked to audit or enforce project guidelines/architecture compliance repo-wide.4---56# Guidelines & architecture compliance — whole project78Enforces the rules written in the project's `API_GUIDELINES.md` and `ARCHITECTURE.md`9the same way clang-tidy enforces its checks: a generated `check_guidelines.py` finds10violations, a generated `fix_guidelines.py` auto-fixes the mechanical ones, and the AI11fixes the rest. Everything derived from the docs is cached in12`<repo-root>/.guidelines-cache/` and reused verbatim until the `guidelines-clear` skill13deletes it. The cache is shared with the sibling skill `guidelines-check-diff`14(same scripts, run with `--diff`); whichever skill runs first builds it.1516**Token economy — follow strictly:** if the cache exists, NEVER read the original17guideline documents. Read only `GUIDELINES_COMPACT.md` and the checker output.1819## 0. Decide cold vs warm2021`ROOT=$(git rev-parse --show-toplevel)`; cache dir is `$ROOT/.guidelines-cache/`.22If `GUIDELINES_COMPACT.md`, `check_guidelines.py` and `fix_guidelines.py` all exist23there → go to **Warm run**. Otherwise do **First run** once, then continue with Warm.2425## First run (cache build — the only expensive run)26271. Find the docs (skip `.git`, build dirs, `external/`, `third_party/`, `vendor/`):28 `find "$ROOT" -maxdepth 4 \( -iname 'API_GUIDELINES.md' -o -iname 'ARCHITECTURE.md' \) -not -path '*/.git/*' -not -path '*/build*' -not -path '*/external/*' -not -path '*/third_party/*'`29 If none exist, tell the user and stop. If only one exists, proceed with that one.302. Read the found docs in full — this is the only time they are ever read.313. Write `$ROOT/.guidelines-cache/GUIDELINES_COMPACT.md`: every enforceable rule as one32 entry — stable ID (`API-1…`, `ARC-1…`), rule statement (≤2 lines), and a tag:33 - `[fix]` — mechanically detectable AND mechanically fixable34 - `[check]` — mechanically detectable, needs judgment to fix35 - `[ai]` — needs judgment even to detect (design/layering intent)36 Also record the source-scope globs (which dirs/extensions the rules apply to).37 Drop prose that isn't a rule (motivation, history, diagrams).384. Write `$ROOT/.guidelines-cache/check_guidelines.py` — Python 3, stdlib only:39 - Config block at the top: `SOURCE_GLOBS`, `EXCLUDE_DIRS`, `SUPPRESSIONS` (list of40 `path:RuleID` accepted exceptions).41 - CLI: no args = scan all files matching `SOURCE_GLOBS`; `--diff` = scan only42 git-changed files (working tree + staged vs HEAD; if clean, merge-base vs43 origin/main|origin/master|main|master) intersected with `SOURCE_GLOBS`.44 - One function per `[check]`/`[fix]` rule, named after the rule ID, with the rule45 text as its docstring.46 - Output one line per violation: `path:line: [RULE-ID] message`; then a summary of47 counts per rule. Exit 0 when clean, 1 when violations exist.48 - Prefer precise-but-simple detection (regex / light parsing). A rule that cannot be49 detected reliably stays `[ai]`-tagged and is NOT implemented — no noisy guessing.505. Write `$ROOT/.guidelines-cache/fix_guidelines.py` — same config block and same51 `--diff` flag; implements only the `[fix]` rules with safe, idempotent textual edits;52 prints each file it modifies; never touches `EXCLUDE_DIRS`.536. Write `$ROOT/.guidelines-cache/manifest.json`: source doc paths, their sha256, and54 the generation date.557. Sanity-check: run the checker once. If a rule produces an obvious flood of false56 positives, refine that rule's function (or demote it to `[ai]` in the compact file)57 before continuing.5859## Warm run (every time)60611. Optional staleness note: if `shasum -a 256` of the source docs differs from62 `manifest.json`, warn the user that the docs changed and that `guidelines-clear`63 would rebuild the cache — but continue with the cache (only an explicit clear64 rebuilds).652. **Reuse a fresh report if one exists**: if `$ROOT/guidelines_report.md` (or `.xml`)66 from `guidelines-check-report` exists, covers the whole project (not `--diff` scope),67 and is newer than both `manifest.json` and the latest local change (`git status`68 clean since, or the report postdates the last commit/uncommitted edit), read its69 violations instead of re-running the checker and skip straight to step 3. Otherwise:70 `python3 $ROOT/.guidelines-cache/check_guidelines.py`71 (If the script itself crashes, repair it in place — it is cache, editable.)723. If violations: `python3 $ROOT/.guidelines-cache/fix_guidelines.py`, then re-run the73 checker.744. Read the remaining checker output **and** `GUIDELINES_COMPACT.md`. Fix the remaining75 `[check]` violations by editing code, opening only the reported regions. For genuine,76 justified exceptions, add a `SUPPRESSIONS` entry with a comment instead of weakening77 the rule. If the count is very large, fix the highest-count rules first and give the78 user a prioritized summary of what remains.795. `[ai]` rules: review the files the checker flagged (plus any the user named) against80 the `[ai]`-tagged entries of the compact file; fix what violates them. A full-repo81 `[ai]` review is expensive — do it only if the user explicitly asked for a deep82 audit, and summarize findings per rule rather than per file.836. Re-run the checker to confirm exit 0, then report: violations auto-fixed, fixed by84 AI, suppressed (with reasons), and any `[ai]` findings.8586## Notes8788- The cache may be committed to git so teammates/other agents skip the first run too;89 follow the project's existing convention if one is visible.90- Portable: copy this folder (with `guidelines-check-diff` and `guidelines-clear`) into91 any project that has an `API_GUIDELINES.md` and/or `ARCHITECTURE.md`; the cache is92 regenerated per project.