T-RQU1-worktree-scope-guard-downstream-setup
Status: planning/proposed · Impact: medium · Complexity: small
The worktree-scope-guard pre-commit hook
(T-1CL4-worktree-scope-guard-pre-commit) protects the
main checkout from cross-worktree edits, but today its activation
(brew install lefthook + lefthook install + the lefthook.yml
entry) lives only in this repo. Downstream projects that adopt the
SDLC plugin run the same /sdlc:task-work flow with the same
worktree-collision risk, but get none of the guard. Closing the gap
makes the guard a plugin-level guarantee rather than a per-project
hand-roll.
The guard ships as plugin/scripts/worktree_scope_guard.ts plus a
companion plugin/conventions/worktree-scope-guard.md. Activation
in this repo is wired by lefthook.yml at the project root:
pre-commit: commands: worktree-scope-guard: run: bun run plugin/scripts/worktree_scope_guard.ts/sdlc:setup (plugin/skills/setup/SKILL.md +
plugin/skills/setup/setup_planning.ts) currently seeds
docs/planning/<type>/ directories and the canonical .gitignore
un-ignore block for .claude/, but does NOT touch lefthook.yml
or check for lefthook’s presence. A fresh downstream project that
adopts the plugin therefore has the script available under
plugin/scripts/ (vendored or referenced) but no hook wiring and
no install hint — the protection is silently absent. PR #78
surfaced this via review.
Proposed
Section titled “Proposed”/sdlc:setup becomes responsible for ensuring the worktree-scope-guard
pre-commit hook is wired in every downstream project:
- If
lefthook.ymlis absent, create it with just the worktree-scope-guardpre-commitblock (sibling pre-commit hooks from sister tasks like T-A5H1-lefthook-project-check-pre-commit merge in non-destructively when they land). - If
lefthook.ymlexists and the block is missing, patch it in idempotently, leaving other hooks intact. - Report
lefthookbinary presence with an install hint (brew install lefthookon macOS, equivalent for other platforms) and the per-checkoutlefthook installstep. Do NOT auto-install the binary. - Document the guard’s contract and the setup behavior in
plugin/skills/setup/SKILL.mdand refer to it fromplugin/conventions/worktree-scope-guard.md.
Approach
Section titled “Approach”- Extend
plugin/skills/setup/setup_planning.tswith a--with-worktree-scope-guardstep (on by default). Reuse the block-detection pattern already shipped for the.gitignoreun-ignore work (T-AWEM-sdlc-setup-seeds-hooks-gitignore-unignore): readlefthook.yml, look for a fenced# --- worktree-scope-guard ---marker, insert/patch the block. - Plumb the new write path through
--dry-runso the existing flag’s semantics (“no writes anywhere”) still hold. - Update
plugin/skills/setup/SKILL.mdanddocs/skills/setup.md(flowchart) to mention the new step. The skill-doc-drift hook will flag drift if missed. - Add a paragraph to
plugin/conventions/worktree-scope-guard.mdpointing at/sdlc:setupas the canonical activation path for downstream consumers; demote the manualbrew install/lefthook installrecipe inlefthook.ymlto a “if you’re wiring this by hand” footnote. - Cover with a fixture-based test under
plugin/skills/setup/tests/: fresh project (nolefthook.yml), project withlefthook.ymlbut no guard block, project with guard block fully populated (no-op).
Files to touch
Section titled “Files to touch”| Location | Kind | Change |
|---|---|---|
plugin/skills/setup/setup_planning.ts | modify | add lefthook-block |
plugin/skills/setup/SKILL.md | new | document the new side-effect. |
docs/skills/setup.md | modify | flowchart refresh. |
plugin/conventions/worktree-scope-guard.md | modify | point at |
lefthook.yml (this repo’s) | modify | demote the manual-install |
plugin/skills/setup/tests/ | modify | fixtures for the three cases. |
Acceptance criteria
Section titled “Acceptance criteria”- AC-1:
/sdlc:setupon a project with nolefthook.ymlcreates one containing the worktree-scope-guard pre-commit block. - AC-2:
/sdlc:setupon a project whoselefthook.ymllacks the guard block inserts it and leaves all other hooks byte-identical. - AC-3:
/sdlc:setup --dry-runreports what would change inlefthook.ymlbut does not write. - AC-4:
/sdlc:setupreportslefthookbinary presence with a platform-appropriate install hint when missing; exits 0 either way (the hook wiring is still written so the guard activates once the operator installs lefthook).
Out of scope
Section titled “Out of scope”- Auto-installing the
lefthookbinary. The skill nudges; the operator runsbrew install lefthook. - Merging multiple project-level pre-commit hooks into a single canonical block — that’s T-A5H1-lefthook-project-check-pre-commit’s remit and they should land independently.
Dependencies
Section titled “Dependencies”- none
Discovery context
Section titled “Discovery context”Spawned by PR #78 review comment from @sksizer asking whether the
worktree-scope-guard hook should apply to downstream consumers,
and suggesting the setup skill (or a sibling deterministic script)
own its activation. The hook protects against a generic
/sdlc:task-work failure mode, so it belongs at the plugin level,
not per-project.