mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-16 01:40:15 +08:00
Provides comprehensive guidance for AI assistants working on AstrBot: - Project overview and architecture - Development setup and commands - Code style rules (type hints, paths, formatting) - Environment variable conventions - Common development patterns - Git and PR guidelines
4.0 KiB
4.0 KiB
name, description
| name | description |
|---|---|
| astrbot-dev-guide | Guide for AI assistants developing AstrBot - project conventions, code style, and common patterns |
AstrBot Developer Guide
This skill provides guidance for AI assistants working on AstrBot development.
Project Overview
AstrBot is an open-source, all-in-one Agentic chat assistant supporting multiple IM platforms (QQ, Telegram, Discord, Lark, DingTalk, Slack, etc.) and LLM providers.
- Main entry:
astrbot/__main__.pyor CLIastrbot run - CLI commands:
astrbot/cli/commands/ - Core modules:
astrbot/core/ - Platform adapters:
astrbot/core/platform/sources/ - Star plugins:
astrbot/builtin_stars/ - Dashboard:
dashboard/(Vue.js)
Quick Start Commands
# Install
uv tool install -e . --force
# Initialize
astrbot init
# Run
astrbot run
# Backend only (no WebUI)
astrbot run --backend-only
# Frontend
cd dashboard && bun dev
# Tests
uv sync --group dev && uv run pytest --cov=astrbot tests/
Code Style Rules
Type Hints (Required)
Use Python 3.12+ syntax:
list[str]notList[str]int | NonenotOptional[int]- Avoid
Anywhen possible
Path Handling
Always use pathlib.Path:
from pathlib import Path
from astrbot.core.utils.astrbot_path import get_astrbot_data_path
Formatting
Run before every commit:
ruff format .
ruff check .
Comments
Write all comments in English.
Environment Variables
When adding new environment variables:
- Prefix with
ASTRBOT_(e.g.,ASTRBOT_ENABLE_FEATURE) - Add to
.env.examplewith description - Update
astrbot/cli/commands/cmd_run.py:- Add to module docstring under "Environment Variables Used in Project"
- Add to
keys_to_printlist for debug output
Core Paths Utility
from astrbot.core.utils.astrbot_path import (
get_astrbot_root, # AstrBot root directory
get_astrbot_data_path, # Data directory
get_astrbot_config_path, # Config directory
get_astrbot_plugin_path, # Plugin directory
get_astrbot_temp_path, # Temp directory
get_astrbot_skills_path, # Skills directory
)
Architecture Patterns
Adding a Platform Adapter
- Create in
astrbot/core/platform/sources/ - Extend
Platformbase class - Use
@register_platform_adapterdecorator - Implement:
run(),convert_message(),meta()
Adding a CLI Command
- Create in
astrbot/cli/commands/ - Use
@click.command() - Update
astrbot/cli/__main__.pyto add command
Adding a Star Handler
- Create in
astrbot/builtin_stars/or as plugin - Extend
Starclass - Use decorators:
@star.on_command(),@star.on_schedule(), etc.
Testing
- Test location:
tests/directory - Framework:
pytestwithpytest-asyncio - Run:
uv run pytest --cov=astrbot tests/
Git Conventions
Commit Messages (Conventional Commits)
feat: add new feature
fix: resolve bug
docs: update documentation
refactor: restructure code
test: add tests
chore: maintenance
PR Guidelines
- Title: conventional commit format in English
- Target branch:
dev - Keep changes atomic and focused
Important Guidelines
- No report files - Do not add
xxx_SUMMARY.md - Componentization - Keep WebUI code clean, avoid duplication
- Backward compatibility - Add deprecation warnings when changing APIs
- CLI help - Run
astrbot help --allto see all commands
Directory Structure
astrbot/
├── __main__.py # Main entry point
├── __init__.py # Package init, exports
├── cli/ # CLI commands
│ └── commands/ # Individual commands
├── core/ # Core functionality
│ ├── agent/ # Agent execution
│ ├── platform/ # Platform adapters
│ ├── pipeline/ # Message processing
│ ├── star/ # Plugin system
│ └── config/ # Configuration
├── builtin_stars/ # Built-in plugins
├── dashboard/ # Vue.js frontend
└── utils/ # Utilities