Capsula
[!WARNING] This project is in early development. The CLI interface and configuration format may change in future releases.
A powerful CLI tool for capturing and preserving the context of your command executions. Capsula automatically records the state of your project environment before and after running commands, making your workflows reproducible and auditable.
Features
- 📸 Context Capture: Automatically capture git state, file contents, environment variables, and more
- 🔄 Reproducible Runs: Complete record of execution context for debugging and auditing
- 🛡️ Safety Checks: Prevent execution on dirty repositories or other unsafe conditions
- 📊 Structured Output: JSON-formatted capture data for easy processing
- 🔧 Extensible: Multiple built-in context types with clean error handling
Installation
Install from crates.io
Install from the GitHub repository
Quick Start
- Create a configuration file (
capsula.toml) in your project root:
[]
= "my-project"
[[]]
= "git"
= "repo-name"
= "."
[[]]
= "cwd"
[[]]
= "file"
= "config.json"
= "copy"
= "sha256"
- Run a command with context capture:
- Or capture context only:
Configuration
Basic Structure
The capsula.toml configuration file defines:
- Vault: Where to store captured data
- Phases: When to capture context (before/after command execution)
- Contexts: What information to capture
[]
= "project-name" # Vault identifier
= ".capsula" # Storage path (optional, defaults to .capsula/{name})
[] # Pre-execution contexts
[[]]
= "git"
# ... context configuration
[] # Post-execution contexts
[[]]
= "file"
# ... context configuration
Available Context Types
Git Context
Captures git repository state including commit hash and cleanliness check.
[[]]
= "git"
= "repo-name" # Context name
= "." # Repository path
= false # Allow uncommitted changes (default: false)
Output Example:
Current Working Directory Context
Captures the current working directory path.
[[]]
= "cwd"
Output Example:
File Context
Captures file contents and/or metadata.
[[]]
= "file"
= "config.json" # File pattern to capture
= "copy" # Capture mode ("copy", "move", or "none". default: "copy")
= "sha256" # Calculate file hash ("sha256" or "none". default: "sha256")
Output Example:
Note: Copy and move modes require a run directory and only work during capsula run command, not standalone capsula capture.
Environment Variables Context
Captures specified environment variables.
[[]]
= "env"
= "HOME" # Variable name to capture
Output Example:
Command Context
Captures output of shell commands.
[[]]
= "command"
= ["uname", "-a"]
= false # Abort if command fails (default: false)
Machine Context
Captures system information like CPU, memory, and OS details.
[[]]
= "machine"
CLI Usage
Commands
capsula run <command>
Execute a command with full context capture.
# Run with default config
# Run with custom config
# Run with arguments
Behavior:
- Captures pre-phase contexts and saves to vault
- Checks for abort conditions (e.g., dirty git repo)
- Executes the command if safe, aborts otherwise
- Captures post-phase contexts and saves to vault
capsula capture
Capture context without running a command.
# Capture pre-phase contexts
# Capture post-phase contexts
Options
--config <path>: Specify custom configuration file (default:capsula.toml)--phase <phase>: Specify phase for capture command (preorpost)
Output Structure
Metadata
Every context output includes metadata for traceability:
Vault Structure
Captured data is organized in the vault:
.capsula/
└── vault-name/
└── 2024-01-15/ # Date-based directory (YYYY-MM-DD, UTC)
└── 143022-example-run--01HKJM2K3L4M5N6P7Q8R9S/ # Unique run directory (timestamp + run name + ULID)
├── metadata.json # Run metadata
├── pre.json # Pre-phase contexts
├── run.json # Command output, exit code, duration
└── post.json # Post-phase contexts