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
11 changes: 3 additions & 8 deletions agents/golang-general-engineer-compact.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ This agent operates as an operator for focused Go development, configuring Claud

| Skill | When to Invoke |
|-------|---------------|
| `go-patterns` | Run Go quality checks via make check with intelligent error categorization and actionable fix suggestions. Use when u... |
| `go-patterns` | Go testing patterns and methodology: table-driven tests, t.Run subtests, t.Helper helpers, mocking interfaces, benchm... |
| `go-patterns` | Go quality checks via `make check` with error categorization; table-driven tests, subtests, helpers, mocks, benchmarks. |

**Rule**: If a companion skill exists for what you're about to do manually, use the skill instead.

Expand Down Expand Up @@ -282,19 +281,15 @@ STOP and ask when:

| Signal | Load These Files | Why |
|---|---|---|
| Idiom upgrade, version compatibility, `any` vs `interface{}` | `go-patterns.md` | Version table Go 1.18–1.26, error wrapping, functional options |
| Goroutines, channels, WaitGroup, worker pools | `concurrency-patterns.md` | `wg.Go()`, context cancellation, failure modes with detection commands |
| Table-driven tests, benchmarks, fuzzing, goroutine leaks | `testing-patterns.md` | `t.Context()`, `b.Loop()`, `t.TempDir()`, goleak patterns |
| interface{}, any, wg.Go, b.Loop, t.Context, t.TempDir, omitzero, SplitSeq, new(val), errors.AsType, go.mod version, undefined:, goleak, DATA RACE, t.Parallel | `go-compact-reference.md` | Version table Go 1.18–1.26 with detection commands, error-message-to-fix map, version notes |

## References

Load the relevant reference file based on the task type:

| Task Type | Reference File | What It Covers |
|-----------|---------------|----------------|
| Idiom upgrade, version compatibility, `any` vs `interface{}` | [references/go-patterns.md](references/go-patterns.md) | Version table Go 1.18–1.26, error wrapping, functional options |
| Goroutines, channels, WaitGroup, worker pools | [references/concurrency-patterns.md](references/concurrency-patterns.md) | `wg.Go()`, context cancellation, failure modes with detection commands |
| Table-driven tests, benchmarks, fuzzing, goroutine leaks | [references/testing-patterns.md](references/testing-patterns.md) | `t.Context()`, `b.Loop()`, `t.TempDir()`, goleak patterns |
| Idiom upgrade, version compatibility, exact error-message lookup, goroutine-leak/test-parallel panics | [references/go-compact-reference.md](references/go-compact-reference.md) | Version table Go 1.18–1.26 with detection commands, error-to-fix map, version notes |

**Shared**:
- [anti-rationalization-core.md](../skills/shared-patterns/anti-rationalization-core.md)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Go Compact Reference — Versions, Detection, Error Map

> **Scope**: Version-pinned idiom upgrades, detection commands, error-to-version lookup. Go 1.18–1.26.

Targets Go 1.26+; check go.mod before using version-specific features.

```bash
grep '^go ' go.mod # "go 1.23" means 1.23 features, not 1.24+
```

## Version Upgrade Table

| Old Idiom | Modern Idiom | Since | Detection |
|-----------|-------------|-------|-----------|
| `interface{}` | `any` | 1.18 | `rg 'interface\{\}' --type go` |
| `sort.Slice(s, func(i,j int) bool{...})` | `slices.SortFunc(s, cmp.Compare)` | 1.21 | `rg 'sort\.Slice\(' --type go` |
| Hand-rolled min/max | `min(a, b)` / `max(a, b)` | 1.21 | manual review |
| `for i := 0; i < n; i++` | `for i := range n` | 1.22 | `rg 'for i := 0; i < ' --type go` |
| `item := item` loop-var capture | Per-iteration variables, capture unneeded | 1.22 | `rg 'item := item' --type go` |
| `strings.Split` in `range` | `strings.SplitSeq` | 1.24 | `rg 'strings\.Split\(' --type go` |
| `context.WithCancel` in tests | `t.Context()` | 1.24 | `rg 'context\.Background' --type go --glob '*_test.go'` |
| `for i := 0; i < b.N; i++` | `for b.Loop()` | 1.24 | `rg 'i < b\.N' --type go` |
| `omitempty` on structs/Duration | `omitzero` | 1.24 | check JSON tags |
| `wg.Add(1); go func(){defer wg.Done()...}` | `wg.Go(fn)` | 1.25 | `rg 'wg\.Add\(1\)' --type go` |
| `x := val; &x` | `new(val)` | 1.26 | `rg 'x := .*; &x' --type go` |
| `errors.As(err, &t)` | `errors.AsType[T](err)` | 1.26 | `rg 'errors\.As\(' --type go` |

Version notes: `t.TempDir()` since 1.15, `t.Setenv` since 1.17, fuzzing since 1.18, `t.Cleanup` since 1.14. On Go < 1.25 keep `wg.Add(1)` before the `go` statement (Add inside the goroutine races `Wait()`). On Go < 1.24 pair `context.WithCancel` with `t.Cleanup(cancel)`.

## Error Message → Fix Map

| Error Message | Root Cause | Fix |
|---------------|------------|-----|
| `undefined: slices.Contains` | Go < 1.21 | Upgrade go.mod or implement manually |
| `cannot range over N (variable of type int)` | Go < 1.22 | `for i := 0; i < N; i++` |
| `t.Context undefined` | Go < 1.24 | `context.WithCancel(context.Background())` + `t.Cleanup(cancel)` |
| `undefined: (*sync.WaitGroup).Go` | Go < 1.25 | Add/Done pattern |
| `undefined: errors.AsType` | Go < 1.26 | `errors.As(err, &target)` |
| `flag provided but not defined: -test.fuzz` | Go < 1.18 | Upgrade; fuzz requires 1.18+ |
| `panic: t.Parallel called after t.Cleanup` | Ordering: `t.Parallel()` must be the subtest's first line | Move `t.Parallel()` to line 1 of the `t.Run` func |
| `goleak: found unexpected goroutines` / `test ended with leaked goroutines` | Goroutines outlive the test | Pass `t.Context()` (1.24+) or `t.Cleanup(cancel)` to every goroutine |
| `DATA RACE` on WaitGroup from `-race` | `wg.Add()` inside goroutine | Move `wg.Add()` before `go`, or `wg.Go()` (1.25+) |

## Detection Commands

```bash
rg 'interface\{\}' --type go # upgrade to any
rg 'for i := 0; i < ' --type go # upgrade to for range n
rg 'wg\.Add\(1\)' --type go # upgrade to wg.Go (1.25+)
rg 'return nil, err$' --type go -g '!*_test.go' # add fmt.Errorf("...: %w", err) context
grep -rn 'os.TempDir()' --include="*_test.go" # upgrade to t.TempDir()
go test -race ./... # always in CI
```
Loading
Loading