Files
clash-verge-rev/crates/AGENTS.md
T
Tunglies 929bb6a0a1 refactor(backend): share single-owner drivers for background tasks (#8759)
* docs(backend): define background task ownership

* refactor(backend): give background operations single task owners

* test(backend): remove actor migration regression cases

* docs(changelog): drop backend actor migration entry

* refactor(backend): extract workspace task drivers

* fix(timer): omit profile identifier from panic log

* docs(backend): define workspace crate boundaries

* refactor(lightweight): use the task countdown driver

* refactor(lightweight): name countdown callbacks

* refactor(task): simplify driver startup and coalescing requests

* refactor(core): bind service handoff to the sidecar generation

* refactor(tun): coalesce background run state reconciliation

* refactor(core): own sidecar exit resources in one session

* refactor(core): remove automatic Windows service handoff

* refactor(task): simplify coalescing job signals

* refactor(runstate): keep operation status with service state

* refactor(dns): coalesce background override synchronization

* refactor(sysproxy): own the local guard under its operation lock

* fix(tray): read menu settings at publication

* fix(dns): retain script lock across caller cancellation

* refactor(profiles): own selected node restoration in one task

* refactor(timer): own subscription schedules in the scheduler

* test(timer): remove the added application test

* fix(service): renew provider sync retry budget on refresh
2026-11-29 00:42:52 +00:00

52 lines
2.9 KiB
Markdown

# Workspace Crate Architecture
## Choose the boundary
- 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,
[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.
## Design the API
- Start with concrete types for data and outcomes. Use a trait when methods must
cooperate under one contract, a closure for one supplied operation, and
`impl Future` when the caller owns scheduling. Add type parameters and bounds
where the contract needs them. Use dynamic dispatch when the API needs to hold
heterogeneous implementations, as [draft](clash-verge-draft/src/lib.rs) does
for the layers claimed by `DraftTransaction`.
- Keep state and its invariants with one owner. Expose snapshots, typed
operations, or guards. Draft owns claim, commit, and rollback of its in-memory
layers. The caller owns persistence and the recovery of external effects.
- Name product workspace libraries with the `clash-verge-` prefix and inherit
workspace lints. Reuse workspace dependencies where available and declare
only the features the crate needs.
## Own background work
- Give ordered start, replacement, and cleanup to one task owner. Reuse
[`clash-verge-task`](clash-verge-task/src/lib.rs) for coalescing scheduled jobs
and replaceable sessions. Keep domain policy, execution callbacks, and runtime
startup at the call site. Select a driver whose delivery guarantees match the
caller's needs.
- Use typed inputs. Coalesce only when intermediate requests may be skipped.
Reply with the actual outcome when a caller waits for completion. Preserve
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.
Verify the extracted contract through its public API when practical. Use
`cargo test -p <crate>` for focused tests and keep native behavior checks at the
app boundary. For timing, prefer Tokio's paused clock for task drivers or a
small clock interface where time is an input, as in
[`clash-verge-limiter`](clash-verge-limiter/src/lib.rs).