Skip to content

acebot712/promptguard-cli

Repository files navigation

PromptGuard CLI

Drop-in LLM security for your applications - Built with Rust + Tree-sitter

Version Rust License Status

Single 5.3MB binary • Zero dependencies • Real AST transformations • <10ms startup


Production Status

PRODUCTION READY - All features implemented and tested

  • Core Features: Init, Scan, Apply, Revert, Disable, Enable
  • AST Transformations: TypeScript, JavaScript, Python (Tree-sitter powered)
  • Provider Support: OpenAI, Anthropic, Cohere, HuggingFace
  • Backup/Restore: Automatic backups with safe revert
  • Configuration: Persistent config with enabled/disabled states
  • Management: Config viewer, API key management, status checks
  • Release Build: Optimized binary (5.3MB) with LTO and strip

Tested workflows:

  • Full init → transform → revert cycle
  • Disable → enable toggle workflow
  • Backup creation and restoration
  • TypeScript/JavaScript transformations (baseURL injection)
  • Python transformations (base_url injection + import os)

Why This CLI?

This is a complete Rust rewrite using proper Tree-sitter AST parsing. Unlike regex-based tools, it provides:

  • True AST transformations - Never breaks your code
  • Zero false positives - Precise detection and modification
  • Single static binary - No Python, Node.js, or runtime dependencies
  • Instant startup - <10ms cold start
  • 4 Providers - OpenAI, Anthropic, Cohere, HuggingFace

Installation

One-Line Install (Recommended)

macOS / Linux:

curl -fsSL https://raw.githubusercontent.com/acebot712/promptguard-cli/main/install.sh | sh

The install script will:

  • Detect your OS and architecture automatically
  • Download the appropriate binary from GitHub releases
  • Verify checksums
  • Install to /usr/local/bin/promptguard
  • Test the installation

Manual Installation

1. Download binary for your platform:

Visit GitHub Releases and download:

  • promptguard-macos-arm64 - macOS Apple Silicon (M1/M2/M3)
  • promptguard-macos-x86_64 - macOS Intel
  • promptguard-linux-x86_64 - Linux 64-bit
  • promptguard-linux-arm64 - Linux ARM64

2. Install:

# Make executable
chmod +x promptguard-*

# Move to PATH
sudo mv promptguard-* /usr/local/bin/promptguard

# Verify
promptguard --version

Package Managers (Coming Soon)

# Homebrew (macOS)
brew install promptguard/tap/promptguard

# Cargo (Rust)
cargo install promptguard-cli

# npm (JavaScript ecosystem)
npm install -g promptguard

Uninstallation

Uninstall (if installed via install.sh)

macOS / Linux:

curl -fsSL https://raw.githubusercontent.com/acebot712/promptguard-cli/main/uninstall.sh | sh

The uninstall script will:

  • Remove the binary from /usr/local/bin/promptguard
  • Ask if you want to remove configuration files
  • Verify successful removal

Manual uninstall:

# Remove binary
sudo rm /usr/local/bin/promptguard

# Optionally remove configuration
rm -rf ~/.promptguard

Uninstall (if installed via make install)

From the project directory:

make uninstall

Or using cargo directly:

cargo uninstall promptguard-cli

Optionally remove configuration:

rm -rf ~/.promptguard

Quick Start

Usage

# Initialize PromptGuard in your project
promptguard init --api-key pg_sk_test_xxx

# Scan for LLM SDKs (dry-run)
promptguard scan

# Check status
promptguard status

# Diagnostics
promptguard doctor

How It Works

Before

const openai = new OpenAI({ 
  apiKey: process.env.OPENAI_API_KEY 
});

After promptguard init

const openai = new OpenAI({
  apiKey: process.env.PROMPTGUARD_API_KEY,
  baseURL: "https://api.promptguard.co/api/v1/proxy"
});

Result: All LLM requests now go through PromptGuard's security layer with zero code changes!


Commands

Command Description
init Initialize PromptGuard in this project
scan Scan project for LLM SDK usage
status Show current configuration
doctor Diagnose common issues
apply Apply pending changes
disable Temporarily disable
enable Re-enable
revert Complete removal

Architecture

True AST Parsing (Not Regex!)

// Tree-sitter query for detecting OpenAI constructor
(new_expression
    constructor: (identifier) @constructor
    (#eq? @constructor "OpenAI")
    arguments: (arguments) @args
) @new_expr

Why this matters:

  • ✅ Never matches patterns in strings or comments
  • ✅ Handles complex nested structures correctly
  • ✅ Validates syntax automatically
  • ✅ Zero false positives

Supported Languages & Providers

Provider TypeScript JavaScript Python
OpenAI
Anthropic
Cohere
HuggingFace

Development

Build

# Debug build
cargo build

# Release build (optimized, 4.3MB)
cargo build --release

# Run tests
cargo test

Project Structure

src/
├── main.rs              # CLI entry point (Clap)
├── scanner/             # Recursive file scanning
├── detector/            # AST-based SDK detection
│   ├── typescript.rs    # Tree-sitter TypeScript/JavaScript
│   └── python.rs        # Tree-sitter Python
├── transformer/         # AST-based code transformation
│   ├── typescript.rs    # TS/JS transformer
│   └── python.rs        # Python transformer
├── config/              # JSON configuration (Serde)
├── backup/              # Backup/restore system
├── env/                 # .env file manager
├── api/                 # HTTP API client (Reqwest)
└── commands/            # 12 CLI commands

Total: 2,325 LOC Rust • 11 modules • Clean architecture


Why Rust?

vs Python CLI

  • 10x faster (<10ms vs ~100ms startup)
  • Single binary (no Python interpreter)
  • Zero pip/venv hell (works on fresh systems)

vs Go CLI

  • Better AST libraries (Tree-sitter is first-class)
  • No cgo needed (Go requires cgo for Tree-sitter)
  • Type safety (Rust catches bugs at compile time)

Binary Metrics

Metric Value
Size (release) 4.3MB
Dependencies 0 runtime
Startup time <10ms
Cross-platform ✅ macOS, Linux, Windows

Examples

Scan a project

$ promptguard scan

🛡️  PromptGuard CLI v1.0.0

📊 LLM SDK Detection Report

OpenAI SDK (3 files, 5 instances)
├── src/api/chat.ts
├── src/services/embeddings.ts
└── lib/openai.ts

Summary:
  • Total files scanned: 247
  • Total instances: 5

Providers detected:
  ✓ openai

Next: promptguard init

Initialize with dry-run

promptguard init --api-key pg_sk_test_xxx --dry-run

# Shows what would change without modifying files

Check status

$ promptguard status

Status: ✓ Active
API Key: pg_sk_test_*** (configured)
Proxy URL: https://api.promptguard.co/api/v1/proxy

Configuration:
  • Files managed: 3
  • Providers: openai

Makefile Targets

make build          # Build debug binary
make release        # Build optimized release
make install        # Install to ~/.cargo/bin
make test           # Run tests
make clean          # Clean artifacts

License

Apache 2.0 - See LICENSE


Links


Built with Rust 🦀 | Powered by Tree-sitter 🌳 | Zero Compromises ⚡

About

PromptGuard CLI - Drop-in LLM security for your applications. Built with Rust + Tree-sitter.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •