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.2.0.tar.gz (167.6 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.2.0-py3-none-any.whl (39.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: regcode-0.2.0.tar.gz
  • Upload date:
  • Size: 167.6 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.2.0.tar.gz
Algorithm Hash digest
SHA256 0f2e78fbe8160aa4f542902b2588decb5422880472d11a1aa56868c2289d0ba8
MD5 e1ae982b755e992fd32dc11fdd08c77c
BLAKE2b-256 90eb2f58b66dc4cd0cb61002fc001f28dfc2626d3116977f8705404cc6e93cd7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: regcode-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 39.2 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c72b15db4c9fc38ccb145851c8fdb61bc51841240fb09d45afd23d33e56a7e83
MD5 dda59f8ba4cdfdbe8e3f850b628e36ee
BLAKE2b-256 5b6e94511d62f2e76aa97673cee066cfb7dcd1f653941037f73db194f70f1f7d

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