fix(rules): named dep-dir globs match, inline-paths error names the form, gitignore newline guard, no | in globs

This commit is contained in:
bchanot committed 2026-10-26 18:04:15 +01:00
1 parent 7b878b5dc3
commit 89334f2901
4 files changed
+27 -7

No files matched your search

+6 -1
View File
@@ -206,7 +206,12 @@ S0 — PREFLIGHT (no write before every row passes):
- `git -C <PROJECT_ROOT> status --porcelain` is empty, else STOP.
- gitignore: `git -C <PROJECT_ROOT> check-ignore -q .claude/rules/probe.md`
rc 0 means the rules would be ignored → append the negation (portable,
lands after any `.claude/*` line):
lands after any `.claude/*` line). If `<PROJECT_ROOT>/.gitignore` does
not exist, STOP: the ignore comes from outside the repo (global excludes
or `.git/info/exclude`); the user decides. Guard the trailing newline
first: `[ -n "$(tail -c1 <PROJECT_ROOT>/.gitignore)" ] && echo >>
<PROJECT_ROOT>/.gitignore` so the negation never glues onto the last
line. Then:
`printf '!.claude/rules/\n' >> <PROJECT_ROOT>/.gitignore`
then re-run `check-ignore`; still rc 0 → STOP: "ignore form cannot be
negated (BDR-003: use the `.claude/*` file form)", and `git -C
+11 -3
View File
@@ -12,8 +12,11 @@
# emit <skeleton> <out> the rule with the matching globs only (rc 1
# when none matches, nothing written)
# Globs match the WORKING TREE (compgen -G with globstar and dotglob,
# through symlinks, no brace expansion: one glob per extension),
# dependency dirs excluded: the engine matches the path the model reads,
# through symlinks, no brace expansion: one glob per extension;
# dotglob makes `*` match dotfiles, which the engine's matcher skips: a
# glob that only hits hidden paths passes here but never loads),
# dependency dirs excluded (unless the glob names one: `vendor/**` is a
# valid rule): the engine matches the path the model reads,
# tracked or not; a typo matches nothing either way. A frontmatter line
# `# static-check: skip` exempts a rule whose files only exist mid-run. A
# rule without frontmatter or without `paths:` is an always-on rule:
@@ -42,6 +45,10 @@ _rules_globs() {
}
_rules_hits() { # <glob> → matching paths outside dependency dirs, rc 1 none
case "$1" in # a glob that names a dependency dir is not filtered
node_modules/*|.venv/*|venv/*|vendor/*|target/*|dist/*|build/*|.git/*)
( shopt -s globstar dotglob; compgen -G "$1" ) 2>/dev/null; return ;;
esac
( shopt -s globstar dotglob; compgen -G "$1" ) 2>/dev/null \
| grep -Ev "$_RULES_DEPS"
}
@@ -62,7 +69,8 @@ _rules_check_file() { # <rule.md> → rc 0 ok or always-on, rc 1 with culprits
globs=$(_rules_globs "$fm")
case $? in
1) echo "$1: always-on (no paths:)"; return 0 ;;
2) echo "$1: paths: is not a JSON array of strings"; return 1 ;;
2) echo "$1: paths: must be one line:" \
"paths: [\"a\", \"b\"]"; return 1 ;;
esac
printf '%s\n' "$fm" | grep -qx '# static-check: skip' && skip=1
while IFS= read -r g; do
+6 -1
View File
@@ -47,7 +47,7 @@ printf -- '---\npaths: src/**\n---\n\n# Malformed\n' > .claude/rules/nofm.md
out=$(bash "$PR" check); rc=$?
check T3f-malformed-paths-fails "$rc" 2
check T3g-named \
"$(printf '%s\n' "$out" | grep -c 'nofm.md: paths: is not a JSON array of strings')" 1
"$(printf '%s\n' "$out" | grep -c 'nofm.md: paths: must be one line')" 1
rm .claude/rules/nofm.md
# T4 the skip marker passes an unmatched glob, and only in its own file
@@ -88,6 +88,11 @@ bash "$PR" matches 'many/**' >/dev/null; check T5k-many-hits-rc "$?" 0
check T5l-three-lines "$(bash "$PR" matches 'many/**' | wc -l | tr -d ' ')" 3
bash "$PR" matches 'src/**/*.{ts,tz}' >/dev/null 2>&1
check T5m-brace-glob-no-match "$?" 1
# T5n a glob that names a dependency dir is a match (vendored area rule)
mkdir -p vendor/lib && echo v > vendor/lib/a.js
bash "$PR" matches 'vendor/**' >/dev/null; check T5n-named-dep-dir-rc "$?" 0
bash "$PR" matches '**/a.js' >/dev/null 2>&1
check T5o-unnamed-dep-dir-still-filtered "$?" 1
# T6 sections lists headings with sizes, fence-aware
cat > CLAUDE.md <<'EOF'
+4 -2
View File
@@ -1127,8 +1127,10 @@ CLAUDE.md` lists every `##` section with its size. For each one decide:
files; never a brace glob `*.{ts,tsx}`: one glob per extension, the
oracle does no brace expansion) and verify EVERY proposed glob with
`bash ~/.claude/lib/project-rules.sh -C <ROOT> matches '<glob>'` (rc 0)
before showing it. A heading containing `'` or `|` is not split by this
mode (say so; the user renames it first).
before showing it. A heading containing
`'` or `|`, or a glob containing `|`, is not split by this mode (the
TABLE rows are `|`-separated; say so, the user renames or re-globs
first).
S5 — GATE (mandatory stop). Print the table, then end the turn: