A CLI tool that wraps shell commands with diagnostics and AI-ready workflows.
Project description
Terminal Copilot
A CLI tool that wraps shell commands with diagnostics and an AI-ready workflow foundation.
Installation
uv sync
Setup
Set your Gemini API key using one of these methods:
Option 1: Environment Variable
export GEMINI_API_KEY=your-api-key-here
Option 2: .env File
Create a .env file in the project root:
cp .env.example .env
Then edit .env and add your API key:
GEMINI_API_KEY=your-actual-api-key-here
Get your API key from Google AI Studio.
Usage
terminal-copilot run "<command>"
Examples
# Run a simple command
terminal-copilot run "echo hello world"
# Run a command that fails
terminal-copilot run "ls /nonexistent"
# Run with plugin detection
terminal-copilot run "git status"
terminal-copilot run "npm install"
terminal-copilot run "docker ps"
Output
The tool displays:
- The command that was executed
- The matching plugin (npm, docker, git, or unknown)
- Exit code (green for success, red for failure)
- Execution time
- stdout and stderr in separate panels
Configuration
Create ~/.terminal-copilot/config.yaml:
provider: gemini
auto_execute: false
plugins:
- npm
- docker
- git
Project Structure
terminal_copilot/
__init__.py # Package init
cli.py # Typer CLI entry point
runner.py # Shell command execution
config.py # YAML config loader
plugins.py # Plugin interface (npm, docker, git)
workflow.py # LangGraph workflow skeleton
models.py # Pydantic models
pyproject.toml
README.md
Tech Stack
- Python 3.12
- Typer – CLI framework
- Rich – Terminal UI
- Pydantic v2 – Data validation
- PyYAML – Config parsing
- LangGraph – Workflow graph
Milestone 5: Interactive Repair Loop
- Failure diagnosis with suggested commands
- Interactive fix selection prompt
- Execute chosen fix command
- Re-investigation on fix failure
- Loop until fix succeeds or user cancels
- Available in both
runandexplaincommands
Interactive Repair Flow
When a command fails, Terminal Copilot now guides you through an interactive repair process:
$ terminal-copilot run "npm install"
# ... command output ...
# Command fails
🔍 Root Cause
Node version mismatch in package.json engines requirement.
💡 Suggested Commands
1. corepack enable
2. pnpm install
3. Cancel
> 1
Executing: corepack enable
# ... fix attempt output ...
✓ Fix succeeded!
How It Works
- Failure: Command executes and fails
- Diagnosis: AI analyzes the failure and provides root cause + suggested fixes
- Choose Fix: You select a suggested command to try
- Execute: The chosen fix is executed
- Succeeded?:
- Yes → Done! Returns success
- No → Re-investigates using the new output, looping back to step 3
This creates an interactive repair loop that continues until either:
- A fix succeeds
- You choose to cancel
Using with explain
The interactive repair loop is also available when analyzing a previously failed command:
terminal-copilot explain
# Shows diagnosis with suggested fixes
# You can select and execute a fix directly
Milestone 4: Project Health & Preflight Checks
- Preflight checks before command execution
- Plugin-specific health checks (npm, docker, git, python, rust, go)
- Warning system for potential issues
- Error blocking for preventing dangerous commands
-
--skip-preflightflag to bypass checks - Project type detection from marker files
- Environment validation against project requirements
- Missing dependency detection (node_modules, Cargo.lock)
- Intelligent warnings for proactive issue detection
Project Detection
Terminal Copilot can automatically detect your project type based on common marker files:
- package.json → Node
- Cargo.toml → Rust
- go.mod → Go
- requirements.txt or pyproject.toml → Python
- Dockerfile → Docker
- docker-compose.yml → Docker Compose
# Detect project type in current directory
terminal-copilot detect
# Detect project type in a specific directory
terminal-copilot detect --path /path/to/project
Environment Validation
Validate your environment against project requirements to catch compatibility issues:
- Node.js: Compares installed version against
package.jsonengines.noderequirement - Python: Compares installed version against
pyproject.tomlpython_requiresrequirement - Docker: Checks if Docker daemon is running when Dockerfile/docker-compose.yml exists
- Dependencies: Detects missing dependency directories (node_modules, Cargo.lock)
# Validate environment compatibility
terminal-copilot validate
# Validate in a specific directory
terminal-copilot validate --path /path/to/project
Plugin Preflight Checks
Each plugin now provides preflight checks that run automatically before command execution. These checks detect common issues specific to each tool ecosystem:
NPM Plugin Example:
✓ package.json
✓ node v22.2.1
✓ npm 9.2.0
✓ lockfile
⚠ node_modules missing (run npm install)
Docker Plugin Example:
✓ Docker installed Docker version 24.0.0
✓ daemon running
⚠ Dockerfile
⚠ compose plugin missing
Available Plugin Checks
- npm: package.json, node version, npm version, lockfile, node_modules
- docker: Docker installed, daemon running, Dockerfile, compose plugin
- git: Git installed, in git repository
- rust: rustc, cargo, Cargo.toml
- go: Go installed, go.mod
- python: Python installed, virtual environment
Intelligent Warnings
Instead of waiting for failure, Terminal Copilot proactively detects potential issues before command execution:
- Git merge conflicts: Warns when your working directory has unresolved merge conflicts
- Docker daemon status: Warns when Docker is not running before executing docker commands
- Port conflicts: Warns when common development ports (3000, 3001, 4000, 5000, 5173, 8000, 8080, 9000) are already in use
Example warnings displayed before execution:
⚠ Git has merge conflicts in your working directory
This build is likely to fail. Resolve conflicts before proceeding.
⚠ Docker daemon is not running
Start Docker: 'systemctl start docker' or launch Docker Desktop
⚠ Port 3000 is already in use
Another process is using port 3000. Check with 'lsof -i :3000' or kill the process.
Future Milestones
- Auto-fixing failed commands
- File scanning and project analysis
- Streaming output improvements
- Watchdog mode
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file terminal_copilot_cli-0.1.3.tar.gz.
File metadata
- Download URL: terminal_copilot_cli-0.1.3.tar.gz
- Upload date:
- Size: 37.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
811320d2d6bb00e1f67afb953b622d6051e8e7de1674bdd8f9e35ab81e5c1b4d
|
|
| MD5 |
ca65fa079ca8df91bdfaad1ee3dc0381
|
|
| BLAKE2b-256 |
1afb72cb864a05fc9a245b7279fc997eb1b519cb5d4b5e8dfd23c8ea939ccae2
|
Provenance
The following attestation bundles were made for terminal_copilot_cli-0.1.3.tar.gz:
Publisher:
publish.yml on Smitbafna/terminal-copilot
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
terminal_copilot_cli-0.1.3.tar.gz -
Subject digest:
811320d2d6bb00e1f67afb953b622d6051e8e7de1674bdd8f9e35ab81e5c1b4d - Sigstore transparency entry: 2184801755
- Sigstore integration time:
-
Permalink:
Smitbafna/terminal-copilot@c934c16fca5bbbda8bfe53cb34f36f5f3d2e2789 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/Smitbafna
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c934c16fca5bbbda8bfe53cb34f36f5f3d2e2789 -
Trigger Event:
push
-
Statement type:
File details
Details for the file terminal_copilot_cli-0.1.3-py3-none-any.whl.
File metadata
- Download URL: terminal_copilot_cli-0.1.3-py3-none-any.whl
- Upload date:
- Size: 44.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71eb40f46f00bdbee5f4e606f624f9072a049fd0c493ed7fc6d25587c73d193e
|
|
| MD5 |
a8322344a254c88c092ef3da2dd69fc7
|
|
| BLAKE2b-256 |
f72aeb749cd14210fd82828f49322158740c6f77a31ca46834ffacb96cc37ed8
|
Provenance
The following attestation bundles were made for terminal_copilot_cli-0.1.3-py3-none-any.whl:
Publisher:
publish.yml on Smitbafna/terminal-copilot
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
terminal_copilot_cli-0.1.3-py3-none-any.whl -
Subject digest:
71eb40f46f00bdbee5f4e606f624f9072a049fd0c493ed7fc6d25587c73d193e - Sigstore transparency entry: 2184801875
- Sigstore integration time:
-
Permalink:
Smitbafna/terminal-copilot@c934c16fca5bbbda8bfe53cb34f36f5f3d2e2789 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/Smitbafna
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c934c16fca5bbbda8bfe53cb34f36f5f3d2e2789 -
Trigger Event:
push
-
Statement type: