agentleFS
Mininglamp-OSSMininglamp-OSS/octo-server/AGENTS.md

octo-server

AGENTS.md1.1k starsChanged 5 months agoApache-2.0View on GitHub

Octo-server is the Go backend for DMWork, an enterprise IM platform. It handles business logic on top of WuKongIM for messaging transport. - Go module: github.com/Mininglamp-OSS/octo-server - Go version: 1.25 - Shared library: github.com/Mininglamp-OSS/octo-lib for config, wkhttp, testutil, register, and model packages - Default branch: main Modules live in modules/. Each module is auto-registered with init() and register.AddModule(). Standard module layout: All user-facing error responses go through the i18n error envelope. Do not use c.ResponseError(errors.New(...)), c.ResponseErrorf(...), c.AbortWithStatusJSON(...), or non-OK c.JSON(...);…

Trending

Quiet since September.about the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 0 mentionsApr 2026: 0 mentionsMay 2026: 7 mentionsJun 2026: 1 mentionJul 2026: 6 mentionsAug 2026: 3 mentionsSep 2026: 21 mentionsOct 2026: 0 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the Mininglamp-OSS/octo-server repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about Mininglamp-OSS/octo-server

The biggest 5 of 38 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 38

Talked about on GitHub (38 times).

On GitHub · 38

33 more on GitHub
  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.

    Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repository2 other files it gives its agents.

The file

Show its rules and text

We split this AGENTS.md into the rules it gives an agent

14 rules. About 0 are common, 5 are distinctive, and 9 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 9

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    All user-facing error responses go through the i18n error envelope.

    line 71
  2. Very specific:

    Use the facades in pkg/httperr:

    line 76
  3. Distinctive:

    After adding or changing error codes, run:

    line 112
  4. Very specific:

    Use the shared middleware in octo-lib pkg/wkhttp/ratelimit.go.

    line 136
  5. Distinctive:

    Use the shared test utilities:

    line 180
  6. Very specific:

    When changing behavior, run the narrowest relevant go test package first.

    line 190
  7. Very specific:

    Use English Conventional Commits when committing, such as feat:, fix:, test:, and refactor:.

    line 196
  8. Very specific:

    Add a blank import in internal/modules.go for new modules.

    line 199
  9. Very specific:

    All routes go through AuthMiddleware unless explicitly excluded.

    line 200
  10. Very specific:

    Run make i18n-extract-check and make i18n-lint after touching error codes or localized error behavior.

    line 205
  11. Distinctive:

    Do not hand-roll Redis counters for generic HTTP request-frequency limiting.

    line 209
  12. Distinctive:

    Follow existing module, service, DB, and handler patterns before introducing new abstractions.

    line 214
  13. Distinctive:

    Keep changes scoped to the requested behavior and avoid unrelated refactors.

    line 216
  14. Very specific:

    Run gofmt on edited Go files.

    line 217

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md 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
AGENTS.md

AGENTS.md

This file provides guidance to coding agents when working in this repository.

Project Overview

Octo-server is the Go backend for DMWork, an enterprise IM platform. It handles business logic on top of WuKongIM for messaging transport.

  • Go module: github.com/Mininglamp-OSS/octo-server
  • Go version: 1.25
  • Shared library: github.com/Mininglamp-OSS/octo-lib for config, wkhttp, testutil, register, and model packages
  • Default branch: main

Common Commands

# Build
docker build -t octo-server .

# Run tests for a module
go test ./modules/group/...
go test ./modules/message/ -run TestSendMsg

# Run all tests
go test ./...

# Lint
golangci-lint run ./...

Architecture

Request Flow

HTTP (Gin/wkhttp) -> Auth Middleware (pkg/auth/) -> Space Middleware -> API Handler -> Service -> DB (MySQL/DBR)
                                                                                       |
                                                                                       v
                                                                                  WuKongIM (gRPC)

Module System

Modules live in modules/. Each module is auto-registered with init() and register.AddModule().

