Guidelines & architecture compliance — current diff only
Same machinery as guidelines-check-all, restricted to the files changed in git
(working tree + staged; falls back to merge-base vs main/master when clean). It shares
the cache in <repo-root>/.guidelines-cache/ with the sibling skill; 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 the First run exactly as specified in
../guidelines-check-all/SKILL.md (the cache build is scope-independent — the
generated scripts must support the --diff flag as that spec requires). If this skill
was copied to a project without its sibling, follow the First-run spec below.
- 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…), statement (≤2 lines), and a tag: [fix]
(mechanically detectable and fixable), [check] (detectable, fixing needs judgment),
[ai] (needs judgment even to detect). Record source-scope globs; drop non-rule prose.
- Write
$ROOT/.guidelines-cache/check_guidelines.py — Python 3, stdlib only. Config
block at top: SOURCE_GLOBS, EXCLUDE_DIRS, SUPPRESSIONS (path:RuleID accepted
exceptions). CLI: no args = scan all SOURCE_GLOBS files; --diff = 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 (rule text as docstring). Output path:line: [RULE-ID] message + per-rule summary; exit 0 clean / 1 violations. Precise-but-simple
detection only; undetectable rules stay [ai] and are not implemented.
- Write
$ROOT/.guidelines-cache/fix_guidelines.py — same config block and --diff
flag; safe, idempotent textual fixes for [fix] rules only; prints modified files;
never touches EXCLUDE_DIRS.
- Write
$ROOT/.guidelines-cache/manifest.json: doc paths, sha256, generation date.
- Sanity-check: run the checker once; refine or demote any rule flooding false
positives.
Warm run (every time)
- Optional staleness note: if
shasum -a 256 of the source docs differs from
manifest.json, warn that the docs changed and guidelines-clear would rebuild —
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, was generated for --diff scope, and is newer
than both manifest.json and the current diff's last edit, read its violations
instead of re-running the checker and skip straight to step 3. Otherwise:
python3 $ROOT/.guidelines-cache/check_guidelines.py --diff
(If the script itself crashes, repair it in place — it is cache, editable.)
- If violations:
python3 $ROOT/.guidelines-cache/fix_guidelines.py --diff, then
re-run the checker with --diff.
- 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.
[ai] rules: review the files in the current git diff against the [ai]-tagged
entries of the compact file; fix what violates them.
- Re-run the checker (
--diff) 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.
- Portable: copy this folder (ideally with
guidelines-check-all 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-diff3description: Check and fix only the files in the current git diff 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 verify the current changes against project guidelines.4---56# Guidelines & architecture compliance — current diff only78Same machinery as `guidelines-check-all`, restricted to the files changed in git9(working tree + staged; falls back to merge-base vs main/master when clean). It shares10the cache in `<repo-root>/.guidelines-cache/` with the sibling skill; whichever skill11runs first builds it.1213**Token economy — follow strictly:** if the cache exists, NEVER read the original14guideline documents. Read only `GUIDELINES_COMPACT.md` and the checker output.1516## 0. Decide cold vs warm1718`ROOT=$(git rev-parse --show-toplevel)`; cache dir is `$ROOT/.guidelines-cache/`.19If `GUIDELINES_COMPACT.md`, `check_guidelines.py` and `fix_guidelines.py` all exist20there → go to **Warm run**. Otherwise do the **First run** exactly as specified in21`../guidelines-check-all/SKILL.md` (the cache build is scope-independent — the22generated scripts must support the `--diff` flag as that spec requires). If this skill23was copied to a project without its sibling, follow the First-run spec below.2425<details><summary>First-run spec (only needed when the sibling skill is absent)</summary>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…`), statement (≤2 lines), and a tag: `[fix]`33 (mechanically detectable and fixable), `[check]` (detectable, fixing needs judgment),34 `[ai]` (needs judgment even to detect). Record source-scope globs; drop non-rule prose.354. Write `$ROOT/.guidelines-cache/check_guidelines.py` — Python 3, stdlib only. Config36 block at top: `SOURCE_GLOBS`, `EXCLUDE_DIRS`, `SUPPRESSIONS` (`path:RuleID` accepted37 exceptions). CLI: no args = scan all `SOURCE_GLOBS` files; `--diff` = only38 git-changed files (working tree + staged vs HEAD; if clean, merge-base vs39 origin/main|origin/master|main|master) intersected with `SOURCE_GLOBS`. One function40 per `[check]`/`[fix]` rule (rule text as docstring). Output `path:line: [RULE-ID]41 message` + per-rule summary; exit 0 clean / 1 violations. Precise-but-simple42 detection only; undetectable rules stay `[ai]` and are not implemented.435. Write `$ROOT/.guidelines-cache/fix_guidelines.py` — same config block and `--diff`44 flag; safe, idempotent textual fixes for `[fix]` rules only; prints modified files;45 never touches `EXCLUDE_DIRS`.466. Write `$ROOT/.guidelines-cache/manifest.json`: doc paths, sha256, generation date.477. Sanity-check: run the checker once; refine or demote any rule flooding false48 positives.4950</details>5152## Warm run (every time)53541. Optional staleness note: if `shasum -a 256` of the source docs differs from55 `manifest.json`, warn that the docs changed and `guidelines-clear` would rebuild —56 but continue with the cache (only an explicit clear rebuilds).572. **Reuse a fresh report if one exists**: if `$ROOT/guidelines_report.md` (or `.xml`)58 from `guidelines-check-report` exists, was generated for `--diff` scope, and is newer59 than both `manifest.json` and the current diff's last edit, read its violations60 instead of re-running the checker and skip straight to step 3. Otherwise:61 `python3 $ROOT/.guidelines-cache/check_guidelines.py --diff`62 (If the script itself crashes, repair it in place — it is cache, editable.)633. If violations: `python3 $ROOT/.guidelines-cache/fix_guidelines.py --diff`, then64 re-run the checker with `--diff`.654. Read the remaining checker output **and** `GUIDELINES_COMPACT.md`. Fix the remaining66 `[check]` violations by editing code, opening only the reported regions. For genuine,67 justified exceptions, add a `SUPPRESSIONS` entry with a comment instead of weakening68 the rule.695. `[ai]` rules: review the files in the current git diff against the `[ai]`-tagged70 entries of the compact file; fix what violates them.716. Re-run the checker (`--diff`) to confirm exit 0, then report: violations auto-fixed,72 fixed by AI, suppressed (with reasons), and any `[ai]` findings.7374## Notes7576- The cache may be committed to git so teammates/other agents skip the first run too.77- Portable: copy this folder (ideally with `guidelines-check-all` and78 `guidelines-clear`) into any project that has an `API_GUIDELINES.md` and/or79 `ARCHITECTURE.md`; the cache is regenerated per project.