{"owner":"bfenetworks","repo":"bfe","hasSkills":true,"totalSkillsCount":1,"totalTokensCount":1737,"categories":["root-instruction"],"hasMcp":false,"mcpConfig":null,"found":["AGENTS.md"],"skills":{"AGENTS.md":"# AGENTS.md — BFE Server\n\nThis file guides AI coding agents working on the `bfe/` codebase (the data-plane BFE Server).\n\n## Project overview\n\nBFE (Beyond Front End) is a modern layer-7 load balancer originated at Baidu and a CNCF sandbox project. This repository contains **BFE Server**, the data-plane component that forwards user traffic based on content-based routing, load balancing, and a flexible plugin framework.\n\nBFE system context (for orientation only):\n- **Data plane**: BFE Server (this repo) — forwards traffic.\n- **Control plane**: API-Server, Conf-Agent, Dashboard (separate repos) — manage and distribute configuration.\n- **Kubernetes integration**: BFE Ingress Controller (separate repo).\n\n## High-level architecture\n\nEntry point: `bfe.go`\n- Parses flags (`-c conf_root`, `-l log_dir`, `-t test_conf`, etc.).\n- Loads server config via `bfe_config/bfe_conf.BfeConfigLoad`.\n- Starts the server via `bfe_server.StartUp`.\n\nCore request flow:\n1. Listener (`bfe_server/`) accepts HTTP/HTTPS/HTTP2/WebSocket/SPDY/FastCGI connections.\n2. TLS handshake and session handling (`bfe_tls/`).\n3. HTTP request parsing (`bfe_http/`, `bfe_http2/`, `bfe_bufio/`).\n4. Routing: host table → cluster table (`bfe_route/`, `bfe_config/bfe_route_conf/`).\n5. Module pipeline execution in fixed order (`bfe_modules/`, registered in `bfe_modules/bfe_modules.go`).\n6. Backend selection and load balancing (`bfe_balance/`).\n7. Proxying and response handling (`bfe_server/reverseproxy.go`, `bfe_server/response.go`).\n\n## Directory structure and module relationships\n\n| Directory | Responsibility |\n|-----------|----------------|\n| `bfe_server/` | HTTP(S) listeners, connection handling, reverse proxy, TLS termination, module registration, status/monitoring. |\n| `bfe_route/` | Host and cluster routing tables, trie-based lookups (`trie/`), server data config (`server_data_conf.go`). |\n| `bfe_balance/` | Backend instances (`backend/`), GSLB (`bal_gslb/`) and SLB (`bal_slb/`) balancing policies, balance table. |\n| `bfe_config/` | Configuration loading: `bfe_conf/`, `bfe_route_conf/`, `bfe_cluster_conf/`, `bfe_tls_conf/`. |\n| `bfe_http/`, `bfe_http2/`, `bfe_websocket/`, `bfe_spdy/`, `bfe_fcgi/`, `bfe_stream/` | Protocol implementations. |\n| `bfe_tls/` | TLS handshake, certificates, session cache, server rules. |\n| `bfe_module/` | Plugin framework: module interface, callback/handler lists, filters. |\n| `bfe_modules/` | Built-in modules (access, WAF, redirect, rewrite, AI routing, rate limiting, etc.). Registered in `bfe_modules/bfe_modules.go`. |\n| `bfe_basic/` | Condition parser/primitives used by modules. Generated parser code lives in `bfe_basic/condition/parser`. |\n| `bfe_net/`, `bfe_bufio/`, `bfe_util/`, `bfe_debug/` | Shared network, buffered I/O, utilities, debug flags. |\n| `conf/` | Sample runtime configuration files. |\n| `docs/`, `examples/`, `tests/` | Documentation, deployment examples, and integration tests. |\n\n## Build/test conventions\n\n- **Go version**: 1.22 (`go.mod`).\n- **Module**: `github.com/bfenetworks/bfe`.\n- **Build**: `make` (or `make all`) → prepare, compile, package.\n  - `make build` builds the `bfe` binary.\n  - `make strip` builds without symbols.\n- **Test**: `make test` runs `go test -cover ./...` and `go vet ./...`.\n- **Prepare**: `make prepare` installs `goyacc` and regenerates `bfe_basic/condition/parser` via `go generate`.\n- **Lint/static analysis**: `make check` runs `staticcheck`; `make license-check` / `make license-fix` use `license-eye`.\n- **Pre-commit**: Install with `pre-commit install`; `gofmt` is required.\n- **Docker**: `make docker` builds prod + debug images; `make docker-push REGISTRY=...` builds and pushes multi-arch images.\n- **Release**: `make release` builds tar.gz packages for darwin/amd64, linux/amd64, linux/arm64, windows/amd64.\n\n## Common modification patterns\n\n### Add or modify a BFE module\n1. Create a package under `bfe_modules/mod_<name>/`.\n2. Implement `bfe_module.BfeModule` and the required callbacks/handlers.\n3. Add config loader under `bfe_config/` if new config files are needed.\n4. Add module registration in `bfe_modules/bfe_modules.go` in the correct execution order; document ordering requirements in comments.\n5. Add sample config under `conf/` and update config documentation.\n6. Add unit tests using `testing` + `testify`.\n7. Run `make test` before submitting.\n\n### AI gateway module changes\n\nThe AI gateway modules under `bfe_modules/mod_ai_*` and `bfe_modules/mod_body_process` have ordering and lifecycle interdependencies:\n\n- `mod_ai_route` runs early to select the target cluster/model.\n- `mod_ai_token_auth` runs at `HandleFoundProduct` for API Key validation and quota plan binding; it also performs final quota deduction at `HandleRequestFinish`.\n- `mod_body_process` runs at `HandleReadResponse` and is responsible for parsing token usage from streaming (SSE) responses. If you modify RMB quota deduction, ensure streaming scenarios still work when `mod_body_process` is loaded.\n- For RMB quota details, see `docs/zh_cn/sys_design/rmb_quota.md`.\n\n### Routing changes\n- Host/cluster tables: `bfe_route/`.\n- Config loaders: `bfe_config/bfe_route_conf/`.\n- Sample configs: `conf/`.\n\n### Load-balancing changes\n- Backend model: `bfe_balance/backend/`.\n- Balancing policies: `bfe_balance/bal_gslb/` and `bfe_balance/bal_slb/`.\n- Balance table: `bfe_balance/bal_table.go`.\n\n### Protocol support changes\n- HTTP: `bfe_http/`, `bfe_server/http_conn.go`.\n- HTTP/2: `bfe_http2/`.\n- WebSocket: `bfe_websocket/`.\n- TLS: `bfe_tls/`.\n\n### Condition/rule language changes\n- Grammar/parser: `bfe_basic/condition/parser`.\n- Run `make prepare` after grammar changes to regenerate parser code.\n\n## Agent guidelines\n\n- **Preserve module order** in `bfe_modules/bfe_modules.go`. Many modules have explicit ordering requirements; keep the comments up to date.\n- **Regenerate generated code** after parser/grammar changes (`make prepare`).\n- **Keep tests idiomatic**: use `testing` and `testify/assert`/`require`. Place `_test.go` files next to the code under test.\n- **License headers**: all new source files need the Apache 2.0 header. Use `make license-fix` if unsure.\n- **Do not hand-edit vendored or generated files**.\n- **Run `make test`** as the minimal local verification.\n- **Configuration changes must be reflected in `conf/`** so that `make package` and Docker builds produce a usable default setup.\n\n## Useful references\n\n- `README.md` / `README-CN.md` — project overview and quick start.\n- `CONTRIBUTING.md` — workflow, commit sign-off, code style.\n- `Makefile` — build, test, Docker, and release targets.\n- `docs/en_us/introduction/overview.md` — detailed architecture documentation.\n"},"files":{"AGENTS.md":"# AGENTS.md — BFE Server\n\nThis file guides AI coding agents working on the `bfe/` codebase (the data-plane BFE Server).\n\n## Project overview\n\nBFE (Beyond Front End) is a modern layer-7 load balancer originated at Baidu and a CNCF sandbox project. This repository contains **BFE Server**, the data-plane component that forwards user traffic based on content-based routing, load balancing, and a flexible plugin framework.\n\nBFE system context (for orientation only):\n- **Data plane**: BFE Server (this repo) — forwards traffic.\n- **Control plane**: API-Server, Conf-Agent, Dashboard (separate repos) — manage and distribute configuration.\n- **Kubernetes integration**: BFE Ingress Controller (separate repo).\n\n## High-level architecture\n\nEntry point: `bfe.go`\n- Parses flags (`-c conf_root`, `-l log_dir`, `-t test_conf`, etc.).\n- Loads server config via `bfe_config/bfe_conf.BfeConfigLoad`.\n- Starts the server via `bfe_server.StartUp`.\n\nCore request flow:\n1. Listener (`bfe_server/`) accepts HTTP/HTTPS/HTTP2/WebSocket/SPDY/FastCGI connections.\n2. TLS handshake and session handling (`bfe_tls/`).\n3. HTTP request parsing (`bfe_http/`, `bfe_http2/`, `bfe_bufio/`).\n4. Routing: host table → cluster table (`bfe_route/`, `bfe_config/bfe_route_conf/`).\n5. Module pipeline execution in fixed order (`bfe_modules/`, registered in `bfe_modules/bfe_modules.go`).\n6. Backend selection and load balancing (`bfe_balance/`).\n7. Proxying and response handling (`bfe_server/reverseproxy.go`, `bfe_server/response.go`).\n\n## Directory structure and module relationships\n\n| Directory | Responsibility |\n|-----------|----------------|\n| `bfe_server/` | HTTP(S) listeners, connection handling, reverse proxy, TLS termination, module registration, status/monitoring. |\n| `bfe_route/` | Host and cluster routing tables, trie-based lookups (`trie/`), server data config (`server_data_conf.go`). |\n| `bfe_balance/` | Backend instances (`backend/`), GSLB (`bal_gslb/`) and SLB (`bal_slb/`) balancing policies, balance table. |\n| `bfe_config/` | Configuration loading: `bfe_conf/`, `bfe_route_conf/`, `bfe_cluster_conf/`, `bfe_tls_conf/`. |\n| `bfe_http/`, `bfe_http2/`, `bfe_websocket/`, `bfe_spdy/`, `bfe_fcgi/`, `bfe_stream/` | Protocol implementations. |\n| `bfe_tls/` | TLS handshake, certificates, session cache, server rules. |\n| `bfe_module/` | Plugin framework: module interface, callback/handler lists, filters. |\n| `bfe_modules/` | Built-in modules (access, WAF, redirect, rewrite, AI routing, rate limiting, etc.). Registered in `bfe_modules/bfe_modules.go`. |\n| `bfe_basic/` | Condition parser/primitives used by modules. Generated parser code lives in `bfe_basic/condition/parser`. |\n| `bfe_net/`, `bfe_bufio/`, `bfe_util/`, `bfe_debug/` | Shared network, buffered I/O, utilities, debug flags. |\n| `conf/` | Sample runtime configuration files. |\n| `docs/`, `examples/`, `tests/` | Documentation, deployment examples, and integration tests. |\n\n## Build/test conventions\n\n- **Go version**: 1.22 (`go.mod`).\n- **Module**: `github.com/bfenetworks/bfe`.\n- **Build**: `make` (or `make all`) → prepare, compile, package.\n  - `make build` builds the `bfe` binary.\n  - `make strip` builds without symbols.\n- **Test**: `make test` runs `go test -cover ./...` and `go vet ./...`.\n- **Prepare**: `make prepare` installs `goyacc` and regenerates `bfe_basic/condition/parser` via `go generate`.\n- **Lint/static analysis**: `make check` runs `staticcheck`; `make license-check` / `make license-fix` use `license-eye`.\n- **Pre-commit**: Install with `pre-commit install`; `gofmt` is required.\n- **Docker**: `make docker` builds prod + debug images; `make docker-push REGISTRY=...` builds and pushes multi-arch images.\n- **Release**: `make release` builds tar.gz packages for darwin/amd64, linux/amd64, linux/arm64, windows/amd64.\n\n## Common modification patterns\n\n### Add or modify a BFE module\n1. Create a package under `bfe_modules/mod_<name>/`.\n2. Implement `bfe_module.BfeModule` and the required callbacks/handlers.\n3. Add config loader under `bfe_config/` if new config files are needed.\n4. Add module registration in `bfe_modules/bfe_modules.go` in the correct execution order; document ordering requirements in comments.\n5. Add sample config under `conf/` and update config documentation.\n6. Add unit tests using `testing` + `testify`.\n7. Run `make test` before submitting.\n\n### AI gateway module changes\n\nThe AI gateway modules under `bfe_modules/mod_ai_*` and `bfe_modules/mod_body_process` have ordering and lifecycle interdependencies:\n\n- `mod_ai_route` runs early to select the target cluster/model.\n- `mod_ai_token_auth` runs at `HandleFoundProduct` for API Key validation and quota plan binding; it also performs final quota deduction at `HandleRequestFinish`.\n- `mod_body_process` runs at `HandleReadResponse` and is responsible for parsing token usage from streaming (SSE) responses. If you modify RMB quota deduction, ensure streaming scenarios still work when `mod_body_process` is loaded.\n- For RMB quota details, see `docs/zh_cn/sys_design/rmb_quota.md`.\n\n### Routing changes\n- Host/cluster tables: `bfe_route/`.\n- Config loaders: `bfe_config/bfe_route_conf/`.\n- Sample configs: `conf/`.\n\n### Load-balancing changes\n- Backend model: `bfe_balance/backend/`.\n- Balancing policies: `bfe_balance/bal_gslb/` and `bfe_balance/bal_slb/`.\n- Balance table: `bfe_balance/bal_table.go`.\n\n### Protocol support changes\n- HTTP: `bfe_http/`, `bfe_server/http_conn.go`.\n- HTTP/2: `bfe_http2/`.\n- WebSocket: `bfe_websocket/`.\n- TLS: `bfe_tls/`.\n\n### Condition/rule language changes\n- Grammar/parser: `bfe_basic/condition/parser`.\n- Run `make prepare` after grammar changes to regenerate parser code.\n\n## Agent guidelines\n\n- **Preserve module order** in `bfe_modules/bfe_modules.go`. Many modules have explicit ordering requirements; keep the comments up to date.\n- **Regenerate generated code** after parser/grammar changes (`make prepare`).\n- **Keep tests idiomatic**: use `testing` and `testify/assert`/`require`. Place `_test.go` files next to the code under test.\n- **License headers**: all new source files need the Apache 2.0 header. Use `make license-fix` if unsure.\n- **Do not hand-edit vendored or generated files**.\n- **Run `make test`** as the minimal local verification.\n- **Configuration changes must be reflected in `conf/`** so that `make package` and Docker builds produce a usable default setup.\n\n## Useful references\n\n- `README.md` / `README-CN.md` — project overview and quick start.\n- `CONTRIBUTING.md` — workflow, commit sign-off, code style.\n- `Makefile` — build, test, Docker, and release targets.\n- `docs/en_us/introduction/overview.md` — detailed architecture documentation.\n"},"items":[{"name":"AGENTS.md","path":"AGENTS.md","rawUrl":"https://raw.githubusercontent.com/bfenetworks/bfe/HEAD/AGENTS.md","title":"AI Agent Protocol & Instructions","category":"root-instruction","format":"markdown","content":"# AGENTS.md — BFE Server\n\nThis file guides AI coding agents working on the `bfe/` codebase (the data-plane BFE Server).\n\n## Project overview\n\nBFE (Beyond Front End) is a modern layer-7 load balancer originated at Baidu and a CNCF sandbox project. This repository contains **BFE Server**, the data-plane component that forwards user traffic based on content-based routing, load balancing, and a flexible plugin framework.\n\nBFE system context (for orientation only):\n- **Data plane**: BFE Server (this repo) — forwards traffic.\n- **Control plane**: API-Server, Conf-Agent, Dashboard (separate repos) — manage and distribute configuration.\n- **Kubernetes integration**: BFE Ingress Controller (separate repo).\n\n## High-level architecture\n\nEntry point: `bfe.go`\n- Parses flags (`-c conf_root`, `-l log_dir`, `-t test_conf`, etc.).\n- Loads server config via `bfe_config/bfe_conf.BfeConfigLoad`.\n- Starts the server via `bfe_server.StartUp`.\n\nCore request flow:\n1. Listener (`bfe_server/`) accepts HTTP/HTTPS/HTTP2/WebSocket/SPDY/FastCGI connections.\n2. TLS handshake and session handling (`bfe_tls/`).\n3. HTTP request parsing (`bfe_http/`, `bfe_http2/`, `bfe_bufio/`).\n4. Routing: host table → cluster table (`bfe_route/`, `bfe_config/bfe_route_conf/`).\n5. Module pipeline execution in fixed order (`bfe_modules/`, registered in `bfe_modules/bfe_modules.go`).\n6. Backend selection and load balancing (`bfe_balance/`).\n7. Proxying and response handling (`bfe_server/reverseproxy.go`, `bfe_server/response.go`).\n\n## Directory structure and module relationships\n\n| Directory | Responsibility |\n|-----------|----------------|\n| `bfe_server/` | HTTP(S) listeners, connection handling, reverse proxy, TLS termination, module registration, status/monitoring. |\n| `bfe_route/` | Host and cluster routing tables, trie-based lookups (`trie/`), server data config (`server_data_conf.go`). |\n| `bfe_balance/` | Backend instances (`backend/`), GSLB (`bal_gslb/`) and SLB (`bal_slb/`) balancing policies, balance table. |\n| `bfe_config/` | Configuration loading: `bfe_conf/`, `bfe_route_conf/`, `bfe_cluster_conf/`, `bfe_tls_conf/`. |\n| `bfe_http/`, `bfe_http2/`, `bfe_websocket/`, `bfe_spdy/`, `bfe_fcgi/`, `bfe_stream/` | Protocol implementations. |\n| `bfe_tls/` | TLS handshake, certificates, session cache, server rules. |\n| `bfe_module/` | Plugin framework: module interface, callback/handler lists, filters. |\n| `bfe_modules/` | Built-in modules (access, WAF, redirect, rewrite, AI routing, rate limiting, etc.). Registered in `bfe_modules/bfe_modules.go`. |\n| `bfe_basic/` | Condition parser/primitives used by modules. Generated parser code lives in `bfe_basic/condition/parser`. |\n| `bfe_net/`, `bfe_bufio/`, `bfe_util/`, `bfe_debug/` | Shared network, buffered I/O, utilities, debug flags. |\n| `conf/` | Sample runtime configuration files. |\n| `docs/`, `examples/`, `tests/` | Documentation, deployment examples, and integration tests. |\n\n## Build/test conventions\n\n- **Go version**: 1.22 (`go.mod`).\n- **Module**: `github.com/bfenetworks/bfe`.\n- **Build**: `make` (or `make all`) → prepare, compile, package.\n  - `make build` builds the `bfe` binary.\n  - `make strip` builds without symbols.\n- **Test**: `make test` runs `go test -cover ./...` and `go vet ./...`.\n- **Prepare**: `make prepare` installs `goyacc` and regenerates `bfe_basic/condition/parser` via `go generate`.\n- **Lint/static analysis**: `make check` runs `staticcheck`; `make license-check` / `make license-fix` use `license-eye`.\n- **Pre-commit**: Install with `pre-commit install`; `gofmt` is required.\n- **Docker**: `make docker` builds prod + debug images; `make docker-push REGISTRY=...` builds and pushes multi-arch images.\n- **Release**: `make release` builds tar.gz packages for darwin/amd64, linux/amd64, linux/arm64, windows/amd64.\n\n## Common modification patterns\n\n### Add or modify a BFE module\n1. Create a package under `bfe_modules/mod_<name>/`.\n2. Implement `bfe_module.BfeModule` and the required callbacks/handlers.\n3. Add config loader under `bfe_config/` if new config files are needed.\n4. Add module registration in `bfe_modules/bfe_modules.go` in the correct execution order; document ordering requirements in comments.\n5. Add sample config under `conf/` and update config documentation.\n6. Add unit tests using `testing` + `testify`.\n7. Run `make test` before submitting.\n\n### AI gateway module changes\n\nThe AI gateway modules under `bfe_modules/mod_ai_*` and `bfe_modules/mod_body_process` have ordering and lifecycle interdependencies:\n\n- `mod_ai_route` runs early to select the target cluster/model.\n- `mod_ai_token_auth` runs at `HandleFoundProduct` for API Key validation and quota plan binding; it also performs final quota deduction at `HandleRequestFinish`.\n- `mod_body_process` runs at `HandleReadResponse` and is responsible for parsing token usage from streaming (SSE) responses. If you modify RMB quota deduction, ensure streaming scenarios still work when `mod_body_process` is loaded.\n- For RMB quota details, see `docs/zh_cn/sys_design/rmb_quota.md`.\n\n### Routing changes\n- Host/cluster tables: `bfe_route/`.\n- Config loaders: `bfe_config/bfe_route_conf/`.\n- Sample configs: `conf/`.\n\n### Load-balancing changes\n- Backend model: `bfe_balance/backend/`.\n- Balancing policies: `bfe_balance/bal_gslb/` and `bfe_balance/bal_slb/`.\n- Balance table: `bfe_balance/bal_table.go`.\n\n### Protocol support changes\n- HTTP: `bfe_http/`, `bfe_server/http_conn.go`.\n- HTTP/2: `bfe_http2/`.\n- WebSocket: `bfe_websocket/`.\n- TLS: `bfe_tls/`.\n\n### Condition/rule language changes\n- Grammar/parser: `bfe_basic/condition/parser`.\n- Run `make prepare` after grammar changes to regenerate parser code.\n\n## Agent guidelines\n\n- **Preserve module order** in `bfe_modules/bfe_modules.go`. Many modules have explicit ordering requirements; keep the comments up to date.\n- **Regenerate generated code** after parser/grammar changes (`make prepare`).\n- **Keep tests idiomatic**: use `testing` and `testify/assert`/`require`. Place `_test.go` files next to the code under test.\n- **License headers**: all new source files need the Apache 2.0 header. Use `make license-fix` if unsure.\n- **Do not hand-edit vendored or generated files**.\n- **Run `make test`** as the minimal local verification.\n- **Configuration changes must be reflected in `conf/`** so that `make package` and Docker builds produce a usable default setup.\n\n## Useful references\n\n- `README.md` / `README-CN.md` — project overview and quick start.\n- `CONTRIBUTING.md` — workflow, commit sign-off, code style.\n- `Makefile` — build, test, Docker, and release targets.\n- `docs/en_us/introduction/overview.md` — detailed architecture documentation.\n","isInternal":false,"tokens":1737,"sizeBytes":6693}],"systemPromptSnippet":"<yakaai_skills repo=\"bfenetworks/bfe\">\n<!-- File: AGENTS.md (Tokens: ~1737 | Category: root-instruction) -->\n# AGENTS.md — BFE Server\n\nThis file guides AI coding agents working on the `bfe/` codebase (the data-plane BFE Server).\n\n## Project overview\n\nBFE (Beyond Front End) is a modern layer-7 load balancer originated at Baidu and a CNCF sandbox project. This repository contains **BFE Server**, the data-plane component that forwards user traffic based on content-based routing, load balancing, and a flexible plugin framework.\n\nBFE system context (for orientation only):\n- **Data plane**: BFE Server (this repo) — forwards traffic.\n- **Control plane**: API-Server, Conf-Agent, Dashboard (separate repos) — manage and distribute configuration.\n- **Kubernetes integration**: BFE Ingress Controller (separate repo).\n\n## High-level architecture\n\nEntry point: `bfe.go`\n- Parses flags (`-c conf_root`, `-l log_dir`, `-t test_conf`, etc.).\n- Loads server config via `bfe_config/bfe_conf.BfeConfigLoad`.\n- Starts the server via `bfe_server.StartUp`.\n\nCore request flow:\n1. Listener (`bfe_server/`) accepts HTTP/HTTPS/HTTP2/WebSocket/SPDY/FastCGI connections.\n2. TLS handshake and session handling (`bfe_tls/`).\n3. HTTP request parsing (`bfe_http/`, `bfe_http2/`, `bfe_bufio/`).\n4. Routing: host table → cluster table (`bfe_route/`, `bfe_config/bfe_route_conf/`).\n5. Module pipeline execution in fixed order (`bfe_modules/`, registered in `bfe_modules/bfe_modules.go`).\n6. Backend selection and load balancing (`bfe_balance/`).\n7. Proxying and response handling (`bfe_server/reverseproxy.go`, `bfe_server/response.go`).\n\n## Directory structure and module relationships\n\n| Directory | Responsibility |\n|-----------|----------------|\n| `bfe_server/` | HTTP(S) listeners, connection handling, reverse proxy, TLS termination, module registration, status/monitoring. |\n| `bfe_route/` | Host and cluster routing tables, trie-based lookups (`trie/`), server data config (`server_data_conf.go`). |\n| `bfe_balance/` | Backend instances (`backend/`), GSLB (`bal_gslb/`) and SLB (`bal_slb/`) balancing policies, balance table. |\n| `bfe_config/` | Configuration loading: `bfe_conf/`, `bfe_route_conf/`, `bfe_cluster_conf/`, `bfe_tls_conf/`. |\n| `bfe_http/`, `bfe_http2/`, `bfe_websocket/`, `bfe_spdy/`, `bfe_fcgi/`, `bfe_stream/` | Protocol implementations. |\n| `bfe_tls/` | TLS handshake, certificates, session cache, server rules. |\n| `bfe_module/` | Plugin framework: module interface, callback/handler lists, filters. |\n| `bfe_modules/` | Built-in modules (access, WAF, redirect, rewrite, AI routing, rate limiting, etc.). Registered in `bfe_modules/bfe_modules.go`. |\n| `bfe_basic/` | Condition parser/primitives used by modules. Generated parser code lives in `bfe_basic/condition/parser`. |\n| `bfe_net/`, `bfe_bufio/`, `bfe_util/`, `bfe_debug/` | Shared network, buffered I/O, utilities, debug flags. |\n| `conf/` | Sample runtime configuration files. |\n| `docs/`, `examples/`, `tests/` | Documentation, deployment examples, and integration tests. |\n\n## Build/test conventions\n\n- **Go version**: 1.22 (`go.mod`).\n- **Module**: `github.com/bfenetworks/bfe`.\n- **Build**: `make` (or `make all`) → prepare, compile, package.\n  - `make build` builds the `bfe` binary.\n  - `make strip` builds without symbols.\n- **Test**: `make test` runs `go test -cover ./...` and `go vet ./...`.\n- **Prepare**: `make prepare` installs `goyacc` and regenerates `bfe_basic/condition/parser` via `go generate`.\n- **Lint/static analysis**: `make check` runs `staticcheck`; `make license-check` / `make license-fix` use `license-eye`.\n- **Pre-commit**: Install with `pre-commit install`; `gofmt` is required.\n- **Docker**: `make docker` builds prod + debug images; `make docker-push REGISTRY=...` builds and pushes multi-arch images.\n- **Release**: `make release` builds tar.gz packages for darwin/amd64, linux/amd64, linux/arm64, windows/amd64.\n\n## Common modification patterns\n\n### Add or modify a BFE module\n1. Create a package under `bfe_modules/mod_<name>/`.\n2. Implement `bfe_module.BfeModule` and the required callbacks/handlers.\n3. Add config loader under `bfe_config/` if new config files are needed.\n4. Add module registration in `bfe_modules/bfe_modules.go` in the correct execution order; document ordering requirements in comments.\n5. Add sample config under `conf/` and update config documentation.\n6. Add unit tests using `testing` + `testify`.\n7. Run `make test` before submitting.\n\n### AI gateway module changes\n\nThe AI gateway modules under `bfe_modules/mod_ai_*` and `bfe_modules/mod_body_process` have ordering and lifecycle interdependencies:\n\n- `mod_ai_route` runs early to select the target cluster/model.\n- `mod_ai_token_auth` runs at `HandleFoundProduct` for API Key validation and quota plan binding; it also performs final quota deduction at `HandleRequestFinish`.\n- `mod_body_process` runs at `HandleReadResponse` and is responsible for parsing token usage from streaming (SSE) responses. If you modify RMB quota deduction, ensure streaming scenarios still work when `mod_body_process` is loaded.\n- For RMB quota details, see `docs/zh_cn/sys_design/rmb_quota.md`.\n\n### Routing changes\n- Host/cluster tables: `bfe_route/`.\n- Config loaders: `bfe_config/bfe_route_conf/`.\n- Sample configs: `conf/`.\n\n### Load-balancing changes\n- Backend model: `bfe_balance/backend/`.\n- Balancing policies: `bfe_balance/bal_gslb/` and `bfe_balance/bal_slb/`.\n- Balance table: `bfe_balance/bal_table.go`.\n\n### Protocol support changes\n- HTTP: `bfe_http/`, `bfe_server/http_conn.go`.\n- HTTP/2: `bfe_http2/`.\n- WebSocket: `bfe_websocket/`.\n- TLS: `bfe_tls/`.\n\n### Condition/rule language changes\n- Grammar/parser: `bfe_basic/condition/parser`.\n- Run `make prepare` after grammar changes to regenerate parser code.\n\n## Agent guidelines\n\n- **Preserve module order** in `bfe_modules/bfe_modules.go`. Many modules have explicit ordering requirements; keep the comments up to date.\n- **Regenerate generated code** after parser/grammar changes (`make prepare`).\n- **Keep tests idiomatic**: use `testing` and `testify/assert`/`require`. Place `_test.go` files next to the code under test.\n- **License headers**: all new source files need the Apache 2.0 header. Use `make license-fix` if unsure.\n- **Do not hand-edit vendored or generated files**.\n- **Run `make test`** as the minimal local verification.\n- **Configuration changes must be reflected in `conf/`** so that `make package` and Docker builds produce a usable default setup.\n\n## Useful references\n\n- `README.md` / `README-CN.md` — project overview and quick start.\n- `CONTRIBUTING.md` — workflow, commit sign-off, code style.\n- `Makefile` — build, test, Docker, and release targets.\n- `docs/en_us/introduction/overview.md` — detailed architecture documentation.\n</yakaai_skills>"}