Standard module layout:

  • 1module.go: registration entry using init() and register.AddModule()
  • api*.go: HTTP handlers implementing register.APIRouter.Route(r *wkhttp.WKHttp)
  • service.go: business logic, usually with an IService interface
  • db*.go: database operations using gocraft/dbr
  • model.go: data models and response structs
  • sql/: SQL migrations embedded with //go:embed sql

Key Packages

PackagePurpose
pkg/auth/Token parsing, CacheTokenParser, auth middleware
pkg/errcode/Error code definitions per module, such as group, message, user, and OIDC
pkg/httperr/ResponseErrorL and ResponseErrorLWithStatus error facades
pkg/i18n/Localization SDK: code registry, localizer, renderer, language negotiation, and locales/
internal/Internal wiring and module imports
modules/base/event/Async event system

Error Handling and i18n

All user-facing error responses go through the i18n error envelope. Do not use c.ResponseError(errors.New(...)), c.ResponseErrorf(...), c.AbortWithStatusJSON(...), or non-OK c.JSON(...); these are legacy patterns and bypass the localized envelope.

Use the facades in pkg/httperr:

FacadeWire statusUse for
ResponseErrorL(c, code, params, details)Pinned 400 for D14 compatibility; real status in error.http_statusDefault for legacy-bearing endpoints
ResponseErrorLWithStatus(c, code, params, details)The code's real HTTPStatusNew endpoints only when no clients depend on fixed 400; maintainer sign-off is required when diverging from D14
httperr.ResponseErrorL(c, errcode.ErrGroupQueryFailed, nil, nil)

Register error codes in pkg/errcode/<module>.go:

ErrXxx = register(codes.Code{
    ID:             "err.server.<module>.<reason>", // or reuse err.shared.* codes
    HTTPStatus:     http.StatusBadRequest,
    DefaultMessage: "English source (D4).",
    SafeDetailKeys: []string{"field"},
    Internal:       false,
})

Error-code rules:

  • 5xx codes must set Internal=true; 4xx codes must not. The renderer hides messages and details for internal errors, so log the cause with zap.Error before responding.
  • Auth and verification failures use one generic anti-enumeration code, such as a single 401. Specific failure reasons go to logs only.
  • params interpolate into the message template. details are structured client-facing fields filtered by SafeDetailKeys.
  • Per-module helpers live in modules/<module>/api_i18n.go.
  • mustLookupSharedCode resolves shared codes at init and should panic loudly when a shared code is not registered.

After adding or changing error codes, run:

make i18n-extract
make i18n-extract-check
make i18n-lint

Then add the zh-CN translation to pkg/i18n/locales/active.zh-CN.toml with one ["id"] block and other = "..." value per code.

Each migrated module has a Test<Module>NoLegacyResponseError source guard that forbids legacy and raw error responses. Add new handler files to that guard's file list. Protocol endpoints that intentionally keep raw responses, such as OAuth2/OIDC browser-redirect flows, are exempted through tools/lint-direct-error-response/baseline.txt.

Localized email templates live in modules/base/common/emailtmpl/templates/{lang}/. Send functions take a lang argument resolved through i18n.OutboundLanguage(ctx); do not hardcode localized subject or body strings.

Rate Limiting

Use the shared middleware in octo-lib pkg/wkhttp/ratelimit.go. Do not hand-roll Redis INCR and TTL counters for generic request-frequency limiting.

The rate limit layers set X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Scope, and X-RateLimit-Retry-After headers, return the i18n rate.limited response, and fail open on Redis errors.

MiddlewareScope headerDimensionUse for
RateLimitMiddlewareipGlobal per-IPDDoS floor; already mounted globally in main.go via route.Use, so do not re-add it
StrictIPRateLimitMiddleware(tag, rps, burst)strict:{tag}Per-IP, per-endpointUnauthenticated sensitive endpoints such as login, register, SMS, search, group invite, and space invite
SharedUIDRateLimiter(r, ctx)uidPer-login-user shared bucket ratelimit:uid:{uid}Default for authenticated endpoints

