Capsula
[!WARNING] This project is in early development. The CLI interface and configuration format may change in future releases.
A powerful CLI tool for running hooks and capturing their output before and after your command executions. Capsula automatically records the state of your project environment before and after running commands, making your workflows reproducible and auditable.
[!NOTE] The Python version of Capsula is deprecated and can be found at the main branch of this repository.
Features
- 📸 Context Capture: Automatically capture git state, file contents, environment variables, and more
- 🔄 Reproducible Runs: Complete record of execution hook 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 hooks 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"
[[]]
= "capture-git-repo"
= "repo-name"
= "."
[[]]
= "capture-cwd"
[[]]
= "capture-file"
= "config.json"
= "copy"
= "sha256"
- Run a command with hooks:
Configuration
Basic Structure
The capsula.toml configuration file defines:
- Vault: Where to store captured data
- Phases: Pre-run and post-run hooks
[]
= "project-name" # Vault identifier
= ".capsula" # Storage path (optional, defaults to .capsula/{name})
[] # Pre-execution hooks
[[]]
= "capture-git-repo"
# ... hook configuration
[] # Post-execution hooks
[[]]
= "capture-file"
# ... hook configuration
Available Hook Types
Git Hook
Captures git repository state including commit hash and cleanliness check.
[[]]
= "capture-git-repo"
= "repo-name" # Hook name
= "." # Repository path
= false # Allow uncommitted changes (default: false)
Output Example:
Current Working Directory
Captures the current working directory path.
[[]]
= "capture-cwd"
Output Example:
File Hook
Captures file contents and/or metadata.
[[]]
= "capture-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:
Environment Variables Hook
Captures specified environment variables.
[[]]
= "capture-env"
= "HOME" # Variable name to capture
Output Example:
Command Hook
Captures output of shell commands.
[[]]
= "capture-command"
= ["uname", "-a"]
= false # Abort if command fails (default: false)
Output Example:
Machine Hook
Captures system information like CPU, memory, and OS details.
[[]]
= "capture-machine"
Output Example:
CLI Usage
Commands
capsula run <command>
Execute a command with full hook capture.
# Run with default config
# Run with custom config
# Run with arguments
Behavior:
- Runs pre-run hooks and saves their outputs to vault
- Checks for abort conditions (e.g., dirty git repo)
- Executes the command if safe, aborts otherwise
- Runs post-run hooks and saves their outputs to vault
capsula list
List all captured runs in the vault.
# List runs with default config
# List runs with custom config
Example Output:
TIMESTAMP (UTC) NAME COMMAND
---------------------------------------------------------------------------------------------
2025-10-31 09:35:29 kind-year echo hello
2025-10-31 09:35:28 smelly-apparel echo hello
2025-10-31 09:35:26 clear-waste echo hello
2025-10-31 09:30:15 cheap-trip echo this is a very long command with many argu...
The output shows:
- Timestamp: UTC time when the command was executed
- Name: Human-readable generated name for the run
- Command: The command that was executed (truncated if too long)
Output Structure
Metadata
Every hook output includes metadata for traceability:
Vault Structure
Captured data is organized in the vault:
.capsula/
└── vault-name/
└── 2025-10-31/ # Date-based directory (YYYY-MM-DD, UTC)
└── 093525-chubby-back/ # Unique run directory (HHMMSS-run-name)
├── _capsula/ # Capsula metadata directory
│ ├── metadata.json # Run metadata (ID, name, command, timestamp)
│ ├── pre-run.json # Pre-phase hook outputs (array)
│ ├── command.json # Command execution results
│ └── post-run.json # Post-phase hook outputs (array)
└── [captured files] # Files copied by file hooks
metadata.json contains run information:
command.json contains command execution results: