<h1 align="center">
<a href="https://prompts.chat">
This file provides guidance to coding agents when working with code in this repository.
Loading actions...
<a href="https://prompts.chat">
TypeScript and ESLint rules that MUST be followed when creating, modifying, or reviewing any file under apps/frontend/, including .ts, .tsx, .js, and .jsx files. Also apply when discussing frontend linting, type safety, or ESLint configuration.
risks
This file provides guidance to coding agents when working with code in this repository.
Cog is a tool that packages machine learning models in production-ready containers.
It consists of:
cmd/cog/) - Command-line interface for building, running, and deploying models, written in Gopython/cog/) - Python library for defining model predictors and training in Pythoncrates/) - Rust-based prediction server that runs inside containers, with Python bindings via PyO3Documentation for the CLI and SDK is available by reading ./docs/llms.txt.
Development tasks are managed with mise. Run mise tasks to see all available tasks.
| Task | Description |
|---|---|
mise run fmt | Check formatting (all languages) |
mise run fmt:fix | Fix formatting (all languages) |
mise run lint | Run linters (all languages) |
mise run lint:fix | Fix lint issues (all languages) |
mise run test:go | Run Go tests |
mise run test:rust | Run Rust tests |
mise run test:python | Run Python tests |
mise run test:integration | Run integration tests |
mise run build:cog | Build cog CLI binary |
mise run build:coglet | Build coglet wheel (dev) |
mise run build:sdk | Build SDK wheel |
mise run install | Build and symlink cog to /usr/local/bin |
mise run docs:llm | IMPORTANT: Regenerate docs/llms.txt after editing docs |
mise run docs:cli | Generate CLI reference docs from Go source code |
Tasks follow a consistent naming pattern:
task:go, task:rust, task:pythonbuild:cog, build:coglet, build:sdkfmt and lint default to check mode (non-destructive); use :fix suffix to auto-fixFormat:
mise run fmt / mise run fmt:check - Check all (alias)mise run fmt:fix - Fix allmise run fmt:go / mise run fmt:rust / mise run fmt:python - Per-languageLint:
mise run lint / mise run lint:check - Check all (alias)mise run lint:fix - Fix allmise run lint:go / mise run lint:rust / mise run lint:python - Per-languagemise run lint:rust:deny - Check Rust licenses/advisoriesTest:
mise run test:go - Go unit testsmise run test:rust - Rust unit testsmise run test:python - Python unit tests (via tox)mise run test:coglet:python - Coglet Python binding testsmise run test:integration - Integration testsBuild:
mise run build:cog - Build cog CLI (development)mise run build:cog:release - Build cog CLI (release)mise run build:coglet - Build coglet wheel (dev install)mise run build:coglet:wheel - Build coglet wheel (native platform)mise run build:coglet:wheel:linux-x64 - Build for Linux x86_64mise run build:coglet:wheel:linux-arm64 - Build for Linux ARM64mise run build:sdk - Build SDK wheelInstall:
mise run install - Symlink cog CLI to /usr/local/bin (requires build:cog first)PREFIX=/custom/path mise run install - Symlink to custom locationOther:
mise run typecheck - Type check all languagesmise run generate - Run code generationmise run clean - Clean all build artifactsmise run docs - Build documentationmise run docs:serve - Serve docs locallygithub.com/replicate/cog/pkg/...)mise run fmt:go:fixpkg/errors.CodedError for user-facing errors with error codestestify/require for assertions; prefer table-driven testsExample import block:
import (
"fmt"
"github.com/spf13/cobra"
"github.com/replicate/cog/pkg/config"
)
mise run fmt:python:fixtyping_extensions for compatibility; avoid Any where possiblemise run fmt:rust:fixmise run lint:rust (clippy)cargo-deny (see crates/deny.toml); run mise run lint:rust:denythiserror for typed errors, anyhow for application errorscargo test; snapshot tests use instaThe CLI code is in the cmd/cog/ and pkg/ directories. Support tooling is in the tools/ directory.
The main commands for working on the CLI are:
go run ./cmd/cog - Runs the Cog CLI directly from source (requires wheel to be built first)mise run build:cog - Builds the Cog CLI binarymise run install - Symlinks the built binary to /usr/local/bin (run build:cog first), or to a custom path with PREFIX=/custom/path mise run installmise run test:go - Runs all Go unit testsgo test ./pkg/... - Runs tests directly with go testThe Python SDK is developed in the python/cog/ directory. It uses uv for virtual environments and tox for testing across multiple Python versions.
The main commands for working on the SDK are:
mise run build:sdk - Builds the Python wheelmise run test:python - Runs Python tests across all supported versionsCoglet is the Rust-based prediction server that runs inside Cog containers, handling HTTP requests, worker process management, and prediction execution.
The code is in the crates/ directory:
crates/coglet/ - Core Rust library (HTTP server, worker orchestration, IPC)crates/coglet-python/ - PyO3 bindings for Python predictor integration (requires Python 3.10+)For detailed architecture documentation, see crates/README.md and crates/coglet/README.md.
The main commands for working on Coglet are:
mise run build:coglet - Build and install coglet wheel for development (macOS, for local Rust/Python tests)mise run build:coglet:wheel:linux-x64 - Build Linux x86_64 wheel (required to test Rust changes in Docker containers via cog predict/cog train)mise run test:rust - Run Rust unit testsmise run lint:rust - Run clippy lintermise run fmt:rust:fix - Format codeGo code is tested using the built-in go test framework:
go test ./pkg/... -run <name> - Runs specific Go tests by namemise run test:go - Runs all Go unit testsPython code is tested using tox, which allows testing across multiple Python versions and configurations:
mise run test:python - Runs all Python unit testsuv run tox -e py312-tests -- python/tests/server/test_http.py::test_openapi_specification_with_yield - Runs a specific Python testThe integration test suite in integration-tests/ tests the end-to-end functionality of the Cog CLI and Python SDK using Go's testscript framework:
mise run test:integration - Runs the integration testsmise run test:integration string_predictor - Runs a specific integration testThe integration tests require a built Cog binary, which defaults to the first cog in PATH. Run tests against a specific binary with the COG_BINARY environment variable:
mise run build:cog
COG_BINARY=dist/go/*/cog mise run test:integration
mise install to set up the development environmentmise run build:sdk after making changes to the ./python directorymise run build:coglet:wheel:linux-x64 after making changes to the ./crates directory (needed for Docker testing)mise run build:cog to build the CLI (wheels are picked up from dist/ at Docker build time, not embedded in the binary)mise run fmt:fix to format codemise run lint to check code qualitymise run docs:llm to regenerate docs/llms.txt after changing README.md or any docs/*.md file./docs directory and make sure the documentation is up to dateThe CLI follows a command pattern with subcommands. The main components are:
pkg/cli/ - Command definitions (build, run, predict, serve, etc.)pkg/docker/ - Docker client and container managementpkg/dockerfile/ - Dockerfile generation and templatingpkg/config/ - cog.yaml parsing and validationpkg/image/ - Image building and pushing logicpython/cog/ - Core SDK
base_predictor.py - Base class for model predictorstypes.py - Input/output type definitionsserver/ - HTTP/queue server implementationcommand/ - Runner implementations for predict/trainThe prediction server that runs inside Cog containers. Uses a two-process architecture: a parent process (HTTP server + orchestrator) and a worker subprocess (Python predictor execution).
See crates/README.md for detailed architecture documentation.
crates/coglet/ - Core Rust library (HTTP server, worker orchestration, IPC bridge)crates/coglet-python/ - PyO3 bindings for Python predictor integrationdist/ at Docker build time (not embedded in the binary)For comprehensive architecture documentation, see architecture/.
pkg/cli/pkg/cli/root.gopkg/ subdirectorypython/cog/mise run build:sdk to rebuild wheelmise run test:pythonmise run test:integrationtools/compatgen/ for compatibility matrix generationdocs/ directory, written in Markdown and generated into HTML using mkdocs.docs/ or README.md, you MUST run mise run docs:llm to regenerate docs/llms.txt. This file is used by coding agents and should be kept in sync with the documentation.docs/cli.md) are auto-generated from Go source code. After modifying CLI commands in cmd/ or pkg/cli/, run mise run docs:cli to regenerate, and ensure mise run docs:cli:check passes before committing.Development tools are managed in two places that must be kept in sync:
mise.toml — Tool versions for local development (uses aqua backend for prebuilt binaries).github/workflows/ci.yaml — Tool installation for CI (uses dedicated GitHub Actions)CI deliberately avoids aqua downloads from GitHub Releases to prevent transient 502 failures. Instead, it uses:
| Tool | CI installation method | Why |
|---|---|---|
| gotestsum | go install | Uses Go module proxy, not GitHub Releases |
| cargo-deny | taiki-e/install-action | Prebuilt with checksum verification |
| cargo-nextest | taiki-e/install-action | Prebuilt with checksum verification |
| coglet wheel (maturin+zig) | PyO3/maturin-action | Bundles maturin and zig |
| golangci-lint | golangci/golangci-lint-action | Built-in caching |
| Rust toolchain | dtolnay/rust-toolchain | Guaranteed ordering |
Tools disabled in CI are listed in MISE_DISABLE_TOOLS in ci.yaml.
When updating a tool version, update both:
mise.toml (for local dev).github/workflows/ci.yaml (for CI)cog.yaml - User-facing model configurationpkg/config/config.go - Go code for parsing and validating cog.yamlpkg/config/data/config_schema_v1.0.json - JSON schema for cog.yamlpython/cog/base_predictor.py - Predictor interfacecrates/Cargo.toml - Rust workspace configurationcrates/README.md - Coglet architecture overviewmise.toml - Task definitions for development workflowmise run build:sdk after making Python changes before testing Go code