Skip to main content

Minimalistic coding agent with Python API and CLI

Project description

RegCode

A minimalistic coding agent with Python API bindings and CLI interface.

Features

  • litellm as the LLM backbone (supports OpenAI, Anthropic, and 100+ providers)
  • YAML configuration for model, tokens, temperature, provider settings
  • Pydantic models for type-safe config loading with environment variable expansion
  • CLI via click: chat, configure, version
  • Python API: import regcode; agent = regcode.Agent()
  • Host filesystem I/O: write_file and patch_file operate directly on the host filesystem with path traversal protection
  • Patch tool: patch_file replaces a range of lines in an existing file
  • Robust tool call handling: malformed tool calls and JSON parse errors are gracefully handled
  • Progressive streaming: TUI always streams assistant responses progressively rather than all at once

Quick Start

# Install dependencies
uv sync

# Configure your API key (or set OPENAI_API_KEY in your environment)
# Edit config.yaml or use environment variables

# Chat with the agent
uv run regcode chat

# View current config
uv run regcode configure

# View version
uv run regcode version

Usage as a Library

import regcode

# Load config (reads config.yaml, falls back to defaults)
config = regcode.Config.load("config.yaml")

# Create agent
agent = regcode.Agent(config=config)

# Chat (TUI always streams responses progressively)
reply = agent.chat("Refactor this function to use async/await.")
print(reply)

# Reset conversation
agent.reset()

Tools

RegCode includes several built-in tools the agent can use:

Tool Permission Description
run_script EXECUTE Execute a Python script in the Monty sandbox
shell_command EXECUTE Execute shell commands (subprocess, not sandbox)
read_file READ Read the contents of a file from the filesystem
write_file WRITE Write content to a file on the host filesystem
patch_file WRITE Replace a range of lines in an existing file
list_dir READ List contents of a directory
search_files READ Search for files matching a pattern
browse_dir READ Recursively list all files in a directory tree
search_dir READ Search for a pattern inside all files within a directory
fetch_git_diff READ Fetch the git diff of the current repository
add_review_note WRITE Save review notes to persistent storage
read_review_notes READ Read previously saved review notes
system_info READ Get system information (OS, Python version, etc.)

All file-writing tools (write_file, patch_file) include path traversal protection (.. is blocked). The patch_file tool validates line number bounds and type correctness before performing the replacement.

Project Structure

regcode/
├── config.yaml          # All configuration
├── regcode/
│   ├── __init__.py      # Python API entry point
│   ├── main.py          # Agent core (chat, code review, etc.)
│   ├── cli.py           # CLI entry point (click)
│   ├── config.py        # Config loader (yaml + pydantic)
│   ├── permissions.py    # Tool permission definitions
│   ├── tui.py           # Terminal UI rendering
│   ├── conversation_manager.py
│   ├── sandbox.py
│   ├── monty_sandbox.py
│   └── tools/
│       ├── __init__.py
│       ├── base.py
│       ├── builtins.py   # Built-in tool implementations
│       ├── registry.py
│       └── review_notes.py
├── tests/
│   ├── conftest.py
│   ├── test_main.py
│   ├── test_config.py
│   ├── test_api.py
│   ├── test_cli.py
│   ├── test_context_manager.py
│   ├── test_monty_sandbox.py
│   ├── test_provider_extra.py
│   └── test_review_notes.py
├── pyproject.toml
├── uv.lock
└── README.md

Testing & Linting

uv run pytest tests/ -v
uv run ruff check --fix regcode/ tests/

Configuration

Edit config.yaml to change the model, provider, or tools:

agent:
  model: "openai/gpt-4o"
  max_tokens: 4096
  context_window: 128000
  temperature: 0.7

provider:
  name: "openai"
  api_key: "${OPENAI_API_KEY}"

system_prompt: |
  You are a coding agent. Help the user with code.

tools:
  code_review: true
  security_scan: false
  sandbox: false

Environment variables are expanded automatically (e.g., ${OPENAI_API_KEY}).

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

regcode-0.3.0.tar.gz (167.9 kB view details)

Uploaded Source

Built Distribution

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

regcode-0.3.0-py3-none-any.whl (39.5 kB view details)

Uploaded Python 3

File details

Details for the file regcode-0.3.0.tar.gz.

File metadata

  • Download URL: regcode-0.3.0.tar.gz
  • Upload date:
  • Size: 167.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for regcode-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c515a27a26e71e0776e010f52df601c23066cb4dd355506cd6cd8b14d18c4e7e
MD5 be83bbb554316252a7d8cdff34b05ae6
BLAKE2b-256 fdc8f84d52704c456ce90f60117c147266ecb0c4870910c225890ddc756b5405

See more details on using hashes here.

File details

Details for the file regcode-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: regcode-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 39.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for regcode-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4c9b11e3535824b459fe7cd0054089577e219fa06fa19f316fb0b26d8bab9d3b
MD5 c9d32fa5d6a17737aa1e10106447d317
BLAKE2b-256 94b9a2a1eb344fe5e63baf55e3320de628f42e0a04908e08fc390ac982d2ac2d

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