Populate the Build & Test, Architecture Overview, and Conventions & Patterns sections of CLAUDE.md with context captured during the phase-1 implementation work. Highlights the non-obvious gotchas (http.Server.Shutdown not interrupting active conns; bd link direction; bd init auto-committing) so future sessions don't re-discover them. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
4.1 KiB
Project Instructions for AI Agents
This file provides instructions and context for AI coding agents working on this project.
Beads Issue Tracker
This project uses bd (beads) for issue tracking. Run bd prime to see full workflow context and commands.
Quick Reference
bd ready # Find available work
bd show <id> # View issue details
bd update <id> --claim # Claim work
bd close <id> # Complete work
Rules
- Use
bdfor ALL task tracking — do NOT use TodoWrite, TaskCreate, or markdown TODO lists - Run
bd primefor detailed command reference and session close protocol - Use
bd rememberfor persistent knowledge — do NOT use MEMORY.md files
Session Completion
When ending a work session, you MUST complete ALL steps below. Work is NOT complete until git push succeeds.
MANDATORY WORKFLOW:
- File issues for remaining work - Create issues for anything that needs follow-up
- Run quality gates (if code changed) - Tests, linters, builds
- Update issue status - Close finished work, update in-progress items
- PUSH TO REMOTE - This is MANDATORY:
git pull --rebase bd dolt push git push git status # MUST show "up to date with origin" - Clean up - Clear stashes, prune remote branches
- Verify - All changes committed AND pushed
- Hand off - Provide context for next session
CRITICAL RULES:
- Work is NOT complete until
git pushsucceeds - NEVER stop before pushing - that leaves work stranded locally
- NEVER say "ready to push when you are" - YOU must push
- If push fails, resolve and retry until it succeeds
Build & Test
make build—./fjmcp-brokerwith-trimpath+ ldflags-stamped build infomake test—go test -race ./...(includes integration tests undercmd/broker/)make lint—go vet;golangci-lintif installedmake tidy—go mod tidy./fjmcp-broker --version— inspect build info without supplying the rest of the config
Architecture Overview
OAuth 2.1 authorization-server facade that fronts forgejo-mcp: brokers the OAuth dance against Forgejo, then spawns a per-session forgejo-mcp --transport stdio subprocess with the authenticated user's token in env. Module path: kode.naiv.no/olemd/forgejo-mcp-broker.
Full design: docs/design.md. Phased plan: docs/plan.md.
Layout: cmd/broker/ → internal/config → internal/store → internal/httpserver, with internal/buildinfo (ldflags-stamped) and internal/log (slog) as shared utilities.
Conventions & Patterns
- SQLite driver:
modernc.org/sqlite(pure Go, no CGO). DSN pragmas via?_pragma=name(value). - Migrations:
embed.FSunderinternal/store/migrations/NNNN_name.sql;loadMigrationstakesfs.FSso tests inject synthetic sets viatesting/fstest. - Graceful HTTP shutdown:
srv.Shutdown()does NOT interrupt active connections; on deadline, fall back tosrv.Close()to force-close and cancel handler contexts. - Signal handling belongs in
mainviasignal.NotifyContext(SIGINT, SIGTERM); packages take actxand never wire signals themselves. - Config validation aggregates errors via
errors.Joinso operators see every problem at once. - Logger:
internal/log.New(w, debug)(JSON slog);internal/log.Discard()for tests (usesslog.DiscardHandler, Go ≥ 1.24). - Empty future packages carry a
doc.gostub whose package comment references the bd issue that will fill it in. - Integration tests under
cmd/broker/*_integration_test.gobuild the binary once inTestMainand exercise it as a subprocess. - Tests use
t.Context()(Go 1.24+) andt.TempDir()throughout — nocontext.Background()or manual cleanup. bd link A Bmeans "A depends on B" (B blocks A).bd create --deps "blocks:id"reverses this and is usually wrong — prefer bare--deps "id".bd initauto-commits its scaffolding; a follow-upgit commitfor the same files will be a no-op.fjoutside a cloned repo needs-H kode.naiv.noto know the host.