Skip to content

Commit 756284f

Browse files
committed
chore(docs): add branch-name validation guidance across skills, agents, and hook script
Update four files plus the git hooks migration spec to prevent committing under a wrong, closed, or non-existent issue number: - create-feature-branch/SKILL.md: validation step before branch creation - run-pre-commit-checks/SKILL.md: manual check for branch name validity - committer.agent.md: step 2 validates branch name against open specs - pre-commit.sh: TODO referencing #1843 for future Rust automation - 1843-migrate-git-hooks-scripts-from-bash-to-rust.md: add T22 + AC22, cross-reference related artifacts
1 parent 73263e9 commit 756284f

5 files changed

Lines changed: 57 additions & 16 deletions

File tree

.github/agents/committer.agent.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,21 @@ Treat every commit request as a review-and-verify workflow, not as a blind reque
3131
- Verify that the spec's progress notes or task list reflect the current state.
3232
- If the spec is out of date, stop and ask the caller to update it before proceeding.
3333
Do not commit with a stale spec.
34-
2. Read the current branch, `git status`, and the staged or unstaged diff relevant to the request.
35-
3. Summarize the intended commit scope before taking action.
36-
4. Ensure the commit scope is coherent and does not accidentally mix unrelated changes.
37-
5. Check for obvious repository-policy violations in the diff (for example missing required spec
34+
2. **Validate the branch name.** If the current branch name starts with an issue number prefix
35+
(e.g., `42-some-description`), verify that `docs/issues/open/` contains a matching spec
36+
(file or directory starting with that number). If no match is found:
37+
- The issue may be closed — check `docs/issues/closed/`; if found, the branch should be
38+
on a different base or renamed.
39+
- The issue may not exist at all — the branch name is likely wrong. Ask the caller to
40+
confirm or rename using a `chore/` prefix for untracked work.
41+
- This prevents committing under a wrong/missing issue number.
42+
3. Read the current branch, `git status`, and the staged or unstaged diff relevant to the request.
43+
4. Summarize the intended commit scope before taking action.
44+
5. Ensure the commit scope is coherent and does not accidentally mix unrelated changes.
45+
6. Check for obvious repository-policy violations in the diff (for example missing required spec
3846
progress updates, missing documented rationale where required, or similar policy blockers).
3947
If found, stop and return to the Implementer/Reviewer before committing.
40-
6. **Check if the pre-commit git hook is already installed** before running checks manually:
48+
7. **Check if the pre-commit git hook is already installed** before running checks manually:
4149

4250
```bash
4351
./contrib/dev-tools/git/check-git-hooks.sh
@@ -53,9 +61,9 @@ Treat every commit request as a review-and-verify workflow, not as a blind reque
5361
- **You must not fix**: build failures, test failures, logic errors, or runtime issues.
5462
These are implementation defects; stop and return them to the **Implementer** to resolve.
5563

56-
7. Propose a precise Conventional Commit message.
57-
8. Create the commit with `git commit -S` only after the scope is clear and blockers are resolved.
58-
9. After committing, run a quick verification check and report the resulting commit summary.
64+
8. Propose a precise Conventional Commit message.
65+
9. Create the commit with `git commit -S` only after the scope is clear and blockers are resolved.
66+
10. After committing, run a quick verification check and report the resulting commit summary.
5967

6068
## Constraints
6169

.github/skills/dev/git-workflow/create-feature-branch/SKILL.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,23 @@ git checkout -b 42-add-peer-expiry-grace-period
7878
- `fix_bug` — underscores instead of hyphens
7979
- `42_add_support` — underscores
8080

81+
## Branch Name Validation
82+
83+
Before creating a branch, verify that the issue number (if used) actually exists as an open issue
84+
spec in `docs/issues/open/`:
85+
86+
```bash
87+
# When creating a branch with an issue-number prefix, verify the spec exists:
88+
ISSUE_NUM=42
89+
if [ ! -d "docs/issues/open/${ISSUE_NUM}-*" ] && \
90+
[ ! -f "docs/issues/open/${ISSUE_NUM}-*" ]; then
91+
echo "WARNING: No open issue spec found for #${ISSUE_NUM} in docs/issues/open/."
92+
echo "Either use a chore/ prefix for untracked maintenance, or confirm the issue exists."
93+
fi
94+
```
95+
96+
This prevents accidentally referencing a wrong, closed, or non-existent issue number.
97+
8198
## Complete Branch Lifecycle
8299

83100
### 1. Create Branch from `develop`

.github/skills/dev/git-workflow/run-pre-commit-checks/SKILL.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ Verify these by hand before committing:
114114
- **Documentation updated**: if public API or behaviour changed, doc comments and `docs/` pages reflect it
115115
- **`AGENTS.md` updated**: if architecture or key workflows changed, the relevant `AGENTS.md` is updated
116116
- **New technical terms in `project-words.txt`**: new jargon added alphabetically
117+
- **Branch name validation**: if the branch uses an issue-number prefix (e.g. `42-some-description`),
118+
verify that `docs/issues/open/` contains a matching spec file or directory. This prevents committing
119+
under a non-existent, closed, or wrong issue number.
120+
- **Future**: a `TODO` is recorded in `contrib/dev-tools/git/hooks/pre-commit.sh` to automate this
121+
check. Until then, AI agents must verify branch names manually (see the committer agent spec).
117122
118123
## Before Opening a PR (Recommended)
119124

contrib/dev-tools/git/hooks/pre-commit.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
# AI agents: set a per-command timeout of at least 3 minutes before invoking this script.
1010
#
1111
# All steps must pass (exit 0) before committing.
12+
#
13+
# TODO: Implement branch-name validation in the Rust git-hooks binary (#1843).
14+
# When the branch uses an issue-number prefix (e.g. "42-some-description"), verify that
15+
# docs/issues/open/ contains a matching spec file or directory starting with that number.
16+
# This prevents committing under a wrong, closed, or non-existent issue number.
17+
# See also: docs/issues/open/1843-migrate-git-hooks-scripts-from-bash-to-rust.md
1218

1319
set -uo pipefail
1420

docs/issues/open/1843-migrate-git-hooks-scripts-from-bash-to-rust.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ semantic-links:
1919
- .githooks/pre-push
2020
- .github/workflows/copilot-setup-steps.yml
2121
- docs/adrs/20260519000000_define_global_cli_output_contract.md
22+
- docs/issues/open/1774-automate-cleanup-completed-issues-skill-script.md
23+
- .github/skills/dev/git-workflow/create-feature-branch/SKILL.md
24+
- .github/agents/committer.agent.md
2225
---
2326

2427
<!-- skill-link: create-issue -->
@@ -210,14 +213,15 @@ Bash scripts are removed. **Phase 2** adds new capabilities on top of the alread
210213

211214
### Phase 2 — Enhancements (new features not present in the original Bash scripts)
212215

213-
| ID | Status | Task | Notes / Expected Output |
214-
| --- | ------ | ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
215-
| T17 | TODO | Implement heartbeat emitter | Background ticker fires every 20–30s while a step is running; emits `heartbeat` NDJSON event (step name, elapsed seconds); extends T3 schema |
216-
| T18 | TODO | Implement staged file type analysis and smart step selection | `git diff --cached --name-only`; classify changeset (Markdown-only / docs-only / mixed); skip inapplicable steps; emit `step_skip` NDJSON events for skipped steps; extends T3 schema |
217-
| T19 | TODO | Implement pre-commit idempotency cache | Compute staged tree SHA (`git write-tree`) + step-config hash; check/write `.git/torrust-hooks/pre-commit-cache`; exit 0 immediately on cache hit |
218-
| T20 | TODO | Implement pre-push idempotency cache | Check/write per-commit-SHA records in `.git/torrust-hooks/pre-push-cache`; exit 0 immediately when all pushed commits have passing records |
219-
| T21 | TODO | Add Phase 2 unit and integration tests | Cover: heartbeat timing and event shape, staged file classification, smart step selection, cache read/write/invalidation, cache-and-smart-skip interaction |
220-
| T22 | TODO | Verify Phase 2 quality gates | `linter all`, full test suite; all Phase 2 ACs met |
216+
| ID | Status | Task | Notes / Expected Output |
217+
| --- | ------ | ------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
218+
| T17 | TODO | Implement heartbeat emitter | Background ticker fires every 20–30s while a step is running; emits `heartbeat` NDJSON event (step name, elapsed seconds); extends T3 schema |
219+
| T18 | TODO | Implement staged file type analysis and smart step selection | `git diff --cached --name-only`; classify changeset (Markdown-only / docs-only / mixed); skip inapplicable steps; emit `step_skip` NDJSON events for skipped steps; extends T3 schema |
220+
| T19 | TODO | Implement pre-commit idempotency cache | Compute staged tree SHA (`git write-tree`) + step-config hash; check/write `.git/torrust-hooks/pre-commit-cache`; exit 0 immediately on cache hit |
221+
| T20 | TODO | Implement pre-push idempotency cache | Check/write per-commit-SHA records in `.git/torrust-hooks/pre-push-cache`; exit 0 immediately when all pushed commits have passing records |
222+
| T21 | TODO | Add Phase 2 unit and integration tests | Cover: heartbeat timing and event shape, staged file classification, smart step selection, cache read/write/invalidation, cache-and-smart-skip interaction |
223+
| T22 | TODO | Implement branch-name validation | When the branch uses an issue-number prefix (e.g. `42-some-description`), verify that `docs/issues/open/` contains a matching spec file or directory. If none found, emit a warning event and optionally block the commit. Prevents committing under a wrong, closed, or non-existent issue number. See `docs/issues/open/1774-automate-cleanup-completed-issues-skill-script.md` for context |
224+
| T23 | TODO | Verify Phase 2 quality gates | `linter all`, full test suite; all Phase 2 ACs met |
221225

222226
## Progress Tracking
223227

@@ -267,6 +271,7 @@ Bash scripts are removed. **Phase 2** adds new capabilities on top of the alread
267271
- [ ] AC19: When only `*.md` files (and documentation-adjacent files) are staged, `pre-commit` skips Rust-specific steps and runs only markdown-relevant linters; a `step_skip` NDJSON event is emitted for each skipped step
268272
- [ ] AC20: A second `torrust-git-hooks pre-commit` invocation with an unchanged staged tree (same `git write-tree` SHA and step config) exits 0 immediately without re-running any step
269273
- [ ] AC21: A `torrust-git-hooks pre-push` invocation where all commits in the push already have passing cache records exits 0 immediately without re-running any step
274+
- [ ] AC22: When the current branch has an issue-number prefix (e.g. `42-some-description`), the `pre-commit` subcommand verifies that a matching spec exists in `docs/issues/open/`. If none is found, it emits a warning event and blocks the commit with exit code 1.
270275

271276
## Verification Plan
272277

0 commit comments

Comments
 (0)