# Code Style

## Python (aiservice)

- **Python 3.12+** — use modern syntax (type unions `X | Y`, `match` statements)
- **Line length**: 120 characters
- **Tooling**: Ruff for linting/formatting (`ruff check .`, `ruff format .`), mypy strict mode, ty for type checking, prek for pre-commit (`uv run prek run --all-files`)
- **Package management**: Always use `uv` — run commands via `uv run`
- **Comments**: Minimal — only explain "why", not "what"
- **Docstrings**: Do not add unless explicitly requested
- **Source transforms**: Use `libcst` for code modification/transformation (preserves formatting); `ast` is acceptable for read-only analysis
- **Async**: All endpoints are `async def` — runs under ASGI via uvicorn. Use `asyncio.TaskGroup` for concurrent operations
- **Schemas**: Use Pydantic `BaseModel` or `ninja.Schema` for all request/response types
- **LLM calls**: Use `aiservice/llm.py` — never call provider APIs directly
- **Prompts**: Stored as `.md` files alongside their modules, rendered with Jinja2
- **Lazy imports**: Use inside function bodies in routers to avoid circular dependencies (`# noqa: PLC0415`)

## JavaScript/TypeScript (cf-api, cf-webapp, VSC-Extension)

- All JS/TS packages use ESLint + Prettier. Run commands from each package directory
- **cf-api**: Express app. Webhook routes MUST be registered before body parser (raw body needed for signature verification). `instrument.ts` must be imported first in entry point (Sentry). Tests use dependency injection: `setXxxDependencies()` / `resetXxxDependencies()`
- **cf-webapp**: Next.js. Default to server components; `"use client"` only for interactivity. Server actions in `"use server"` files. Prisma queries in server components only. Path alias `@/*` → `./src/*`
- **VSC-Extension**: Different prettier config (80 width + semicolons vs 100/no-semi elsewhere). npm workspaces for local `@codeflash/*` packages. Sidebar is a separate Vite/React app embedded via webview postMessage
- **Prisma**: Schema in `common/prisma/schema.prisma`, shared by cf-api and cf-webapp. `common` is CommonJS — use `require`-style imports
