id: no-api-env-imports
language: ts
severity: error
message: API routes must not import runtime env directly; read request-scoped bindings from handler locals/services.
files:
  - '**/src/pages/api/**/*.ts'
ignores:
  - '**/src/server/api/define-api.ts'
  - '**/src/server/middleware/services.ts'
  - '**/src/pages/api/test/factory/**/*.ts'
rule:
  any:
    - pattern: import { env } from '@/server/env'
    - pattern: import { env } from '@/server/env.js'
    - pattern: $LOCALS.runtime?.env
    - pattern: $LOCALS.runtime!.env
    - pattern: $LOCALS.runtime.env
