Go 1.26+ proxy server providing OpenAI/Gemini/Claude/Codex compatible APIs with OAuth and round-robin load balancing.
gofmt -w . # Format (required after Go changes)
go build -o cli-proxy-api ./cmd/server # Build
go run ./cmd/server # Run dev server
go test ./... # Run all tests
go test -v -run TestName ./path/to/pkg # Run single test
go build -o test-output ./cmd/server && rm test-output # Verify compile (REQUIRED after changes)- Common flags:
--config <path>,--tui,--standalone,--local-model,--no-browser,--oauth-callback-port <port>
- Default config:
config.yaml(template:config.example.yaml) .envis auto-loaded from the working directory- Auth material defaults under
auths/ - Storage backends: file-based default; optional Postgres/git/object store (
PGSTORE_*,GITSTORE_*,OBJECTSTORE_*)
cmd/server/— Server entrypointinternal/api/— Gin HTTP API (routes, middleware, modules)internal/api/modules/amp/— Amp integration (Amp-style routes + reverse proxy)internal/thinking/— Main thinking/reasoning pipeline.ApplyThinking()(apply.go) parses suffixes (suffix.go, suffix overrides body), normalizes config to canonicalThinkingConfig(types.go), normalizes and validates centrally (validate.go/convert.go), then applies provider-specific output viaProviderApplier. Do not break this "canonical representation → per-provider translation" architecture.internal/runtime/executor/— Per-provider runtime executors (incl. Codex WebSocket)internal/translator/— Provider protocol translators (and sharedcommon)internal/registry/— Model registry + remote updater (StartModelsUpdater);--local-modeldisables remote updatesinternal/store/— Storage implementations and secret resolutioninternal/managementasset/— Config snapshots and management assetsinternal/cache/— Request signature cachinginternal/watcher/— Config hot-reload and watchersinternal/wsrelay/— WebSocket relay sessionsinternal/usage/— Usage and token accountinginternal/home/— CLIProxyAPIHome control plane integration (bootstrap, RESP communication, dispatch coordination)internal/tui/— Bubbletea terminal UI (--tui,--standalone)sdk/cliproxy/— Embeddable SDK entry (service/builder/watchers/pipeline)test/— Cross-module integration tests
- Keep changes small and simple (KISS)
- Comments in English only
- If editing code that already contains non-English comments, translate them to English (don’t add new non-English comments)
- For user-visible strings, keep the existing language used in that file/area
- New Markdown docs should be in English unless the file is explicitly language-specific (e.g.
README_CN.md) - As a rule, do not make standalone changes to
internal/translator/. You may modify it only as part of broader changes elsewhere. - If a task requires changing only
internal/translator/, rungh repo view --json viewerPermission -q .viewerPermissionto confirm you haveWRITE,MAINTAIN, orADMIN. If you do, you may proceed; otherwise, file a GitHub issue including the goal, rationale, and the intended implementation code, then stop further work. internal/runtime/executor/should contain executors and their unit tests only. Place any helper/supporting files underinternal/runtime/executor/helps/.- Do not use
github.com/tidwall/gjson,github.com/tidwall/sjson, Go's standardencoding/json, Go's standardencoding/base64, or Go's standardregexp. Always usegithub.com/MoeForge/moego/json,github.com/MoeForge/moego/ojson,github.com/MoeForge/moego/base64, andgithub.com/MoeForge/moego/regexpfor all JSON, Base64, and regular expression operations. All JSON write operations (Set,SetRaw,Delete, etc.) MUST be performed on*ojson.Doc(ojson.NewDoc/ojson.NewDocString), passing*ojson.Docacross mutation stages and serializing only once at the final exit (doc.Bytes()/doc.String()), rather than mutating raw[]byteorstringpayloads directly. - Payload configuration MUST be the final semantic barrier before sending requests in every executor, including streaming, WebSocket, continuation, retry/fallback, image, and token-count paths where applicable. Complete all built-in payload translation, normalization, injection, and cleanup first, then evaluate and apply user payload rules exactly once to the final business payload. No subsequent logic may overwrite configured values or restore filtered fields. Only necessary transport framing, serialization, signature calculation, and read-only validation may follow without changing business payload semantics. Add regression tests when introducing or changing request-building paths to enforce this ordering.
- Follow
gofmt; keep imports goimports-style; wrap errors with context where helpful - Do not use
log.Fatal/log.Fatalf(terminates the process); prefer returning errors and logging via logrus - Shadowed variables: use method suffix (
errStart := server.Start()) - Wrap defer errors:
defer func() { if err := f.Close(); err != nil { log.Errorf(...) } }() - Use logrus structured logging; avoid leaking secrets/tokens in logs
- Avoid panics in HTTP handlers; prefer logged errors and meaningful HTTP status codes
- Timeouts are allowed only during credential acquisition; after an upstream connection is established, do not set timeouts for any subsequent network behavior. Intentional exceptions that must remain allowed are the Codex websocket liveness deadlines in
internal/runtime/executor/codex_websockets_executor.go, the wsrelay session deadlines ininternal/wsrelay/session.go, the management APICall timeout ininternal/api/handlers/management/api_tools.go, and thecmd/fetch_antigravity_modelsutility timeouts
- Start from the business outcome, not the first page or implementation mentioned. Use the capability map, then verify current UI/entry points, routes, permissions, services and data sources for the affected scope.
- Before implementation, briefly describe existing capabilities, real alternatives, reuse/extension/migration choices and affected entry points. Explain why an independent new implementation is needed. Do not expand small fixes into unrelated rewrites.
- For non-trivial behavior, architecture, contract or tooling decisions, use the project-local Skill and workflow guide. Search active notes first:
rg --hidden --glob '!**/archived/**' '<topic>' .agents/notes. Update an existing owner note when its rationale still holds. - New decisions start in proposed; move and rewrite them as implemented only after implementation and relevant verification, in the same commit as the change. Record genuine alternatives and costs; do not invent historical rationale or create notes for purely mechanical edits.
- User instructions and existing project rules take precedence over imported Skill defaults. Continue within existing authorization without repeated approval gates; ask only for material unresolved decisions or actions outside that scope. This workflow does not grant deployment, release or cross-project write permission.
- Validate complete affected user flows and adjacent entry points, including shared definitions, filtering, permissions and failure behavior where relevant. Structural note checks do not prove design quality or guarantee all important decisions were recorded.
- Update affected capability-map entries and notes alongside code. Run
bash .agents/verify-notes.shplus the existing checks required for the change. Existing architecture, language, build, release and subdirectory rules remain in force.
Project-specific context: Use personal/main, not upstream origin, for project pushes. The parent CPA scope includes only this backend and Cli-Proxy-API-Management-Center. Retain English authored docs/comments and required Go compile checks.
- Avoid wall-clock
time.Sleepin TTL, expiration, ordering, or cache-eviction unit tests due to platform timer granularity (e.g. Windows default timer resolution of ~15.6ms) and CI jitter under load; prefer controllable clocks (nowFunc/ mock clock), explicit timestamp manipulation, or deterministic synchronization primitives. - Note: if modifying features that involve CLIProxyAPIHome, check if corresponding updates are needed in the CLIProxyAPIHome repository.
- Endpoints under the
/v0/managementbase URL are deprecated and no longer maintained. For any feature changes, do not modify endpoints under/v0/managementunless necessary to fix compilation errors.