codeflash-internal/tiles/codeflash-internal-rules/rules/code-style.md
Kevin Turcios dfc56f19a0 feat: add Tessl tiles for codeflash-internal (rules, docs, skills)
Three private tiles published to the codeflash workspace:
- codeflash-internal-rules: 6 eager rules (code-style, architecture,
  optimization-patterns, git-conventions, testing-rules, multi-language-handlers)
- codeflash-internal-docs: 8 lazy doc pages (domain-types, optimization-pipeline,
  test-generation-pipeline, context-extraction, aiservice/cf-api endpoints,
  configuration-thresholds, llm-provider-abstraction)
- codeflash-internal-skills: 4 on-demand skills (debug-optimization-failure,
  add-language-support, add-api-endpoint, debug-test-generation)
2026-02-14 22:16:33 -05:00

2.1 KiB

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