|
| 1 | +# CLI Tester |
| 2 | + |
| 3 | +The CLI Tester is a tool designed specifically for plugin developers to build a fast feedback loop, supporting the "Vibe Coding" development mode. |
| 4 | + |
| 5 | +Traditional plugin development requires: writing code → restarting the bot → logging into an IM platform → sending test messages → checking results → modifying code... This process has a long feedback cycle and can be distracting. |
| 6 | + |
| 7 | +CLI Tester allows you to: **write code → test via command line → see results immediately → modify code...** |
| 8 | + |
| 9 | +## Core Values |
| 10 | + |
| 11 | +- ⚡ **Instant Feedback**: Test directly from the command line without logging into IM platforms. |
| 12 | +- 🔄 **Fast Iteration**: Shorten the feedback loop and improve development efficiency. |
| 13 | +- 🎯 **Focused Development**: Focus on plugin logic rather than platform interaction. |
| 14 | +- 🧪 **Independent Testing**: Isolated sessions for each request, supporting concurrent testing. |
| 15 | + |
| 16 | +## Enabling CLI Tester |
| 17 | + |
| 18 | +Enable the CLI platform in the management panel, or add the configuration in `data/config/platforms.json`: |
| 19 | + |
| 20 | +```json |
| 21 | +{ |
| 22 | + "type": "cli", |
| 23 | + "enable": true, |
| 24 | + "mode": "socket", |
| 25 | + "socket_path": "/tmp/astrbot.sock" |
| 26 | +} |
| 27 | +``` |
| 28 | + |
| 29 | +> **Note**: CLI Tester is disabled by default. It is recommended to enable it only in development environments. |
| 30 | +
|
| 31 | +## Usage |
| 32 | + |
| 33 | +### 1. Basic Testing |
| 34 | + |
| 35 | +You can use the built-in `astrbot-cli` tool to send messages. |
| 36 | + |
| 37 | +```bash |
| 38 | +# Test inside the container |
| 39 | +docker exec astrbot python3 /AstrBot/astrbot-cli "Hello" |
| 40 | + |
| 41 | +# Test plugin commands |
| 42 | +docker exec astrbot python3 /AstrBot/astrbot-cli "/help" |
| 43 | + |
| 44 | +# JSON format output (includes rich media like images) |
| 45 | +docker exec astrbot python3 /AstrBot/astrbot-cli -j "/time" |
| 46 | +``` |
| 47 | + |
| 48 | +### 2. Create a Global Command (Optional) |
| 49 | + |
| 50 | +For convenience, you can create a wrapper script on the host machine: |
| 51 | + |
| 52 | +```bash |
| 53 | +# Create wrapper script on host |
| 54 | +cat > /usr/local/bin/astrbot-cli << 'EOF' |
| 55 | +#!/bin/bash |
| 56 | +docker exec astrbot python3 /AstrBot/astrbot-cli "$@" |
| 57 | +EOF |
| 58 | + |
| 59 | +chmod +x /usr/local/bin/astrbot-cli |
| 60 | + |
| 61 | +# Use directly |
| 62 | +astrbot-cli "Test message" |
| 63 | +``` |
| 64 | + |
| 65 | +## Core Features |
| 66 | + |
| 67 | +1. **Unix Socket Mode**: Provides synchronous request-response via `/tmp/astrbot.sock`. |
| 68 | +2. **Session Isolation**: Supports concurrent testing; each request can have an independent session (requires `use_isolated_sessions` enabled in config). |
| 69 | +3. **Rich Media Support**: Automatically handles rich media content like images (Base64 encoded). |
| 70 | +4. **Whitelist Exemption**: The CLI platform automatically bypasses whitelist checks for easier local debugging. |
| 71 | + |
| 72 | +## Technical Characteristics |
| 73 | + |
| 74 | +- 📦 **Zero External Dependencies**: Uses only the Python standard library. |
| 75 | +- 💾 **Lightweight**: Total size is about 35KB. |
| 76 | +- 🏗️ **Unix Philosophy**: Atomic modules, explicit I/O, and pipeline orchestration. |
0 commit comments