SharedUIDRateLimiter wraps UIDRateLimitMiddleware and is defined in pkg/wkhttp/ratelimit_helper.go. It is a process-wide singleton with one quota per UID across all mounted routes. Defaults are 2 rps and burst 60, tunable via DM_API_UID_RATELIMIT_RPS and DM_API_UID_RATELIMIT_BURST.

Mount SharedUIDRateLimiter after AuthMiddleware; otherwise it cannot read the UID and silently fails open.

auth := r.Group("/v1/foo", ctx.AuthMiddleware(r), appwkhttp.SharedUIDRateLimiter(r, ctx))

Per-resource cooldowns keyed by business identity, such as phone, email, or bind session, may use a hand-written Redis counter when IP and UID buckets cannot express the rule. Existing examples include sms_rate_limit:{zone}@{phone}, email_rate_limit:{email}, and OIDC bind attempt caps. These are intentional; generic HTTP request-frequency limiting is not.

Tests that hit UID-limited routes must reset the bucket in setup, such as ratelimit:uid:*. The bucket persists in Redis and is not cleared by CleanAllTables.

Database

  • ORM: gocraft/dbr v2
  • Migration files: modules/<name>/sql/<yyyyMMdd>-<seq>_<name>.sql
  • SQL migrations are embedded via //go:embed sql
  • Field naming uses underscore conversion through util.AttrToUnderscore()

Testing

Use the shared test utilities:

_, ctx := testutil.NewTestServer()
defer testutil.CleanAllTables(ctx)

Tests require MySQL, Redis, and WuKongIM to be running. Check CI or make env-test in dmworkim for the expected test environment.

When changing behavior, run the narrowest relevant go test package first. Run broader tests when the change touches shared behavior, cross-module contracts, middleware, auth, rate limiting, or database migrations.

Coding Conventions

  • Use English Conventional Commits when committing, such as feat:, fix:, test:, and refactor:.
  • API routes use the /v1/ prefix.
  • Add a blank import in internal/modules.go for new modules.
  • All routes go through AuthMiddleware unless explicitly excluded; document the reason when skipping auth.
  • User-facing errors use httperr.ResponseErrorL with a registered pkg/errcode code. Do not use raw c.ResponseError, c.JSON, or AbortWithStatusJSON for non-OK responses.
  • Run make i18n-extract-check and make i18n-lint after touching error codes or localized error behavior.
  • Authenticated routes should mount SharedUIDRateLimiter.
  • Unauthenticated sensitive endpoints should mount StrictIPRateLimitMiddleware.
  • Do not hand-roll Redis counters for generic HTTP request-frequency limiting.
  • Handlers that access user data must go through the Space middleware.
  • Bot API code in modules/bot_api/ must validate bot ownership before operations.
  • Thread code in modules/thread/ must verify parent channel access.
  • Follow existing module, service, DB, and handler patterns before introducing new abstractions.
  • Keep changes scoped to the requested behavior and avoid unrelated refactors.
  • Run gofmt on edited Go files.
<!-- octospec:begin -->

octo-spec engineering standard

This repo carries shared engineering rules in .octospec/, readable by any coding agent working in this checkout (Claude Code, Codex, OpenClaw, or others).

  • Rules: .octospec/rules/ (+ index .octospec/rules/_index.yaml) — the source of truth for this repo's conventions: error-handling, rate-limit, space-isolation, testing, commit-style.
  • Before changing load-bearing behavior, read the rules whose inject_when matches the files you touch.
  • Tasks: capture goal / load-bearing list / out-of-scope / acceptance in .octospec/tasks/<slug>/brief.md.
  • PRs: fill Linked Spec + the COMPREHENSION three questions for load-bearing, architectural, or P0 changes; trivial changes (typo/docs/lint/config) are exempt.

Claude Code users also have /octospec-plan|go|check|finish slash commands (committed under .claude/commands/). Other agents read the same .octospec/ files directly.

This region is managed by octospec; edit outside the markers.

<!-- octospec:end -->

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.