npm package: @lineuman/langchain-deepseek-cli
Description: An agent CLI similar to Claude Code using LangChain and DeepSeek
Author: lineuman123@gmail.com
Latest version: 1.0.0

# Agent CLI - LangChain + DeepSeek

A powerful AI agent CLI similar to Claude Code, built with LangChain.js and DeepSeek. This CLI provides an interactive agent that can help with file operations, code tasks, and system commands.

## Features

- > **Intelligent Agent**: Powered by DeepSeek's LLM with ReAct reasoning pattern
- =� **File Operations**: Read, write, edit, and list files
- = **Search Tools**: Glob pattern matching and grep text search
- =� **Command Execution**: Execute bash commands safely
- =� **Interactive Chat**: Real-time conversation with the agent
- <� **Beautiful CLI**: Colored output and loading indicators

## Installation

1. Clone the repository:
```bash
git clone <repository-url>
cd langchain-deepseek-cli
```

2. Install dependencies:
```bash
npm install
```

3. Set up environment variables:
```bash
cp .env.example .env
```

4. Edit `.env` and add your DeepSeek API key:
```env
DEEPSEEK_API_KEY=your_api_key_here
DEEPSEEK_MODEL=deepseek-chat
DEEPSEEK_TEMPERATURE=0.7
MAX_ITERATIONS=10
```

## Getting Your DeepSeek API Key

1. Visit [DeepSeek Platform](https://platform.deepseek.com/)
2. Sign up or log in to your account
3. Navigate to API Keys section
4. Create a new API key
5. Copy the key to your `.env` file

## Usage

### Development Mode

Run in development mode with auto-reload:
```bash
npm run dev
```

### Build and Run

Build the TypeScript code:
```bash
npm run build
```

Run the built application:
```bash
npm start
```

### Interactive Chat Mode

Start an interactive chat session (default):
```bash
npm run dev
# or
npm run dev chat
```

Example conversation:
```
You: List all TypeScript files in the current directory
Assistant: [Uses glob tool to find *.ts files]

You: Read the package.json file
Assistant: [Uses read_file tool and displays content]

You: Create a new file called hello.txt with content "Hello World"
Assistant: [Uses write_file tool]
```

### Single Command Mode

Run a single prompt and exit:
```bash
npm run dev run "List all files in the src directory"
```

### Available Commands in Chat

- `help` - Show available commands and tools
- `clear` - Clear conversation history
- `exit` or `quit` - Exit the CLI

## Available Tools

The agent has access to the following tools:

### File Operations
- **read_file** - Read the contents of any file
- **write_file** - Write or create files
- **edit_file** - Edit existing files by replacing text
- **list_files** - List files in a directory

### Search
- **glob** - Search for files by pattern (e.g., `*.js`, `**/*.ts`)
- **grep** - Search for text within files

### Execution
- **bash** - Execute bash commands (git, npm, etc.)

## Example Use Cases

### 1. File Analysis
```
You: Find all JavaScript files and count how many there are
```

### 2. Code Modification
```
You: Read index.ts and add a new import statement for 'chalk'
```

### 3. Project Setup
```
You: Create a new React component file called Button.tsx with basic boilerplate
```

### 4. Git Operations
```
You: Show me the current git status and recent commits
```

### 5. Search and Replace
```
You: Find all files containing 'TODO' and list them
```

## Configuration

Edit `.env` to customize:

- `DEEPSEEK_API_KEY` - Your DeepSeek API key (required)
- `DEEPSEEK_MODEL` - Model to use (default: `deepseek-chat`)
- `DEEPSEEK_TEMPERATURE` - Creativity level 0-1 (default: `0.7`)
- `MAX_ITERATIONS` - Max agent reasoning steps (default: `10`)

## Architecture

```
src/
 agent/          # Agent setup with ReAct pattern
 cli/            # Interactive CLI interface
 config/         # Configuration management
 tools/          # Tool implementations
    file-tools.ts    # File operations
    bash-tool.ts     # Bash execution
    search-tools.ts  # Glob and grep
 index.ts        # Main entry point
```

## Technologies

- **LangChain.js** - Agent framework
- **@langchain/deepseek** - DeepSeek LLM integration
- **TypeScript** - Type-safe development
- **Commander** - CLI command parsing
- **Chalk** - Terminal colors
- **Ora** - Loading spinners
- **Zod** - Schema validation

## Troubleshooting

### API Key Error
```
Error: DEEPSEEK_API_KEY is not set
```
Solution: Create a `.env` file and add your DeepSeek API key.

### Module Not Found
```
Error: Cannot find module 'X'
```
Solution: Run `npm install` to install all dependencies.

### Permission Denied (Bash Tool)
Solution: Some commands may require elevated permissions. Run with appropriate access rights.

## License

MIT

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.