From dbd20dd5756ae556f5abb0a252d132aa14e3cfa8 Mon Sep 17 00:00:00 2001 From: bchanot Date: Mon, 26 Oct 2026 17:55:01 +0100 Subject: [PATCH] feat(generators): onboarder and scaffolder emit docker/testing/ci path rules from templates/project-rules --- agents/onboarder.md | 18 ++++++++++++++++++ agents/scaffolder.md | 19 +++++++++++++++++++ lib/tests/project-rules.test.sh | 18 ++++++++++++++++++ templates/project-CLAUDE.md | 1 + templates/project-rules/ci.md | 10 ++++++++++ templates/project-rules/docker.md | 10 ++++++++++ templates/project-rules/testing.md | 10 ++++++++++ 7 files changed, 86 insertions(+) create mode 100644 templates/project-rules/ci.md create mode 100644 templates/project-rules/docker.md create mode 100644 templates/project-rules/testing.md diff --git a/agents/onboarder.md b/agents/onboarder.md index f9d2b63..23a4915 100644 --- a/agents/onboarder.md +++ b/agents/onboarder.md @@ -128,6 +128,24 @@ ls ${PROJECT_ROOT}/.claude/tasks/TODO.md ${PROJECT_ROOT}/.claude/memory/ 2>/dev/ **Do NOT overwrite existing content.** +## PHASE 5b — PATH-SCOPED RULES (born split) + +For each of `docker`, `testing`, `ci`: +```bash +bash ~/.claude/lib/project-rules.sh -C emit ~/.claude/templates/project-rules/.md .claude/rules/.md +``` +- rc 0 → written with the globs that match this tree; its stub comments + are `` placeholders the orchestrator's + STEP 3 fills (list them in OUTPUT beside the CLAUDE.md placeholders). + Fill now only what the BRIEF already settles (`docker` commands from + `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. +Then `bash ~/.claude/lib/project-rules.sh -C 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. + --- ## PHASE 6 — GSD v2 ROADMAP (optional, per orchestrator flag) diff --git a/agents/scaffolder.md b/agents/scaffolder.md index 607bde3..9d24a93 100644 --- a/agents/scaffolder.md +++ b/agents/scaffolder.md @@ -73,6 +73,25 @@ Empty structure only: imports + empty main/init. No logic. `.dockerignore`: node_modules, .git, .env, dist/build/target, __pycache__. Add `COMPOSE_PROJECT_NAME=` to `.env.example`. +## PHASE 3b — PATH-SCOPED RULES (born split) + +After PHASE 3 wrote the files and BEFORE PHASE 4 installs dependencies +(installed packages must not match the globs). `` is the +project root PHASE 1 wrote `CLAUDE.md` into, as a literal absolute path +(`pwd` there; it is not an INPUT, the scaffold defines it). For each of +`docker`, `testing`, `ci`, one uniform loop: +```bash +bash ~/.claude/lib/project-rules.sh -C emit ~/.claude/templates/project-rules/.md .claude/rules/.md +``` +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 +`bash ~/.claude/lib/project-rules.sh -C 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 +commit); do not add `.claude` lines to the stack `.gitignore` yourself. + --- ## PHASE 4 — INSTALL DEPS diff --git a/lib/tests/project-rules.test.sh b/lib/tests/project-rules.test.sh index 91d2eb1..b6ab70b 100644 --- a/lib/tests/project-rules.test.sh +++ b/lib/tests/project-rules.test.sh @@ -182,5 +182,23 @@ check T11b-four-rules "$(printf '%s\n' "$out" | grep -c '4 rule(s) ok')" 1 check T11c-transient-skipped \ "$(printf '%s\n' "$out" | grep -c 'transient-artifacts.md: SKIP docs/superpowers/\*\*')" 1 +# T12 skeletons: emit keeps the matching globs only, skips when none match +mkdir -p "$FIX/gen/tests" && cd "$FIX/gen" || exit 1 +echo x > Dockerfile; echo y > tests/test_a.py +bash "$PR" emit "$ROOT/templates/project-rules/docker.md" .claude/rules/docker.md >/dev/null +check T12-docker-emitted "$?" 0 +check T12b-docker-globs-pruned "$(sed -n '2p' .claude/rules/docker.md)" 'paths: ["Dockerfile*"]' +check T12c-docker-body-kept "$(grep -c '^# Docker' .claude/rules/docker.md)" 1 +bash "$PR" emit "$ROOT/templates/project-rules/testing.md" .claude/rules/testing.md >/dev/null +check T12d-testing-emitted "$?" 0 +check T12e-testing-globs-pruned "$(sed -n '2p' .claude/rules/testing.md)" 'paths: ["tests/**"]' +bash "$PR" emit "$ROOT/templates/project-rules/ci.md" .claude/rules/ci.md 2>/dev/null +check T12f-ci-not-emitted-rc "$?" 1 +check T12g-ci-not-written "$([ -e .claude/rules/ci.md ] && echo yes || echo no)" no +bash "$PR" emit "$ROOT/templates/project-rules/docker.md" .claude/rules/docker.md 2>/dev/null +check T12h-existing-target-rc "$?" 2 +bash "$PR" check >/dev/null; check T12i-emitted-rules-pass-check "$?" 0 +cd "$FIX" || exit 1 + echo "PASS=$pass FAIL=$fail" [ "$fail" -eq 0 ] diff --git a/templates/project-CLAUDE.md b/templates/project-CLAUDE.md index e8b8417..401ffb7 100644 --- a/templates/project-CLAUDE.md +++ b/templates/project-CLAUDE.md @@ -2,6 +2,7 @@ # Generated by /init-project or /onboard. Single source of truth for Claude in this repo. # Global rules: ~/.claude/CLAUDE.md — this file extends or overrides them. +# Path-scoped rules: .claude/rules/.md (paths: frontmatter), loaded on Read of a matching file. --- diff --git a/templates/project-rules/ci.md b/templates/project-rules/ci.md new file mode 100644 index 0000000..fc5cbb0 --- /dev/null +++ b/templates/project-rules/ci.md @@ -0,0 +1,10 @@ +--- +paths: [".github/workflows/**", ".gitlab-ci.yml", ".circleci/**"] +--- + +# CI + + + + + diff --git a/templates/project-rules/docker.md b/templates/project-rules/docker.md new file mode 100644 index 0000000..d6e39c5 --- /dev/null +++ b/templates/project-rules/docker.md @@ -0,0 +1,10 @@ +--- +paths: ["Dockerfile*", "docker-compose*", "compose*.y*ml", ".dockerignore"] +--- + +# Docker + + + + + diff --git a/templates/project-rules/testing.md b/templates/project-rules/testing.md new file mode 100644 index 0000000..7e1611b --- /dev/null +++ b/templates/project-rules/testing.md @@ -0,0 +1,10 @@ +--- +paths: ["tests/**", "test/**", "**/*.test.*", "**/*.spec.*", "**/conftest.py"] +--- + +# Testing conventions + + + + +