Skip to content

Commit 0536ea0

Browse files
committed
Claude boilerplate (#52)
1 parent 0393d71 commit 0536ea0

File tree

3 files changed

+165
-40
lines changed

3 files changed

+165
-40
lines changed

.github/workflows/claude.yaml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Claude Assistant
2+
on:
3+
issue_comment:
4+
types: [created]
5+
pull_request_review_comment:
6+
types: [created]
7+
pull_request:
8+
types: [opened, synchronize] # opened = new PR, synchronize = new commits pushed
9+
issues:
10+
types: [opened, assigned]
11+
12+
permissions:
13+
contents: write
14+
pull-requests: write
15+
issues: write
16+
id-token: write
17+
actions: read # Required for Claude to read CI results on PRs
18+
19+
jobs:
20+
# Auto-review for same-repo PRs
21+
claude-review:
22+
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 1
28+
- uses: anthropics/claude-code-action@v1
29+
with:
30+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
31+
track_progress: true # ✨ Enables tracking comments
32+
claude_args: |
33+
--model opus \
34+
--allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*)"
35+
prompt: |
36+
REPO: ${{ github.repository }}
37+
PR NUMBER: ${{ github.event.pull_request.number }}
38+
39+
Act as a code reviewer for this pull request. Focus your review on:
40+
- Overall code quality and adherence to best practices
41+
- Possible bugs, edge cases, or logical errors
42+
- Security concerns or unsafe patterns
43+
- Performance characteristics and potential optimizations
44+
45+
Provide thorough, actionable feedback, and use inline comments for any line-specific issues you identify.
46+
47+
Note: The PR branch is already checked out in the current working directory.
48+
49+
Use `gh pr comment` for summary or top-level feedback on the PR.
50+
Use `mcp__github_inline_comment__create_inline_comment` to annotate specific code issues inline.
51+
Only post GitHub comments - don't submit review text as messages.
52+
Use top-level comments for general observations or praise.
53+
54+
# Manual review triggered by "@claude review" comment (works for forks too)
55+
claude-manual-review:
56+
if: |
57+
github.event_name == 'issue_comment' &&
58+
github.event.issue.pull_request &&
59+
contains(github.event.comment.body, '@claude review')
60+
runs-on: ubuntu-latest
61+
steps:
62+
- uses: actions/checkout@v4
63+
with:
64+
fetch-depth: 1
65+
- name: Checkout PR branch
66+
run: gh pr checkout ${{ github.event.issue.number }}
67+
env:
68+
GH_TOKEN: ${{ github.token }}
69+
- uses: anthropics/claude-code-action@v1
70+
with:
71+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
72+
track_progress: true # ✨ Enables tracking comments
73+
claude_args: |
74+
--model opus \
75+
--allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*)"
76+
prompt: |
77+
REPO: ${{ github.repository }}
78+
PR NUMBER: ${{ github.event.issue.number }}
79+
80+
Act as a code reviewer for this pull request. Focus your review on:
81+
- Overall code quality and adherence to best practices
82+
- Possible bugs, edge cases, or logical errors
83+
- Security concerns or unsafe patterns
84+
- Performance characteristics and potential optimizations
85+
86+
Provide thorough, actionable feedback, and use inline comments for any line-specific issues you identify.
87+
88+
Note: The PR branch is already checked out in the current working directory.
89+
90+
Use `gh pr comment` for summary or top-level feedback on the PR.
91+
Use `mcp__github_inline_comment__create_inline_comment` to annotate specific code issues inline.
92+
Only post GitHub comments - don't submit review text as messages.
93+
Use top-level comments for general observations or praise.
94+
95+
# General interactive mode - responds to @claude mentions (but NOT review requests on PRs)
96+
claude-response:
97+
if: |
98+
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude') && !contains(github.event.comment.body, '@claude review')) ||
99+
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude') && !contains(github.event.comment.body, '@claude review')) ||
100+
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude') && !contains(github.event.review.body, '@claude review')) ||
101+
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
102+
runs-on: ubuntu-latest
103+
steps:
104+
- uses: actions/checkout@v4
105+
with:
106+
fetch-depth: 1
107+
- uses: anthropics/claude-code-action@v1
108+
with:
109+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
110+
claude_args: |
111+
--model opus \
112+
--allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr create:*)"

AGENTS.md

