agentleFS
mo-cmykmo-cmyk/mazarbul/.claude/skills/go-backend/SKILL.md

go-backend

Skill2 starsChanged 35 days agoApache-2.0View on GitHub

Mazarbul Go backend rules. USE WHEN editing any *.go file, working with internal/, cmd/, migrations/, .mise.toml, or SQL. Covers Google Go style, Google AIP naming applied to JSON and Go, event-log append-only discipline, kernel helper catalog, Zap structured logging, and the no-proto / JSONL convention. NOT FOR TUI-specific work (use tui-design) or CLI argument parsing (use cli-developer agent).

3 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

10 rules. About 0 are common, 7 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Event log is append-only: Never UPDATE or DELETE event rows.

    line 15
  2. Distinctive:

    Provenance on every fact: Every event carries source, confidence, timestamp.

    line 16
  3. Distinctive:

    If unsure about a kernel invariant, ASK USER.

    line 19
  4. Very specific:

    Run go vet ./... plus mise run lint.

    line 25
  5. Very specific:

    No stuttering: entity.ByID() not entity.GetEntityByID().

    line 46
  6. Very specific:

    No generic packages: util, common, helpers, FORBIDDEN.

    line 47
  7. Distinctive:

    No global state: dependency injection only.

    line 48
  8. Distinctive:

    No panic in library code: return errors.

    line 49
  9. Distinctive:

    Before adding new helpers, check:

    line 66
  10. Distinctive:

    Update README.md when changing: command surface, project structure, dev workflow, or prerequisites.

    line 143

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “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 Backend Rules

Core invariants (NON-NEGOTIABLE)

  • Event log is append-only. Never UPDATE or DELETE event rows. Supersede via newer events.
  • Provenance on every fact. Every event carries source, confidence, timestamp.
  • Timestamps: UTC time.Time, JSON RFC 3339. Never *_at.
  • No proto. Wire format is JSONL. Schema layer is JSON Schema. Types are Go structs with json: tags.
  • If unsure about a kernel invariant, ASK USER.

Schema and types

  1. Define or update the JSON Schema in internal/kernel/schemas/.
  2. Define or update the Go struct with json: tags. Doc-comment on every exported field.
  3. Run go vet ./... plus mise run lint.
  4. Tests cover happy path plus at least one documented error code.

See /aip-naming for the full naming rules.

Naming Standards

  • Packages: lowercase, single word, no underscores (kernel, mcp, plugin, cli, tui).
  • Variables: camelCase, descriptive (entityID not eid, eventCount not cnt).
  • Exported functions: PascalCase, verb-noun (AppendEvent, ValidateSchema).
  • Interfaces: -er suffix when single method (Reader, Writer, Validator).
  • Acronyms in Go (Mazarbul convention): single words in PascalCase (Jwk not JWK, Mcp not MCP, Url not URL, Http not HTTP). Brand names preserved (OAuth, JSONRPC).
  • Enum values in Go: PascalCase typed constants (EventKindUnspecified, EventKindCreated).
  • Boolean fields (AIP-140): adjectives, active not isActive. Exception: reserved words.
  • Time fields (AIP-142): *Time suffix, createTime, updateTime, deleteTime.

Code Standards (Google Go Style)

  • Context first parameter: func Foo(ctx context.Context, ...)
  • Return errors, don't log-and-return (let caller decide).
  • Error wrapping: fmt.Errorf("operation: %w", err).
  • No stuttering: entity.ByID() not entity.GetEntityByID().
  • No generic packages: util, common, helpers, FORBIDDEN.
  • No global state: dependency injection only.
  • No panic in library code: return errors.
  • Receiver names: short, consistent (s for Server, not server or self).
  • Line length: prefer <100 characters, hard limit 120.

Log Message Conventions

Per Google Go Style:

TypeCasingExample
Log messagesCapitalizedlogger.Info(ctx, "Starting server")
Error stringslowercasefmt.Errorf("failed to start: %w", err)

Proper nouns and acronyms (OpenTelemetry, MCP, HTTP, JSON-RPC) keep standard casing in log messages.

Code Reuse, ALWAYS check helpers first

Before adding new helpers, check:

  • internal/kernel/ for event-log writers, query composers, supersede helpers.
  • internal/mcp/ for JSON-RPC error mapping, tool registry helpers.
  • internal/tui/style/ for theme accessors.

Full catalog with usage examples lives in the references/ subfolder.

When to Use What, Observability

NeedToolWhen
Structured logZapEvery method (already configured)
Event-log writekernel.Append(ctx, event)Every state-changing user or system action
Custom spanOTEL tracer.StartExternal APIs, complex multi-step logic
Custom metricOTEL meter.Int64CounterQuotas, rate-limited APIs

Full patterns live in the references/ subfolder.

AIP Compliance, TL;DR

AIPWhat
122/123Resource references + definitions
131-135Get/List/Create/Update/Delete
140Boolean field naming (adjectives)
142Time fields (*Time suffix)
155Idempotency (requestId UUID4)
158Pagination (cursor-based)
160Filtering (CEL syntax)
192Documentation (comments everywhere)
193Error model (JSON-RPC or RFC 7807)
203Field behavior (required/readOnly/writeOnly)

Full mapping with worked examples: agent-docs/synthesis.md section 3 and the aip-naming skill.

Pull Request Standards

  • Target: 50 to 100 LoC for incremental changes.
  • Initial development exception: larger PRs OK for new packages.
  • Hard limit: 300 LoC (excluding generated code, migrations).
  • Review SLA: <1 hour for small PRs, max 1 business day.

Forbidden Actions

  • Emojis in code or comments.
  • Logging passwords, tokens, API keys, encryption keys.
  • Hardcoded credentials or connection strings.
  • Skipping error handling with _ assignment.
  • Guessing kernel invariants (ask user instead).
  • Modifying event-log entries (append-only).
  • Creating types that bypass JSON Schema (define the schema first).
  • Non-idiomatic Go patterns.
  • Creating docs/ directories or documentation without being asked.
  • Em-dashes in code, comments, docs, or commits.

When Uncertain, ASK USER

  • Kernel invariant interpretations.
  • Domain model definitions (entities, relationships).
  • Business logic behavior.
  • Provenance requirements for a new event type.
  • Schema design decisions.

Key Commands

CommandWhat
go vet ./...Compile-time checks.
mise run testAll tests with race detector.
mise run lintgolangci-lint.
mise run ciFormat + lint + test (before every commit).
mise run fmtgofumpt + goimports with local prefix.
lefthook installInstall git hooks.

README.md Maintenance

Update README.md when changing: command surface, project structure, dev workflow, or prerequisites. Keep it concise (~100 lines).

Gotchas

Concrete pitfalls encountered when implementing Go backend code in Mazarbul. Add new ones as you hit them, this is the compounding-engineering log (see agent-docs/lessons-learned.md for the broader pattern).

  • Never embed unbounded inside a tool's Invoke. Any synchronous embedding call on the request path must either (a) bound itself with the internal/ontology/dedup pattern, a hard ceiling (defaultSemanticTimeout, 20s, in dedup.go) plus a single EmbedBatch round-trip instead of N per-text calls, or (b) defer the embed to a background worker the way remember and recall do (enqueue, return immediately, drain off the request path). A deadline-less embed makes the tool look hung when Ollama is cold or busy: this was the real cause of the defineEntityKind "multi-second hang" (fixed in PR #286). When you add a new tool that needs a vector, copy the dedup ceiling-plus-batch shape; do not call the embedder in a bare loop.

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.