### Execute ExplainCommand
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/commands.md
Example of initializing and executing an explanation command.
```rust
let cmd = ExplainCommand {
git_entity: GitEntity::Commit(commit),
query: None,
};
cmd.execute(&provider).await?;
```
--------------------------------
### Operate Command Examples
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/cli-arguments.md
Examples of using natural language queries to perform git operations.
```bash
# Squash commits
lumen operate "squash the last 3 commits into 1 with the message 'squashed commit'"
# Interactive rebase
lumen operate "rebase my branch onto main interactively"
# Reset changes
lumen operate "undo my last commit but keep the changes"
```
--------------------------------
### Execute Explain Prompt Example
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/ai-prompts.md
Demonstrates building an explanation prompt and completing it via a provider.
```rust
let command = ExplainCommand {
git_entity: GitEntity::Commit(commit),
query: Some("What's the performance impact?".to_string()),
};
let prompt = AIPrompt::build_explain_prompt(&command)?;
let explanation = provider.complete(prompt).await?;
```
--------------------------------
### Initialize and Run Diff UI
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/diff-viewer.md
Example of configuring DiffOptions and invoking the UI runner.
```rust
let options = DiffOptions {
reference: Some(CommitReference::Single("HEAD".to_string())),
theme: Some("dracula".to_string()),
wrap: true,
..Default::new()
};
run_diff_ui(options, &backend)?;
```
--------------------------------
### Execute OperateCommand
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/commands.md
Example of initializing and executing an OperateCommand.
```rust
let cmd = OperateCommand {
query: "squash the last 3 commits into 1 with the message 'squashed commit'".to_string(),
};
cmd.execute(&provider).await?;
```
--------------------------------
### Execute DraftCommand
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/commands.md
Example of initializing and executing a draft command with context.
```rust
let cmd = DraftCommand {
git_entity: GitEntity::Diff(diff),
context: Some("match brand guidelines".to_string()),
draft_config,
};
cmd.execute(&provider).await?;
```
--------------------------------
### Explain Prompt Usage
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/ai-prompts.md
Example of providing specific context to the explain command.
```bash
lumen explain --query "focus on security"
```
--------------------------------
### Install Lumen via Cargo
Source: https://github.com/jnsahaj/lumen/blob/main/README.md
Install the tool using the Rust package manager. Ensure Rust is installed on your system first.
```bash
cargo install lumen
```
--------------------------------
### Execute Draft Prompt Example
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/ai-prompts.md
Demonstrates building a draft prompt and printing the resulting commit message.
```rust
let command = DraftCommand {
git_entity: GitEntity::Diff(diff),
context: Some("match brand guidelines".to_string()),
draft_config: DraftConfig { commit_types: ... },
};
let prompt = AIPrompt::build_draft_prompt(&command)?;
let commit_msg = provider.complete(prompt).await?;
println!("{}", commit_msg);
```
--------------------------------
### Configuration Precedence Example
Source: https://github.com/jnsahaj/lumen/blob/main/README.md
Demonstrates setting global defaults via environment variables and overriding them with configuration files or CLI flags.
```bash
# Set global defaults in .zshrc/.bashrc
export LUMEN_AI_PROVIDER="openai"
export LUMEN_AI_MODEL="gpt-5-mini"
export LUMEN_API_KEY="sk-xxxxxxxxxxxxxxxxxxxxxxxx"
# Override per project using config file
{
"provider": "ollama",
"model": "llama3.2"
}
# Or override using CLI flags
lumen -p "ollama" -m "llama3.2" draft
```
--------------------------------
### Install Lumen via Homebrew
Source: https://github.com/jnsahaj/lumen/blob/main/README.md
Use this command to install the Lumen CLI on MacOS or Linux systems.
```bash
brew install jnsahaj/lumen/lumen
```
--------------------------------
### Draft Prompt Context
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/ai-prompts.md
Example of using the context flag to guide commit message generation.
```bash
--context "breaking change"
```
--------------------------------
### Full Configuration with Claude
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/configuration.md
An extensive configuration example including model selection, API keys, UI themes, and custom commit types.
```json
{
"provider": "claude",
"model": "claude-opus-4-5-20251115",
"api_key": "sk-ant-...",
"theme": "catppuccin-mocha",
"wrap": true,
"draft": {
"commit_types": {
"feat": "A new feature",
"fix": "A bug fix",
"docs": "Documentation changes",
"style": "Code style changes",
"refactor": "Code refactoring",
"perf": "Performance improvements",
"test": "Test changes",
"build": "Build system changes",
"ci": "CI/CD changes",
"chore": "Chore"
}
}
}
```
--------------------------------
### Lumen Configuration File
Source: https://github.com/jnsahaj/lumen/blob/main/README.md
Example JSON configuration file for setting providers, models, and commit types.
```json
{
"provider": "openai",
"model": "gpt-5-mini",
"api_key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"theme": "catppuccin-mocha",
"wrap": true,
"draft": {
"commit_types": {
"docs": "Documentation only changes",
"style": "Changes that do not affect the meaning of the code",
"refactor": "A code change that neither fixes a bug nor adds a feature",
"perf": "A code change that improves performance",
"test": "Adding missing tests or correcting existing tests",
"build": "Changes that affect the build system or external dependencies",
"ci": "Changes to our CI configuration files and scripts",
"chore": "Other changes that don't modify src or test files",
"revert": "Reverts a previous commit",
"feat": "A new feature",
"fix": "A bug fix"
}
}
}
```
--------------------------------
### Diff Command Usage
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/cli-arguments.md
Examples for launching the interactive side-by-side diff viewer with various filters and modes.
```bash
# View uncommitted changes
lumen diff
# View specific commit
lumen diff HEAD~1
# View commit range
lumen diff main..feature
# View PR by number
lumen diff --pr 123
# View PR by URL
lumen diff https://github.com/owner/repo/pull/123
# Auto-detect and view PR
lumen diff --detect-pr
# Filter to specific files
lumen diff --file src/main.rs --file src/lib.rs
# Watch mode
lumen diff --watch
# Stacked mode
lumen diff main..feature --stacked
# Focus on file and wrap
lumen diff --focus src/main.rs --wrap --theme dracula
```
--------------------------------
### XML Response Example
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/ai-prompts.md
The expected XML output format from the AI provider.
```xml
git reset --soft HEAD~3 && git commit -m "squashed commit"
This will undo the last 3 commits but keep changes staged
This cannot be undone without reflog access
```
--------------------------------
### Handle AIPromptError
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/ai-prompts.md
Example of matching on prompt building errors.
```rust
match AIPrompt::build_draft_prompt(&command) {
Err(AIPromptError(msg)) => eprintln!("Error: {}", msg),
Ok(prompt) => { /* proceed */ }
}
```
--------------------------------
### Explain Command Usage Examples
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/cli-arguments.md
Common usage patterns for the explain command, including range selection, staged changes, and interactive mode.
```bash
# Explain current working tree changes
lumen explain
# Explain staged changes only
lumen explain --staged
# Explain a specific commit
lumen explain HEAD~2
# Explain a range of commits
lumen explain main..feature
# Ask a specific question about changes
lumen explain HEAD --query "What's the performance impact?"
# Interactive commit selection
lumen explain --list
```
--------------------------------
### Draft Command Usage
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/cli-arguments.md
Examples for generating commit messages using the draft command.
```bash
# Generate commit message
lumen draft
# Add context for more meaningful message
lumen draft --context "match brand guidelines"
# Pipe to clipboard
lumen draft | pbcopy
# Direct commit
lumen draft | git commit -F -
```
--------------------------------
### Select commit SHA via fzf
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/commands.md
Interactively retrieves a commit SHA; requires fzf to be installed in the system PATH.
```rust
let sha = LumenCommand::get_sha_from_fzf(backend.as_ref())?;
```
--------------------------------
### Get VCS backend name
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/vcs-backend.md
Retrieve the name of the active VCS backend, which will be either "git" or "jj".
```rust
println!("Using {}", backend.name());
```
--------------------------------
### Execute ConfigureCommand
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/commands.md
Launches the interactive configuration wizard via the command line.
```bash
lumen configure
```
--------------------------------
### get_current_branch()
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/vcs-backend.md
Gets the current branch or bookmark name.
```APIDOC
## get_current_branch()
### Description
Gets current branch/bookmark name. Returns None if detached or not on a bookmark.
```
--------------------------------
### Build Explain Prompt Method
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/ai-prompts.md
Constructs an explanation prompt based on a GitEntity and optional query.
```rust
impl AIPrompt {
pub fn build_explain_prompt(command: &ExplainCommand) -> Result
}
```
--------------------------------
### get_working_tree_diff(staged: bool)
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/vcs-backend.md
Gets the diff of uncommitted changes.
```APIDOC
## get_working_tree_diff(staged: bool)
### Description
Gets diff of uncommitted changes. For git, if staged is true, shows only staged changes; if false, shows all changes. Ignored for jj.
```
--------------------------------
### get_commit_log_for_fzf()
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/vcs-backend.md
Gets a formatted commit log for interactive fzf selection.
```APIDOC
## get_commit_log_for_fzf()
### Description
Gets ANSI-colored formatted log, one commit per line, suitable for piping to fzf.
```
--------------------------------
### Operate Prompt Usage
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/ai-prompts.md
Demonstrates building and executing an operate prompt.
```rust
let query = "squash the last 3 commits into 1 with message 'squashed'";
let prompt = AIPrompt::build_operate_prompt(query)?;
let response = provider.complete(prompt).await?;
let result = extract_operate_response(&response)?;
println!("{}", result.explanation);
```
--------------------------------
### Configure Lumen via Environment Variables and CLI
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/configuration.md
Demonstrates setting global defaults using environment variables and overriding them with project-specific configuration files and CLI flags.
```bash
# Set global defaults in shell config (.zshrc/.bashrc)
export LUMEN_AI_PROVIDER="openai"
export LUMEN_AI_MODEL="gpt-5-mini"
export LUMEN_API_KEY="sk-..."
# Override with project config (lumen.config.json)
# {
# "provider": "claude",
# "model": "claude-sonnet-4-5-20250930"
# }
# Override everything with CLI flags
lumen -p ollama -m llama3.2 draft
```
--------------------------------
### get_range_diff(from: &str, to: &str, three_dot: bool)
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/vcs-backend.md
Gets the diff between two references.
```APIDOC
## get_range_diff(from: &str, to: &str, three_dot: bool)
### Description
Gets diff between two references. If three_dot is true, uses symmetric difference (A...B); if false, uses two-dot (A..B).
```
--------------------------------
### Minimal Configuration
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/configuration.md
A basic configuration file specifying only the provider.
```json
{
"provider": "openai"
}
```
--------------------------------
### Initialize LumenCommand
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/commands.md
Creates a new instance using a configured provider.
```rust
let provider = LumenProvider::new(provider_type, api_key, model)?;
let command = LumenCommand::new(provider);
```
--------------------------------
### Load Configuration from File
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/configuration.md
Loads and parses configuration from a specified JSON file path.
```rust
let config = LumenConfig::from_file("./lumen.config.json")?;
```
--------------------------------
### Build Operate Prompt Method
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/ai-prompts.md
Defines the signature for creating an operate prompt from a natural language query.
```rust
impl AIPrompt {
pub fn build_operate_prompt(query: &str) -> Result
}
```
--------------------------------
### Load Configuration Programmatically in Rust
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/configuration.md
Demonstrates three methods for initializing LumenConfig and accessing configuration fields. Ensure the necessary modules are imported from lumen::config.
```rust
use lumen::config::LumenConfig;
use lumen::config::cli::Cli;
// Method 1: Build from CLI arguments (applies precedence)
let cli = Cli::parse();
let config = LumenConfig::build(&cli)?;
// Method 2: Load from file directly
let config = LumenConfig::from_file("lumen.config.json")?;
// Method 3: Use defaults
let config = LumenConfig::default();
// Access configuration
println!("Provider: {}", config.provider);
println!("Model: {:?}", config.model);
println!("API Key: {:?}", config.api_key);
println!("Theme: {:?}", config.theme);
println!("Wrap: {:?}", config.wrap);
```
--------------------------------
### Propagate errors using LumenError
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/README.md
Example of propagating errors through operations, relying on automatic conversion to the LumenError type.
```rust
fn operation() -> Result {
let config = LumenConfig::build(&cli)?; // VcsError or other errors convert to LumenError
let diff = backend.get_working_tree_diff(true)?; // VcsError -> LumenError
Ok(result)
}
```
--------------------------------
### Configure AI Providers
Source: https://github.com/jnsahaj/lumen/blob/main/README.md
Set up AI providers using CLI flags or environment variables.
```bash
# Using CLI arguments
lumen -p openai -k "your-api-key" -m "gpt-5-mini" draft
# Using environment variables
export LUMEN_AI_PROVIDER="openai"
export LUMEN_API_KEY="your-api-key"
export LUMEN_AI_MODEL="gpt-5-mini"
```
--------------------------------
### Get current branch in Rust
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/vcs-backend.md
Retrieves the current branch or bookmark name, returning None if detached or not on a bookmark.
```rust
if let Some(branch) = backend.get_current_branch()? {
println!("On branch: {}", branch);
}
```
--------------------------------
### Get range diff in Rust
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/vcs-backend.md
Calculates the difference between two references using either two-dot or three-dot syntax.
```rust
let diff = backend.get_range_diff("main", "feature", false)?;
```
--------------------------------
### Workflow Tips and Tricks
Source: https://github.com/jnsahaj/lumen/blob/main/README.md
Integrate generated messages with system clipboards or direct git commits.
```bash
# Copy commit message to clipboard (macOS / Linux)
lumen draft | pbcopy
lumen draft | xclip -selection c
# Directly commit using the generated message
lumen draft | git commit -F -
```
--------------------------------
### Get commit log for fzf in Rust
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/vcs-backend.md
Retrieves an ANSI-colored commit log formatted for interactive selection tools like fzf.
```rust
let log = backend.get_commit_log_for_fzf()?;
// Pipe to fzf
```
--------------------------------
### Interact with VcsBackend
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/vcs-backend.md
Shows how to auto-detect or explicitly specify a backend and perform common operations like fetching commits and diffs.
```rust
use lumen::vcs::{get_backend, VcsBackendType};
use std::env;
use std::path::Path;
// Auto-detect backend
let cwd = env::current_dir()?;
let backend = get_backend(&cwd, None)?;
// Or specify backend explicitly
let backend = get_backend(&cwd, Some(VcsBackendType::Git))?;
// Use backend
let commit = backend.get_commit("HEAD")?;
let diff = backend.get_working_tree_diff(true)?;
let files = backend.get_changed_files("HEAD")?;
println!("Backend: {}", backend.name());
```
--------------------------------
### Get working tree diff in Rust
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/vcs-backend.md
Retrieves a unified diff of uncommitted changes, with optional filtering for staged changes in Git.
```rust
let diff = backend.get_working_tree_diff(true)?; // staged only
```
--------------------------------
### Configure Diff Viewer Themes
Source: https://github.com/jnsahaj/lumen/blob/main/README.md
Set the visual theme using CLI flags, environment variables, or the configuration file.
```bash
# Using CLI flag
lumen diff --theme dracula
# Using environment variable
LUMEN_THEME=catppuccin-mocha lumen diff
# Or set permanently in config file (~/.config/lumen/lumen.config.json)
{
"theme": "dracula"
}
```
--------------------------------
### build_explain_prompt
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/core-types.md
Constructs an AIPrompt instance designed for explaining code changes or answering questions about diffs and commits.
```APIDOC
## build_explain_prompt
### Description
Builds prompts for explaining changes or answering questions about diffs/commits. The output includes system instructions to summarize changes concisely and a user prompt containing formatted context such as commit info or diffs.
### Signature
`build_explain_prompt(command: &ExplainCommand) -> Result`
### Parameters
- **command** (&ExplainCommand) - Required - The command containing the context for the explanation.
```
--------------------------------
### Get parent reference or empty tree
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/vcs-backend.md
Resolve the parent reference for a given commit, returning an empty tree SHA for root commits.
```rust
let parent = backend.get_parent_ref_or_empty("HEAD")?;
```
--------------------------------
### Configure Diff Viewer Settings
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/diff-viewer.md
Define the default theme and line wrapping behavior in the configuration file.
```json
{
"theme": "catppuccin-mocha",
"wrap": true
}
```
--------------------------------
### lumen configure
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/cli-arguments.md
Launches an interactive prompt to configure AI provider settings, API keys, and models.
```APIDOC
## lumen configure
### Description
Launches an interactive prompt to configure AI provider settings. Settings are saved to `~/.config/lumen/lumen.config.json`.
### Signature
`lumen configure`
### Examples
```bash
lumen configure
```
```
--------------------------------
### GitEntity Prompt Composition
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/ai-prompts.md
Demonstrates how prompts are constructed based on the type of GitEntity being processed.
```rust
match &command.git_entity {
GitEntity::Commit(commit) => {
// Include: commit message + full diff
}
GitEntity::Diff(Diff::WorkingTree { diff, .. }) => {
// Include: diff content only
}
GitEntity::Diff(Diff::CommitsRange { diff, from, to }) => {
// Include: range info (from..to) + diff
}
}
```
--------------------------------
### LumenConfig::from_file
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/configuration.md
Loads the configuration directly from a specified JSON file path.
```APIDOC
## LumenConfig::from_file(file_path: &str) -> Result
### Description
Loads configuration from a JSON file.
### Parameters
- **file_path** (&str) - Required - Path to JSON configuration file
### Returns
- **Result** - Parsed configuration or error
### Errors
- **InvalidConfiguration** - JSON parsing failed or invalid structure
### Example
```rust
let config = LumenConfig::from_file("./lumen.config.json")?;
```
```
--------------------------------
### Define Theme and SyntaxColors structs
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/types.md
Structures for defining UI color themes and syntax highlighting rules.
```rust
pub struct Theme {
pub mode: ThemeMode,
pub syntax: SyntaxColors,
pub diff: DiffColors,
pub ui: UiColors,
}
```
```rust
pub struct SyntaxColors {
pub comment: Color,
pub keyword: Color,
pub string: Color,
pub number: Color,
pub function: Color,
pub function_macro: Color,
pub r#type: Color,
pub variable_builtin: Color,
pub variable_member: Color,
pub module: Color,
pub operator: Color,
pub tag: Color,
pub attribute: Color,
pub label: Color,
pub punctuation: Color,
pub default_text: Color,
}
```
--------------------------------
### Build Configuration from CLI
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/configuration.md
Merges CLI arguments with configuration files and environment variables.
```rust
let cli = Cli::parse();
let config = LumenConfig::build(&cli)?;
```
--------------------------------
### Explain Command Signature
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/cli-arguments.md
The basic syntax for invoking the explain command with optional references and flags.
```bash
lumen explain [reference] [--staged] [--query ] [--list]
```
--------------------------------
### Define Configuration structs
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/types.md
Structures for managing application-wide configuration and draft-specific settings.
```rust
pub struct LumenConfig {
pub provider: ProviderType,
pub model: Option,
pub api_key: Option,
pub draft: DraftConfig,
pub theme: Option,
pub wrap: Option,
}
```
```rust
pub struct DraftConfig {
pub commit_types: String, // JSON string
}
```
--------------------------------
### ConfigureCommand Structure
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/commands.md
Defines the structure for the interactive configuration command.
```rust
pub struct ConfigureCommand;
```
--------------------------------
### LumenCommand::new
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/commands.md
Creates a new command executor instance initialized with a LumenProvider.
```APIDOC
## LumenCommand::new(provider: LumenProvider) -> Self
### Description
Creates a new command executor with an AI provider.
### Parameters
- **provider** (LumenProvider) - Required - Configured LumenProvider instance
### Returns
- LumenCommand instance
### Example
```rust
let provider = LumenProvider::new(provider_type, api_key, model)?;
let command = LumenCommand::new(provider);
```
```
--------------------------------
### Configure Vercel Provider
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/providers.md
Sets the Vercel API key and executes the draft command.
```bash
# Configure Vercel gateway
export VERCEL_API_KEY="..."
lumen -p vercel draft
```
--------------------------------
### Configure OpenRouter Provider
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/providers.md
Sets the API key and model via environment variables or a configuration file.
```bash
# Set API key
export OPENROUTER_API_KEY="sk-or-..."
# Use specific model
lumen -p openrouter -m "openai/gpt-4" draft
# Or use default model in config
cat > lumen.config.json < Result
### Description
Builds configuration by merging CLI arguments with config file and environment variables.
### Parameters
- **cli** (&Cli) - Required - Parsed CLI arguments
### Returns
- **Result** - Merged configuration or error
### Example
```rust
let cli = Cli::parse();
let config = LumenConfig::build(&cli)?;
```
```
--------------------------------
### Global CLI Arguments
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/cli-arguments.md
Configuration arguments available for all Lumen commands.
```APIDOC
## Global Arguments
### Description
These arguments can be used with any Lumen command to configure the environment, provider, and model settings.
### Parameters
- **--config** (string) - Optional - Path to configuration file (e.g., `./lumen.config.json`)
- **-p, --provider** (enum) - Optional - AI provider: `openai`, `groq`, `claude`, `ollama`, `opencode-zen`, `openrouter`, `deepseek`, `gemini`, `xai`, `vercel`
- **-k, --api-key** (string) - Optional - API key for the selected provider
- **-m, --model** (string) - Optional - Model identifier
- **--vcs** (enum) - Optional - Version control system: `git` or `jj`
```
--------------------------------
### Build Draft Prompt Method
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/ai-prompts.md
Constructs a commit message generation prompt based on a working tree diff.
```rust
impl AIPrompt {
pub fn build_draft_prompt(command: &DraftCommand) -> Result
}
```
--------------------------------
### lumen operate
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/cli-arguments.md
Generates and executes git commands based on a natural language description provided as an argument.
```APIDOC
## lumen operate
### Description
Generates and executes natural language git commands.
### Signature
`lumen operate `
### Arguments
- **query** (string) - Required - Natural language description of git operation
### Examples
```bash
lumen operate "squash the last 3 commits into 1 with the message 'squashed commit'"
lumen operate "rebase my branch onto main interactively"
lumen operate "undo my last commit but keep the changes"
```
```
--------------------------------
### Run Diff Viewer Modes
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/diff-viewer.md
Commands to launch the diff viewer in various operational modes.
```bash
lumen diff
lumen diff HEAD~3
lumen diff main..feature
```
```bash
lumen diff --watch
```
```bash
lumen diff main..feature --stacked
```
```bash
lumen diff --pr 123
lumen diff https://github.com/owner/repo/pull/456
lumen diff --detect-pr
```
--------------------------------
### Build the Lumen project
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/README.md
Commands for compiling the project in debug or release modes, with optional feature flags for VCS support.
```bash
# Debug build
cargo build
# Release build (optimized, LTO)
cargo build --release
# With jj support (default)
cargo build --features jj
# Without jj support
cargo build --no-default-features
```
--------------------------------
### ExplainCommand Structure
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/commands.md
Defines the structure for explaining git commits or diffs.
```rust
pub struct ExplainCommand {
pub git_entity: GitEntity,
pub query: Option,
}
```
--------------------------------
### LumenProvider::operate
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/providers.md
Generates a git command from a natural language query.
```APIDOC
## LumenProvider::operate(command)
### Description
Translates a natural language query into a git command. Returns an XML response containing the command, explanation, and optional warning.
### Parameters
- **command** (&OperateCommand) - Required - The natural language query.
### Returns
- **Result** - An XML string containing the command, explanation, and warning.
```
--------------------------------
### Explain changes with AI
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/providers.md
Generates an explanation for a git entity or query using the provider.
```rust
let explanation = provider.explain(&explain_cmd).await?;
println!("{}", explanation);
```
--------------------------------
### Define the Diff UI Entry Point
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/diff-viewer.md
The primary function to initialize the terminal UI for diff viewing.
```rust
pub fn run_diff_ui(
options: DiffOptions,
backend: &dyn VcsBackend,
) -> Result<(), LumenError>
```
--------------------------------
### Implement Custom VcsBackend
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/vcs-backend.md
Outlines the structure for implementing a new VCS backend by satisfying the VcsBackend trait.
```rust
pub struct MyVcsBackend;
impl VcsBackend for MyVcsBackend {
fn get_commit(&self, reference: &str) -> Result {
// Implementation
}
// ... implement all other methods
}
```
--------------------------------
### LumenProvider::explain
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/providers.md
Generates an explanation of changes or answers questions about a diff or commit.
```APIDOC
## LumenProvider::explain(command)
### Description
Generates a text explanation for a given git entity or query using the configured AI backend.
### Parameters
- **command** (&ExplainCommand) - Required - Contains the git entity and optional query.
### Returns
- **Result** - The generated explanation text.
```
--------------------------------
### LumenProvider::new
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/providers.md
Creates a new AI provider instance with configuration for specific provider types, API keys, and models.
```APIDOC
## LumenProvider::new(provider_type, api_key, model)
### Description
Creates a new AI provider instance. It configures the backend based on the provider type and handles optional API key and model overrides.
### Parameters
- **provider_type** (ProviderType) - Required - Type of AI provider (OpenAI, Claude, Groq, etc.)
- **api_key** (Option) - Optional - API key to override environment variables
- **model** (Option) - Optional - Model name to override provider default
### Returns
- **Result** - Returns the initialized provider or a LumenError if initialization fails.
```
--------------------------------
### AIPrompt::build_operate_prompt
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/ai-prompts.md
Constructs an AI prompt for git operations based on a natural language query.
```APIDOC
## AIPrompt::build_operate_prompt
### Description
Generates a git command prompt based on a natural language description of a git operation. The resulting prompt instructs the AI to respond in a specific XML format containing the command, explanation, and optional warnings.
### Method
`pub fn build_operate_prompt(query: &str) -> Result`
### Parameters
- **query** (str) - Required - Natural language description of the desired git operation.
### Returns
- **Result** - Returns an AIPrompt instance on success or an AIPromptError if validation fails.
```
--------------------------------
### Format GitEntity Details
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/core-types.md
Formats entity metadata as markdown for display using the provided AI provider.
```rust
let entity = GitEntity::Commit(commit);
let formatted = entity.format_static_details(&provider);
println!("{}", formatted);
```
--------------------------------
### Build a custom prompt variant in Rust
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/ai-prompts.md
Implement this function in src/ai_prompt.rs to define custom system and user prompt strings.
```rust
pub fn build_custom_prompt(&self) -> Result {
let system_prompt = "Your system instructions...".to_string();
let user_prompt = "Your user prompt...".to_string();
Ok(AIPrompt { system_prompt, user_prompt })
}
```
--------------------------------
### Define Command and Provider dispatchers
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/types.md
Structures for command execution routing and AI provider abstraction.
```rust
pub struct LumenCommand {
provider: LumenProvider,
}
```
```rust
pub struct LumenProvider {
backend: ProviderBackend,
provider_name: String,
}
```
--------------------------------
### View Diffs with Lumen
Source: https://github.com/jnsahaj/lumen/blob/main/README.md
Various commands to launch the interactive side-by-side diff viewer for different git contexts.
```bash
# View uncommitted changes
lumen diff
# View changes for a specific commit
lumen diff HEAD~1
# View changes between branches
lumen diff main..feature/A
# View changes in a GitHub Pull Request
lumen diff --pr 123 # (--pr is optional)
lumen diff https://github.com/owner/repo/pull/123
# Open the PR associated with the current branch
lumen diff --detect-pr
# Filter to specific files
lumen diff --file src/main.rs --file src/lib.rs
# Watch mode - auto-refresh on file changes
lumen diff --watch
# Stacked mode - review commits one by one
lumen diff main..feature --stacked
# Jump to a specific file on open
lumen diff --focus src/main.rs
# Soft-wrap long lines (also settable in lumen.config.json)
lumen diff --wrap
```
--------------------------------
### View Project Source Structure
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/00-START-HERE.md
Displays the directory layout of the Lumen source code, highlighting key modules like commands, configuration, and AI providers.
```text
src/
├── main.rs # Entry point
├── command/ # Commands (explain, draft, etc.)
├── config/ # CLI and configuration
├── provider/ # AI provider abstraction
├── vcs/ # Git/jj abstraction
├── git_entity/ # Commit/diff types
├── ai_prompt.rs # Prompt building
├── commit_reference.rs # Reference parsing
└── error.rs # Error types
```
--------------------------------
### Explain Changes
Source: https://github.com/jnsahaj/lumen/blob/main/README.md
Analyze working directory, staged changes, or specific commit ranges for insights.
```bash
# Working directory or staged changes
lumen explain
lumen explain --staged
# Specific commits or ranges
lumen explain HEAD
lumen explain HEAD~3..HEAD
lumen explain main..feature/A
# Ask specific questions
lumen explain --query "What's the performance impact of these changes?"
# Interactive commit selection (requires: fzf)
lumen explain --list
```
--------------------------------
### lumen explain
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/cli-arguments.md
Generate summaries or answers about code changes.
```APIDOC
## lumen explain
### Description
Generates summaries or answers specific questions about code changes based on commit references.
### Signature
`lumen explain [reference] [--staged] [--query ] [--list]`
### Arguments
- **reference** (CommitReference) - Optional - Commit reference (SHA, HEAD, ranges)
- **--staged** (flag) - Optional - Use staged diff only
- **-q, --query** (string) - Optional - Ask a specific question
- **--list** (flag) - Optional - Select commit interactively using fzf
```
--------------------------------
### Define Commands CLI Enum
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/types.md
CLI subcommands.
```rust
pub enum Commands {
Explain { reference, staged, query, list },
List,
Draft { context },
Operate { query },
Diff { reference, pr, detect_pr, file, watch, theme, stacked, focus, origin, wrap },
Configure,
}
```
--------------------------------
### name()
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/vcs-backend.md
Returns the name of the current VCS backend.
```APIDOC
## name() -> &'static str
### Description
Gets VCS backend name.
### Returns
- **&'static str** - "git" or "jj"
### Example
```rust
println!("Using {}", backend.name());
```
```
--------------------------------
### Generate git command
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/providers.md
Translates a natural language query into a structured git command response.
```rust
let response = provider.operate(&operate_cmd).await?;
// Parse with extract_operate_response()
```
--------------------------------
### LumenCommand::print_with_mdcat
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/commands.md
Prints content with markdown formatting using mdcat if available.
```APIDOC
## LumenCommand::print_with_mdcat(content: String) -> Result<(), LumenError>
### Description
Prints content with optional markdown formatting using mdcat. Falls back to plain print if mdcat is not installed.
### Parameters
- **content** (String) - Required - Text to print
### Returns
- Result<(), LumenError>
### Example
```rust
LumenCommand::print_with_mdcat("# Changes\nAdded feature X".to_string())?;
```
```
--------------------------------
### Configure LumenProvider
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/README.md
Initialization of the LumenProvider with a specific provider type, API key, and model identifier.
```rust
let provider = LumenProvider::new(
ProviderType::Claude,
Some("api_key".to_string()),
Some("claude-opus-4-5-20251115".to_string())
)?;
```
--------------------------------
### System Prompt Definition
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/ai-prompts.md
The system instruction set for the git assistant.
```text
You are a helpful git assistant. Generate git commands based on natural language requests.
Respond in XML format with , , and optional tags.
```
--------------------------------
### Construct Commit from Info
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/core-types.md
Constructs a Commit instance from raw commit information retrieved from the VCS backend.
```rust
let commit_info = backend.get_commit("HEAD")?;
let commit = Commit::from_commit_info(commit_info);
```
--------------------------------
### Local Ollama Configuration
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/configuration.md
Configuration for running with a local Ollama instance.
```json
{
"provider": "ollama",
"model": "llama3.2"
}
```
--------------------------------
### Define DiffOptions and PrInfo structs
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/types.md
Structures for configuring the diff viewer and handling GitHub pull request metadata.
```rust
pub struct DiffOptions {
pub reference: Option,
pub pr: Option,
pub detect_pr: bool,
pub file: Option>,
pub watch: bool,
pub theme: Option,
pub stacked: bool,
pub focus: Option,
pub origin: Option,
pub wrap: bool,
}
```
```rust
pub struct PrInfo {
pub number: u64,
pub node_id: String,
pub repo_owner: String,
pub repo_name: String,
pub base_ref: String,
pub head_ref: String,
pub base_repo_owner: String,
pub head_repo_owner: Option,
}
```
--------------------------------
### Generate Git Commands
Source: https://github.com/jnsahaj/lumen/blob/main/README.md
Convert natural language queries into executable git commands with safety prompts.
```bash
lumen operate "squash the last 3 commits into 1 with the message 'squashed commit'"
# Output: git reset --soft HEAD~3 && git commit -m "squashed commit" [y/N]
```
--------------------------------
### Agent Integration Workflow
Source: https://github.com/jnsahaj/lumen/blob/main/README.md
The standard flow for using Lumen as a review surface for coding agents.
```text
agent finishes turn → !lumen diff → annotate → press `s`
→ stdout returns to the agent → agent fixes your notes
```
--------------------------------
### Define AIPrompt struct
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/types.md
Structure for defining structured AI system and user prompts.
```rust
pub struct AIPrompt {
pub system_prompt: String,
pub user_prompt: String,
}
```
--------------------------------
### Define Cli struct
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/types.md
Structure for parsing and storing command-line arguments.
```rust
pub struct Cli {
pub config: Option,
pub provider: Option,
pub api_key: Option,
pub model: Option,
pub vcs: Option,
pub command: Commands,
}
```
--------------------------------
### Prompt Context Modification
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/ai-prompts.md
Shows how the provided context is formatted before being sent to the AI.
```text
Use the following context to understand intent:
match brand guidelines
```
--------------------------------
### DraftCommand Usage Patterns
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/commands.md
Common CLI usage patterns for the draft command.
```bash
# Output to terminal
lumen draft
# Pipe to clipboard
lumen draft | pbcopy
# Direct commit
lumen draft | git commit -F -
```
--------------------------------
### Handling Configuration Errors
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/error-handling.md
Matches different configuration error variants to provide specific troubleshooting instructions.
```rust
match LumenConfig::build(&cli) {
Err(LumenError::InvalidConfiguration(msg)) => {
eprintln!("Invalid configuration: {}", msg);
eprintln!("Check ~/.config/lumen/lumen.config.json");
}
Err(LumenError::ConfigurationError(msg)) => {
eprintln!("Configuration error: {}", msg);
}
_ => {}
}
```
--------------------------------
### build_draft_prompt
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/core-types.md
Constructs an AIPrompt instance designed for generating commit messages based on provided diffs.
```APIDOC
## build_draft_prompt
### Description
Builds prompts for generating commit messages. The output includes system instructions for commit format and style, and a user prompt containing commit types reference, context, and diff.
### Signature
`build_draft_prompt(command: &DraftCommand) -> Result`
### Parameters
- **command** (&DraftCommand) - Required - The command containing the context for the commit draft.
### Errors
- Returns an error if the GitEntity is not a WorkingTree diff.
```
--------------------------------
### Inject Context via CLI
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/ai-prompts.md
Provides additional context to the AI to improve commit message relevance.
```bash
lumen draft --context "match brand guidelines"
```
--------------------------------
### Retrieve file content at reference in Rust
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/vcs-backend.md
Fetches the content of a specific file at a given revision.
```rust
let content = backend.get_file_content_at_ref("HEAD", Path::new("src/main.rs"))?;
```
--------------------------------
### Review Stacked Diffs
Source: https://github.com/jnsahaj/lumen/blob/main/README.md
Navigate through a range of commits individually using the stacked mode.
```bash
lumen diff main..feature --stacked
lumen diff HEAD~5..HEAD --stacked
```
--------------------------------
### Lumen Configuration File Schema
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/configuration.md
The structure of the lumen.config.json file, defining provider, model, and UI preferences.
```json
{
"provider": "openai",
"model": "gpt-5-mini",
"api_key": "sk-...",
"theme": "dracula",
"wrap": true,
"draft": {
"commit_types": {
"feat": "A new feature",
"fix": "A bug fix",
...
}
}
}
```
--------------------------------
### lumen diff
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/cli-arguments.md
Launches an interactive side-by-side diff viewer.
```APIDOC
## lumen diff
### Description
Launch interactive side-by-side diff viewer.
### Signature
`lumen diff [reference] [--pr ] [--detect-pr] [--file ...] [--watch] [--theme ] [--stacked] [--focus ] [--origin ] [--wrap]`
### Arguments
- **reference** (CommitReference) - Optional - Commit reference: SHA, HEAD, `HEAD~3..HEAD`, `main..feature`, `main...feature` or PR number/URL
- **--pr** (string) - Optional - View a GitHub pull request (number or full URL)
- **--detect-pr** (flag) - Optional - Detect and view PR associated with current branch
- **--file** (string) - Optional - Filter to specific files (can specify multiple times)
- **--watch** (flag) - Optional - Watch for file changes and auto-reload
- **--theme** (string) - Optional - Color theme: `dark`, `light`, `dracula`, `nord`, `catppuccin-mocha`, `catppuccin-latte`, `gruvbox-dark`, `gruvbox-light`, `one-dark`, `solarized-dark`, `solarized-light`
- **--stacked** (flag) - Optional - Review commits one at a time with commit-by-commit navigation
- **--focus** (string) - Optional - Initially focus on this file path
- **--origin** (string) - Optional - Origin repository in `owner/repo` format (default: origin git remote)
- **--wrap** (flag) - Optional - Soft-wrap long diff lines instead of scrolling horizontally
### Examples
```bash
# View uncommitted changes
lumen diff
# View specific commit
lumen diff HEAD~1
# View PR by number
lumen diff --pr 123
```
```
--------------------------------
### List working tree changed files in Rust
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/vcs-backend.md
Returns a list of all files with changes in the current working tree.
```rust
let files = backend.get_working_tree_changed_files()?;
```
--------------------------------
### User Prompt Template
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/ai-prompts.md
The template used to structure user queries for the AI.
```text
Generate a git command for: [user query]
Respond in XML format:
git [command]
[what it does]
[optional warning about dangerous operations]
```
--------------------------------
### Define ThemePreset Enum
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/types.md
Available color themes for diff viewer.
```rust
pub enum ThemePreset {
DefaultDark,
DefaultLight,
CatppuccinMocha,
CatppuccinLatte,
Dracula,
Nord,
GruvboxDark,
GruvboxLight,
OneDark,
SolarizedDark,
SolarizedLight,
}
```
--------------------------------
### run_diff_ui
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/diff-viewer.md
The primary function to initialize and execute the diff viewer terminal UI.
```APIDOC
## run_diff_ui
### Description
Initializes the terminal UI for viewing diffs, handles user interactions, and manages the rendering lifecycle.
### Signature
`pub fn run_diff_ui(options: DiffOptions, backend: &dyn VcsBackend) -> Result<(), LumenError>`
### Parameters
- **options** (DiffOptions) - Required - Parsed CLI arguments for the diff viewer.
- **backend** (&dyn VcsBackend) - Required - The VCS backend implementation used for fetching diff content.
### Returns
- **Result<(), LumenError>** - Returns Ok(()) on successful exit or a LumenError if initialization or execution fails.
### Example Usage
```rust
let options = DiffOptions {
reference: Some(CommitReference::Single("HEAD".to_string())),
theme: Some("dracula".to_string()),
wrap: true,
..Default::new()
};
run_diff_ui(options, &backend)?;
```
```
--------------------------------
### Interact with VCS Backend
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/README.md
Common operations for retrieving commit information, working tree diffs, and changed file lists from the VCS backend.
```rust
let commit_info = backend.get_commit("HEAD")?;
let diff = backend.get_working_tree_diff(true)?;
let files = backend.get_changed_files("HEAD")?;
```
--------------------------------
### Execute command
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/commands.md
Dispatches a command type for execution; requires an active tokio runtime.
```rust
let command_type = CommandType::Explain {
git_entity,
query: None,
};
command.execute(command_type).await?;
```
--------------------------------
### Define Commit and CommitInfo structs
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/types.md
Structures for representing Git commit data and VCS-specific commit information.
```rust
pub struct Commit {
pub full_hash: String,
pub message: String,
pub diff: String,
pub author_name: String,
pub author_email: String,
pub date: String,
}
```
```rust
pub struct CommitInfo {
pub commit_id: String,
pub change_id: Option,
pub message: String,
pub diff: String,
pub author: String,
pub date: String,
}
```
--------------------------------
### Parse VcsBackendType from CLI
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/vcs-backend.md
Demonstrates case-insensitive parsing of the backend type from a string.
```rust
let backend_type = VcsBackendType::from("git"); // or "jj"
```
--------------------------------
### Groq Configuration
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/configuration.md
Configuration for using the Groq provider with a specific model and API key.
```json
{
"provider": "groq",
"model": "llama-3.3-70b-versatile",
"api_key": "gsk_..."
}
```
--------------------------------
### LumenCommand::execute
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/commands.md
Executes a command based on the provided CommandType.
```APIDOC
## async LumenCommand::execute(&self, command_type: CommandType<'_>) -> Result<(), LumenError>
### Description
Executes a command based on its type (Explain, Draft, List, or Operate). Requires a tokio runtime.
### Parameters
- **command_type** (CommandType) - Required - Type of command to execute
### Returns
- Result<(), LumenError> - Success or error
### Example
```rust
let command_type = CommandType::Explain {
git_entity,
query: None,
};
command.execute(command_type).await?;
```
```
--------------------------------
### Define LumenCommand struct
Source: https://github.com/jnsahaj/lumen/blob/main/_autodocs/commands.md
Initializes the command dispatcher with a required LumenProvider.
```rust
pub struct LumenCommand {
provider: LumenProvider,
}
```