Lines changed: 52 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,52 @@
1-
# Repository Guidelines
2-
3-
## Project Structure & Module Organization
4-
- Source layout: `cmd/cli` and `cmd/httpserver` are entrypoints; shared packages live in `common/`, `httpserver/`, `database/`, and `metrics/`.
5-
- Tests: co-located `*_test.go` files (e.g., `httpserver/handler_test.go`, `database/database_test.go`).
6-
- Artifacts: binaries output to `build/` via Makefile targets. Dockerfiles: `cli.dockerfile`, `httpserver.dockerfile`.
7-
- Go version: 1.24 (see `go.mod`). Module path: `github.com/flashbots/go-template`.
8-
9-
## Coding Style & Naming Conventions
10-
- Use tabs instead of spaces for indentation.
11-
- Always run `make fmt` and `make lint` (and `make test`) before committing.
12-
- Formatting: run `make fmt` before committing. Go files must pass `golangci-lint` (config in `.golangci.yaml`).
13-
- Style: idiomatic Go; exported identifiers use CamelCase; packages lower-case short names; errors returned, not panicked.
14-
- JSON tags: prefer snake_case (configured via `tagliatelle`).
15-
- Logging: use `common.SetupLogger` (slog) and structured fields; respect `--log-json` and `--log-debug` flags.
16-
17-
## Build, Test, and Development Commands
18-
- `make build`: builds CLI and HTTP server into `build/`.
19-
- `make build-cli` / `make build-httpserver`: build individual binaries.
20-
- `make lint`: run formatters and linters (`gofmt`, `gofumpt`, `go vet`, `staticcheck`, `golangci-lint`).
21-
- `make test` / `make test-race`: run tests (optionally with race detector).
22-
- `make fmt`: apply formatting (`gofmt`, `gci`, `gofumpt`) and `go mod tidy`.
23-
- `make cover` / `make cover-html`: coverage summary / HTML report.
24-
- Docker: `make docker-cli`, `make docker-httpserver` build images using the respective Dockerfiles.
25-
26-
## Testing Guidelines
27-
- Framework: standard `testing` with `testify/require` for assertions.
28-
- Run: `make test` (or `go test ./...`).
29-
- Database tests: gated by `RUN_DB_TESTS=1` and a Postgres instance. Example:
30-
- `docker run -d --name postgres-test -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres`
31-
- `RUN_DB_TESTS=1 make test`
32-
- Coverage: aim to keep or increase coverage; use `make cover`.
33-
34-
## Commit & Pull Request Guidelines
35-
- Commits: concise, imperative mood; scope prefixes like `ci:`, `docs:`, `fix:`, `feat:` when helpful. Reference issues/PRs.
36-
- PRs: include a clear description, linked issues, test plan (commands run), and any config notes. Ensure `make fmt lint test` pass locally.
37-
38-
## Security & Configuration Tips
39-
- Configuration: prefer flags/env via `common.GetEnv` and CLI options; avoid hardcoding secrets.
40-
- HTTP server: `/debug` (pprof) is opt-in; do not expose publicly. Metrics on `/metrics` (Prometheus format).
1+
This file provides guidance to LLMs when working with code in this repository.
2+
3+
## Build Commands
4+
5+
```bash
6+
make build-cli # Build CLI binary to ./build/cli
7+
make build-httpserver # Build HTTP server binary to ./build/httpserver
8+
make build # Build all binaries
9+
```
10+
11+
## Test Commands
12+
13+
```bash
14+
make test # Run all tests
15+
make test-race # Run tests with race detector
16+
go test ./... -run TestName # Run a single test
17+
18+
# Database tests require a running Postgres instance:
19+
docker run -d --name postgres-test -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=postgres postgres
20+
RUN_DB_TESTS=1 make test
21+
```
22+
23+
## Lint and Format
24+
25+
```bash
26+
make lint # Run all linters (gofmt, gofumpt, go vet, staticcheck, golangci-lint)
27+
make fmt # Format code (gofmt, gci, gofumpt, go mod tidy)
28+
make lt # Run both lint and test
29+
```
30+
31+
## Architecture
32+
33+
This is a Go project template with two entry points:
34+
35+
- **cmd/cli/main.go** - CLI application entry point using urfave/cli
36+
- **cmd/httpserver/main.go** - HTTP server entry point with graceful shutdown
37+
38+
### Key Packages
39+
40+
- **httpserver/** - HTTP server with chi router, includes `/livez`, `/readyz`, `/drain`, `/undrain` endpoints, metrics middleware, and optional pprof
41+
- **database/** - Postgres database layer using sqlx with sql-migrate for migrations
42+
- **database/migrations/** - In-memory migrations registered in `Migrations` variable
43+
- **metrics/** - VictoriaMetrics-based Prometheus metrics with HTTP middleware
44+
- **common/** - Shared utilities including structured logging setup (slog-based via httplog)
45+
46+
### HTTP Server Pattern
47+
48+
The server runs two HTTP servers: main API (default :8080) and metrics (default :8090). Supports graceful shutdown with configurable drain duration for load balancer compatibility.
49+
50+
### Database Migrations
51+
52+
Migrations are defined as Go code in `database/migrations/` and registered in `migrations.Migrations`. They run automatically on database connection unless `DB_DONT_APPLY_SCHEMA` env var is set.

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@AGENTS.md

0 commit comments

Comments
 (0)