Skip to main content

A versioned documentation layer for AI-assisted development

Project description

spec

CI Release codecov PyPI version Python Support License: MIT Code style: ruff Type checked: mypy

A versioned documentation layer for AI-assisted development. spec maintains a separate Git repository of contextual documentation that helps AI agents understand your codebase without polluting your main Git history.

Why spec?

  • AI-Optimized Context: Structured documentation designed for LLM consumption
  • Version-Controlled Memory: AI agents can learn from past attempts and decisions
  • Isolated Git History: Documentation changes don't clutter your main repository
  • Scoped Context Windows: Load only relevant documentation to fit within token limits
  • Rich Terminal UI: Beautiful, colorful interface with progress indicators
  • Modular Architecture: Clean, testable codebase built for extensibility

Installation

pip install spec-cli

Quick Start

# Initialize spec in your project
spec init

# Generate documentation for files
spec gen src/models.py        # Single file
spec gen src/                 # Directory
spec gen .                    # Current directory (all files)

# Track documentation changes
spec add .
spec commit -m "Document authentication flow"

# View documentation status
spec status
spec log
spec diff

Features

โœ… Core Features

  • Project Initialization: spec init creates isolated Git repository structure
  • Documentation Generation: spec gen creates structured documentation with templates
  • Version Control: Full Git workflow (add, commit, status, log, diff)
  • Template System: Customizable documentation templates via .spectemplate
  • File Filtering: Smart filtering with .specignore patterns
  • Rich Terminal UI: Beautiful interface with colors, progress bars, and styling
  • Batch Processing: Generate documentation for entire directories
  • File Type Detection: Support for 20+ programming languages and file types
  • Conflict Resolution: Interactive handling of existing documentation
  • Debug Mode: Comprehensive debugging with SPEC_DEBUG=1
  • Modular Architecture: Clean, maintainable codebase with 80%+ test coverage

๐Ÿ”ฎ Future Features

  • AI Documentation Generation: Replace placeholder content with AI-generated documentation
  • Git Hook Integration: Auto-generate documentation on code changes
  • Enhanced CLI: Advanced options and configuration management

How It Works

spec creates two directories:

  • .spec/ - A bare Git repository (like .git)
  • .specs/ - Working tree containing documentation

Your documentation mirrors your project structure:

project/
โ”œโ”€โ”€ .spec/              # Bare Git repo for versioning
โ”œโ”€โ”€ .specs/             # Documentation working tree
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ””โ”€โ”€ models/
โ”‚   โ”‚       โ”œโ”€โ”€ index.md
โ”‚   โ”‚       โ””โ”€โ”€ history.md
โ”‚   โ””โ”€โ”€ api/
โ”‚       โ””โ”€โ”€ users/
โ”‚           โ”œโ”€โ”€ index.md
โ”‚           โ””โ”€โ”€ history.md
โ”œโ”€โ”€ .spectemplate       # Customizable templates
โ”œโ”€โ”€ .specignore         # Ignore patterns
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ models.py
โ””โ”€โ”€ api/
    โ””โ”€โ”€ users.py

Each source file gets a documentation directory with:

  • index.md: Current understanding and specifications
  • history.md: Evolution, decisions, and lessons learned

Commands

Core Commands

  • spec init - Initialize spec in current directory
  • spec gen <path> - Generate documentation for file(s) or directory
  • spec add <path> - Stage documentation changes
  • spec commit -m "message" - Commit documentation changes

View Documentation

  • spec status - Show documentation status
  • spec log [path] - Show documentation history
  • spec diff [path] - Show uncommitted changes
  • spec show <path> - Display documentation for a file (coming soon)

Future Commands

  • spec regen <path> - Regenerate documentation (preserves history)
  • spec agent-scope [options] - Export scoped context for AI agents

Advanced Usage

Custom Templates

Create a .spectemplate file to customize documentation format:

index:
  template: |
    # {{filename}}

    **Location**: {{filepath}}
    **Purpose**: {{purpose}}
    **Responsibilities**: {{responsibilities}}
    **Requirements**: {{requirements}}
    **Example Usage**: {{example_usage}}
    **Notes**: {{notes}}

history:
  template: |
    ## {{date}} - Initial Creation

    **Purpose**: Created initial specification for {{filename}}
    **Context**: {{context}}
    **Decisions**: {{decisions}}
    **Lessons Learned**: {{lessons}}

Environment Variables

