Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .claude/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ Hooks run before tool execution. Defined in `settings.json`, scripts in `hooks/`

## Skills

| Skill | Invocation | Purpose |
| --------------- | ----------------------------------- | ----------------------------------------------------------------------------- |
| `work-on-issue` | `/work-on-issue <github-issue-url>` | Full issue lifecycle: triage → worktree → plan mode → implement → verify → PR |
| Skill | Invocation | Purpose |
| --------------- | ------------------------------- | ----------------------------------------------------------------------------- |
| `work-on-issue` | `/work-on-issue <issue-number>` | Full issue lifecycle: triage → worktree → plan mode → implement → verify → PR |

Skill definitions live in `skills/<name>/SKILL.md`.

`work-on-issue` calls GitHub through an MCP server registered as `github` (tools are named `mcp__github__*`). The repo does not commit an `.mcp.json`, so register the server yourself, per user, for example with `claude mcp add` at user or local scope, under the name `github`. Without it the skill cannot run end to end.

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.
Expand Down
53 changes: 32 additions & 21 deletions .claude/skills/work-on-issue/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ 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)

---

## Step 1 — Fetch Issue Context

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

Expand Down Expand Up @@ -82,14 +82,14 @@ 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
<type>: <short description>

<body explaining what and why>

Closes #$ARGUMENTS

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
```

Use the appropriate type: `feat`, `fix`, `docs`, `style`, `refactor`, `test`, `chore`.
Expand All @@ -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
Expand Down Expand Up @@ -129,43 +129,54 @@ 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` subcommands for workflow runs are not blocked, so use them to wait.

```
gh pr checks <PR-number> --repo The-Read-Onlys/cscs.dev --watch
The GitHub Actions `build` job is a check run. `get_status` returns only legacy commit statuses (here, the Netlify deploy preview), so take the Actions result from `gh run watch --exit-status` and its logs from `gh run view`.

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, for up to 2 minutes; if no run for the current commit appears by then, stop and report to the user. A run with conclusion `cancelled` for an older commit was superseded by the concurrency group, so ignore it and look for the run for the current commit:

```bash
gh run list --repo brazostech/cscs.dev --branch "$(git branch --show-current)" --limit 1 --json databaseId,status,conclusion,headSha
```

2. **If all checks pass** → proceed to Step 10.
If the run for the current commit itself ends `cancelled`, re-run it once with `gh run rerun <run-id> --repo brazostech/cscs.dev`, then watch the new run. If it is cancelled again, report it to the user.

3. **If any check fails** (max 3 fix attempts):
a. Identify failures:
2. Wait for that run to finish. A run can outlast the Bash tool's timeout, so run the command with the longest timeout available, or in the background:

```
gh pr checks <PR-number> --repo The-Read-Onlys/cscs.dev --json name,state,bucket
```bash
gh run watch <run-id> --repo brazostech/cscs.dev --exit-status
```

b. Get failure logs:
If the command times out before the run ends, list the run again and watch it again, or poll its state with `gh run view <run-id> --repo brazostech/cscs.dev --json status,conclusion`.

```
gh run view <run-id> --repo The-Read-Onlys/cscs.dev --log-failed
3. Read the external statuses, such as the Netlify deploy preview, which `gh run` does not show: call `mcp__github__pull_request_read` with method `get_status`, owner `brazostech`, repo `cscs.dev`, pullNumber `<PR-number>`. For check-run details, call the same tool with method `get_check_runs`. If a status is still pending, wait a minute and call it again, for at most 10 minutes. After that, report the pending status to the user instead of waiting longer.

4. **If all checks pass** → proceed to Step 10.

5. **If any check fails** (max 3 fix attempts):
a. Identify the failure: a failed `gh run watch` is the Actions `build` job; a failed or errored status from `get_status` is an external check such as Netlify.
b. For an Actions failure, get the logs:

```bash
gh run view <run-id> --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 <check-name>`, 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.

---

## Step 10 — Cleanup

Ask the user: "Should I close issue #$ARGUMENTS now, or let the PR merge close it automatically?"

- If close now → `mcp__github__issue_write` with method `update`, state `closed`, state_reason `completed`
- If close now → `mcp__github__issue_write` with method `update`, owner `brazostech`, repo `cscs.dev`, issue_number `$ARGUMENTS`, state `closed`, state_reason `completed`
- If let PR close it → confirm the `Closes #$ARGUMENTS` reference is in the PR body (it is from Step 8)

---
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ jobs:
grep -Eq "^[[:space:]]*POCKETBASE_VERSION:[[:space:]]*\"?${pb//./\\.}\"?[[:space:]]*$" podman-compose.yaml \
|| { echo "POCKETBASE_VERSION in podman-compose.yaml does not match Containerfile (${pb})"; exit 1; }

- name: Test agent hooks
run: scripts/test-agent-hooks.sh

- name: Install dependencies
run: npm ci

Expand Down
7 changes: 4 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
```

Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions doc/adr/0009-ci-cd-github-actions-and-netlify.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,8 @@ 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 runs a `Test agent hooks` step, before `npm ci`, 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.
- The step gates merges: editing any `SKILL.md` under `.claude/skills/`, `.claude/settings.json` or the `prefer-github-mcp.sh` hook can now fail the required `build` check.
Loading
Loading