---
name: go-implement
description: Implement a bounded Go change using idiomatic Go, tests and repository acceptance criteria. Use when adding or changing Go code in this repository.
argument-hint: "[task or acceptance criterion]"
disable-model-invocation: true
effort: high
---

# Implement a bounded Go change

Task:

$ARGUMENTS

## Context reconstruction

Before editing:

1. Read `CLAUDE.md` and `AGENTS.md`.
2. Read `docs/CURRENT_STATE.md`.
3. Read the relevant project specification section.
4. Read relevant ADRs.
5. Inspect existing packages, tests and the Git diff.
6. Identify the active acceptance criterion.

## Design checkpoint

State:

- Required behaviour
- Inputs and outputs
- Error cases
- Existing package that should own the behaviour
- Smallest implementation satisfying the requirement
- Tests required
- Whether an interface is genuinely needed

Do not create an interface unless it has an immediate concrete reason.

Do not introduce a new package when an existing cohesive package should own the
behaviour.

## Implementation rules

- Use typed domain models.
- Validate data at boundaries.
- Return actionable errors.
- Wrap errors using `%w` when adding context.
- Avoid global mutable state.
- Avoid hidden side effects.
- Avoid unnecessary concurrency.
- Keep core logic independent from CLI rendering.
- Keep raw source metrics separate from normalised metrics.
- Do not mix collection, diagnosis and presentation concerns.

## Testing

Write or update tests with the implementation.

Tests must include:

- Expected success
- Invalid input
- Missing required data
- Relevant boundary condition
- Regression case where applicable

Prefer table-driven tests when cases share structure.

## Validation

Run:

```bash
go fmt ./...
go vet ./...
go test ./...
go build ./...
make policy-check
```

Run focused tests during development.

## Completion

Review the diff and report:

- Behaviour implemented
- Important Go design choices
- Tests added
- Commands run
- Limitations
- Exact next task

Update `docs/CURRENT_STATE.md`.

Do not commit.