Control spec behavior with environment variables:

  • SPEC_DEBUG=1 - Enable debug output for troubleshooting
  • SPEC_DEBUG_LEVEL=INFO|DEBUG|WARNING|ERROR - Set debug level
  • SPEC_DEBUG_TIMING=1 - Enable operation timing

File Filtering

Use .specignore to exclude files from documentation generation:

# Ignore patterns
*.log
node_modules/
build/
*.min.js

Architecture

spec follows a clean, modular architecture built through a comprehensive refactoring:

Directory Structure

spec_cli/
โ”œโ”€โ”€ cli/                     # Command-line interface layer
โ”œโ”€โ”€ core/                    # Core business logic and workflow orchestration
โ”œโ”€โ”€ git/                     # Git operations abstraction
โ”œโ”€โ”€ templates/               # Template system for documentation generation
โ”œโ”€โ”€ file_system/             # File system operations and path handling
โ”œโ”€โ”€ config/                  # Configuration management
โ”œโ”€โ”€ ui/                      # Rich terminal UI components
โ”œโ”€โ”€ file_processing/         # Batch processing and conflict resolution
โ”œโ”€โ”€ exceptions.py            # Custom exception hierarchy
โ””โ”€โ”€ logging/                 # Debug logging and timing

Key Design Principles

  • Single Responsibility: Each module has a clear, focused purpose
  • Dependency Injection: Services are easily testable and mockable
  • Clean Interfaces: Well-defined boundaries between layers
  • Rich Terminal UI: Beautiful, colorful interface throughout
  • Comprehensive Testing: 80%+ test coverage across all modules

Development Setup

This project uses Poetry for dependency management and uv for virtual environments:

# Create virtual environment with uv
uv venv

# Activate virtual environment
source .venv/bin/activate  # On Unix/macOS
# or
.venv\Scripts\activate  # On Windows

# Install dependencies with poetry
poetry install

# Run tests with coverage (80% minimum required)
poetry run pytest tests/unit/ -v --cov=spec_cli --cov-report=term-missing --cov-fail-under=80

# Run type checking
poetry run mypy spec_cli/

# Run linting and formatting
poetry run ruff check --fix .
poetry run ruff format .

# Run all pre-commit hooks
poetry run pre-commit run --all-files

Use Cases

For AI Development

  • Provide rich context to AI coding assistants
  • Track why certain approaches failed
  • Maintain institutional knowledge across AI sessions
  • Export scoped documentation for specific tasks

For Teams

  • Onboard new developers with comprehensive docs
  • Document architectural decisions and trade-offs
  • Track technical debt and future improvements
  • Maintain living documentation that evolves with code

For Code Review

  • Understand the "why" behind implementations
  • Review documentation changes alongside code
  • Ensure specs stay synchronized with reality
  • Track decision history and lessons learned

IDE Integration

Hide .spec/ and .specs/ directories in your IDE. For VSCode, add to workspace settings:

{
  "files.exclude": {
    ".spec": true,
    ".specs": true
  }
}

Contributing

We follow a vertical slice development philosophy - implementing features completely through implementation, testing, and typing before moving on. See CLAUDE.md for detailed development guidelines.

License

MIT License - see LICENSE for details.

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

spec_ai-0.1.5.tar.gz (133.6 kB view details)

Uploaded Source

Built Distribution

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

spec_ai-0.1.5-py3-none-any.whl (174.4 kB view details)

Uploaded Python 3

File details

Details for the file spec_ai-0.1.5.tar.gz.

File metadata

  • Download URL: spec_ai-0.1.5.tar.gz
  • Upload date:
  • Size: 133.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for spec_ai-0.1.5.tar.gz
Algorithm Hash digest
SHA256 789949d68065c4c2623b85d8a9cace0dc368fe8919e9c7aeee817f869ba318d9
MD5 42b349734aa1c284db9bb7baa265f15e
BLAKE2b-256 43618bdf227bd5a89c91e8ec8f0d73998930a6f70026739b01fab8536dfbc193

See more details on using hashes here.

Provenance

The following attestation bundles were made for spec_ai-0.1.5.tar.gz:

Publisher: release.yml on Spenquatch/spec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spec_ai-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: spec_ai-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 174.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for spec_ai-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 8d167e51e65263aa4c1d19a064c60ba615a36102aff7d477dd25a9e5c317adea
MD5 fb4c4fa6e647a8d974464836c3e67360
BLAKE2b-256 e037422b52671de7c1fc9abce0f69240c2af84711f39ed0f8aa2998e438b56cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for spec_ai-0.1.5-py3-none-any.whl:

Publisher: release.yml on Spenquatch/spec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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