Skip to main content

Know before you run - A safety wrapper for dangerous shell commands

Project description

safe-cli

Know before you run - A safety wrapper for dangerous shell commands

Overview

safe analyzes shell commands before execution, warns you about potential dangers, and helps you avoid costly mistakes.

Part of a developer safety ecosystem:

  • scaffold → create projects safely
  • safe → run commands safely
  • cleaner → clean projects safely
  • uterm → undo mistakes safely
  • envdoctor → fix broken environments

Features

  • 🛡️ Danger Detection: Identifies risky command patterns before execution
  • ⚠️ Smart Warnings: Context-aware risk assessment
  • 🎯 Interactive Prompts: Beautiful CLI prompts powered by Rich
  • 🔍 Dry Run Mode: See what would happen without executing
  • 📚 Educational: Learn why commands are dangerous

Installation

pip install safe-cli

Or with Poetry:

poetry add safe-cli

Quick Start

# Analyze and run a command safely
safe rm -rf /tmp/test

# Dry run mode - see what would happen
safe --dry-run rm -rf /tmp/test

# Skip confirmations (useful for scripts)
safe --yes rm file.txt

# Get help
safe --help

Examples

Dangerous File Operations

$ safe rm -rf /
⚠️  CRITICAL DANGER DETECTED
This command will permanently delete files recursively from root directory.
→ Abort / Continue / View Safe Alternative?

Git Operations

$ safe git reset --hard HEAD~5
⚠️  HIGH RISK OPERATION
This will permanently discard uncommitted changes and reset 5 commits.
→ Continue? (y/N)

System Commands

$ safe sudo dd if=/dev/zero of=/dev/sda
⚠️  CRITICAL DANGER DETECTED
This will overwrite disk with root privileges - DATA LOSS IMMINENT
→ Abort / Continue / View Safe Alternative?

Command Coverage (v0.1.0)

Filesystem Operations

  • rm - File deletion with recursive and force flags
  • mv - File moving with force overwrite detection
  • cp - File copying with recursive operations
  • chmod - Permission changes (detects dangerous 777/666)
  • chown - Ownership changes on system files

Git Operations

  • git reset - Detects --hard and commit resets
  • git push --force - Warns about force pushes, especially to main/master
  • git clean - Prevents accidental deletion of untracked files
  • git branch -D - Warns about force-deleting unmerged branches

Docker Operations

  • docker system prune - Detects --all and --volumes flags
  • docker rm - Container removal with force and volume flags
  • docker rmi - Image removal warnings
  • docker volume prune - Critical volume data deletion warning

System Commands

  • sudo - Detects dangerous command combinations with root
  • dd - Warns about disk device overwrites
  • kill/killall - Especially with -9 (SIGKILL) flag
  • shutdown/reboot - System restart warnings
  • mkfs - Filesystem formatting (data destruction)

Development

# Clone the repository
git clone https://github.com/Njau-dev/safe-cli.git
cd safe-cli

# Install dependencies
poetry install

# Run tests
poetry run pytest

# Run with coverage
poetry run pytest --cov

# Format code
poetry run black src tests

# Lint
poetry run ruff check src tests

Architecture

safe-cli/
├── src/safe_cli/
│   ├── cli.py           # Entry point
│   ├── core/            # Core functionality
│   │   ├── parser.py    # Command parsing
│   │   ├── analyzer.py  # Risk analysis
│   │   └── executor.py  # Command execution
│   ├── rules/           # Risk detection rules
│   ├── ui/              # User interface
│   └── utils/           # Utilities
└── tests/               # Test suite

Roadmap

  • v0.1.0 (Current): MVP with core safety features
  • v0.2.0: Command history and pattern learning
  • v0.3.0: Team-wide safety policies
  • v0.4.0: Integration with UTerm, Cleaner, EnvDoctor
  • v0.5.0: Advanced simulation and dry-run
  • v1.0.0: Shell integration and plugin system

Contributing

See CONTRIBUTING.md for development guidelines.

License

MIT License - see LICENSE for details.

Ecosystem

Part of the developer safety toolkit:

  • scaffold-cli - Project scaffolding
  • safe-cli - Command safety (you are here)
  • Coming soon: cleaner, uterm, envdoctor

Safety first, always. 🛡️

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

safectl-0.1.0.tar.gz (23.4 kB view details)

Uploaded Source

Built Distribution

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

safectl-0.1.0-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

File details

Details for the file safectl-0.1.0.tar.gz.

File metadata

  • Download URL: safectl-0.1.0.tar.gz
  • Upload date:
  • Size: 23.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.12 Linux/6.11.0-1018-azure

File hashes

Hashes for safectl-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b14c057a69b9e02ce6b47d7629e6282e1e10bb09576f0090f736a45d7aad1673
MD5 857cb64156e7d737d3f3de55cbad01ad
BLAKE2b-256 916ac2371de5b469ca59b5457b4c6acaf0586175b76a80db3a5803f855d821a9

See more details on using hashes here.

File details

Details for the file safectl-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: safectl-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 29.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.12 Linux/6.11.0-1018-azure

File hashes

Hashes for safectl-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 480b8193230267982a4acf0337c939c9a4dec82efa7779357b36ef74a3558d5f
MD5 184da45073a0bf8bbb29d5aa7c52cf2f
BLAKE2b-256 7821a0c9a976c386478aecdb75fdfd90949e6dd749f50464f0384b28926fc9ff

See more details on using hashes here.

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