diff --git a/AGENTS.md b/AGENTS.md index e64505af7..d4c227efd 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -60,6 +60,10 @@ the ownership evidence the AI-slop review evaluates (see - For development and bug fixes, follow the [development workflow](CONTRIBUTING.md#development-workflow). +- For Rust backend changes that affect capability ownership or dependency + boundaries, follow [Workspace Crate Architecture](crates/AGENTS.md). + For Tauri commands and desktop integration, also follow + [Backend Architecture Guardrails](src-tauri/AGENTS.md). - For code review and verification of review fixes, follow [REVIEW.md](REVIEW.md). Review is read-only unless changes are authorized; findings do not expand that authorization to unrelated fixes, commits, pushes, or GitHub updates. diff --git a/crates/AGENTS.md b/crates/AGENTS.md index 5436a3d04..fa92c9b93 100644 --- a/crates/AGENTS.md +++ b/crates/AGENTS.md @@ -2,19 +2,28 @@ ## Choose the boundary +- Apply Functional Core, Imperative Shell and Ports and Adapters. Keep domain + types, invariants, parsing, validation, and deterministic transitions + independent of Tauri, concrete OS APIs, and implicit application state. +- Keep use cases, async coordination, cancellation, and timeouts in + framework-independent application modules. Pass dependencies explicitly. + Define ports where an external effect needs a contract. Adapters implement + the contracts owned by their consumers. Keep filesystem, network, IPC, process, + and OS-specific operations in their adapters. - Extract a capability whose invariants can be owned behind a small API. Before creating a crate, identify its owner, what callers supply, and what can be - verified through the crate API. Keep a module when the proposed boundary only - relocates implementation or introduces a pass-through API. -- Keep the dependency direction from the app to the crate. Resolve app paths, - read product settings, start app-owned tasks, and publish UI events in the app. - Pass the values, resources, or callbacks the crate needs. For example, + verified through the crate API. Extract a crate when it provides a useful + dependency, portability, testing, or ownership boundary. Keep a module when + the proposed boundary only relocates implementation or introduces a + pass-through API. +- Keep dependencies pointing toward domain and application contracts. Resolve + app paths and read current settings at the application boundary. Pass in the + required values, resources, or callbacks. For example, [logging](clash-verge-logging/src/lib.rs) owns its pipeline and writers while the app supplies directories and limits through `LoggerConfig`. -- Keep framework and platform dependencies scoped to the capability that needs - them. Runtime-independent logic should be runnable without the desktop app. - A platform adapter can own runtime startup when its resource lifetime requires - it, as [signal](clash-verge-signal/src/lib.rs) does for Linux shutdown. +- Run framework-independent tests without starting the desktop app. A platform + adapter can own runtime startup when its resource lifetime requires it, as + [signal](clash-verge-signal/src/lib.rs) does for Linux shutdown. ## Design the API @@ -31,6 +40,14 @@ workspace lints. Reuse workspace dependencies where available and declare only the features the crate needs. +## Handle fallible input + +- Define crate-owned error types with `thiserror` in a dedicated `error` module. + Re-export public errors through their established import paths. +- Crates may use `unwrap()` or `expect()` for internal invariants. Propagate + errors from required external data and use defaults only when the input + contract gives the default a meaning. + ## Own background work - Give ordered start, replacement, and cleanup to one task owner. Reuse @@ -43,6 +60,20 @@ transaction boundaries and keep the reply path free of locks held by the waiting caller. Cancel only at safe boundaries and own issued effects through completion or explicit reconciliation. +- Distinguish requested effects from completed effects in typed outcomes. + Define how failures, cancellation, and timeouts affect publication, retry, + rollback, or reconciliation. + +## Validate new crates + +- Fuzz the public boundary before tuning. Exercise malformed input, fallback + behavior, and failures that can affect user data. Preserve the corpus and + record the baseline revision and dependency resolution. +- Try at least one targeted performance improvement. Compare the baseline and + candidate on the same workload and build settings. Record stable gains, flat + cases, and regressions, and justify which changes to keep. +- Fuzz the final candidate again. Use the baseline corpus and compare outputs, + diagnostics, and errors with the baseline where behavior should be preserved. Verify the extracted contract through its public API when practical. Use `cargo test -p ` for focused tests and keep native behavior checks at the diff --git a/src-tauri/AGENTS.md b/src-tauri/AGENTS.md index af2554807..5be7ee572 100644 --- a/src-tauri/AGENTS.md +++ b/src-tauri/AGENTS.md @@ -1,10 +1,17 @@ # Backend Architecture Guardrails -Use [Workspace Crate Architecture](../crates/AGENTS.md) when extracting backend -capabilities or changing background task ownership. +Follow [Workspace Crate Architecture](../crates/AGENTS.md) when changing +backend capability boundaries, reusable orchestration, or background task +ownership. +- **Tauri adapter.** Commands validate transport input, delegate to application + use cases, and map results and errors to IPC. Tauri wires dependencies and + owns desktop lifecycle, window and tray integration, and event delivery. + Keep domain validation and reusable orchestration independent of command + handlers and framework state. - **Configuration and effects.** `config` owns source configuration, drafts, and - persistence. The effects layer classifies every Verge patch field, including + persistence coordination. Persistence adapters perform storage and recovery. + The effects layer classifies every Verge patch field, including fields without effects and platform-specific fields, and reconciles requested state in dependency order. Publish rollbackable state after persistence and commit. On failure, preserve already applied runtime effects, independently