From 89334f29014dd1c8a85fc7aa65a544920ce89cbc Mon Sep 17 00:00:00 2001 From: bchanot Date: Mon, 26 Oct 2026 18:04:15 +0100 Subject: [PATCH] fix(rules): named dep-dir globs match, inline-paths error names the form, gitignore newline guard, no | in globs --- agents/onboarder.md | 7 ++++++- lib/project-rules.sh | 14 +++++++++++--- lib/tests/project-rules.test.sh | 7 ++++++- skills/onboard/SKILL.md | 6 ++++-- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/agents/onboarder.md b/agents/onboarder.md index 23a4915..d50d331 100644 --- a/agents/onboarder.md +++ b/agents/onboarder.md @@ -206,7 +206,12 @@ S0 — PREFLIGHT (no write before every row passes): - `git -C status --porcelain` is empty, else STOP. - gitignore: `git -C 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 `/.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 /.gitignore)" ] && echo >> + /.gitignore` so the negation never glues onto the last + line. Then: `printf '!.claude/rules/\n' >> /.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 diff --git a/lib/project-rules.sh b/lib/project-rules.sh index a592583..6b50ad6 100644 --- a/lib/project-rules.sh +++ b/lib/project-rules.sh @@ -12,8 +12,11 @@ # emit 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() { # → 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() { # → 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 diff --git a/lib/tests/project-rules.test.sh b/lib/tests/project-rules.test.sh index b6ab70b..a827ce3 100644 --- a/lib/tests/project-rules.test.sh +++ b/lib/tests/project-rules.test.sh @@ -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' diff --git a/skills/onboard/SKILL.md b/skills/onboard/SKILL.md index a0e3fd4..f12ce69 100644 --- a/skills/onboard/SKILL.md +++ b/skills/onboard/SKILL.md @@ -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 matches ''` (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: