refact(AGENTS.md): code rules, tokio (#14911)

* refact(AGENTS.md): code rules, tokio

Signed-off-by: fufesou <linlong1266@gmail.com>

* Update AGENTS.md

* Update AGENTS.md

* Update AGENTS.md

* Update AGENTS.md

---------

Signed-off-by: fufesou <linlong1266@gmail.com>
Co-authored-by: RustDesk <71636191+rustdesk@users.noreply.github.com>
This commit is contained in:
fufesou
2026-04-26 21:25:31 +08:00
committed by GitHub
parent 38f1300717
commit 3a1622e8b5

122
AGENTS.md
View File

@@ -1,47 +1,18 @@
# RustDesk Guide # RustDesk Guide
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. ## Project Layout
## Development Commands
### Build Commands
- `cargo run` - Build and run the desktop application (requires libsciter library)
- `python3 build.py --flutter` - Build Flutter version (desktop)
- `python3 build.py --flutter --release` - Build Flutter version in release mode
- `python3 build.py --hwcodec` - Build with hardware codec support
- `python3 build.py --vram` - Build with VRAM feature (Windows only)
- `cargo build --release` - Build Rust binary in release mode
- `cargo build --features hwcodec` - Build with specific features
### Flutter Mobile Commands
- `cd flutter && flutter build android` - Build Android APK
- `cd flutter && flutter build ios` - Build iOS app
- `cd flutter && flutter run` - Run Flutter app in development mode
- `cd flutter && flutter test` - Run Flutter tests
### Testing
- `cargo test` - Run Rust tests
- `cd flutter && flutter test` - Run Flutter tests
### Platform-Specific Build Scripts
- `flutter/build_android.sh` - Android build script
- `flutter/build_ios.sh` - iOS build script
- `flutter/build_fdroid.sh` - F-Droid build script
## Project Architecture
### Directory Structure ### Directory Structure
- **`src/`** - Main Rust application code * `src/` Rust app
- `src/ui/` - Legacy Sciter UI (deprecated, use Flutter instead) * `src/server/` audio / clipboard / input / video / network
- `src/server/` - Audio/clipboard/input/video services and network connections * `src/platform/` platform-specific code
- `src/client.rs` - Peer connection handling * `src/ui/` legacy Sciter UI (deprecated)
- `src/platform/` - Platform-specific code * `flutter/` current UI
- **`flutter/`** - Flutter UI code for desktop and mobile * `libs/hbb_common/` config / proto / shared utils
- **`libs/`** - Core libraries * `libs/scrap/` screen capture
- `libs/hbb_common/` - Video codec, config, network wrapper, protobuf, file transfer utilities * `libs/enigo/` input control
- `libs/scrap/` - Screen capture functionality * `libs/clipboard/` clipboard
- `libs/enigo/` - Platform-specific keyboard/mouse control * `libs/hbb_common/src/config.rs` all options
- `libs/clipboard/` - Cross-platform clipboard implementation
### Key Components ### Key Components
- **Remote Desktop Protocol**: Custom protocol implemented in `src/rendezvous_mediator.rs` for communicating with rustdesk-server - **Remote Desktop Protocol**: Custom protocol implemented in `src/rendezvous_mediator.rs` for communicating with rustdesk-server
@@ -57,50 +28,35 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
- Mobile: `flutter/lib/mobile/` - Mobile: `flutter/lib/mobile/`
- Shared: `flutter/lib/common/` and `flutter/lib/models/` - Shared: `flutter/lib/common/` and `flutter/lib/models/`
## Important Build Notes
### Dependencies
- Requires vcpkg for C++ dependencies: `libvpx`, `libyuv`, `opus`, `aom`
- Set `VCPKG_ROOT` environment variable
- Download appropriate Sciter library for legacy UI support
### Ignore Patterns
When working with files, ignore these directories:
- `target/` - Rust build artifacts
- `flutter/build/` - Flutter build output
- `flutter/.dart_tool/` - Flutter tooling files
### Cross-Platform Considerations
- Windows builds require additional DLLs and virtual display drivers
- macOS builds need proper signing and notarization for distribution
- Linux builds support multiple package formats (deb, rpm, AppImage)
- Mobile builds require platform-specific toolchains (Android SDK, Xcode)
### Feature Flags
- `hwcodec` - Hardware video encoding/decoding
- `vram` - VRAM optimization (Windows only)
- `flutter` - Enable Flutter UI
- `unix-file-copy-paste` - Unix file clipboard support
- `screencapturekit` - macOS ScreenCaptureKit (macOS only)
### Config
All configurations or options are under `libs/hbb_common/src/config.rs` file, 4 types:
- Settings
- Local
- Display
- Built-in
## Rust Rules ## Rust Rules
- In Rust code, do not introduce `unwrap()` or `expect()`. * Avoid `unwrap()` / `expect()` in production code.
- Allowed exceptions: * Exceptions:
- Tests may use `unwrap()` or `expect()` when it keeps the test focused and readable.
- Lock acquisition may use `unwrap()` only when the locking API makes that the practical option and the failure mode is poison handling rather than normal control flow. * tests;
- Outside those exceptions, propagate errors, handle them explicitly, or use safer fallbacks instead of `unwrap()` and `expect()`. * lock acquisition where failure means poisoning, not normal control flow.
* Otherwise prefer `Result` + `?` or explicit handling.
* Do not ignore errors silently.
* Avoid unnecessary `.clone()`.
* Prefer borrowing when practical.
* Do not add dependencies unless needed.
* Keep code simple and idiomatic.
## Tokio Rules
* Assume a Tokio runtime already exists.
* Never create nested runtimes.
* Never call `Runtime::block_on()` inside Tokio / async code.
* Do not hide runtime creation inside helpers or libraries.
* Do not hold locks across `.await`.
* Prefer `.await`, `tokio::spawn`, channels.
* Use `spawn_blocking` or dedicated threads for blocking work.
* Do not use `std::thread::sleep()` in async code.
## Editing Hygiene ## Editing Hygiene
- Do not introduce formatting-only changes. * Change only what is required.
- Do not run repository-wide formatters or reflow unrelated code unless the * Prefer the smallest valid diff.
user explicitly asks for formatting. * Do not refactor unrelated code.
- Keep diffs limited to semantic changes required for the task. * Do not make formatting-only changes.
* Keep naming/style consistent with nearby code.