Skip to main content

A literate programming system for the AI coding era

Project description

Codemixture

A literate programming system for the AI coding era.

Programs are written as markdown documents with executable code in standard fenced code blocks. The prose — design rationale, specifications, constraints, prompts — is interwoven with the code. The documents are simultaneously human-readable documentation, AI-readable context, and executable programs.

The Problem

Code and documentation live in separate worlds. Comments rot. READMEs drift. Design docs go stale the moment code ships. AI coding agents work from context that's scattered across files, commit messages, and Slack threads.

The Idea

What if the documentation was the program? What if the markdown you write to explain your design also contained the code that implements it?

Codemixture documents are valid CommonMark. Code lives in standard fenced code blocks. Metadata lives in invisible HTML comments. Macros are expressed as comments in the target language. Everything renders correctly on GitHub, in VS Code, in any markdown viewer — with zero preprocessing.

Example

Here's a complete codemixture document:

# Hello World

<!-- codemixture
type: module
file: hello.py
language: python
-->

A simple greeting program.

```python
def main():
    print("Hello from codemixture!")

if __name__ == "__main__":
    main()
```

Run cm tangle hello.md and out comes hello.py.

For more complex programs, named sections let you define code in the order that makes sense for explanation, then assemble it in the order the language requires:

```python
# @begin(imports)
import sys
# @end(imports)
```

Later, we can include that section:

```python
# @include(imports)

def main():
    print("hello")
```

Quick Start

# Clone and bootstrap
git clone <repo-url> && cd codemixture
python3 bootstrap.py tangler.md
python3 bootstrap.py cli.md

# Install with uv
uv sync --all-extras

# Tangle, check, test
uv run cm tangle tangler.md cli.md checker.md watcher.md
uv run cm check tangler.md cli.md checker.md watcher.md
uv run pytest tests/ -v

How It Works

Tangling extracts executable code from .md files:

cm tangle mymodule.md              # Single file
cm tangle *.md                     # Project (enables cross-document refs)
cm tangle mymodule.md --dry-run    # Preview without writing

Checking validates documents without tangling:

cm check *.md           # Report errors and warnings
cm check *.md --strict  # Treat warnings as errors

Watching re-tangles on file changes:

cm watch *.md           # Requires: pip install codemixture[watch]

Initializing scaffolds a new project:

cm init myproject --language python

Self-Hosting

Codemixture is written in codemixture. The .md files in this repository are the source of truth:

Document Produces Description
tangler.md tangle.py The tangler — code extraction and macro resolution
cli.md cli.py, __init__.py The cm command-line tool
checker.md check.py Document validator
watcher.md watch.py File watcher with debouncing

bootstrap.py is the only non-.md Python source — a minimal ~90-line tangler that bootstraps the real one.

Format Specification

See codemixture.md for the complete format specification, including:

  • Document anatomy (prose, code, metadata)
  • The macro system (@begin/@end, @include, @append)
  • Cross-document references
  • Multiple output files
  • Metadata fields

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codemixture-0.1.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codemixture-0.1.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file codemixture-0.1.0.tar.gz.

File metadata

  • Download URL: codemixture-0.1.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.19

File hashes

Hashes for codemixture-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cae8db8977847404e444f88ee65a89e72c37a5fb7672bde233dc9465066e6ace
MD5 46cc8926054d1ca4c664fe4a62a20c5a
BLAKE2b-256 f69a6b0667a9f4add6e796a672157eb1c8165258a7be2d6c4f813d5615f7775f

See more details on using hashes here.

File details

Details for the file codemixture-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for codemixture-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2713ed6830cfe20bf3e68f1fc0d42e5cdef5a2284d4dce96f230858e5cc8509f
MD5 63ad02bd984b0bbfc36c817f2c29d65c
BLAKE2b-256 a51c0acb21a38ad1bbe93b37be2910112dd1b5459f3152b97f184cfdb37f1d73

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page