mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-15 17:30:13 +08:00
3.6 KiB
3.6 KiB
Why
AstrBot's core runtime is currently implemented in Python. Performance-critical components (orchestration, protocol management, message processing) would benefit from Rust's memory safety, zero-cost abstractions, and native performance. Additionally, exposing core functionality via pyo3 allows seamless Python integration while leveraging Rust's strengths.
What Changes
- Create a new Rust crate
astrbot-coreinrust/directory - Implement core runtime components in Rust:
Orchestrator: Thread-safe runtime coordinator with RwLockProtocolClienttrait: Unified interface for LSP, MCP, ACP, ABP clientsMessageandMessageType: Message serialization with serdeRuntimeStats: Atomic message counting and uptime trackingConfig: TOML-based configuration management
- Provide Python bindings via pyo3 for seamless integration
- Follow strict Rust best practices:
- No
unsafecode - No
.unwrap()- proper error handling - Clippy pedantic compliance
- Full test coverage
- No
Architecture
Python Layer (astrbot/core/)
│
▼ (pyo3 bindings)
┌─────────────────────────────────────────────────┐
│ Rust Core (astrbot-core) │
│ ┌─────────────┐ ┌─────────────┐ ┌──────────┐ │
│ │ Orchestrator│ │ Config │ │ Stats │ │
│ └─────────────┘ └─────────────┘ └──────────┘ │
│ ┌─────────────────────────────────────────────┐│
│ │ Protocol Clients ││
│ │ LSP │ MCP │ ACP │ ABP ││
│ └─────────────────────────────────────────────┘│
└─────────────────────────────────────────────────┘
Capabilities
New Capabilities
astrbot-core: Rust-based high-performance core runtime with pyo3 bindings
Modified Capabilities
- (none - new implementation)
Impact
- New directory:
rust/containing Cargo.toml and src/ - New files:
rust/Cargo.tomlrust/src/lib.rsrust/src/main.rs(CLI binary)rust/src/error.rsrust/src/orchestrator.rsrust/src/message.rsrust/src/stats.rsrust/src/protocol.rsrust/src/config.rsrust/src/python.rs
- Python integration via
astrbot_corePython module - CLI:
astrbot-corebinary with start/stats/health commands
Verification
cargo clippypasses with no warningscargo buildcompiles successfully- Python bindings importable:
from astrbot_core import PythonOrchestrator - CLI functional:
astrbot-core --help
Relationship to OpenSpec Architecture
This change introduces a new implementation pathway that complements (not replaces) the existing Python architecture defined in openspec/SPEC.md. The Rust implementation:
- Provides a reference implementation of the same interfaces (Orchestrator, ProtocolClient, etc.)
- Uses Rust idioms (no anyio - uses native Rust async/tokio)
- Is opt-in via pyo3 feature flag
- Coexists with Python implementation until Rust is production-ready
Status
- Proposal created
- Spec created
- Design created
- Tasks created
- Implementation started