Add AGENTS.md and handoff notes for agents
Distill the session findings (BlueZ RSSI dedupe, beacon pauses, MSRV pinning, scan-only decision) so future agents and humans don't have to rediscover them. AGENTS.md carries the rules, docs/HANDOFF.md the history and open threads.
This commit is contained in:
1 parent
a5b798dceb
commit
aef8e2af17
2 files changed
+134
No files matched your search
@@ -0,0 +1,66 @@
|
||||
# AGENTS.md
|
||||
|
||||
Guidance for AI coding agents working in this repository. Read this before
|
||||
changing code; see `docs/HANDOFF.md` for the history behind the gotchas.
|
||||
|
||||
## What this is
|
||||
|
||||
`btle-proximity` is a Linux daemon (Rust, tokio, zbus) that locks the
|
||||
desktop session when a paired phone leaves BLE range. It watches
|
||||
advertisement updates from BlueZ over D-Bus, runs a small state machine
|
||||
(Bootstrapping → Present → Suspect → Locked) and locks via
|
||||
`loginctl lock-session`. There is no unlock: the phone returning only
|
||||
rearms monitoring. See README.md for the full design.
|
||||
|
||||
## Commands
|
||||
|
||||
- `cargo build` / `cargo test` — build; run the policy state-machine tests
|
||||
- `cargo install --path .` — install to `~/.cargo/bin`
|
||||
- `systemctl --user restart btle-proximity` — restart the dev service
|
||||
- `journalctl --user -u btle-proximity -f` — follow the daemon log
|
||||
- `RUST_LOG=debug btle-proximity --dry-run` — run manually, no locking
|
||||
|
||||
## Toolchain constraints
|
||||
|
||||
- MSRV is `rust-version = "1.85"` in Cargo.toml (Ubuntu 24.04's rustc).
|
||||
The resolver is MSRV-aware; do not bump dependencies past what 1.85
|
||||
supports. `Cargo.lock` is committed — keep it in sync.
|
||||
- The dev machine has no rustup; distro `rustc`/`cargo` only.
|
||||
|
||||
## Code map
|
||||
|
||||
- `src/main.rs` — CLI entry, config loading, sd-notify readiness
|
||||
- `src/config.rs` — TOML config, defaults, validation
|
||||
- `src/policy.rs` — presence state machine: pure logic, unit-tested,
|
||||
no I/O; timing/Duty decisions live here
|
||||
- `src/scanner/bluez.rs` — BlueZ D-Bus integration: discovery duty
|
||||
toggling, PropertiesChanged/InterfacesAdded handling, pre-lock connect
|
||||
probe
|
||||
- `src/locker.rs` — screen locking (logind or `lock_command`)
|
||||
- `systemd/btle-proximity.service` — user service, `Type=notify`
|
||||
- `config.toml.example` — shipped config sample with tuning guidance
|
||||
|
||||
## Domain gotchas (learned the hard way — see docs/HANDOFF.md)
|
||||
|
||||
- **BlueZ dedupes identical RSSI values**: `PropertiesChanged` is not
|
||||
emitted when RSSI repeats, so a stationary phone goes silent in the
|
||||
event stream. Silence is NOT evidence of absence. The duty escalation
|
||||
in Present and the 10s connect probe before locking exist because of
|
||||
this; do not "simplify" them away.
|
||||
- **Beacon apps pause advertising** while the phone sits still (doze,
|
||||
battery optimization). `missing_after_secs` must outlast those pauses;
|
||||
during a pause the phone is both undetectable and unconnectable.
|
||||
- `DuplicateData = true` in the discovery filter does not bypass the
|
||||
RSSI dedupe at the `Device1` property level.
|
||||
- `Device1.Connect` is the only reliable "is it actually there" oracle,
|
||||
and it works whenever the phone advertises. Scan-based checks cannot
|
||||
distinguish "silent but present" from "gone".
|
||||
- The long-term fix for all of the above is the AdvertisementMonitor
|
||||
roadmap (controller-offloaded patterns, BlueZ ≥ 5.65 + Experimental).
|
||||
|
||||
## Conventions
|
||||
|
||||
- Comments explain *why* (BlueZ quirks, design rationale), not *what*.
|
||||
- State-machine changes belong in `policy.rs` with unit tests;
|
||||
`bluez.rs` is the I/O shell around it. Keep the split.
|
||||
- Commits: short imperative subject; body explains the why.
|
||||
Reference in new issue
Block a user