From 53b430becdef5cc5693b080189ae2dae5e9c8bef Mon Sep 17 00:00:00 2001 From: Jack Hall Date: Mon, 2 Nov 2026 18:15:25 -0600 Subject: [PATCH 1/4] fix(agents): make work-on-issue pass the repo hooks and update the org links The skill's CI step ran `gh pr checks`, which the repo's own prefer-github-mcp hook denies. Step 9 now reads check status through mcp__github__pull_request_read (get_status) and waits with `gh run list` and `gh run watch`, which the hook allows. The hook is unchanged. The skill hardcodes brazostech/cscs.dev instead of the old org. scripts/test-agent-hooks.sh extracts every command the skill instructs, feeds each through the hook, and expects no deny, with negative controls so it cannot pass vacuously. CI runs it in the build job. The GitHub links in the Hero, Footer and about page point at the brazostech org. The .claude README usage line takes an issue number. Closes: #88 Refs: #90 Co-Authored-By: Claude Opus 5.5 --- .claude/README.md | 8 +- .claude/skills/work-on-issue/SKILL.md | 45 ++++--- .github/workflows/ci.yml | 3 + AGENTS.md | 7 +- .../0009-ci-cd-github-actions-and-netlify.md | 4 + scripts/test-agent-hooks.sh | 121 ++++++++++++++++++ src/components/Footer.tsx | 2 +- src/components/Hero.tsx | 2 +- src/pages/about.astro | 2 +- 9 files changed, 165 insertions(+), 29 deletions(-) create mode 100755 scripts/test-agent-hooks.sh diff --git a/.claude/README.md b/.claude/README.md index 1434d5d..b533d54 100644 --- a/.claude/README.md +++ b/.claude/README.md @@ -21,12 +21,14 @@ Hooks run before tool execution. Defined in `settings.json`, scripts in `hooks/` ## Skills -| Skill | Invocation | Purpose | -| --------------- | ----------------------------------- | ----------------------------------------------------------------------------- | -| `work-on-issue` | `/work-on-issue ` | Full issue lifecycle: triage → worktree → plan mode → implement → verify → PR | +| Skill | Invocation | Purpose | +| --------------- | ------------------------------- | ----------------------------------------------------------------------------- | +| `work-on-issue` | `/work-on-issue ` | Full issue lifecycle: triage → worktree → plan mode → implement → verify → PR | Skill definitions live in `skills//SKILL.md`. +Every shell command a skill tells an agent to run must pass the hooks. `scripts/test-agent-hooks.sh` extracts the commands from `work-on-issue/SKILL.md`, feeds each through `prefer-github-mcp.sh`, and fails on any deny. CI runs it. GitHub reads and writes go through the GitHub MCP tools; the skill waits on CI with `gh run list` and `gh run watch`, which the hook does not block. + ## Worktrees All implementation work happens in `.claude/worktrees/` (gitignored). `EnterWorktree` creates them automatically. One worktree per unit of work. diff --git a/.claude/skills/work-on-issue/SKILL.md b/.claude/skills/work-on-issue/SKILL.md index 4c9f86e..7db9e36 100644 --- a/.claude/skills/work-on-issue/SKILL.md +++ b/.claude/skills/work-on-issue/SKILL.md @@ -9,8 +9,8 @@ argument-hint: "[issue-number]" Complete workflow to take a GitHub issue from triage to pull request. -**Repository**: `The-Read-Onlys/cscs.dev` -**Issue number**: `$ARGUMENTS` (required — abort with a clear message if empty) +**Repository**: `brazostech/cscs.dev` (owner `brazostech`, repo `cscs.dev`). Use these literal values in every GitHub call below. +**Issue number**: `$ARGUMENTS` (required, a bare issue number such as `88` — abort with a clear message if empty) --- @@ -18,7 +18,7 @@ Complete workflow to take a GitHub issue from triage to pull request. Gather all issue details in parallel: -- `mcp__github__issue_read` with method `get`, owner `The-Read-Onlys`, repo `cscs.dev`, issue_number `$ARGUMENTS` +- `mcp__github__issue_read` with method `get`, owner `brazostech`, repo `cscs.dev`, issue_number `$ARGUMENTS` - `mcp__github__issue_read` with method `get_comments`, same owner/repo/issue_number - `mcp__github__issue_read` with method `get_labels`, same owner/repo/issue_number @@ -82,7 +82,7 @@ If build or lint fails, fix the errors and re-run from the failing step. Do not 2. Stage **specific files** (never `git add -A`) 3. Create a commit with a conventional commit message: -``` +```text : @@ -100,7 +100,7 @@ Use the appropriate type: `feat`, `fix`, `docs`, `style`, `refactor`, `test`, `c 1. Push the branch: `git push -u origin HEAD` 2. Create the PR using `mcp__github__create_pull_request`: - - owner: `The-Read-Onlys` + - owner: `brazostech` - repo: `cscs.dev` - title: Short description (under 70 chars) - head: current branch name @@ -129,35 +129,40 @@ Generated with [Claude Code](https://claude.com/claude-code) ## Step 9 — Monitor CI -After the PR is created, wait for CI checks to complete and fix any failures. +After the PR is created, wait for CI to complete and fix any failures. -1. Watch for CI completion: +The repo's hook denies the `gh` subcommands for pull requests, issues and search, so read PR status through the GitHub MCP server. The `gh run` subcommands are not blocked, so use them to wait. - ``` - gh pr checks --repo The-Read-Onlys/cscs.dev --watch - ``` +1. Find the workflow run for the pushed commit. If the list is empty or its `headSha` differs from `git rev-parse HEAD`, wait a few seconds and list again: -2. **If all checks pass** → proceed to Step 10. + ```bash + gh run list --repo brazostech/cscs.dev --branch "$(git branch --show-current)" --limit 1 --json databaseId,status,conclusion,headSha + ``` -3. **If any check fails** (max 3 fix attempts): - a. Identify failures: +2. Wait for that run to finish: - ``` - gh pr checks --repo The-Read-Onlys/cscs.dev --json name,state,bucket + ```bash + gh run watch --repo brazostech/cscs.dev --exit-status ``` - b. Get failure logs: +3. Read the status of every check, including external ones such as the Netlify deploy preview that `gh run` does not show: call `mcp__github__pull_request_read` with method `get_status`, owner `brazostech`, repo `cscs.dev`, pullNumber ``. If a check is still pending, wait a minute and call it again. - ``` - gh run view --repo The-Read-Onlys/cscs.dev --log-failed +4. **If all checks pass** → proceed to Step 10. + +5. **If any check fails** (max 3 fix attempts): + a. Identify the failing check from the `get_status` result. + b. For a GitHub Actions failure, get the logs: + + ```bash + gh run view --repo brazostech/cscs.dev --log-failed ``` c. Fix the failures in the worktree. d. Re-run Step 6 (Verify) locally to confirm the fix. e. Stage specific files, commit with a message like `fix: resolve CI failure in `, and push. - f. Loop back to watch CI again (step 9.1). + f. Loop back to find the new run (step 9.1) and watch it. -4. **If still failing after 3 attempts** → tell the user, provide the PR URL and failing check details, and proceed to Step 10. +6. **If still failing after 3 attempts** → tell the user, provide the PR URL and failing check details, and proceed to Step 10. --- diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d756f1b..1af8db0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -104,3 +104,6 @@ jobs: - name: Build Storybook run: npm run build-storybook + + - name: Test agent hooks + run: scripts/test-agent-hooks.sh diff --git a/AGENTS.md b/AGENTS.md index b7297e5..1ee646f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -6,7 +6,7 @@ Instructions for AI coding agents. `CLAUDE.md` is a symlink to this file. - **Project**: CSCS community website — Astro 7 + React 19, Tailwind CSS v4, PocketBase backend, Catalyst UI Kit - **Worktree required**: All implementation work must happen in a git worktree. Use `EnterWorktree` before editing project files. A hook enforces this. -- **GitHub MCP tools**: Use MCP tools (not `gh` CLI) for PRs, issues, etc. A hook redirects `gh` commands. +- **GitHub MCP tools**: Use MCP tools (not `gh` CLI) for PRs, issues, etc. A hook redirects `gh pr`, `gh issue` and `gh search`. `gh run list`, `gh run watch` and `gh run view` are allowed for waiting on CI and reading logs. - **Package manager**: npm only (yarn/pnpm/bun are denied by settings) ## Commands @@ -23,6 +23,7 @@ npm run test:run # Vitest (single run) npm run test:pb # PocketBase API rule tests (downloads PocketBase v0.34.0) npm run test:coverage # Vitest with v8 coverage npm run build-storybook # Build Storybook +scripts/test-agent-hooks.sh # Checks the work-on-issue skill's commands pass the .claude hooks (needs jq) make -C backend pocketbase # Install the pinned PocketBase at backend/pocketbase (gitignored, not committed) ``` @@ -139,7 +140,7 @@ Store dates as text (`YYYY-MM-DD`). Parse with `new Date(year, month - 1, day)` - **Commits**: conventional commits — `feat:`, `fix:`, `chore:`, `docs:`. Brief subject line, body for "why". - **PRs**: create via GitHub MCP tools. Title under 70 chars. Body with `## Summary` and `## Test plan`. `main` takes changes only through PRs (ruleset, ADR 0012). - **Merging**: squash only. The PR title becomes the commit subject on `main`, so it must be a Conventional Commit; the body becomes the commit message. Branches delete on merge. -- **CI**: PRs run lint, format check, typecheck, tests, PocketBase API rule tests (`npm run test:pb`), build, Storybook build via GitHub Actions. The `build` job and Netlify's `deploy-preview` must both pass before merge. +- **CI**: PRs run lint, format check, typecheck, tests, PocketBase API rule tests (`npm run test:pb`), build, Storybook build, and the agent hook test via GitHub Actions. The `build` job and Netlify's `deploy-preview` must both pass before merge. ## Boundaries @@ -158,7 +159,7 @@ Store dates as text (`YYYY-MM-DD`). Parse with `new Date(year, month - 1, day)` - **Auth system details**: `doc/authentication.md` - **Project audit & known issues**: `doc/audit.md` - **Feature roadmap**: `doc/improvements.md` -- **CI pipeline**: `.github/workflows/ci.yml` (lint, format check, typecheck, test, PocketBase API rule tests, build, Storybook build) +- **CI pipeline**: `.github/workflows/ci.yml` (lint, format check, typecheck, test, PocketBase API rule tests, build, Storybook build, agent hook test) - **Hook & skill docs**: `.claude/README.md` ## Worktree Workflow diff --git a/doc/adr/0009-ci-cd-github-actions-and-netlify.md b/doc/adr/0009-ci-cd-github-actions-and-netlify.md index 9a168f6..72bb028 100644 --- a/doc/adr/0009-ci-cd-github-actions-and-netlify.md +++ b/doc/adr/0009-ci-cd-github-actions-and-netlify.md @@ -65,3 +65,7 @@ Netlify watches the same repository and deploys independently when it detects a - `check-latest` fails open: if setup-node cannot fetch the Node release manifest, it keeps the cached Node. The engines step then fails the job when that Node is too old, and the job needs a re-run. - The `Containerfile` and `netlify.toml` still state only the major version and float on `22`, as the #81 amendment notes. - Cost: when the cache is stale, setup-node downloads Node, which adds seconds to the run. + +## Amendment (2026-11-02, #88) + +- The `build` job ends with a `Test agent hooks` step that runs `scripts/test-agent-hooks.sh`. It extracts the shell commands in `.claude/skills/work-on-issue/SKILL.md` and fails if `.claude/hooks/prefer-github-mcp.sh` denies any of them. It needs `jq`, which ubuntu-latest provides. `permissions` is unchanged. diff --git a/scripts/test-agent-hooks.sh b/scripts/test-agent-hooks.sh new file mode 100755 index 0000000..a657b10 --- /dev/null +++ b/scripts/test-agent-hooks.sh @@ -0,0 +1,121 @@ +#!/usr/bin/env bash +# test-agent-hooks.sh — checks that the work-on-issue skill and the repo's +# PreToolUse hook agree. +# +# Extracts every shell command the skill tells an agent to run (fenced +# blocks other than ```markdown/```text/```json, and inline `gh|git|npm|...` code spans), feeds each +# one to .claude/hooks/prefer-github-mcp.sh as PreToolUse JSON, and expects no +# deny. Negative controls (commands the hook must deny) keep the test from +# passing vacuously. +# +# Usage: scripts/test-agent-hooks.sh [path/to/SKILL.md] +set -euo pipefail + +cd "$(dirname "$0")/.." + +HOOK=.claude/hooks/prefer-github-mcp.sh +SKILL=${1:-.claude/skills/work-on-issue/SKILL.md} + +command -v jq >/dev/null || { echo "jq is required" >&2; exit 2; } +[ -f "$SKILL" ] || { echo "skill not found: $SKILL" >&2; exit 2; } + +# Prints the hook's decision for a command: "deny", "ask", "allow", ... +decision() { + local out + out=$(jq -n --arg c "$1" '{tool_name: "Bash", tool_input: {command: $c}}' | "$HOOK") + # The hook prints nothing when it has no objection. + if [ -z "$out" ]; then + echo allow + else + jq -r '.hookSpecificOutput.permissionDecision // "allow"' <<<"$out" + fi +} + +failures=0 +check() { # check