CODI is a rules-first, AI-assisted container optimisation toolkit that analyses, rewrites, benchmarks, and reports deterministic improvements across Node, Python, and Java stacks. The MVP ships:
- End-to-end CLI/API pipelines with embedded offline LLM + RAG memory (
codi:complete) - Air-gapped security enforcement, environment-aware config snapshots, and CPU/security validation suites
- Curated example runs, a
codi dashboardaggregator, and a static browser dashboard (docs/dashboard/) for showcasing optimisation impact - Schema-validated CMD/ENTRYPOINT rewrite catalog (
cmd_rewrites) with aRulesCataloghelper and regression coverage for deterministic rule selection - Renderer-aware CMD rewrites with template promotions ensuring shell-form commands convert to exec-form with rationale comments
- Full report/API/CLI surfacing of CMD analysis, dedicated report sections, and per-run metadata for CMD rewrites
All flows honour offline defaults, policy guardrails, and reproducible artefact layouts.
The MVP roadmap delivers two runtimes:
codi:slimβ Rules-based CLI and API without external model dependenciescodi:completeβ Slim runtime bundled with an offline LLM and lightweight RAG memory
codi/
βββ core/ # parse, detect, render, build, report, store, security
βββ cli/ # Typer/Rich-based CLI interface
βββ api/ # FastAPI REST service
βββ patterns/ # rules.yml templates for supported stacks
βββ models/ # Local LLM documentation and configs
βββ docker/ # Dockerfiles for Slim and Complete containers
βββ data/ # LLM training data pipeline
β βββ raw/ # Collected Dockerfiles + metadata
β βββ curated/ # Standardized, deduplicated data
β βββ pairs/ # Training pairs (JSONL)
β βββ splits/ # Train/val/test splits
βββ training/ # QLoRA training config, notebooks, and adapter packaging
βββ eval/ # LLM evaluation harness and metrics
βββ tune_module/ # Analyzer and Docker best-practice docs
βββ demo/ # Sample applications for testing (Node.js, Python, Java)
βββ tests/ # Test suite (unit + CLI + reporter)
βββ docs/ # PRD, task plan, estimates, quickstart, runbook
βββ Makefile # Build automation and shortcuts
βββ pyproject.toml # Python project configuration
βββ requirements.txt # Core dependencies
Core rules pipeline
- Typer/Rich CLI with
analyze,rewrite,run,report,all,perf,dashboard, andservecommands - Tolerant Dockerfile parser + stack detector + policy validation
- Stack-specific renderer sourcing
patterns/rules.yml - Metrics harness capturing size, layer, and timing estimates (dry-run)
RunStorefor reproducible artefact layout underruns/<timestamp>- Markdown and HTML reporter with diffs and rationale sections
API service
- FastAPI application in
api/server.pyexposing/analyze,/rewrite,/run,/report codi servecommand launching uvicorn with configurable host/port- OpenAPI metadata aligned with PRD schemas and response contracts
Container packaging
- Multi-stage
docker/Dockerfile.slim(Python 3.12-slim, non-rootcodiuser,AIRGAP=true) docker/Dockerfile.completeextending Slim with offline LLM runtime, shared/work/runsvolumes, and dual health checksdocker/runtime_complete.pyorchestrator that bootsLocalLLMServerbefore FastAPI
Security and environment
httpxair-gap guard enforcing zero outbound calls by default;AIRGAP_ALLOWLISTfor selective access- Central
CodiEnvironmentconfig snapshot (core/config.py) with CLI/API/container toggle support - Security gates rejecting risky Dockerfile patterns (privileged,
ADD http://, sudo)
LLM and RAG
- SQLite-backed
RAGIndexincore/store.pywith cosine retrieval, persisted per run - Guarded
LLMAssistfunctions generating summaries and template recommendations without emitting raw Dockerfiles /llm/rankand/llm/explainAPI endpoints with schema-validated responses- QLoRA training pipeline for Qwen2.5-Coder-1.5B (
training/qwen15b_lora/) - Adapter v0.1 metadata and packaging under
models/adapters/qwen15b-lora-v0.1 - LLM evaluation harness under
eval/
CMD/ENTRYPOINT optimisation
core/cmd_parser.pyandcore/script_analyzer.pyfor deterministic CMD/ENTRYPOINT analysis- Schema-driven
cmd_rewritescatalog inpatterns/rules.ymlwithRulesCatalogselector - Renderer integration converting shell-form to exec-form with rationale comments
- Full CLI/API/report surfacing of CMD analysis and per-run metadata
Dashboard
codi dashboardcommand aggregating runs to a JSON dataset- Static browser dashboard in
docs/dashboard/with run cards and stack aggregates
Release automation
.github/workflows/release-images.ymlpublishingcodi:slimandcodi:completeto GHCR- cosign keyless signatures + SPDX SBOM attestations
make release-images/make publish-imagesMakefile targets
Data pipeline (for LLM training)
- GitHub Dockerfile collector, quality labelling, standardisation, and synthetic pair generation
- Stratified train/val/test splits under
data/splits/
| Component | Technology | Status |
|---|---|---|
| Language | Python 3.12 | β Production-ready |
| CLI Framework | Typer + Rich | β Operational |
| Renderer | Jinja2 + policy guards | β Operational |
| CMD Rewrite Catalog | YAML schema + RulesCatalog helper + renderer integration | β Operational |
| Build Runner | Dry-run metrics estimator | β Operational |
| Reporter | Markdown + handcrafted HTML | β Operational |
| API Framework | FastAPI + Uvicorn | β Operational |
| Container Packaging | Multi-stage Dockerfiles (Slim & Complete) | β Production-ready |
| Complete Runtime Launcher | Python orchestrator (docker/runtime_complete.py) |
β Operational |
| Container Runtime | Dry-run heuristics (real BuildKit builds planned for v0.2) | β³ In progress |
| Code Quality | Ruff, Black, mypy | β Enforced via Makefile |
| Local LLM Server | Threaded HTTP stub (core/llm.py) |
β Assist-ready |
| RAG Memory | SQLite-based RAGIndex with cosine retrieval |
β Operational |
| LLM Assist Functions | LLMAssist summary + template recommendation |
β Integrated |
| Dashboard Aggregator | core/dashboard.py + static viewer (docs/dashboard/) |
β Operational |
| Air-gap Guard | httpx outbound interceptor + env toggles |
β Enforced |
| Environment Configuration | core/config.py snapshots + environment metadata |
β Operational |
| Testing | pytest (49 tests incl. tests/test_rules.py) |
βΉοΈ Run python3 -m pytest |
Note: Size and layer metrics are heuristic estimates produced by the dry-run build runner β no real Docker builds are executed in the current release. Reported reductions reflect template-level analysis. Real BuildKit integration is planned for v0.2.
π Prefer copy-paste commands? See
docs/quickstart.md.
- Python 3.12+ (for local development)
- Docker (for containerized deployment)
- Make
git clone https://github.com/KiniunCorp/codi.git
cd codi
make setup # create .venv and install all dev dependencies
source .venv/bin/activate # activate the virtual environment
make test # execute pytest suite# Execute deterministic optimisation against a project directory
codi run demo/node
# Generate human-readable report for the latest run folder
LATEST_RUN=$(ls -dt runs/* | head -n 1)
codi report "$LATEST_RUN"
# Reporter writes Markdown and HTML under runs/<id>/reports/βΉοΈ
codi runemits "LLM Assist" and "CMD Summary" panels detailing template recommendations and applied CMD rewrites alongside metrics.
# Run the optimiser on the Node demo and capture the latest run directory
codi run demo/node
LATEST_RUN=$(ls -dt runs/* | head -n 1)
# Inspect promoted builder steps and CMD rewrite rationale comments
grep -n "CMD rewrite" "$LATEST_RUN"/candidates/*.Dockerfile
grep -n "RUN pip wheel" "$LATEST_RUN"/candidates/*.DockerfileRenderer outputs include CMD rewrite rationale comments and builder-stage promotions sourced from
cmd_rewrites.
# Execute the automated smoke suite across Node/Python/Java demos
python3 -m pytest tests/test_smoke.pypython3 -m cli.main perf --out runs/perf --analysis-budget 5 --total-budget 180
cat runs/perf/cpu_perf_report.json | jqDetailed guidance lives in
docs/performance_cpu_sanity.md.
# Aggregate runs into a dashboard-ready dataset
python3 -m cli.main dashboard \
--runs docs/examples/dashboard \
--export-json docs/dashboard/data/sample_runs.json \
--relative-to docs/dashboard
# Serve the static dashboard (opens on http://127.0.0.1:8001)
python3 -m http.server --directory docs/dashboard 8001The dashboard fetches JSON generated by
codi dashboardand renders run cards, stack aggregates, and links to Markdown/HTML reports. Seedocs/dashboard.mdfor full instructions.
python3 - <<'PY'
from core.llm import LocalLLMClient, LocalLLMServer
with LocalLLMServer() as server:
client = LocalLLMClient(server.base_url)
print(client.complete("Summarise CODI smoke test benefits."))
PY# Persist runs somewhere else without passing --out to every CLI command
export CODI_OUTPUT_ROOT="$HOME/codi-runs"
# Allow-lists make it easy to invoke the FastAPI test client while keeping AIRGAP enabled
export AIRGAP_ALLOWLIST="testserver,internal.example.com"
# Disable assist calls (fallback summaries still render) or point to a remote endpoint
export LLM_ENABLED=false
# export LLM_ENDPOINT="http://127.0.0.1:8081"
# Override the default rules file if you want to experiment with custom templates
# export RULES_PATH=/path/to/custom/rules.yml
# Run the suite afterwards to verify everything remains green
python3 -m pytest# Serve the CODI API (defaults: host=127.0.0.1, port=8000)
codi serve --host 0.0.0.0 --port 8000
# Analyze a project via HTTP
curl -X POST "http://localhost:8000/analyze" \
-H 'Content-Type: application/json' \
-d '{"project_path": "demo/node"}' | jq
# Generate a full run over the same project
curl -X POST "http://localhost:8000/run" \
-H 'Content-Type: application/json' \
-d '{"project_path": "demo/node"}' | jq# Build the multi-stage Slim container image
make build-slim
# Or directly with Docker
docker build -f docker/Dockerfile.slim -t codi:slim .# Build the Complete container image with embedded offline LLM runtime
make build-complete
# Or directly with Docker
docker build -f docker/Dockerfile.complete -t codi:complete .# Start the API server with volume mount
make run-slim
# Or directly with Docker
docker run --rm -it -v "$PWD:/work" -p 8000:8000 codi:slim
# Access the API at http://localhost:8000
curl http://localhost:8000/# Start the Complete image with API, embedded LLM, and mounted model weights
docker run --rm -it \
-v "$PWD:/work" \
-v "$HOME/.codi-models:/models" \
-e AIRGAP=true \
-p 8000:8000 -p 8081:8081 \
codi:complete
# Verify both services respond
curl http://localhost:8000/docs
curl http://localhost:8081/healthzβΉοΈ
LLM_ENABLED,AIRGAP, andMODEL_MOUNT_PATHdefault to secure offline values; mount your own weight directory at/models(or setMODEL_MOUNT_PATH) to inject larger models without rebuilding the image. π Need selective outbound access? ProvideAIRGAP_ALLOWLIST=internal.example.com(comma-separated) or disable temporarily withAIRGAP=falsefor controlled testing.
Automated GHCR publishing with provenance:
-
Dry-run builds locally
# Loads release-tagged images into Docker without pushing make release-images RELEASE_VERSION=v1.4.0 IMAGE_NAMESPACE=my-org/codi -
Publish from a workstation (requires
docker login ghcr.io):make publish-images \ RELEASE_VERSION=v1.4.0 \ IMAGE_NAMESPACE=my-org/codi \ REGISTRY=ghcr.io
-
Tag + push (
git tag v1.4.0 && git push origin v1.4.0) to invoke.github/workflows/release-images.yml, which:- Builds
ghcr.io/<namespace>/codi-slimandghcr.io/<namespace>/codi-complete - Publishes
v1.4.0,latest, and digest tags - Generates SPDX SBOMs and uploads them as workflow artifacts
- Signs images + SBOM attestations with cosign keyless (OIDC)
- Builds
-
Verify signatures anywhere
OWNER=my-org REPO=codi IMAGE=ghcr.io/$OWNER/$REPO/codi-slim:v1.4.0 cosign verify \ --certificate-identity "https://github.com/${OWNER}/${REPO}/.github/workflows/release-images.yml@refs/tags/v1.4.0" \ --certificate-oidc-issuer https://token.actions.githubusercontent.com \ "$IMAGE" cosign verify-attestation \ --type spdxjson \ "$IMAGE"
Substitute
OWNER/REPOwith your fork if publishing under a different org.
Refer to docs/runbook.md for the end-to-end release checklist, approval gates, and rollback plan.
# Override the default entrypoint to run CLI commands
docker run --rm -v "$PWD:/work" codi:slim \
codi all /work/demo/node --dry-run
# Or get an interactive shell with all CLI verbs available
make run-slim-cli
# Inside the container you can verify the installation
codi --version
codi report --in /work/runs/<latest>π‘ Swap
codi:slimforcodi:completeto run the same CLI workflows with the embedded LLM assist enabled by default.
# Mount your project directory and analyze
docker run --rm -v "$PWD:/work" codi:slim \
codi all /work/demo/node --dry-run
# Results are written to /work/runs/<timestamp>/
ls -la runs/- CODI-MVP-001 β Initialise repo skeleton & Makefile
- CODI-MVP-002 β Bootstrap CLI (Typer/Rich) with stubs
- CODI-MVP-003 β Implement tolerant Dockerfile parser
- CODI-MVP-004 β Implement stack detector (node/python/java)
- CODI-MVP-005 β Seed
patterns/rules.ymlfor 3 stacks - CODI-MVP-006 β Implement renderer (Jinja2 + policy guards)
- CODI-MVP-007 β Build runner (BuildKit) + metrics capture
- CODI-MVP-008 β Reporter (Markdown + HTML, diffs & rationale)
- CODI-MVP-009 β Store module for runs/ artefacts
- CODI-MVP-010 β Security & policy gates
- CODI-MVP-011 β FastAPI service with 4 endpoints
- CODI-MVP-012 β Slim container packaging
- CODI-MVP-013 β Create minimal sample apps (3 stacks)
- CODI-MVP-014 β End-to-end Slim smoke on 3 stacks
- CODI-MVP-015 β Quickstart docs for Slim
- CODI-MVP-016 β Integrate local LLM server (Ollama/llama.cpp)
- CODI-MVP-017 β RAG store (SQLite/Chroma) + retrieval helper
- CODI-MVP-018 β LLM-assist functions with strict boundaries
- CODI-MVP-019 β Complete container packaging
- CODI-MVP-020 β Airgap + model mount toggles
- CODI-MVP-021 β Env wiring & configuration
- CODI-MVP-022 β CPU-only perf sanity tests
- CODI-MVP-023 β Security & air-gap verification
- CODI-MVP-024 β Models README & runbook
- CODI-MVP-025 β Example runs + dashboard how-to
| Stack | Builder Base | Runtime Base | Status |
|---|---|---|---|
| Node.js / Next.js | node:20-slim |
node:20-alpine |
β Supported |
| Python / FastAPI | python:3.12-slim |
python:3.12-slim |
β Supported |
| Java / Spring Boot | maven:3.9-eclipse-temurin-21 |
eclipse-temurin:21-jre |
β Supported |
Full documentation suite β docs/deliverables/docs/INDEX.md
The index covers installation, CLI usage, API reference, architecture, LLM module, rules guide, operations, security, CI/CD release, performance, and testing β organised by role.
Quick links
| Guide | Description |
|---|---|
| Installation & Setup | Clone, venv, platform notes |
| CLI Guide | All commands, env flags, workflows |
| API Guide | FastAPI endpoints, schemas, examples |
| Architecture | System diagram, module deep-dive |
| Slim Container | Build and run codi:slim |
| Complete Container | Embedded LLM runtime, adapter mounts |
| LLM Module | Data pipeline, training, evaluation |
| Rules Guide | Template authoring, CMD rewrites |
| Operations Runbook | Day-2 health checks, troubleshooting |
| Security | Air-gap controls, container hardening |
| CI/CD & Release | Signing, SBOMs, rollback |
| Performance | Budgets, codi perf, tips |
| Reference | Commands, schemas, glossary, roadmap |
Product spec
- Air-gapped by default β no external calls in the rules-only pipeline
- Template-based rendering guarded by security policies and allowlists
- Reporter embeds policy notes and rationale for every candidate
- Build runner operates in dry-run mode until BuildKit integration lands
- Air-gap guard blocks outbound HTTP(S) when
AIRGAP=true; optionally setAIRGAP_ALLOWLISTfor vetted internal hosts
| Metric | Target | Status |
|---|---|---|
| Median size reduction | β₯40% | Pending BuildKit integration |
| Syntactically valid candidates | 100% | β Enforced via parser + policy checks |
| Report generation | Every run | β Automated |
| Offline operation | 0 outbound calls | β Enforced by air-gap guard |
| Analysis performance | β€3s (no build) | β
CPU dry-run suite via codi perf |
| Full run performance | β€5m per stack | β Dry-run pipeline <0.01s; real builds forthcoming |
Contributions are welcome! Development follows the task plan in docs/codi_mvp_tasks.md.
- Pick a task from the roadmap or open an issue
- Create a feature branch
- Implement with tests (
python3 -m pytest) - Run
make lint+make test - Submit a PR referencing the task ID
MIT License β see LICENSE for details.
- PRD:
docs/codi_mvp_prd.md - Tasks:
docs/codi_mvp_tasks.md - Issues: Track progress and report bugs via repository issues
Project Status: β
MVP Active β rules pipeline, CMD optimisation, local LLM assist, and release automation shipped
Next Milestone: Public launch, real BuildKit build integration, CHANGELOG
Last Updated: 2026-05-04