[中文](./README.md) | English

# @easbot/agent

EASBot Agent - Core Runtime for Multi-Agent Collaboration Ecosystem

## Features

- **Multiple Run Modes**: TUI interactive mode, ACP server mode, command-line mode
- **Layered Context System**: Dynamic context building with system prompts, tools, and memories
- **Tool System**: Built-in file operations, search, editing, shell execution tools
- **Memory System**: Integrated Memory, Note, and Codebase knowledge bases
- **Session Management**: Automatic context compression, multi-session support
- **Command System**: Extensible built-in command system
- **Hook Mechanism**: Event-driven plugin system
- **Skill System**: Skill discovery, loading, and lifecycle management
- **MCP Support**: Model Context Protocol integration

## Installation

```bash
# pnpm add @easbot/agent
```

## Quick Start

### TUI Interactive Mode (Default)

```bash
easbot
```

### ACP Server Mode

```bash
easbot acp
```

### HTTP Server Mode

```bash
easbot serve
```

## Usage Examples

### Initialize New Project

```bash
easbot init
```

### File Operations

```typescript
import { File, Ripgrep } from '@easbot/agent';

// Read file
const content = await File.read('/path/to/file');

// Search file content
const results = await Ripgrep.search({
  pattern: 'TODO',
  cwd: '/path/to/project'
});
```

### Context Building

```typescript
import { ContextEngine } from '@easbot/agent';

const contextEngine = new ContextEngine(config);
const context = await contextEngine.build({
  mode: 'coder',
  userMessage: 'Help me refactor this function'
});
```

### Command Registration

```typescript
import { define } from '@easbot/agent';

define('hello', {
  description: 'Print greeting',
  execute: async ({ session }) => {
    await session.send('Hello!');
  }
});
```

### Hook System

```typescript
import { HookRegistry } from '@easbot/agent';

const hooks = new HookRegistry();
hooks.register('before:tool-call', async (tool) => {
  console.log('Tool called:', tool.name);
});
```

## CLI Commands

| Command | Description |
|---------|-------------|
| `easbot` | Start TUI interactive mode |
| `easbot tui` | Start TUI interactive mode |
| `easbot acp` | Start ACP server mode |
| `easbot serve` | Start HTTP server mode |
| `easbot init` | Initialize new project |
| `easbot update` | Check and update |
| `easbot upgrade` | Upgrade to latest version |

### Global Options

| Option | Description |
|--------|-------------|
| `--log-level` | Set log level (DEBUG/INFO/WARN/ERROR) |
| `--print-logs` | Print logs to terminal |
| `--debug` | Enable debug mode |

## Module Structure

```
src/
├── adapter/          # Agent communication adapter
├── api/              # Business logic API layer
├── auth/             # Authentication & authorization
├── bus/              # Event bus
├── cli/              # Command-line interface
├── command/          # Command definition system
├── compaction/       # Session context compression
├── config/           # Configuration loading
├── context/          # Context building engine
├── creation/         # Dynamic tool building
├── env/              # Environment variable management
├── file/             # File operations
├── format/           # Formatting
├── global/           # Global configuration
├── hook/             # Hook plugin system
├── i18n/             # Internationalization
├── ide/              # IDE integration
├── installation/     # Installation management
├── knowledge/        # Knowledge base integration
├── provider/         # AI model providers
├── session/          # Session management
├── skill/            # Skill system
├── tool/             # Tool system
├── server/           # HTTP/WebSocket server
├── pty/              # PTY support
├── pkg/              # Package management
└── shell/            # Shell execution
```

## Configuration

### Environment Variables

```bash
# Model provider configuration
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...

# Log configuration
LOG_LEVEL=INFO

# Proxy configuration
HTTP_PROXY=http://proxy:8080
HTTPS_PROXY=http://proxy:8080
```

### Configuration Files

The `.easbot/` directory in project root contains:

- `easbot.json` - Main configuration file
- `AGENTS.md` - Agent definitions
- `BOOT.md` - Boot configuration
- `SOUL.md` - Values configuration
- `IDENTITY.md` - Identity configuration
- `USER.md` - User configuration
- `CODER.md` - Coder mode configuration

## Development

```bash
# Install dependencies
pnpm install

# Development mode
pnpm dev

# Build
pnpm build

# Type check
pnpm type-check

# Lint
pnpm lint
pnpm lint:fix
```

## Publishing

```bash
# Windows
powershell -ExecutionPolicy Bypass -File scripts/publish.ps1

# Unix/macOS
bash scripts/publish.sh
```

## License

MIT
