release gate / check (push) Failing after 5m49s
- .opencode/agents/superbrain.md: primary project engineer agent - .opencode/agents/invariant-reviewer.md: read-only diff reviewer subagent - .opencode/skills/: db-migration, add-endpoint, web-invariants, verify, release - RUNNING.md: warn that the repo docker-compose.yml is local dev/test only and must never be run on a core (cores use the federated render + shared postgresql)
3.0 KiB
3.0 KiB
name, description
| name | description |
|---|---|
| Add Endpoint | Add a new Go API endpoint the Superbrain way — handler + route registration, effective-user resolution, netguard, entitlement gate, write-only secrets, version/409 contract, and tests. Use when adding or changing an HTTP endpoint in internal/. |
Add an endpoint
Data endpoints live in internal/handlers/*.go and are registered in
internal/http/server.go on the mux. Every data endpoint resolves the
effective user, returns 401 if none, checks ownership, returns 404 if not
theirs, then acts. Errors are {error: string}; all routes return JSON unless
marked .md.
Steps
- Handler in the right
internal/handlers/<area>.gofile. Use the shared helpers fromcommon.go:user(r)— effective user id (from the session context).database(r)— the*db.DB.read(w, r)— decode a JSON object (1 MiB cap, 413 on oversize).writeJSON(w, status, body)/Error{...}.bad(...)→ 400,conflict(...)→ 409 (optimistic concurrency).
- Route in
internal/http/server.go, e.g.mux.HandleFunc("POST /api/things", authed(handlers.HandleThingsCreate)). Useauthed(...)for session endpoints;admin(...)for admin-only. - Identity — never trust a browser-supplied user id; never use an OIDC
subas a local user id. API keys (sb_...) resolve inAuthMiddlewarebefore assertions. - Secrets (if the endpoint stores credentials) — encrypt at rest
(
internal/crypto, versioned ciphertextbase64(0x01 || ...)), mask (••••••••) in EVERY response, write-only: a PATCH echoing the mask or omitting the field keeps the stored value. - Outbound dials — go through
internal/netguard(DialContextPorts/DialContext, ports pinned, no redirect following) and draw from the shared budget viaoutbound.Reserve(key, limit, window). User-supplied hosts get NONETGUARD_TRUSTED_HOSTSexemption. - Plan gate — gate on the entitlement catalog, never
TIER:entitlements.For(plan).AllowConnector(name)/AllowChannel(name)/AllowServerAI(plan). Gate at creation AND at use (downgrade ⇒ suppress). Resolve the caller's tenant plan (seewebdavConnectorGateinhandlers/webdav.gofor the shape). - Optimistic concurrency — mutating collection PATCHes take the expected
version; return 409 (conflict(...)) on stale. Page content PATCHes must requireversion. - Tests — add
internal/http/<area>_test.go(DB-backed; set secrets witht.Setenv, not.Parallel()when usingt.Setenv). Cover auth (401), ownership (404), the plan gate, and the version/409 path. - Verify —
make test, andmake integrationif it touches the DB (see the verify skill).
Reference
internal/handlers/webdav.go— the canonical connector handler (gates, write-only secrets, netguard, version, per-user limiter).internal/handlers/common.go— shared helpers.internal/http/server.go— route registration.API.md— endpoint documentation (keep it in sync).