A Claude Code-style AI coding assistant built with LangGraph and GPT-4o
Project description
Coder Buddy - AI-Powered Coding Assistant
A Claude Code-style AI coding assistant built with LangGraph and OpenAI GPT-4o that transforms natural language prompts into complete, working projects. Supports both creating new projects from scratch and modifying existing codebases.
Open Source - Free to use, modify, and distribute under the MIT License.
+-----------------------------------------------------+
| CCCCC OOOOO DDDD EEEEE RRRR |
| C O O D D E R R |
| C O O D D EEEE RRRR |
| C O O D D E R R |
| CCCCC OOOOO DDDD EEEEE R R |
| |
| Coder Buddy - AI Assistant |
+-----------------------------------------------------+
โจ Features
Core Capabilities
- ๐๏ธ Multi-Agent Architecture - Specialized agents (Clarifier, Planner, Architect, Coder) orchestrated by LangGraph
- ๐จ Beautiful Terminal UI - Rich formatting with spinners, progress indicators, panels, and syntax highlighting
- โก Real-time Streaming - Stream tokens as the AI thinks and writes code
- ๐บ Live Command Output - Real-time buffered streaming of shell command output (npm install, builds, etc.)
- ๐ Build & Edit Modes - Create new projects from scratch OR modify existing codebases
- ๐ Smart Project Discovery - Auto-detects project structure before planning modifications
- โ Intelligent Clarification - Asks clarifying questions for vague prompts
- ๐ฅ Human-in-the-Loop - Review and approve/edit plans before implementation
- ๐ฌ Interactive Chat - Discuss your project with full context awareness
- ๐ Dynamic Project Folders - Projects created in named directories (e.g.,
todo-app/,snake-game/) - ๐ ๏ธ Comprehensive Tools - File operations, pattern matching, content search, shell commands
- ๐ Sandboxed Execution - All operations confined to project root
- โ๏ธ Permission System - Strict mode (asks confirmation) or permissive (automatic)
Advanced Features
- โ Plan Confirmation - Review architecture before building
- โ๏ธ Edit Instructions - Request changes to plan/architecture mid-workflow
- ๐ฏ Precise Editing -
edit_file()for exact string replacement - ๐ File Discovery -
glob_files()for pattern matching - ๐ Content Search -
grep()with regex support - ๐ Post-Completion Options - Chat, continue editing, or start new project
- ๐ Run Instructions - Detailed step-by-step guide with copy-paste commands
- ๐ Auto-Launch - Opens projects in browser or starts servers
๐ Installation
Prerequisites
- Python 3.12+
- OpenAI API key (for GPT-4o access)
Option 1: Install from PyPI (Recommended)
pip install coder-buddy
# Set your API key
export OPENAI_API_KEY=sk-your-key-here
# Run
coder-buddy
Option 2: Install from Source
# Clone the repository
git clone https://github.com/garodisk/CodeBuddy.git
cd CodeBuddy
# Install with uv (recommended)
uv sync
# Or install with pip
pip install -e .
# Create .env file with your API key
echo "OPENAI_API_KEY=sk-your-key-here" > .env
๐ Usage
Interactive Mode (Build or Edit)
uv run python main.py
This starts the REPL with interactive mode selection:
What would you like to do?
1) Build a new project - Start from scratch
2) Edit an existing project - Modify existing code
Choice [1-2]:
Build Mode Examples:
> Create a snake game in Python with pygame
> Build a REST API with FastAPI and SQLite
> Make a React todo app with Tailwind CSS
Edit Mode Examples:
> Add dark mode toggle to the settings
> Implement JWT authentication
> Add database migration system
Single Prompt Mode
uv run python main.py --prompt "Create a calculator web app"
CLI Options
uv run python main.py --mode build # Explicitly use build mode
uv run python main.py --mode edit --root ./my-project # Edit existing project
uv run python main.py --permission strict # Ask before dangerous operations
uv run python main.py --permission permissive # Allow all operations
uv run python main.py --recursion-limit 150 # Set graph recursion limit
Commands in REPL
| Command | Description |
|---|---|
/new |
Start a new project (re-select build/edit mode) |
/status |
Show current mode and settings |
/help |
Show all commands |
/clear |
Clear the screen |
/exit |
Exit the application |
Chat Commands (in Chat Mode)
| Command | Description |
|---|---|
/done |
Exit chat and finish |
/continue |
Continue building this project (switch to edit mode) |
/new |
Start a new project |
/help |
Show chat commands |
๐๏ธ Architecture
LangGraph Multi-Agent Flow
graph TD
A[User Input] --> B[Clarifier Agent]
B --> C{Vague Prompt?}
C -->|Yes| D[Ask Clarifications]
C -->|No| E[Project Discovery]
D --> E
E --> F[Planner Agent]
F --> G{User Confirms Plan?}
G -->|Edit| F
G -->|Cancel| END1[End]
G -->|Proceed| H[Architect Agent]
H --> I{User Confirms Tasks?}
I -->|Edit| H
I -->|Cancel| END2[End]
I -->|Proceed| J[Coder Agent]
J --> K[Tools]
K --> L{More Tasks?}
L -->|Yes| J
L -->|No| M[Complete]
M --> N{What's Next?}
N -->|Chat| O[Chat Mode]
N -->|Continue| F
N -->|New| A
N -->|Exit| END3[End]
O --> N
Detailed Agent Pipeline
flowchart TD
subgraph INPUT["๐ฏ USER INPUT"]
A[User Prompt]
end
subgraph CLARIFIER["๐ CLARIFIER AGENT"]
B{Vague prompt?}
C[๐ฌ Ask Questions<br>max 3 Q&A]
end
subgraph DISCOVERY["๐ PROJECT DISCOVERY"]
D["Edit Mode Only:<br>โข Read directory tree<br>โข Find README<br>โข Parse dependencies<br>โข Read main files"]
end
subgraph PLANNING["๐ PLANNING LOOP"]
E["๐ PLANNER AGENT<br>โข Name & description<br>โข Tech stack<br>โข Features list<br>โข Files to create"]
F{"๐ค CONFIRM?"}
end
subgraph ARCHITECTURE["๐ ARCHITECTURE LOOP"]
G["๐๏ธ ARCHITECT AGENT<br>โข Break into tasks<br>โข ONE task per file<br>โข Order by deps"]
H{"๐ค CONFIRM?"}
end
subgraph IMPLEMENTATION["๐ IMPLEMENTATION LOOP"]
I["๐ป CODER AGENT"]
I1["๐ ๏ธ Tools:<br>read_file | write_file | edit_file<br>glob_files | grep | list_files | run_cmd"]
K["๐ Files Created/Modified"]
end
subgraph COMPLETE["โ
COMPLETE"]
L[Project Ready!]
M{"What's next?"}
end
A --> B
B -->|YES| C
B -->|NO| D
C --> D
D --> E
E --> F
F -->|Proceed| G
F -->|Edit| E
F -->|Cancel| END1[END]
G --> H
H -->|Start| I
H -->|Modify| G
H -->|Cancel| END2[END]
I --> I1
I1 --> K
K -->|loop| I
K -->|done| L
L --> M
M -->|Continue| E
M -->|New| A
style INPUT fill:#e1f5fe
style CLARIFIER fill:#fff3e0
style DISCOVERY fill:#f3e5f5
style PLANNING fill:#e8f5e9
style ARCHITECTURE fill:#fff8e1
style IMPLEMENTATION fill:#fce4ec
style COMPLETE fill:#c8e6c9
Key Design Principles
| Principle | Description |
|---|---|
| ๐ Human-in-the-Loop | User confirms/edits at every major step |
| ๐ ONE Task Per File | Architect creates exactly one task per file |
| ๐ Discovery Before Planning | Edit mode reads project structure first |
| ๐ก๏ธ Sandboxed Execution | All file ops confined to project root |
| โ ๏ธ Dangerous Command Blocking | Blocks rm -rf, sudo, etc. in strict mode |
๐ง Tools
File Operations
| Tool | Signature | Description |
|---|---|---|
read_file |
(path: str) -> str |
Read file contents |
write_file |
(path: str, content: str) -> str |
Write/create files |
edit_file |
(path: str, old_str: str, new_str: str) -> str |
NEW: Precise string replacement (old_str must appear exactly once) |
list_files |
(directory: str) -> str |
List files recursively |
get_current_directory |
() -> str |
Get project root path |
Discovery & Search
| Tool | Signature | Description |
|---|---|---|
glob_files |
(pattern: str, max_results: int = 100) -> str |
NEW: Find files by glob pattern |
grep |
(pattern: str, path: str, max_results: int = 50, ignore_case: bool) -> str |
NEW: Search with regex |
Execution
| Tool | Signature | Description |
|---|---|---|
run_cmd |
(cmd: str, cwd: str?, timeout: int?) -> dict |
Run shell command with real-time output streaming and permission check |
Sandbox Protection
All tools use path validation to prevent escape:
def safe_path_for_project(path: str) -> pathlib.Path:
root = get_project_root()
p = (root / path).resolve()
# Ensure p is within root
if root.resolve() not in p.parents and root.resolve() != p:
raise ValueError("Attempt to write outside project root")
return p
This prevents:
- Path traversal:
../../etc/passwd - Absolute paths:
/etc/passwd - Symlink escape:
link โ /etc
๐ฏ Modes
Build Mode
- Use Case: Create new projects from scratch
- Workflow: Plan โ Confirm โ Architect โ Confirm โ Code
- Tools: Full write access to new project directory
- Default: Yes
uv run python main.py --mode build
Edit Mode
- Use Case: Modify existing projects
- Workflow: Discover โ Plan โ Confirm โ Architect โ Confirm โ Code
- Tools:
read_file()to understand existing codeedit_file()for precise modificationsglob_files()andgrep()to find relevant codewrite_file()for new files only
- Special: Project discovery runs first
uv run python main.py --mode edit --root ./my-project
โ๏ธ Permission Modes
Strict Mode (Default)
- Asks for confirmation before:
- Overwriting existing files
- Running dangerous commands (
rm -rf,sudo, etc.)
- Safe for learning and experimentation
uv run python main.py --permission strict
Permissive Mode
- Allows all operations without confirmation
- Faster execution
- Use only when fully trusting the agent
uv run python main.py --permission permissive
๐ค Workflow Examples
Example 1: Build Mode with Clarification
> todo app
[!] Your request needs some clarification...
Clarification Questions
Q1. What is the main purpose/goal of this project?
A1: A simple app to manage daily tasks
Q2. What are the key features or functionalities needed?
A2: Add tasks, mark complete, delete, filter by status
Q3. Any specific requirements or constraints?
A3: Should work offline with local storage
[+] Clarifications collected!
[*] Planning project...
Then user reviews plan and can:
- โ Proceed with building
- โ Edit the plan ("Use React instead")
- โ Cancel and restart
Example 2: Edit Mode Project Discovery
> Add authentication to the project
[*] Discovering Project Structure
[>] Reading project structure...
[>] Looking for README...
[>] Looking for dependency files...
[>] Looking for main code files...
[+] Project discovery complete! Found 5 key items.
[*] Planning project...
Agent now knows about existing code and suggests modifications to:
- models/User.js
- routes/auth.js
- middleware/authenticate.js
Example 3: Post-Completion Chat
[+] Project generated successfully!
Generated Files
+-- src/
+-- styles/
+-- index.html
๐ Project Location
/home/user/projects/my-app
--- How to Run Your Project ---
1. Open Terminal & Navigate to Project:
cd /home/user/projects/my-app
2. Install Dependencies:
npm install
3. Start the Server:
npm start
โ Opened in browser!
--- What's Next? ---
What would you like to do?
1) ๐ฌ Chat - Ask questions about the project
2) ๐ง Continue - Keep building on this project
3) ๐ New Project - Start something new
4) ๐ Exit - Done for now
Choice [1-4]: 1
--- Chat Mode ---
Chat> How do I add a new feature?
You: A feature typically involves...
๐ State Schema
GraphState (TypedDict)
GraphState
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ user_prompt: str โ
โ plan: Plan โ
โ task_plan: TaskPlan โ
โ coder_state: CoderState โ
โ messages: list[BaseMessage] โ
โ status: str โ
โโ NEW FIELDS โโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ mode: str ("build" | "edit") โ
โ project_root: str (absolute path) โ
โ permission_mode: str ("strict" | ...) โ
โ edit_instruction: Optional[str] โ
โ clarification_questions: Optional[] โ
โ clarification_answers: Optional[] โ
โ project_context: Optional[str] โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
New Models
class ClarificationRequest(BaseModel):
questions: list[str] # 1-3 questions to ask user
reason: str # Why these questions are needed
๐ Project Structure
CodeBuddy/
โโโ main.py # Entry point, REPL, modes
โ โโโ main()
โ โโโ repl()
โ โโโ run_agent()
โ โโโ select_mode_interactive()
โ โโโ chat_about_project()
โ โโโ post_completion_menu()
โ โโโ show_run_instructions()
โ โโโ handle_command()
โ
โโโ pyproject.toml # Project config (uv)
โโโ .env # API keys
โโโ README.md # This file
โ
โโโ agent/
โโโ __init__.py
โ
โโโ graph.py # LangGraph orchestration
โ โโโ clarifier_agent() # NEW: Detect vague prompts
โ โโโ discover_project() # NEW: Read existing project
โ โโโ planner_agent()
โ โโโ planner_confirm_node() # NEW: Review plan
โ โโโ architect_agent()
โ โโโ architect_confirm_node() # NEW: Review architecture
โ โโโ coder_agent()
โ โโโ agent (compiled graph)
โ
โโโ states.py # Pydantic models
โ โโโ File
โ โโโ Plan
โ โโโ ImplementationTask
โ โโโ TaskPlan
โ โโโ CoderState
โ โโโ ClarificationRequest # NEW
โ โโโ GraphState
โ
โโโ tools.py # LangChain tools
โ โโโ read_file
โ โโโ write_file
โ โโโ edit_file # NEW: Precise editing
โ โโโ list_files
โ โโโ glob_files # NEW: Pattern matching
โ โโโ grep # NEW: Content search
โ โโโ get_current_directory
โ โโโ run_cmd (with permission checks)
โ โโโ set_permission_mode()
โ โโโ is_dangerous_command()
โ โโโ safe_path_for_project()
โ
โโโ prompts.py # System prompts
โ โโโ planner_prompt() (mode-aware)
โ โโโ architect_prompt() (mode-aware)
โ โโโ coder_system_prompt() (mode-aware)
โ
โโโ ui.py # Terminal UI (Rich)
โโโ TerminalUI class
โโโ spinner()
โโโ stream_text()
โโโ tool_panel()
โโโ diff_panel() # NEW: Show edits
โโโ file_tree()
โโโ todo_list()
โโโ prompt()
โโโ confirm()
โโโ [colored messages]
๐ Permission System
Dangerous Commands
The following patterns are blocked in strict mode:
DANGEROUS_PATTERNS = [
r"rm\s+-rf", # rm -rf
r"sudo\s+", # sudo
r"chmod\s+777", # chmod 777
r"curl.*\|\s*sh", # curl | sh
r"wget.*\|\s*sh", # wget | sh
r"dd\s+if=", # dd if= (disk operations)
r"mkfs\.", # mkfs (format disk)
r":(){ :|:& };:", # fork bomb
r">\s*/dev/sd", # redirect to disk
r"mv.*\s+/dev/null", # mv to /dev/null
]
Permission Flow
Agent runs command
โ
Is permission mode "strict"?
โโ YES โ Check if command matches DANGEROUS_PATTERNS
โ โโ YES โ Show warning, ask user confirmation
โ โ โโ User says YES โ Execute
โ โ โโ User says NO โ Block
โ โโ NO โ Execute
โโ NO (permissive) โ Execute immediately
๐จ Terminal UI
Built with Rich:
| Component | Usage | Example |
|---|---|---|
| Spinner | During LLM calls | [*] Planning project... |
| Streaming | Real-time output | Tokens print as they generate |
| Panels | Tool output | [READ] file.py in box |
| Diff Panel | NEW Edit visualization | Shows old/new with colors |
| Trees | File listings | Project structure |
| Messages | Status updates | [+] Success / [!] Warning |
| Prompts | User input | > Your request: |
| Confirmations | NEW Yes/No choice | Overwrite? [y/N] |
| Tables | Lists | Task list with checkboxes |
๐ Advanced Features
Clarification System
For vague prompts (< 10 words, no tech stack, generic), automatically asks:
is_vague = (
word_count < 10 or
(not has_tech_stack and has_generic_phrases)
)
if is_vague:
# Ask max 3 clarification questions
questions = llm.generate_clarifications(prompt)
# User provides answers
enhanced_prompt = f"{prompt}\n\nQ&A:\n{qa_pairs}"
Edit File Tool
Enables precise editing in edit mode:
edit_file("models/User.js", old_str=<search>, new_str=<replace>)
# - Must find old_str exactly once
# - Shows diff panel before writing
# - Maintains code consistency
Project Discovery (Edit Mode)
Reads before planning to avoid hallucination:
1. Read directory tree (skip node_modules, .git, etc.)
2. Find and read: README, package.json, main files
3. Pass project_context to planner/architect prompts
4. Agents now suggest edits to REAL files
Human-in-the-Loop
Two confirmation points prevent bad code:
Plan Review:
1) Proceed
2) Edit plan ("Use React instead")
3) Cancel
Architecture Review:
1) Start building
2) Modify tasks ("Split User.js into multiple files")
3) Cancel
๐ Roadmap
See docs/PLAN.md for detailed implementation plan.
โ Completed (Recent Releases)
- โ Edit mode for existing projects
- โ Clarification agent for vague prompts
- โ Human-in-the-loop confirmations
- โ New tools: edit_file, glob_files, grep
- โ Permission system with dangerous command blocking
- โ Chat mode with project context
- โ Post-completion options (chat/continue/new)
- โ Project discovery before editing
- โ Enhanced run instructions
- โ Build/edit mode selection
๐ In Progress
- Streaming improvements
- Better error recovery
- Performance optimizations
๐ Future Features
- Git integration (create commits, push to GitHub)
- Web search integration
- Custom tool creation
- Project templates
- Batch operations
- Team collaboration
๐ Key Concepts
ONE Task Per File Rule
Architect creates exactly ONE task per file to prevent duplication:
โ WRONG:
Task 1: models/User.js - Add email field
Task 2: models/User.js - Add password hashing
โ
CORRECT:
Task 1: models/User.js - Add email field to schema,
implement password hashing, add validation
Mode-Aware Prompts
Planner, Architect, and Coder prompts change based on mode:
# Build mode: Focus on creating new files
# Edit mode: Focus on existing files, use edit_file()
Message Persistence
Coder maintains full message history across all steps:
Step 1: SystemMessage + HumanMessage(task 1) + AI + Tools
Step 2: [all above] + HumanMessage(task 2) + AI + Tools
Step 3: [all above] + HumanMessage(task 3) + AI + Tools
This gives full context for consistency.
๐ค Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/my-feature) - Make your changes
- Test thoroughly
- Submit a pull request
๐ License
MIT
๐ Acknowledgments
- LangGraph - Multi-agent orchestration
- LangChain - LLM framework
- Rich - Beautiful terminal formatting
- OpenAI - GPT-4o API
๐ Support
- ๐ Check docs/PLAN.md for detailed architecture
- ๐ Report issues on GitHub Issues
- ๐ฌ Start a GitHub Discussion
Built with LangGraph + GPT-4o by the Coder Buddy team
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file coder_buddy-0.1.1.tar.gz.
File metadata
- Download URL: coder_buddy-0.1.1.tar.gz
- Upload date:
- Size: 40.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a02f2506d9cc8ea06b92087f51f56880709d1700c6a8677e9f8c8a9ff28d8596
|
|
| MD5 |
434fcb720142e39118cc6db9a5c33041
|
|
| BLAKE2b-256 |
74b447c21a73663d5bab7175c8fea8811241441b01e45523d967e65ee8be123b
|
File details
Details for the file coder_buddy-0.1.1-py3-none-any.whl.
File metadata
- Download URL: coder_buddy-0.1.1-py3-none-any.whl
- Upload date:
- Size: 35.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ccdc30918a364a44fa324357da9981d31d178de922818461222461272c6e5c3b
|
|
| MD5 |
1e7a84372eb428b56d2519bcc659fadc
|
|
| BLAKE2b-256 |
e98669796e2e2fa278ba7a405239257a33a49f6a51492a76bd5c9942785b9b64
|