npm package: @midewev/midewev-cli
Description: Autonomous coding agent with MCP, LangGraph and Docker - npm wrapper
Author: Midewev Team
Latest version: 0.2.1

# @midewev/midewev-cli

🤖 **Autonomous coding agent** powered by MCP, LangGraph, and Docker - npm wrapper

## Installation

### Step 1: Install the npm package

```bash
# npm
npm install -g @midewev/midewev-cli

# yarn
yarn global add @midewev/midewev-cli

# pnpm
pnpm add -g @midewev/midewev-cli
```

### Step 2: Install the Python backend

The npm package provides a CLI wrapper, but **requires the Python backend** to be installed separately:

```bash
# Clone the repository
git clone https://github.com/LunarBs7/Midewev-CLI.git
cd Midewev-CLI

# Install Poetry (if not already installed)
pip install poetry

# Install Python dependencies
poetry install

# Verify installation
poetry run codeforge --version
```

### Requirements

- **Node.js** 18.0.0 or higher
- **Python** 3.11 or higher
- **Poetry** for Python dependency management
- **Docker** (optional, for sandbox execution)

## Quick Start

### 🎨 Interactive Mode (New!)

Simply run `midewev` without arguments to launch the beautiful interactive interface:

```bash
midewev
```

You'll be greeted with:
- **Stunning ASCII art logo** with welcome message
- **Interactive menu** with arrow key navigation
- **Quick action templates**: Tests, Bug Fixes, Refactoring, Documentation, Code Review
- **Real-time spinners** and colored output
- **Easy-to-use prompts** for all options

**See [INTERFACE.md](./INTERFACE.md) for a complete visual guide!**

### 💻 Command Line Mode

Or use direct commands for automation and scripting:

```bash
# Initialize in your project
midewev init

# Execute a task directly
midewev execute "Add unit tests for authentication module"

# Start interactive chat mode
midewev interactive

# Start MCP server
midewev agent --mcp-server

# View statistics
midewev stats
```

## CLI Commands

### `midewev init`

Initialize Midewev CLI in your project:

```bash
midewev init
midewev init --project-path /path/to/project
midewev init --force  # Overwrite existing configuration
```

### `midewev execute`

Execute a coding task:

```bash
midewev execute --prompt "Task description"
midewev execute --prompt "Fix bug in auth.py" --output-format json
midewev execute --prompt "Refactor user service" --thread-id my-thread
```

**Options:**
- `--prompt` (required): Task description
- `--output-format`: Output format (`markdown` or `json`)
- `--checkpoint`: Enable checkpointing (default: true)
- `--thread-id`: Thread ID for checkpointing

### `midewev interactive`

Start interactive mode:

```bash
midewev interactive
```

Type your requests naturally, type `exit` to quit.

### `midewev agent`

Start the MCP server:

```bash
midewev agent --mcp-server
```

### `midewev stats`

View agent statistics:

```bash
midewev stats
```

### `midewev github`

Start GitHub webhook handler:

```bash
midewev github --port 8080
```

## Programmatic API

You can also use Midewev CLI programmatically from Node.js:

```javascript
import midewev from '@lunarbsdev/midewev-cli';

// Initialize project
await midewev.init('./my-project');

// Execute a task
const result = await midewev.executeTask(
  'Add error handling to user service',
  {
    format: 'json',
    threadId: 'task-123',
    onProgress: (output) => console.log(output)
  }
);

console.log(result.summary);

// Get statistics
const stats = await midewev.getStats();
console.log(`Total tasks: ${stats.tool_calls.total}`);

// Start MCP server
const server = midewev.startMCPServer({ detached: true });
```

### API Reference

#### `execute(command, args, options)`

Execute any Midewev CLI command:

```javascript
const result = await midewev.execute('execute', ['--prompt', 'Task'], {
  env: { LOG_LEVEL: 'DEBUG' },
  onStdout: (data) => console.log(data),
  onStderr: (data) => console.error(data)
});
```

#### `init(projectPath)`

Initialize Midewev in a project:

```javascript
await midewev.init('./my-project');
```

#### `executeTask(prompt, options)`

Execute a task:

```javascript
const result = await midewev.executeTask('Add tests', {
  format: 'json',
  threadId: 'thread-1',
  onProgress: (output) => {}
});
```

#### `getStats()`

Get agent statistics:

```javascript
const stats = await midewev.getStats();
```

#### `startMCPServer(options)`

Start MCP server:

```javascript
const server = midewev.startMCPServer({
  stdio: 'inherit',
  detached: false
});

// Stop server
server.kill();
```

## Configuration

Create a `.env` file in your project:

```env
# Required
OPENAI_API_KEY=sk-...

# Optional
ANTHROPIC_API_KEY=sk-ant-...
GITHUB_TOKEN=ghp_...
DOCKER_ENABLED=true
MIN_TEST_COVERAGE=90
LOG_LEVEL=INFO
```

## Architecture

Midewev CLI consists of:

1. **Node.js Wrapper** (this package) - Provides npm installation and CLI interface
2. **Python Backend** - Core agent with MCP server, LangGraph orchestration, and Docker sandbox
3. **MCP Protocol** - Communication between components

```
┌─────────────────────────────────────┐
│   Node.js CLI (midewev command)     │
└──────────────┬──────────────────────┘
               │ (spawn)
┌──────────────▼──────────────────────┐
│   Python Backend (Poetry/pip)       │
│   - MCP Server (13 tools)           │
│   - LangGraph Orchestrator          │
│   - Docker Sandbox                  │
│   - ChromaDB Memory                 │
└─────────────────────────────────────┘
```

## Features

- 🤖 **Autonomous Agent**: Plan, execute, validate, and report
- 🔧 **13 MCP Tools**: File ops, git, code analysis, testing, web fetch, monitoring
- 🧠 **LangGraph Workflow**: Planner → Executor → Validator → Reporter
- 🔒 **Secure Sandbox**: Docker isolation with resource limits
- 💾 **Vector Memory**: ChromaDB for long-term context
- ✅ **Validation Pipeline**: Static analysis, security scan, style check, tests
- 📊 **Observability**: Comprehensive metrics and logging
- 🔌 **Extensible**: Custom tool registry

## Troubleshooting

### Python not found

```bash
# Install Python 3.11+
# macOS
brew install python@3.11

# Ubuntu/Debian
sudo apt install python3.11

# Windows
# Download from https://www.python.org/downloads/
```

### Poetry installation fails

The installer will fall back to pip automatically. You can also install Poetry manually:

```bash
curl -sSL https://install.python-poetry.org | python3 -
```

### Docker not available

Docker is optional. Disable it in `.env`:

```env
DOCKER_ENABLED=false
```

### Permission denied

On Linux/macOS, you may need to add execute permissions:

```bash
chmod +x $(which midewev)
```

## Development

```bash
# Clone repository
git clone https://github.com/LunarBs7/Midewev-CLI.git
cd Midewev-CLI

# Install npm dependencies
cd npm
npm install

# Link locally
npm link

# Now you can use 'midewev' command globally
midewev --help
```

## Documentation

- [Installation Guide](../docs/installation.md)
- [Configuration Guide](../docs/configuration.md)
- [Architecture Documentation](../docs/architecture.md)
- [GitHub Repository](https://github.com/LunarBs7/Midewev-CLI)

## License

MIT © Midewev Team

## Support

- Issues: https://github.com/LunarBs7/Midewev-CLI/issues
- Discussions: https://github.com/LunarBs7/Midewev-CLI/discussions