<h1 align="center">
<a href="https://prompts.chat">
This file provides guidance to coding agents when working with code in this repository.
Sign in to like and favorite skills
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 |
|---|---|
| Check formatting (all languages) |
| Fix formatting (all languages) |
| Run linters (all languages) |
| Fix lint issues (all languages) |
| Run Go tests |
| Run Rust tests |
| Run Python tests |
| Run integration tests |
| Build cog CLI binary |
| Build coglet wheel (dev) |
| Build SDK wheel |
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 wheelOther:
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 binary, embedding the Python wheelmake install - Builds and installs the Cog CLI binary to /usr/local/bin, or to a custom path with make install PREFIX=/custom/pathmise 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 developmentmise 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:
make install PREFIX=./cog COG_BINARY=./cog/cog mise run test:integration
mise install to set up the development environmentmise run build:sdk after making changes to the ./python directorymise run fmt:fix to format codemise run lint to check code quality./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 integrationpkg/dockerfile/embed/)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.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