diff --git a/.githooks/pre-commit b/.githooks/pre-commit index a42373a..0812c53 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -34,13 +34,15 @@ case "$br" in *) exit 0 ;; # working branch — allow esac -# whitelist: all-staged-under-.claude/ (memory/doc/deploy helpers) or -# .githooks/ (the hooks themselves, refreshed by the lib) — allow -if [ -z "$(git diff --cached --name-only | grep -vE '^\.(claude|githooks)/' | head -1)" ]; then +# whitelist: every staged path under .claude/{memory,tasks,audits,deploy}/ or +# .githooks/ (memory/doc/deploy helpers, the hooks themselves) — allow. Rules, +# settings, agents, skills stay blocked. --no-renames lists a rename's source +# too, so a git mv out of a blocked path cannot hide. +if [ -z "$(git diff --cached --name-only --no-renames | grep -vE '^(\.claude/(memory|tasks|audits|deploy)|\.githooks)/' | head -1)" ]; then exit 0 fi echo "gitflow pre-commit: BLOCKED — direct commit on '$br'." >&2 echo " Branch from the right base (feature/bugfix->develop, hotfix->main), or merge." >&2 -echo " (.claude/** and .githooks/** commits are exempt; foreign clone? git config gitflow.protect false)" >&2 +echo " (.claude/{memory,tasks,audits,deploy}/ and .githooks/ commits are exempt; foreign clone? git config gitflow.protect false)" >&2 exit 1 diff --git a/CLAUDE.global.md b/CLAUDE.global.md index b858626..5db6d62 100644 --- a/CLAUDE.global.md +++ b/CLAUDE.global.md @@ -157,8 +157,9 @@ open release; prod incidents only, a small fix on develop is a `bugfix`). `master` → `main` everywhere. Never commit code on `main` or `develop`: branch first as `/` -(a `.claude/**` memory/config commit that follows merged work is hook-exempt -and lands in place; a standalone memory task branches `chore/*`). +(a commit under the `.claude/{memory,tasks,audits,deploy}/` allowlist that +follows merged work is hook-exempt and lands in place; a standalone memory +task branches `chore/*`). Branch, merge and delete only via the lib: `bash ~/.claude/lib/gitflow.sh start ` · `finish` · `delete
`. `finish` runs only on an explicit human signal ("merge it", "feature OK"), never because tests pass, @@ -169,10 +170,10 @@ Assistance flows (`/feat` protected base but commit in place on a working branch, never finishing (one exception, BDR-068: `/capitalize` and `/close` auto-finish the memory-only `chore/*` they created this run), so they branch to `chore/*` -via the aiguillage, not the `.claude/**` exemption. +via the aiguillage, not the hook allowlist. Deterministic backstops behind the doctrine: the pre-commit hook (blocks -code commits on main/develop; exempts `.claude/**`, `.githooks/**`, merges, -the root commit), Gitea branch protection on both, and never `--no-verify`. +code commits on main/develop; exempts the `.claude/{memory,tasks,audits, +deploy}/` allowlist, `.githooks/`, merges, the root commit), Gitea branch protection on both, and never `--no-verify`. Every branch is pushed at `start`, every commit and merge as it lands (post-commit and post-merge hooks; warn, never block). A branch is deleted only by `finish` or `delete`, local and `origin/` copy alike: never diff --git a/githooks/pre-commit b/githooks/pre-commit index a42373a..0812c53 100755 --- a/githooks/pre-commit +++ b/githooks/pre-commit @@ -34,13 +34,15 @@ case "$br" in *) exit 0 ;; # working branch — allow esac -# whitelist: all-staged-under-.claude/ (memory/doc/deploy helpers) or -# .githooks/ (the hooks themselves, refreshed by the lib) — allow -if [ -z "$(git diff --cached --name-only | grep -vE '^\.(claude|githooks)/' | head -1)" ]; then +# whitelist: every staged path under .claude/{memory,tasks,audits,deploy}/ or +# .githooks/ (memory/doc/deploy helpers, the hooks themselves) — allow. Rules, +# settings, agents, skills stay blocked. --no-renames lists a rename's source +# too, so a git mv out of a blocked path cannot hide. +if [ -z "$(git diff --cached --name-only --no-renames | grep -vE '^(\.claude/(memory|tasks|audits|deploy)|\.githooks)/' | head -1)" ]; then exit 0 fi echo "gitflow pre-commit: BLOCKED — direct commit on '$br'." >&2 echo " Branch from the right base (feature/bugfix->develop, hotfix->main), or merge." >&2 -echo " (.claude/** and .githooks/** commits are exempt; foreign clone? git config gitflow.protect false)" >&2 +echo " (.claude/{memory,tasks,audits,deploy}/ and .githooks/ commits are exempt; foreign clone? git config gitflow.protect false)" >&2 exit 1 diff --git a/lib/gitflow-aiguillage.md b/lib/gitflow-aiguillage.md index 35235f7..8f94d61 100644 --- a/lib/gitflow-aiguillage.md +++ b/lib/gitflow-aiguillage.md @@ -32,8 +32,8 @@ doc reconciliation & curation skills (+ `/refactor`), run OUTSIDE an assistance `/bugfix` `/hotfix` `/ship-feature` a working branch already exists (this check returns WORKING) and the memory commit rides it. The aiguillage only fires when such a skill is invoked directly on `main`/`develop` — i.e. memory IS the work, -with no code branch to follow. That is the leak it closes: the `.claude/**` hook -exemption still lets a *manual* memory commit through on a protected base, but a +with no code branch to follow. That is the leak it closes: the `.claude/` allowlist hook exemption +still lets a *manual* memory commit through on a protected base, but a skill-driven one now branches to `chore/*` first. **Integration is human-gated by default** — these flows commit, they do not merge. diff --git a/lib/gitflow-test.sh b/lib/gitflow-test.sh index ce0b9a5..644de1d 100644 --- a/lib/gitflow-test.sh +++ b/lib/gitflow-test.sh @@ -89,7 +89,7 @@ echo x >> README.md; git add README.md chk "block direct code on main" '! git commit -q -m onmain 2>/dev/null' git restore --staged README.md 2>/dev/null; git checkout -q -- README.md mkdir -p .claude/memory; echo m > .claude/memory/decisions.md; git add .claude/memory/decisions.md -chk "allow .claude/** on main" 'git commit -q -m "chore(memory)" 2>/dev/null' +chk "allow .claude/memory on main" 'git commit -q -m "chore(memory)" 2>/dev/null' gitflow_start feature demo >/dev/null 2>&1 echo f > feat.txt; git add feat.txt chk "allow code on feature" 'git commit -q -m "feat work" 2>/dev/null' @@ -474,6 +474,29 @@ git config gitflow.protect false chk "T21c gitflow.protect=false → allowed" '.githooks/pre-commit 2>/dev/null' git config --unset gitflow.protect git restore --staged code.txt .githooks/post-merge 2>/dev/null || true +git reset -q; rm -f code.txt +# allowlist (memory, tasks, audits, deploy, .githooks): any other .claude/ path blocks +mkdir -p .claude/rules .claude/tasks .claude/memory .claude/audits .claude/deploy +echo r > .claude/rules/x.md; echo '{}' > .claude/settings.json +git add .claude/rules/x.md; git -c core.hooksPath=/dev/null commit -q -m "seed rules" +echo r2 >> .claude/rules/x.md; git add .claude/rules/x.md +chk "T21d .claude/rules-only on develop → blocked" '! .githooks/pre-commit 2>/dev/null' +git reset -q; git checkout -q -- .claude/rules/x.md +git add .claude/settings.json +chk "T21e .claude/settings.json-only on develop → blocked" '! .githooks/pre-commit 2>/dev/null' +git reset -q +git mv .claude/rules/x.md .claude/tasks/x.md +chk "T21f rename rules→tasks on develop → blocked (--no-renames)" '! .githooks/pre-commit 2>/dev/null' +git reset -q --hard +for d in memory tasks audits deploy; do + echo "$d" > ".claude/$d/n.md"; git add ".claude/$d/n.md" + chk "T21g .claude/$d-only on develop → allowed" '.githooks/pre-commit 2>/dev/null' + git reset -q +done +echo m > .claude/memory/n.md; echo r3 >> .claude/rules/x.md +git add .claude/memory/n.md .claude/rules/x.md +chk "T21h memory + rules mix on develop → blocked" '! .githooks/pre-commit 2>/dev/null' +git reset -q --hard echo "T22 — delete guard: never main/develop, never unmerged (premise: -d is dead once the upstream is in sync)" newrepo delguard; echo a>a; hookon; gitflow_init >/dev/null 2>&1 diff --git a/lib/gitflow.sh b/lib/gitflow.sh index 9cabaa8..115df39 100644 --- a/lib/gitflow.sh +++ b/lib/gitflow.sh @@ -485,15 +485,17 @@ case "\$br" in *) exit 0 ;; # working branch — allow esac -# whitelist: all-staged-under-.claude/ (memory/doc/deploy helpers) or -# .githooks/ (the hooks themselves, refreshed by the lib) — allow -if [ -z "\$(git diff --cached --name-only | grep -vE '^\.(claude|githooks)/' | head -1)" ]; then +# whitelist: every staged path under .claude/{memory,tasks,audits,deploy}/ or +# .githooks/ (memory/doc/deploy helpers, the hooks themselves) — allow. Rules, +# settings, agents, skills stay blocked. --no-renames lists a rename's source +# too, so a git mv out of a blocked path cannot hide. +if [ -z "\$(git diff --cached --name-only --no-renames | grep -vE '^(\.claude/(memory|tasks|audits|deploy)|\.githooks)/' | head -1)" ]; then exit 0 fi echo "gitflow pre-commit: BLOCKED — direct commit on '\$br'." >&2 echo " Branch from the right base (feature/bugfix->develop, hotfix->main), or merge." >&2 -echo " (.claude/** and .githooks/** commits are exempt; foreign clone? git config gitflow.protect false)" >&2 +echo " (.claude/{memory,tasks,audits,deploy}/ and .githooks/ commits are exempt; foreign clone? git config gitflow.protect false)" >&2 exit 1 HOOK } diff --git a/settings.json b/settings.json index c587a15..ea95232 100644 --- a/settings.json +++ b/settings.json @@ -605,7 +605,7 @@ "**Repository visibility**: private. The Gitea instance is self-hosted and not publicly indexed, and a checkout with no remote is local-only. Treat every repo here as private unless its remote points at a public host.", "**Trusted repo**: the checkout Claude Code is currently working in, under `/home/bchanot/Documents/`. No single repo is privileged over the others — read the current one, do not assume a previous session's project.", "**Trusted internal domains**: `git.bchanot.fr` (self-hosted Gitea). It is the only internal service.", - "**Default / protected branches**: gitflow. `main` (prod) and `develop` (integration) are protected: a per-repo pre-commit hook refuses code commits on either (exempting `.claude/**` and merges) and Gitea enforces branch protection on both. Neither is ever deleted or renamed: a reference-transaction hook vetoes it at the ref layer, and a working branch is deleted only by `gitflow.sh finish` or `gitflow.sh delete` after an explicit merged-into-develop-or-main check, the `origin/` copy going with it under the same check on its tip. Work lands on `feature/*`, `bugfix/*`, `chore/*`, `release/*`, `hotfix/*`.", + "**Default / protected branches**: gitflow. `main` (prod) and `develop` (integration) are protected: a per-repo pre-commit hook refuses code commits on either (exempting the `.claude/{memory,tasks,audits,deploy}/` allowlist and merges) and Gitea enforces branch protection on both. Neither is ever deleted or renamed: a reference-transaction hook vetoes it at the ref layer, and a working branch is deleted only by `gitflow.sh finish` or `gitflow.sh delete` after an explicit merged-into-develop-or-main check, the `origin/` copy going with it under the same check on its tip. Work lands on `feature/*`, `bugfix/*`, `chore/*`, `release/*`, `hotfix/*`.", "**Secrets management**: `~/.claude/.env` is the single source of truth and lives outside every git tree; repos reach it through a gitignored symlink. Only `.env.example`, holding placeholders, is ever tracked. A real secret inside a repo is a defect, not a configuration.", "**Internal sharing / snippet hosting**: none. Public paste, gist and pastebin services are outside the trust boundary.", "**CI/CD deploy targets**: no CI system. Deploys run out of band by the user, from a per-project runbook that Claude writes or explains (typically lftp/FTP to OVH mutualised hosting for web projects). Claude never runs a deploy or a transfer tool; nothing deploys automatically on a push or a merge.",