fix(project-rules): physical parent check, emit write guard, extract keeps both copies

_rules_out_path_ok resolves the first existing ancestor with cd -P and
refuses an out that escapes the project; emit goes through it and checks
mkdir and the write; an extract rewrite failure keeps tmp and out and
names both. Callers (onboarder, scaffolder) stop on any rc 2 but exists.
This commit is contained in:
bchanot committed 2026-11-13 13:14:24 +01:00
1 parent 4e71b1af64
commit 9d5530af89
4 files changed
+83 -24

No files matched your search

+4 -2
View File
@@ -141,7 +141,8 @@ bash ~/.claude/lib/project-rules.sh -C <PROJECT_ROOT> emit ~/.claude/templates/p
`build_cmd`, `testing` layout from `test_cmd`); never duplicate the
always-on Build/Test sections.
- rc 1 → no match, nothing written, skip silently.
- rc 2 → the file exists: keep it, never overwrite.
- rc 2 whose stderr line ends with ` exists` → keep the file, never
overwrite; any other rc 2 → STOP, relay the lib's line.
Then `bash ~/.claude/lib/project-rules.sh -C <PROJECT_ROOT> check` must print
`N rule(s) ok`. The `!.claude/rules/` negation comes from the gitflow socle
at /onboard STEP 2.6 (`gitflow init` reconciles it); PHASE 4 stays as is.
@@ -252,7 +253,8 @@ rc ≠ 0 (should not happen after S0) → ROLLBACK: `git -C <PROJECT_ROOT>
reset -q`, `git -C <PROJECT_ROOT> checkout -- CLAUDE.md` (plus
`.gitignore` when S0 appended to it), delete every
`.claude/rules/<name>.md` this run wrote (literal paths, one `rm` per
row), then STOP with the row and the lib's message.
row; a row that failed at the rewrite step also leaves a tmp file named
on stderr: delete it too), then STOP with the row and the lib's message.
S2 — POINTER. If CLAUDE.md has no `## Path-scoped rules` section, append:
```markdown
+3 -1
View File
@@ -87,7 +87,9 @@ bash ~/.claude/lib/project-rules.sh -C <PROJECT_ROOT> emit ~/.claude/templates/p
rc 0 → fill its stubs from the DESIGN (image, compose services, test
layout, pipeline jobs), no placeholders left; rc 1 → nothing matched,
skipped (a plain scaffold yields `docker.md` when Docker is relevant, and
`testing.md` only when the stack scaffolds a test file). Then
`testing.md` only when the stack scaffolds a test file); rc 2 whose stderr
line ends with ` exists` → keep the file, any other rc 2 → STOP, relay the
lib's line. Then
`bash ~/.claude/lib/project-rules.sh -C <PROJECT_ROOT> check` prints
`N rule(s) ok`. The `.gitignore` negation `!.claude/rules/` comes from the
gitflow socle at STEP 5f (`gitflow init` reconciles it before the root