> ## Documentation Index
> Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Code Editor Examples

> 10 real-world examples of PraisonAI as an AI code editor - editing files, running tests, and fixing bugs

## Overview

PraisonAI functions as a **real AI code editor** that can:

* **Edit files** on disk
* **Run terminal commands** (pytest, ruff, etc.)
* **Observe failures** and fix them
* **Converge to green tests**

This guide covers 10 real-world scenarios demonstrating these capabilities.

## CLI Contract (January 2026)

| Command             | Description                    | Key Flags                    |
| ------------------- | ------------------------------ | ---------------------------- |
| `praisonai chat`    | Terminal-native REPL           | `-m`, `-w`, `-f`, `-c`, `-s` |
| `praisonai code`    | Terminal-native code assistant | `-m`, `-w`, `-f`, `-c`, `-s` |
| `praisonai tui`     | Full TUI interface             | `-w`, `-s`, `-m`             |
| `praisonai ui chat` | Browser-based chat             | `--port`, `--host`           |
| `praisonai ui code` | Browser-based code             | `--port`, `--host`           |

### Key Flags

| Flag              | Description                             |
| ----------------- | --------------------------------------- |
| `-m, --model`     | LLM model to use (default: gpt-4o-mini) |
| `-w, --workspace` | Working directory for file operations   |
| `-f, --file`      | Attach file(s) to prompt                |
| `-c, --continue`  | Continue last session                   |
| `-s, --session`   | Resume specific session ID              |
| `--no-acp`        | Disable ACP tools                       |
| `--no-lsp`        | Disable LSP tools                       |

### Auto-Approval for Automation

Set `PRAISON_APPROVAL_MODE=auto` to enable non-interactive tool execution:

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
PRAISON_APPROVAL_MODE=auto praisonai code -w . "Fix the bug"
```

## Prerequisites

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
pip install praisonai praisonaiagents
export OPENAI_API_KEY=your-key-here
```

## AI Code Editor Scenarios

### 1. Implement Code from Specification

Implement a function and run tests until they pass.

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai chat -w . -m gpt-4o-mini "Implement the celsius_to_fahrenheit function in src/converter.py. Formula: F = C * 9/5 + 32. Run pytest to verify."
```

**What happens:**

1. Agent reads the existing file
2. Implements the function with the formula
3. Runs `pytest` to verify
4. If tests fail, fixes and reruns

### 2. Fix Division by Zero Bug

Fix a bug that causes test failures.

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai chat -w . -m gpt-4o-mini "Fix the divide method in calculator.py to raise ValueError('Cannot divide by zero') when b is 0. Run pytest to verify."
```

**What happens:**

1. Agent reads the buggy code
2. Adds the zero-check with proper error
3. Runs tests to confirm the fix
4. Iterates until tests pass

### 3. Implement Missing Function

Implement a function that's currently a stub.

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai chat -w . -m gpt-4o-mini "Implement the mode function in stats.py. Mode returns the most frequent value. Run pytest -k mode to verify."
```

**What happens:**

1. Agent reads the stub function
2. Implements the logic using Counter or similar
3. Runs targeted tests
4. Fixes any edge cases

### 4. Fix Empty List Handling

Add proper error handling for edge cases.

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai chat -w . -m gpt-4o-mini "Fix mean() in stats.py to raise ValueError('Cannot calculate mean of empty list') for empty input. Run pytest -k mean."
```

**What happens:**

1. Agent adds input validation
2. Raises appropriate error
3. Verifies with tests

### 5. Add CLI Command

Extend a CLI with a new command.

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai chat -w . -m gpt-4o-mini "Add a 'version' command to cli.py that prints __version__. Test with: python -m myapp.cli version"
```

**What happens:**

1. Agent reads the CLI code
2. Adds the version subcommand
3. Runs the command to verify output

### 6. Fix Lint Errors

Clean up code style issues.

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai chat -w . -m gpt-4o-mini "Run ruff check . to find lint errors. Fix all errors. Run ruff again to verify."
```

**What happens:**

1. Agent runs `ruff check .`
2. Reads the error output
3. Fixes each issue (unused imports, whitespace, etc.)
4. Reruns ruff until clean

### 7. Implement Temperature Conversion

Implement the reverse conversion function.

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai chat -w . -m gpt-4o-mini "Implement fahrenheit_to_celsius in converter.py. Formula: C = (F - 32) * 5/9. Run pytest -k fahrenheit."
```

**What happens:**

1. Agent implements the function
2. Runs targeted tests
3. Fixes any precision issues

### 8. Fix Median Edge Case

Handle empty list in median function.

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai chat -w . -m gpt-4o-mini "Fix median() in stats.py to raise ValueError('Cannot calculate median of empty list') for empty input. Run pytest -k median."
```

**What happens:**

1. Agent adds the validation check
2. Runs tests to verify
3. Ensures existing tests still pass

### 9. Add Type Hints

Improve code with type annotations.

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai chat -w . -m gpt-4o-mini "Add type hints to all methods in calculator.py. Example: def add(self, a: float, b: float) -> float:"
```

**What happens:**

1. Agent reads the file
2. Adds parameter and return type hints
3. Optionally runs mypy to verify

### 10. Make All Tests Pass

Fix all remaining issues in a project.

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai chat -w . -m gpt-4o-mini "Run pytest to see failing tests. Fix each one by implementing missing functions and fixing bugs. Keep going until ALL tests pass."
```

**What happens:**

1. Agent runs full test suite
2. Identifies all failures
3. Fixes each one systematically
4. Reruns until 100% pass

## Key Flags

| Flag              | Description                               |
| ----------------- | ----------------------------------------- |
| `-w, --workspace` | Set working directory for file operations |
| `-m, --model`     | LLM model to use (default: gpt-4o-mini)   |
| `-c, --continue`  | Continue previous session                 |
| `-f, --file`      | Attach file(s) to prompt                  |
| `-s, --session`   | Resume specific session ID                |

## The Closed-Loop Workflow

PraisonAI implements a **closed-loop workflow** similar to OpenCode:

```
Agent → Edit File → Run Tests → Read Output → Fix → Repeat
```

This means:

* The agent runs commands itself (not you)
* The agent reads test output itself
* The agent iterates until success

## Tips for Best Results

1. **Use Workspace Flag:** Always use `-w .` to enable file editing
2. **Be Specific:** Include file paths and expected behavior
3. **Request Verification:** Ask the agent to run tests after changes
4. **Use Cheap Models:** Start with `gpt-4o-mini` for cost efficiency
5. **Continue Sessions:** Use `--continue` for multi-step tasks

## Troubleshooting

### Agent Not Editing Files

Ensure you're using the workspace flag:

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai chat -w . "your prompt"
```

### Tests Not Running

Make sure pytest is installed in your environment:

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
pip install pytest
```

### API Key Issues

Set your API key:

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
export OPENAI_API_KEY=your-key-here
```

## Related

* [Interactive Runtime](/cli/interactive-runtime) - Core runtime details
* [Session Management](/cli/session) - Session commands
* [Chat Command](/cli/chat) - Chat mode options
