diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 46abea8..7ec68b4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,17 @@ jobs: - run: make test - run: make build + golangci: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: actions/setup-go@v6 + with: + go-version-file: go.mod + - uses: golangci/golangci-lint-action@v9 + with: + version: v2.15.0 + lint: runs-on: ubuntu-latest steps: diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..20b7db3 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,8 @@ +version: "2" + +linters: + enable: + - revive # golint's successor: doc comments, naming, error strings + exclusions: + presets: + - std-error-handling # unchecked Close, os.Remove, fmt.Fprint* diff --git a/CLAUDE.md b/CLAUDE.md index 495e4b3..9e491d0 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -15,7 +15,7 @@ agent-quorum is local coordination for concurrent coding-agent sessions that sha | Command | What it does | |---|---| | `make build` | Build `./bin/agent-quorum` (version from `plugin.json` + `-dev`) | -| `make check` | `vet` + `lint` + `test`. What CI runs. | +| `make check` | `vet` + `lint` + `test`. What CI runs, except the `golangci` job (`golangci-lint run`, v2, config in `.golangci.yml`). | | `make test` | `go test -race -count=1 ./...` | | `make vet` | `go vet` plus a gofmt check that fails on unformatted files | | `make lint` | `sh -n` and shellcheck (optional locally, enforced in CI) on all scripts; `jq` on the plugin JSON | diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5ec6f67..6795531 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,6 +8,7 @@ Thanks for helping. This file covers the dev loop, the rules the code lives by, - `jq` (used by `make lint`, `make release` and the version stamp) - the `gh` CLI, for `make release` to open the release pull request - `shellcheck` (optional locally, enforced in CI) +- `golangci-lint` v2 (optional locally, enforced in CI; config in `.golangci.yml`) - the `claude` CLI, for `make validate-plugin` and for trying the plugin by hand - the `codex` CLI, for installing and checking the Codex marketplace package locally - the `agy` CLI, for validating the Antigravity plugin (`make validate-antigravity-plugin`) @@ -17,7 +18,8 @@ Thanks for helping. This file covers the dev loop, the rules the code lives by, ## Dev loop ```bash -make check # vet + lint + test: exactly what CI runs +make check # vet + lint + test: what CI runs, minus golangci-lint +golangci-lint run # the CI golangci job (v2.15.0) make dev # build, then start Claude Code with the local plugin and local binary ``` @@ -112,7 +114,7 @@ Do not break these. Review will check each one. 2. **Commit** with short imperative subjects, one logical change per commit: `fix: allow git stash list`, `feat: add status --json`. 3. **Run `make check` locally**, and `make validate-plugin` if you touched `plugin/` or the marketplace manifest. 4. **Open a pull request against `main`.** Describe the behaviour change and how you tested it. Call out any change to a public surface (see [Versioning](#versioning)), because it decides the next version bump. -5. **CI must be green** (`test` on Ubuntu and macOS, `lint`, `plugin`) and the pull request needs an approving review before it can merge. +5. **CI must be green** (`test` on Ubuntu and macOS, `golangci`, `lint`, `plugin`) and the pull request needs an approving review before it can merge. 6. **Squash-merge**, then delete the branch. The squash subject becomes the line in the generated release notes, so make it read well. Rules: @@ -200,6 +202,7 @@ Two workflows in `.github/workflows/`. | Job | What it checks | |---|---| | `test` (Ubuntu and macOS) | `make vet`, `make test` (race detector), `make build` | +| `golangci` | `golangci-lint run` (v2.15.0) with `.golangci.yml`: the standard linters plus `revive`, golint's successor | | `lint` | `make lint` (shellcheck, `sh -n`, JSON syntax), and that the launcher fails open when no binary exists | | `plugin` | `make validate-plugin`: validates the Claude plugin and marketplace, then installs the Codex plugin in a temporary Codex home | @@ -251,7 +254,7 @@ Run this before every tag. Do not skip steps because the change is small. 1. **Start from a clean, up-to-date `main` with CI green.** `git status` is clean, `git pull` is done, and the latest CI run on that commit passed on Ubuntu and macOS. 2. **Decide the version** (`x.y.z`, or `x.y.z-rc.N` for a candidate) from the versioning rules above, by reading the changes since the last tag (`git log ..HEAD`). Look for anything touching the public API. -3. **`make check`.** vet, lint and race tests must pass locally. Install `shellcheck` so lint is not skipped. +3. **`make check`.** vet, lint and race tests must pass locally. Install `shellcheck` so lint is not skipped, and run `golangci-lint run`. 4. **`make validate-plugin`.** Strict validation of the plugin and of the marketplace root. 5. **`make snapshot`, then inspect `dist/`.** There must be exactly four archives (`darwin` and `linux`, `amd64` and `arm64`) and `checksums.txt`. Verify the checksums (`shasum -a 256 -c checksums.txt` inside `dist/`), unpack the archive for your platform and run `agent-quorum version`. 6. **End-to-end by hand with two real sessions** on the current Claude Code version, using `make dev`, a scratch repository and a scratch `AGENT_QUORUM_HOME`: diff --git a/internal/adapter/codex/codex.go b/internal/adapter/codex/codex.go index 7fcf4b1..81085a1 100644 --- a/internal/adapter/codex/codex.go +++ b/internal/adapter/codex/codex.go @@ -10,20 +10,25 @@ import ( "github.com/bytedance/sonic" ) +// Agent is the value of proto.Request.Agent for this adapter. const Agent = "codex" var plainJSON = sonic.Config{SortMapKeys: true, EscapeHTML: false, ValidateString: true}.Froze() +// Event is the parsed Codex hook call. type Event struct { HookEvent string Tool string Req proto.Request HasReq bool } + +// Output is what the hook process writes and how it exits. type Output struct { Stdout []byte Exit int } + type hookInput struct { SessionID string `json:"session_id"` CWD string `json:"cwd"` @@ -33,6 +38,9 @@ type hookInput struct { Prompt string `json:"prompt"` } +// Parse turns one Codex hook payload into an Event. It returns an error only +// for input that is not valid JSON. Missing sessions or unhandled events and +// tools return HasReq false (no opinion). func Parse(raw []byte) (Event, error) { var in hookInput if err := sonic.ConfigStd.Unmarshal(raw, &in); err != nil { @@ -122,6 +130,8 @@ type hookSpecific struct { AdditionalContext string `json:"additionalContext,omitempty"` } +// Render turns the daemon's answer into hook output. Only a deny on +// PreToolUse and a non-empty Context on SessionStart produce output. func Render(ev Event, r proto.Response) Output { if !r.OK { return Output{} diff --git a/internal/client/client_test.go b/internal/client/client_test.go index 3b6c52b..5bfd9fc 100644 --- a/internal/client/client_test.go +++ b/internal/client/client_test.go @@ -63,7 +63,10 @@ func TestDoAgainstRealDaemon(t *testing.T) { t.Cleanup(func() { cancel() select { - case <-done: + case err := <-done: + if err != nil { + t.Errorf("daemon.Serve() = %v, want nil", err) + } case <-time.After(5 * time.Second): t.Error("daemon stopped within 5s = false, want true") } diff --git a/internal/core/state_test.go b/internal/core/state_test.go index d6c9218..96aa08d 100644 --- a/internal/core/state_test.go +++ b/internal/core/state_test.go @@ -346,9 +346,10 @@ func TestGuard(t *testing.T) { t.Run(tc.name, func(t *testing.T) { env := newEnv() s := newState(env) - if tc.holder == "a" { + switch tc.holder { + case "a": do(t, s, rq(proto.OpClaim, "a", 1, tc.path)) - } else if tc.holder == "b" { + case "b": do(t, s, rq(proto.OpClaim, "b", 2, tc.path)) } if tc.setup != nil { @@ -482,8 +483,8 @@ func TestHelloContextCap(t *testing.T) { if n := utf8.RuneCountInString(resp.Context); n == 0 || n > 600 { t.Fatalf("len(Context) = %d chars, want 1..600: %q", n, resp.Context) } - if !strings.Contains(resp.Context, "reset --hard") || - !(strings.Contains(resp.Context, "more") || strings.Contains(resp.Context, "files")) { + truncated := strings.Contains(resp.Context, "more") || strings.Contains(resp.Context, "files") + if !strings.Contains(resp.Context, "reset --hard") || !truncated { t.Errorf("Context = %q, want instructions and a truncation marker", resp.Context) } })