check @AGENTS.md
This guide is designed for AI Agents performing automated code reviews on a Flutter library that utilizes flutter_rust_bridge (FRB). The goal is to ensure safety, performance, and seamless DX (Developer Experience) across the FFI boundary.
- Context: Compare the current branch against
main. - Scope: Focus on
lib/src/rust/,rust/src/, and the generatedbridge_generated.dart/bridge_generated.rsfiles (to ensure they match). - Action: Categorize findings and provide a Fix Prompt that the agent can use to auto-remediate the issue.
Priority: π΄ High Focus on memory safety, panic handling, and async deadlocks.
- Rust Panics: Ensure no
unwrap()orexpect()is used in the Rust code. FRB handlesResulttypes gracefully; panics can crash the Dart VM. - Pointer Safety: Check for raw pointer manipulation without
unsafeblocks or proper encapsulation. - Async Overlap: Ensure
DartAbitypes are not being accessed across thread boundaries illegally.
Agent Fix Prompt: "Rewrite this Rust function to return a
Result<T, anyhow::Error>instead of using.unwrap(), and ensure the Dart side handles the potential error."
Priority: π‘ Medium Adherence to the idiomatic styles of both languages.
- Crate Organization: Check if
pub modis exposed correctly for FRB discovery. - Naming Conventions: Ensure Rust uses
snake_caseand Flutter useslowerCamelCase, even for bridge-exposed methods. - Unused Dependencies: Check
Cargo.tomlandpubspec.yamlfor bloat.
Agent Fix Prompt: "Run
cargo clippy --fixanddart fix --applyon the changed files and commit the suggestions."
Priority: π‘ Medium Architectural issues that lead to technical debt.
- Large Data Transfers: Sending massive
Vec<u8>or large strings across the bridge frequently. SuggestStreamorExternalObjectif applicable. - Duplicate Logic: Validations happening in both Dart and Rust. Validation should ideally live in the "Source of Truth" (Rust).
- Generated File Tampering: Manual edits inside
bridge_generated.dart. These will be overwritten.
Agent Fix Prompt: "Move this validation logic from the Dart wrapper into the Rust implementation to ensure a single source of truth and reduce bridge chatter."
Priority: π΅ Low How easy it is for a human to use this library.
- Missing Documentation: Exported Rust functions must have
///doc comments, which FRB carries over to Dart. - Opaque Errors: Ensure
Stringerrors are replaced with specificEnumsfor better pattern matching in Dart.
Agent Fix Prompt: "Generate Dart-compatible doc comments for this Rust function based on its logic and parameters."
Priority: π‘ Medium Impact on the end-user application.
- Blocking the UI Thread: Long-running Rust functions should be
asyncin Rust or called via an isolate-heavy task to prevent frame drops in Flutter. - Initialization Latency: Check if the Rust library initialization (
RustLib.init()) is blocking the app startup unnecessarily.
| Category | Priority | Focus Area | Fix Strategy |
|---|---|---|---|
| Bugs | π΄ High | Panics, Memory, Sync | Wrap in Result, avoid unwrap |
| Smells | π‘ Medium | Data Bloat, Duplication | Use Streams, move logic to Rust |
| Lints | π‘ Medium | Naming, Formatting | clippy, dart format |
| DX | π΅ Low | Docs, Error Enums | Add /// comments, use Enums |
| UX | π‘ Medium | UI Jank, Latency | Move to async Rust functions |
screen-20260304-085017.mp4