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.
3.1 KiB
3.1 KiB
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 testscargo install --path .— install to~/.cargo/binsystemctl --user restart btle-proximity— restart the dev servicejournalctl --user -u btle-proximity -f— follow the daemon logRUST_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.lockis committed — keep it in sync. - The dev machine has no rustup; distro
rustc/cargoonly.
Code map
src/main.rs— CLI entry, config loading, sd-notify readinesssrc/config.rs— TOML config, defaults, validationsrc/policy.rs— presence state machine: pure logic, unit-tested, no I/O; timing/Duty decisions live heresrc/scanner/bluez.rs— BlueZ D-Bus integration: discovery duty toggling, PropertiesChanged/InterfacesAdded handling, pre-lock connect probesrc/locker.rs— screen locking (logind orlock_command)systemd/btle-proximity.service— user service,Type=notifyconfig.toml.example— shipped config sample with tuning guidance
Domain gotchas (learned the hard way — see docs/HANDOFF.md)
- BlueZ dedupes identical RSSI values:
PropertiesChangedis 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_secsmust outlast those pauses; during a pause the phone is both undetectable and unconnectable. DuplicateData = truein the discovery filter does not bypass the RSSI dedupe at theDevice1property level.Device1.Connectis 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.rswith unit tests;bluez.rsis the I/O shell around it. Keep the split. - Commits: short imperative subject; body explains the why.