Skip to main content

Interactive coding agent CLI

Project description

pig-coding-agent

Interactive coding agent CLI with file operations and code generation.

Features

  • ๐Ÿ’ป Code Generation: AI-powered code generation
  • ๐Ÿ“ File Operations: Read, write, edit files
  • ๐Ÿ” Code Analysis: Understand and analyze code
  • ๐Ÿ› ๏ธ Refactoring: Automated code refactoring
  • ๐Ÿš Shell Integration: Execute shell commands
  • ๐Ÿ’ฌ Interactive Chat: Conversational interface
  • ๐Ÿ”„ Resilience: Automatic API key rotation and fallback (NEW in v0.0.4)
  • ๐Ÿ’ฐ Cost Tracking: Track LLM and tool usage costs (NEW in v0.0.4)

Installation

pip install pig-coding-agent

Quick Start

Start Interactive Session

# Start coding agent
pig-code

# With specific model
pig-code --model gpt-4

# In a specific directory
pig-code --path /path/to/project

Command Line Usage

# Generate code
pig-code gen "Create a FastAPI hello world app"

# Analyze file
pig-code analyze main.py

# Refactor code
pig-code refactor main.py "Add type hints"

# Chat mode
pig-code chat

Built-in Tools

The coding agent comes with these tools:

File Operations

  • read_file(path) - Read file contents
  • write_file(path, content) - Write to file
  • list_files(directory) - List directory contents
  • search_files(pattern) - Search for files

Code Operations

  • generate_code(description) - Generate code from description
  • explain_code(code) - Explain what code does
  • fix_code(code, error) - Fix code errors
  • add_tests(code) - Generate tests for code

Shell Operations

  • run_command(command) - Execute shell command
  • git_status() - Get git status
  • git_diff() - Get git diff

Usage Examples

Generate a Python Module

$ pig-code
> Create a Python module for handling JSON files with read/write functions

Agent will:
1. Generate the code
2. Write to file
3. Show you the result

Analyze Codebase

$ pig-code analyze
> Analyze this codebase and suggest improvements

Agent will:
1. Read relevant files
2. Analyze structure
3. Provide recommendations

Interactive Refactoring

$ pig-code
> Refactor main.py to use async/await

Agent will:
1. Read the file
2. Refactor the code
3. Show diff
4. Ask for confirmation
5. Write changes

Configuration

Create .pig-code-config.json:

{
  "provider": "openai",
  "model": "gpt-4",
  "temperature": 0.7,
  "max_iterations": 10,
  "auto_confirm": false,
  "workspace": "./",
  "ignore_patterns": [
    "node_modules",
    ".git",
    "__pycache__"
  ]
}

Chat Commands

Inside the agent:

/help       - Show help
/exit       - Exit agent
/clear      - Clear conversation
/files      - List files in workspace
/status     - Show agent status
/resilience - Show resilience status (API keys, rotation)
/cost       - Show cost tracking summary
/usage      - Show usage statistics

Resilience Features (v0.0.4)

The agent now supports automatic resilience for production stability:

API Key Rotation

Set multiple API keys for automatic rotation on rate limits:

export OPENAI_API_KEY=sk-...
export OPENAI_API_KEY_2=sk-...
export OPENAI_API_KEY_3=sk-...
export ANTHROPIC_API_KEY=sk-ant-...
export ANTHROPIC_API_KEY_2=sk-ant-...

The agent will automatically:

  • Rotate to next available key on rate limits
  • Apply per-failure-type cooldowns (AUTH=5min, RATE_LIMIT=1min, etc.)
  • Fall back to alternative models on context overflow

Check Resilience Status

$ pig-code
> /resilience

Resilience Status
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
Total API keys: 5
Available: 4
In cooldown: 1

Profiles:
1. openai (key #0): โœ“
2. openai (key #2): โœ“
3. openai (key #3): โœ— (cooldown)
4. anthropic (key #0): โœ“
5. anthropic (key #2): โœ“

Disable Resilience

pig-code --no-resilience

Cost Tracking (v0.0.4)

Track LLM and tool usage costs automatically:

View Cost Summary

$ pig-code
> /cost

Usage Summary
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
Total LLM calls: 42
Total tool calls: 156
Total tokens: 125,430 in + 38,920 out
Total cost: $2.4580

By Model:
  gpt-4: 15 calls, 45,230 in + 12,450 out, $1.8900
  gpt-3.5-turbo: 27 calls, 80,200 in + 26,470 out, $0.5680

By Tool:
  read_file: 45 calls
  write_file: 23 calls
  run_command: 88 calls

Usage Data Location

Cost data is saved to .agents/usage.json in your workspace.

Disable Cost Tracking

pig-code --no-cost-tracking

Safety Features

  • File operation confirmations
  • Command execution warnings
  • Workspace boundaries
  • Backup before overwrite
  • Git integration for tracking changes

Architecture

CodingAgent
โ”œโ”€โ”€ Agent Core (pig-agent-core)
โ”œโ”€โ”€ LLM Client (pig-llm)
โ”œโ”€โ”€ TUI (pig-tui)
โ””โ”€โ”€ Built-in Tools
    โ”œโ”€โ”€ FileTools
    โ”œโ”€โ”€ CodeTools
    โ””โ”€โ”€ ShellTools

Examples

See examples/coding-agent/:

  • generate_app.py - Generate full application
  • refactor_demo.py - Code refactoring
  • analysis_demo.py - Code analysis

License

MIT

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

pig_coding_agent-0.0.4.tar.gz (28.3 kB view details)

Uploaded Source

Built Distribution

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

pig_coding_agent-0.0.4-py3-none-any.whl (25.6 kB view details)

Uploaded Python 3

File details

Details for the file pig_coding_agent-0.0.4.tar.gz.

File metadata

  • Download URL: pig_coding_agent-0.0.4.tar.gz
  • Upload date:
  • Size: 28.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pig_coding_agent-0.0.4.tar.gz
Algorithm Hash digest
SHA256 a1b69a03d5f923468800c44eae418ea7d1df93687316233ee7bc47d2e00493cb
MD5 87e24216f3d1234117fc90a0278109cc
BLAKE2b-256 104c7c9f6c7d3f14552d4291f43639ccfbc625dea2662509bfe9b4ef2df63914

See more details on using hashes here.

File details

Details for the file pig_coding_agent-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for pig_coding_agent-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 78e204fda98132307ad6b1ec03972beec2feb63fd91e1ff48a127a7ab31751fb
MD5 2c764a911f04eac7e335516fb53a7bba
BLAKE2b-256 95ac653f8efcae2bad353aaf48bb042276d1289ea16d7e91577e8ac2f4f25b16

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