agentleFS
alexderzalexderz/agentic-toolbox/skills/golang-safety/SKILL.md

golang-safety

Skill5 starsChanged 48 days agoMITView on GitHub

use this when writing or reviewing Go for nil panics, typed-nil interfaces, append backing-array aliasing, silent integer truncation, float ==, defer-in-loops, defensive copies, or zero-value design — not concurrency primitives, not attacker vulns, not debugging an already-failing program.

14 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use golang-continuous-integration, golang-pkg-go-dev and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • guynhsichngeodiecSkill

    golang-continuous-integration

    Provides CI/CD pipeline configuration using GitHub Actions for Golang projects. Covers testing, linting, SAST, security scanning, code coverage, Dependabot, Renovate, GoReleaser, code review automation, and release pipelines. Use this whenever setting up CI for a Go project, configuring workflows, adding linters or security scanners, setting up Dependabot or Renovate, automating releases, or improving an existing CI pipeline. Also use when the user wants to add quality gates to their Go project.

    Also in 12 projects that use this

  • rockcookiesSkill

    golang-pkg-go-dev

    Golang package and module documentation and exploration via `godig`, a pkg.go.dev API client (CLI + MCP server) — package docs, API references, symbols, code examples, available versions, importers (who imports a package), licenses, and known vulnerabilities. Read-only, no auth. Use for looking up any Go/Golang library's documentation, API signatures, usage examples, which versions exist, whether a dependency has CVEs, or who imports a package — prefer this over Context7 for any Go package or module. Triggers on: how to use a Go library, Go API docs, import usage, code examples, pkg.go.dev. Not for upgrading dependencies (→ See `golang-dependency-management` skill) or choosing a library (→ See `golang-popular-libraries` skill). Not for local symbols, or for navigating an already-used dependency's resolved source, call sites, or generic instantiations — → See `golang-gopls` skill for those.

    Also in 6 projects that use this

  • guynhsichngeodiecSkill

    golang-samber-ro

    Reactive streams and event-driven programming in Golang using samber/ro — ReactiveX implementation with 150+ type-safe operators, cold/hot observables, 5 subject types (Publish, Behavior, Replay, Async, Unicast), declarative pipelines via Pipe, 40+ plugins (HTTP, cron, fsnotify, JSON, logging), automatic backpressure, error propagation, and Go context integration. Apply when using or adopting samber/ro, when the codebase imports github.com/samber/ro, or when building asynchronous event-driven pipelines, real-time data processing, streams, or reactive architectures in Go. Not for finite slice transforms (-> See golang-samber-lo skill).

    Also in 10 projects that use this

  • +9 more from guynhsichngeodiec

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 14 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Very specific:

    Do not merge golang-testing, golang-security and golang-safety into one body.

    line 26
  2. Distinctive:

    Do not self-except. Record the decision.

    line 58
  3. Distinctive:

    Stop. Initialize, bound-check, or copy.

    line 168

“Common” is measured: kept by at least 6 in 10 of the 14 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Go safety

Rewrite of samber/cc-skills-golang golang-safety @ 22c58a55. Not a vendor paste. Not an npx / marketplace pack. SKILL.md only — no evals/, no scripts/, no references/. Id: golang-safety.

security CLEAR (conditional): SKILL only. Safety is our bugs.

Iron law

No untested assumption about nil, capacity, or numeric range ships.

Did not initialize it, bound-check it, or copy it? Treat it as a latent panic or a silent wrap.

Scope

This skillNot this skill
Panics and silent corruption in ordinary GoConcurrent maps, channels, goroutine leaks
Nil, slices/maps, numbers, defer, zero valuesInjection, crypto, secrets, path traversal → golang-security / security-hardening
Stopping the next crashDebugging a crash already in hand

Do not merge golang-testing, golang-security and golang-safety into one body. Which Go skill loads, and what loads with it: language-router.

Always

RuleWhy
Comma-ok assert: v, ok := x.(T)Bare x.(T) panics on mismatch
Return untyped nil for a nil interfaceA typed-nil pointer inside an interface is != nil
make (or lazy-init) maps before writeNil map read is fine; write panics
Full-slice or slices.Clone before append when the original must stay intactappend reuses leftover cap and aliases the array
Return copies of exported slices/mapsCallers otherwise mutate internals
Extract the loop body so defer runs per itemdefer fires at function exit, not at the iteration
Bound-check before narrowing intsint64→int32 wraps with no error
Epsilon (or math/big) for floats0.1+0.2 == 0.3 is false
Guard integer division by zeroInteger / 0 panics; float / 0 is Inf/NaN
Usable zero value; sync.Once if lazy-init can racevar x T must not panic on first use
Prefer generics over any when the set is knownCompiler, not a runtime panic
errcheck, forcetypeassert, nilerr, govet, staticchecktester static catch

Go 1.25+ reflection: reflect.TypeAssert[T](v) — not v.Interface().(T).

Ask first

TopicWhy it is a stop
Skipping a bounds check because "the value is small"Small today; wrap tomorrow
Returning an internal slice/map "just this once"Alias is a contract leak
Concurrent map read/writeWrong skill; needs sync, not a comment
init() order across filesUnspecified; use a constructor
Integer overflow an attacker can drivegolang-security, not a safety nit
"Linters will catch it" without a fresh runtester evidence, not vibes

Do not self-except. Record the decision.

Never

NeverWhy
Bare v := x.(T) on a production pathCrash on mismatch
Write to a map you did not initializePanic
defer f.Close() inside a loop in the same functionFDs pile up until return
== on computed floatsSilent wrong branch
npx skills add / marketplace install of the samber packINTAKE: clone, do not install
Copy evals/, scripts/, or references/ into this skill dirConditional CLEAR is SKILL only
Treat this skill as a vuln auditAttackers are golang-security + security

Traps (compressed)

Typed nil

An interface is nil only when type and value are both nil.

func handler(ok bool) http.Handler {
    if !ok {
        return nil // return plain nil; a nil *MyHandler in an interface is != nil
    }
    return &MyHandler{}
}

Nil containers

IndexWriteLen/capRange
Mapzeropaniclen 0; no cap0
Slicepanicpanic00
Chanblockblock0block
func (r *Reg) Put(k string, v int) {
    if r.items == nil {
        r.items = make(map[string]int)
    }
    r.items[k] = v
}

Append alias

// may share a's array — writes to out can mutate a
out := append(a, x)

// keep a stable: cap==len forces a new array
out := append(a[:len(a):len(a)], x)

Narrowing

if n < math.MinInt32 || n > math.MaxInt32 {
    return 0, fmt.Errorf("int32 overflow: %d", n)
}

Defer per item

for _, path := range paths {
    if err := one(path); err != nil {
        return err
    }
}

func one(path string) error {
    f, err := os.Open(path)
    if err != nil {
        return err
    }
    defer f.Close()
    return use(f)
}

Zero value

sync.Mutex and bytes.Buffer work at zero. A struct whose first write is m[k]=v on a nil map field does not. Lazy-init the map. If two goroutines can hit that init, sync.Once — do not invent a concurrency protocol in this skill.

Exported accessors that hand back []T or map[K]V return slices.Clone / maps.Clone, not the live field.

Roles

RoleOwnsDoes not own
builderApplying this gate when writing or reviewing GoInstalling the samber pack beside these ids
securityIntake CLEAR; overflow-as-vuln → security skillsDay-to-day nil coaching
testergofmt / staticcheck / errcheck hooksClaiming DoD from fmt-only green
managerAfter-actBlessing a panic class that skipped the gate

Workers do not bypass intake. A green gofmt is not a security clear.

Red flags

  • "It's never nil in practice"
  • "append always copies"
  • "I'll close everything at function exit"
  • "int conversion is fine, the number is small"
  • "npx the samber golang pack"
  • "Safety and security are the same skill"
  • "Copy the evals so we can score it"

Stop. Initialize, bound-check, or copy. Or ask.

Upstream pin

Intent: samber/cc-skills-golang golang-safety @ 22c58a55a0a799b901aa251172923180bad9e010. Body is a rewrite. See SOURCES.md.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.