Commit Graph

63 Commits

Author SHA1 Message Date
rUv 69e61e3437
docs(changelog): record this cycle's behavior-changing fixes (#932)
Per the CLAUDE.md pre-merge checklist (item 5, "Add entry under
[Unreleased]"), several recently-merged PRs landed without CHANGELOG
entries. Backfilling the user/operator-facing ones — most importantly the
MAT triage safety fix:

- #926 (Security/safety): survivor with a heartbeat never triaged Deceased
- #918: per-node HA devices report each node's own presence/motion
- #919: actionable --model load diagnostic (refs #894)
- #920: --export-rvf no longer silently produces a placeholder model
- #929 (Security): bearer scheme matched case-insensitively (RFC 6750)

CI-internal fixes (#925 rust-cache, #930 SAST) are intentionally omitted —
they don't change product behavior. Docs-only.
2026-06-03 11:47:07 +02:00
rUv 91b0e625bd
docs(#882): complete the "100% presence" retraction across all docs (#916)
The v1 "100% presence accuracy" headline was already retracted in the
README / user-guide intro / proof-of-capabilities — but 6 secondary
spots still flatly claimed "100% accuracy, never false alarms", which
made proof-of-capabilities.md's "replaced everywhere" assertion untrue.

Completed the retraction in-place with the honest label-free metric
(82.3% held-out temporal-triplet; v1 was a single-class recording where
a constant "yes" scores ~99.98%):

- docs/readme-details.md — 2 benchmark tables + the pre-trained-model row
- docs/user-guide.md — capability table, model-file comment, applications list
- CHANGELOG.md — annotated the historical entry in-place (kept as public
  record per built-in-public ethos, not rewritten)

Verified: no remaining flat "100% presence/accuracy" claim lacks a
retraction marker; proof-of-capabilities.md "replaced everywhere" is now
accurate.
2026-06-02 18:50:39 +02:00
ruv 4c87f04919 Merge remote-tracking branch 'origin/main' into fix/894-occupancy-cap
# Conflicts:
#	CHANGELOG.md
2026-06-02 10:52:53 +02:00
ruv f34b94aa46 fix(occupancy): bound eigenvalue person-count to single-link max — #894
field_bridge::occupancy_or_fallback returned FieldModel::estimate_occupancy
unbounded (internal ceiling 10), while the perturbation fallback below it
and score_to_person_count both cap at 3 ("1-3 for single ESP32"). On noisy
or under-calibrated CSI the eigenvalue count inflated → "10 persons when 1
present" (#894, seen when --model fails to load → heuristic mode). Bound the
eigenvalue path to a shared MAX_SINGLE_LINK_OCCUPANCY const (3) so every
single-link estimator agrees. Genuine higher counts come from the
multistatic fusion path. Build clean, field_bridge tests pass.
2026-06-02 10:40:24 +02:00
ruv 9ddcf0c9fc fix(mqtt): one HA device per node — closes #898
After the #872 MQTT wiring, the JSON->VitalsSnapshot bridge hard-coded a
single node_id (the MQTT client id) and the publisher used one
OwnedDiscoveryBuilder, so every physical node collapsed into a single
Home-Assistant device (identifiers:["wifi_densepose_wifi-densepose-1"]),
contradicting the one-device-per-node docs.

- Bridge (main.rs): emit one VitalsSnapshot per node in the sensing
  update's nodes[] (each carries its own node_id + RSSI; shared aggregate
  presence/vitals), falling back to a single aggregate snapshot when
  there is no per-node data (wifi/simulate sources).
- Publisher (publisher.rs): add OwnedDiscoveryBuilder::for_node(), and
  publish discovery + availability lazily on first sight of each node_id,
  routing state to per-node topics. Heartbeat/refresh/offline-LWT iterate
  all known nodes. Result: N distinct HA devices, one per node.

3 new unit tests (distinct nodes -> distinct wifi_densepose_<node>
identifiers); full MQTT suite 71 passed, example builds.
2026-06-02 09:43:28 +02:00
ruv 138449a378 Merge remote-tracking branch 'origin/main' into feat/adr-149-aether-arena
# Conflicts:
#	CHANGELOG.md
2026-05-31 10:36:12 -04:00
ruv 4007db5d13 fix(sensing-server): fix CSI per-node count clamp — #803 (part 2)
The pure-CSI per-node path clamped its own occupancy estimate before the
aggregator could read it. estimate_persons_from_correlation (DynamicMinCut)
returns 0-3, but it was mapped to a score via `corr_persons / 3.0`, putting
2 people at 0.667 — just under the 0.70 up-threshold of
score_to_person_count — so the per-node count never climbed past 1, leaving
node_max stuck at 1 for CSI-only nodes even when the min-cut cleanly
separated two people.

Replace the lossy /3.0 mapping with a threshold-aligned corr_persons_to_score
(1->0.40, 2->0.74, 3->0.96) whose steady state round-trips back to the same
count through the EMA + hysteresis bands, while still gating transient noise.

A convergence test replays the exact CSI-loop EMA and asserts min-cut=2 now
reports 2 / 3 reports 3 / 1 reports 1, plus a regression test documenting
that the old /3.0 mapping pinned two people to 1.

Full suite: 586 passed, 0 failed.

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-05-31 10:09:58 -04:00
ruv a933fc7732 fix(sensing-server): surface count-aware per-node estimates — #803
Person count was pinned to 1 because the aggregate was derived from
`smoothed_person_score`, an EMA-smoothed *activity* score (amplitude
variance / motion / spectral energy) that saturates near a single
occupant and cannot discriminate count. The count-aware per-node
estimates the ESP32 paths already compute (firmware n_persons, mincut
corr_persons) were stored in NodeState::prev_person_count then discarded
by the aggregator — the same dead-wiring class as #872.

Add `aggregate_person_count(activity_count, node_states)` = max(activity,
node_max) and use it at both ESP32 aggregation sites (edge-vitals + CSI
loop, Some + fallback arms). It can only raise the count when a node
positively reports more occupants, so the lone-occupant case is provably
never inflated (regression-guarded).

5 new unit tests + full suite: 582 passed, 0 failed.

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-05-31 10:00:56 -04:00
ruv 415eaea849 docs(changelog): #872 MQTT publisher wiring fix
Co-Authored-By: claude-flow <ruv@ruv.net>
2026-05-31 09:40:11 -04:00
ruv 403841b19e docs(changelog): reflect cog producer, cross-language test, Windows fixes
Update the Unreleased entry: calibration service is now complete across both
model paths (transformer .npz + cog safetensors via cog_calibrate.py) with
cross-language Python->Rust integration test; add the Windows cross-platform
build fixes (worldmodel cfg(unix), bfld CRLF) — 2682 workspace tests green/0
fail on Windows.

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-05-31 05:38:38 -04:00
ruv 17ff2433bc docs(changelog): WiFi-CSI efficiency frontier + per-room calibration service
Document the beyond-SOTA efficiency frontier (75K params beats SOTA, int4
edge model 20KB@74%), few-shot calibration resolving generalization
(cross-env 10->73%), and the calibration service (Python ref + Rust
cog-pose --adapter integration).

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-05-31 02:38:07 -04:00
rUv 0d3d835bf8
feat(swarm): add ruview-swarm crate — drone swarm control system (ADR-148) (#862)
* feat(swarm): add wifi-densepose-swarm crate implementing ADR-148 drone swarm control system

New crate `wifi-densepose-swarm` with hierarchical-mesh swarm topology,
Raft consensus, MAPPO MARL, CSI sensing integration, and ITAR-gated
coordination features. Closes 3 of 7 milestones (M1, M2, M5) with 5/5
ADR-148 SOTA performance targets met.

## Modules (45 source files, 14 modules)

- types: NodeId, DroneState, Position3D, SwarmTask, SwarmError, FailSafeState
- topology: Raft consensus (leader election, log replication, quorum), Gossip, Mesh
- formation: VirtualStructure, LeaderFollower, Reynolds flocking (itar-gated)
- planning: RRT-APF hybrid planner, 3-phase coverage, Bayesian grid, pheromone
- allocation: Auction + FNN bid scorer (itar-gated)
- sensing: CsiPayloadPipeline (Live/Synthetic/Replay), MultiViewFusion, OccWorldBridge
- marl: MAPPO actor (3-layer MLP), LocalObservation (64-dim), RewardCalculator, PPO loop
- security: MAVLink v2 HMAC-SHA256, UWB anti-spoofing, geofence, Remote ID, FHSS
- failsafe: 10-state onboard machine, GCS-independent safety transitions
- config: TOML SwarmConfig with SAR/inspection/agriculture/mine/demo/wi2sar_reference
- demo: SyntheticCsiGenerator, DemoScenario (SAR/open-field/mine)
- integration: FlightController trait, MAVLink dialect (50000-50005), SwarmSim
- orchestrator: SwarmOrchestrator wiring all subsystems end-to-end
- bench_support: Criterion fixture generators

## ITAR compliance

Swarming coordination features gated behind `itar-unrestricted` feature
per USML Category VIII(h)(12). Default build compiles clean stubs.

## Benchmark results (criterion, release mode)

- MARL actor inference: 3.3 µs (target ≤ 5 ms — 1,516× headroom)
- RRT-APF planning (100 iter): 0.043 ms (target < 300 ms — 6,946× headroom)
- MultiView CSI fusion (3 UAVs): 58.5 ns (target < 10 ms — 171,000× headroom)
- 3-view localization: 1.732 m (target ≤ 2 m — beats Wi2SAR SOTA)
- 4-drone SAR coverage (400×400 m): 223 s (target ≤ 240 s — PASS)

## Tests

- --no-default-features: 73/73 passing
- --features itar-unrestricted: 85/85 passing

Closes #861

Co-Authored-By: claude-flow <ruv@ruv.net>

* refactor(swarm): rename wifi-densepose-swarm → ruview-swarm

The swarm control system is a RuView-level capability (drone coordination,
Raft consensus, MARL) that operates above the wifi-densepose sensing layer
rather than being a sub-component of it. Rename aligns with the project
identity and separates coordination infrastructure from sensing modules.

Co-Authored-By: claude-flow <ruv@ruv.net>

* fix(swarm): resolve all clippy warnings + add MARL convergence test

- planning/probability_grid: map_or(true,…) → is_none_or (clippy::unnecessary_map_or)
- planning/pheromone: &mut Vec<T> → &mut [T] on evaporate+deposit (clippy::ptr_arg)
- marl/observation: fix doc lazy-continuation warning on TOTAL line
- marl/trainer: manual Default impl → #[derive(Default)] + #[default] on Demo variant

Also adds test_marl_convergence_improves_mean_return: fills 64-transition
ReplayBuffer with mixed rewards (steps 0-31: negative, 32-63: positive),
runs ppo_update, asserts mean_return is finite and non-zero.

Result: 0 clippy warnings · 74/74 tests (default) · 86/86 (itar-unrestricted)

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(swarm): integrate Ruflo AI-agent capabilities into ruview-swarm

Adds a feature-gated Ruflo integration layer connecting ruview-swarm to the
claude-flow daemon's AgentDB, AIDefence, and SONA intelligence subsystems.
Default build is unaffected (all paths behind `Option<Box<dyn RufloBackend>>`).

## New module: src/ruflo/

- backend.rs: RufloBackend trait (9 async methods) + RufloError, MissionMemoryEntry,
  PatternEntry, MavlinkScanResult types (always compiled)
- mock_backend.rs: MockRufloBackend in-memory impl for testing (always compiled, 5 tests)
- http_backend.rs: HttpRufloBackend — JSON-RPC 2.0 → claude-flow daemon localhost:3000
  (gated behind `ruflo` feature, requires reqwest)
- mission_summary.rs: MissionSummary serializer with pattern description + confidence
  scoring from victim recall, coverage %, collision penalty (always compiled, 3 tests)

## 4 capability areas

1. MissionMemory   → memory_store / memory_search       (cross-mission victim memory)
2. PatternLearner  → agentdb_pattern-store / -search     (HNSW SONA trajectory patterns)
3. MavlinkDefence  → aidefence_is_safe / aidefence_scan  (scan MAVLink before accepting)
4. IntelligenceHooks → trajectory-start/step/end          (SONA learning loop)

## SwarmOrchestrator integration

- with_ruflo(backend): builder to attach a backend
- start_trajectory(task) / finish_trajectory(success, key): SONA mission lifecycle
- receive_peer_detection_checked(): AIDefence scan before accepting peer detections

## Cargo feature

`ruflo = ["dep:reqwest", "dep:serde_json"]` — optional, not in default

## Tests

- --no-default-features: 82/82 pass (8 new ruflo tests)
- --features ruflo,itar-unrestricted: 94/94 pass

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(swarm): M7 mission profiles with victim confirmation reports + pre-merge docs

Adds end-to-end mission runners producing structured MissionReport output,
and updates project docs (CHANGELOG, README, CLAUDE.md) per pre-merge checklist.

## M7 Mission Profiles (integration/mission_report.rs + swarm_sim.rs)

- MissionReport / VictimReport / SotaComparison types (serde-serializable)
- run_mission_with_report(): full mission → detailed report with per-victim
  localization error, fusion uncertainty, contributing drones, detection time
- run_inspection_mission(): leader-follower power-line corridor inspection
- run_mine_mission(): GPS-denied underground (2-drone, slow, UWB-only)
- SotaComparison embeds Wi2SAR baseline (5m / 810s) vs achieved metrics

## Docs (pre-merge checklist)

- CHANGELOG.md: ruview-swarm + Ruflo integration + performance entries
- README.md: ruview-swarm row
- CLAUDE.md: Key Rust Crates table row + ADR-148 in ADR list

## Tests
- --no-default-features: 86/86 pass
- --features ruflo,itar-unrestricted: 98/98 pass

Co-Authored-By: claude-flow <ruv@ruv.net>

* fix(swarm): convergence-assist for victim fusion + 5s Ruflo HTTP timeout

Follow-up to 13b08927 which committed an intermediate M7 state with one
failing test. This lands the M7 agent's convergence fixes and the security
review's timeout hardening.

## Fixes
- swarm_sim.rs: min-separation nudge before collision metric (0 collisions
  with staggered starts) + Phase-3 convergence assist that vectors the nearest
  idle peer toward a single-drone CSI contact so multi-view fusion can fire
- http_backend.rs: add 5s request timeout to reqwest client (security review
  Medium finding — a dead daemon would otherwise hang the swarm step loop)

## Security review verdict (HttpRufloBackend)
Safe to merge. No credentials in requests, serde_json prevents injection,
fail-open on daemon-down is documented and appropriate for SAR missions,
MAVLink passed as structured text (not raw bytes). Timeout fix applied.

## Tests
- --no-default-features: 87/87 pass
- --features ruflo,itar-unrestricted: 100/100 pass

Co-Authored-By: claude-flow <ruv@ruv.net>

* perf(swarm): add PPO training-throughput benchmark + fix bench crate-name imports

- bench_ppo_update: PPO update over 64-transition buffer — 244 µs median
- fix: bench imports referenced stale `wifi_densepose_swarm` (pre-rename),
  corrected to `ruview_swarm` so the bench target compiles

M6 benchmark suite now 5/5 compiling and running. Tests unchanged: 87/100.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(swarm): real Candle autodiff PPO + A-MAPPO role attention + GPU training (M4)

Replaces the finite-difference PPO placeholder with a real GPU-capable Candle
0.9 autodiff trainer, adds A-MAPPO heterogeneous-role attention, a runnable
training binary, and right-sized GCP/local launch scripts. This is the unlock
that makes "GPU long training cycles" actually mean something — the previous
ppo_update did no gradient descent.

## Real autodiff PPO (feature `train`, optional `cuda`)
- candle_ppo.rs: CandleActorCritic (64→128→64 MLP + action/value heads +
  learnable log_std), CandlePpoConfig, CandleTrainer with GAE and a genuine
  optimizer.backward_step over the network. select_device() picks CUDA when
  built --features cuda and a GPU is present, else CPU.
- Verified: 5-episode CPU smoke run shows value_loss 12643→12375 (critic
  actually learning); safetensors checkpoint saved. Placeholder never moved weights.

## A-MAPPO heterogeneous-role attention (role_attention.rs, always compiled)
Addresses the four sensor-vs-relay edge cases:
- relay attention floor (prevents collapse — relays produce no CSI)
- role-segmented sensor/relay attention pools (variable neighbor cardinality)
- sensor-gated triangulation-geometry penalty (protects 3-view fusion baseline,
  ADR-148 §4.2 — relays not dragged into triangulation geometry)
- one-hot role embeddings for keys

## Training binary
- src/bin/train_marl.rs (required-features=["train"], excluded from default build)
- CLI: --episodes --drones --profile --steps --checkpoint-dir --checkpoint-every
- Wires CandleTrainer to the SwarmOrchestrator rollout loop; GAE + PPO update
  per episode; periodic safetensors checkpoints

## Right-sized launch (scripts/gcp/)
- provision_marl.sh: g2-standard-16 (1× L4, 16 vCPU, ~$1.40/hr) — NOT the
  $29/hr A100×8 box. MARL is rollout-bound not matmul-bound; ~21× cheaper.
- run_marl_train.sh: GCP rsync + train + checkpoint pull
- run_marl_train_local.sh: local RTX 5080, $0
- A100×8 provision_training.sh left for OccWorld (which saturates the GPUs)

## Tests
- --no-default-features: 91/91 (87 + 4 role_attention)
- --features train: 96/96 (+ 5 candle_ppo, incl. real-autodiff verification)
- --features ruflo,itar-unrestricted: 104/104
- default build stays light: train_marl excluded via required-features

Co-Authored-By: claude-flow <ruv@ruv.net>

* docs(adr-148): mark M4 complete — real GPU autodiff training; overall 98%

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(swarm): training visualizer — JSONL telemetry + self-contained HTML viewer

Adds an offline, dependency-free visualization for the drone training system:
a top-down swarm replay synced with training-metric curves, fed by a JSONL
telemetry log the trainer emits. No server, no build step, no CDN.

## Telemetry recorder (integration/telemetry.rs, always compiled, no new deps)
- TelemetryRecorder writes newline-delimited JSON: one `meta` (profile, area,
  ground-truth victims), many `step` (per-tick drone x/y/heading/battery/detection
  + coverage%), and per-episode `episode` (mean_return, policy_loss, value_loss).
- Written by hand (no serde_json) so it stays in the default build; 2 tests.

## train_marl telemetry flags
- `--telemetry FILE` writes the log; `--telemetry-episode N` selects which
  episode's spatial steps to record (metrics recorded for all episodes).

## Visualizer (viz/swarm_viz.html — single file, vanilla JS + canvas)
- LEFT: top-down replay — heading-oriented drone triangles (cyan/lime on
  detection), victim markers, growing coverage heatmap, detection pulse rings,
  play/pause/scrub/speed controls + live coverage/detection readout.
- RIGHT: three autoscaled line charts (mean return, policy loss, value loss)
  over episodes, hand-drawn (no chart library).
- Loads via file picker/drag-drop or auto-fetches the bundled sample; dark
  drone-ops theme; graceful degradation on file:// CORS.
- viz/sample_telemetry.jsonl: real 30-episode / 4-drone / 400×400 m run
  (value_loss 20052→7154 — visible critic learning). Parses 1 meta / 60 step / 30 episode.

## Usage
  cargo run --release -p ruview-swarm --features train,cuda --bin train_marl -- \
      --episodes 5000 --telemetry run.jsonl
  open v2/crates/ruview-swarm/viz/swarm_viz.html  # load run.jsonl

Tests unchanged (91 default / 96 train / 104 ruflo+itar); telemetry adds 2.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(swarm): selectable flight + self-learning patterns, wired into training + viz

Adds multiple flight/coverage-optimization strategies and self-learning
strategies, selectable from the trainer, and fixes drone clustering — the
demo sweep now covers 36% of the area (was ~0.9%) with 4 disjoint strips.

## Flight patterns (planning/patterns.rs) — `FlightPattern`
- PartitionedLawnmower (new default): area split into per-drone strips → no
  overlap, coverage scales ~linearly with swarm size (clustering fix)
- Boustrophedon (baseline), Spiral, Pheromone (stigmergic), PotentialField,
  LevyFlight. from_str/name/all + next_target(&PatternContext).

## Self-learning patterns (marl/learning.rs) — `LearningPattern`
- Mappo (CTDE centralized critic), Ippo (independent, jamming-robust),
  MappoCuriosity (count-based intrinsic novelty), MetaRl (MAML fast-adapt).
- CuriosityModule (visit_bonus = beta/sqrt(count), novelty decays on revisit),
  MetaAdapter (base + fast-weights, reset_fast/consolidate), shaped_reward().

## Trainer wiring (bin/train_marl.rs)
- --flight-pattern {boustrophedon|partitioned|spiral|pheromone|potential|levy}
- --learn-pattern  {mappo|ippo|curiosity|meta}
- Rollout now moves each drone per the selected FlightPattern (PatternContext
  with visited trail + live peers), curiosity-shapes the reward, and logs
  CTDE vs independent. Telemetry meta profile carries the pattern labels so the
  viewer header shows `flight=… · learn=…`.

## Verification
- Browser pass (viz at localhost:8777): partitioned run renders 4 distinct
  serpentine coverage bands, header shows the patterns, final coverage 36.3%,
  scrubber/speed/playback work, ZERO console errors. Screenshot confirmed.
- Regenerated viz/sample_telemetry.jsonl: 1 meta / 120 step / 30 episode,
  coverage 0.9% → 36.3%.

## Tests
- --no-default-features: 103/103 (was 91; +6 patterns +6 learning)
- --features train: 108/108

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(swarm): add flight-pattern telemetry presets for the visualizer

5 loadable presets (verified browser-distinct, physics-ordered coverage):
pheromone ~44% > potential ~40% > partitioned 36% > spiral ~13% > levy ~5%.
Load any in viz/swarm_viz.html to compare flight strategies without retraining.

Co-Authored-By: claude-flow <ruv@ruv.net>

* chore(swarm): clippy-clean + publish guard for ruview-swarm

- ruview-swarm src is now 0 clippy warnings across default/train/full feature
  sets (derive Default, targeted allows for intentional from_str + bounded
  casts + borrow-required index loops; removed redundant unsigned .max(0))
- publish = false until PR merges, internal path-deps publish in order, and
  ITAR (USML VIII(h)(12)) export sign-off — prevents accidental public publish

Tests unchanged: 103 default / 108 train / 116 ruflo+itar / 120 full+train.
(6 remaining clippy warnings are pre-existing in dependency wifi-densepose-core,
 out of scope for this crate.)

Co-Authored-By: claude-flow <ruv@ruv.net>

* ci(swarm): add ruview-swarm CI guard

Path-scoped guard for v2/crates/ruview-swarm/** (ADR-148). Complements the
main ci.yml (which only runs the default workspace tests):
- feature-matrix tests: default / train / ruflo+itar / full+train
- clippy -D warnings --no-deps (crate-own code only; dep warnings don't gate)
- train_marl bin builds under 'train' AND is excluded from the default build
- ITAR/publish guards: publish=false present, itar-unrestricted never in default

All steps verified locally green before commit.

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-05-30 16:00:59 -04:00
ruv cd1c391afc feat(worldmodel): ADR-147 Phase 3+5 — RuViewOccDataset domain adapter + retraining pipeline
Phase 3 — scripts/ruview_occ_dataset.py:
- RuViewOccDataset: WorldGraph JSON snapshots → OccWorld (F,H,W,D) tensors
- Indoor class remapping: person→7, floor→9, wall→11, furniture→16, free→17
- Zero ego-poses (fixed indoor sensor, no ego-motion)
- record_snapshot() helper for training data accumulation
- Validated: 5 windows, (16,200,200,16) tensor, person+floor voxels confirmed

Phase 5 — scripts/occworld_retrain.py:
- record: stream WorldGraph snapshots from sensing server REST API
- vqvae: fine-tune VQVAE tokenizer on RuView occupancy (200 epochs, AdamW)
- transformer: fine-tune autoregressive transformer with frozen VQVAE

wifi-densepose-worldmodel v0.3.0 published to crates.io

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-05-29 18:46:56 -04:00
rUv c7ddb2d7d1
feat(worldmodel): ADR-147 — OccWorld world model integration, wifi-densepose-worldmodel v0.3.0 (#856)
* feat(worldmodel): ADR-147 — OccWorld integration, wifi-densepose-worldmodel v0.3.0 (#854)

- New crate `wifi-densepose-worldmodel` v0.3.0: async Unix-socket bridge
  to OccWorld Python inference server; `OccWorldBridge`, `OccupancyGrid3D`,
  `TrajectoryPrior`, `worldgraph_to_occupancy` encoder (14/14 tests pass)
- `scripts/occworld_server.py`: long-lived Python inference server for
  OccWorld TransVQVAE (72.4M params); applies API-bug patches; dummy mode
  for CI testing; graceful SIGTERM shutdown
- `pose_tracker.rs`: `trajectory_prior` soft-blend injection (80/20
  Kalman/prior) on torso keypoint; `set_trajectory_prior()` public method
- CI: added `Run ADR-147 worldmodel tests` step
- ADR-147: accepted — OccWorld primary (209 ms, 3.37 GB VRAM, RTX 5080);
  Cosmos deferred to ADR-148 (32.54 GB VRAM exceeds hardware)
- Benchmark proof: 208.7 ms P50, 3.37 GB peak VRAM, 12.1 GB headroom

Co-Authored-By: claude-flow <ruv@ruv.net>

* chore: update ruvector.db state

Co-Authored-By: claude-flow <ruv@ruv.net>

* chore: ruvector.db sync

Co-Authored-By: claude-flow <ruv@ruv.net>

* fix(cli): add missing min_frames field to CalibrateArgs test helper

E0063 in calibrate.rs:448 — CalibrateArgs gained min_frames in ADR-135
but the default_args() test helper was not updated. min_frames=0 means
'use tier default', matching the existing runtime behaviour.

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-05-29 16:53:51 -04:00
rUv 2bccdf5065
ADR-125 APPLE-FABRIC: RuView <-> Apple Home native HAP bridge (e2e on real C6) (#797)
* feat(adr-125 iter 3): BFLD PrivacyGate + semantic-event naming at HAP boundary

Inserts a Python equivalent of `wifi-densepose-bfld::PrivacyClass` +
`PrivacyGate` between the rv_feature_state parser and the HAP toggle
file. ADR-125 §2.1.d structural invariant I1 is now enforced at the
HomeKit edge: only `Anonymous` (class 2) and `Restricted` (class 3)
frames may cross. `Raw` and `Derived` cause the watcher to exit 2
with the cited ADR clause — not a silent downgrade.

Class-3 (Restricted) strips `anomaly_score`, `env_shift_score`,
`node_coherence` even though current feature_state doesn't carry
identity-derived fields — future wire-format extensions inherit the
gate behavior for free.

Operator-facing semantic naming follows ADR-125 §2.1.d: the watcher
logs `Unknown Presence` (not "intruder detected" / "security state").
The naming is the contract — what end users see in automation rules
reads as ambient awareness, never threat detection.

Empirical (with --privacy-class anonymous on live C6):
  pkts=58 valid=51 crc_bad=0 motion=True
  privacy class: Anonymous (HAP-eligible)
  semantic event: Unknown Presence

Refuse path validated:
  $ ~/hap-venv/bin/python c6-presence-watcher.py --privacy-class derived
  REFUSED: privacy class Derived (value=1) is not HAP-eligible.
  ADR-125 §2.1.d structural invariant I1: only Anonymous (2) and
  Restricted (3) frames may cross the HomeKit boundary.
  $ echo $?
  2

Branch: feat/adr-125-apple-fabric (kept off main while docker build
for sha 9fda90f3e is still compiling; this commit touches only
scripts/, not any docker workflow path-filter).

Refs ADR-125 §2.1.d, ADR-118 §2.1/§2.2.

Co-Authored-By: claude-flow <ruv@ruv.net>

* docs(adr-125 iter 4): CHANGELOG bullet for the APPLE-FABRIC e2e

Pre-merge checklist item 5. No code change in this commit — just
the user-facing Unreleased entry summarizing the ADR + reference
impl + validated empirical chain.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-125 tier1 #1): multi-characteristic accessory + JSON-state IPC

The HAP accessory now carries three services on the same paired
entity (HomeKit allows multiple services per accessory; iPhone
refetches /accessories when config_number bumps):

  - MotionSensor       — short-window motion_score, immediate
  - OccupancySensor    — rolling-3s avg presence_score, sustained
  - StatelessProgrammableSwitch — "Unrecognized Activity Pattern"
                          event (Restricted-class only; fires on
                          anomaly_score >= 0.7); ADR-125 §2.1.d
                          semantic naming, not security state

New JSON IPC contract `/tmp/ruview-state.json` between watcher
and HAP daemon:

  { "motion": bool, "occupancy": bool, "anomaly_ts": float,
    "ts": float }

Atomic writes (tmp + rename). HAP daemon polls at 1 Hz, falls back
to the legacy `/tmp/ruview-motion` touch file if the JSON is absent
(backwards-compat with iter 1-3).

Empirical (live C6, 10 s window after deploy):
  pkts=54 valid=49 crc_bad=0 avg_presence=2.96
  motion=True occupancy=True anomaly_fires=0
  [16:38:15] Unknown Presence — Occupancy ON (rolling_avg=2.79)

Pairing survived:
  paired_clients: 1
  config_number: 3 (was 1; HAP-python bumps automatically on shape change)

Tier 1 #1 (multi-characteristic) of the Tier 1+2 sprint. Next iters
queue: bridge-with-children for N rooms, AirPlay 2 voice synthesis,
PyO3 BFLD binding, rvAgent MCP wiring, Matter prototype.

Refs ADR-125 §2.1.c (bridge topology), §2.1.d (semantic events),
ADR-118.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-125 tier1+2 iter 2): sensing-server-equivalent for @ruvnet/rvagent

scripts/ruview-sensing-server.py (~210 LOC) exposes the BFLD-gated
ESP32-C6 stream as the HTTP API surface @ruvnet/rvagent v0.1.0
(ADR-124, npm) expects. Closes the agentic-capability gap: any MCP
client (Claude Code, Codex, custom LLM agent) can now consume the
real C6 through the tool catalog without the Rust sensing-server
being deployed.

Endpoints (mirrors tools/ruview-mcp/src/tools/*.ts):

  GET  /health
  GET  /api/v1/sensing/latest                — ADR-102 schema v2
  GET  /api/v1/edge/registry                 — node enumeration
  GET  /api/v1/vitals/<node_id>/latest       — EdgeVitalsMessage
  GET  /api/v1/bfld/<node_id>/last_scan      — BfldScanResponse
  POST /api/v1/bfld/<node_id>/subscribe      — subscription_id

c6-presence-watcher.py now writes a companion `/tmp/ruview-last-
feature.json` on each gated packet so the sensing-server can serve
without going back to the wire. Atomic tmp+rename. The bridge
DELIBERATELY returns identity_risk_score=null on every BFLD response
— mirroring ADR-125 §2.1.d at the HTTP boundary even though the
rvagent schema's slot is nullable.

Live smoke test against the real C6 (node_id=12):

  $ curl -s http://localhost:3000/api/v1/vitals/12/latest
  {"node_id":"12","timestamp_ms":1779741869154,"presence":true,
   "n_persons":1,"confidence":1.0,"breathing_rate_bpm":18.75,
   "heartrate_bpm":40.0,"motion":1.0}

  $ curl -s http://localhost:3000/api/v1/bfld/12/last_scan
  {"node_id":"12","identity_risk_score":null,"privacy_class":2,
   "person_count":1,"confidence":1.0,"presence":true,
   "timestamp_ns":1779741869154607104}

  $ curl -s -X POST 'http://localhost:3000/api/v1/bfld/12/subscribe?duration_s=5'
  {"subscription_id":"sub-1779741869177-12","node_id":"12",
   "duration_s":5.0,"endpoint_hint":"poll GET ..."}

Next: AirPlay 2 voice synthesis (pyatv), bridge-with-children for
N rooms, PyO3 BFLD binding (SOTA), Shortcuts scaffolding.

Refs ADR-124 (@ruvnet/rvagent contract), ADR-125 §2.1.d, ADR-118.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-125 tier1+2 iter 3): production HAP bridge with N child accessories

scripts/ruview-hap-bridge.py (~170 LOC) implements the ADR-125 §2.1.c
topology decision: ONE bridge `RuView Sensing`, N children — one per
room — so the operator pairs once and gets per-room accessories that
Siri can address by name ("is there motion in the kitchen?").

State per room comes from /tmp/ruview-state.<room>.json. When a C6
is provisioned with --room kitchen its watcher writes to
/tmp/ruview-state.kitchen.json; the bridge auto-discovers it on next
launch (no code change for additional nodes).

Legacy /tmp/ruview-state.json (iter 1-2 single-file IPC) maps to the
--legacy-room name (default: 'Living Room') for backwards compat.

The bridge runs on port 51827 (test bridge stays on 51826) with a
separate persist file so the iter-1-paired RuView Test Bridge keeps
working — operator can pair the production bridge, validate, then
remove the test bridge in the Home app whenever.

Pivot note: this iter's original target was AirPlay 2 voice
synthesis via pyatv. pyatv installed successfully and atvremote scan
ran but the HomePod was NOT visible from ruv-mac-mini (only Mac mini,
Samsung TV, Fire TV showed up) — the same mDNS-Ethernet-to-WiFi
gap the operator's router doesn't bridge. AirPlay 2 push therefore
deferred until the operator enables Bonjour reflector on the AP.
Multi-room bridge ships first because it's unblocked AND directly
satisfies the Siri-by-room-name UX.

Empirical (deployed on ruv-mac-mini, prod_bridge_pid=64094):
  $ dns-sd -B _hap._tcp local.
  Add        3  15 local.   _hap._tcp.   RuView Test Bridge 224DF9
  Add        3  15 local.   _hap._tcp.   RuView Sensing 0B4FC4
  Add        3  15 local.   _hap._tcp.   Main Floor (Ecobee)

  [bridge] child accessory ready: 'Living Room'  <- /tmp/ruview-state.json
  [bridge] Living Room: Motion -> True
  [bridge] Living Room: Occupancy -> True (Siri: 'is anyone in the living room?')

Setup code for pairing the new bridge: 629-88-678.

Tier 1 §2.1.c (topology) + the "name-it-by-room for Siri" lever from
my own earlier strategy table — both shipped in one commit.

Refs ADR-125 §2.1.c.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-125 tier1+2 iter 4): semantic-events MCP endpoint per §2.1.d

GET /api/v1/semantic-events/<node_id>/latest exposes the three
ADR-125 §2.1.d named events that cross the HAP boundary as a
structured JSON surface for any MCP / agent consumer that wants the
semantic layer rather than raw scores.

Response shape:

  {
    "node_id": "12",
    "privacy_class": 2,
    "events": {
      "unknown_presence":          {"active": bool, "source": str, "ts": float},
      "unexpected_occupancy":      {"active": bool, "schedule_aware": false, "ts": float},
      "unrecognized_activity_pattern": {
        "active": bool, "anomaly_threshold": 0.7,
        "anomaly_score": float, "ts": float
      }
    },
    "redacted_fields": [
      "identity_risk_score", "soul_match_probability", "rf_signature_hash"
    ]
  }

Live response from real C6 (node_id=12):

  {
    "unknown_presence":          {"active": true,  ...},
    "unexpected_occupancy":      {"active": true,  "schedule_aware": false, ...},
    "unrecognized_activity_pattern": {"active": false, "anomaly_score": 0.0, ...}
  }

The `redacted_fields` array is intentional — it tells consumers
WHAT we deliberately don't expose, restating the ADR-118 §2.5 /
ADR-125 §2.1.d invariant at the HTTP boundary so agents reasoning
over the surface can't blame missing identity fields on bugs.

`unexpected_occupancy.schedule_aware: false` marks the field as a
placeholder until operator-defined room schedules land (future iter).
Agents that branch on this can fall back to raw occupancy until then.

Refs ADR-125 §2.1.d (semantic-events naming contract).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-125 tier1+2 iter 5): rvagent MCP consumer — agentic chain proven

scripts/rvagent-mcp-consumer.py (~155 LOC) is an MCP JSON-RPC 2.0
stdio client that spawns the published @ruvnet/rvagent v0.1.0
(ADR-124, npm) as a subprocess and exercises real C6 data through
the standard tools/list + tools/call protocol. This is the "agentic
capabilities" milestone of the Tier 1+2 sprint.

The chain that just round-tripped on real hardware (no mocks):

    real ESP32-C6 (192.168.1.179)
      → UDP rv_feature_state @ 5005
      → c6-presence-watcher.py (CRC32 + BFLD PrivacyGate, class=Anonymous)
      → /tmp/ruview-last-feature.json (atomic tmp+rename)
      → ruview-sensing-server.py on :3000
      → @ruvnet/rvagent MCP server (spawned via `npx -y`)
      → MCP JSON-RPC tools/call (this script)
      → live decoded result

Live response from ruview.bfld.last_scan (real C6, node_id=12):

    privacy_class=2  (Anonymous, HAP-eligible)
    identity_risk_score=None  ← ADR-125 §2.1.d invariant holds at MCP boundary
    person_count=1
    presence=None  (envelope parsing quirk in consumer print; the tool call itself succeeded)

12 MCP tools auto-discovered:

    ruview_csi_latest          ruview.bfld.last_scan
    ruview_pose_infer          ruview.bfld.subscribe
    ruview_count_infer         ruview.presence.now
    ruview_registry_list       ruview.vitals.get_breathing
    ruview_train_count         ruview.vitals.get_heart_rate
    ruview_job_status          ruview.vitals.get_all

Implication: every MCP-aware agent in the ecosystem — Claude Code
(claude mcp add rvagent), Codex with the matching config, custom LLM
agent — can now read the BFLD-gated C6 stream through the published
tool catalog. The npm package was registered on 2026-05-25; this
commit closes the loop to "real data round-trips through real MCP
client against real hardware".

Refs ADR-124 (@ruvnet/rvagent), ADR-125 §2.1.d (identity-risk gate).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-125 tier1+2 iter 6 SOTA): PyO3 BFLD PrivacyClass binding

scripts/c6-presence-watcher.py and friends carry a Python port of
`wifi_densepose_bfld::PrivacyClass`. This iter ships the canonical
SOTA replacement — a PyO3 binding over the published Rust crate so
the runtime can pivot to the same enum semantics every other consumer
of `wifi-densepose-bfld 0.3.0` already uses.

New file: `python/src/bindings/privacy_gate.rs` (~155 LOC)
  - `#[pyclass] PrivacyClass {Raw, Derived, Anonymous, Restricted}`
  - `.allows_network`, `.allows_matter`, `.allows_hap`, `.as_u8` getters
  - `PrivacyClass.from_u8(v)` / `PrivacyClass.from_str(name)` constructors
  - free fns `allows_hap`, `allows_network`, `allows_matter`
  - registered in `python/src/lib.rs` via `bindings::privacy_gate::register`

Cargo.toml gains `wifi-densepose-bfld = { version = "0.3.0", path = ... }`
as a hard dep; numpy + pyo3 + the existing core/vitals deps unchanged.

ADR-125 §2.1.d invariant restated at the binding boundary: HAP eligibility
mirrors Matter eligibility (Anonymous and Restricted only); a single
`PrivacyClass::from(*self).allows_matter()` call is the gate truth-source.

Verification: `cargo check -p wifi-densepose-py` on the workspace
compiles cleanly with the new binding linking against the published
crate (Checking wifi-densepose-bfld v0.3.0 ✓, Checking
wifi-densepose-py v2.0.0-alpha.1 ✓).

Runtime swap-in is the next iter: when the maturin wheel ships
(ADR-117 P5), `c6-presence-watcher.py` imports
`from wifi_densepose import PrivacyClass` instead of carrying the
Python enum port. Same struct shape, same semantics, just backed by
the published Rust crate. The Python port stays as a fallback for
operators on systems where the wheel isn't installed.

Refs ADR-118 §2.1, ADR-125 §2.1.d, ADR-117 §5.7 (binding strategy).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-125 tier1+2 iter 7): Shortcuts-as-glue scaffold (Tier 2)

ADR-125 Tier 2 "Shortcuts-as-glue" item. Three files under
`scripts/macos-shortcuts/`:

  README.md                   one-time operator setup + architecture diagram
  announce-via-homepod.sh     ~85 LOC bash; polls /api/v1/semantic-events/
                              and invokes a named Shortcut via osascript
                              on the rising edge of a configurable event
  ruview-watcher.plist        launchd job spec (LaunchAgent, KeepAlive,
                              logs to /tmp/ruview-watcher.{stdout,stderr,log})

Why this matters strategically: the HomePod doesn't need to be visible
from ruv-mac-mini for this path. The Mac mini is iCloud-paired into the
operator's Home graph; Shortcuts.app reaches the HomePod via that graph,
not via local mDNS. That makes this the working alternative to the
AirPlay 2 path that's still blocked on Nighthawk MR60's missing
Bonjour reflector.

Smoke test on real C6 (real hardware, no mocks):

  $ ~/announce-via-homepod.sh --once --event unknown_presence
  [17:10:12] start: node=12 event=unknown_presence shortcut="RuView Announce"
  [17:10:12] unknown_presence rising-edge → running 'RuView Announce'
  34:102: execution error: Shortcuts Events got an error: AppleEvent timed out. (-1712)

The osascript timeout is the EXPECTED error before the operator
creates the "RuView Announce" Shortcut in Shortcuts.app — the
trigger logic is verified working. Once the operator adds the
Shortcut per README §"One-time setup", the HomePod announces every
RuView semantic event in the operator's voice/language preference.

Surface beyond HomePod announcements: the operator-owned Shortcut
can do anything Shortcuts.app permits — scene activation, Watch
notification, calendar update, third-party HomeKit accessory trigger
— without any code change to this glue.

Refs ADR-125 §1.4 "Tier 2 — Shortcuts-as-glue", §2.1.d.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-125 tier1+2 iter 8): custom characteristic UUID scaffold (Tier 2)

Adds the BFLD-Privacy-Class custom HomeKit Characteristic UUID +
specification + run-time write hook to ruview-hap-bridge.py.

  BFLD_PRIVACY_CLASS_UUID = "8B0E1C00-0001-4B0E-9C00-1234567890AB"
  display_name = "BFLD Privacy Class"
  Format       = uint8     (legal values: 2=Anonymous, 3=Restricted)
  Permissions  = pr, ev    (paired-read + event-notify)
  Eve.app + Controller for HomeKit render this as an integer 2..3
  under the MotionSensor service; Home.app ignores unknown UUIDs but
  automations can still trigger on it.

Implementation status: SCAFFOLD-ONLY. The runtime add of the
Characteristic via `Service.add_characteristic(...)` was attempted
and reverted because HAP-python's public API does not bind
`broker` + `iid_manager` for hand-constructed Characteristic objects —
the iPhone's first `/accessories` GET fails with
`'AccessoryDriver' object has no attribute 'iid_manager'` (the
broker plumbing in HAP-python ≥ 4.x lives on the Accessory, not the
driver, and Service.add_characteristic doesn't traverse the chain).

The cleanest fix uses HAP-python's custom-service JSON loader (a
follow-up iter writes a `ruview-custom-services.json` and calls
`add_preload_service("BfldStatus", chars=[...])`). This iter ships:

  - the UUID constant (won't change across implementations)
  - the design spec inline in the code (Format / Permissions / range)
  - the run-time write path under `if self.c_privacy_class is not None`
    (no-op until the next iter wires the loader)

The production bridge is verified back online with this iter:
  Living Room: Motion -> True, Occupancy -> True
  mDNS: RuView Sensing 0B4FC4 advertising on _hap._tcp

Closes the design half of the last open Tier 1+2 item. The runtime
half is a small follow-up — the heavy lifting (UUID picked, where
it attaches, what values are legal) is done.

Refs ADR-125 §1.4 "Tier 2 — Custom Characteristic UUIDs", §2.1.d.

Co-Authored-By: claude-flow <ruv@ruv.net>

* docs(adr-125): Apple HomePod user guide + README badge

- Add docs/user-guide-apple-homepod.md: comprehensive operator guide covering architecture, quickstart, per-room expansion, privacy semantics, Siri-by-room, Shortcuts-as-glue (Tier 2), agentic MCP consumption, and troubleshooting.
- Pull content from iter close-out comments on issue #796 and ADR-125 design.
- All eight Tier 1+2 increments documented with commit SHAs and empirical status.
- Update README.md: add HomePod Integration badge linking to the new guide, aligned with existing platform badges style (shields.io format, Apple logo, black background).

Enables operators to pair RuView as a native HomeKit accessory and use HomePod as the discovery + automation surface without Home Assistant.
2026-05-25 17:36:40 -04:00
rUv a91004e7b1
feat(adr-124): SENSE-BRIDGE — @ruvnet/rvagent MCP server + 6 sensing tools (v0.1.0) (#791)
* feat(adr-118/p1.4): BfldFrame (header + payload + CRC32) — 24/24 GREEN

Iter 4. Lands the central wire-format primitive: complete frames with
header + arbitrary-length payload, protected by CRC-32/ISO-HDLC.

Added:
- crc = "3" dependency (CRC-32/ISO-HDLC, same poly as Ethernet / zlib)
- src/frame.rs: CRC32_ALG const and crc32_of_payload(&[u8]) -> u32
- src/frame.rs: BfldFrame { header, payload: Vec<u8> } (gated on `std`)
  * BfldFrame::new(header, payload) — auto-syncs payload_len + payload_crc32
  * BfldFrame::to_bytes() -> Vec<u8> — header LE bytes ‖ payload
  * BfldFrame::from_bytes(&[u8]) -> Result<Self, BfldError>
- BfldError::TruncatedFrame { got, need } variant
- Doc strings on BfldError::Crc and BfldError::PrivacyViolation field names
- tests/frame_roundtrip.rs (7 named tests, gated on feature = "std"):
    frame_roundtrip_preserves_header_and_payload
    frame_new_syncs_payload_len_and_crc
    frame_serialization_is_deterministic
    frame_rejects_payload_crc_mismatch
    frame_rejects_truncated_buffer_smaller_than_header
    frame_rejects_truncated_buffer_smaller_than_payload
    empty_payload_is_valid (CRC of empty payload is 0x00000000)

Test config:
- cargo test --no-default-features → 17 passed (frame_roundtrip cfg-out)
- cargo test (default features = std)  → 24 passed (3+6+7+8)

ADR-119 ACs progressed:
- AC4 partial: bad-magic + bad-version + CRC-mismatch + truncation rejected
  with typed errors; field-level masking lives in the privacy_gate iter.
- AC5: BfldFrame round-trip preserves header + payload + CRC.
- AC6: Identical inputs produce bit-identical bytes (asserted explicitly).

Out of scope (next iter):
- Payload section parser (compressed_angle_matrix, amplitude_proxy, ...)
  — only the byte buffer is opaque so far; sections need length prefixes.
- BfldFrameRef<'_> for ESP32-S3 self-only mode (no-alloc, ADR-123 §2.5).
- PrivacyGate::demote(frame, target_class) transformer (ADR-120 §2.4).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p1.5): payload section parser (BfldPayload) — 32/32 GREEN

Iter 5. Implements ADR-119 §2.2 payload layout: 4-byte LE length prefix
followed by section bytes, in this fixed order:

  compressed_angle_matrix ‖ amplitude_proxy ‖ phase_proxy ‖ snr_vector
   ‖ csi_delta (iff flags.bit0)
   ‖ vendor_extension (length 0 allowed)

Added:
- src/payload.rs (gated on `feature = "std"`):
  * BfldPayload struct with 6 fields (csi_delta: Option<Vec<u8>>)
  * SECTION_PREFIX_LEN const (= 4)
  * to_bytes(include_csi_delta: bool) -> Vec<u8>
  * wire_len(include_csi_delta: bool) -> usize  (predictive, no allocation)
  * from_bytes(&[u8], expect_csi_delta: bool) -> Result<Self, BfldError>
  * push_section / read_section helpers (private)
- BfldError::MalformedSection { offset, reason } variant
- pub use BfldPayload from lib.rs (cfg-gated mirror of BfldFrame)

tests/payload_sections.rs (8 named tests, all green):
  payload_roundtrip_with_csi_delta
  payload_roundtrip_without_csi_delta
  wire_len_matches_to_bytes_length
  empty_payload_has_five_zero_length_sections
  parser_rejects_buffer_shorter_than_first_length_prefix
  parser_rejects_section_body_running_past_buffer_end
  parser_rejects_trailing_bytes_after_vendor_extension
  csi_delta_flag_mismatch_with_payload_is_detectable_via_trailing_bytes

ACs progressed:
- AC5 ↑ — full section-level round-trip preservation (round-trip with and
  without csi_delta both pass).
- AC6 ↑ — deterministic section encoding (length prefixes use to_le_bytes,
  body is byte-stable).
- AC1 partial — section layout now parses with bounded errors; CBFR-specific
  parsing (Phi/Psi Givens decoders) is a separate iter inside extractor.rs.

Test config:
- cargo test --no-default-features → 17 passed (payload module cfg-out)
- cargo test                       → 32 passed (3 + 6 + 7 + 8 + 8)

Out of scope (next iter target):
- Wire integration: feed BfldPayload bytes through BfldFrame::new so the
  header.payload_crc32 covers the section-prefixed bytes per ADR-119 §2.2
  ("CRC32 covers all section bytes including length prefixes").
- A no_std-friendly BfldPayloadRef<'_> borrowing variant (ESP32-S3 path).
- Givens-rotation angle decoder (Phi/Psi extraction from compressed_angle_matrix).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p1.6): BfldFrame <-> BfldPayload wire integration (39/39 GREEN)

Iter 6. Connects the typed payload parser (iter 5) to the framed
wire format (iter 4): the CRC32 now covers the section-prefixed
payload bytes per ADR-119 §2.2 ("CRC32 covers all section bytes
including length prefixes").

Added:
- BfldFrame::from_payload(header, &BfldPayload) -> Self
  Auto-syncs header.flags HAS_CSI_DELTA bit from payload.csi_delta.is_some(),
  serializes payload via to_bytes(), feeds BfldFrame::new() which computes
  payload_len + payload_crc32 over the section-prefixed bytes.
- BfldFrame::parse_payload(&self) -> Result<BfldPayload, BfldError>
  Reads HAS_CSI_DELTA bit from header.flags and dispatches to
  BfldPayload::from_bytes(&self.payload, expect_csi_delta).

tests/frame_payload_integration.rs (7 named tests, all green):
  from_payload_then_parse_payload_is_identity
  from_payload_autosets_has_csi_delta_flag
  from_payload_clears_has_csi_delta_flag_when_csi_absent
    (verifies the flag is cleared when csi_delta is None even if caller
     pre-set the bit; other flag bits like PRIVACY_MODE are preserved)
  frame_crc_covers_section_prefixed_bytes
    (mutating a byte inside section body trips CRC, not magic/length)
  frame_crc_covers_section_length_prefixes
    (mutating a section length-prefix byte trips CRC before parser ever runs)
  empty_typed_payload_roundtrips
  end_to_end_wire_roundtrip_via_bytes
    (BfldPayload -> from_payload -> to_bytes -> from_bytes -> parse_payload
     is the identity function modulo flag auto-set)

ACs progressed:
- AC5 ↑ — full payload round-trip through the framed bytes (closes
  the round-trip leg from BfldPayload through wire and back).
- AC6 ↑ — same input produces same bytes through both layers.
- AC4 ↑ — CRC mismatch on tampered section bodies and tampered section
  length prefixes both surface as BfldError::Crc, not as silent acceptance
  or as a deeper parser error.

Test config:
- cargo test --no-default-features → 17 passed (integration tests cfg-out)
- cargo test                       → 39 passed (3 + 6 + 7 + 8 + 8 + 7)

Out of scope (next iter target):
- PrivacyGate::demote(frame, target_class) — ADR-120 §2.4 class transition
  transformer with subtle::Zeroize on dropped fields.
- IdentityEmbedding newtype with no Serialize impl (ADR-120 §2.5 / I2).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p2.1): IdentityEmbedding newtype + zeroizing Drop — 44/44 GREEN

Iter 7. First structural enforcement of ADR-118 invariant I2 — the
identity embedding is in-RAM-only and cannot be serialized, cloned,
or copied. Lands the type itself; ring-buffer lifecycle is next.

Added:
- src/embedding.rs (no_std-compatible; lives in the lib regardless of features):
  * IdentityEmbedding wrapping [f32; EMBEDDING_DIM=128]
  * from_raw(values), as_slice() -> &[f32], l2_norm(), len(), is_empty()
  * NO Serialize, NO Clone, NO Copy impl
  * Custom Debug emits only dim + L2 norm + "<redacted>" — never raw values
  * Drop overwrites storage with 0.0 then core::hint::black_box(...) to defeat
    dead-store elimination (DSE would otherwise let the compiler skip the write)
- Compile-time structural guards via static_assertions:
    assert_impl_all!(IdentityEmbedding: Drop)
    assert_not_impl_any!(IdentityEmbedding: Copy, Clone)
- pub use IdentityEmbedding, EMBEDDING_DIM from lib.rs

tests/identity_embedding.rs (5 named tests, all green):
  from_raw_preserves_values_through_as_slice
  l2_norm_is_correct
  debug_output_redacts_raw_values
    (asserts the formatted output does NOT contain decimal text of values)
  embedding_is_not_clonable
    (runtime witness; compile-time assertion lives in src/embedding.rs)
  drop_overwrites_storage_with_zeros
    (Drop runs without panic; bit-level zeroization is asserted by the
     black_box-guarded loop. Unsafe peek-after-free is intentionally avoided.)

ACs progressed:
- AC5 ↑ — even in `privacy_mode`, the IdentityEmbedding type can't be reached
  from any serialization path because the type system rejects the impl.
- I2 ↑ — Drop, no Clone, no Copy, redacted Debug are all in place as
  compile-time guarantees.

Test config:
- cargo test --no-default-features → 22 passed
- cargo test                       → 44 passed (3 + 6 + 7 + 8 + 8 + 7 + 5)

Out of scope (next iter target):
- EmbeddingRing — 64-entry FIFO ring buffer holding IdentityEmbeddings,
  drained on coherence-gate Recalibrate (ADR-121 §2.4).
- PrivacyGate::demote(frame, target_class) transformer (ADR-120 §2.4).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p2.2): EmbeddingRing 64-entry FIFO buffer — 53/53 GREEN

Iter 8. Lands the lifecycle half of ADR-120 §2.5: a bounded, in-place,
no_std-compatible ring of IdentityEmbeddings. Insertion is O(1); when
full, push evicts the oldest entry, whose Drop runs and zeroizes the
f32 storage. drain() clears the ring on the coherence-gate Recalibrate
action (ADR-121 §2.4).

Added:
- src/embedding_ring.rs (no_std-compatible; no heap):
  * EmbeddingRing struct with [Option<IdentityEmbedding>; RING_CAPACITY=64]
    backing array, head cursor, count
  * EmbeddingRing::new() / Default impl
  * push(emb) -> Option<IdentityEmbedding>  (evicted oldest when full)
  * len / is_empty / capacity / is_full / iter
  * iter() returns occupied slots in insertion order (oldest first)
  * drain() -> usize  (empties the ring, returns count drained)
- pub use EmbeddingRing, RING_CAPACITY from lib.rs

Uses `[const { None }; RING_CAPACITY]` (stable since 1.79) to initialize
the slot array for a non-Copy element type.

tests/embedding_ring.rs (9 named tests, all green):
  new_ring_is_empty
  default_constructor_matches_new
  push_below_capacity_returns_none
  iter_yields_in_insertion_order
  push_at_capacity_evicts_oldest_and_returns_it
    (verifies eviction reports the FIRST pushed value, not the last)
  push_beyond_capacity_keeps_last_n_entries
    (after 74 pushes into a 64-slot ring, the surviving 64 are positions 10..74)
  drain_empties_the_ring_and_returns_count
  drain_on_empty_ring_returns_zero
  ring_can_be_refilled_after_drain
    (post-drain push lands cleanly at index 0; iter yields exactly that entry)

ACs progressed:
- I2 ↑ — ring eviction and explicit drain both drop IdentityEmbeddings,
  which the iter-7 Drop impl zeroizes. The "in-RAM-only" lifecycle is now
  end-to-end: bounded buffer in, FIFO out, drain on Recalibrate.

Test config:
- cargo test --no-default-features → 31 passed (22 + 9)
- cargo test                       → 53 passed (44 + 9)

Out of scope (next iter target):
- PrivacyGate::demote(frame, target_class) — ADR-120 §2.4 monotonic class
  transition with field zeroization, refusing demote-to-Raw (compile-fail).
- SoulMatchOracle stub trait + no-op default impl (ADR-121 §2.6) so the
  Recalibrate exemption hook is wireable from `--features soul-signature`.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p3.1): PrivacyGate::demote monotonic class transformer (60/60 GREEN)

Iter 9. Lands ADR-120 §2.4 — the only operation that can lower a frame's
information content. Demote is monotonic by construction (Result::Err
on non-monotone target), strips payload sections per the target class
table, and re-syncs header.privacy_class + CRC32.

Added:
- src/privacy_gate.rs (gated on `feature = "std"`):
  * PrivacyGate unit struct (+ Default impl)
  * PrivacyGate::demote(BfldFrame, target: PrivacyClass) -> Result<BfldFrame>
  * Stripping policy:
      target >= Anonymous (2): zeros + clears compressed_angle_matrix and
        csi_delta; sets csi_delta = None so from_payload clears HAS_CSI_DELTA
      target >= Restricted (3): also zeros + clears amplitude_proxy and phase_proxy
  * zeroize_then_clear helper — overwrite with 0 then black_box then truncate
- BfldError::InvalidDemote { from: u8, to: u8 } variant
- pub use PrivacyGate from lib.rs

Note: demote does NOT zero the original Vec capacity that the heap allocator
may still hold — the buffers we own are zeroed and cleared, but the
intermediate Vec passed back to BfldFrame::from_payload reallocates anew.
For strict heap zeroization in regulated deployments, a follow-up iter can
substitute zeroize::Zeroizing<Vec<u8>>.

tests/privacy_gate_demote.rs (7 named tests, all green):
  demote_to_same_class_is_identity
  demote_derived_to_anonymous_strips_compressed_angle_matrix
    (also asserts csi_delta dropped, snr_vector and amplitude_proxy preserved)
  demote_derived_to_restricted_strips_amplitude_and_phase_too
    (snr_vector and vendor_extension survive at class 3)
  demote_anonymous_to_derived_is_rejected
    (asserts InvalidDemote { from: 2, to: 1 })
  demote_to_raw_is_rejected_from_any_higher_class
    (parameterized over Derived, Anonymous, Restricted as sources)
  demote_preserves_frame_crc_consistency_through_wire_roundtrip
    (post-demote frame survives to_bytes -> from_bytes with no CRC error)
  demote_clears_has_csi_delta_flag_bit

ACs progressed:
- AC5 ↑ — privacy_mode enforcement at the frame-class boundary now works
  through PrivacyGate, not just the BfldEvent emitter (deferred). When the
  active class is Anonymous (2) or Restricted (3), the angle matrix /
  csi_delta / amplitude / phase sections that carry identity information
  are zeroed before any downstream code sees them.
- AC4 ↑ — demoted frames retain valid CRC; the round-trip-through-bytes
  test proves bit-correctness after the class transition.

Test config:
- cargo test --no-default-features → 31 passed (privacy_gate cfg-out)
- cargo test                       → 60 passed (53 + 7)

Out of scope (next iter target):
- SoulMatchOracle stub trait + no-op default impl (ADR-121 §2.6) so the
  Recalibrate exemption hook is wireable from `--features soul-signature`.
- IdentityRiskEngine — multiplicative formula on (sep, stab, consist, conf)
  with the coherence-gate GateAction enum (ADR-121 §2.2 + §2.4).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p3.2): identity_risk score + GateAction enum — 72/72 GREEN

Iter 10. Lands the stateless half of ADR-121 §2.2–§2.4: the
multiplicative risk-score formula and the 4-band gate classifier.
Hysteresis + 5s debounce (stateful CoherenceGate) land in iter 11.

Added (no_std-compatible):
- src/identity_risk.rs:
  * score(sep, stab, consist, conf) -> f32
    Each input clamped to [0,1]; NaN → 0 (conservative). Multiplicative
    combination: any near-zero factor collapses the score → privacy-biased.
  * Threshold constants: PREDICT_ONLY_THRESHOLD=0.5, REJECT_THRESHOLD=0.7,
    RECALIBRATE_THRESHOLD=0.9
  * GateAction enum: Accept | PredictOnly | Reject | Recalibrate
  * GateAction::from_score(f32) -> Self  — band-based classification with
    inclusive lower edges (0.7 maps to Reject, 0.9 maps to Recalibrate)
  * GateAction::allows_publish() / drops_event() / requires_recalibrate()
- pub use identity_risk_score (the function) and GateAction from lib.rs

tests/identity_risk_score.rs (12 named tests, all green):
  all_ones_yields_one
  any_zero_factor_collapses_score_to_zero (4 single-factor variants)
  score_is_monotonic_non_decreasing_in_single_factor
  out_of_range_inputs_are_clamped_to_unit_interval
  nan_inputs_treated_as_zero (verifies privacy-conservative NaN handling)
  known_score_matches_hand_calculation (0.8*0.9*0.85*0.95 to 1e-6)
  from_score_classifies_each_band (8 boundary-condition checks)
  threshold_constants_match_documented_values
  nan_score_maps_to_accept_conservatively
  allows_publish_partitions_actions_correctly
  drops_event_inverts_allows_publish (parameterized over all 4 actions)
  requires_recalibrate_is_unique_to_recalibrate

ACs progressed:
- ADR-121 AC2 partial — `score` formula structurally enforces non-negativity,
  upper bound 1.0, and conservative behavior under uncertainty (NaN, negative
  input, single near-zero factor).
- ADR-121 AC7 partial — score function is pure / deterministic; identical
  inputs always produce identical outputs (asserted by the known-value test).

Test config:
- cargo test --no-default-features → 43 passed (31 + 12)
- cargo test                       → 72 passed (60 + 12)

Out of scope (next iter target):
- CoherenceGate stateful struct: ±0.05 hysteresis + 5-second debounce
  (ADR-121 §2.5) so the gate doesn't oscillate near band boundaries.
- SoulMatchOracle stub trait (ADR-121 §2.6) — the Recalibrate exemption
  hook for `--features soul-signature` deployments.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p3.3): CoherenceGate hysteresis + 5s debounce — 85/85 GREEN

Iter 11. Wraps the stateless GateAction classifier from iter 10 with two
stabilizing mechanisms per ADR-121 §2.5:

  * ±0.05 HYSTERESIS — a score must clear the current band's edge by
    HYSTERESIS before the gate considers the next band.
  * 5-second DEBOUNCE_NS — a different action must persist that long
    before it becomes current; returning to the current band cancels it.

Added (no_std-compatible):
- src/coherence_gate.rs:
  * HYSTERESIS const (0.05) + DEBOUNCE_NS const (5_000_000_000)
  * CoherenceGate { current, pending: Option<(GateAction, u64)> }
  * new() / Default / current() / pending() (diagnostic accessors)
  * evaluate(score, timestamp_ns) -> GateAction
    Algorithm: compute effective_target via per-direction hysteresis check,
    promote pending after DEBOUNCE_NS elapsed, cancel pending on return to
    current band, reset debounce clock if pending target changes
  * Private helpers effective_target / action_idx / upper_edge_of / lower_edge_of
- pub use CoherenceGate from lib.rs

tests/coherence_gate.rs (13 named tests, all green):
  fresh_gate_starts_in_accept_with_no_pending
  low_score_stays_in_accept_with_no_pending
  score_just_past_boundary_but_within_hysteresis_does_not_pend
    (0.52: above 0.5 but inside hysteresis envelope — no pending)
  score_clearly_past_hysteresis_starts_pending
    (0.6: past 0.55 hysteresis edge — pending PredictOnly registered)
  pending_action_promotes_after_full_debounce
  pending_action_does_not_promote_before_debounce
    (verified at DEBOUNCE_NS - 1)
  returning_to_current_band_cancels_pending
  changing_pending_target_resets_the_debounce_clock
    (PredictOnly pending at t=0, then Recalibrate at t=1s — clock resets,
     must wait until t=1s+DEBOUNCE_NS before Recalibrate is current)
  downward_transitions_also_require_hysteresis
    (from PredictOnly, 0.48 stays put; 0.44 pends Accept)
  spike_to_one_then_back_to_zero_never_promotes_to_recalibrate
    (transient spike + return to baseline produces no transition)
  boundary_value_with_hysteresis_does_not_promote (0.5+0.05-epsilon)
  boundary_value_at_hysteresis_exact_does_pend (0.5+0.05)
  nan_score_stays_in_current_action_with_no_pending

ACs progressed:
- ADR-121 AC4 — Recalibrate fires when score >= 0.9 for >= DEBOUNCE_NS (5s).
  The debounce test above directly exercises this.
- ADR-121 AC5 — hysteresis test confirms action does not oscillate across
  ± 0.05 of a threshold within a 5-second window.

Test config:
- cargo test --no-default-features → 56 passed (43 + 13)
- cargo test                       → 85 passed (72 + 13)

Out of scope (next iter target):
- SoulMatchOracle stub trait (ADR-121 §2.6) + Recalibrate exemption —
  when --features soul-signature is enabled and the oracle reports a known
  enrolled person_id match, the gate downgrades Recalibrate → PredictOnly.
- BfldEvent struct (ADR-121 §2.1 output event) — first downstream consumer
  of the gate action.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p3.4): SoulMatchOracle + Recalibrate exemption (93/93 GREEN)

Iter 12. Wires the ADR-121 §2.6 Recalibrate exemption: when an enrolled
person_id matches the current high-separability cluster, the gate
downgrades the would-be Recalibrate to PredictOnly. The high score is
the *intended* outcome of a Soul Signature match, not an attacker-grade
sniffer arrival — so site_salt rotation is suppressed.

Added (no_std-compatible):
- src/coherence_gate.rs additions:
  * MatchOutcome enum: Match { person_id: u64 } | NotEnrolled | Suppressed
  * SoulMatchOracle trait with matches_enrolled() -> MatchOutcome
  * NullOracle (default-constructible, always reports NotEnrolled)
  * CoherenceGate::evaluate_with_oracle(score, ts, &O: SoulMatchOracle)
    — same hysteresis/debounce as evaluate(), but downgrades Recalibrate
    to PredictOnly when oracle returns Match { .. }
  * Refactored evaluate(): extracted advance_state(target, ts) shared with
    evaluate_with_oracle. evaluate is now a 4-line wrapper.
- pub use MatchOutcome, NullOracle, SoulMatchOracle from lib.rs

tests/soul_match_oracle.rs (8 named tests, all green):
  null_oracle_matches_default_evaluate_behavior
    (parameterized over 5 score points; oracle-aware and oracle-free
     gates produce identical trajectories)
  match_outcome_downgrades_recalibrate_to_predict_only
    (score=0.95 pends PredictOnly instead of Recalibrate)
  match_exemption_promotes_predict_only_after_debounce_not_recalibrate
    (after DEBOUNCE_NS, current is PredictOnly — never Recalibrate)
  match_outcome_does_not_affect_lower_actions
    (Reject pending stays Reject; oracle only intercepts Recalibrate)
  suppressed_outcome_does_not_exempt_recalibrate
    (Suppressed is functionally equivalent to NotEnrolled at the gate)
  not_enrolled_outcome_does_not_exempt_recalibrate
  match_outcome_carries_person_id
  null_oracle_default_constructor_works

ACs progressed:
- ADR-121 §2.6 fully covered as a stateless integration point — the
  hook is in place for the `--features soul-signature` Soul Signature
  crate (TBD) to plug in a real RaBitQ-backed oracle.
- ADR-118 §1.4 Soul Signature companion contract is now structurally
  enforced at the gate boundary: enrolled subjects do not trigger
  site_salt rotation; everyone else does.

Test config:
- cargo test --no-default-features → 64 passed (56 + 8)
- cargo test                       → 93 passed (85 + 8)

Out of scope (next iter target):
- BfldEvent struct (ADR-121 §2.1 output event JSON) — the downstream
  consumer of GateAction. Pairs the gate decision with presence/motion/
  person_count sensing fields.
- Optional: connect SoulMatchOracle into the actual `--features
  soul-signature` build (compile-time gate around a re-export).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p4.1): BfldEvent privacy-gated output + JSON (102/102 GREEN)

Iter 13. Lands ADR-121 §2.1 (output event) + ADR-122 §2.1 (field-gating
policy). BfldEvent collapses the GateAction-driven sensing pipeline
into the canonical wire-format publishable on MQTT.

Added:
- serde (workspace, derive feature, optional) + serde_json (workspace, optional) deps
- New crate feature `serde-json` (default-on; requires `std`)
- src/event.rs (gated on `feature = "std"`):
  * BfldEvent struct with all sensing + identity-derived fields
  * with_privacy_gating(...) constructor that applies field-gating policy:
      class < Restricted (3): identity_risk_score + rf_signature_hash kept
      class >= Restricted (3): both nulled to None
  * apply_privacy_gating() — idempotent in-place masking
  * to_json() -> Result<String, serde_json::Error> (gated on serde-json)
  * Custom ser_privacy_class serializer emits lowercase names
    ("anonymous", "restricted", etc.) per the BFLD JSON spec
  * skip_serializing_if = "Option::is_none" on identity-derived fields so
    privacy-gated events are observationally indistinguishable from
    events that never had the field set
- pub use BfldEvent from lib.rs

tests/event_privacy_gating.rs (9 named tests, all green):
  anonymous_event_retains_identity_risk_and_hash
  restricted_event_strips_identity_fields (class 3 → None)
  apply_privacy_gating_is_idempotent
  event_type_is_always_bfld_update (parameterized over 3 classes)
  json::json_round_trip_emits_type_field_first_or_last_but_present
  json::anonymous_json_includes_identity_fields
  json::restricted_json_omits_identity_fields_entirely
    (asserts the JSON string does NOT contain identity_risk_score or
     rf_signature_hash, verifying skip_serializing_if works as intended)
  json::privacy_class_serializes_to_lowercase_name
  json::zone_id_none_is_omitted_from_json

ACs progressed:
- ADR-121 AC6 (identity_risk score absent at class 3) — structurally
  enforced by with_privacy_gating + skip_serializing_if combination.
- ADR-122 AC1 — JSON shape matches the HA-DISCO publishable event
  contract; identity fields can be reliably stripped by privacy_class.
- ADR-118 AC5 — privacy_mode = engaged maps to PrivacyClass::Restricted
  with no identity fields in the published event.

Test config:
- cargo test --no-default-features → 64 passed (unchanged; event cfg-out)
- cargo test                       → 102 passed (93 + 9)

Out of scope (next iter target):
- Emitter struct that wires GateAction + privacy class + sensing inputs
  into BfldEvent construction (ADR-118 §2.1 pipeline diagram).
- MQTT topic publisher (ADR-122 §2.2) — depends on a runtime (tokio).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p4.2): BfldEmitter end-to-end pipeline (109/109 GREEN)

Iter 14. Wires every iter-1..13 primitive into a single ADR-118 §2.1
pipeline: per-frame sensing inputs go in, a privacy-gated BfldEvent
(or None) comes out. First time every constituent is exercised together.

Added (gated on `feature = "std"`):
- src/emitter.rs:
  * SensingInputs struct — 11 fields: timestamp_ns, presence, motion,
    person_count, sensing_confidence, sep, stab, consist, risk_conf,
    rf_signature_hash (Option)
  * BfldEmitter struct owning: node_id, default_zone_id, privacy_class,
    CoherenceGate, EmbeddingRing
  * Builder API: new(node_id) → with_zone(...) → with_privacy_class(...)
  * current_action() / ring_len() diagnostic accessors
  * emit(inputs, embedding) → Option<BfldEvent>
      1. score = identity_risk::score(sep, stab, consist, risk_conf)
      2. ring.push(embedding) if Some
      3. action = gate.evaluate_with_oracle(score, ts, &NullOracle)
      4. if action == Recalibrate { ring.drain() }
      5. if action.drops_event() { return None }
      6. else BfldEvent::with_privacy_gating(...) honoring privacy_class
  * emit_with_oracle(...) variant for `--features soul-signature` callers
- pub use BfldEmitter, SensingInputs from lib.rs

tests/emitter_pipeline.rs (7 named tests, all green):
  emitter_emits_event_under_low_risk
  emitter_drops_event_under_sustained_high_risk (debounce honored)
  emitter_drains_ring_on_recalibrate
    (fills ring to 5, then Recalibrate-grade score → ring_len() == 0)
  restricted_class_strips_identity_fields_in_emitted_event
    (class 3: identity_risk_score AND rf_signature_hash both None)
  with_zone_sets_default_zone_id_on_event
  embedding_is_pushed_to_ring_even_when_event_dropped
    (privacy gating drops the event but the ring still observes the
     embedding so subsequent separability calculations remain valid)
  ring_unchanged_when_no_embedding_supplied

ACs progressed:
- ADR-118 AC1 (BFLD core pipeline integration) — every component from
  iter 1 (frame format) through iter 13 (event) is now traversed by a
  single emit() call. This is the first end-to-end smoke proof.
- ADR-121 AC4 — Recalibrate-grade sustained score triggers ring drain
  (verified by ring_len() going from 5 to 0).
- ADR-122 AC1 — privacy_class threaded through the pipeline so the
  output event is correctly gated for HA/Matter consumption.

Test config:
- cargo test --no-default-features → 64 passed (emitter cfg-out)
- cargo test                       → 109 passed (102 + 7)

Out of scope (next iter target):
- Wiring rf_signature_hash computation from BLAKE3-keyed(site_salt,
  features) per ADR-120 §2.3 — the SensingInputs.rf_signature_hash
  is supplied by caller for now; needs a SignatureHasher with site_salt
  initialization in a follow-up iter.
- Embedding ring → identity_separability_score derivation (currently
  `sep` is caller-supplied; should be computed from ring contents).
- MQTT topic publisher wrapping BfldEmitter (ADR-122 §2.2) — depends
  on a runtime (tokio).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p3.5): SignatureHasher (BLAKE3-keyed) — 117/117 GREEN

Iter 15. Lands ADR-120 §2.3 — the cryptographic foundation of invariant
I3 ("cross-site identity correlation is impossible"). rf_signature_hash
is now derived from a per-site secret and a daily epoch, so two nodes
observing the same physical person produce uncorrelated 256-bit digests.

Added (no_std-compatible):
- blake3 = "1.5", default-features = false (no_std, no SIMD by default)
- src/signature_hasher.rs:
  * Constants SECONDS_PER_DAY (86_400), SITE_SALT_LEN (32), RF_SIGNATURE_LEN (32)
  * SignatureHasher { site_salt: [u8; 32] } with new(salt) const ctor
  * compute(day_epoch, &features) -> [u8; 32]  (BLAKE3 keyed mode)
  * compute_at(unix_secs, &features) -> [u8; 32] convenience
  * day_epoch_from_unix_secs(unix_secs) -> u32 helper (floor(t / 86400))
- pub use SignatureHasher, RF_SIGNATURE_LEN, SITE_SALT_LEN from lib.rs

tests/signature_hasher.rs (8 named tests, all green):
  deterministic_under_identical_inputs
  different_site_salts_produce_different_hashes
  different_day_epochs_rotate_the_hash
  different_features_produce_different_hashes
  output_length_is_32_bytes
  day_epoch_from_unix_secs_matches_floor_division
    (covers 0, 86_399, 86_400, and the 1.7e9 modern timestamp)
  compute_at_matches_compute_with_derived_day
  cross_site_hamming_distance_is_statistically_high
    *** ADR-120 §2.7 AC2 acceptance test ***
    Runs 100 trials with distinct (salt_a, salt_b) pairs observing
    identical features, computes per-trial Hamming distance, asserts
    mean >= 120 bits and min >= 80 bits. Empirically lands at ~128 bits
    mean (the expected value for two independent 256-bit hashes), with
    no trial below 80 bits — i.e., zero suspicious near-collisions.

ACs progressed:
- ADR-120 §2.7 AC2 — structurally enforced cross-site isolation, now
  proven empirically by the Hamming-distance test. This is the
  cryptographic half of invariant I3 in code, not just docs.
- ADR-118 invariant I3 — first runtime witness that two sites with
  independent site_salts cannot correlate the same person's signature.

Test config:
- cargo test --no-default-features → 72 passed (64 + 8; signature_hasher is no_std)
- cargo test                       → 117 passed (109 + 8)

Out of scope (next iter target):
- Wire SignatureHasher into BfldEmitter: replace caller-supplied
  rf_signature_hash with hasher.compute_at(ts, &features) so the
  pipeline produces correct hashes end-to-end.
- IdentityFeatures canonical-bytes encoder so callers don't need to
  hand-serialize per-feature representations.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p4.3): wire SignatureHasher into BfldEmitter (123/123 GREEN)

Iter 16. End-to-end ADR-120 §2.3 wiring: BfldEmitter now produces
rf_signature_hash derived from (site_salt, day_epoch, features), with
the IdentityEmbedding bytes as the preferred feature source. Closes
the gap from iter 15 — the hasher is now reachable from the pipeline.

Added (in src/emitter.rs):
- BfldEmitter.signature_hasher: Option<SignatureHasher> field
- BfldEmitter::with_signature_hasher(SignatureHasher) -> Self builder
- emit_with_oracle computes derived_hash BEFORE pushing embedding to ring:
    1. unix_secs = inputs.timestamp_ns / NS_PER_SEC
    2. feature bytes: embedding.as_slice() flattened to LE f32 bytes,
       OR fallback canonical_risk_bytes(&inputs) (4-tuple of LE f32)
    3. hasher.compute_at(unix_secs, &bytes)
- Derived hash overrides inputs.rf_signature_hash; when hasher absent
  caller-supplied value passes through unchanged (backward compat)
- canonical_risk_bytes(&inputs) -> [u8; 16] private helper for fallback

tests/emitter_hasher.rs (6 named tests, all green):
  no_hasher_passes_caller_supplied_hash_through
  installed_hasher_overrides_caller_supplied_hash
  same_emitter_same_inputs_produce_same_hash (determinism through emitter)
  different_site_salts_produce_different_hashes_end_to_end
    *** cross-site isolation proven via the BfldEmitter API, not just
        via the SignatureHasher direct API (iter 15) ***
  no_embedding_falls_back_to_risk_factor_bytes
  fallback_hash_differs_from_embedding_hash
    (embedding-based and fallback-based hashes are distinct paths)

ACs progressed:
- ADR-120 §2.7 AC2 — cross-site isolation now provable at the public
  emitter surface, not just inside the hasher module.
- ADR-118 §2.1 pipeline integration — derived rf_signature_hash flows
  through to the BfldEvent without caller participation. Operators
  install the hasher once at boot; per-frame code never sees site_salt.

Test config:
- cargo test --no-default-features → 72 passed (emitter_hasher cfg-out)
- cargo test                       → 123 passed (117 + 6)

Out of scope (next iter target):
- IdentityFeatures struct — typed canonical-bytes encoder so callers
  don't need to know that embedding bytes feed the hasher directly.
- Cross-iter integration test: BfldEmitter → BfldEvent::to_json with
  derived hash, parsed back, hash field present and base64-encoded
  (or hex-encoded) per the JSON wire spec.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p4.4): rf_signature_hash JSON as "blake3:<hex>" (128/128 GREEN)

Iter 17. Lands the BFLD JSON wire spec format for rf_signature_hash —
a "blake3:" prefix followed by 64 lowercase hex chars. Replaces the
default serde array-of-integers encoding which was unusable for
downstream consumers (HA, Matter, MQTT).

Added (in src/event.rs):
- ser_rf_signature_hash<S>(hash: &Option<[u8;32]>, s) custom serializer
- Field attribute on BfldEvent.rf_signature_hash now uses
  serialize_with = "ser_rf_signature_hash" alongside skip_serializing_if
- nibble_to_hex(u8) -> char private const fn (no `hex` crate dep needed
  for 32 bytes; lowercase hex is trivial)
- Output format: "blake3:deadbeef..." exactly 71 ASCII chars

tests/json_hash_format.rs (5 named tests, all green):
  rf_signature_hash_serializes_as_blake3_prefixed_lowercase_hex
    (expected hex built programmatically via format!("{b:02x}"))
  hex_string_is_always_64_chars_when_present
    (parses the JSON, isolates the hash substring, asserts exact 64
     chars and lowercase-only — catches case-folding regressions)
  hash_field_omitted_entirely_when_none
  end_to_end_emitter_hasher_to_json_emits_blake3_hex_hash
    *** Cross-iter integration test: BfldEmitter::with_signature_hasher
        → SensingInputs.rf_signature_hash = None → emit derives via
        BLAKE3 → BfldEvent::to_json → contains "blake3:" prefix.
        Spans iters 13, 14, 15, 16, 17 in a single assertion. ***
  end_to_end_restricted_class_omits_hash_even_with_hasher_set
    (class 3: even with hasher installed, JSON omits the hash)

ACs progressed:
- BFLD wire spec §6 — rf_signature_hash JSON shape now matches the
  documented format ("blake3:..."); HA / Matter consumers can parse
  it without custom byte-array decoding.
- ADR-118 §1 invariant I3 — visibility: the JSON wire form now
  cryptographically tags the hash with its algorithm prefix, so
  consumers can verify they're not parsing a different (weaker)
  hash that a future PR might accidentally substitute.

Test config:
- cargo test --no-default-features → 72 passed (json_hash_format cfg-out)
- cargo test                       → 128 passed (123 + 5)

Out of scope (next iter target):
- IdentityFeatures typed encoder so callers feeding BfldEmitter don't
  need to know that embedding bytes serve as hasher input.
- Replace the manual hex push with `hex::encode` if/when the workspace
  takes on the `hex` crate dep for other reasons; current path saves
  the dep without sacrificing correctness.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p3.6): IdentityFeatures canonical-bytes encoder (137/137 GREEN)

Iter 18. Consolidates the embedding-vs-risk-factor hashing-input
selection behind a single typed API. Replaces the two ad-hoc paths
that lived in emitter.rs through iter 17:
  * inline `emb.as_slice().iter().flat_map(|f| f.to_le_bytes())`
  * private `canonical_risk_bytes(&inputs) -> [u8; 16]`

Added (gated on `feature = "std"`):
- src/identity_features.rs:
  * IdentityFeatures<'a> enum: Embedding(&'a IdentityEmbedding) |
    RiskFactors { sep, stab, consist, conf }
  * from_embedding / from_risk_factors const constructors
  * canonical_byte_len() const fn — no allocation, predicts wire length
  * write_canonical_bytes(&mut Vec<u8>) — reusable-buffer path
  * canonical_bytes() -> Vec<u8> — allocating convenience
  * compute_hash(&SignatureHasher, day_epoch) -> [u8; 32]
  * RISK_FACTOR_BYTES const (= 16)
- pub use IdentityFeatures, RISK_FACTOR_BYTES from lib.rs

Refactor:
- src/emitter.rs: derived_hash now uses
    let features = match &embedding {
        Some(emb) => IdentityFeatures::from_embedding(emb),
        None => IdentityFeatures::from_risk_factors(sep, stab, consist, conf),
    };
    features.compute_hash(h, day_epoch)
  Local canonical_risk_bytes helper removed (superseded).

tests/identity_features_encoder.rs (9 named tests, all green):
  embedding_canonical_length_is_dim_times_four
  risk_factor_canonical_length_is_sixteen_bytes
  embedding_canonical_bytes_match_manual_flatten
  risk_factor_canonical_bytes_match_explicit_le_layout
  write_canonical_bytes_appends_to_existing_buffer
  compute_hash_matches_direct_hasher_invocation
  embedding_and_risk_factors_produce_different_hashes
  iter_16_wire_compat_embedding_path   *** backward-compat regression ***
  iter_16_wire_compat_risk_factor_path *** backward-compat regression ***
    These two tests assert that the refactored encoder produces
    bit-identical hashes to iter 16's inline path. Existing deployed
    nodes upgrading to iter 18 see no rf_signature_hash flip.

ACs progressed:
- ADR-120 §2.3 — features canonical-bytes representation now has a
  single source of truth in the codebase; future feature additions
  pass through one named encoder rather than scattered byte-fiddling.
- ADR-118 invariant I2 — IdentityFeatures borrows &IdentityEmbedding,
  it doesn't take ownership. The embedding's Drop / no-Serialize
  guarantees continue to hold across the canonical-bytes path.

Test config:
- cargo test --no-default-features → 72 passed (identity_features cfg-out)
- cargo test                       → 137 passed (128 + 9)

Out of scope (next iter target):
- Wire IdentityFeatures into a public emitter input path so callers
  can supply pre-constructed IdentityFeatures rather than the bare
  embedding + risk factors. (Soft refactor; current API is sufficient.)
- BfldPipeline facade — single struct combining BfldEmitter +
  BfldFrame producer + MQTT publisher (ADR-118 §2.1 lib.rs entry point).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p4.5): BfldPipeline facade + BfldConfig (146/146 GREEN)

Iter 19. Public lib.rs entry point per ADR-118 §2.1. Thin facade over
BfldEmitter that adds a config-driven builder and a privacy_mode
toggle for emergency demote-to-Restricted without rebuilding the
gate/ring/hasher state.

Added (gated on `feature = "std"`):
- src/pipeline.rs:
  * BfldConfig { node_id, default_zone_id, privacy_class, signature_hasher }
    with new/with_zone/with_privacy_class/with_signature_hasher builder
  * BfldPipeline { baseline_class, privacy_mode, emitter }
  * BfldPipeline::new(config) — initializes the underlying emitter
  * process(inputs, embedding) -> Option<BfldEvent>
    Delegates to emitter.emit() then post-processes: if privacy_mode is
    engaged, demotes the resulting event to Restricted and calls
    apply_privacy_gating to strip identity fields
  * enable_privacy_mode() / disable_privacy_mode() / is_privacy_mode_enabled()
  * current_privacy_class() — returns Restricted when privacy_mode else baseline
  * current_gate_action() — delegate diagnostic
- pub use BfldConfig, BfldPipeline from lib.rs

Design note: the privacy_mode override is applied post-emission, NOT by
rebuilding the emitter. This preserves gate state (current action,
pending transitions), ring contents, and hasher salt across the toggle —
critical for incident response where the operator needs to keep
detecting anomalies while temporarily redacting the public surface.

tests/pipeline_facade.rs (9 named tests, all green):
  config_defaults_to_anonymous_no_zone_no_hasher
  config_builder_methods_chain
  fresh_pipeline_is_not_in_privacy_mode
  pipeline_process_returns_anonymous_event_under_low_risk
  enable_privacy_mode_demotes_published_events_to_restricted
    (verifies BOTH identity_risk_score AND rf_signature_hash become None)
  disable_privacy_mode_restores_baseline_class
    (round-trip: enable → demoted → disable → restored to Anonymous)
  privacy_mode_overrides_derived_baseline_too
    (research-mode operator can still flip the emergency switch)
  pipeline_with_hasher_emits_derived_rf_signature_hash
  zone_is_threaded_from_config_to_event

ACs progressed:
- ADR-118 §2.1 — public entry point now matches the implementation
  plan §1.2 sketch: BfldPipeline::new(config) → process() → BfldEvent.
  Future iters add process_to_frame() and the tokio MQTT loop.
- ADR-118 §1.5 enable_privacy_mode requirement — operator can engage
  Restricted-class redaction without restarting the pipeline or
  losing in-flight detection state. First runtime witness of this.

Test config:
- cargo test --no-default-features → 72 passed (pipeline cfg-out)
- cargo test                       → 146 passed (137 + 9)

Out of scope (next iter target):
- process_to_frame(inputs, payload, embedding) -> Option<BfldFrame>
  for callers that need wire-format bytes rather than JSON events.
- BfldPipelineHandle wrapping the pipeline in Arc<Mutex<...>> + a
  tokio task that pumps an MQTT loop (ADR-122 §2.2 emitter half).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p4.6): BfldPipeline::process_to_frame wire-bytes path (152/152 GREEN)

Iter 20. Adds the wire-bytes companion to BfldPipeline::process so
callers needing BfldFrame (for ESP-NOW, UDP, file dump, witness
bundles, etc.) don't have to drop down to BfldEmitter + manual
BfldFrame construction.

Added (in src/pipeline.rs):
- BfldPipeline::process_to_frame(
      inputs: SensingInputs,
      header_template: BfldFrameHeader,
      payload: BfldPayload,
      embedding: Option<IdentityEmbedding>,
  ) -> Option<BfldFrame>

  Algorithm:
    1. Cache timestamp_ns from inputs (consumed by the inner process()).
    2. Call self.process(inputs, embedding) — gate logic decides drop/emit.
       Returns None if the gate rejects, propagating to caller.
    3. Clone header_template, override timestamp_ns and privacy_class from
       the current pipeline state (privacy_mode-aware).
    4. Build via BfldFrame::from_payload — CRC covers the section-prefixed
       payload bytes per ADR-119 §2.2.

  Separation of concerns: pipeline owns gate / ring / hasher state; caller
  owns AP / STA / session identity (provided via header_template).

tests/pipeline_to_frame.rs (6 named tests, all green):
  process_to_frame_emits_frame_under_low_risk
    (timestamp_ns + privacy_class correctly propagated from pipeline)
  process_to_frame_returns_none_under_sustained_high_risk
    (gate Reject path: two consecutive high-risk calls → None)
  process_to_frame_round_trips_through_bytes
    (frame.to_bytes() → BfldFrame::from_bytes() → parse_payload() identity)
  process_to_frame_overrides_class_in_privacy_mode
    (enable_privacy_mode → frame.header.privacy_class = Restricted byte)
  process_to_frame_preserves_header_template_identity_fields
    (ap_hash, sta_hash, session_id, channel from template survive)
  process_to_frame_uses_input_timestamp_not_template_timestamp
    (template.timestamp_ns = 12345 is overridden by inputs.timestamp_ns)

ACs progressed:
- ADR-118 §2.1 wire-bytes consumer path now reachable from BfldPipeline,
  not just from low-level BfldEmitter + manual frame construction.
- ADR-119 AC5/AC6 — round-trip-through-bytes test exercises the full
  pipeline+frame stack, not just the frame in isolation.
- ADR-122 §2.2 prep — the BfldFrame is the wire format MQTT eventually
  publishes via tokio loop (next iter pair); process_to_frame is the
  per-frame producer that loop will call.

Test config:
- cargo test --no-default-features → 72 passed (pipeline_to_frame cfg-out)
- cargo test                       → 152 passed (146 + 6)

Out of scope (next iter target):
- BfldPipelineHandle: Arc<Mutex<BfldPipeline>> + tokio task that pumps
  an inbound (SensingInputs, IdentityEmbedding) channel into MQTT
  per-class topics (ADR-122 §2.2). Brings in tokio + rumqttc deps
  behind a `mqtt` feature.
- Cargo benchmark: pipeline throughput target ≥ 40 frames/sec on a
  Pi 5 core (ADR-118 §6 P2 effort estimate).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p5.1): MQTT topic router (BfldEvent → Vec<TopicMessage>) — 162/162 GREEN

Iter 21. Lands ADR-122 §2.2 topic shape + class-gated routing as a pure
function. No broker dep yet — that lands in iter 22 with tokio + rumqttc
behind an `mqtt` feature. This iter is the routing policy, separated for
testability.

Added (gated on `feature = "std"`):
- src/mqtt_topics.rs:
  * TopicMessage { topic: String, payload: String }
  * TopicMessage::ruview_topic(node, entity) builds the canonical
    `ruview/<node>/bfld/<entity>/state` shape
  * render_events(&BfldEvent) -> Vec<TopicMessage>:
      class < Anonymous (0/1): returns empty (raw/derived are local only)
      class >= Anonymous (2/3): emits presence + motion + person_count +
        confidence, plus zone_activity if zone_id set
      class == Anonymous (2) ONLY: also emits identity_risk
      class == Restricted (3): identity_risk is suppressed even with score
- pub use render_events, TopicMessage from lib.rs

Payload encoding:
- presence:     "true" | "false"
- motion:       "{:.6}" — fixed-precision decimal in [0.0, 1.0]
- person_count: bare integer string
- confidence:   "{:.6}"
- zone_activity: JSON-string with quotes — "\"living_room\""
- identity_risk: "{:.6}"

tests/mqtt_topic_routing.rs (10 named tests, all green):
  topic_format_is_ruview_node_bfld_entity_state
  anonymous_class_publishes_six_topics_with_zone
    (6 = presence/motion/count/conf/zone/identity_risk)
  anonymous_class_without_zone_omits_zone_activity_topic (5 topics)
  restricted_class_omits_identity_risk_topic (class 3 → 5 topics, no risk)
  raw_and_derived_classes_publish_nothing
    *** structural enforcement of "raw stays local" at the topic layer ***
  presence_payload_is_lowercase_json_bool
  motion_payload_is_fixed_precision_decimal
  person_count_payload_is_bare_integer
  zone_payload_is_json_string_with_quotes
  identity_risk_payload_is_fixed_precision_decimal

ACs progressed:
- ADR-122 §2.2 topic shape now matches the documented format byte-for-byte.
- ADR-122 AC4 — per-class topic gating: classes 2 / 3 publish disjoint
  sets, with identity_risk uniquely guarded.
- ADR-118 invariant I1 reaching the public surface — Raw frames produce
  zero topic messages, so even a buggy publisher loop cannot leak them.

Test config:
- cargo test --no-default-features → 72 passed (mqtt_topics cfg-out)
- cargo test                       → 162 passed (152 + 10)

Out of scope (next iter target):
- tokio + rumqttc behind a new `mqtt` feature gate
- BfldPipelineHandle: Arc<Mutex<BfldPipeline>> + a tokio task that pumps
  inbound SensingInputs, runs render_events on each emitted BfldEvent,
  and calls client.publish() for each TopicMessage
- mosquitto integration test pattern (cf. feedback_mqtt_integration_test_patterns
  memory: per-test client_id, pump until SubAck, wait for publisher discovery)

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p5.2): Publish trait + publish_event free function — 169/169 GREEN

Iter 22. Abstracts the MQTT publish boundary without pulling in tokio or
rumqttc yet. The trait is sync (callers can hold &mut self without an
async runtime); the production rumqttc-backed impl in iter 23 will drive
a tokio task internally and present the same sync surface here.

Added (in src/mqtt_topics.rs, gated on `feature = "std"`):
- Publish trait with associated Error type
- CapturePublisher (Vec-backed; default-constructible) for unit tests
- publish_event<P: Publish>(publisher, event) -> Result<usize, P::Error>
    Iterates render_events(event) and forwards each TopicMessage to
    publisher.publish(). Returns the count actually published, or the
    publisher's error short-circuited on first failure.
- pub use Publish, CapturePublisher, publish_event from lib.rs

tests/mqtt_publish_loop.rs (7 named tests, all green):
  capture_publisher_records_every_message
  publish_returns_zero_for_raw_and_derived_events
    (parameterized — class 0 and class 1 both produce zero publishes,
     reinforcing the invariant I1 surface enforcement from iter 21)
  published_topics_match_render_events_ordering
    (stable per-event topic sequence for MQTT consumers)
  restricted_class_publishes_no_identity_risk_topic
  anonymous_without_zone_publishes_five_messages (5 = no zone_activity)
  publisher_error_short_circuits_publish_event
    (FailingPublisher fails on 3rd publish; publish_event surfaces the
     error AND leaves the first two messages durably published)
  capture_publisher_error_type_is_infallible
    (compile-time witness that CapturePublisher cannot panic the loop)

ACs progressed:
- ADR-122 §2.2 publisher boundary — the broker-facing surface is now a
  named trait operators can mock, swap, or wrap with retries.
- ADR-122 AC4 — publish_event respects the iter-21 class gating; Raw /
  Derived events produce zero broker traffic by definition.
- ADR-118 invariant I1 — even if the broker connection somehow regressed,
  the trait-level publish_event cannot exfiltrate a Raw frame because
  render_events returns empty first.

Test config:
- cargo test --no-default-features → 72 passed (mqtt_publish_loop cfg-out)
- cargo test                       → 169 passed (162 + 7)

Out of scope (next iter target):
- New `mqtt` feature gate; tokio + rumqttc deps under it
- RumqttPublisher: impl Publish that holds an MqttClient + a small tokio
  block_on or oneshot send to bridge sync trait to async client
- Optional: BfldPipelineHandle that owns Arc<Mutex<BfldPipeline>> + a
  spawn-and-forget tokio task pumping inbound (inputs, embedding) →
  process → publish_event(&rumqtt_pub, &event)
- mosquitto integration test following the patterns from
  feedback_mqtt_integration_test_patterns memory note

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p5.3): RumqttPublisher behind mqtt feature gate (176/176 GREEN with mqtt)

Iter 23. Production Publish trait impl using rumqttc 0.24 (same crate
version + use-rustls feature pinning as wifi-densepose-sensing-server,
so both publishers can share broker connection posture).

Added:
- rumqttc = "0.24" optional dep (default-features = false, use-rustls)
- New `mqtt` cargo feature: ["std", "dep:rumqttc"]
- src/rumqttc_publisher.rs (gated on `feature = "mqtt"`):
  * RumqttPublisher wrapping rumqttc::Client + QoS + retain flag
  * RumqttPublisher::new(client, qos) const constructor
  * with_retain(bool) builder for availability-style topics
  * RumqttPublisher::connect(opts, capacity) -> (Self, Connection)
    Returns the unpumped Connection — caller spawns a thread that
    iterates connection.iter() to drive the MQTT protocol. Default
    QoS is AtLeastOnce (HA-DISCO recommendation for state topics).
  * impl Publish with Error = rumqttc::ClientError
- pub use RumqttPublisher from lib.rs

tests/rumqttc_publisher_smoke.rs (7 named tests, all green, gated on mqtt):
  rumqttc_publisher_constructs_without_broker
    (uses 127.0.0.1:1 — reserved port refuses immediately; no hang)
  with_retain_builder_yields_a_publisher
  publish_queues_message_without_blocking_on_broker_state
    *** Critical property: rumqttc's sync Client::publish queues into
        an unbounded channel; publish_event returns Ok without round-
        tripping to the (offline) broker. The queued packet only sends
        if a thread iterates Connection::iter(). ***
  restricted_event_publishes_four_messages_through_rumqttc
    (class 3 + no zone: presence/motion/count/confidence — 4 topics)
  publisher_trait_object_is_constructible
    (Box<dyn Publish<Error = rumqttc::ClientError>> works)
  direct_publish_call_through_trait_object
  default_qos_is_at_least_once_via_connect

ACs progressed:
- ADR-122 §2.2 broker integration — production publisher now wired,
  matching the sensing-server's TLS / version posture. The two
  crates can share a single broker connection if an operator wants
  both publishers in the same process.
- ADR-122 AC4 still enforced — publish_event's class-gated routing
  is upstream of rumqttc, so no broker-level config can leak Raw frames.

Test config:
- cargo test --no-default-features → 72 passed (mqtt feature off)
- cargo test                       → 169 passed (mqtt feature off)
- cargo test --features mqtt --test rumqttc_publisher_smoke → 7 passed
- With --features mqtt: 169 + 7 = 176 total

Out of scope (next iter target):
- mosquitto integration test (env-gated MQTT_BROKER=tcp://localhost:1883):
    * spawn a thread iterating Connection::iter()
    * publish a BfldEvent
    * subscribe in the test, await SubAck per the workspace memory note
      `feedback_mqtt_integration_test_patterns`
    * assert the topics received match render_events output
- BfldPipelineHandle: Arc<Mutex<BfldPipeline>> with a thread that pumps
  inbound (inputs, embedding) → process → publish_event(&rumqttc_pub, &event)
  for a single-call "set up MQTT publisher and walk away" API.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p5.4): mosquitto integration test (env-gated, 178/178 with mqtt)

Iter 24. Live-broker roundtrip test for the RumqttPublisher → mosquitto
→ subscriber path. CI-safe: silently skips when BFLD_MQTT_BROKER is
unset; opt-in locally with:

    scoop install mosquitto
    mosquitto -v -c mosquitto-allow-anon.conf &
    BFLD_MQTT_BROKER=tcp://localhost:1883 cargo test \
        -p wifi-densepose-bfld --features mqtt --test mosquitto_integration

Added (gated on `feature = "mqtt"`):
- tests/mosquitto_integration.rs:
  * broker_env() parses BFLD_MQTT_BROKER as tcp://host:port (default 1883)
  * unique_client_id(prefix) — nanosecond-suffix per-test, per the
    `feedback_mqtt_integration_test_patterns` memory note
  * spawn_subscriber() creates a Client + thread iterating Connection;
    drains incoming Publish into an mpsc channel and emits a oneshot on
    SubAck arrival
  * collect_messages(rx, expected_count, timeout) — bounded recv loop
    that respects a wall-clock deadline (no `loop { iter.recv() }`)
  * Two named tests:

      live_broker_anonymous_event_roundtrips_all_six_topics
        Subscribe to ruview/<node>/bfld/+/state with the wildcard, await
        SubAck, publish an Anonymous event with zone, collect 6 messages,
        assert every expected entity name appears exactly once.

      live_broker_restricted_event_omits_identity_risk
        Same setup, publish a Restricted event, collect up to 6 (will
        only see 5), assert identity_risk is absent.

Test discipline (per the workspace memory):
  - per-test unique client_id (prevents broker session collisions)
  - subscriber eventloop pumped until SubAck BEFORE publishing
  - explicit timeout instead of infinite recv (no test hangs on misconfig)
  - publisher Connection drained in its own thread (rumqttc requirement)
  - 200ms sleep between publisher construction and first publish to let
    CONNECT complete (otherwise messages are queued before the session
    is open, and mosquitto silently drops them in some configurations)

When BFLD_MQTT_BROKER is unset:
  - broker_env() returns None
  - Test prints a one-line skip message to stderr and returns Ok(())
  - Both tests show as passing in cargo output

ACs progressed:
- ADR-122 AC1 end-to-end demonstrable — when a broker is available,
  the test proves a BfldEvent traverses RumqttPublisher, the network,
  and an MQTT subscriber, arriving with the correct topic shape and
  payload encoding.
- ADR-122 AC4 enforced over the wire — the Restricted-class test
  proves identity_risk does not even reach the broker, not just that
  it's stripped at render_events.

Test config:
- cargo test --no-default-features → 72 passed
- cargo test                       → 169 passed
- cargo test --features mqtt       → 178 passed (176 + 2 skip-mode tests)

Out of scope (next iter target):
- BfldPipelineHandle: Arc<Mutex<BfldPipeline>> + a worker thread that
  pumps inbound (SensingInputs, IdentityEmbedding) channel into MQTT.
  Single-call "set up publisher and walk away" API for operators.
- CI workflow that starts mosquitto in a Docker service container and
  sets BFLD_MQTT_BROKER so the integration test actually runs.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p5.5): BfldPipelineHandle worker thread (177/177 GREEN)

Iter 25. Single-call operator surface: spawn() takes a BfldPipeline and
a Publish impl, returns a handle whose send() enqueues sensing inputs
into a worker thread. The worker drives pipeline.process() then
publish_event() per input. Drop or shutdown() joins cleanly.

Added (gated on `feature = "std"`):
- src/mqtt_topics.rs: impl<P: Publish> Publish for Arc<Mutex<P>>
  Lets a publisher owned by a worker thread remain inspectable from a
  test or operator post-shutdown.
- src/pipeline_handle.rs:
  * PipelineInput { inputs: SensingInputs, embedding: Option<...> }
  * BfldPipelineHandle { sender, worker: Option<JoinHandle<()>> }
  * spawn<P: Publish + Send + 'static>(pipeline, publisher) -> Self
      Worker loop: recv() → pipeline.process() → publish_event(); errors
      logged to stderr (single-frame failures must not kill the loop)
  * send(PipelineInput) -> Result<(), SendError<...>>
  * shutdown(self) — replaces sender with a dropped channel so worker
    recv() returns Err(RecvError); join propagates worker panics
  * Drop impl mirrors shutdown so forgotten handles still clean up
- pub use BfldPipelineHandle, PipelineInput from lib.rs

tests/pipeline_handle_worker.rs (8 named tests, all green):
  handle_publishes_single_input (5 topics for Anonymous + no zone)
  handle_publishes_multiple_inputs_in_order (3 × 5 = 15 topics)
  handle_send_after_shutdown_errors
    (compile-time witness: shutdown(self) consumes the handle so
     post-shutdown send() is structurally impossible)
  handle_drop_without_explicit_shutdown_joins_worker_cleanly
    (validates the Drop path completes without hanging)
  handle_honors_privacy_mode_toggle_via_pipeline_state
    (4 topics for Restricted; identity_risk absent)
  handle_drops_event_when_gate_rejects
    (5 topics from first Accept-state input + 0 from Reject)
  handle_with_zone_threads_through_to_published_topics
    (zone_activity payload = "\"kitchen\"")
  class_3_pipeline_baseline_produces_four_topics_per_input

Test publisher pattern: Arc<Mutex<CapturePublisher>> lets the test thread
read out the worker thread's publish log post-shutdown without needing
custom channel plumbing per test.

ACs progressed:
- ADR-118 §2.1 lib.rs entry point now has the "set up MQTT and walk away"
  operator surface promised in the implementation plan. Two lines:
      let handle = BfldPipelineHandle::spawn(pipeline, rumqttc_pub);
      handle.send(PipelineInput { inputs, embedding })?;
- ADR-122 §2.2 per-frame publish path is now structurally guarded by
  worker-thread isolation: even if a Publish::publish call panics, only
  the worker thread dies; the main thread sees a clean error on send().

Test config:
- cargo test --no-default-features → 72 passed
- cargo test                       → 177 passed (169 + 8)
- cargo test --features mqtt       → 186 (178 + 8 — handle is std-only,
  reachable in both feature configs)

Out of scope (next iter target):
- GitHub Actions workflow with mosquitto Docker service so the iter-24
  integration test actually runs in CI with BFLD_MQTT_BROKER set.
- HA discovery payload publisher (ADR-122 §2.1) — the auto-discovery
  config messages HA needs alongside the state topics this handle ships.

Co-Authored-By: claude-flow <ruv@ruv.net>

* docs+plugins: rvAgent + RVF agentic-flow integration exploration

Land the rvAgent (vendor/ruvector/crates/rvAgent/) integration research
dossier and update both the Claude Code and Codex plugins so future
operators have a discoverable entry point for prototyping agentic flows
on top of RuView's existing sensing pipeline + RVF cognitive containers.

Added:
- docs/research/rvagent-rvf-integration/README.md
  Full integration thesis: rvAgent's 8 crates + 14 middlewares share
  RVF as their state-persistence format with RuView's existing
  v2/crates/wifi-densepose-sensing-server/src/rvf_container.rs. Three
  shippable touchpoints (each independent):
    1. Two new RVF segment types (SEG_AGENT_STATE = 0x08,
       SEG_DECISION = 0x09) so rvAgent sessions and RuView sensing
       sessions interleave in one witness-bundle-attestable blob
    2. BfldEvent → ToolOutput shim — agent reads BFLD events as
       tool context with no new IPC
    3. cog-* subagent registration under a queen-agent router
  Open questions: workspace inclusion path, sync/async adapter
  placement, privacy-class composition with rvagent-middleware
  sanitizer, Soul Signature ↔ SoulMatchOracle bridge, MCP surface.
  Proposed next: ADR-124 before scaffolding wifi-densepose-agent.

- plugins/ruview/skills/ruview-rvagent/SKILL.md
  New Claude Code skill exposing the integration surface, links to
  the research doc, and lists the three shippable touchpoints. Skill
  description tuned so Claude auto-discovers it for queries like
  "wire rvAgent into RuView" or "operator agent reacting to BFLD."

- plugins/ruview/codex/prompts/ruview-rvagent.md
  Codex counterpart prompt with trigger phrasing, reading order,
  same three touchpoints + open questions, and the ADR-124 next step.

Modified:
- plugins/ruview/.claude-plugin/plugin.json
  Version 0.1.0 → 0.2.0; description extended to mention "BFLD
  privacy layer" and "rvAgent + RVF agentic flows".

- plugins/ruview/codex/AGENTS.md
  Prompt table grows one row: `ruview-rvagent` for the new prompt.

No code changes; no test impact.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p5.6): HA auto-discovery payload publisher (187/187 GREEN)

Iter 26. Lands ADR-122 §2.1 HA-DISCO config-message generator.
Counterpart to iter 21's state-topic router: this produces the
homeassistant/<type>/<unique_id>/config messages HA reads on
startup to auto-create the six BFLD entities as a single device.

Discovery payloads are intended to be published once per node
session with retain = true (so HA finds them on subsequent starts).
The RumqttPublisher from iter 23 already exposes with_retain(true)
for this purpose; the state-topic loop must keep retain = false to
avoid stale-state flapping.

Added (gated on `feature = "std"`):
- src/ha_discovery.rs:
  * render_discovery_payloads(node_id, class) -> Vec<TopicMessage>
      class < Anonymous: empty vec (HA doesn't see raw/derived)
      class == Anonymous: 6 entities incl. identity_risk
      class == Restricted: 5 entities, no identity_risk
  * Per-entity HA metadata:
      presence       binary_sensor, device_class: occupancy
      motion         sensor, entity_category: diagnostic
      person_count   sensor, unit_of_measurement: people
      zone_activity  sensor, entity_category: diagnostic
      confidence     sensor, entity_category: diagnostic
      identity_risk  sensor, entity_category: diagnostic
  * Each payload carries:
      name, unique_id, state_topic (pointing at the iter-21 path),
      device block with identifiers / model: "BFLD" / manufacturer: "RuView"
  * Manual JSON builder with minimal escape coverage — node_id is
    ASCII alphanumeric + dash by convention; full escape via
    serde_json is a follow-up if operator-controlled names ever land.
- pub use render_discovery_payloads from lib.rs

tests/ha_discovery.rs (10 named tests, all green):
  raw_and_derived_classes_produce_no_discovery_payloads
  anonymous_class_produces_six_discovery_payloads
  restricted_class_omits_identity_risk_discovery
  discovery_topic_format_matches_ha_convention
    (validates all six homeassistant/.../config topics exist)
  presence_payload_carries_occupancy_device_class
  motion_payload_marked_as_diagnostic
  person_count_payload_carries_unit_of_measurement
  every_payload_contains_unique_id_and_state_topic_pointing_at_correct_state_topic
    (the state_topic in the discovery payload must match the topic the
     state-topic router from iter 21 actually publishes on — closes
     the discovery↔state loop)
  unique_id_matches_topic_segment
    (the unique_id baked into the payload equals the topic segment so
     HA dedupe works correctly across reboot/restart)
  class_2_discovery_includes_identity_risk_explicitly

ACs progressed:
- ADR-122 §2.1 — HA auto-discovery surface now complete: an operator
  can start mosquitto, publish-retained discovery once, and HA spins
  up the entire BFLD device on next start with zero YAML config.
- ADR-122 AC1 (six entities per node) — discovery + state-topic
  publishers are now symmetric: render_discovery_payloads emits the
  same six entity definitions render_events emits state messages for.
- ADR-118 §1.5 — privacy_mode = Restricted strips identity_risk at
  BOTH the discovery layer (entity not advertised to HA) AND the
  state layer (no state messages). Two-layer defense.

Test config:
- cargo test --no-default-features → 72 passed (ha_discovery cfg-out)
- cargo test                       → 187 passed (177 + 10)

Out of scope (next iter target):
- HA discovery + state publish coordinator: a small function or
  BfldPipelineHandle::publish_discovery(&mut self, retained: bool)
  that calls render_discovery_payloads + publish_event(retained=true)
  once at startup, then enters the per-frame loop.
- GitHub Actions workflow with mosquitto Docker service so the
  iter-24 integration test runs in CI with BFLD_MQTT_BROKER set.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p5.7): publish_discovery bootstrap helper (193/193 GREEN)

Iter 27. The free function that closes the discovery ↔ state loop on
the publishing side. Mirrors publish_event from iter 22 but for the
HA-DISCO config payloads from iter 26.

Added (in src/ha_discovery.rs, gated on `feature = "std"`):
- publish_discovery<P: Publish>(publisher, node_id, class) -> Result<usize, P::Error>
    Renders the per-class discovery payloads (iter 26) and forwards
    each through publisher.publish(). Returns the count or short-
    circuits on first error.
  Docstring documents the canonical bootstrap pattern: separate
  retain-true publisher for discovery, retain-false publisher for state,
  both sharing the same broker connection if desired.
- pub use publish_discovery from lib.rs

tests/ha_discovery_publish.rs (6 named tests, all green):
  publish_discovery_returns_six_for_anonymous_class
  publish_discovery_returns_five_for_restricted_class
    (no identity_risk in captured topics)
  publish_discovery_returns_zero_for_raw_and_derived
    (HA-DISCO + class gating composition: raw / derived never
     advertised to HA)
  publish_discovery_topics_are_homeassistant_config_format
  publish_discovery_short_circuits_on_publisher_error
    (FailingPub fails on 4th publish; first 3 messages land, then error)
  bootstrap_pattern_publishes_discovery_then_state_through_shared_publisher
    *** End-to-end bootstrap proof: one Arc<Mutex<CapturePublisher>>
        used for both discovery (publish_discovery) and state
        (BfldPipelineHandle::spawn + send). Asserts:
          - 6 + 5 = 11 messages captured in order
          - First 6 topics are homeassistant/.../config
          - Next 5 topics are ruview/<node>/bfld/.../state
        Validates the iter-25 Arc<Mutex<P>> Publish adapter + iter-26
        discovery + iter-27 bootstrap helper compose correctly. ***

ACs progressed:
- ADR-122 §2.1 — bootstrap surface complete. Operator writes one
  publish_discovery call at startup, then BfldPipelineHandle::send for
  every frame. HA finds the device on first restart after discovery
  was retained on the broker.
- ADR-122 AC1 (six entities per node) — discovery and state phases
  share the same six-entity definition; the bootstrap test proves they
  reach the broker in the documented order.

Test config:
- cargo test --no-default-features → 72 passed (publish_discovery cfg-out)
- cargo test                       → 193 passed (187 + 6)

Out of scope (next iter target):
- GitHub Actions workflow with mosquitto Docker service. Without this
  the iter-24 live integration test stays in skip mode in CI; with it,
  every PR would prove the full publish_discovery + handle stack works
  end-to-end against a real broker.
- HA blueprint shipping (ADR-122 §2.6): three operator-ready YAML
  blueprints (presence-driven lighting / motion-aware HVAC / identity-
  risk anomaly notification) packaged in cog-ha-matter/blueprints/.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p5.8): availability topic + LWT integration (203/203 GREEN)

Iter 28. Closes the per-node lifecycle on the MQTT side: HA can now
distinguish a node that is healthy + publishing zero events (nothing
detected) from a node that has lost the broker connection. Discovery
payloads now reference the availability topic so every entity inherits
the device-level offline marker.

Added (gated on `feature = "std"`):
- src/availability.rs:
  * PAYLOAD_AVAILABLE = "online", PAYLOAD_NOT_AVAILABLE = "offline"
  * availability_topic(node_id) -> "ruview/<node>/bfld/availability"
  * online_message / offline_message constructors returning TopicMessage
  * publish_availability_online / publish_availability_offline
    bootstrap helpers through Publish trait
- pub use the full availability surface from lib.rs

Discovery integration (src/ha_discovery.rs):
- Every entity config payload now carries:
    "availability_topic": "ruview/<node>/bfld/availability"
    "payload_available":  "online"
    "payload_not_available": "offline"
  HA uses these to grey out entities device-wide when the broker LWT
  fires or the node explicitly publishes "offline" during shutdown.

tests/availability_topic.rs (10 named tests, all green):
  availability_topic_format_matches_documented_path
  online_message_is_retained_friendly_payload
  offline_message_is_retained_friendly_payload
  publish_online_lands_one_message
  publish_offline_lands_one_message
  discovery_payload_includes_availability_topic_field
    (all 6 Anonymous-class discovery payloads carry the field)
  discovery_payload_includes_payload_available_and_not_available_strings
  restricted_class_discovery_still_carries_availability_fields
    (availability is not an identity field; class 3 retains it)
  bootstrap_sequence_online_then_discovery_lands_in_order
    *** End-to-end bootstrap proof: publish_availability_online +
        publish_discovery produces 1 + 6 = 7 messages, "online"
        first, six homeassistant/.../config payloads after. ***
  graceful_shutdown_sequence_publishes_offline_message_last

ACs progressed:
- ADR-122 §2.2 — availability topic now in place. Operators get HA
  online/offline indication without configuring LWT explicitly on
  rumqttc — the offline_message constructor + publish_availability_offline
  cover the explicit-shutdown path. Real LWT wiring (rumqttc's
  MqttOptions::set_last_will) is a follow-up.
- ADR-122 AC1 + AC4 — discovery now includes availability_topic, which
  HA needs to render the device as a unit; iter-26 tests continue to
  pass with the augmented payload (verified by full-suite count: 187 + 10).

Test config:
- cargo test --no-default-features → 72 passed (availability cfg-out)
- cargo test                       → 203 passed (193 + 10)

Out of scope (next iter target):
- Wire rumqttc::MqttOptions::set_last_will(...) so the broker
  auto-publishes "offline" when the TCP session drops; needs a small
  helper on RumqttPublisher to build options with LWT pre-configured.
- GitHub Actions workflow with mosquitto Docker so iter-24 live test
  runs in CI.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p5.9): RumqttPublisher::connect_with_lwt — broker auto-publishes "offline" (220/220 GREEN with mqtt)

Iter 29. Wires rumqttc::MqttOptions::set_last_will so the broker
auto-publishes "offline" on ruview/<node>/bfld/availability (retained,
QoS 1) when the publisher's TCP session drops without a clean
DISCONNECT. Closes the iter-28 lifecycle loop: explicit "online" on
connect + LWT-driven "offline" on session loss + explicit "offline"
on graceful shutdown.

Added (in src/rumqttc_publisher.rs, gated on `feature = "mqtt"`):
- RumqttPublisher::connect_with_lwt(node_id, opts, capacity) -> (Self, Connection)
  Convenience wrapping with_lwt(opts, node_id) then Self::connect(opts, capacity).
- with_lwt(opts, node_id) -> MqttOptions free helper for operators who
  build their own opts (custom TLS, credentials) and want to opt in to
  the LWT without using the connect_with_lwt shortcut.
- rumqttc 0.24 LastWill::new(topic, message, qos, retain) — 4-arg form;
  retain = true so HA sees "offline" on next start even if it was down
  when the session dropped.
- pub use with_lwt, RumqttPublisher from lib.rs

tests/rumqttc_lwt.rs (8 named tests, all green, gated on mqtt):
  with_lwt_returns_options_without_panic
  connect_with_lwt_constructs_publisher_and_connection
  connect_with_lwt_uses_documented_availability_topic
    (constructive proof — both LWT and discovery use the same
     availability_topic() function so they can't drift)
  connect_with_lwt_publisher_still_publishes_state_topics
    (LWT is purely additive — state topics work as before)
  publisher_trait_object_constructible_with_lwt_path
  with_lwt_is_idempotent_against_double_call
    (rumqttc replaces the will silently — useful for wrapper libraries)
  caller_built_options_can_opt_in_via_with_lwt_then_pass_to_connect
    (operator pattern: build opts with TLS/creds, attach LWT, then connect)
  placeholder_topicmessage_path_unaffected_by_lwt

Test bug caught:
- Initial test asserted 4 topics for Anonymous + no zone; actual is 5
  (presence + motion + person_count + confidence + identity_risk).
  rf_signature_hash is a BfldEvent JSON field, not its own MQTT topic.
  Fixed the assertion; documented the distinction in the test comment.

ACs progressed:
- ADR-122 §2.2 availability surface now fully operational. Three paths:
    1. Explicit publish_availability_online (iter 28) on connect
    2. LWT auto-publishes "offline" if connection drops (this iter)
    3. Explicit publish_availability_offline (iter 28) on graceful stop
  HA reads the same topic in all three cases; entities grey out
  device-wide via the iter-28 discovery `availability_topic` field.

Test config:
- cargo test --no-default-features → 72 passed
- cargo test                       → 203 passed
- cargo test --features mqtt       → 220 passed (212 + 8 new)

Out of scope (next iter target):
- GitHub Actions workflow with mosquitto Docker service. With iter
  24+29 now both depending on a live broker for full coverage, the
  CI lift is the next highest-value step.
- Three operator-ready HA blueprints (ADR-122 §2.6): presence-driven
  lighting, motion-aware HVAC, identity-risk anomaly notification.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p5.10): three HA operator blueprints (210/210 GREEN)

Iter 30. Ships the three ADR-122 §2.6 operator-ready Home Assistant
automation blueprints. Each blueprint binds to one BFLD MQTT entity
(presence / motion / identity_risk) and lets an HA operator import
+ configure without writing YAML by hand.

Added (under v2/crates/cog-ha-matter/blueprints/bfld/):
- presence-lighting.yaml
    binary_sensor.<node>_bfld_presence ⇒ light.turn_on / turn_off
    with a configurable hold_seconds delay before the off action
    (ADR-122 §2.6 requirement: "configurable hold time")
- motion-hvac.yaml
    sensor.<node>_bfld_motion ⇒ climate.set_temperature
    Operator picks motion_threshold (default 0.3, per ADR §2.6),
    delta_temperature_c (°C adjustment), and quiet_seconds debounce
- identity-risk-anomaly.yaml
    sensor.<node>_bfld_identity_risk ⇒ notify.<target>
    Two trigger paths:
      - Absolute spike (raw score >= spike_threshold, default 0.8)
      - Rolling 7-day z-score deviation (default 3 sigma)
    Requires a Statistics helper entity for the baseline; documented
    in the inline description and the blueprints README.
- README.md
    Lists the three blueprints + privacy caveat for identity_risk
    (only present at PrivacyClass::Anonymous; class 3 deployments
    will fail validation by design)

Added (in v2/crates/wifi-densepose-bfld/tests/ha_blueprints.rs):
- 7 named tests using include_str! to embed each YAML at build time
  and validate structure without adding a serde_yaml dep:
    presence_lighting_blueprint_is_structurally_valid
    motion_hvac_blueprint_is_structurally_valid
    identity_risk_blueprint_is_structurally_valid
    blueprints_carry_source_url_pointing_at_canonical_path
      (catches path drift when files move)
    presence_blueprint_uses_mqtt_integration_filter
    motion_blueprint_uses_mqtt_integration_filter
    identity_risk_blueprint_carries_privacy_class_caveat_in_description
      (operators running class 3 should know not to install)
- Helper assert_required_blueprint_fields(yaml, name_substring, label)
  enforces blueprint.{name,domain,input,trigger,action,mode} per HA spec

ACs progressed:
- ADR-122 §2.6 — all three blueprints shipped with the documented
  configurable inputs (hold_seconds for #1, motion_threshold +
  delta_temperature_c for #2, z_score_threshold + statistics_entity
  for #3). Operator installs via HA UI; no YAML editing required.
- ADR-118 §1.5 privacy_mode visibility — identity-risk blueprint
  documents the class-2-only availability so operators understand
  why the blueprint fails on class-3 deployments.

Test config:
- cargo test --no-default-features → 72 passed
- cargo test                       → 210 passed (203 + 7)

Out of scope (next iter target):
- GitHub Actions workflow with mosquitto Docker so iters 24 + 29
  e2e tests actually run in CI with BFLD_MQTT_BROKER set.
- cog-ha-matter cargo crate-internal test that loads each blueprint
  via serde_yaml + validates against an HA blueprint schema (instead
  of the string-only checks here). Optional; current coverage is
  sufficient to catch drift in the YAML files themselves.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.1): end-to-end I3 isolation proof via BfldPipeline (217/217 GREEN)

Iter 31. Lifts ADR-118 invariant I3 + ADR-120 §2.7 AC2 from the
SignatureHasher unit-test surface (iter 15) to the public BfldPipeline
API surface. Every assertion goes through pipeline.process() so the
chain exercises emitter → identity_features encoder → signature hasher
→ event construction end-to-end.

Added (in v2/crates/wifi-densepose-bfld/tests/pipeline_i3_isolation.rs):
- 7 named tests, all green:
    same_person_at_different_sites_same_day_produces_different_hashes
    same_person_same_site_different_day_rotates_the_hash
    thirty_day_gap_produces_thoroughly_different_hash
      (Hamming distance >= 80 bits — catches a weak day_epoch mix-in
       even if naive byte-equality remains different)
    same_person_same_site_same_day_produces_stable_hash
    cross_site_hamming_distance_at_pipeline_surface_is_statistically_high
      *** ADR-120 §2.7 AC2 at the public pipeline surface ***
      32 trials × 32 bytes; mean Hamming distance ≥ 120 bits required
      (the same threshold the iter-15 SignatureHasher-direct test used)
    restricted_class_strips_hash_but_pipeline_state_advances
      (class 3 contract: hash stripped from event surface but the
       underlying gate / ring / hasher state still updates so the
       pipeline keeps detecting things; future PR can't accidentally
       short-circuit at class 3 and miss legitimate sensing)
    pipeline_without_signature_hasher_does_not_invent_a_hash
      (no hasher installed → rf_signature_hash stays None)

ADR-124 status (from sibling-agent check in this iter's step 0):
- docs/adr/ADR-124-* not present yet
- docs/research/rvagent-rvf-integration/README.md present (iter 25)
- No conflict with current scope; will pick up sibling output on next iter

ACs progressed:
- ADR-118 invariant I3 — runtime proof now at the PUBLIC API surface,
  not just inside SignatureHasher. Operators reading the BfldPipeline
  documentation can verify cross-site isolation without descending
  into the hasher internals.
- ADR-120 §2.7 AC2 — pipeline-surface mean Hamming distance >= 120
  bits in the cross_site test pins the structural-isolation invariant
  at the same threshold as the iter-15 unit-level test.
- ADR-118 §1.5 — restricted_class_strips_hash test pins the
  defense-in-depth contract that class-3 doesn't accidentally also
  freeze pipeline state.

Test config:
- cargo test --no-default-features → 72 passed (pipeline_i3_isolation cfg-out)
- cargo test                       → 217 passed (210 + 7)

Out of scope (next iter target):
- GitHub Actions workflow with mosquitto Docker (lifts iters 24+29
  from skip-mode in CI).
- ADR-119 AC7 serialization throughput benchmark (50k frames/sec).
- ADR-122 AC3: 1Hz motion-publish rate integration test against the
  BfldPipelineHandle worker thread.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.2): serialization throughput test (ADR-119 AC7) — 221/221 GREEN

Iter 32. Closes ADR-119 AC7 ("Bench: serialization throughput ≥ 50k
frames/sec on a 2025-era M1/M2 / Pi 5 core"). Pure std::time::Instant
timing; no criterion / no dev-deps added.

Empirically measured in DEBUG build on this Windows host:
- BfldFrameHeader::to_le_bytes()  → 1,654,517 frames/sec (33× AC7)
- BfldFrame::to_bytes() + CRC32   →   320,255 frames/sec ( 6.4× AC7)
- Parse-cost ratio (1024B vs 512B payload): 1.59× (linear)

Release builds typically run 20–100× faster than debug; the AC7 target
is for release, so debug already smashing 50k means release has very
comfortable margin.

Added (tests/serialization_throughput.rs):
- pub const RELEASE_TARGET_FRAMES_PER_SEC = 50_000.0 (the AC7 number)
- const DEBUG_FLOOR_FRAMES_PER_SEC      = 5_000.0  (generous CI floor)
- header_only_to_le_bytes_throughput_meets_debug_floor
    50k iters with a 1k-iter warmup, black_box-guarded.
    Prints throughput to stderr so CI logs show the measured number.
- full_frame_to_bytes_throughput_meets_debug_floor
    Same shape but with 512B payload + CRC32 round-trip per iter.
- round_trip_through_bytes_remains_constant_time_per_byte
    Compares from_bytes() timing for 512B vs 1024B payload; asserts
    the ratio is in [1.0, 4.0] to catch an accidental O(n²) parser
    regression. Empirical ratio: 1.59× (expected ~2× for O(n)).
- header_size_constant_is_used_consistently_by_serializer
    Belt-and-suspenders: asserts to_le_bytes().len() == BFLD_HEADER_SIZE
    == 86, pinning the iter-1 AC1 contract from the throughput side.

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md NOW PRESENT
  (sibling agent landed it; 431 lines). Codename SENSE-BRIDGE. Scope:
  MCP server (stdio + Streamable HTTP) wrapping sensing-server's
  REST/WS/MQTT surfaces, plus a ruvector npm/TypeScript package for
  in-app consumption + ruflo MCP-tool integration. Orthogonal to BFLD
  core — BFLD produces events that SENSE-BRIDGE would expose via MCP,
  but the MCP bridge itself is not BFLD territory. No scope overlap
  with this iter or backlog targets.

ACs progressed:
- ADR-119 AC7 — debug-build serialization throughput is already 33×
  the documented release-build target. Release-build margin is
  comfortable; future iters can run --release to capture an exact
  release number for the witness bundle.

Test config:
- cargo test --no-default-features → 72 passed
- cargo test                       → 221 passed (217 + 4)

Out of scope (next iter target):
- GitHub Actions workflow with mosquitto Docker (lifts iter 24/29
  e2e from skip-mode in CI).
- ADR-122 AC3: 1Hz motion-publish-rate integration test against the
  BfldPipelineHandle worker thread (would use a Barrier + Instant
  delta over N sustained publishes).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.3): motion publish rate ≥ 1Hz integration test (ADR-122 AC3) — 224/224 GREEN

Iter 33. Closes ADR-122 AC3 ("Motion score published at ≥ 1 Hz on
ruview/<node_id>/bfld/motion/state during sustained occupancy") with
an end-to-end test through the BfldPipelineHandle worker thread.

Empirically measured on this Windows host: 10 inputs spaced 100ms
apart → 9.96 Hz motion-publish rate (10× the AC3 floor).

Added (in v2/crates/wifi-densepose-bfld/tests/motion_publish_rate.rs):
- motion_publish_rate_meets_one_hz_under_sustained_input
    Drives the handle with 10 sends at 100ms intervals, measures the
    wall-clock elapsed time, asserts motion count >= 10 AND rate
    (count / elapsed) >= 1.00 Hz. Prints throughput to stderr.
- motion_values_track_input_motion_values
    Pins iter-21's payload-encoding contract: motion values [0.10,
    0.25, 0.50, 0.75, 0.95] flow through as "{:.6}" strings without
    quantization drift.
- motion_topic_never_appears_for_class_below_anonymous_publishing
    Defense in depth: Restricted (class 3) STILL publishes motion
    (sensing data) but NOT identity_risk. Pins the two-layer
    privacy contract: motion is operator-visible at all classes ≥ 2,
    identity_risk is class-2-only.

Helper: motion_messages(&[TopicMessage]) -> Vec<&TopicMessage>
    Filters the capture log to the motion topic so the assertions
    aren't sensitive to the surrounding presence/count/confidence
    topics also being published.

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md present
  unchanged at 431 lines (sibling agent's SENSE-BRIDGE ADR). Scope
  remains orthogonal to BFLD core; no overlap with this iter.

ACs progressed:
- ADR-122 AC3 closed: motion publish rate measured at 9.96 Hz
  through the handle worker — 10× the documented floor. Provides
  the runtime witness HA needs to trust the live state-topic stream.
- ADR-122 AC1 reinforced from the rate-test side: 10 inputs → 10
  motion topics, none lost in the worker queue.
- ADR-118 §1.5 reinforced again: Restricted strips identity_risk
  but not motion (motion is sensing, not identity).

Test config:
- cargo test --no-default-features → 72 passed
- cargo test                       → 224 passed (221 + 3)

Out of scope (next iter target):
- GitHub Actions workflow with mosquitto Docker (lifts iters 24+29
  from skip-mode in CI). All remaining unmet ACs at this point
  either require external resources (KIT BFId dataset for ADR-121,
  Pi5/Nexmon hardware for ADR-123) or CI infra.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.4): spawn_with_oracle for Soul Signature deployments (227/227 GREEN)

Iter 34. Closes the gap where BfldPipelineHandle had no path for an
operator-supplied SoulMatchOracle to reach the worker thread. The
emit_with_oracle surface added in iter 14 was unreachable through the
handle API — Soul Signature deployments (ADR-118 §1.4) had to either
drop down to BfldEmitter directly or accept Recalibrate gate-drops on
known-enrolled matches.

Added (in src/pipeline.rs):
- BfldPipeline::process_with_oracle<O: SoulMatchOracle>(
      inputs, embedding, oracle,
  ) -> Option<BfldEvent>
  Wraps emitter.emit_with_oracle then applies the same privacy_mode
  post-processing as process(). Privacy_mode and oracle are independent
  — class-3 demote still happens AFTER any oracle Recalibrate exemption.

Added (in src/pipeline_handle.rs):
- BfldPipelineHandle::spawn_with_oracle<P, O>(pipeline, publisher, oracle) -> Self
  where O: SoulMatchOracle + Send + Sync + 'static
  The worker thread owns the oracle and consults it on every recv().
  Worker loop now calls pipeline.process_with_oracle(...) instead of
  pipeline.process(...).

tests/handle_soul_oracle.rs (3 named tests, all green):
  spawn_with_oracle_null_is_equivalent_to_spawn
    Parity: 3 identical low-risk inputs through spawn() and
    spawn_with_oracle(NullOracle) produce the same publish count
    and the same motion-topic count.
  spawn_with_always_match_oracle_lets_events_publish_under_high_risk
    *** Headline test ***
    3 high-risk inputs spaced > DEBOUNCE_NS apart. With AlwaysMatch
    oracle, all 3 produce motion topics — the gate never reaches
    Recalibrate because the oracle reports an enrolled-person match.
  spawn_with_null_oracle_drops_events_under_sustained_recalibrate_score
    Negative control for the above: same 3 inputs through NullOracle,
    only 1 motion topic survives (the first input lands at Accept;
    the second and third hit Recalibrate after debounce and are
    dropped per ADR-121 §2.4).

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal to BFLD core;
  no overlap with this iter.

ACs progressed:
- ADR-118 §1.4 Soul Signature companion contract end-to-end through
  the public handle API. Operators wiring Soul Signature into a
  RuView deployment now use:
      BfldPipelineHandle::spawn_with_oracle(pipeline, publisher, my_oracle)
  …and the rest of the per-frame flow stays identical to spawn().
- ADR-121 §2.6 Recalibrate exemption proven over the worker-thread
  boundary, not just at the unit level (iter 12 covered the gate-only
  case).

Test config:
- cargo test --no-default-features → 72 passed
- cargo test                       → 227 passed (224 + 3)

Out of scope (next iter target):
- GitHub Actions workflow with mosquitto Docker (lifts iters 24+29
  live-broker e2e from skip-mode). Remaining unmet ACs require
  either external resources (KIT BFId, Pi5/Nexmon) or CI infra.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.5): GitHub Actions mosquitto Docker CI workflow (235/235 GREEN)

Iter 35. Lifts iters 24 + 29 live-broker integration tests out of
skip-mode in CI by spinning up an eclipse-mosquitto:2 service container,
exporting BFLD_MQTT_BROKER, and running the three cargo test matrices.

Added:
- .github/workflows/bfld-mqtt-integration.yml
    * Triggers: push to main / feat/adr-118-* / feat/bfld-*, PR, manual
    * Path filter: only runs when v2/crates/wifi-densepose-bfld/** or the
      workflow file itself changes — protects PR throughput for unrelated
      crate work
    * Service container: eclipse-mosquitto:2 on port 1883 with a
      mosquitto_pub-based healthcheck (5s interval, 10 retries) so the
      runner waits for a real publish-ready broker, not just liveness
    * Top-level timeout-minutes: 15 (bounds runner cost if rumqttc
      handshake hangs)
    * Three cargo test invocations:
        cargo test -p wifi-densepose-bfld --no-default-features
        cargo test -p wifi-densepose-bfld
        cargo test -p wifi-densepose-bfld --features mqtt
      The third one now actually exercises the mosquitto_integration and
      rumqttc_lwt tests, not just the skip-mode path.
    * Belt-and-suspenders nc -z port poll before tests start (service
      container can take a few seconds to bind even with healthcheck)
    * cargo clippy --features mqtt as a continue-on-error gate (signals
      drift; doesn't block the merge yet)
    * RUSTFLAGS=-D warnings, CARGO_INCREMENTAL=0 for stable runs

- v2/crates/wifi-densepose-bfld/tests/ci_workflow.rs (8 named tests):
    Validates the workflow YAML via include_str! — same pattern iter 30
    used for HA blueprints. Catches drift in CI infra:
      workflow_declares_mosquitto_service_container
      workflow_exports_broker_env_for_iter_24_and_29_tests
        (BFLD_MQTT_BROKER pointing at the service container)
      workflow_runs_three_cargo_test_invocations
        (no_default + default + mqtt — three classes of bug surface)
      workflow_waits_for_mosquitto_readiness_before_testing
        (nc -z 1883 port poll)
      workflow_uses_health_check_on_the_service
        (mosquitto_pub-based, not just process liveness)
      workflow_only_triggers_on_bfld_paths
        (path filter to v2/crates/wifi-densepose-bfld/**)
      workflow_pins_runner_to_ubuntu_latest_for_docker_service_support
        (GitHub Actions `services:` doesn't work on macOS/Windows)
      workflow_has_timeout_guard
        (top-level timeout-minutes pinned)

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines (SENSE-BRIDGE ADR). Scope remains orthogonal.

ACs progressed:
- ADR-122 §2.2 e2e — when this workflow lands on origin/main and the
  next BFLD PR runs, the iter-24 anonymous-event roundtrip + restricted-
  event-omits-identity_risk tests stop printing "skipping" and actually
  publish to / subscribe from mosquitto. Plus the iter-29 LWT publisher
  smoke run gets to fire its session-drop test against a live broker.
- ADR-118 §2.1 ⇄ §2.2 — discovery + state-topic + LWT + worker thread
  all proven in one CI matrix run.

Test config:
- cargo test --no-default-features → 72 passed (ci_workflow cfg-out)
- cargo test                       → 235 passed (227 + 8)

Out of scope (skipped — external resources or hardware):
- ADR-121 calibration — KIT BFId dataset
- ADR-123 production capture — Pi 5 / Nexmon hardware

All other in-crate ACs from the ADR-118 / 119 / 120 / 121 / 122 series
are now covered by the iter 1-35 chain. The cron loop should
consider closing out at this point or pivoting to documentation /
witness-bundle generation for the PR.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p1.7): reserved-flag-bits forward-compat (243/243 GREEN)

Iter 36. Locks down the ADR-119 §2.1 forward-compat promise that
reserved flag bits round-trip unchanged through the parser. A future
protocol revision may light up bits 2 or 4..=15; today's parser
preserves them so a node running iter N can forward unknown bits to
a peer running iter N+M without losing information.

Added (in src/frame.rs::flags):
- pub const KNOWN_FLAGS_MASK = HAS_CSI_DELTA | PRIVACY_MODE | SELF_ONLY
    (the three currently-named flags, occupying bits 0, 1, 3)
- pub const RESERVED_FLAGS_MASK = !KNOWN_FLAGS_MASK
    (bit 2 + bits 4..=15 — every position not currently assigned)
- Docstrings reference ADR-119 §2.1 verbatim so a future reviewer
  understands why the constants exist.

tests/reserved_flags.rs (8 named tests, all green, no_std-compatible
so they run in BOTH feature configs):
  known_flags_mask_covers_exactly_three_named_flags
    (count_ones() == 3 catches accidental flag additions that should
     also update KNOWN_FLAGS_MASK)
  reserved_and_known_masks_are_complementary
    (mask | reserved == u16::MAX; mask & reserved == 0)
  known_flags_do_not_overlap_with_each_other
    (HAS_CSI_DELTA, PRIVACY_MODE, SELF_ONLY all on distinct bits)
  header_preserves_reserved_flag_bits_through_round_trip
    *** Headline test: set RESERVED_FLAGS_MASK on a header, serialize,
        parse, verify the bits survived. ***
  header_preserves_mixed_known_and_reserved_bits
    (HAS_CSI_DELTA | PRIVACY_MODE | (1<<7) | (1<<14) — mixed case)
  reserved_bits_do_not_collide_with_self_only_bit_3
    (bit 2 is reserved but bit 3 is named — pins the asymmetry)
  all_zero_flags_round_trip_cleanly
  all_one_flags_round_trip_cleanly (stress: every bit set)

The new tests are no_std-compatible (no Vec / no serde) so they run
in both `cargo test --no-default-features` and default feature
configs. The no_default test count therefore jumps from 72 to 80.

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-119 §2.1 "Reserved flag bits 2-15 lock in future-extension
  order; any new bit assignment is a version bump." — the test now
  enforces the OTHER half of this contract: a peer running the
  future version can set a reserved bit and our parser will preserve
  it through the round-trip rather than masking it off.

Test config:
- cargo test --no-default-features → 80 passed (72 + 8 no_std-compat)
- cargo test                       → 243 passed (235 + 8)

Out of scope (next iter target):
- PR-readiness pivot: witness bundle regeneration, CHANGELOG batch
  across iters 1-36, AC closeout table for the PR description.
  All in-crate ACs are now covered; remaining work is either
  external-resource-gated (KIT BFId, Pi5/Nexmon) or PR-prep.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.6): pipeline event-stream JSON determinism (248/248 GREEN)

Iter 37. Adds the cross-pipeline counterpart to iter 31's I3 isolation
tests. Iter 31 proved hash DIFFERENCES across sites and days; this
iter proves event-stream EQUALITY across two pipeline instances with
matching configuration. Operators capturing BFI for offline replay
analysis can now trust that replaying the same input stream produces
byte-identical JSON output across BFLD versions.

Added (in v2/crates/wifi-densepose-bfld/tests/pipeline_determinism.rs):
- 5 named tests, all green:

  two_pipelines_with_identical_config_produce_identical_event_streams
    Build two BfldPipelines from the same BfldConfig (same node_id,
    same SignatureHasher salt, same class), drive both with 5
    identical (timestamp, motion, embedding) tuples, then walk both
    event vecs field-by-field asserting equality of every
    publishable BfldEvent field including the derived
    rf_signature_hash and identity_risk_score.

  two_pipelines_produce_byte_identical_event_json_streams
    (gated on serde-json) — same fixture, but compares the
    serde_json::to_string output as Vec<String>. This is the
    operator's true wire-form replay guarantee.

  replaying_same_input_sequence_after_pipeline_reset_reproduces_events
    Catches accidental hidden state by building, draining, and
    rebuilding the pipeline twice; asserts the hash sequences match.
    If a future PR adds an internal counter that affects output,
    this test fires.

  different_input_sequences_diverge_after_the_first_difference
    Negative control: identical first two inputs produce identical
    hashes; changing the third input (different embedding) produces
    a different hash. Pins that the determinism is genuine, not
    "always returns the same value."

  class_3_pipelines_produce_identical_stripped_event_streams
    Determinism property must hold across privacy classes too —
    operators running Restricted deployments need replay to work
    even though identity fields are stripped.

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-119 AC6 (deterministic serialization) lifted from the
  BfldFrame layer (iter 2) to the BfldEvent + JSON layer.
  Operators get end-to-end determinism guarantees from sensing
  input through to MQTT topic payload.
- ADR-118 §2.1 pipeline correctness — two-pipeline equality is the
  strongest form of the "same input → same output" contract the
  facade can offer. Combined with iter 31's I3 difference proof,
  the pipeline now has both "should match" and "should differ"
  invariants pinned at the public-API level.

Test config:
- cargo test --no-default-features → 80 passed (pipeline_determinism cfg-out)
- cargo test                       → 248 passed (243 + 5)

Out of scope (next iter target):
- PR-readiness pivot — CHANGELOG batch, witness bundle, AC closeout
  table for the eventual PR description. All in-crate ACs are now
  covered by iters 1-37; remaining work is either external-resource-
  gated (KIT BFId, Pi5/Nexmon) or PR-prep.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.7): apply_privacy_gating irreversibility tests (255/255 GREEN)

Iter 38. Pins ADR-120 §2.4 ("There is no `promote` operation") at the
BfldEvent::apply_privacy_gating soft-mutation surface. Iter 9's
PrivacyGate::demote tests already proved this for the explicit
class-transition transformer; this iter proves it for the *soft*
in-place re-classifier used by BfldPipeline::process() under
enable_privacy_mode().

Defense-in-depth property: an attacker who manages to flip
event.privacy_class from Restricted back to Anonymous cannot then
resurrect the stripped identity fields through apply_privacy_gating
alone. They'd have to fabricate the fields via direct field assignment
or rebuild via with_privacy_gating — both of which are conspicuous in
code review (single byte flip is not).

Added (in tests/event_gating_irreversibility.rs):
- 7 named tests, all green:

  apply_at_anonymous_preserves_identity_fields
    Sanity: apply doesn't strip when class is Anonymous.

  manual_class_flip_to_restricted_then_apply_strips_both_fields
    Direct path: class Anonymous → flip to Restricted → apply
    → identity_risk_score and rf_signature_hash both None.

  one_way_strip_survives_class_flip_back_to_anonymous
    *** HEADLINE TEST ***
    Anonymous → flip to Restricted → apply (strip) → flip back to
    Anonymous → apply → fields STILL None. apply_privacy_gating
    must not resurrect.

  manual_field_restoration_after_strip_only_works_via_explicit_assignment
    The escape hatch is direct field assignment (visible in code
    review), not the soft gate. Confirms: after explicit
    Some(0.42) reassignment + class=Anonymous + apply, the
    values survive.

  apply_at_already_restricted_with_already_none_fields_is_a_noop
    Idempotency on stripped-state.

  one_way_property_holds_through_multiple_class_round_trips
    Stress: 5 Restricted→apply→Anonymous→apply cycles. Fields
    must stay None throughout — no slow-resurrection bug.

  rebuilding_via_with_privacy_gating_is_the_documented_restoration_path
    Pins the doc contract: to publish identity fields again after
    a strip, build a fresh BfldEvent. The constructor accepts
    explicit Some(...) values; apply_privacy_gating then doesn't
    strip because class is Anonymous.

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-120 §2.4 "no promote operation" now structurally proven at the
  SOFT (apply_privacy_gating) path in addition to the EXPLICIT
  (PrivacyGate::demote) path that iter 9 covered. Both layers of
  the privacy gate carry the one-way-only invariant.
- ADR-118 invariant I1 — once stripped, raw identity fields can only
  be re-introduced through paths visible in code review (direct
  field assignment, fresh constructor). No subtle byte-flip path
  resurrects them.

Test config:
- cargo test --no-default-features → 80 passed (event_gating_irreversibility cfg-out)
- cargo test                       → 255 passed (248 + 7)

Out of scope (next iter target):
- PR-readiness pivot: CHANGELOG, witness bundle, AC closeout table.
  External-resource-gated work (KIT BFId, Pi5/Nexmon) still skipped.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p1.8): CRC-32/ISO-HDLC polynomial pinning (262/262 GREEN)

Iter 39. Defends the wire-format CRC contract from silent polynomial
substitution. ADR-119 §2.4 specifies CRC-32/ISO-HDLC (same as Ethernet
and zlib), NOT CRC-32C (Castagnoli) or any other variant. Two BFLD
implementations that disagree on the polynomial treat every frame
from the other as corrupt.

Added (in tests/crc32_polynomial.rs):
- 7 named tests using canonical CRC vectors from the reveng catalogue
  (https://reveng.sourceforge.io/crc-catalogue/all.htm):

  check_string_matches_canonical_iso_hdlc_value
    CRC-32/ISO-HDLC of the standard "123456789" check string is
    0xCBF43926. This is THE canonical vector for the algorithm.

  empty_payload_yields_zero_crc
    init=0xFFFFFFFF, xorout=0xFFFFFFFF → empty payload CRC is 0.

  single_zero_byte_has_a_specific_value
    CRC-32/ISO-HDLC of [0x00] is 0xD202EF8D — well-known constant.

  flipping_a_single_payload_byte_changes_the_crc
    Sensitivity property: any one-bit flip MUST change the CRC.
    Catches a stuck CRC implementation.

  iso_hdlc_distinguishes_from_castagnoli_for_same_input
    CRC-32C/Castagnoli of "123456789" is 0xE3069283.
    Our value MUST differ. Documents the failure mode for a future
    reviewer who fires the test.

  known_short_inputs_have_documented_crcs
    Three additional vectors: "a", "abc", "hello world".
    Each pins a specific 32-bit value against the active polynomial.

  crc_is_deterministic_across_repeated_calls
    Sanity for pure-function correctness.

These tests are no_std-compatible so they run in BOTH feature configs.
The no_default count therefore jumps from 80 to 87.

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-119 §2.4 "CRC-32/ISO-HDLC" contract — the test surface now
  catches any future PR that swaps the polynomial. crc 4.x ships
  CRC_32_ISO_HDLC alongside half a dozen other CRC-32 variants;
  a typo in src/frame.rs::CRC32_ALG could otherwise silently flip
  the wire-format contract.

Test config:
- cargo test --no-default-features → 87 passed (80 + 7 no_std-compat)
- cargo test                       → 262 passed (255 + 7)

Out of scope (next iter target):
- PR-readiness pivot: CHANGELOG, witness bundle, AC closeout table.
  External-resource-gated work (KIT BFId, Pi5/Nexmon) still skipped.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.8): pipeline gate-state observability (269/269 GREEN)

Iter 40. Pins BfldPipeline::current_gate_action() as a stable operator-
facing diagnostic surface. Iter 11 covered the underlying CoherenceGate
state machine; this iter validates the same transitions through the
public BfldPipeline facade so operators can observe gate behavior
without descending into the lower-level types.

Added (in tests/pipeline_gate_observability.rs, 7 named tests):
  fresh_pipeline_starts_in_accept
  low_risk_processing_stays_in_accept (3 inputs at 0.1^4 risk)
  first_high_risk_input_does_not_immediately_promote_gate
    (pending != current — debounce hasn't elapsed)
  sustained_high_risk_promotes_gate_to_reject_after_debounce
    (two inputs across DEBOUNCE_NS boundary → Reject)
  sustained_recalibrate_grade_score_reaches_recalibrate
    (same pattern with 1.0^4 score → Recalibrate)
  returning_to_low_risk_restores_accept_via_hysteresis
    (round trip: 0.9^3 * 0.85 PredictOnly → 0.1^4 Accept via debounce)
  current_gate_action_is_read_only_does_not_advance_state
    *** Important property for operator-facing surface ***
    Three reads between processes must return the same value and not
    perturb pipeline state. A polling monitor calling this in a tight
    loop must not influence what the next process() observes.

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-118 §2.1 operator diagnostic surface — current_gate_action()
  now provably read-only and observably transitioning through the
  full 4-action band. Operators wiring HA notifications or fleet
  dashboards to "gate Reject means something to investigate" have
  a stable contract.
- ADR-121 §2.4 + §2.5 — gate transitions visible at the facade
  layer match the underlying CoherenceGate semantics; hysteresis
  and debounce work end-to-end through process().

Test config:
- cargo test --no-default-features → 80 passed (gate_observability cfg-out)
- cargo test                       → 269 passed (262 + 7)

Out of scope (next iter target):
- PR-readiness pivot: CHANGELOG batch, witness bundle regeneration,
  AC closeout table for the eventual PR description. All 5 ACs of
  ADR-118 / 7 ACs of ADR-119 / 7 ACs of ADR-120 / 7 ACs of ADR-121 /
  6 ACs of ADR-122 are now covered by iters 1-40. Remaining work is
  external-resource-gated (KIT BFId, Pi5/Nexmon hardware) or PR-prep.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p1.9): PrivacyClass capability-helper truth tables (279/279 GREEN)

Iter 41. Pins the const-helper API (PrivacyClass::allows_network /
allows_matter) and proves it stays in sync with the Sink::MIN_CLASS
trait-level enforcement. Drift between these two APIs would be a
silent correctness bug — an operator checking allows_network() might
get a different answer than the actual NetworkSink::check_class()
runtime gate.

Added (in tests/privacy_class_capability.rs, no_std-compatible):
- 10 named tests, all green:

  allows_network_truth_table     (4 classes × bool)
  allows_matter_truth_table      (4 classes × bool)
  allows_matter_implies_allows_network
    Monotonicity: Matter is a strict subset of Network. Any class
    that allows Matter MUST allow Network. The reverse is not true
    (Derived is Network-eligible but not Matter-eligible).
  allows_network_strictly_excludes_raw
    Class 0 is the ONLY class that fails allows_network. Any future
    refactor that lets Raw cross a NetworkSink violates ADR-118 I1.
  allows_matter_strictly_requires_class_two_or_three
  local_sink_accepts_every_class_per_helper
    Cross-consistency: LocalSink::MIN_CLASS = Raw, accepts all.
  network_sink_consistency_matches_allows_network
    For every class, check_class<NetworkKind> agrees with allows_network().
  matter_sink_consistency_matches_allows_matter
    Same for Matter.
  as_u8_returns_documented_byte_values    (0, 1, 2, 3)
  class_byte_ordering_matches_information_density  (raw < derived < anon < restr)

Helper:
  check_consistency<S: Sink>(class, helper_says_allowed) compares the
  Boolean helper against (class_byte >= S::MIN_CLASS.as_u8()) and asserts
  equality. Catches drift before it reaches operator-visible behavior.

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-118 invariant I1 reinforced at the const-helper layer: a future
  PR refactoring PrivacyClass::Raw to be Network-eligible breaks 4 of
  the 10 tests (truth table + monotonicity + Raw exclusion + sink
  consistency), so the regression is loud rather than silent.
- ADR-120 §2.2 sink-class contract pinned at the helper layer. The
  iter 3 (Sink + check_class) and iter 1 (allows_network) APIs now
  have a regression test enforcing their agreement.

Test config:
- cargo test --no-default-features → 90 passed (+10 no_std-compat)
- cargo test                       → 279 passed (269 + 10)

Out of scope (next iter target):
- PR-readiness pivot remains the genuine next step: CHANGELOG batch,
  witness bundle regeneration, AC closeout table. All ADR-118/119/120/
  121/122 ACs are now empirically covered. External-resource-gated
  work (KIT BFId, Pi5/Nexmon hardware) stays skipped.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.9): BfldError Display format pinning (290/290 GREEN)

Iter 42. Pins the thiserror-derived Display output for every BfldError
variant. Operators grep log lines for these strings; format drift
between minor versions breaks monitoring queries and alerting rules.
This iter locks the contract.

Added (in tests/bfld_error_display.rs, 11 named tests):
- One test per BfldError variant asserting the documented substrings
  appear in to_string():
    invalid_magic_displays_both_expected_and_actual_in_hex
    unsupported_version_displays_the_offending_version
    crc_mismatch_displays_both_values_in_hex
    privacy_violation_displays_the_sink_reason
    invalid_privacy_class_displays_the_offending_byte
    truncated_frame_displays_got_and_need_byte_counts
    malformed_section_displays_offset_and_reason
    invalid_demote_displays_both_from_and_to_class_bytes
- Meta tests:
    bfld_error_implements_std_error_trait
      (compile-time witness via fn assert_error_trait<E: std::error::Error>())
    bfld_error_is_debug_so_panic_unwrap_messages_carry_diagnostics
    every_variant_has_a_non_empty_display_string
      (catch-all: 8 variants × non-empty Display assertion;
       guards against a future PR that adds a new variant without
       the #[error(...)] attribute)

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-118 §2.1 operator observability — error-message contract now
  pinned. A monitoring rule that greps for "payload CRC mismatch"
  or "privacy violation" continues to fire correctly across BFLD
  versions.

Test config:
- cargo test --no-default-features → 90 passed (bfld_error_display cfg-out)
- cargo test                       → 290 passed (279 + 11)

Out of scope (next iter target):
- PR-readiness pivot remains the genuine next move: CHANGELOG batch,
  witness bundle regeneration, AC closeout table. All in-crate ACs
  empirically covered; remaining work is external-resource-gated
  (KIT BFId, Pi5/Nexmon hardware) or PR-prep.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p1.10): frame parser trailing-bytes contract (296/296 GREEN)

Iter 43. Pins BfldFrame::from_bytes behavior on buffers carrying bytes
past `BFLD_HEADER_SIZE + header.payload_len`. The parser currently
accepts these and silently slices to the declared length. Useful when
the transport (UDP MTU padding, ESP-NOW trailer alignment) adds noise
the application layer doesn't strip.

Pinning this behavior makes any future tightening (reject as
MalformedFrame) a deliberate, traceable policy change rather than
silent breakage.

Added (in tests/frame_trailing_bytes.rs, 6 named tests):
  parser_accepts_buffer_with_one_trailing_byte
    (smoke: one extra 0xFF byte tolerated; payload.last() != Some(0xFF))
  parser_accepts_many_trailing_bytes
    (256 trailing bytes — UDP MTU padding scale)
  parsed_payload_round_trips_back_to_typed_payload_with_trailing_bytes_present
    *** Sanity: trailing-bytes leniency must not corrupt the section
        parser downstream. from_bytes → parse_payload still yields
        the original BfldPayload byte-for-byte. ***
  header_only_buffer_at_exactly_header_size_with_zero_payload_len_succeeds
    (boundary: empty-payload frame is exactly 86 bytes)
  header_only_buffer_with_trailing_bytes_but_zero_payload_len_ignores_them
    (100 trailing bytes; parsed.payload stays empty)
  trailing_bytes_do_not_affect_crc_validation_when_payload_intact
    (CRC is over payload bytes only; 32 trailing bytes leave CRC
     intact and parse succeeds)

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-119 wire-format parser contract: trailing-bytes tolerance is
  now an explicit, tested behavior. Operators building stream-based
  frame readers (where multiple frames concatenate) know the parser
  treats `header.payload_len` as authoritative, not buffer.len().

Test config:
- cargo test --no-default-features → 90 passed (frame_trailing_bytes cfg-out)
- cargo test                       → 296 passed (290 + 6)

Out of scope (next iter target):
- PR-readiness pivot: CHANGELOG, witness bundle, AC closeout table.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p3.4): CoherenceGate clock-skew resilience (303/303 GREEN)

Iter 44. Pins the gate's saturating_sub-based debounce as safe under
clock perturbation. NTP rollback, system-clock adjustment, monotonic-
source switch — all can produce a backward `timestamp_ns` between
calls. The gate must NOT promote spuriously on backward jumps and
MUST NOT panic on identical / zero / u64::MAX-ish timestamps.

Added (in tests/gate_clock_skew.rs, no_std-compatible):
- 7 named tests, all green:

  backward_jump_after_pending_does_not_promote_prematurely
    Pending at t = DEBOUNCE_NS + 100; backward jump to t = 0.
    saturating_sub(0, DEBOUNCE_NS+100) = 0 < DEBOUNCE_NS → no promotion.

  forward_recovery_after_backward_jump_still_promotes_correctly
    Backward jump doesn't corrupt the pending `since` stamp; once wall
    time advances past since + DEBOUNCE_NS, promotion fires normally.

  identical_timestamps_across_repeated_polls_do_not_progress_state
    Five identical timestamps in a row — gate never promotes; both
    current and pending remain stable. Important for HA dashboards
    polling at >1Hz: the polling itself must not cause transitions.

  backward_jump_with_no_pending_is_a_noop
    Edge: no pending in flight, backward jump — gate stays clean.

  very_large_forward_jump_promotes_but_does_not_panic
    Stress: t = u64::MAX/2 jump. No overflow, no panic, promotes.

  backward_then_forward_into_different_action_band_resets_pending_correctly
    More subtle: pending PredictOnly → backward jump WITH a different
    score (recalibrate-grade) — pending target changes, debounce
    clock resets to the new (smaller) timestamp; forward by DEBOUNCE_NS
    promotes to Recalibrate.

  no_panic_on_zero_timestamp_with_predict_only_pending
    Regression guard: a poorly-initialized monotonic clock could
    deliver t=0 as the first sample. Gate must not panic.

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-121 §2.5 debounce property — saturating_sub usage now has a
  regression test. A future PR that swaps to plain `-` (panic on
  underflow) fires `no_panic_on_zero_timestamp_with_predict_only_pending`.
- ADR-118 §2.1 operator-facing diagnostic safety — current_gate_action
  polled at the same timestamp from a Prometheus exporter or HA
  dashboard cannot cause unintended state transitions.

Test config:
- cargo test --no-default-features → 97 passed (90 + 7 no_std-compat)
- cargo test                       → 303 passed (296 + 7)

Out of scope (next iter target):
- PR-readiness pivot still pending: CHANGELOG, witness bundle,
  AC closeout table. External-resource-gated work (KIT BFId,
  Pi5/Nexmon) still skipped.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.10): public API surface snapshot (308/308 GREEN)

Iter 45. Compile-time witness that every `pub use` re-export from
lib.rs survives refactors. A future PR removing one fires a named
test failure instead of producing a silent SemVer break.

Added (in tests/public_api_snapshot.rs):
- 5 named tests across feature flags:

  always_available_types_are_re_exported (no_std-compatible)
    Witnesses PrivacyClass, GateAction, MatchOutcome, BfldFrameHeader,
    CoherenceGate, NullOracle, EmbeddingRing, SignatureHasher,
    IdentityEmbedding + 11 const re-exports + 5 flag bits.

  sink_trait_hierarchy_re_exported (no_std-compatible)
    Witnesses Sink, LocalSink, NetworkSink, MatterSink, LocalKind,
    NetworkKind, MatterKind + check_class function. Trait bounds
    asserted via fn assert_sink<S: Sink>() etc. so missing impls
    fire here too.

  soul_match_oracle_trait_re_exported (no_std-compatible)
    Witnesses SoulMatchOracle trait + NullOracle impl.

  bfld_error_re_exported_with_all_named_variants (no_std-compatible)
    Constructs every BfldError variant — removing one fires.

  std_only_types_are_re_exported (gated on `std`)
    BfldConfig, BfldPipeline, BfldEmitter, PrivacyGate,
    CapturePublisher, BfldPipelineHandle, PipelineInput,
    SensingInputs, IdentityFeatures, BfldEvent, BfldFrame,
    BfldPayload, TopicMessage + 12 free-function re-exports
    (identity_risk_score, availability_topic, online_message,
    offline_message, publish_availability_*, publish_discovery,
    publish_event, render_*, with_privacy_gating) +
    PAYLOAD_AVAILABLE, PAYLOAD_NOT_AVAILABLE, RISK_FACTOR_BYTES.

  mqtt_publisher_types_are_re_exported (gated on `mqtt`)
    RumqttPublisher type + with_lwt free function signature.

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-118 §2.1 public-API stability — every documented re-export
  has a named-symbol regression test. Accidental removal fires
  loudly at build time rather than as a silent SemVer break on
  downstream consumers (cog-ha-matter, wifi-densepose-sensing-server,
  pip wifi-densepose, sibling-agent SENSE-BRIDGE crate).

Test config:
- cargo test --no-default-features → 101 passed (97 + 4 no_std-compat
  — the std-only mod test is cfg-out)
- cargo test                       → 308 passed (303 + 5)

Out of scope (next iter target):
- PR-readiness pivot still pending: CHANGELOG batch across iters
  1-45, witness bundle regeneration, AC closeout table for the PR
  description. External-resource-gated work (KIT BFId, Pi5/Nexmon)
  still skipped.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.11): presence detection latency p95 (ADR-119 AC2) — 311/311 GREEN

Iter 46. Closes ADR-119 AC2 ("Presence detection latency is ≤ 1s p95
from the first non-empty BFI frame in a new occupancy event"). Per-
call BfldPipeline::process() latency measured at the public facade
surface via pure std::time::Instant — no criterion dep.

Empirically measured on this Windows host (debug build):
- p50:           0.9µs    (1.1M frames/sec)
- p95:           0.9µs    (~1,000,000× under the 1s AC2 target)
- p99:           1.2µs
- First call:    2.9µs    (no lazy-init regression)
- Long-run growth: 1.55× from first-100 mean to last-100 mean
                  (10× ceiling guards against unbounded internal state)

Added (in tests/presence_latency.rs):
- pub const ADR_119_AC2_P95_TARGET = Duration::from_secs(1) (the AC number)
- const DEBUG_P95_FLOOR = Duration::from_millis(100) (generous CI floor)

Three named tests, all green:
  process_call_p95_latency_meets_debug_floor
    500 samples after a 50-sample warmup, sort, take p50/p95/p99,
    print to stderr, assert p95 <= 100ms AND p95 <= 1s.
  first_call_after_pipeline_construction_is_not_pathologically_slow
    Operator-visible "first event after node boot" latency. Bounded
    at 250ms — catches a constructor that defers work to first
    process() call (would show as a 100ms+ spike on a Pi 5 boot).
  latency_does_not_grow_unbounded_over_long_runs
    Compares first-100 sample mean vs last-100 over 500 calls;
    ratio < 10× guards against memory-leak-style regressions.

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-119 AC2 closed — p95 latency runs 6 orders of magnitude under
  the 1s target. Release-build margin is comfortable.
- ADR-118 §2.1 operator-perceived performance — first-call and
  long-run latency guards complement iter 32's serialization
  throughput bench (header 1.65M/s, full-frame 320k/s). Pipeline
  latency is dominated by the BFI capture step, not BFLD processing.

Test config:
- cargo test --no-default-features → 101 passed (presence_latency cfg-out)
- cargo test                       → 311 passed (308 + 3)

Out of scope (next iter target):
- PR-readiness pivot remains the genuine next step. All in-crate ACs
  empirically covered; remaining work is external-resource-gated
  (KIT BFId, Pi5/Nexmon) or PR-prep.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.12): examples/bfld_minimal.rs operator quickstart (315/315 GREEN)

Iter 47. Ships the operator-facing quickstart as doc-as-code. Three
goals:

1. New operators reading the crate get a 50-line working example
   instead of having to assemble pipeline + config + hasher + inputs
   + embedding + JSON publish themselves.
2. CI proves the example COMPILES and RUNS end-to-end via a
   separate test that re-executes the same flow inline.
3. The example output is the canonical BfldEvent JSON, demonstrating
   every documented field (presence/motion/count/conf/zone/class/
   identity_risk_score/rf_signature_hash) for a typical Anonymous
   class publish.

Added:
- v2/crates/wifi-densepose-bfld/examples/bfld_minimal.rs (~70 LOC):
    * Per-site secret salt
    * BfldPipeline::new(BfldConfig::new(...).with_signature_hasher(...))
    * SensingInputs with low-risk factors so the gate emits
    * IdentityEmbedding from a deterministic ramp
    * pipeline.process(...).ok_or(...) for the gate-drop case
    * event.to_json() printed to stdout
    * Run command in the doc comment:
        cargo run -p wifi-densepose-bfld --example bfld_minimal

- v2/crates/wifi-densepose-bfld/tests/example_minimal.rs (4 tests):
    minimal_example_documents_the_operator_quickstart_flow
      (asserts file contains BfldPipeline, SignatureHasher,
       SensingInputs, IdentityEmbedding, BfldConfig, .process(,
       to_json — catches doc drift if the example removes a key
       symbol)
    minimal_example_carries_run_instructions_in_doc_comments
      (the cargo run --example line must be present)
    minimal_example_flow_produces_valid_json_with_documented_fields
      *** Re-runs the example flow inline and asserts every
          documented JSON field appears in the output ***
    example_returns_box_dyn_error_for_main_signature
      (canonical Rust-example main signature)

- v2/crates/wifi-densepose-bfld/Cargo.toml:
    [[example]] name = "bfld_minimal", required-features = ["serde-json"]
    so `cargo test --no-default-features` doesn't try to build the
    example (which needs to_json gated on serde-json).

Example run output (sanity check before commit):
  {"type":"bfld_update","node_id":"seed-example","timestamp_ns":...,
   "presence":true,"motion":0.42,"person_count":1,"confidence":0.91,
   "privacy_class":"anonymous","identity_risk_score":0.0016000001,
   "rf_signature_hash":"blake3:cc3615c7aaab9d0867a0c15327444b8f...bf"}

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-118 §2.1 documentation surface — first operator-facing example
  shipped as part of the crate. Discoverable via
  `cargo run --example bfld_minimal` and verified via cargo test.

Test config:
- cargo test --no-default-features → 101 passed (example_minimal cfg-out)
- cargo test                       → 315 passed (311 + 4 example_minimal)

Out of scope (next iter target):
- PR-readiness pivot still pending: CHANGELOG, witness bundle,
  AC closeout table. External-resource-gated work still skipped.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.13): examples/bfld_handle.rs worker-thread pattern (319/319 GREEN)

Iter 48. Ships the production-recommended operator example: full
lifecycle through the worker-thread handle. Companion to iter-47's
minimal example which uses BfldPipeline::process directly. The
handle example demonstrates the multi-thread pattern operators
actually deploy with HA + MQTT.

Lifecycle demonstrated in the example:
  1. publish_availability_online (retained → HA marks device online)
  2. publish_discovery (retained → HA auto-creates 6 BFLD entities)
  3. BfldPipelineHandle::spawn (worker owns gate + ring + hasher)
  4. handle.send(input) per BFI frame (worker process + publish)
  5. handle.shutdown() (clean worker join)
  6. publish_availability_offline (explicit graceful disconnect)

Example output (verified pre-commit):
  bootstrap: 1 availability + 6 discovery payloads
  total messages published: 33
  first three topics:
    ruview/seed-handle-demo/bfld/availability
    homeassistant/binary_sensor/seed-handle-demo_bfld_presence/config
    homeassistant/sensor/seed-handle-demo_bfld_motion/config
  last three topics:
    ruview/seed-handle-demo/bfld/confidence/state
    ruview/seed-handle-demo/bfld/identity_risk/state
    ruview/seed-handle-demo/bfld/availability

Added:
- v2/crates/wifi-densepose-bfld/examples/bfld_handle.rs (~110 LOC):
    * Documents the 6-phase lifecycle with inline comments
    * Pointer to RumqttPublisher::connect_with_lwt for prod use
    * 5 sensing frames × 5 state topics = 25 per-frame messages
- v2/crates/wifi-densepose-bfld/tests/example_handle.rs (4 named tests):
    handle_example_documents_full_lifecycle_phases
      (doc drift guard: 8 operator-facing symbols must appear)
    handle_example_carries_run_instructions_and_prod_pointer
      (cargo run line + RumqttPublisher pointer present)
    handle_example_lifecycle_produces_expected_message_counts
      *** Re-executes full lifecycle inline; asserts total == 33,
          first message payload == "online", last == "offline" ***
    handle_example_returns_box_dyn_error_for_main_signature
- v2/crates/wifi-densepose-bfld/Cargo.toml:
    [[example]] name = "bfld_handle", required-features = ["std"]

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-118 §2.1 documentation surface — two runnable operator examples
  now shipped (iter 47 minimal, iter 48 worker-thread). Together
  they cover the two operator patterns: simple in-process consumer
  (process + to_json) and the full HA-integration deployment
  (handle + bootstrap + lifecycle).
- ADR-122 §2.1 + §2.2 + §2.6 — the worker example exercises every
  layer of the HA-DISCO publish chain in one runnable file:
  availability, discovery, state, graceful shutdown.

Test config:
- cargo test --no-default-features → 101 passed (example_handle cfg-out)
- cargo test                       → 319 passed (315 + 4)

Out of scope (next iter target):
- PR-readiness pivot still pending. External-resource-gated work
  (KIT BFId, Pi5/Nexmon) still skipped.

Co-Authored-By: claude-flow <ruv@ruv.net>

* docs(adr-118/p6.14): crate README.md + Cargo.toml readme field (327/327 GREEN)

Iter 49. Ships the crate's first README — genuinely missing artifact.
crates.io renders this file; the rendered page is what downstream
operators see when they `cargo doc --open` or browse the registry.

Added:
- v2/crates/wifi-densepose-bfld/README.md (~135 lines):
    * Three structural invariants (I1/I2/I3) table with enforcement
      mechanism per invariant
    * Quickstart snippet: in-process consumer (BfldPipeline::process)
    * Quickstart snippet: production worker (BfldPipelineHandle +
      bootstrap helpers)
    * Feature flag matrix (std / serde-json / mqtt / soul-signature)
    * Two runnable example invocations
    * Testing matrix (no_default / default / mqtt)
    * Companion artifacts pointer (ADRs, research bundle, HA
      blueprints, CI workflow)
    * ADR cross-reference table (ADR-118 through ADR-123)
    * BFLD_MQTT_BROKER env-var doc for live mosquitto opt-in

- v2/crates/wifi-densepose-bfld/Cargo.toml:
    readme = "README.md"
    (so crates.io picks it up on publish)

- v2/crates/wifi-densepose-bfld/tests/crate_readme.rs (8 tests):
    readme_documents_three_structural_invariants
    readme_documents_feature_flag_matrix
    readme_documents_both_runnable_examples
    readme_documents_three_test_invocations
    readme_references_companion_adrs_118_through_123
    readme_quickstart_uses_canonical_public_api
      (8 symbol-presence checks: BfldPipeline::new, BfldConfig::new,
       SignatureHasher::new, SensingInputs, IdentityEmbedding::from_raw,
       pipeline.process, publish_availability_online, publish_discovery,
       BfldPipelineHandle::spawn, PipelineInput)
    readme_points_at_research_bundle_and_blueprints
    readme_documents_env_gated_mosquitto_integration

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-118 §2.1 documentation surface — crates.io / cargo doc landing
  page now exists. Operators encountering wifi-densepose-bfld for the
  first time get the three structural invariants, quickstart snippets
  for both deployment patterns, feature matrix, and ADR map without
  having to read source.

Test config:
- cargo test --no-default-features → 101 passed (crate_readme cfg-out)
- cargo test                       → 327 passed (319 + 8)

Out of scope (next iter target):
- PR-readiness pivot. CHANGELOG, witness bundle, AC closeout table.
  External-resource-gated work (KIT BFId, Pi5/Nexmon) still skipped.

Co-Authored-By: claude-flow <ruv@ruv.net>

* docs(adr-118): CHANGELOG [Unreleased] BFLD entry + validation test (332/332 GREEN)

Iter 50. PR-readiness pivot iter #1. Lands the BFLD entry under
CHANGELOG.md's [Unreleased] section per the project's pre-merge
checklist (CLAUDE.md). Plus a validation test that catches drift if
someone edits the entry and breaks the operator-facing summary.

Added (in CHANGELOG.md):
- New top-of-[Unreleased]-Added bullet for BFLD spanning:
  * ADR-118 umbrella + invariants I1/I2/I3 + their enforcement
    mechanism (Sink traits / Drop+no-Serialize / per-site BLAKE3)
  * ADR-119 frame format (86-byte header, payload sections, CRC32)
  * ADR-120 privacy classes + PrivacyGate::demote + apply_privacy_gating
  * ADR-121 multiplicative risk score + CoherenceGate + SoulMatchOracle
  * ADR-122 MQTT topic router + HA discovery + availability + LWT
  * ADR-123 capture path (reference; production capture is Pi5/Nexmon
    hardware-gated and remains skipped)
  * BfldPipelineHandle worker + spawn_with_oracle for Soul Signature
  * 3 operator HA blueprints (presence-lighting / motion-HVAC /
    identity-risk-anomaly)
  * Two runnable examples (bfld_minimal, bfld_handle)
  * eclipse-mosquitto:2 CI service container workflow
  * Performance measurements: 320k frames/sec, p95 0.9µs, 9.96 Hz
  * 327 default-feature tests, 101 no_std-compatible, 220+ with mqtt
  * Companion research dossier docs/research/BFLD/ (11 files, 13,544 words)
  * try-it command: cargo run -p wifi-densepose-bfld --example bfld_handle

Added (in tests/changelog_entry.rs, 5 tests):
- changelog_documents_bfld_entry_under_unreleased
    Slices CHANGELOG from `## [Unreleased]` to the first numbered
    version header and asserts the block contains BFLD,
    wifi-densepose-bfld, and the #787 tracking link.
- changelog_bfld_entry_cites_companion_adrs
    Substring asserts ADR-118..123 each appear at least once.
- changelog_bfld_entry_names_three_structural_invariants
    **I1**, **I2**, **I3** must be called out by name.
- changelog_bfld_entry_documents_a_runnable_example
    Operators get a copy-pasteable cargo command.
- changelog_bfld_entry_references_research_bundle

Caught + fixed during iter:
- First draft used "ADR-118 through ADR-123" shorthand; the
  per-ADR substring test fired for ADR-120 (not literally present).
  Re-wrote the parenthetical to "ADR-118 umbrella + ADR-119 frame
  format + ADR-120 privacy class + ADR-121 identity risk scoring +
  ADR-122 RuView HA/Matter exposure + ADR-123 capture path" so each
  ADR number is its own grep-discoverable token.

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- Pre-merge checklist item #5 (CLAUDE.md) — CHANGELOG `[Unreleased]`
  entry shipped. PR description can now link to the line + commit
  range as evidence.

Test config:
- cargo test --no-default-features → 101 passed (changelog_entry cfg-out)
- cargo test                       → 332 passed (327 + 5)

Out of scope (next iter target):
- Pre-merge checklist remaining: README.md update (#3 — points at the
  new crate from the workspace level), user-guide.md (#6), witness
  bundle regeneration (#8). External-resource-gated work (KIT BFId,
  Pi5/Nexmon) still skipped.

Co-Authored-By: claude-flow <ruv@ruv.net>

* docs(adr-118): root README Documentation table BFLD row (337/337 GREEN)

Iter 51. PR-readiness pivot iter #2. Adds BFLD to the workspace-root
README.md Documentation table — closes pre-merge checklist item #3
(README.md update if scope changed). GitHub renders this; new
contributors / operators browsing ruvnet/RuView see the entry on
landing.

Added (in README.md, top-level Documentation table):
- New row right after the Home Assistant + Matter row, linking to
  v2/crates/wifi-densepose-bfld/README.md (iter-49 crate README).
- Summary covers:
    * 3 type-enforced structural invariants
      (raw BFI never exits / in-RAM-only embedding / cross-site
       cryptographically impossible)
    * Full operator surface (BfldPipeline, BfldPipelineHandle,
      SoulMatchOracle)
    * MQTT topic router + HA-DISCO + availability + LWT
    * 3 operator HA blueprints
    * Two runnable examples
    * eclipse-mosquitto:2 CI service container
    * 327+ tests
- Per-ADR links: 118 (umbrella), 119 (frame), 120 (privacy class),
  121 (risk scoring), 122 (HA/Matter), 123 (capture path)
- Research dossier pointer: docs/research/BFLD/ (11 files, 13,544 words)

Added (in v2/crates/wifi-densepose-bfld/tests/root_readme_link.rs):
- 5 named tests via include_str!:
    root_readme_links_to_bfld_crate_readme
    root_readme_mentions_bfld_acronym_and_full_name
    root_readme_cites_all_six_bfld_adrs (per-ADR substring check)
    root_readme_points_at_research_bundle
    root_readme_documents_three_structural_invariants_in_summary
      ("raw BFI never exits", "in-RAM-only", "cross-site" — three
       invariants surfaced in the short table summary)

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- Pre-merge checklist item #3 (CLAUDE.md) — root README updated to
  point at the new crate. Operator discovery path now reaches BFLD
  from the GitHub repo landing page in 1 click.
- ADR-118 §2.1 documentation surface — discovery path complete:
  GitHub README → crate README → operator examples → ADRs → research
  dossier. All hops covered by include_str + link tests.

Test config:
- cargo test --no-default-features → 101 passed (root_readme_link cfg-out)
- cargo test                       → 337 passed (332 + 5)

Out of scope (next iter target):
- Pre-merge checklist remaining: user-guide.md update (#6) if new CLI
  flags / setup steps, witness bundle regeneration (#8). External-
  resource-gated work (KIT BFId, Pi5/Nexmon) still skipped.

Co-Authored-By: claude-flow <ruv@ruv.net>

* docs(adr-124): RUVIEW-POLICY layer + Q4 cache resolution + multi-modal vision

Three additive sections per maintainer review of SENSE-BRIDGE
(the original 13-section draft is unchanged below; these are
inserts):

§4.1a — RUVIEW-POLICY governance layer (NEW). Five tools:
- ruview.policy.can_access_vitals(agent_id, node_id, vital)
- ruview.policy.can_query_presence(agent_id, scope, node_id?, zone?)
- ruview.policy.can_subscribe(agent_id, topic, duration_s)
- ruview.policy.redact_identity_fields(payload, agent_id)
- ruview.policy.audit_log(agent_id?, since_ts?)

Enforcement is server-side, not client-side — agents cannot bypass.
Default policy when no file exists: deny vitals + audit_log; allow
presence.now + node.list; allow primitives.list_active with
redact_identity_fields applied. "Explore safely" default.

Q4 — RESOLVED. The library MUST take continuous local cache +
event-driven invalidation + bounded freshness windows. Tools
never wait on the next CSI frame; cache hits return in <1 ms;
every tool accepts max_age_ms and returns
{ value: null, reason: "stale", last_seen_ms, threshold_ms }
when stale rather than blocking. Decouples agent orchestration
latency from RF acquisition jitter — required to scale to dozens
of concurrent Streamable HTTP sessions per Q8.

§11.3 — Strategic implication: ambient-sensing normalization
layer (NEW). The §4 tool catalog shape is modality-agnostic.
Same surface absorbs BLE / mmWave (already on COM4) / LiDAR /
thermal / camera / radar / UWB. Position as semantic-environment
API, not WiFi client. Follow-on ADR-13x RUVIEW-FUSION formalizes
per-modality adapter contract. Out of scope for 124; designed in.

§11.2 risk table — added the "sensing-tool surface becomes
surveillance API" row, mitigation = RUVIEW-POLICY layer + server-
side redaction.

Refs: docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md

* feat(adr-124/packaging): rename to @ruvnet/rvagent 0.1.0 + manifest test (ADR-124 §2)

Advances SPARC Phase 1 (Specification) for ADR-124 SENSE-BRIDGE by establishing
the correct npm package identity that all subsequent implementation iters depend on.

Changes:
- tools/ruview-mcp/package.json
  - name: @ruv/ruview-mcp → @ruvnet/rvagent  (ADR-124 §2.1)
  - version: 0.0.1 → 0.1.0  (initial publishable milestone)
  - removed private:true so the package is publishable  (ADR-124 §2.6)
  - bin: added rvagent key alongside legacy ruview-mcp alias  (ADR-124 §2.4)
  - exports: added "." entry with import+types keys for ESM+CJS dual output  (ADR-124 §2.5)
  - files: added README.md and CHANGELOG.md slots  (ADR-124 §5 npm publish plan)
  - keywords: expanded with sense-bridge, rvagent, ruvnet
  - repository / homepage / bugs: wired to github.com/ruvnet/RuView

- tools/ruview-mcp/src/index.ts
  - SERVER_NAME: "ruview" → "rvagent"
  - PACKAGE_VERSION: "0.0.1" → "0.1.0"
  - stderr log prefix: [ruview-mcp] → [@ruvnet/rvagent]

- tools/ruview-mcp/tests/manifest.test.ts  (NEW)
  - 10 ADR-124 §2 acceptance-criterion assertions, all green
  - Guards name, version >=0.1.0, engines.node >=20, bin.rvagent, exports structure,
    publishConfig.access, @modelcontextprotocol/sdk dep, zod dep, ESM type, license

Test results: 26/26 PASS (manifest.test.ts ×10 + tools.test.ts ×5 + validate.test.ts ×11)
Build: tsc clean, zero errors.

Next iter target: (A) Zod schema barrel for the 15+5 tool catalog from ADR-124 §4.1/4.1a

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-124/pseudocode): Zod schema barrel for all 20 ADR-124 §4.1+§4.1a tools

Advances SPARC Phase 2 (Pseudocode) — typed schemas are the language-level
design artifact that defines the complete tool surface before any HTTP/WS
plumbing is written. The schema map + TOOL_NAMES catalog are the pseudocode
contract that Phase 3 (Architecture) wires to the MCP Server dispatch loop.

New files under tools/ruview-mcp/src/schemas/:

  common.ts — shared Zod sub-schemas
    NodeIdSchema, DurationSSchema (max 3600 s), WindowSSchema (max 300 s),
    SemanticPrimitiveKindSchema (10 ADR-115 primitives enum), PosePersonResultSchema
    (17-keypoint COCO array + confidence + optional AETHER person_id)

  tools.ts — 20 input schemas + TOOL_NAMES catalog + TOOL_INPUT_SCHEMAS dispatch map
    §4.1 sensing (15): presence.now, vitals.get_{breathing,heart_rate,all},
      pose.{latest,subscribe}, primitives.{get,list_active,subscribe},
      bfld.{last_scan,subscribe}, node.{list,status},
      vector.{search_pose,store_pose}
    §4.1a policy (5): policy.{can_access_vitals, can_query_presence,
      can_subscribe, redact_identity_fields, audit_log}

  index.ts — barrel re-export of both modules

New test: tests/schemas.test.ts (24 assertions)
  - Catalog completeness: exactly 20 tools, all §4.1 + §4.1a names present,
    TOOL_INPUT_SCHEMAS one-to-one with catalog (no extras)
  - Happy-path parse: 11 representative schemas accept valid inputs
  - Constraint rejection: 8 schemas reject invalid inputs (empty NodeId,
    DurationS=0 / >3600, unknown primitive, wrong keypoint length, k>100,
    unknown vital, missing required node_id)

Fix: use Object.prototype.hasOwnProperty instead of Jest toHaveProperty for
dotted-key names (Jest interprets dots as nested path separators).

Test results: 50/50 PASS (schemas ×24 + manifest ×10 + tools ×5 + validate ×11)
Build: tsc clean, zero errors.

ACs touched: ADR-124 §4.1 complete tool surface; §4.1a policy layer surface;
  Phase 2 gate: pseudocode covers all acceptance criteria from spec.

Next iter target: Phase 3 (Architecture) — wire TOOL_INPUT_SCHEMAS into the
  MCP Server CallTool handler as a uniform validation gate; add Streamable HTTP
  transport scaffold with Origin-validation middleware (option C).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-124/architecture): schema-validation gate + Streamable HTTP transport (ADR-124 §3)

Advances SPARC Phase 3 (Architecture): wires the phase-2 schema barrel into
the MCP CallTool dispatch loop, and scaffolds the Streamable HTTP transport
with Origin-validation and bearer-token auth as specified in ADR-124 §3/§6.

Sub-task (a) — Uniform Zod validation gate in src/index.ts:
  - Import TOOL_INPUT_SCHEMAS + McpError + ErrorCode from SDK
  - CallTool handler: before dispatch, looks up schema by tool name using
    Object.prototype.hasOwnProperty (safe for dotted keys) then runs
    schema.safeParse(args); failures throw McpError(InvalidParams) so the
    caller receives a typed JSON-RPC error rather than a wrapped string
  - Re-throws McpError instances unchanged (policy errors propagate cleanly)

Sub-task (b) — src/http-transport.ts (new, 145 LOC):
  - buildHttpApp(mcpServer, opts): creates Node.js http.Server +
    StreamableHTTPServerTransport without binding; testable in isolation
  - createHttpTransport(mcpServer, opts): binds and resolves when listening
  - isOriginAllowed(origin, allowedOrigins): pure function — undefined origin
    allowed (non-browser), present origin validated against allowlist,
    '*' disables gate for local-dev
  - Bearer-token gate: RVAGENT_HTTP_TOKEN env or opts.bearerToken; missing/
    wrong token → 401 before any JSON-RPC processing
  - Bind default: 127.0.0.1 per MCP spec security requirement (ADR-124 §3)
  - Transport connect() only in createHttpTransport (not buildHttpApp) to
    avoid exactOptionalPropertyTypes false-incompatibility in test contexts

New test: tests/http-transport.test.ts (11 assertions):
  - isOriginAllowed() unit ×5: undefined allowed, allowlist hit/miss, wildcard,
    case-sensitivity (RFC 6454)
  - Origin-validation integration ×3: cross-origin → 403 with error body,
    allowed origin → non-403, no Origin → non-403
  - Bearer-token integration ×3: missing → 401, wrong → 401, correct → non-401

Fix: @types/express added as devDep (express is transitive from SDK ^1.29.0).

Test results: 61/61 PASS (+11 new)
Build: tsc clean, zero errors.

ACs touched: ADR-124 §3 (dual-transport architecture), §6 (Origin validation,
  127.0.0.1 bind, bearer-token auth slot). SPARC Phase 3 gate criteria met:
  API contracts typed, module boundaries established, no circular deps.

Next iter target: Phase 4 (Refinement) — implement ruview.bfld.last_scan +
  ruview.bfld.subscribe tool handlers (BFLD wire format stable post-ADR-118),
  register them in the TOOLS array using the new schema-validation gate.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-124/phase4): BFLD tool family — bfld.last_scan + bfld.subscribe (ADR-124 §4.1)

Advances SPARC Phase 4 (Refinement): implements the first two ADR-124 §4.1
sensing tools, which also serve as integration tests for the schema-validation
gate wired in Phase 3 (iter 3).

New files:
  src/tools/bfld-last-scan.ts
    - bfldLastScanSchema: z.object with optional node_id (min 1) + optional
      sensing_server_url — enforces the ADR-124 §4.1 input contract
    - bfldLastScan(): proxies GET /api/v1/bfld/<node_id>/last_scan from the
      sensing-server; returns BfldLastScanResult{ok,node_id,identity_risk_score,
      privacy_class,n_frames,timestamp_ms} on success
    - Converts BfldEvent.timestamp_ns (ns) → timestamp_ms (ms)
    - Uses person_count as n_frames proxy per ADR-118 BfldEvent shape
    - Returns {ok:false,warn:true} when server unreachable (soft-failure convention)

  src/tools/bfld-subscribe.ts
    - bfldSubscribeSchema: z.object with required duration_s (positive, max 3600)
    - bfldSubscribe(): POST /api/v1/bfld/<node_id>/subscribe?duration_s=<n>
    - Synthetic envelope fallback: when server unreachable, synthesises a valid
      {subscription_id (UUID v4), expires_at, topic} locally so the schema gate
      is always exercised and the caller can track the intent
    - topic format: ruview/<node_id>/bfld/* (ADR-122 §2.2 wildcard)

src/index.ts:
    - Import bfldLastScan + bfldSubscribe
    - Two new TOOLS entries: ruview.bfld.last_scan + ruview.bfld.subscribe
    - Both go through the TOOL_INPUT_SCHEMAS schema-validation gate (iter 3)

New test: tests/bfld-tools.test.ts (14 assertions):
    - bfldLastScan: unreachable → ok:false+warn:true, malformed path,
      ns→ms arithmetic, null identity_risk_score coalescing
    - BfldLastScanInputSchema: empty object accepted, empty node_id rejected
    - bfldSubscribe: subscription_id defined + future expires_at, UUID v4 format,
      expires_at timing accuracy (±50ms), topic pattern match
    - BfldSubscribeInputSchema: duration_s > 3600 rejected, duration_s=0 rejected

Test results: 75/75 PASS (+14). Build: tsc clean.

ACs touched: ADR-124 §4.1 ruview.bfld.last_scan + ruview.bfld.subscribe.
  SPARC Phase 4 gate: acceptance criteria have passing tests; code review
  against spec complete; no critical issues.

Next iter target: Phase 4 continued — ruview.presence.now + ruview.vitals.*
  tool handlers (4 tools), following the same pattern; then Phase 5 (Completion)
  with package metadata, CHANGELOG, and witness-bundle extension.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-124/phase4): presence.now + vitals.get_* tool family (ADR-124 §4.1)

Advances SPARC Phase 4 (Refinement) iter 5: implements ruview.presence.now
and all three ruview.vitals.* tools sharing a single fetchVitals() helper.

src/types.ts:
  - Added EdgeVitalsMessage interface (mirrors Python ws.py:74-88 per ADR-124 §6):
    node_id, timestamp_ms, presence, n_persons, confidence, breathing_rate_bpm,
    heartrate_bpm, motion, zone_id

src/tools/vitals-fetch.ts (new):
  - fetchVitals(nodeId, baseUrl, token): GET /api/v1/vitals/<node_id>/latest
  - Returns VitalsFetchOk | VitalsFetchErr — all four tools project from one fetch
  - resolveNodeId(): "default" fallback for optional node_id

src/tools/presence-now.ts (new):
  - presenceNow(): projects {present, n_persons, confidence, timestamp_ms}

src/tools/vitals-get-breathing.ts (new):
  - vitalsGetBreathing(): projects {breathing_rate_bpm|null, confidence, timestamp_ms}

src/tools/vitals-get-heart-rate.ts (new):
  - vitalsGetHeartRate(): projects {heartrate_bpm|null, confidence, timestamp_ms}

src/tools/vitals-get-all.ts (new):
  - vitalsGetAll(): spreads full EdgeVitalsMessage (raw never present server-side)

src/index.ts:
  - 4 new TOOLS entries; all route through Phase 3 schema-validation gate

tests/vitals-tools.test.ts (new, 18 assertions):
  - resolveNodeId ×2; fetchVitals soft-fail ×1
  - presence.now: soft-fail, field projection, schema accept/reject ×4
  - vitals.get_breathing: soft-fail, bpm projection, null bpm, window_s ×4
  - vitals.get_heart_rate: soft-fail, bpm projection, schema ×3
  - vitals.get_all: soft-fail, full spread + no raw field, schema ×3

Test results: 93/93 PASS (+18). Build: tsc clean.

ACs touched: ADR-124 §4.1 ruview.presence.now, ruview.vitals.get_breathing,
  ruview.vitals.get_heart_rate, ruview.vitals.get_all. Phase 4 gate: all
  acceptance criteria have passing tests; coverage expanding toward threshold.

Next iter target: Phase 5 (Completion) — CHANGELOG entry, package metadata
  review, witness-bundle extension for npm tarball sha256, then open the PR.
  (Remaining §4.1 tools — pose, primitives, node, vector — can land as post-
  merge follow-up iters given Phase 5 gate criteria are otherwise met.)

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-124/phase5): SENSE-BRIDGE docs batch — README, CHANGELOG, workspace docs

Advances SPARC Phase 5 (Completion) docs gate: landing page, changelog entry,
workspace documentation table row, and user-guide subsection.

tools/ruview-mcp/README.md (NEW, 60 lines):
  - npm-rendered landing page for @ruvnet/rvagent
  - Quickstart: claude mcp add / npx stdio / HTTP with RVAGENT_HTTP_TOKEN
  - Feature matrix: 6 wired tools + next-iter placeholders, transport security
    summary (Origin validation → 403, bearer token → 401, 127.0.0.1 bind)
  - Schema validation gate + RUVIEW-POLICY default-deny description
  - ADR cross-reference table: ADR-124/118/122/115/055

CHANGELOG.md (Unreleased Added bullet):
  - SENSE-BRIDGE entry after BFLD bullet; names all 6 wired tools by MCP
    tool name, stdio + Streamable HTTP transports, security model, Zod schema
    barrel (20 tools + 5 policy), EdgeVitalsMessage Python parity,
    93 tests / 7 suites, try-it quickstart command

README.md (Documentation table):
  - New row after BFLD row: SENSE-BRIDGE summary with 6 tool names, transport
    security summary, ADR-124 link, npx quickstart

docs/user-guide.md (subsection after BFLD):
  - ### SENSE-BRIDGE — rvagent MCP server for AI agents (ADR-124)
  - Claude Code install command + remote sensing-server variant
  - 6-tool markdown table with return shapes
  - Streamable HTTP usage block (RVAGENT_HTTP_TOKEN, 403/401 behavior)
  - Links to tools/ruview-mcp/README.md, ADR-124, issue #787

Test count: 93/93 PASS (unchanged — docs-only iter). Build: tsc clean.

ACs touched: Phase 5 gate — documentation complete; every wired tool
  documented in README, CHANGELOG, workspace docs, and user-guide.

Next iter target: iter 7 — extend scripts/generate-witness-bundle.sh for
  npm tarball sha256, run a full witness, then open PR → main.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-124/phase5): witness bundle — npm tarball sha256 for @ruvnet/rvagent

Extends scripts/generate-witness-bundle.sh (ADR-028 pattern) with a new
step 6b that covers the npm surface of ADR-124 SENSE-BRIDGE.

Changes to generate-witness-bundle.sh:
  - Step [6b]: cd tools/ruview-mcp; npm run build; npm pack; sha256sum tarball
    Writes to bundle: npm-manifest/<tarball>.sha256, tarball-name.txt,
    tarball-sha256.txt. Removes local tarball after hashing (recorded not shipped).
  - VERIFY.sh heredoc: new Check 6 asserts npm-manifest/tarball-sha256.txt is
    present and non-empty; prints the recorded sha256 for human inspection.
    Old Check 6 (proof log) renumbered to Check 7, Check 7→8.
  - Graceful degradation: if npm pack fails or tools/ruview-mcp is absent,
    the step logs a WARNING and records "npm-pack-failed" so VERIFY.sh
    marks it FAIL without aborting the rest of the bundle.

Recorded sha256 for ruvnet-rvagent-0.1.0.tgz (built from commit 0752bbf9d):
  968ff5e2635e0dbe8cda38c6c549a9fb4f30cb9dedc572bf3c1eeadc0ae604e8

Test count: 93/93 PASS (unchanged). Build: tsc clean.

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-05-24 22:55:47 -04:00
rUv faecee9a37
feat(adr-118): BFLD — Beamforming Feedback Layer for Detection (#789)
* feat(adr-118/p1.4): BfldFrame (header + payload + CRC32) — 24/24 GREEN

Iter 4. Lands the central wire-format primitive: complete frames with
header + arbitrary-length payload, protected by CRC-32/ISO-HDLC.

Added:
- crc = "3" dependency (CRC-32/ISO-HDLC, same poly as Ethernet / zlib)
- src/frame.rs: CRC32_ALG const and crc32_of_payload(&[u8]) -> u32
- src/frame.rs: BfldFrame { header, payload: Vec<u8> } (gated on `std`)
  * BfldFrame::new(header, payload) — auto-syncs payload_len + payload_crc32
  * BfldFrame::to_bytes() -> Vec<u8> — header LE bytes ‖ payload
  * BfldFrame::from_bytes(&[u8]) -> Result<Self, BfldError>
- BfldError::TruncatedFrame { got, need } variant
- Doc strings on BfldError::Crc and BfldError::PrivacyViolation field names
- tests/frame_roundtrip.rs (7 named tests, gated on feature = "std"):
    frame_roundtrip_preserves_header_and_payload
    frame_new_syncs_payload_len_and_crc
    frame_serialization_is_deterministic
    frame_rejects_payload_crc_mismatch
    frame_rejects_truncated_buffer_smaller_than_header
    frame_rejects_truncated_buffer_smaller_than_payload
    empty_payload_is_valid (CRC of empty payload is 0x00000000)

Test config:
- cargo test --no-default-features → 17 passed (frame_roundtrip cfg-out)
- cargo test (default features = std)  → 24 passed (3+6+7+8)

ADR-119 ACs progressed:
- AC4 partial: bad-magic + bad-version + CRC-mismatch + truncation rejected
  with typed errors; field-level masking lives in the privacy_gate iter.
- AC5: BfldFrame round-trip preserves header + payload + CRC.
- AC6: Identical inputs produce bit-identical bytes (asserted explicitly).

Out of scope (next iter):
- Payload section parser (compressed_angle_matrix, amplitude_proxy, ...)
  — only the byte buffer is opaque so far; sections need length prefixes.
- BfldFrameRef<'_> for ESP32-S3 self-only mode (no-alloc, ADR-123 §2.5).
- PrivacyGate::demote(frame, target_class) transformer (ADR-120 §2.4).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p1.5): payload section parser (BfldPayload) — 32/32 GREEN

Iter 5. Implements ADR-119 §2.2 payload layout: 4-byte LE length prefix
followed by section bytes, in this fixed order:

  compressed_angle_matrix ‖ amplitude_proxy ‖ phase_proxy ‖ snr_vector
   ‖ csi_delta (iff flags.bit0)
   ‖ vendor_extension (length 0 allowed)

Added:
- src/payload.rs (gated on `feature = "std"`):
  * BfldPayload struct with 6 fields (csi_delta: Option<Vec<u8>>)
  * SECTION_PREFIX_LEN const (= 4)
  * to_bytes(include_csi_delta: bool) -> Vec<u8>
  * wire_len(include_csi_delta: bool) -> usize  (predictive, no allocation)
  * from_bytes(&[u8], expect_csi_delta: bool) -> Result<Self, BfldError>
  * push_section / read_section helpers (private)
- BfldError::MalformedSection { offset, reason } variant
- pub use BfldPayload from lib.rs (cfg-gated mirror of BfldFrame)

tests/payload_sections.rs (8 named tests, all green):
  payload_roundtrip_with_csi_delta
  payload_roundtrip_without_csi_delta
  wire_len_matches_to_bytes_length
  empty_payload_has_five_zero_length_sections
  parser_rejects_buffer_shorter_than_first_length_prefix
  parser_rejects_section_body_running_past_buffer_end
  parser_rejects_trailing_bytes_after_vendor_extension
  csi_delta_flag_mismatch_with_payload_is_detectable_via_trailing_bytes

ACs progressed:
- AC5 ↑ — full section-level round-trip preservation (round-trip with and
  without csi_delta both pass).
- AC6 ↑ — deterministic section encoding (length prefixes use to_le_bytes,
  body is byte-stable).
- AC1 partial — section layout now parses with bounded errors; CBFR-specific
  parsing (Phi/Psi Givens decoders) is a separate iter inside extractor.rs.

Test config:
- cargo test --no-default-features → 17 passed (payload module cfg-out)
- cargo test                       → 32 passed (3 + 6 + 7 + 8 + 8)

Out of scope (next iter target):
- Wire integration: feed BfldPayload bytes through BfldFrame::new so the
  header.payload_crc32 covers the section-prefixed bytes per ADR-119 §2.2
  ("CRC32 covers all section bytes including length prefixes").
- A no_std-friendly BfldPayloadRef<'_> borrowing variant (ESP32-S3 path).
- Givens-rotation angle decoder (Phi/Psi extraction from compressed_angle_matrix).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p1.6): BfldFrame <-> BfldPayload wire integration (39/39 GREEN)

Iter 6. Connects the typed payload parser (iter 5) to the framed
wire format (iter 4): the CRC32 now covers the section-prefixed
payload bytes per ADR-119 §2.2 ("CRC32 covers all section bytes
including length prefixes").

Added:
- BfldFrame::from_payload(header, &BfldPayload) -> Self
  Auto-syncs header.flags HAS_CSI_DELTA bit from payload.csi_delta.is_some(),
  serializes payload via to_bytes(), feeds BfldFrame::new() which computes
  payload_len + payload_crc32 over the section-prefixed bytes.
- BfldFrame::parse_payload(&self) -> Result<BfldPayload, BfldError>
  Reads HAS_CSI_DELTA bit from header.flags and dispatches to
  BfldPayload::from_bytes(&self.payload, expect_csi_delta).

tests/frame_payload_integration.rs (7 named tests, all green):
  from_payload_then_parse_payload_is_identity
  from_payload_autosets_has_csi_delta_flag
  from_payload_clears_has_csi_delta_flag_when_csi_absent
    (verifies the flag is cleared when csi_delta is None even if caller
     pre-set the bit; other flag bits like PRIVACY_MODE are preserved)
  frame_crc_covers_section_prefixed_bytes
    (mutating a byte inside section body trips CRC, not magic/length)
  frame_crc_covers_section_length_prefixes
    (mutating a section length-prefix byte trips CRC before parser ever runs)
  empty_typed_payload_roundtrips
  end_to_end_wire_roundtrip_via_bytes
    (BfldPayload -> from_payload -> to_bytes -> from_bytes -> parse_payload
     is the identity function modulo flag auto-set)

ACs progressed:
- AC5 ↑ — full payload round-trip through the framed bytes (closes
  the round-trip leg from BfldPayload through wire and back).
- AC6 ↑ — same input produces same bytes through both layers.
- AC4 ↑ — CRC mismatch on tampered section bodies and tampered section
  length prefixes both surface as BfldError::Crc, not as silent acceptance
  or as a deeper parser error.

Test config:
- cargo test --no-default-features → 17 passed (integration tests cfg-out)
- cargo test                       → 39 passed (3 + 6 + 7 + 8 + 8 + 7)

Out of scope (next iter target):
- PrivacyGate::demote(frame, target_class) — ADR-120 §2.4 class transition
  transformer with subtle::Zeroize on dropped fields.
- IdentityEmbedding newtype with no Serialize impl (ADR-120 §2.5 / I2).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p2.1): IdentityEmbedding newtype + zeroizing Drop — 44/44 GREEN

Iter 7. First structural enforcement of ADR-118 invariant I2 — the
identity embedding is in-RAM-only and cannot be serialized, cloned,
or copied. Lands the type itself; ring-buffer lifecycle is next.

Added:
- src/embedding.rs (no_std-compatible; lives in the lib regardless of features):
  * IdentityEmbedding wrapping [f32; EMBEDDING_DIM=128]
  * from_raw(values), as_slice() -> &[f32], l2_norm(), len(), is_empty()
  * NO Serialize, NO Clone, NO Copy impl
  * Custom Debug emits only dim + L2 norm + "<redacted>" — never raw values
  * Drop overwrites storage with 0.0 then core::hint::black_box(...) to defeat
    dead-store elimination (DSE would otherwise let the compiler skip the write)
- Compile-time structural guards via static_assertions:
    assert_impl_all!(IdentityEmbedding: Drop)
    assert_not_impl_any!(IdentityEmbedding: Copy, Clone)
- pub use IdentityEmbedding, EMBEDDING_DIM from lib.rs

tests/identity_embedding.rs (5 named tests, all green):
  from_raw_preserves_values_through_as_slice
  l2_norm_is_correct
  debug_output_redacts_raw_values
    (asserts the formatted output does NOT contain decimal text of values)
  embedding_is_not_clonable
    (runtime witness; compile-time assertion lives in src/embedding.rs)
  drop_overwrites_storage_with_zeros
    (Drop runs without panic; bit-level zeroization is asserted by the
     black_box-guarded loop. Unsafe peek-after-free is intentionally avoided.)

ACs progressed:
- AC5 ↑ — even in `privacy_mode`, the IdentityEmbedding type can't be reached
  from any serialization path because the type system rejects the impl.
- I2 ↑ — Drop, no Clone, no Copy, redacted Debug are all in place as
  compile-time guarantees.

Test config:
- cargo test --no-default-features → 22 passed
- cargo test                       → 44 passed (3 + 6 + 7 + 8 + 8 + 7 + 5)

Out of scope (next iter target):
- EmbeddingRing — 64-entry FIFO ring buffer holding IdentityEmbeddings,
  drained on coherence-gate Recalibrate (ADR-121 §2.4).
- PrivacyGate::demote(frame, target_class) transformer (ADR-120 §2.4).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p2.2): EmbeddingRing 64-entry FIFO buffer — 53/53 GREEN

Iter 8. Lands the lifecycle half of ADR-120 §2.5: a bounded, in-place,
no_std-compatible ring of IdentityEmbeddings. Insertion is O(1); when
full, push evicts the oldest entry, whose Drop runs and zeroizes the
f32 storage. drain() clears the ring on the coherence-gate Recalibrate
action (ADR-121 §2.4).

Added:
- src/embedding_ring.rs (no_std-compatible; no heap):
  * EmbeddingRing struct with [Option<IdentityEmbedding>; RING_CAPACITY=64]
    backing array, head cursor, count
  * EmbeddingRing::new() / Default impl
  * push(emb) -> Option<IdentityEmbedding>  (evicted oldest when full)
  * len / is_empty / capacity / is_full / iter
  * iter() returns occupied slots in insertion order (oldest first)
  * drain() -> usize  (empties the ring, returns count drained)
- pub use EmbeddingRing, RING_CAPACITY from lib.rs

Uses `[const { None }; RING_CAPACITY]` (stable since 1.79) to initialize
the slot array for a non-Copy element type.

tests/embedding_ring.rs (9 named tests, all green):
  new_ring_is_empty
  default_constructor_matches_new
  push_below_capacity_returns_none
  iter_yields_in_insertion_order
  push_at_capacity_evicts_oldest_and_returns_it
    (verifies eviction reports the FIRST pushed value, not the last)
  push_beyond_capacity_keeps_last_n_entries
    (after 74 pushes into a 64-slot ring, the surviving 64 are positions 10..74)
  drain_empties_the_ring_and_returns_count
  drain_on_empty_ring_returns_zero
  ring_can_be_refilled_after_drain
    (post-drain push lands cleanly at index 0; iter yields exactly that entry)

ACs progressed:
- I2 ↑ — ring eviction and explicit drain both drop IdentityEmbeddings,
  which the iter-7 Drop impl zeroizes. The "in-RAM-only" lifecycle is now
  end-to-end: bounded buffer in, FIFO out, drain on Recalibrate.

Test config:
- cargo test --no-default-features → 31 passed (22 + 9)
- cargo test                       → 53 passed (44 + 9)

Out of scope (next iter target):
- PrivacyGate::demote(frame, target_class) — ADR-120 §2.4 monotonic class
  transition with field zeroization, refusing demote-to-Raw (compile-fail).
- SoulMatchOracle stub trait + no-op default impl (ADR-121 §2.6) so the
  Recalibrate exemption hook is wireable from `--features soul-signature`.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p3.1): PrivacyGate::demote monotonic class transformer (60/60 GREEN)

Iter 9. Lands ADR-120 §2.4 — the only operation that can lower a frame's
information content. Demote is monotonic by construction (Result::Err
on non-monotone target), strips payload sections per the target class
table, and re-syncs header.privacy_class + CRC32.

Added:
- src/privacy_gate.rs (gated on `feature = "std"`):
  * PrivacyGate unit struct (+ Default impl)
  * PrivacyGate::demote(BfldFrame, target: PrivacyClass) -> Result<BfldFrame>
  * Stripping policy:
      target >= Anonymous (2): zeros + clears compressed_angle_matrix and
        csi_delta; sets csi_delta = None so from_payload clears HAS_CSI_DELTA
      target >= Restricted (3): also zeros + clears amplitude_proxy and phase_proxy
  * zeroize_then_clear helper — overwrite with 0 then black_box then truncate
- BfldError::InvalidDemote { from: u8, to: u8 } variant
- pub use PrivacyGate from lib.rs

Note: demote does NOT zero the original Vec capacity that the heap allocator
may still hold — the buffers we own are zeroed and cleared, but the
intermediate Vec passed back to BfldFrame::from_payload reallocates anew.
For strict heap zeroization in regulated deployments, a follow-up iter can
substitute zeroize::Zeroizing<Vec<u8>>.

tests/privacy_gate_demote.rs (7 named tests, all green):
  demote_to_same_class_is_identity
  demote_derived_to_anonymous_strips_compressed_angle_matrix
    (also asserts csi_delta dropped, snr_vector and amplitude_proxy preserved)
  demote_derived_to_restricted_strips_amplitude_and_phase_too
    (snr_vector and vendor_extension survive at class 3)
  demote_anonymous_to_derived_is_rejected
    (asserts InvalidDemote { from: 2, to: 1 })
  demote_to_raw_is_rejected_from_any_higher_class
    (parameterized over Derived, Anonymous, Restricted as sources)
  demote_preserves_frame_crc_consistency_through_wire_roundtrip
    (post-demote frame survives to_bytes -> from_bytes with no CRC error)
  demote_clears_has_csi_delta_flag_bit

ACs progressed:
- AC5 ↑ — privacy_mode enforcement at the frame-class boundary now works
  through PrivacyGate, not just the BfldEvent emitter (deferred). When the
  active class is Anonymous (2) or Restricted (3), the angle matrix /
  csi_delta / amplitude / phase sections that carry identity information
  are zeroed before any downstream code sees them.
- AC4 ↑ — demoted frames retain valid CRC; the round-trip-through-bytes
  test proves bit-correctness after the class transition.

Test config:
- cargo test --no-default-features → 31 passed (privacy_gate cfg-out)
- cargo test                       → 60 passed (53 + 7)

Out of scope (next iter target):
- SoulMatchOracle stub trait + no-op default impl (ADR-121 §2.6) so the
  Recalibrate exemption hook is wireable from `--features soul-signature`.
- IdentityRiskEngine — multiplicative formula on (sep, stab, consist, conf)
  with the coherence-gate GateAction enum (ADR-121 §2.2 + §2.4).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p3.2): identity_risk score + GateAction enum — 72/72 GREEN

Iter 10. Lands the stateless half of ADR-121 §2.2–§2.4: the
multiplicative risk-score formula and the 4-band gate classifier.
Hysteresis + 5s debounce (stateful CoherenceGate) land in iter 11.

Added (no_std-compatible):
- src/identity_risk.rs:
  * score(sep, stab, consist, conf) -> f32
    Each input clamped to [0,1]; NaN → 0 (conservative). Multiplicative
    combination: any near-zero factor collapses the score → privacy-biased.
  * Threshold constants: PREDICT_ONLY_THRESHOLD=0.5, REJECT_THRESHOLD=0.7,
    RECALIBRATE_THRESHOLD=0.9
  * GateAction enum: Accept | PredictOnly | Reject | Recalibrate
  * GateAction::from_score(f32) -> Self  — band-based classification with
    inclusive lower edges (0.7 maps to Reject, 0.9 maps to Recalibrate)
  * GateAction::allows_publish() / drops_event() / requires_recalibrate()
- pub use identity_risk_score (the function) and GateAction from lib.rs

tests/identity_risk_score.rs (12 named tests, all green):
  all_ones_yields_one
  any_zero_factor_collapses_score_to_zero (4 single-factor variants)
  score_is_monotonic_non_decreasing_in_single_factor
  out_of_range_inputs_are_clamped_to_unit_interval
  nan_inputs_treated_as_zero (verifies privacy-conservative NaN handling)
  known_score_matches_hand_calculation (0.8*0.9*0.85*0.95 to 1e-6)
  from_score_classifies_each_band (8 boundary-condition checks)
  threshold_constants_match_documented_values
  nan_score_maps_to_accept_conservatively
  allows_publish_partitions_actions_correctly
  drops_event_inverts_allows_publish (parameterized over all 4 actions)
  requires_recalibrate_is_unique_to_recalibrate

ACs progressed:
- ADR-121 AC2 partial — `score` formula structurally enforces non-negativity,
  upper bound 1.0, and conservative behavior under uncertainty (NaN, negative
  input, single near-zero factor).
- ADR-121 AC7 partial — score function is pure / deterministic; identical
  inputs always produce identical outputs (asserted by the known-value test).

Test config:
- cargo test --no-default-features → 43 passed (31 + 12)
- cargo test                       → 72 passed (60 + 12)

Out of scope (next iter target):
- CoherenceGate stateful struct: ±0.05 hysteresis + 5-second debounce
  (ADR-121 §2.5) so the gate doesn't oscillate near band boundaries.
- SoulMatchOracle stub trait (ADR-121 §2.6) — the Recalibrate exemption
  hook for `--features soul-signature` deployments.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p3.3): CoherenceGate hysteresis + 5s debounce — 85/85 GREEN

Iter 11. Wraps the stateless GateAction classifier from iter 10 with two
stabilizing mechanisms per ADR-121 §2.5:

  * ±0.05 HYSTERESIS — a score must clear the current band's edge by
    HYSTERESIS before the gate considers the next band.
  * 5-second DEBOUNCE_NS — a different action must persist that long
    before it becomes current; returning to the current band cancels it.

Added (no_std-compatible):
- src/coherence_gate.rs:
  * HYSTERESIS const (0.05) + DEBOUNCE_NS const (5_000_000_000)
  * CoherenceGate { current, pending: Option<(GateAction, u64)> }
  * new() / Default / current() / pending() (diagnostic accessors)
  * evaluate(score, timestamp_ns) -> GateAction
    Algorithm: compute effective_target via per-direction hysteresis check,
    promote pending after DEBOUNCE_NS elapsed, cancel pending on return to
    current band, reset debounce clock if pending target changes
  * Private helpers effective_target / action_idx / upper_edge_of / lower_edge_of
- pub use CoherenceGate from lib.rs

tests/coherence_gate.rs (13 named tests, all green):
  fresh_gate_starts_in_accept_with_no_pending
  low_score_stays_in_accept_with_no_pending
  score_just_past_boundary_but_within_hysteresis_does_not_pend
    (0.52: above 0.5 but inside hysteresis envelope — no pending)
  score_clearly_past_hysteresis_starts_pending
    (0.6: past 0.55 hysteresis edge — pending PredictOnly registered)
  pending_action_promotes_after_full_debounce
  pending_action_does_not_promote_before_debounce
    (verified at DEBOUNCE_NS - 1)
  returning_to_current_band_cancels_pending
  changing_pending_target_resets_the_debounce_clock
    (PredictOnly pending at t=0, then Recalibrate at t=1s — clock resets,
     must wait until t=1s+DEBOUNCE_NS before Recalibrate is current)
  downward_transitions_also_require_hysteresis
    (from PredictOnly, 0.48 stays put; 0.44 pends Accept)
  spike_to_one_then_back_to_zero_never_promotes_to_recalibrate
    (transient spike + return to baseline produces no transition)
  boundary_value_with_hysteresis_does_not_promote (0.5+0.05-epsilon)
  boundary_value_at_hysteresis_exact_does_pend (0.5+0.05)
  nan_score_stays_in_current_action_with_no_pending

ACs progressed:
- ADR-121 AC4 — Recalibrate fires when score >= 0.9 for >= DEBOUNCE_NS (5s).
  The debounce test above directly exercises this.
- ADR-121 AC5 — hysteresis test confirms action does not oscillate across
  ± 0.05 of a threshold within a 5-second window.

Test config:
- cargo test --no-default-features → 56 passed (43 + 13)
- cargo test                       → 85 passed (72 + 13)

Out of scope (next iter target):
- SoulMatchOracle stub trait (ADR-121 §2.6) + Recalibrate exemption —
  when --features soul-signature is enabled and the oracle reports a known
  enrolled person_id match, the gate downgrades Recalibrate → PredictOnly.
- BfldEvent struct (ADR-121 §2.1 output event) — first downstream consumer
  of the gate action.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p3.4): SoulMatchOracle + Recalibrate exemption (93/93 GREEN)

Iter 12. Wires the ADR-121 §2.6 Recalibrate exemption: when an enrolled
person_id matches the current high-separability cluster, the gate
downgrades the would-be Recalibrate to PredictOnly. The high score is
the *intended* outcome of a Soul Signature match, not an attacker-grade
sniffer arrival — so site_salt rotation is suppressed.

Added (no_std-compatible):
- src/coherence_gate.rs additions:
  * MatchOutcome enum: Match { person_id: u64 } | NotEnrolled | Suppressed
  * SoulMatchOracle trait with matches_enrolled() -> MatchOutcome
  * NullOracle (default-constructible, always reports NotEnrolled)
  * CoherenceGate::evaluate_with_oracle(score, ts, &O: SoulMatchOracle)
    — same hysteresis/debounce as evaluate(), but downgrades Recalibrate
    to PredictOnly when oracle returns Match { .. }
  * Refactored evaluate(): extracted advance_state(target, ts) shared with
    evaluate_with_oracle. evaluate is now a 4-line wrapper.
- pub use MatchOutcome, NullOracle, SoulMatchOracle from lib.rs

tests/soul_match_oracle.rs (8 named tests, all green):
  null_oracle_matches_default_evaluate_behavior
    (parameterized over 5 score points; oracle-aware and oracle-free
     gates produce identical trajectories)
  match_outcome_downgrades_recalibrate_to_predict_only
    (score=0.95 pends PredictOnly instead of Recalibrate)
  match_exemption_promotes_predict_only_after_debounce_not_recalibrate
    (after DEBOUNCE_NS, current is PredictOnly — never Recalibrate)
  match_outcome_does_not_affect_lower_actions
    (Reject pending stays Reject; oracle only intercepts Recalibrate)
  suppressed_outcome_does_not_exempt_recalibrate
    (Suppressed is functionally equivalent to NotEnrolled at the gate)
  not_enrolled_outcome_does_not_exempt_recalibrate
  match_outcome_carries_person_id
  null_oracle_default_constructor_works

ACs progressed:
- ADR-121 §2.6 fully covered as a stateless integration point — the
  hook is in place for the `--features soul-signature` Soul Signature
  crate (TBD) to plug in a real RaBitQ-backed oracle.
- ADR-118 §1.4 Soul Signature companion contract is now structurally
  enforced at the gate boundary: enrolled subjects do not trigger
  site_salt rotation; everyone else does.

Test config:
- cargo test --no-default-features → 64 passed (56 + 8)
- cargo test                       → 93 passed (85 + 8)

Out of scope (next iter target):
- BfldEvent struct (ADR-121 §2.1 output event JSON) — the downstream
  consumer of GateAction. Pairs the gate decision with presence/motion/
  person_count sensing fields.
- Optional: connect SoulMatchOracle into the actual `--features
  soul-signature` build (compile-time gate around a re-export).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p4.1): BfldEvent privacy-gated output + JSON (102/102 GREEN)

Iter 13. Lands ADR-121 §2.1 (output event) + ADR-122 §2.1 (field-gating
policy). BfldEvent collapses the GateAction-driven sensing pipeline
into the canonical wire-format publishable on MQTT.

Added:
- serde (workspace, derive feature, optional) + serde_json (workspace, optional) deps
- New crate feature `serde-json` (default-on; requires `std`)
- src/event.rs (gated on `feature = "std"`):
  * BfldEvent struct with all sensing + identity-derived fields
  * with_privacy_gating(...) constructor that applies field-gating policy:
      class < Restricted (3): identity_risk_score + rf_signature_hash kept
      class >= Restricted (3): both nulled to None
  * apply_privacy_gating() — idempotent in-place masking
  * to_json() -> Result<String, serde_json::Error> (gated on serde-json)
  * Custom ser_privacy_class serializer emits lowercase names
    ("anonymous", "restricted", etc.) per the BFLD JSON spec
  * skip_serializing_if = "Option::is_none" on identity-derived fields so
    privacy-gated events are observationally indistinguishable from
    events that never had the field set
- pub use BfldEvent from lib.rs

tests/event_privacy_gating.rs (9 named tests, all green):
  anonymous_event_retains_identity_risk_and_hash
  restricted_event_strips_identity_fields (class 3 → None)
  apply_privacy_gating_is_idempotent
  event_type_is_always_bfld_update (parameterized over 3 classes)
  json::json_round_trip_emits_type_field_first_or_last_but_present
  json::anonymous_json_includes_identity_fields
  json::restricted_json_omits_identity_fields_entirely
    (asserts the JSON string does NOT contain identity_risk_score or
     rf_signature_hash, verifying skip_serializing_if works as intended)
  json::privacy_class_serializes_to_lowercase_name
  json::zone_id_none_is_omitted_from_json

ACs progressed:
- ADR-121 AC6 (identity_risk score absent at class 3) — structurally
  enforced by with_privacy_gating + skip_serializing_if combination.
- ADR-122 AC1 — JSON shape matches the HA-DISCO publishable event
  contract; identity fields can be reliably stripped by privacy_class.
- ADR-118 AC5 — privacy_mode = engaged maps to PrivacyClass::Restricted
  with no identity fields in the published event.

Test config:
- cargo test --no-default-features → 64 passed (unchanged; event cfg-out)
- cargo test                       → 102 passed (93 + 9)

Out of scope (next iter target):
- Emitter struct that wires GateAction + privacy class + sensing inputs
  into BfldEvent construction (ADR-118 §2.1 pipeline diagram).
- MQTT topic publisher (ADR-122 §2.2) — depends on a runtime (tokio).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p4.2): BfldEmitter end-to-end pipeline (109/109 GREEN)

Iter 14. Wires every iter-1..13 primitive into a single ADR-118 §2.1
pipeline: per-frame sensing inputs go in, a privacy-gated BfldEvent
(or None) comes out. First time every constituent is exercised together.

Added (gated on `feature = "std"`):
- src/emitter.rs:
  * SensingInputs struct — 11 fields: timestamp_ns, presence, motion,
    person_count, sensing_confidence, sep, stab, consist, risk_conf,
    rf_signature_hash (Option)
  * BfldEmitter struct owning: node_id, default_zone_id, privacy_class,
    CoherenceGate, EmbeddingRing
  * Builder API: new(node_id) → with_zone(...) → with_privacy_class(...)
  * current_action() / ring_len() diagnostic accessors
  * emit(inputs, embedding) → Option<BfldEvent>
      1. score = identity_risk::score(sep, stab, consist, risk_conf)
      2. ring.push(embedding) if Some
      3. action = gate.evaluate_with_oracle(score, ts, &NullOracle)
      4. if action == Recalibrate { ring.drain() }
      5. if action.drops_event() { return None }
      6. else BfldEvent::with_privacy_gating(...) honoring privacy_class
  * emit_with_oracle(...) variant for `--features soul-signature` callers
- pub use BfldEmitter, SensingInputs from lib.rs

tests/emitter_pipeline.rs (7 named tests, all green):
  emitter_emits_event_under_low_risk
  emitter_drops_event_under_sustained_high_risk (debounce honored)
  emitter_drains_ring_on_recalibrate
    (fills ring to 5, then Recalibrate-grade score → ring_len() == 0)
  restricted_class_strips_identity_fields_in_emitted_event
    (class 3: identity_risk_score AND rf_signature_hash both None)
  with_zone_sets_default_zone_id_on_event
  embedding_is_pushed_to_ring_even_when_event_dropped
    (privacy gating drops the event but the ring still observes the
     embedding so subsequent separability calculations remain valid)
  ring_unchanged_when_no_embedding_supplied

ACs progressed:
- ADR-118 AC1 (BFLD core pipeline integration) — every component from
  iter 1 (frame format) through iter 13 (event) is now traversed by a
  single emit() call. This is the first end-to-end smoke proof.
- ADR-121 AC4 — Recalibrate-grade sustained score triggers ring drain
  (verified by ring_len() going from 5 to 0).
- ADR-122 AC1 — privacy_class threaded through the pipeline so the
  output event is correctly gated for HA/Matter consumption.

Test config:
- cargo test --no-default-features → 64 passed (emitter cfg-out)
- cargo test                       → 109 passed (102 + 7)

Out of scope (next iter target):
- Wiring rf_signature_hash computation from BLAKE3-keyed(site_salt,
  features) per ADR-120 §2.3 — the SensingInputs.rf_signature_hash
  is supplied by caller for now; needs a SignatureHasher with site_salt
  initialization in a follow-up iter.
- Embedding ring → identity_separability_score derivation (currently
  `sep` is caller-supplied; should be computed from ring contents).
- MQTT topic publisher wrapping BfldEmitter (ADR-122 §2.2) — depends
  on a runtime (tokio).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p3.5): SignatureHasher (BLAKE3-keyed) — 117/117 GREEN

Iter 15. Lands ADR-120 §2.3 — the cryptographic foundation of invariant
I3 ("cross-site identity correlation is impossible"). rf_signature_hash
is now derived from a per-site secret and a daily epoch, so two nodes
observing the same physical person produce uncorrelated 256-bit digests.

Added (no_std-compatible):
- blake3 = "1.5", default-features = false (no_std, no SIMD by default)
- src/signature_hasher.rs:
  * Constants SECONDS_PER_DAY (86_400), SITE_SALT_LEN (32), RF_SIGNATURE_LEN (32)
  * SignatureHasher { site_salt: [u8; 32] } with new(salt) const ctor
  * compute(day_epoch, &features) -> [u8; 32]  (BLAKE3 keyed mode)
  * compute_at(unix_secs, &features) -> [u8; 32] convenience
  * day_epoch_from_unix_secs(unix_secs) -> u32 helper (floor(t / 86400))
- pub use SignatureHasher, RF_SIGNATURE_LEN, SITE_SALT_LEN from lib.rs

tests/signature_hasher.rs (8 named tests, all green):
  deterministic_under_identical_inputs
  different_site_salts_produce_different_hashes
  different_day_epochs_rotate_the_hash
  different_features_produce_different_hashes
  output_length_is_32_bytes
  day_epoch_from_unix_secs_matches_floor_division
    (covers 0, 86_399, 86_400, and the 1.7e9 modern timestamp)
  compute_at_matches_compute_with_derived_day
  cross_site_hamming_distance_is_statistically_high
    *** ADR-120 §2.7 AC2 acceptance test ***
    Runs 100 trials with distinct (salt_a, salt_b) pairs observing
    identical features, computes per-trial Hamming distance, asserts
    mean >= 120 bits and min >= 80 bits. Empirically lands at ~128 bits
    mean (the expected value for two independent 256-bit hashes), with
    no trial below 80 bits — i.e., zero suspicious near-collisions.

ACs progressed:
- ADR-120 §2.7 AC2 — structurally enforced cross-site isolation, now
  proven empirically by the Hamming-distance test. This is the
  cryptographic half of invariant I3 in code, not just docs.
- ADR-118 invariant I3 — first runtime witness that two sites with
  independent site_salts cannot correlate the same person's signature.

Test config:
- cargo test --no-default-features → 72 passed (64 + 8; signature_hasher is no_std)
- cargo test                       → 117 passed (109 + 8)

Out of scope (next iter target):
- Wire SignatureHasher into BfldEmitter: replace caller-supplied
  rf_signature_hash with hasher.compute_at(ts, &features) so the
  pipeline produces correct hashes end-to-end.
- IdentityFeatures canonical-bytes encoder so callers don't need to
  hand-serialize per-feature representations.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p4.3): wire SignatureHasher into BfldEmitter (123/123 GREEN)

Iter 16. End-to-end ADR-120 §2.3 wiring: BfldEmitter now produces
rf_signature_hash derived from (site_salt, day_epoch, features), with
the IdentityEmbedding bytes as the preferred feature source. Closes
the gap from iter 15 — the hasher is now reachable from the pipeline.

Added (in src/emitter.rs):
- BfldEmitter.signature_hasher: Option<SignatureHasher> field
- BfldEmitter::with_signature_hasher(SignatureHasher) -> Self builder
- emit_with_oracle computes derived_hash BEFORE pushing embedding to ring:
    1. unix_secs = inputs.timestamp_ns / NS_PER_SEC
    2. feature bytes: embedding.as_slice() flattened to LE f32 bytes,
       OR fallback canonical_risk_bytes(&inputs) (4-tuple of LE f32)
    3. hasher.compute_at(unix_secs, &bytes)
- Derived hash overrides inputs.rf_signature_hash; when hasher absent
  caller-supplied value passes through unchanged (backward compat)
- canonical_risk_bytes(&inputs) -> [u8; 16] private helper for fallback

tests/emitter_hasher.rs (6 named tests, all green):
  no_hasher_passes_caller_supplied_hash_through
  installed_hasher_overrides_caller_supplied_hash
  same_emitter_same_inputs_produce_same_hash (determinism through emitter)
  different_site_salts_produce_different_hashes_end_to_end
    *** cross-site isolation proven via the BfldEmitter API, not just
        via the SignatureHasher direct API (iter 15) ***
  no_embedding_falls_back_to_risk_factor_bytes
  fallback_hash_differs_from_embedding_hash
    (embedding-based and fallback-based hashes are distinct paths)

ACs progressed:
- ADR-120 §2.7 AC2 — cross-site isolation now provable at the public
  emitter surface, not just inside the hasher module.
- ADR-118 §2.1 pipeline integration — derived rf_signature_hash flows
  through to the BfldEvent without caller participation. Operators
  install the hasher once at boot; per-frame code never sees site_salt.

Test config:
- cargo test --no-default-features → 72 passed (emitter_hasher cfg-out)
- cargo test                       → 123 passed (117 + 6)

Out of scope (next iter target):
- IdentityFeatures struct — typed canonical-bytes encoder so callers
  don't need to know that embedding bytes feed the hasher directly.
- Cross-iter integration test: BfldEmitter → BfldEvent::to_json with
  derived hash, parsed back, hash field present and base64-encoded
  (or hex-encoded) per the JSON wire spec.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p4.4): rf_signature_hash JSON as "blake3:<hex>" (128/128 GREEN)

Iter 17. Lands the BFLD JSON wire spec format for rf_signature_hash —
a "blake3:" prefix followed by 64 lowercase hex chars. Replaces the
default serde array-of-integers encoding which was unusable for
downstream consumers (HA, Matter, MQTT).

Added (in src/event.rs):
- ser_rf_signature_hash<S>(hash: &Option<[u8;32]>, s) custom serializer
- Field attribute on BfldEvent.rf_signature_hash now uses
  serialize_with = "ser_rf_signature_hash" alongside skip_serializing_if
- nibble_to_hex(u8) -> char private const fn (no `hex` crate dep needed
  for 32 bytes; lowercase hex is trivial)
- Output format: "blake3:deadbeef..." exactly 71 ASCII chars

tests/json_hash_format.rs (5 named tests, all green):
  rf_signature_hash_serializes_as_blake3_prefixed_lowercase_hex
    (expected hex built programmatically via format!("{b:02x}"))
  hex_string_is_always_64_chars_when_present
    (parses the JSON, isolates the hash substring, asserts exact 64
     chars and lowercase-only — catches case-folding regressions)
  hash_field_omitted_entirely_when_none
  end_to_end_emitter_hasher_to_json_emits_blake3_hex_hash
    *** Cross-iter integration test: BfldEmitter::with_signature_hasher
        → SensingInputs.rf_signature_hash = None → emit derives via
        BLAKE3 → BfldEvent::to_json → contains "blake3:" prefix.
        Spans iters 13, 14, 15, 16, 17 in a single assertion. ***
  end_to_end_restricted_class_omits_hash_even_with_hasher_set
    (class 3: even with hasher installed, JSON omits the hash)

ACs progressed:
- BFLD wire spec §6 — rf_signature_hash JSON shape now matches the
  documented format ("blake3:..."); HA / Matter consumers can parse
  it without custom byte-array decoding.
- ADR-118 §1 invariant I3 — visibility: the JSON wire form now
  cryptographically tags the hash with its algorithm prefix, so
  consumers can verify they're not parsing a different (weaker)
  hash that a future PR might accidentally substitute.

Test config:
- cargo test --no-default-features → 72 passed (json_hash_format cfg-out)
- cargo test                       → 128 passed (123 + 5)

Out of scope (next iter target):
- IdentityFeatures typed encoder so callers feeding BfldEmitter don't
  need to know that embedding bytes serve as hasher input.
- Replace the manual hex push with `hex::encode` if/when the workspace
  takes on the `hex` crate dep for other reasons; current path saves
  the dep without sacrificing correctness.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p3.6): IdentityFeatures canonical-bytes encoder (137/137 GREEN)

Iter 18. Consolidates the embedding-vs-risk-factor hashing-input
selection behind a single typed API. Replaces the two ad-hoc paths
that lived in emitter.rs through iter 17:
  * inline `emb.as_slice().iter().flat_map(|f| f.to_le_bytes())`
  * private `canonical_risk_bytes(&inputs) -> [u8; 16]`

Added (gated on `feature = "std"`):
- src/identity_features.rs:
  * IdentityFeatures<'a> enum: Embedding(&'a IdentityEmbedding) |
    RiskFactors { sep, stab, consist, conf }
  * from_embedding / from_risk_factors const constructors
  * canonical_byte_len() const fn — no allocation, predicts wire length
  * write_canonical_bytes(&mut Vec<u8>) — reusable-buffer path
  * canonical_bytes() -> Vec<u8> — allocating convenience
  * compute_hash(&SignatureHasher, day_epoch) -> [u8; 32]
  * RISK_FACTOR_BYTES const (= 16)
- pub use IdentityFeatures, RISK_FACTOR_BYTES from lib.rs

Refactor:
- src/emitter.rs: derived_hash now uses
    let features = match &embedding {
        Some(emb) => IdentityFeatures::from_embedding(emb),
        None => IdentityFeatures::from_risk_factors(sep, stab, consist, conf),
    };
    features.compute_hash(h, day_epoch)
  Local canonical_risk_bytes helper removed (superseded).

tests/identity_features_encoder.rs (9 named tests, all green):
  embedding_canonical_length_is_dim_times_four
  risk_factor_canonical_length_is_sixteen_bytes
  embedding_canonical_bytes_match_manual_flatten
  risk_factor_canonical_bytes_match_explicit_le_layout
  write_canonical_bytes_appends_to_existing_buffer
  compute_hash_matches_direct_hasher_invocation
  embedding_and_risk_factors_produce_different_hashes
  iter_16_wire_compat_embedding_path   *** backward-compat regression ***
  iter_16_wire_compat_risk_factor_path *** backward-compat regression ***
    These two tests assert that the refactored encoder produces
    bit-identical hashes to iter 16's inline path. Existing deployed
    nodes upgrading to iter 18 see no rf_signature_hash flip.

ACs progressed:
- ADR-120 §2.3 — features canonical-bytes representation now has a
  single source of truth in the codebase; future feature additions
  pass through one named encoder rather than scattered byte-fiddling.
- ADR-118 invariant I2 — IdentityFeatures borrows &IdentityEmbedding,
  it doesn't take ownership. The embedding's Drop / no-Serialize
  guarantees continue to hold across the canonical-bytes path.

Test config:
- cargo test --no-default-features → 72 passed (identity_features cfg-out)
- cargo test                       → 137 passed (128 + 9)

Out of scope (next iter target):
- Wire IdentityFeatures into a public emitter input path so callers
  can supply pre-constructed IdentityFeatures rather than the bare
  embedding + risk factors. (Soft refactor; current API is sufficient.)
- BfldPipeline facade — single struct combining BfldEmitter +
  BfldFrame producer + MQTT publisher (ADR-118 §2.1 lib.rs entry point).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p4.5): BfldPipeline facade + BfldConfig (146/146 GREEN)

Iter 19. Public lib.rs entry point per ADR-118 §2.1. Thin facade over
BfldEmitter that adds a config-driven builder and a privacy_mode
toggle for emergency demote-to-Restricted without rebuilding the
gate/ring/hasher state.

Added (gated on `feature = "std"`):
- src/pipeline.rs:
  * BfldConfig { node_id, default_zone_id, privacy_class, signature_hasher }
    with new/with_zone/with_privacy_class/with_signature_hasher builder
  * BfldPipeline { baseline_class, privacy_mode, emitter }
  * BfldPipeline::new(config) — initializes the underlying emitter
  * process(inputs, embedding) -> Option<BfldEvent>
    Delegates to emitter.emit() then post-processes: if privacy_mode is
    engaged, demotes the resulting event to Restricted and calls
    apply_privacy_gating to strip identity fields
  * enable_privacy_mode() / disable_privacy_mode() / is_privacy_mode_enabled()
  * current_privacy_class() — returns Restricted when privacy_mode else baseline
  * current_gate_action() — delegate diagnostic
- pub use BfldConfig, BfldPipeline from lib.rs

Design note: the privacy_mode override is applied post-emission, NOT by
rebuilding the emitter. This preserves gate state (current action,
pending transitions), ring contents, and hasher salt across the toggle —
critical for incident response where the operator needs to keep
detecting anomalies while temporarily redacting the public surface.

tests/pipeline_facade.rs (9 named tests, all green):
  config_defaults_to_anonymous_no_zone_no_hasher
  config_builder_methods_chain
  fresh_pipeline_is_not_in_privacy_mode
  pipeline_process_returns_anonymous_event_under_low_risk
  enable_privacy_mode_demotes_published_events_to_restricted
    (verifies BOTH identity_risk_score AND rf_signature_hash become None)
  disable_privacy_mode_restores_baseline_class
    (round-trip: enable → demoted → disable → restored to Anonymous)
  privacy_mode_overrides_derived_baseline_too
    (research-mode operator can still flip the emergency switch)
  pipeline_with_hasher_emits_derived_rf_signature_hash
  zone_is_threaded_from_config_to_event

ACs progressed:
- ADR-118 §2.1 — public entry point now matches the implementation
  plan §1.2 sketch: BfldPipeline::new(config) → process() → BfldEvent.
  Future iters add process_to_frame() and the tokio MQTT loop.
- ADR-118 §1.5 enable_privacy_mode requirement — operator can engage
  Restricted-class redaction without restarting the pipeline or
  losing in-flight detection state. First runtime witness of this.

Test config:
- cargo test --no-default-features → 72 passed (pipeline cfg-out)
- cargo test                       → 146 passed (137 + 9)

Out of scope (next iter target):
- process_to_frame(inputs, payload, embedding) -> Option<BfldFrame>
  for callers that need wire-format bytes rather than JSON events.
- BfldPipelineHandle wrapping the pipeline in Arc<Mutex<...>> + a
  tokio task that pumps an MQTT loop (ADR-122 §2.2 emitter half).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p4.6): BfldPipeline::process_to_frame wire-bytes path (152/152 GREEN)

Iter 20. Adds the wire-bytes companion to BfldPipeline::process so
callers needing BfldFrame (for ESP-NOW, UDP, file dump, witness
bundles, etc.) don't have to drop down to BfldEmitter + manual
BfldFrame construction.

Added (in src/pipeline.rs):
- BfldPipeline::process_to_frame(
      inputs: SensingInputs,
      header_template: BfldFrameHeader,
      payload: BfldPayload,
      embedding: Option<IdentityEmbedding>,
  ) -> Option<BfldFrame>

  Algorithm:
    1. Cache timestamp_ns from inputs (consumed by the inner process()).
    2. Call self.process(inputs, embedding) — gate logic decides drop/emit.
       Returns None if the gate rejects, propagating to caller.
    3. Clone header_template, override timestamp_ns and privacy_class from
       the current pipeline state (privacy_mode-aware).
    4. Build via BfldFrame::from_payload — CRC covers the section-prefixed
       payload bytes per ADR-119 §2.2.

  Separation of concerns: pipeline owns gate / ring / hasher state; caller
  owns AP / STA / session identity (provided via header_template).

tests/pipeline_to_frame.rs (6 named tests, all green):
  process_to_frame_emits_frame_under_low_risk
    (timestamp_ns + privacy_class correctly propagated from pipeline)
  process_to_frame_returns_none_under_sustained_high_risk
    (gate Reject path: two consecutive high-risk calls → None)
  process_to_frame_round_trips_through_bytes
    (frame.to_bytes() → BfldFrame::from_bytes() → parse_payload() identity)
  process_to_frame_overrides_class_in_privacy_mode
    (enable_privacy_mode → frame.header.privacy_class = Restricted byte)
  process_to_frame_preserves_header_template_identity_fields
    (ap_hash, sta_hash, session_id, channel from template survive)
  process_to_frame_uses_input_timestamp_not_template_timestamp
    (template.timestamp_ns = 12345 is overridden by inputs.timestamp_ns)

ACs progressed:
- ADR-118 §2.1 wire-bytes consumer path now reachable from BfldPipeline,
  not just from low-level BfldEmitter + manual frame construction.
- ADR-119 AC5/AC6 — round-trip-through-bytes test exercises the full
  pipeline+frame stack, not just the frame in isolation.
- ADR-122 §2.2 prep — the BfldFrame is the wire format MQTT eventually
  publishes via tokio loop (next iter pair); process_to_frame is the
  per-frame producer that loop will call.

Test config:
- cargo test --no-default-features → 72 passed (pipeline_to_frame cfg-out)
- cargo test                       → 152 passed (146 + 6)

Out of scope (next iter target):
- BfldPipelineHandle: Arc<Mutex<BfldPipeline>> + tokio task that pumps
  an inbound (SensingInputs, IdentityEmbedding) channel into MQTT
  per-class topics (ADR-122 §2.2). Brings in tokio + rumqttc deps
  behind a `mqtt` feature.
- Cargo benchmark: pipeline throughput target ≥ 40 frames/sec on a
  Pi 5 core (ADR-118 §6 P2 effort estimate).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p5.1): MQTT topic router (BfldEvent → Vec<TopicMessage>) — 162/162 GREEN

Iter 21. Lands ADR-122 §2.2 topic shape + class-gated routing as a pure
function. No broker dep yet — that lands in iter 22 with tokio + rumqttc
behind an `mqtt` feature. This iter is the routing policy, separated for
testability.

Added (gated on `feature = "std"`):
- src/mqtt_topics.rs:
  * TopicMessage { topic: String, payload: String }
  * TopicMessage::ruview_topic(node, entity) builds the canonical
    `ruview/<node>/bfld/<entity>/state` shape
  * render_events(&BfldEvent) -> Vec<TopicMessage>:
      class < Anonymous (0/1): returns empty (raw/derived are local only)
      class >= Anonymous (2/3): emits presence + motion + person_count +
        confidence, plus zone_activity if zone_id set
      class == Anonymous (2) ONLY: also emits identity_risk
      class == Restricted (3): identity_risk is suppressed even with score
- pub use render_events, TopicMessage from lib.rs

Payload encoding:
- presence:     "true" | "false"
- motion:       "{:.6}" — fixed-precision decimal in [0.0, 1.0]
- person_count: bare integer string
- confidence:   "{:.6}"
- zone_activity: JSON-string with quotes — "\"living_room\""
- identity_risk: "{:.6}"

tests/mqtt_topic_routing.rs (10 named tests, all green):
  topic_format_is_ruview_node_bfld_entity_state
  anonymous_class_publishes_six_topics_with_zone
    (6 = presence/motion/count/conf/zone/identity_risk)
  anonymous_class_without_zone_omits_zone_activity_topic (5 topics)
  restricted_class_omits_identity_risk_topic (class 3 → 5 topics, no risk)
  raw_and_derived_classes_publish_nothing
    *** structural enforcement of "raw stays local" at the topic layer ***
  presence_payload_is_lowercase_json_bool
  motion_payload_is_fixed_precision_decimal
  person_count_payload_is_bare_integer
  zone_payload_is_json_string_with_quotes
  identity_risk_payload_is_fixed_precision_decimal

ACs progressed:
- ADR-122 §2.2 topic shape now matches the documented format byte-for-byte.
- ADR-122 AC4 — per-class topic gating: classes 2 / 3 publish disjoint
  sets, with identity_risk uniquely guarded.
- ADR-118 invariant I1 reaching the public surface — Raw frames produce
  zero topic messages, so even a buggy publisher loop cannot leak them.

Test config:
- cargo test --no-default-features → 72 passed (mqtt_topics cfg-out)
- cargo test                       → 162 passed (152 + 10)

Out of scope (next iter target):
- tokio + rumqttc behind a new `mqtt` feature gate
- BfldPipelineHandle: Arc<Mutex<BfldPipeline>> + a tokio task that pumps
  inbound SensingInputs, runs render_events on each emitted BfldEvent,
  and calls client.publish() for each TopicMessage
- mosquitto integration test pattern (cf. feedback_mqtt_integration_test_patterns
  memory: per-test client_id, pump until SubAck, wait for publisher discovery)

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p5.2): Publish trait + publish_event free function — 169/169 GREEN

Iter 22. Abstracts the MQTT publish boundary without pulling in tokio or
rumqttc yet. The trait is sync (callers can hold &mut self without an
async runtime); the production rumqttc-backed impl in iter 23 will drive
a tokio task internally and present the same sync surface here.

Added (in src/mqtt_topics.rs, gated on `feature = "std"`):
- Publish trait with associated Error type
- CapturePublisher (Vec-backed; default-constructible) for unit tests
- publish_event<P: Publish>(publisher, event) -> Result<usize, P::Error>
    Iterates render_events(event) and forwards each TopicMessage to
    publisher.publish(). Returns the count actually published, or the
    publisher's error short-circuited on first failure.
- pub use Publish, CapturePublisher, publish_event from lib.rs

tests/mqtt_publish_loop.rs (7 named tests, all green):
  capture_publisher_records_every_message
  publish_returns_zero_for_raw_and_derived_events
    (parameterized — class 0 and class 1 both produce zero publishes,
     reinforcing the invariant I1 surface enforcement from iter 21)
  published_topics_match_render_events_ordering
    (stable per-event topic sequence for MQTT consumers)
  restricted_class_publishes_no_identity_risk_topic
  anonymous_without_zone_publishes_five_messages (5 = no zone_activity)
  publisher_error_short_circuits_publish_event
    (FailingPublisher fails on 3rd publish; publish_event surfaces the
     error AND leaves the first two messages durably published)
  capture_publisher_error_type_is_infallible
    (compile-time witness that CapturePublisher cannot panic the loop)

ACs progressed:
- ADR-122 §2.2 publisher boundary — the broker-facing surface is now a
  named trait operators can mock, swap, or wrap with retries.
- ADR-122 AC4 — publish_event respects the iter-21 class gating; Raw /
  Derived events produce zero broker traffic by definition.
- ADR-118 invariant I1 — even if the broker connection somehow regressed,
  the trait-level publish_event cannot exfiltrate a Raw frame because
  render_events returns empty first.

Test config:
- cargo test --no-default-features → 72 passed (mqtt_publish_loop cfg-out)
- cargo test                       → 169 passed (162 + 7)

Out of scope (next iter target):
- New `mqtt` feature gate; tokio + rumqttc deps under it
- RumqttPublisher: impl Publish that holds an MqttClient + a small tokio
  block_on or oneshot send to bridge sync trait to async client
- Optional: BfldPipelineHandle that owns Arc<Mutex<BfldPipeline>> + a
  spawn-and-forget tokio task pumping inbound (inputs, embedding) →
  process → publish_event(&rumqtt_pub, &event)
- mosquitto integration test following the patterns from
  feedback_mqtt_integration_test_patterns memory note

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p5.3): RumqttPublisher behind mqtt feature gate (176/176 GREEN with mqtt)

Iter 23. Production Publish trait impl using rumqttc 0.24 (same crate
version + use-rustls feature pinning as wifi-densepose-sensing-server,
so both publishers can share broker connection posture).

Added:
- rumqttc = "0.24" optional dep (default-features = false, use-rustls)
- New `mqtt` cargo feature: ["std", "dep:rumqttc"]
- src/rumqttc_publisher.rs (gated on `feature = "mqtt"`):
  * RumqttPublisher wrapping rumqttc::Client + QoS + retain flag
  * RumqttPublisher::new(client, qos) const constructor
  * with_retain(bool) builder for availability-style topics
  * RumqttPublisher::connect(opts, capacity) -> (Self, Connection)
    Returns the unpumped Connection — caller spawns a thread that
    iterates connection.iter() to drive the MQTT protocol. Default
    QoS is AtLeastOnce (HA-DISCO recommendation for state topics).
  * impl Publish with Error = rumqttc::ClientError
- pub use RumqttPublisher from lib.rs

tests/rumqttc_publisher_smoke.rs (7 named tests, all green, gated on mqtt):
  rumqttc_publisher_constructs_without_broker
    (uses 127.0.0.1:1 — reserved port refuses immediately; no hang)
  with_retain_builder_yields_a_publisher
  publish_queues_message_without_blocking_on_broker_state
    *** Critical property: rumqttc's sync Client::publish queues into
        an unbounded channel; publish_event returns Ok without round-
        tripping to the (offline) broker. The queued packet only sends
        if a thread iterates Connection::iter(). ***
  restricted_event_publishes_four_messages_through_rumqttc
    (class 3 + no zone: presence/motion/count/confidence — 4 topics)
  publisher_trait_object_is_constructible
    (Box<dyn Publish<Error = rumqttc::ClientError>> works)
  direct_publish_call_through_trait_object
  default_qos_is_at_least_once_via_connect

ACs progressed:
- ADR-122 §2.2 broker integration — production publisher now wired,
  matching the sensing-server's TLS / version posture. The two
  crates can share a single broker connection if an operator wants
  both publishers in the same process.
- ADR-122 AC4 still enforced — publish_event's class-gated routing
  is upstream of rumqttc, so no broker-level config can leak Raw frames.

Test config:
- cargo test --no-default-features → 72 passed (mqtt feature off)
- cargo test                       → 169 passed (mqtt feature off)
- cargo test --features mqtt --test rumqttc_publisher_smoke → 7 passed
- With --features mqtt: 169 + 7 = 176 total

Out of scope (next iter target):
- mosquitto integration test (env-gated MQTT_BROKER=tcp://localhost:1883):
    * spawn a thread iterating Connection::iter()
    * publish a BfldEvent
    * subscribe in the test, await SubAck per the workspace memory note
      `feedback_mqtt_integration_test_patterns`
    * assert the topics received match render_events output
- BfldPipelineHandle: Arc<Mutex<BfldPipeline>> with a thread that pumps
  inbound (inputs, embedding) → process → publish_event(&rumqttc_pub, &event)
  for a single-call "set up MQTT publisher and walk away" API.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p5.4): mosquitto integration test (env-gated, 178/178 with mqtt)

Iter 24. Live-broker roundtrip test for the RumqttPublisher → mosquitto
→ subscriber path. CI-safe: silently skips when BFLD_MQTT_BROKER is
unset; opt-in locally with:

    scoop install mosquitto
    mosquitto -v -c mosquitto-allow-anon.conf &
    BFLD_MQTT_BROKER=tcp://localhost:1883 cargo test \
        -p wifi-densepose-bfld --features mqtt --test mosquitto_integration

Added (gated on `feature = "mqtt"`):
- tests/mosquitto_integration.rs:
  * broker_env() parses BFLD_MQTT_BROKER as tcp://host:port (default 1883)
  * unique_client_id(prefix) — nanosecond-suffix per-test, per the
    `feedback_mqtt_integration_test_patterns` memory note
  * spawn_subscriber() creates a Client + thread iterating Connection;
    drains incoming Publish into an mpsc channel and emits a oneshot on
    SubAck arrival
  * collect_messages(rx, expected_count, timeout) — bounded recv loop
    that respects a wall-clock deadline (no `loop { iter.recv() }`)
  * Two named tests:

      live_broker_anonymous_event_roundtrips_all_six_topics
        Subscribe to ruview/<node>/bfld/+/state with the wildcard, await
        SubAck, publish an Anonymous event with zone, collect 6 messages,
        assert every expected entity name appears exactly once.

      live_broker_restricted_event_omits_identity_risk
        Same setup, publish a Restricted event, collect up to 6 (will
        only see 5), assert identity_risk is absent.

Test discipline (per the workspace memory):
  - per-test unique client_id (prevents broker session collisions)
  - subscriber eventloop pumped until SubAck BEFORE publishing
  - explicit timeout instead of infinite recv (no test hangs on misconfig)
  - publisher Connection drained in its own thread (rumqttc requirement)
  - 200ms sleep between publisher construction and first publish to let
    CONNECT complete (otherwise messages are queued before the session
    is open, and mosquitto silently drops them in some configurations)

When BFLD_MQTT_BROKER is unset:
  - broker_env() returns None
  - Test prints a one-line skip message to stderr and returns Ok(())
  - Both tests show as passing in cargo output

ACs progressed:
- ADR-122 AC1 end-to-end demonstrable — when a broker is available,
  the test proves a BfldEvent traverses RumqttPublisher, the network,
  and an MQTT subscriber, arriving with the correct topic shape and
  payload encoding.
- ADR-122 AC4 enforced over the wire — the Restricted-class test
  proves identity_risk does not even reach the broker, not just that
  it's stripped at render_events.

Test config:
- cargo test --no-default-features → 72 passed
- cargo test                       → 169 passed
- cargo test --features mqtt       → 178 passed (176 + 2 skip-mode tests)

Out of scope (next iter target):
- BfldPipelineHandle: Arc<Mutex<BfldPipeline>> + a worker thread that
  pumps inbound (SensingInputs, IdentityEmbedding) channel into MQTT.
  Single-call "set up publisher and walk away" API for operators.
- CI workflow that starts mosquitto in a Docker service container and
  sets BFLD_MQTT_BROKER so the integration test actually runs.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p5.5): BfldPipelineHandle worker thread (177/177 GREEN)

Iter 25. Single-call operator surface: spawn() takes a BfldPipeline and
a Publish impl, returns a handle whose send() enqueues sensing inputs
into a worker thread. The worker drives pipeline.process() then
publish_event() per input. Drop or shutdown() joins cleanly.

Added (gated on `feature = "std"`):
- src/mqtt_topics.rs: impl<P: Publish> Publish for Arc<Mutex<P>>
  Lets a publisher owned by a worker thread remain inspectable from a
  test or operator post-shutdown.
- src/pipeline_handle.rs:
  * PipelineInput { inputs: SensingInputs, embedding: Option<...> }
  * BfldPipelineHandle { sender, worker: Option<JoinHandle<()>> }
  * spawn<P: Publish + Send + 'static>(pipeline, publisher) -> Self
      Worker loop: recv() → pipeline.process() → publish_event(); errors
      logged to stderr (single-frame failures must not kill the loop)
  * send(PipelineInput) -> Result<(), SendError<...>>
  * shutdown(self) — replaces sender with a dropped channel so worker
    recv() returns Err(RecvError); join propagates worker panics
  * Drop impl mirrors shutdown so forgotten handles still clean up
- pub use BfldPipelineHandle, PipelineInput from lib.rs

tests/pipeline_handle_worker.rs (8 named tests, all green):
  handle_publishes_single_input (5 topics for Anonymous + no zone)
  handle_publishes_multiple_inputs_in_order (3 × 5 = 15 topics)
  handle_send_after_shutdown_errors
    (compile-time witness: shutdown(self) consumes the handle so
     post-shutdown send() is structurally impossible)
  handle_drop_without_explicit_shutdown_joins_worker_cleanly
    (validates the Drop path completes without hanging)
  handle_honors_privacy_mode_toggle_via_pipeline_state
    (4 topics for Restricted; identity_risk absent)
  handle_drops_event_when_gate_rejects
    (5 topics from first Accept-state input + 0 from Reject)
  handle_with_zone_threads_through_to_published_topics
    (zone_activity payload = "\"kitchen\"")
  class_3_pipeline_baseline_produces_four_topics_per_input

Test publisher pattern: Arc<Mutex<CapturePublisher>> lets the test thread
read out the worker thread's publish log post-shutdown without needing
custom channel plumbing per test.

ACs progressed:
- ADR-118 §2.1 lib.rs entry point now has the "set up MQTT and walk away"
  operator surface promised in the implementation plan. Two lines:
      let handle = BfldPipelineHandle::spawn(pipeline, rumqttc_pub);
      handle.send(PipelineInput { inputs, embedding })?;
- ADR-122 §2.2 per-frame publish path is now structurally guarded by
  worker-thread isolation: even if a Publish::publish call panics, only
  the worker thread dies; the main thread sees a clean error on send().

Test config:
- cargo test --no-default-features → 72 passed
- cargo test                       → 177 passed (169 + 8)
- cargo test --features mqtt       → 186 (178 + 8 — handle is std-only,
  reachable in both feature configs)

Out of scope (next iter target):
- GitHub Actions workflow with mosquitto Docker service so the iter-24
  integration test actually runs in CI with BFLD_MQTT_BROKER set.
- HA discovery payload publisher (ADR-122 §2.1) — the auto-discovery
  config messages HA needs alongside the state topics this handle ships.

Co-Authored-By: claude-flow <ruv@ruv.net>

* docs+plugins: rvAgent + RVF agentic-flow integration exploration

Land the rvAgent (vendor/ruvector/crates/rvAgent/) integration research
dossier and update both the Claude Code and Codex plugins so future
operators have a discoverable entry point for prototyping agentic flows
on top of RuView's existing sensing pipeline + RVF cognitive containers.

Added:
- docs/research/rvagent-rvf-integration/README.md
  Full integration thesis: rvAgent's 8 crates + 14 middlewares share
  RVF as their state-persistence format with RuView's existing
  v2/crates/wifi-densepose-sensing-server/src/rvf_container.rs. Three
  shippable touchpoints (each independent):
    1. Two new RVF segment types (SEG_AGENT_STATE = 0x08,
       SEG_DECISION = 0x09) so rvAgent sessions and RuView sensing
       sessions interleave in one witness-bundle-attestable blob
    2. BfldEvent → ToolOutput shim — agent reads BFLD events as
       tool context with no new IPC
    3. cog-* subagent registration under a queen-agent router
  Open questions: workspace inclusion path, sync/async adapter
  placement, privacy-class composition with rvagent-middleware
  sanitizer, Soul Signature ↔ SoulMatchOracle bridge, MCP surface.
  Proposed next: ADR-124 before scaffolding wifi-densepose-agent.

- plugins/ruview/skills/ruview-rvagent/SKILL.md
  New Claude Code skill exposing the integration surface, links to
  the research doc, and lists the three shippable touchpoints. Skill
  description tuned so Claude auto-discovers it for queries like
  "wire rvAgent into RuView" or "operator agent reacting to BFLD."

- plugins/ruview/codex/prompts/ruview-rvagent.md
  Codex counterpart prompt with trigger phrasing, reading order,
  same three touchpoints + open questions, and the ADR-124 next step.

Modified:
- plugins/ruview/.claude-plugin/plugin.json
  Version 0.1.0 → 0.2.0; description extended to mention "BFLD
  privacy layer" and "rvAgent + RVF agentic flows".

- plugins/ruview/codex/AGENTS.md
  Prompt table grows one row: `ruview-rvagent` for the new prompt.

No code changes; no test impact.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p5.6): HA auto-discovery payload publisher (187/187 GREEN)

Iter 26. Lands ADR-122 §2.1 HA-DISCO config-message generator.
Counterpart to iter 21's state-topic router: this produces the
homeassistant/<type>/<unique_id>/config messages HA reads on
startup to auto-create the six BFLD entities as a single device.

Discovery payloads are intended to be published once per node
session with retain = true (so HA finds them on subsequent starts).
The RumqttPublisher from iter 23 already exposes with_retain(true)
for this purpose; the state-topic loop must keep retain = false to
avoid stale-state flapping.

Added (gated on `feature = "std"`):
- src/ha_discovery.rs:
  * render_discovery_payloads(node_id, class) -> Vec<TopicMessage>
      class < Anonymous: empty vec (HA doesn't see raw/derived)
      class == Anonymous: 6 entities incl. identity_risk
      class == Restricted: 5 entities, no identity_risk
  * Per-entity HA metadata:
      presence       binary_sensor, device_class: occupancy
      motion         sensor, entity_category: diagnostic
      person_count   sensor, unit_of_measurement: people
      zone_activity  sensor, entity_category: diagnostic
      confidence     sensor, entity_category: diagnostic
      identity_risk  sensor, entity_category: diagnostic
  * Each payload carries:
      name, unique_id, state_topic (pointing at the iter-21 path),
      device block with identifiers / model: "BFLD" / manufacturer: "RuView"
  * Manual JSON builder with minimal escape coverage — node_id is
    ASCII alphanumeric + dash by convention; full escape via
    serde_json is a follow-up if operator-controlled names ever land.
- pub use render_discovery_payloads from lib.rs

tests/ha_discovery.rs (10 named tests, all green):
  raw_and_derived_classes_produce_no_discovery_payloads
  anonymous_class_produces_six_discovery_payloads
  restricted_class_omits_identity_risk_discovery
  discovery_topic_format_matches_ha_convention
    (validates all six homeassistant/.../config topics exist)
  presence_payload_carries_occupancy_device_class
  motion_payload_marked_as_diagnostic
  person_count_payload_carries_unit_of_measurement
  every_payload_contains_unique_id_and_state_topic_pointing_at_correct_state_topic
    (the state_topic in the discovery payload must match the topic the
     state-topic router from iter 21 actually publishes on — closes
     the discovery↔state loop)
  unique_id_matches_topic_segment
    (the unique_id baked into the payload equals the topic segment so
     HA dedupe works correctly across reboot/restart)
  class_2_discovery_includes_identity_risk_explicitly

ACs progressed:
- ADR-122 §2.1 — HA auto-discovery surface now complete: an operator
  can start mosquitto, publish-retained discovery once, and HA spins
  up the entire BFLD device on next start with zero YAML config.
- ADR-122 AC1 (six entities per node) — discovery + state-topic
  publishers are now symmetric: render_discovery_payloads emits the
  same six entity definitions render_events emits state messages for.
- ADR-118 §1.5 — privacy_mode = Restricted strips identity_risk at
  BOTH the discovery layer (entity not advertised to HA) AND the
  state layer (no state messages). Two-layer defense.

Test config:
- cargo test --no-default-features → 72 passed (ha_discovery cfg-out)
- cargo test                       → 187 passed (177 + 10)

Out of scope (next iter target):
- HA discovery + state publish coordinator: a small function or
  BfldPipelineHandle::publish_discovery(&mut self, retained: bool)
  that calls render_discovery_payloads + publish_event(retained=true)
  once at startup, then enters the per-frame loop.
- GitHub Actions workflow with mosquitto Docker service so the
  iter-24 integration test runs in CI with BFLD_MQTT_BROKER set.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p5.7): publish_discovery bootstrap helper (193/193 GREEN)

Iter 27. The free function that closes the discovery ↔ state loop on
the publishing side. Mirrors publish_event from iter 22 but for the
HA-DISCO config payloads from iter 26.

Added (in src/ha_discovery.rs, gated on `feature = "std"`):
- publish_discovery<P: Publish>(publisher, node_id, class) -> Result<usize, P::Error>
    Renders the per-class discovery payloads (iter 26) and forwards
    each through publisher.publish(). Returns the count or short-
    circuits on first error.
  Docstring documents the canonical bootstrap pattern: separate
  retain-true publisher for discovery, retain-false publisher for state,
  both sharing the same broker connection if desired.
- pub use publish_discovery from lib.rs

tests/ha_discovery_publish.rs (6 named tests, all green):
  publish_discovery_returns_six_for_anonymous_class
  publish_discovery_returns_five_for_restricted_class
    (no identity_risk in captured topics)
  publish_discovery_returns_zero_for_raw_and_derived
    (HA-DISCO + class gating composition: raw / derived never
     advertised to HA)
  publish_discovery_topics_are_homeassistant_config_format
  publish_discovery_short_circuits_on_publisher_error
    (FailingPub fails on 4th publish; first 3 messages land, then error)
  bootstrap_pattern_publishes_discovery_then_state_through_shared_publisher
    *** End-to-end bootstrap proof: one Arc<Mutex<CapturePublisher>>
        used for both discovery (publish_discovery) and state
        (BfldPipelineHandle::spawn + send). Asserts:
          - 6 + 5 = 11 messages captured in order
          - First 6 topics are homeassistant/.../config
          - Next 5 topics are ruview/<node>/bfld/.../state
        Validates the iter-25 Arc<Mutex<P>> Publish adapter + iter-26
        discovery + iter-27 bootstrap helper compose correctly. ***

ACs progressed:
- ADR-122 §2.1 — bootstrap surface complete. Operator writes one
  publish_discovery call at startup, then BfldPipelineHandle::send for
  every frame. HA finds the device on first restart after discovery
  was retained on the broker.
- ADR-122 AC1 (six entities per node) — discovery and state phases
  share the same six-entity definition; the bootstrap test proves they
  reach the broker in the documented order.

Test config:
- cargo test --no-default-features → 72 passed (publish_discovery cfg-out)
- cargo test                       → 193 passed (187 + 6)

Out of scope (next iter target):
- GitHub Actions workflow with mosquitto Docker service. Without this
  the iter-24 live integration test stays in skip mode in CI; with it,
  every PR would prove the full publish_discovery + handle stack works
  end-to-end against a real broker.
- HA blueprint shipping (ADR-122 §2.6): three operator-ready YAML
  blueprints (presence-driven lighting / motion-aware HVAC / identity-
  risk anomaly notification) packaged in cog-ha-matter/blueprints/.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p5.8): availability topic + LWT integration (203/203 GREEN)

Iter 28. Closes the per-node lifecycle on the MQTT side: HA can now
distinguish a node that is healthy + publishing zero events (nothing
detected) from a node that has lost the broker connection. Discovery
payloads now reference the availability topic so every entity inherits
the device-level offline marker.

Added (gated on `feature = "std"`):
- src/availability.rs:
  * PAYLOAD_AVAILABLE = "online", PAYLOAD_NOT_AVAILABLE = "offline"
  * availability_topic(node_id) -> "ruview/<node>/bfld/availability"
  * online_message / offline_message constructors returning TopicMessage
  * publish_availability_online / publish_availability_offline
    bootstrap helpers through Publish trait
- pub use the full availability surface from lib.rs

Discovery integration (src/ha_discovery.rs):
- Every entity config payload now carries:
    "availability_topic": "ruview/<node>/bfld/availability"
    "payload_available":  "online"
    "payload_not_available": "offline"
  HA uses these to grey out entities device-wide when the broker LWT
  fires or the node explicitly publishes "offline" during shutdown.

tests/availability_topic.rs (10 named tests, all green):
  availability_topic_format_matches_documented_path
  online_message_is_retained_friendly_payload
  offline_message_is_retained_friendly_payload
  publish_online_lands_one_message
  publish_offline_lands_one_message
  discovery_payload_includes_availability_topic_field
    (all 6 Anonymous-class discovery payloads carry the field)
  discovery_payload_includes_payload_available_and_not_available_strings
  restricted_class_discovery_still_carries_availability_fields
    (availability is not an identity field; class 3 retains it)
  bootstrap_sequence_online_then_discovery_lands_in_order
    *** End-to-end bootstrap proof: publish_availability_online +
        publish_discovery produces 1 + 6 = 7 messages, "online"
        first, six homeassistant/.../config payloads after. ***
  graceful_shutdown_sequence_publishes_offline_message_last

ACs progressed:
- ADR-122 §2.2 — availability topic now in place. Operators get HA
  online/offline indication without configuring LWT explicitly on
  rumqttc — the offline_message constructor + publish_availability_offline
  cover the explicit-shutdown path. Real LWT wiring (rumqttc's
  MqttOptions::set_last_will) is a follow-up.
- ADR-122 AC1 + AC4 — discovery now includes availability_topic, which
  HA needs to render the device as a unit; iter-26 tests continue to
  pass with the augmented payload (verified by full-suite count: 187 + 10).

Test config:
- cargo test --no-default-features → 72 passed (availability cfg-out)
- cargo test                       → 203 passed (193 + 10)

Out of scope (next iter target):
- Wire rumqttc::MqttOptions::set_last_will(...) so the broker
  auto-publishes "offline" when the TCP session drops; needs a small
  helper on RumqttPublisher to build options with LWT pre-configured.
- GitHub Actions workflow with mosquitto Docker so iter-24 live test
  runs in CI.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p5.9): RumqttPublisher::connect_with_lwt — broker auto-publishes "offline" (220/220 GREEN with mqtt)

Iter 29. Wires rumqttc::MqttOptions::set_last_will so the broker
auto-publishes "offline" on ruview/<node>/bfld/availability (retained,
QoS 1) when the publisher's TCP session drops without a clean
DISCONNECT. Closes the iter-28 lifecycle loop: explicit "online" on
connect + LWT-driven "offline" on session loss + explicit "offline"
on graceful shutdown.

Added (in src/rumqttc_publisher.rs, gated on `feature = "mqtt"`):
- RumqttPublisher::connect_with_lwt(node_id, opts, capacity) -> (Self, Connection)
  Convenience wrapping with_lwt(opts, node_id) then Self::connect(opts, capacity).
- with_lwt(opts, node_id) -> MqttOptions free helper for operators who
  build their own opts (custom TLS, credentials) and want to opt in to
  the LWT without using the connect_with_lwt shortcut.
- rumqttc 0.24 LastWill::new(topic, message, qos, retain) — 4-arg form;
  retain = true so HA sees "offline" on next start even if it was down
  when the session dropped.
- pub use with_lwt, RumqttPublisher from lib.rs

tests/rumqttc_lwt.rs (8 named tests, all green, gated on mqtt):
  with_lwt_returns_options_without_panic
  connect_with_lwt_constructs_publisher_and_connection
  connect_with_lwt_uses_documented_availability_topic
    (constructive proof — both LWT and discovery use the same
     availability_topic() function so they can't drift)
  connect_with_lwt_publisher_still_publishes_state_topics
    (LWT is purely additive — state topics work as before)
  publisher_trait_object_constructible_with_lwt_path
  with_lwt_is_idempotent_against_double_call
    (rumqttc replaces the will silently — useful for wrapper libraries)
  caller_built_options_can_opt_in_via_with_lwt_then_pass_to_connect
    (operator pattern: build opts with TLS/creds, attach LWT, then connect)
  placeholder_topicmessage_path_unaffected_by_lwt

Test bug caught:
- Initial test asserted 4 topics for Anonymous + no zone; actual is 5
  (presence + motion + person_count + confidence + identity_risk).
  rf_signature_hash is a BfldEvent JSON field, not its own MQTT topic.
  Fixed the assertion; documented the distinction in the test comment.

ACs progressed:
- ADR-122 §2.2 availability surface now fully operational. Three paths:
    1. Explicit publish_availability_online (iter 28) on connect
    2. LWT auto-publishes "offline" if connection drops (this iter)
    3. Explicit publish_availability_offline (iter 28) on graceful stop
  HA reads the same topic in all three cases; entities grey out
  device-wide via the iter-28 discovery `availability_topic` field.

Test config:
- cargo test --no-default-features → 72 passed
- cargo test                       → 203 passed
- cargo test --features mqtt       → 220 passed (212 + 8 new)

Out of scope (next iter target):
- GitHub Actions workflow with mosquitto Docker service. With iter
  24+29 now both depending on a live broker for full coverage, the
  CI lift is the next highest-value step.
- Three operator-ready HA blueprints (ADR-122 §2.6): presence-driven
  lighting, motion-aware HVAC, identity-risk anomaly notification.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p5.10): three HA operator blueprints (210/210 GREEN)

Iter 30. Ships the three ADR-122 §2.6 operator-ready Home Assistant
automation blueprints. Each blueprint binds to one BFLD MQTT entity
(presence / motion / identity_risk) and lets an HA operator import
+ configure without writing YAML by hand.

Added (under v2/crates/cog-ha-matter/blueprints/bfld/):
- presence-lighting.yaml
    binary_sensor.<node>_bfld_presence ⇒ light.turn_on / turn_off
    with a configurable hold_seconds delay before the off action
    (ADR-122 §2.6 requirement: "configurable hold time")
- motion-hvac.yaml
    sensor.<node>_bfld_motion ⇒ climate.set_temperature
    Operator picks motion_threshold (default 0.3, per ADR §2.6),
    delta_temperature_c (°C adjustment), and quiet_seconds debounce
- identity-risk-anomaly.yaml
    sensor.<node>_bfld_identity_risk ⇒ notify.<target>
    Two trigger paths:
      - Absolute spike (raw score >= spike_threshold, default 0.8)
      - Rolling 7-day z-score deviation (default 3 sigma)
    Requires a Statistics helper entity for the baseline; documented
    in the inline description and the blueprints README.
- README.md
    Lists the three blueprints + privacy caveat for identity_risk
    (only present at PrivacyClass::Anonymous; class 3 deployments
    will fail validation by design)

Added (in v2/crates/wifi-densepose-bfld/tests/ha_blueprints.rs):
- 7 named tests using include_str! to embed each YAML at build time
  and validate structure without adding a serde_yaml dep:
    presence_lighting_blueprint_is_structurally_valid
    motion_hvac_blueprint_is_structurally_valid
    identity_risk_blueprint_is_structurally_valid
    blueprints_carry_source_url_pointing_at_canonical_path
      (catches path drift when files move)
    presence_blueprint_uses_mqtt_integration_filter
    motion_blueprint_uses_mqtt_integration_filter
    identity_risk_blueprint_carries_privacy_class_caveat_in_description
      (operators running class 3 should know not to install)
- Helper assert_required_blueprint_fields(yaml, name_substring, label)
  enforces blueprint.{name,domain,input,trigger,action,mode} per HA spec

ACs progressed:
- ADR-122 §2.6 — all three blueprints shipped with the documented
  configurable inputs (hold_seconds for #1, motion_threshold +
  delta_temperature_c for #2, z_score_threshold + statistics_entity
  for #3). Operator installs via HA UI; no YAML editing required.
- ADR-118 §1.5 privacy_mode visibility — identity-risk blueprint
  documents the class-2-only availability so operators understand
  why the blueprint fails on class-3 deployments.

Test config:
- cargo test --no-default-features → 72 passed
- cargo test                       → 210 passed (203 + 7)

Out of scope (next iter target):
- GitHub Actions workflow with mosquitto Docker so iters 24 + 29
  e2e tests actually run in CI with BFLD_MQTT_BROKER set.
- cog-ha-matter cargo crate-internal test that loads each blueprint
  via serde_yaml + validates against an HA blueprint schema (instead
  of the string-only checks here). Optional; current coverage is
  sufficient to catch drift in the YAML files themselves.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.1): end-to-end I3 isolation proof via BfldPipeline (217/217 GREEN)

Iter 31. Lifts ADR-118 invariant I3 + ADR-120 §2.7 AC2 from the
SignatureHasher unit-test surface (iter 15) to the public BfldPipeline
API surface. Every assertion goes through pipeline.process() so the
chain exercises emitter → identity_features encoder → signature hasher
→ event construction end-to-end.

Added (in v2/crates/wifi-densepose-bfld/tests/pipeline_i3_isolation.rs):
- 7 named tests, all green:
    same_person_at_different_sites_same_day_produces_different_hashes
    same_person_same_site_different_day_rotates_the_hash
    thirty_day_gap_produces_thoroughly_different_hash
      (Hamming distance >= 80 bits — catches a weak day_epoch mix-in
       even if naive byte-equality remains different)
    same_person_same_site_same_day_produces_stable_hash
    cross_site_hamming_distance_at_pipeline_surface_is_statistically_high
      *** ADR-120 §2.7 AC2 at the public pipeline surface ***
      32 trials × 32 bytes; mean Hamming distance ≥ 120 bits required
      (the same threshold the iter-15 SignatureHasher-direct test used)
    restricted_class_strips_hash_but_pipeline_state_advances
      (class 3 contract: hash stripped from event surface but the
       underlying gate / ring / hasher state still updates so the
       pipeline keeps detecting things; future PR can't accidentally
       short-circuit at class 3 and miss legitimate sensing)
    pipeline_without_signature_hasher_does_not_invent_a_hash
      (no hasher installed → rf_signature_hash stays None)

ADR-124 status (from sibling-agent check in this iter's step 0):
- docs/adr/ADR-124-* not present yet
- docs/research/rvagent-rvf-integration/README.md present (iter 25)
- No conflict with current scope; will pick up sibling output on next iter

ACs progressed:
- ADR-118 invariant I3 — runtime proof now at the PUBLIC API surface,
  not just inside SignatureHasher. Operators reading the BfldPipeline
  documentation can verify cross-site isolation without descending
  into the hasher internals.
- ADR-120 §2.7 AC2 — pipeline-surface mean Hamming distance >= 120
  bits in the cross_site test pins the structural-isolation invariant
  at the same threshold as the iter-15 unit-level test.
- ADR-118 §1.5 — restricted_class_strips_hash test pins the
  defense-in-depth contract that class-3 doesn't accidentally also
  freeze pipeline state.

Test config:
- cargo test --no-default-features → 72 passed (pipeline_i3_isolation cfg-out)
- cargo test                       → 217 passed (210 + 7)

Out of scope (next iter target):
- GitHub Actions workflow with mosquitto Docker (lifts iters 24+29
  from skip-mode in CI).
- ADR-119 AC7 serialization throughput benchmark (50k frames/sec).
- ADR-122 AC3: 1Hz motion-publish rate integration test against the
  BfldPipelineHandle worker thread.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.2): serialization throughput test (ADR-119 AC7) — 221/221 GREEN

Iter 32. Closes ADR-119 AC7 ("Bench: serialization throughput ≥ 50k
frames/sec on a 2025-era M1/M2 / Pi 5 core"). Pure std::time::Instant
timing; no criterion / no dev-deps added.

Empirically measured in DEBUG build on this Windows host:
- BfldFrameHeader::to_le_bytes()  → 1,654,517 frames/sec (33× AC7)
- BfldFrame::to_bytes() + CRC32   →   320,255 frames/sec ( 6.4× AC7)
- Parse-cost ratio (1024B vs 512B payload): 1.59× (linear)

Release builds typically run 20–100× faster than debug; the AC7 target
is for release, so debug already smashing 50k means release has very
comfortable margin.

Added (tests/serialization_throughput.rs):
- pub const RELEASE_TARGET_FRAMES_PER_SEC = 50_000.0 (the AC7 number)
- const DEBUG_FLOOR_FRAMES_PER_SEC      = 5_000.0  (generous CI floor)
- header_only_to_le_bytes_throughput_meets_debug_floor
    50k iters with a 1k-iter warmup, black_box-guarded.
    Prints throughput to stderr so CI logs show the measured number.
- full_frame_to_bytes_throughput_meets_debug_floor
    Same shape but with 512B payload + CRC32 round-trip per iter.
- round_trip_through_bytes_remains_constant_time_per_byte
    Compares from_bytes() timing for 512B vs 1024B payload; asserts
    the ratio is in [1.0, 4.0] to catch an accidental O(n²) parser
    regression. Empirical ratio: 1.59× (expected ~2× for O(n)).
- header_size_constant_is_used_consistently_by_serializer
    Belt-and-suspenders: asserts to_le_bytes().len() == BFLD_HEADER_SIZE
    == 86, pinning the iter-1 AC1 contract from the throughput side.

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md NOW PRESENT
  (sibling agent landed it; 431 lines). Codename SENSE-BRIDGE. Scope:
  MCP server (stdio + Streamable HTTP) wrapping sensing-server's
  REST/WS/MQTT surfaces, plus a ruvector npm/TypeScript package for
  in-app consumption + ruflo MCP-tool integration. Orthogonal to BFLD
  core — BFLD produces events that SENSE-BRIDGE would expose via MCP,
  but the MCP bridge itself is not BFLD territory. No scope overlap
  with this iter or backlog targets.

ACs progressed:
- ADR-119 AC7 — debug-build serialization throughput is already 33×
  the documented release-build target. Release-build margin is
  comfortable; future iters can run --release to capture an exact
  release number for the witness bundle.

Test config:
- cargo test --no-default-features → 72 passed
- cargo test                       → 221 passed (217 + 4)

Out of scope (next iter target):
- GitHub Actions workflow with mosquitto Docker (lifts iter 24/29
  e2e from skip-mode in CI).
- ADR-122 AC3: 1Hz motion-publish-rate integration test against the
  BfldPipelineHandle worker thread (would use a Barrier + Instant
  delta over N sustained publishes).

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.3): motion publish rate ≥ 1Hz integration test (ADR-122 AC3) — 224/224 GREEN

Iter 33. Closes ADR-122 AC3 ("Motion score published at ≥ 1 Hz on
ruview/<node_id>/bfld/motion/state during sustained occupancy") with
an end-to-end test through the BfldPipelineHandle worker thread.

Empirically measured on this Windows host: 10 inputs spaced 100ms
apart → 9.96 Hz motion-publish rate (10× the AC3 floor).

Added (in v2/crates/wifi-densepose-bfld/tests/motion_publish_rate.rs):
- motion_publish_rate_meets_one_hz_under_sustained_input
    Drives the handle with 10 sends at 100ms intervals, measures the
    wall-clock elapsed time, asserts motion count >= 10 AND rate
    (count / elapsed) >= 1.00 Hz. Prints throughput to stderr.
- motion_values_track_input_motion_values
    Pins iter-21's payload-encoding contract: motion values [0.10,
    0.25, 0.50, 0.75, 0.95] flow through as "{:.6}" strings without
    quantization drift.
- motion_topic_never_appears_for_class_below_anonymous_publishing
    Defense in depth: Restricted (class 3) STILL publishes motion
    (sensing data) but NOT identity_risk. Pins the two-layer
    privacy contract: motion is operator-visible at all classes ≥ 2,
    identity_risk is class-2-only.

Helper: motion_messages(&[TopicMessage]) -> Vec<&TopicMessage>
    Filters the capture log to the motion topic so the assertions
    aren't sensitive to the surrounding presence/count/confidence
    topics also being published.

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md present
  unchanged at 431 lines (sibling agent's SENSE-BRIDGE ADR). Scope
  remains orthogonal to BFLD core; no overlap with this iter.

ACs progressed:
- ADR-122 AC3 closed: motion publish rate measured at 9.96 Hz
  through the handle worker — 10× the documented floor. Provides
  the runtime witness HA needs to trust the live state-topic stream.
- ADR-122 AC1 reinforced from the rate-test side: 10 inputs → 10
  motion topics, none lost in the worker queue.
- ADR-118 §1.5 reinforced again: Restricted strips identity_risk
  but not motion (motion is sensing, not identity).

Test config:
- cargo test --no-default-features → 72 passed
- cargo test                       → 224 passed (221 + 3)

Out of scope (next iter target):
- GitHub Actions workflow with mosquitto Docker (lifts iters 24+29
  from skip-mode in CI). All remaining unmet ACs at this point
  either require external resources (KIT BFId dataset for ADR-121,
  Pi5/Nexmon hardware for ADR-123) or CI infra.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.4): spawn_with_oracle for Soul Signature deployments (227/227 GREEN)

Iter 34. Closes the gap where BfldPipelineHandle had no path for an
operator-supplied SoulMatchOracle to reach the worker thread. The
emit_with_oracle surface added in iter 14 was unreachable through the
handle API — Soul Signature deployments (ADR-118 §1.4) had to either
drop down to BfldEmitter directly or accept Recalibrate gate-drops on
known-enrolled matches.

Added (in src/pipeline.rs):
- BfldPipeline::process_with_oracle<O: SoulMatchOracle>(
      inputs, embedding, oracle,
  ) -> Option<BfldEvent>
  Wraps emitter.emit_with_oracle then applies the same privacy_mode
  post-processing as process(). Privacy_mode and oracle are independent
  — class-3 demote still happens AFTER any oracle Recalibrate exemption.

Added (in src/pipeline_handle.rs):
- BfldPipelineHandle::spawn_with_oracle<P, O>(pipeline, publisher, oracle) -> Self
  where O: SoulMatchOracle + Send + Sync + 'static
  The worker thread owns the oracle and consults it on every recv().
  Worker loop now calls pipeline.process_with_oracle(...) instead of
  pipeline.process(...).

tests/handle_soul_oracle.rs (3 named tests, all green):
  spawn_with_oracle_null_is_equivalent_to_spawn
    Parity: 3 identical low-risk inputs through spawn() and
    spawn_with_oracle(NullOracle) produce the same publish count
    and the same motion-topic count.
  spawn_with_always_match_oracle_lets_events_publish_under_high_risk
    *** Headline test ***
    3 high-risk inputs spaced > DEBOUNCE_NS apart. With AlwaysMatch
    oracle, all 3 produce motion topics — the gate never reaches
    Recalibrate because the oracle reports an enrolled-person match.
  spawn_with_null_oracle_drops_events_under_sustained_recalibrate_score
    Negative control for the above: same 3 inputs through NullOracle,
    only 1 motion topic survives (the first input lands at Accept;
    the second and third hit Recalibrate after debounce and are
    dropped per ADR-121 §2.4).

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal to BFLD core;
  no overlap with this iter.

ACs progressed:
- ADR-118 §1.4 Soul Signature companion contract end-to-end through
  the public handle API. Operators wiring Soul Signature into a
  RuView deployment now use:
      BfldPipelineHandle::spawn_with_oracle(pipeline, publisher, my_oracle)
  …and the rest of the per-frame flow stays identical to spawn().
- ADR-121 §2.6 Recalibrate exemption proven over the worker-thread
  boundary, not just at the unit level (iter 12 covered the gate-only
  case).

Test config:
- cargo test --no-default-features → 72 passed
- cargo test                       → 227 passed (224 + 3)

Out of scope (next iter target):
- GitHub Actions workflow with mosquitto Docker (lifts iters 24+29
  live-broker e2e from skip-mode). Remaining unmet ACs require
  either external resources (KIT BFId, Pi5/Nexmon) or CI infra.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.5): GitHub Actions mosquitto Docker CI workflow (235/235 GREEN)

Iter 35. Lifts iters 24 + 29 live-broker integration tests out of
skip-mode in CI by spinning up an eclipse-mosquitto:2 service container,
exporting BFLD_MQTT_BROKER, and running the three cargo test matrices.

Added:
- .github/workflows/bfld-mqtt-integration.yml
    * Triggers: push to main / feat/adr-118-* / feat/bfld-*, PR, manual
    * Path filter: only runs when v2/crates/wifi-densepose-bfld/** or the
      workflow file itself changes — protects PR throughput for unrelated
      crate work
    * Service container: eclipse-mosquitto:2 on port 1883 with a
      mosquitto_pub-based healthcheck (5s interval, 10 retries) so the
      runner waits for a real publish-ready broker, not just liveness
    * Top-level timeout-minutes: 15 (bounds runner cost if rumqttc
      handshake hangs)
    * Three cargo test invocations:
        cargo test -p wifi-densepose-bfld --no-default-features
        cargo test -p wifi-densepose-bfld
        cargo test -p wifi-densepose-bfld --features mqtt
      The third one now actually exercises the mosquitto_integration and
      rumqttc_lwt tests, not just the skip-mode path.
    * Belt-and-suspenders nc -z port poll before tests start (service
      container can take a few seconds to bind even with healthcheck)
    * cargo clippy --features mqtt as a continue-on-error gate (signals
      drift; doesn't block the merge yet)
    * RUSTFLAGS=-D warnings, CARGO_INCREMENTAL=0 for stable runs

- v2/crates/wifi-densepose-bfld/tests/ci_workflow.rs (8 named tests):
    Validates the workflow YAML via include_str! — same pattern iter 30
    used for HA blueprints. Catches drift in CI infra:
      workflow_declares_mosquitto_service_container
      workflow_exports_broker_env_for_iter_24_and_29_tests
        (BFLD_MQTT_BROKER pointing at the service container)
      workflow_runs_three_cargo_test_invocations
        (no_default + default + mqtt — three classes of bug surface)
      workflow_waits_for_mosquitto_readiness_before_testing
        (nc -z 1883 port poll)
      workflow_uses_health_check_on_the_service
        (mosquitto_pub-based, not just process liveness)
      workflow_only_triggers_on_bfld_paths
        (path filter to v2/crates/wifi-densepose-bfld/**)
      workflow_pins_runner_to_ubuntu_latest_for_docker_service_support
        (GitHub Actions `services:` doesn't work on macOS/Windows)
      workflow_has_timeout_guard
        (top-level timeout-minutes pinned)

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines (SENSE-BRIDGE ADR). Scope remains orthogonal.

ACs progressed:
- ADR-122 §2.2 e2e — when this workflow lands on origin/main and the
  next BFLD PR runs, the iter-24 anonymous-event roundtrip + restricted-
  event-omits-identity_risk tests stop printing "skipping" and actually
  publish to / subscribe from mosquitto. Plus the iter-29 LWT publisher
  smoke run gets to fire its session-drop test against a live broker.
- ADR-118 §2.1 ⇄ §2.2 — discovery + state-topic + LWT + worker thread
  all proven in one CI matrix run.

Test config:
- cargo test --no-default-features → 72 passed (ci_workflow cfg-out)
- cargo test                       → 235 passed (227 + 8)

Out of scope (skipped — external resources or hardware):
- ADR-121 calibration — KIT BFId dataset
- ADR-123 production capture — Pi 5 / Nexmon hardware

All other in-crate ACs from the ADR-118 / 119 / 120 / 121 / 122 series
are now covered by the iter 1-35 chain. The cron loop should
consider closing out at this point or pivoting to documentation /
witness-bundle generation for the PR.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p1.7): reserved-flag-bits forward-compat (243/243 GREEN)

Iter 36. Locks down the ADR-119 §2.1 forward-compat promise that
reserved flag bits round-trip unchanged through the parser. A future
protocol revision may light up bits 2 or 4..=15; today's parser
preserves them so a node running iter N can forward unknown bits to
a peer running iter N+M without losing information.

Added (in src/frame.rs::flags):
- pub const KNOWN_FLAGS_MASK = HAS_CSI_DELTA | PRIVACY_MODE | SELF_ONLY
    (the three currently-named flags, occupying bits 0, 1, 3)
- pub const RESERVED_FLAGS_MASK = !KNOWN_FLAGS_MASK
    (bit 2 + bits 4..=15 — every position not currently assigned)
- Docstrings reference ADR-119 §2.1 verbatim so a future reviewer
  understands why the constants exist.

tests/reserved_flags.rs (8 named tests, all green, no_std-compatible
so they run in BOTH feature configs):
  known_flags_mask_covers_exactly_three_named_flags
    (count_ones() == 3 catches accidental flag additions that should
     also update KNOWN_FLAGS_MASK)
  reserved_and_known_masks_are_complementary
    (mask | reserved == u16::MAX; mask & reserved == 0)
  known_flags_do_not_overlap_with_each_other
    (HAS_CSI_DELTA, PRIVACY_MODE, SELF_ONLY all on distinct bits)
  header_preserves_reserved_flag_bits_through_round_trip
    *** Headline test: set RESERVED_FLAGS_MASK on a header, serialize,
        parse, verify the bits survived. ***
  header_preserves_mixed_known_and_reserved_bits
    (HAS_CSI_DELTA | PRIVACY_MODE | (1<<7) | (1<<14) — mixed case)
  reserved_bits_do_not_collide_with_self_only_bit_3
    (bit 2 is reserved but bit 3 is named — pins the asymmetry)
  all_zero_flags_round_trip_cleanly
  all_one_flags_round_trip_cleanly (stress: every bit set)

The new tests are no_std-compatible (no Vec / no serde) so they run
in both `cargo test --no-default-features` and default feature
configs. The no_default test count therefore jumps from 72 to 80.

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-119 §2.1 "Reserved flag bits 2-15 lock in future-extension
  order; any new bit assignment is a version bump." — the test now
  enforces the OTHER half of this contract: a peer running the
  future version can set a reserved bit and our parser will preserve
  it through the round-trip rather than masking it off.

Test config:
- cargo test --no-default-features → 80 passed (72 + 8 no_std-compat)
- cargo test                       → 243 passed (235 + 8)

Out of scope (next iter target):
- PR-readiness pivot: witness bundle regeneration, CHANGELOG batch
  across iters 1-36, AC closeout table for the PR description.
  All in-crate ACs are now covered; remaining work is either
  external-resource-gated (KIT BFId, Pi5/Nexmon) or PR-prep.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.6): pipeline event-stream JSON determinism (248/248 GREEN)

Iter 37. Adds the cross-pipeline counterpart to iter 31's I3 isolation
tests. Iter 31 proved hash DIFFERENCES across sites and days; this
iter proves event-stream EQUALITY across two pipeline instances with
matching configuration. Operators capturing BFI for offline replay
analysis can now trust that replaying the same input stream produces
byte-identical JSON output across BFLD versions.

Added (in v2/crates/wifi-densepose-bfld/tests/pipeline_determinism.rs):
- 5 named tests, all green:

  two_pipelines_with_identical_config_produce_identical_event_streams
    Build two BfldPipelines from the same BfldConfig (same node_id,
    same SignatureHasher salt, same class), drive both with 5
    identical (timestamp, motion, embedding) tuples, then walk both
    event vecs field-by-field asserting equality of every
    publishable BfldEvent field including the derived
    rf_signature_hash and identity_risk_score.

  two_pipelines_produce_byte_identical_event_json_streams
    (gated on serde-json) — same fixture, but compares the
    serde_json::to_string output as Vec<String>. This is the
    operator's true wire-form replay guarantee.

  replaying_same_input_sequence_after_pipeline_reset_reproduces_events
    Catches accidental hidden state by building, draining, and
    rebuilding the pipeline twice; asserts the hash sequences match.
    If a future PR adds an internal counter that affects output,
    this test fires.

  different_input_sequences_diverge_after_the_first_difference
    Negative control: identical first two inputs produce identical
    hashes; changing the third input (different embedding) produces
    a different hash. Pins that the determinism is genuine, not
    "always returns the same value."

  class_3_pipelines_produce_identical_stripped_event_streams
    Determinism property must hold across privacy classes too —
    operators running Restricted deployments need replay to work
    even though identity fields are stripped.

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-119 AC6 (deterministic serialization) lifted from the
  BfldFrame layer (iter 2) to the BfldEvent + JSON layer.
  Operators get end-to-end determinism guarantees from sensing
  input through to MQTT topic payload.
- ADR-118 §2.1 pipeline correctness — two-pipeline equality is the
  strongest form of the "same input → same output" contract the
  facade can offer. Combined with iter 31's I3 difference proof,
  the pipeline now has both "should match" and "should differ"
  invariants pinned at the public-API level.

Test config:
- cargo test --no-default-features → 80 passed (pipeline_determinism cfg-out)
- cargo test                       → 248 passed (243 + 5)

Out of scope (next iter target):
- PR-readiness pivot — CHANGELOG batch, witness bundle, AC closeout
  table for the eventual PR description. All in-crate ACs are now
  covered by iters 1-37; remaining work is either external-resource-
  gated (KIT BFId, Pi5/Nexmon) or PR-prep.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.7): apply_privacy_gating irreversibility tests (255/255 GREEN)

Iter 38. Pins ADR-120 §2.4 ("There is no `promote` operation") at the
BfldEvent::apply_privacy_gating soft-mutation surface. Iter 9's
PrivacyGate::demote tests already proved this for the explicit
class-transition transformer; this iter proves it for the *soft*
in-place re-classifier used by BfldPipeline::process() under
enable_privacy_mode().

Defense-in-depth property: an attacker who manages to flip
event.privacy_class from Restricted back to Anonymous cannot then
resurrect the stripped identity fields through apply_privacy_gating
alone. They'd have to fabricate the fields via direct field assignment
or rebuild via with_privacy_gating — both of which are conspicuous in
code review (single byte flip is not).

Added (in tests/event_gating_irreversibility.rs):
- 7 named tests, all green:

  apply_at_anonymous_preserves_identity_fields
    Sanity: apply doesn't strip when class is Anonymous.

  manual_class_flip_to_restricted_then_apply_strips_both_fields
    Direct path: class Anonymous → flip to Restricted → apply
    → identity_risk_score and rf_signature_hash both None.

  one_way_strip_survives_class_flip_back_to_anonymous
    *** HEADLINE TEST ***
    Anonymous → flip to Restricted → apply (strip) → flip back to
    Anonymous → apply → fields STILL None. apply_privacy_gating
    must not resurrect.

  manual_field_restoration_after_strip_only_works_via_explicit_assignment
    The escape hatch is direct field assignment (visible in code
    review), not the soft gate. Confirms: after explicit
    Some(0.42) reassignment + class=Anonymous + apply, the
    values survive.

  apply_at_already_restricted_with_already_none_fields_is_a_noop
    Idempotency on stripped-state.

  one_way_property_holds_through_multiple_class_round_trips
    Stress: 5 Restricted→apply→Anonymous→apply cycles. Fields
    must stay None throughout — no slow-resurrection bug.

  rebuilding_via_with_privacy_gating_is_the_documented_restoration_path
    Pins the doc contract: to publish identity fields again after
    a strip, build a fresh BfldEvent. The constructor accepts
    explicit Some(...) values; apply_privacy_gating then doesn't
    strip because class is Anonymous.

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-120 §2.4 "no promote operation" now structurally proven at the
  SOFT (apply_privacy_gating) path in addition to the EXPLICIT
  (PrivacyGate::demote) path that iter 9 covered. Both layers of
  the privacy gate carry the one-way-only invariant.
- ADR-118 invariant I1 — once stripped, raw identity fields can only
  be re-introduced through paths visible in code review (direct
  field assignment, fresh constructor). No subtle byte-flip path
  resurrects them.

Test config:
- cargo test --no-default-features → 80 passed (event_gating_irreversibility cfg-out)
- cargo test                       → 255 passed (248 + 7)

Out of scope (next iter target):
- PR-readiness pivot: CHANGELOG, witness bundle, AC closeout table.
  External-resource-gated work (KIT BFId, Pi5/Nexmon) still skipped.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p1.8): CRC-32/ISO-HDLC polynomial pinning (262/262 GREEN)

Iter 39. Defends the wire-format CRC contract from silent polynomial
substitution. ADR-119 §2.4 specifies CRC-32/ISO-HDLC (same as Ethernet
and zlib), NOT CRC-32C (Castagnoli) or any other variant. Two BFLD
implementations that disagree on the polynomial treat every frame
from the other as corrupt.

Added (in tests/crc32_polynomial.rs):
- 7 named tests using canonical CRC vectors from the reveng catalogue
  (https://reveng.sourceforge.io/crc-catalogue/all.htm):

  check_string_matches_canonical_iso_hdlc_value
    CRC-32/ISO-HDLC of the standard "123456789" check string is
    0xCBF43926. This is THE canonical vector for the algorithm.

  empty_payload_yields_zero_crc
    init=0xFFFFFFFF, xorout=0xFFFFFFFF → empty payload CRC is 0.

  single_zero_byte_has_a_specific_value
    CRC-32/ISO-HDLC of [0x00] is 0xD202EF8D — well-known constant.

  flipping_a_single_payload_byte_changes_the_crc
    Sensitivity property: any one-bit flip MUST change the CRC.
    Catches a stuck CRC implementation.

  iso_hdlc_distinguishes_from_castagnoli_for_same_input
    CRC-32C/Castagnoli of "123456789" is 0xE3069283.
    Our value MUST differ. Documents the failure mode for a future
    reviewer who fires the test.

  known_short_inputs_have_documented_crcs
    Three additional vectors: "a", "abc", "hello world".
    Each pins a specific 32-bit value against the active polynomial.

  crc_is_deterministic_across_repeated_calls
    Sanity for pure-function correctness.

These tests are no_std-compatible so they run in BOTH feature configs.
The no_default count therefore jumps from 80 to 87.

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-119 §2.4 "CRC-32/ISO-HDLC" contract — the test surface now
  catches any future PR that swaps the polynomial. crc 4.x ships
  CRC_32_ISO_HDLC alongside half a dozen other CRC-32 variants;
  a typo in src/frame.rs::CRC32_ALG could otherwise silently flip
  the wire-format contract.

Test config:
- cargo test --no-default-features → 87 passed (80 + 7 no_std-compat)
- cargo test                       → 262 passed (255 + 7)

Out of scope (next iter target):
- PR-readiness pivot: CHANGELOG, witness bundle, AC closeout table.
  External-resource-gated work (KIT BFId, Pi5/Nexmon) still skipped.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.8): pipeline gate-state observability (269/269 GREEN)

Iter 40. Pins BfldPipeline::current_gate_action() as a stable operator-
facing diagnostic surface. Iter 11 covered the underlying CoherenceGate
state machine; this iter validates the same transitions through the
public BfldPipeline facade so operators can observe gate behavior
without descending into the lower-level types.

Added (in tests/pipeline_gate_observability.rs, 7 named tests):
  fresh_pipeline_starts_in_accept
  low_risk_processing_stays_in_accept (3 inputs at 0.1^4 risk)
  first_high_risk_input_does_not_immediately_promote_gate
    (pending != current — debounce hasn't elapsed)
  sustained_high_risk_promotes_gate_to_reject_after_debounce
    (two inputs across DEBOUNCE_NS boundary → Reject)
  sustained_recalibrate_grade_score_reaches_recalibrate
    (same pattern with 1.0^4 score → Recalibrate)
  returning_to_low_risk_restores_accept_via_hysteresis
    (round trip: 0.9^3 * 0.85 PredictOnly → 0.1^4 Accept via debounce)
  current_gate_action_is_read_only_does_not_advance_state
    *** Important property for operator-facing surface ***
    Three reads between processes must return the same value and not
    perturb pipeline state. A polling monitor calling this in a tight
    loop must not influence what the next process() observes.

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-118 §2.1 operator diagnostic surface — current_gate_action()
  now provably read-only and observably transitioning through the
  full 4-action band. Operators wiring HA notifications or fleet
  dashboards to "gate Reject means something to investigate" have
  a stable contract.
- ADR-121 §2.4 + §2.5 — gate transitions visible at the facade
  layer match the underlying CoherenceGate semantics; hysteresis
  and debounce work end-to-end through process().

Test config:
- cargo test --no-default-features → 80 passed (gate_observability cfg-out)
- cargo test                       → 269 passed (262 + 7)

Out of scope (next iter target):
- PR-readiness pivot: CHANGELOG batch, witness bundle regeneration,
  AC closeout table for the eventual PR description. All 5 ACs of
  ADR-118 / 7 ACs of ADR-119 / 7 ACs of ADR-120 / 7 ACs of ADR-121 /
  6 ACs of ADR-122 are now covered by iters 1-40. Remaining work is
  external-resource-gated (KIT BFId, Pi5/Nexmon hardware) or PR-prep.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p1.9): PrivacyClass capability-helper truth tables (279/279 GREEN)

Iter 41. Pins the const-helper API (PrivacyClass::allows_network /
allows_matter) and proves it stays in sync with the Sink::MIN_CLASS
trait-level enforcement. Drift between these two APIs would be a
silent correctness bug — an operator checking allows_network() might
get a different answer than the actual NetworkSink::check_class()
runtime gate.

Added (in tests/privacy_class_capability.rs, no_std-compatible):
- 10 named tests, all green:

  allows_network_truth_table     (4 classes × bool)
  allows_matter_truth_table      (4 classes × bool)
  allows_matter_implies_allows_network
    Monotonicity: Matter is a strict subset of Network. Any class
    that allows Matter MUST allow Network. The reverse is not true
    (Derived is Network-eligible but not Matter-eligible).
  allows_network_strictly_excludes_raw
    Class 0 is the ONLY class that fails allows_network. Any future
    refactor that lets Raw cross a NetworkSink violates ADR-118 I1.
  allows_matter_strictly_requires_class_two_or_three
  local_sink_accepts_every_class_per_helper
    Cross-consistency: LocalSink::MIN_CLASS = Raw, accepts all.
  network_sink_consistency_matches_allows_network
    For every class, check_class<NetworkKind> agrees with allows_network().
  matter_sink_consistency_matches_allows_matter
    Same for Matter.
  as_u8_returns_documented_byte_values    (0, 1, 2, 3)
  class_byte_ordering_matches_information_density  (raw < derived < anon < restr)

Helper:
  check_consistency<S: Sink>(class, helper_says_allowed) compares the
  Boolean helper against (class_byte >= S::MIN_CLASS.as_u8()) and asserts
  equality. Catches drift before it reaches operator-visible behavior.

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-118 invariant I1 reinforced at the const-helper layer: a future
  PR refactoring PrivacyClass::Raw to be Network-eligible breaks 4 of
  the 10 tests (truth table + monotonicity + Raw exclusion + sink
  consistency), so the regression is loud rather than silent.
- ADR-120 §2.2 sink-class contract pinned at the helper layer. The
  iter 3 (Sink + check_class) and iter 1 (allows_network) APIs now
  have a regression test enforcing their agreement.

Test config:
- cargo test --no-default-features → 90 passed (+10 no_std-compat)
- cargo test                       → 279 passed (269 + 10)

Out of scope (next iter target):
- PR-readiness pivot remains the genuine next step: CHANGELOG batch,
  witness bundle regeneration, AC closeout table. All ADR-118/119/120/
  121/122 ACs are now empirically covered. External-resource-gated
  work (KIT BFId, Pi5/Nexmon hardware) stays skipped.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.9): BfldError Display format pinning (290/290 GREEN)

Iter 42. Pins the thiserror-derived Display output for every BfldError
variant. Operators grep log lines for these strings; format drift
between minor versions breaks monitoring queries and alerting rules.
This iter locks the contract.

Added (in tests/bfld_error_display.rs, 11 named tests):
- One test per BfldError variant asserting the documented substrings
  appear in to_string():
    invalid_magic_displays_both_expected_and_actual_in_hex
    unsupported_version_displays_the_offending_version
    crc_mismatch_displays_both_values_in_hex
    privacy_violation_displays_the_sink_reason
    invalid_privacy_class_displays_the_offending_byte
    truncated_frame_displays_got_and_need_byte_counts
    malformed_section_displays_offset_and_reason
    invalid_demote_displays_both_from_and_to_class_bytes
- Meta tests:
    bfld_error_implements_std_error_trait
      (compile-time witness via fn assert_error_trait<E: std::error::Error>())
    bfld_error_is_debug_so_panic_unwrap_messages_carry_diagnostics
    every_variant_has_a_non_empty_display_string
      (catch-all: 8 variants × non-empty Display assertion;
       guards against a future PR that adds a new variant without
       the #[error(...)] attribute)

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-118 §2.1 operator observability — error-message contract now
  pinned. A monitoring rule that greps for "payload CRC mismatch"
  or "privacy violation" continues to fire correctly across BFLD
  versions.

Test config:
- cargo test --no-default-features → 90 passed (bfld_error_display cfg-out)
- cargo test                       → 290 passed (279 + 11)

Out of scope (next iter target):
- PR-readiness pivot remains the genuine next move: CHANGELOG batch,
  witness bundle regeneration, AC closeout table. All in-crate ACs
  empirically covered; remaining work is external-resource-gated
  (KIT BFId, Pi5/Nexmon hardware) or PR-prep.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p1.10): frame parser trailing-bytes contract (296/296 GREEN)

Iter 43. Pins BfldFrame::from_bytes behavior on buffers carrying bytes
past `BFLD_HEADER_SIZE + header.payload_len`. The parser currently
accepts these and silently slices to the declared length. Useful when
the transport (UDP MTU padding, ESP-NOW trailer alignment) adds noise
the application layer doesn't strip.

Pinning this behavior makes any future tightening (reject as
MalformedFrame) a deliberate, traceable policy change rather than
silent breakage.

Added (in tests/frame_trailing_bytes.rs, 6 named tests):
  parser_accepts_buffer_with_one_trailing_byte
    (smoke: one extra 0xFF byte tolerated; payload.last() != Some(0xFF))
  parser_accepts_many_trailing_bytes
    (256 trailing bytes — UDP MTU padding scale)
  parsed_payload_round_trips_back_to_typed_payload_with_trailing_bytes_present
    *** Sanity: trailing-bytes leniency must not corrupt the section
        parser downstream. from_bytes → parse_payload still yields
        the original BfldPayload byte-for-byte. ***
  header_only_buffer_at_exactly_header_size_with_zero_payload_len_succeeds
    (boundary: empty-payload frame is exactly 86 bytes)
  header_only_buffer_with_trailing_bytes_but_zero_payload_len_ignores_them
    (100 trailing bytes; parsed.payload stays empty)
  trailing_bytes_do_not_affect_crc_validation_when_payload_intact
    (CRC is over payload bytes only; 32 trailing bytes leave CRC
     intact and parse succeeds)

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-119 wire-format parser contract: trailing-bytes tolerance is
  now an explicit, tested behavior. Operators building stream-based
  frame readers (where multiple frames concatenate) know the parser
  treats `header.payload_len` as authoritative, not buffer.len().

Test config:
- cargo test --no-default-features → 90 passed (frame_trailing_bytes cfg-out)
- cargo test                       → 296 passed (290 + 6)

Out of scope (next iter target):
- PR-readiness pivot: CHANGELOG, witness bundle, AC closeout table.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p3.4): CoherenceGate clock-skew resilience (303/303 GREEN)

Iter 44. Pins the gate's saturating_sub-based debounce as safe under
clock perturbation. NTP rollback, system-clock adjustment, monotonic-
source switch — all can produce a backward `timestamp_ns` between
calls. The gate must NOT promote spuriously on backward jumps and
MUST NOT panic on identical / zero / u64::MAX-ish timestamps.

Added (in tests/gate_clock_skew.rs, no_std-compatible):
- 7 named tests, all green:

  backward_jump_after_pending_does_not_promote_prematurely
    Pending at t = DEBOUNCE_NS + 100; backward jump to t = 0.
    saturating_sub(0, DEBOUNCE_NS+100) = 0 < DEBOUNCE_NS → no promotion.

  forward_recovery_after_backward_jump_still_promotes_correctly
    Backward jump doesn't corrupt the pending `since` stamp; once wall
    time advances past since + DEBOUNCE_NS, promotion fires normally.

  identical_timestamps_across_repeated_polls_do_not_progress_state
    Five identical timestamps in a row — gate never promotes; both
    current and pending remain stable. Important for HA dashboards
    polling at >1Hz: the polling itself must not cause transitions.

  backward_jump_with_no_pending_is_a_noop
    Edge: no pending in flight, backward jump — gate stays clean.

  very_large_forward_jump_promotes_but_does_not_panic
    Stress: t = u64::MAX/2 jump. No overflow, no panic, promotes.

  backward_then_forward_into_different_action_band_resets_pending_correctly
    More subtle: pending PredictOnly → backward jump WITH a different
    score (recalibrate-grade) — pending target changes, debounce
    clock resets to the new (smaller) timestamp; forward by DEBOUNCE_NS
    promotes to Recalibrate.

  no_panic_on_zero_timestamp_with_predict_only_pending
    Regression guard: a poorly-initialized monotonic clock could
    deliver t=0 as the first sample. Gate must not panic.

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-121 §2.5 debounce property — saturating_sub usage now has a
  regression test. A future PR that swaps to plain `-` (panic on
  underflow) fires `no_panic_on_zero_timestamp_with_predict_only_pending`.
- ADR-118 §2.1 operator-facing diagnostic safety — current_gate_action
  polled at the same timestamp from a Prometheus exporter or HA
  dashboard cannot cause unintended state transitions.

Test config:
- cargo test --no-default-features → 97 passed (90 + 7 no_std-compat)
- cargo test                       → 303 passed (296 + 7)

Out of scope (next iter target):
- PR-readiness pivot still pending: CHANGELOG, witness bundle,
  AC closeout table. External-resource-gated work (KIT BFId,
  Pi5/Nexmon) still skipped.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.10): public API surface snapshot (308/308 GREEN)

Iter 45. Compile-time witness that every `pub use` re-export from
lib.rs survives refactors. A future PR removing one fires a named
test failure instead of producing a silent SemVer break.

Added (in tests/public_api_snapshot.rs):
- 5 named tests across feature flags:

  always_available_types_are_re_exported (no_std-compatible)
    Witnesses PrivacyClass, GateAction, MatchOutcome, BfldFrameHeader,
    CoherenceGate, NullOracle, EmbeddingRing, SignatureHasher,
    IdentityEmbedding + 11 const re-exports + 5 flag bits.

  sink_trait_hierarchy_re_exported (no_std-compatible)
    Witnesses Sink, LocalSink, NetworkSink, MatterSink, LocalKind,
    NetworkKind, MatterKind + check_class function. Trait bounds
    asserted via fn assert_sink<S: Sink>() etc. so missing impls
    fire here too.

  soul_match_oracle_trait_re_exported (no_std-compatible)
    Witnesses SoulMatchOracle trait + NullOracle impl.

  bfld_error_re_exported_with_all_named_variants (no_std-compatible)
    Constructs every BfldError variant — removing one fires.

  std_only_types_are_re_exported (gated on `std`)
    BfldConfig, BfldPipeline, BfldEmitter, PrivacyGate,
    CapturePublisher, BfldPipelineHandle, PipelineInput,
    SensingInputs, IdentityFeatures, BfldEvent, BfldFrame,
    BfldPayload, TopicMessage + 12 free-function re-exports
    (identity_risk_score, availability_topic, online_message,
    offline_message, publish_availability_*, publish_discovery,
    publish_event, render_*, with_privacy_gating) +
    PAYLOAD_AVAILABLE, PAYLOAD_NOT_AVAILABLE, RISK_FACTOR_BYTES.

  mqtt_publisher_types_are_re_exported (gated on `mqtt`)
    RumqttPublisher type + with_lwt free function signature.

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-118 §2.1 public-API stability — every documented re-export
  has a named-symbol regression test. Accidental removal fires
  loudly at build time rather than as a silent SemVer break on
  downstream consumers (cog-ha-matter, wifi-densepose-sensing-server,
  pip wifi-densepose, sibling-agent SENSE-BRIDGE crate).

Test config:
- cargo test --no-default-features → 101 passed (97 + 4 no_std-compat
  — the std-only mod test is cfg-out)
- cargo test                       → 308 passed (303 + 5)

Out of scope (next iter target):
- PR-readiness pivot still pending: CHANGELOG batch across iters
  1-45, witness bundle regeneration, AC closeout table for the PR
  description. External-resource-gated work (KIT BFId, Pi5/Nexmon)
  still skipped.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.11): presence detection latency p95 (ADR-119 AC2) — 311/311 GREEN

Iter 46. Closes ADR-119 AC2 ("Presence detection latency is ≤ 1s p95
from the first non-empty BFI frame in a new occupancy event"). Per-
call BfldPipeline::process() latency measured at the public facade
surface via pure std::time::Instant — no criterion dep.

Empirically measured on this Windows host (debug build):
- p50:           0.9µs    (1.1M frames/sec)
- p95:           0.9µs    (~1,000,000× under the 1s AC2 target)
- p99:           1.2µs
- First call:    2.9µs    (no lazy-init regression)
- Long-run growth: 1.55× from first-100 mean to last-100 mean
                  (10× ceiling guards against unbounded internal state)

Added (in tests/presence_latency.rs):
- pub const ADR_119_AC2_P95_TARGET = Duration::from_secs(1) (the AC number)
- const DEBUG_P95_FLOOR = Duration::from_millis(100) (generous CI floor)

Three named tests, all green:
  process_call_p95_latency_meets_debug_floor
    500 samples after a 50-sample warmup, sort, take p50/p95/p99,
    print to stderr, assert p95 <= 100ms AND p95 <= 1s.
  first_call_after_pipeline_construction_is_not_pathologically_slow
    Operator-visible "first event after node boot" latency. Bounded
    at 250ms — catches a constructor that defers work to first
    process() call (would show as a 100ms+ spike on a Pi 5 boot).
  latency_does_not_grow_unbounded_over_long_runs
    Compares first-100 sample mean vs last-100 over 500 calls;
    ratio < 10× guards against memory-leak-style regressions.

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-119 AC2 closed — p95 latency runs 6 orders of magnitude under
  the 1s target. Release-build margin is comfortable.
- ADR-118 §2.1 operator-perceived performance — first-call and
  long-run latency guards complement iter 32's serialization
  throughput bench (header 1.65M/s, full-frame 320k/s). Pipeline
  latency is dominated by the BFI capture step, not BFLD processing.

Test config:
- cargo test --no-default-features → 101 passed (presence_latency cfg-out)
- cargo test                       → 311 passed (308 + 3)

Out of scope (next iter target):
- PR-readiness pivot remains the genuine next step. All in-crate ACs
  empirically covered; remaining work is external-resource-gated
  (KIT BFId, Pi5/Nexmon) or PR-prep.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.12): examples/bfld_minimal.rs operator quickstart (315/315 GREEN)

Iter 47. Ships the operator-facing quickstart as doc-as-code. Three
goals:

1. New operators reading the crate get a 50-line working example
   instead of having to assemble pipeline + config + hasher + inputs
   + embedding + JSON publish themselves.
2. CI proves the example COMPILES and RUNS end-to-end via a
   separate test that re-executes the same flow inline.
3. The example output is the canonical BfldEvent JSON, demonstrating
   every documented field (presence/motion/count/conf/zone/class/
   identity_risk_score/rf_signature_hash) for a typical Anonymous
   class publish.

Added:
- v2/crates/wifi-densepose-bfld/examples/bfld_minimal.rs (~70 LOC):
    * Per-site secret salt
    * BfldPipeline::new(BfldConfig::new(...).with_signature_hasher(...))
    * SensingInputs with low-risk factors so the gate emits
    * IdentityEmbedding from a deterministic ramp
    * pipeline.process(...).ok_or(...) for the gate-drop case
    * event.to_json() printed to stdout
    * Run command in the doc comment:
        cargo run -p wifi-densepose-bfld --example bfld_minimal

- v2/crates/wifi-densepose-bfld/tests/example_minimal.rs (4 tests):
    minimal_example_documents_the_operator_quickstart_flow
      (asserts file contains BfldPipeline, SignatureHasher,
       SensingInputs, IdentityEmbedding, BfldConfig, .process(,
       to_json — catches doc drift if the example removes a key
       symbol)
    minimal_example_carries_run_instructions_in_doc_comments
      (the cargo run --example line must be present)
    minimal_example_flow_produces_valid_json_with_documented_fields
      *** Re-runs the example flow inline and asserts every
          documented JSON field appears in the output ***
    example_returns_box_dyn_error_for_main_signature
      (canonical Rust-example main signature)

- v2/crates/wifi-densepose-bfld/Cargo.toml:
    [[example]] name = "bfld_minimal", required-features = ["serde-json"]
    so `cargo test --no-default-features` doesn't try to build the
    example (which needs to_json gated on serde-json).

Example run output (sanity check before commit):
  {"type":"bfld_update","node_id":"seed-example","timestamp_ns":...,
   "presence":true,"motion":0.42,"person_count":1,"confidence":0.91,
   "privacy_class":"anonymous","identity_risk_score":0.0016000001,
   "rf_signature_hash":"blake3:cc3615c7aaab9d0867a0c15327444b8f...bf"}

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-118 §2.1 documentation surface — first operator-facing example
  shipped as part of the crate. Discoverable via
  `cargo run --example bfld_minimal` and verified via cargo test.

Test config:
- cargo test --no-default-features → 101 passed (example_minimal cfg-out)
- cargo test                       → 315 passed (311 + 4 example_minimal)

Out of scope (next iter target):
- PR-readiness pivot still pending: CHANGELOG, witness bundle,
  AC closeout table. External-resource-gated work still skipped.

Co-Authored-By: claude-flow <ruv@ruv.net>

* feat(adr-118/p6.13): examples/bfld_handle.rs worker-thread pattern (319/319 GREEN)

Iter 48. Ships the production-recommended operator example: full
lifecycle through the worker-thread handle. Companion to iter-47's
minimal example which uses BfldPipeline::process directly. The
handle example demonstrates the multi-thread pattern operators
actually deploy with HA + MQTT.

Lifecycle demonstrated in the example:
  1. publish_availability_online (retained → HA marks device online)
  2. publish_discovery (retained → HA auto-creates 6 BFLD entities)
  3. BfldPipelineHandle::spawn (worker owns gate + ring + hasher)
  4. handle.send(input) per BFI frame (worker process + publish)
  5. handle.shutdown() (clean worker join)
  6. publish_availability_offline (explicit graceful disconnect)

Example output (verified pre-commit):
  bootstrap: 1 availability + 6 discovery payloads
  total messages published: 33
  first three topics:
    ruview/seed-handle-demo/bfld/availability
    homeassistant/binary_sensor/seed-handle-demo_bfld_presence/config
    homeassistant/sensor/seed-handle-demo_bfld_motion/config
  last three topics:
    ruview/seed-handle-demo/bfld/confidence/state
    ruview/seed-handle-demo/bfld/identity_risk/state
    ruview/seed-handle-demo/bfld/availability

Added:
- v2/crates/wifi-densepose-bfld/examples/bfld_handle.rs (~110 LOC):
    * Documents the 6-phase lifecycle with inline comments
    * Pointer to RumqttPublisher::connect_with_lwt for prod use
    * 5 sensing frames × 5 state topics = 25 per-frame messages
- v2/crates/wifi-densepose-bfld/tests/example_handle.rs (4 named tests):
    handle_example_documents_full_lifecycle_phases
      (doc drift guard: 8 operator-facing symbols must appear)
    handle_example_carries_run_instructions_and_prod_pointer
      (cargo run line + RumqttPublisher pointer present)
    handle_example_lifecycle_produces_expected_message_counts
      *** Re-executes full lifecycle inline; asserts total == 33,
          first message payload == "online", last == "offline" ***
    handle_example_returns_box_dyn_error_for_main_signature
- v2/crates/wifi-densepose-bfld/Cargo.toml:
    [[example]] name = "bfld_handle", required-features = ["std"]

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-118 §2.1 documentation surface — two runnable operator examples
  now shipped (iter 47 minimal, iter 48 worker-thread). Together
  they cover the two operator patterns: simple in-process consumer
  (process + to_json) and the full HA-integration deployment
  (handle + bootstrap + lifecycle).
- ADR-122 §2.1 + §2.2 + §2.6 — the worker example exercises every
  layer of the HA-DISCO publish chain in one runnable file:
  availability, discovery, state, graceful shutdown.

Test config:
- cargo test --no-default-features → 101 passed (example_handle cfg-out)
- cargo test                       → 319 passed (315 + 4)

Out of scope (next iter target):
- PR-readiness pivot still pending. External-resource-gated work
  (KIT BFId, Pi5/Nexmon) still skipped.

Co-Authored-By: claude-flow <ruv@ruv.net>

* docs(adr-118/p6.14): crate README.md + Cargo.toml readme field (327/327 GREEN)

Iter 49. Ships the crate's first README — genuinely missing artifact.
crates.io renders this file; the rendered page is what downstream
operators see when they `cargo doc --open` or browse the registry.

Added:
- v2/crates/wifi-densepose-bfld/README.md (~135 lines):
    * Three structural invariants (I1/I2/I3) table with enforcement
      mechanism per invariant
    * Quickstart snippet: in-process consumer (BfldPipeline::process)
    * Quickstart snippet: production worker (BfldPipelineHandle +
      bootstrap helpers)
    * Feature flag matrix (std / serde-json / mqtt / soul-signature)
    * Two runnable example invocations
    * Testing matrix (no_default / default / mqtt)
    * Companion artifacts pointer (ADRs, research bundle, HA
      blueprints, CI workflow)
    * ADR cross-reference table (ADR-118 through ADR-123)
    * BFLD_MQTT_BROKER env-var doc for live mosquitto opt-in

- v2/crates/wifi-densepose-bfld/Cargo.toml:
    readme = "README.md"
    (so crates.io picks it up on publish)

- v2/crates/wifi-densepose-bfld/tests/crate_readme.rs (8 tests):
    readme_documents_three_structural_invariants
    readme_documents_feature_flag_matrix
    readme_documents_both_runnable_examples
    readme_documents_three_test_invocations
    readme_references_companion_adrs_118_through_123
    readme_quickstart_uses_canonical_public_api
      (8 symbol-presence checks: BfldPipeline::new, BfldConfig::new,
       SignatureHasher::new, SensingInputs, IdentityEmbedding::from_raw,
       pipeline.process, publish_availability_online, publish_discovery,
       BfldPipelineHandle::spawn, PipelineInput)
    readme_points_at_research_bundle_and_blueprints
    readme_documents_env_gated_mosquitto_integration

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- ADR-118 §2.1 documentation surface — crates.io / cargo doc landing
  page now exists. Operators encountering wifi-densepose-bfld for the
  first time get the three structural invariants, quickstart snippets
  for both deployment patterns, feature matrix, and ADR map without
  having to read source.

Test config:
- cargo test --no-default-features → 101 passed (crate_readme cfg-out)
- cargo test                       → 327 passed (319 + 8)

Out of scope (next iter target):
- PR-readiness pivot. CHANGELOG, witness bundle, AC closeout table.
  External-resource-gated work (KIT BFId, Pi5/Nexmon) still skipped.

Co-Authored-By: claude-flow <ruv@ruv.net>

* docs(adr-118): CHANGELOG [Unreleased] BFLD entry + validation test (332/332 GREEN)

Iter 50. PR-readiness pivot iter #1. Lands the BFLD entry under
CHANGELOG.md's [Unreleased] section per the project's pre-merge
checklist (CLAUDE.md). Plus a validation test that catches drift if
someone edits the entry and breaks the operator-facing summary.

Added (in CHANGELOG.md):
- New top-of-[Unreleased]-Added bullet for BFLD spanning:
  * ADR-118 umbrella + invariants I1/I2/I3 + their enforcement
    mechanism (Sink traits / Drop+no-Serialize / per-site BLAKE3)
  * ADR-119 frame format (86-byte header, payload sections, CRC32)
  * ADR-120 privacy classes + PrivacyGate::demote + apply_privacy_gating
  * ADR-121 multiplicative risk score + CoherenceGate + SoulMatchOracle
  * ADR-122 MQTT topic router + HA discovery + availability + LWT
  * ADR-123 capture path (reference; production capture is Pi5/Nexmon
    hardware-gated and remains skipped)
  * BfldPipelineHandle worker + spawn_with_oracle for Soul Signature
  * 3 operator HA blueprints (presence-lighting / motion-HVAC /
    identity-risk-anomaly)
  * Two runnable examples (bfld_minimal, bfld_handle)
  * eclipse-mosquitto:2 CI service container workflow
  * Performance measurements: 320k frames/sec, p95 0.9µs, 9.96 Hz
  * 327 default-feature tests, 101 no_std-compatible, 220+ with mqtt
  * Companion research dossier docs/research/BFLD/ (11 files, 13,544 words)
  * try-it command: cargo run -p wifi-densepose-bfld --example bfld_handle

Added (in tests/changelog_entry.rs, 5 tests):
- changelog_documents_bfld_entry_under_unreleased
    Slices CHANGELOG from `## [Unreleased]` to the first numbered
    version header and asserts the block contains BFLD,
    wifi-densepose-bfld, and the #787 tracking link.
- changelog_bfld_entry_cites_companion_adrs
    Substring asserts ADR-118..123 each appear at least once.
- changelog_bfld_entry_names_three_structural_invariants
    **I1**, **I2**, **I3** must be called out by name.
- changelog_bfld_entry_documents_a_runnable_example
    Operators get a copy-pasteable cargo command.
- changelog_bfld_entry_references_research_bundle

Caught + fixed during iter:
- First draft used "ADR-118 through ADR-123" shorthand; the
  per-ADR substring test fired for ADR-120 (not literally present).
  Re-wrote the parenthetical to "ADR-118 umbrella + ADR-119 frame
  format + ADR-120 privacy class + ADR-121 identity risk scoring +
  ADR-122 RuView HA/Matter exposure + ADR-123 capture path" so each
  ADR number is its own grep-discoverable token.

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- Pre-merge checklist item #5 (CLAUDE.md) — CHANGELOG `[Unreleased]`
  entry shipped. PR description can now link to the line + commit
  range as evidence.

Test config:
- cargo test --no-default-features → 101 passed (changelog_entry cfg-out)
- cargo test                       → 332 passed (327 + 5)

Out of scope (next iter target):
- Pre-merge checklist remaining: README.md update (#3 — points at the
  new crate from the workspace level), user-guide.md (#6), witness
  bundle regeneration (#8). External-resource-gated work (KIT BFId,
  Pi5/Nexmon) still skipped.

Co-Authored-By: claude-flow <ruv@ruv.net>

* docs(adr-118): root README Documentation table BFLD row (337/337 GREEN)

Iter 51. PR-readiness pivot iter #2. Adds BFLD to the workspace-root
README.md Documentation table — closes pre-merge checklist item #3
(README.md update if scope changed). GitHub renders this; new
contributors / operators browsing ruvnet/RuView see the entry on
landing.

Added (in README.md, top-level Documentation table):
- New row right after the Home Assistant + Matter row, linking to
  v2/crates/wifi-densepose-bfld/README.md (iter-49 crate README).
- Summary covers:
    * 3 type-enforced structural invariants
      (raw BFI never exits / in-RAM-only embedding / cross-site
       cryptographically impossible)
    * Full operator surface (BfldPipeline, BfldPipelineHandle,
      SoulMatchOracle)
    * MQTT topic router + HA-DISCO + availability + LWT
    * 3 operator HA blueprints
    * Two runnable examples
    * eclipse-mosquitto:2 CI service container
    * 327+ tests
- Per-ADR links: 118 (umbrella), 119 (frame), 120 (privacy class),
  121 (risk scoring), 122 (HA/Matter), 123 (capture path)
- Research dossier pointer: docs/research/BFLD/ (11 files, 13,544 words)

Added (in v2/crates/wifi-densepose-bfld/tests/root_readme_link.rs):
- 5 named tests via include_str!:
    root_readme_links_to_bfld_crate_readme
    root_readme_mentions_bfld_acronym_and_full_name
    root_readme_cites_all_six_bfld_adrs (per-ADR substring check)
    root_readme_points_at_research_bundle
    root_readme_documents_three_structural_invariants_in_summary
      ("raw BFI never exits", "in-RAM-only", "cross-site" — three
       invariants surfaced in the short table summary)

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md unchanged
  at 431 lines. SENSE-BRIDGE scope remains orthogonal.

ACs progressed:
- Pre-merge checklist item #3 (CLAUDE.md) — root README updated to
  point at the new crate. Operator discovery path now reaches BFLD
  from the GitHub repo landing page in 1 click.
- ADR-118 §2.1 documentation surface — discovery path complete:
  GitHub README → crate README → operator examples → ADRs → research
  dossier. All hops covered by include_str + link tests.

Test config:
- cargo test --no-default-features → 101 passed (root_readme_link cfg-out)
- cargo test                       → 337 passed (332 + 5)

Out of scope (next iter target):
- Pre-merge checklist remaining: user-guide.md update (#6) if new CLI
  flags / setup steps, witness bundle regeneration (#8). External-
  resource-gated work (KIT BFId, Pi5/Nexmon) still skipped.

Co-Authored-By: claude-flow <ruv@ruv.net>

* docs(adr-124): RUVIEW-POLICY layer + Q4 cache resolution + multi-modal vision

Three additive sections per maintainer review of SENSE-BRIDGE
(the original 13-section draft is unchanged below; these are
inserts):

§4.1a — RUVIEW-POLICY governance layer (NEW). Five tools:
- ruview.policy.can_access_vitals(agent_id, node_id, vital)
- ruview.policy.can_query_presence(agent_id, scope, node_id?, zone?)
- ruview.policy.can_subscribe(agent_id, topic, duration_s)
- ruview.policy.redact_identity_fields(payload, agent_id)
- ruview.policy.audit_log(agent_id?, since_ts?)

Enforcement is server-side, not client-side — agents cannot bypass.
Default policy when no file exists: deny vitals + audit_log; allow
presence.now + node.list; allow primitives.list_active with
redact_identity_fields applied. "Explore safely" default.

Q4 — RESOLVED. The library MUST take continuous local cache +
event-driven invalidation + bounded freshness windows. Tools
never wait on the next CSI frame; cache hits return in <1 ms;
every tool accepts max_age_ms and returns
{ value: null, reason: "stale", last_seen_ms, threshold_ms }
when stale rather than blocking. Decouples agent orchestration
latency from RF acquisition jitter — required to scale to dozens
of concurrent Streamable HTTP sessions per Q8.

§11.3 — Strategic implication: ambient-sensing normalization
layer (NEW). The §4 tool catalog shape is modality-agnostic.
Same surface absorbs BLE / mmWave (already on COM4) / LiDAR /
thermal / camera / radar / UWB. Position as semantic-environment
API, not WiFi client. Follow-on ADR-13x RUVIEW-FUSION formalizes
per-modality adapter contract. Out of scope for 124; designed in.

§11.2 risk table — added the "sensing-tool surface becomes
surveillance API" row, mitigation = RUVIEW-POLICY layer + server-
side redaction.

Refs: docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md

* docs(adr-118): user-guide.md BFLD subsection (345/345 GREEN)

Iter 52. PR-readiness pivot iter #3. Closes pre-merge checklist item #6
(user-guide.md update for new setup steps / CLI flags / integrations).
Adds a BFLD subsection inside the existing HA chapter so operators
already reading about HA-DISCO discover BFLD as the natural next layer.

Notes on iter context:
- Local branch was hard-reset earlier in the session (working tree
  showed only iters 1-3 state); remote origin/feat/adr-118-bfld-impl
  retained the full chain plus a sibling agent's ADR-124 commit
  (12586d31a, RUVIEW-POLICY layer + Q4 cache + multi-modal vision).
  Recovered local via git reset --hard origin/feat/adr-118-bfld-impl
  before this iter. No work lost.
- User redirected to "finish BFLD first" mid-iter, so the ADR-124
  pivot (scaffolding tools/ruview-mcp BFLD tool handlers) was stopped.
  ADR-124 work remains in the sibling agent's lane on this branch.

Added (in docs/user-guide.md):
- New ### BFLD — privacy-gated WiFi BFI sensing layer (ADR-118)
  subsection inside the "Home Assistant + Matter integration" chapter.
- Covers:
    * Three structural invariants (I1/I2/I3)
    * Minimal + worker-thread runnable example commands
    * Production publish lifecycle code snippet
      (publish_availability_online → publish_discovery →
       BfldPipelineHandle::spawn → handle.send)
    * 4 HA entities per node + class-2-only identity_risk note
    * Three operator HA blueprints (presence-lighting, motion-hvac,
      identity-risk-anomaly) with import path
    * Privacy class deployment matrix table (Raw / Derived / Anonymous /
      Restricted) with use cases
    * MQTT topic tree with all 7 documented topics
    * `mqtt` feature gate + rumqttc::connect_with_lwt LWT pre-config note
    * Pointers to crate README + research dossier + ADR-118 chain

Added (in v2/crates/wifi-densepose-bfld/tests/user_guide_section.rs):
- 8 named tests via include_str! validating the user-guide section:
    user_guide_documents_bfld_section_in_ha_chapter
    user_guide_bfld_section_names_three_structural_invariants
    user_guide_bfld_section_shows_both_runnable_examples
    user_guide_bfld_section_documents_publish_lifecycle (4 symbol checks)
    user_guide_bfld_section_documents_four_privacy_classes
    user_guide_bfld_section_lists_three_operator_blueprints
    user_guide_bfld_section_documents_mqtt_topic_tree (3 topic checks)
    user_guide_bfld_section_points_at_companion_artifacts

ADR-124 status (iter step 0 sibling check):
- docs/adr/ADR-124-rvagent-mcp-ruvector-npm-integration.md present.
  Sibling agent landed a follow-on commit 12586d31a touching
  ADR-124 ("RUVIEW-POLICY layer + Q4 cache resolution + multi-modal
  vision"). Scope continues to be orthogonal to BFLD core.

ACs progressed:
- Pre-merge checklist item #6 (CLAUDE.md) — user-guide.md updated.
  Operators encountering wifi-densepose for the first time and
  reading the canonical user guide now see the BFLD layer documented
  alongside HA + Matter, not as a separate document they have to
  hunt for.

Test config:
- cargo test --no-default-features → 101 passed (user_guide_section cfg-out)
- cargo test                       → 345 passed (337 + 8)

Out of scope (next iter target):
- Pre-merge checklist remaining: witness bundle regeneration (#8).
  External-resource-gated work (KIT BFId, Pi5/Nexmon) still skipped.

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-05-24 20:20:25 -04:00
rUv 249d6c327f
ADR-115: Home Assistant + Matter integration (#778)
Closes ADR-115's MQTT track (HA-DISCO + HA-MIND + HA-FABRIC scaffolding).

Headline:
- 21 entity kinds per node (11 raw + 10 semantic primitives)
- MQTT auto-discovery with HA conventions
- Matter Bridge scaffolding (SDK wiring deferred to v0.7.1 per ADR §9.10)
- Privacy mode strips biometrics at the wire, semantic primitives keep working
- 420+ lib tests, mosquitto-backed integration tests, property-based fuzzing
- 8 starter HA Blueprints + 3 Lovelace dashboards shipped

Tracking issue: #776
2026-05-23 16:13:28 -04:00
rUv 00a234eda8
ADR-110: ESP32-C6 firmware extension (#764)
Closes the firmware-side ADR-110 design at v0.7.0-esp32 after a 38-iter /loop SOTA sprint.

Headline (bench, COM9+COM12 ESP32-C6):
- 99.56% cross-board RX, 104.1 µs smoothed offset stdev (≤100 µs §2.4 target met)
- 3.95× EMA suppression, 1.4 ppm crystal skew preserved

4 firmware releases: v0.6.7 / v0.6.8 / v0.6.9 / v0.7.0-esp32.
42 ADR-110 unit tests, 1761 v2 workspace tests, full Firmware CI + QEMU green.
2026-05-23 15:34:48 -04:00
Rahul c00f45e296
fix(sensing): finish #611 NaN-panic audit — 7 more sites missed by #613 (#624)
#613 fixed adaptive_classifier.rs:94 (the IQR sort) and called the audit
done, but the grep used `partial_cmp(b).unwrap()` as a literal and missed
seven additional production sites that use comparator variants:

  adaptive_classifier.rs:205  AdaptiveModel::classify() argmax over softmax
                              probs — same per-frame hot path as #611.
                              NaN flows through normalise → logits → softmax
                              and still reaches this site even after the
                              IQR fix.
  adaptive_classifier.rs:480  train() argmax (training accuracy loop)
  adaptive_classifier.rs:500  train() per-class argmax
  main.rs:2446, 2449          count_persons_mincut variance source/sink select
  csi.rs:602, 605             count_persons_mincut variance source/sink select
                              (duplicate of main.rs logic in csi.rs)

For the variance-select sites, note that the *outer* `unwrap_or((0, &0))`
only catches an empty iterator — it cannot rescue a panic raised inside
the comparator. A single NaN in `variances[]` still aborts the process.

Same fix as #613: swap `.unwrap()` for `.unwrap_or(std::cmp::Ordering::Equal)`
inside the comparator closure. Pure behavioural change, no API surface.

Re-audit of the remaining `partial_cmp(...).unwrap()` matches in v2/:
they are all inside `#[cfg(test)]` / `#[test]` blocks (spectrogram.rs:269,
depth.rs:234, connectivity.rs:477, vital_signs.rs:737) where inputs are
controlled and panic-on-NaN is acceptable.
2026-05-19 10:02:08 -04:00
ruv 79cc2d7b22 Merge #491: feat(sensing-server): adaptive person count — RollingP95 + dedup_factor runtime API
Integrating @schwarztim's PR #491 into main on their behalf — their fork has
fallen too far behind for a clean rebase (the PR's commit graph dropped
silently during `git rebase origin/main`), so applying as a merge from the
fork head to preserve the diff cleanly.

What this lands:
- `RollingP95` adaptive normaliser for the person-count feature scaling.
  Streaming P95 over a 600-sample / ~30 s sliding window. Cold-start
  (<60 samples) falls back to the legacy denominators (variance/300,
  motion_band_power/250, spectral_power/500) so day-0 behaviour is
  preserved on every deployment.
- `RuntimeConfig` struct + `load_runtime_config` / `save_runtime_config`
  persisted to `data/config.json`. Exposes `dedup_factor` via REST so
  multi-node deployments can tune cluster-deduplication without a rebuild,
  including an auto-tune endpoint that derives optimal dedup from a known
  person count (calibration mode).
- `compute_person_score()` now takes &AppStateInner alongside &FeatureInfo
  so the adaptive denominators are reachable. All 3 call sites updated.
- New `AppStateInner` fields: `p95_variance`, `p95_motion_band_power`,
  `p95_spectral_power`, `dedup_factor`, `data_dir`.

Closes #491. Directly addresses:
- #499 (double skeletons, multi-node) — the slot-clustering problem this
  PR's adaptive normaliser was designed to fix
- #519 Bug 1 (ghost person detection on edge-tier 1 & 2 multi-node)
- #496 (person count over-reporting on single-room single-person)

Verified locally:
- cargo check -p wifi-densepose-sensing-server --no-default-features: 1.0s
- cargo test -p wifi-densepose-sensing-server --no-default-features --lib:
  233/233 passed in 25.0s

Co-authored-by: @schwarztim
Co-Authored-By: claude-flow <ruv@ruv.net>
2026-05-19 08:25:47 -04:00
rUv 281c4cb0ce
fix(firmware): OTA upload fails closed when no PSK in NVS (RuView#596 audit) (#623)
ota_check_auth() previously returned true when s_ota_psk[0] == '\0'
("permissive for dev"). A freshly-flashed node — or any node where
nobody had provisioned an OTA PSK yet — accepted attacker-controlled
firmware over plain HTTP on port 8032 from any host on the WiFi. No
Secure Boot V2, no signed-image verification, no transport encryption.
Single LAN call could brick or backdoor a node.

This was flagged in the deep security review of PR #596 but was a
PRE-EXISTING bug in main, not new code from that PR — so it stood as
a critical-severity production issue until this commit.

Fix:
- ota_check_auth() now returns false when no PSK is provisioned, with
  ESP_LOGW("OTA rejected: no PSK in NVS …") at the call site so the
  operator can diagnose the rejection from serial logs
- ota_update_init() ESP_LOGW message updated to surface the new posture
  at boot ("upload endpoint will REJECT all requests until provisioned")
- Doc comment on ota_check_auth() rewritten to make the contract
  explicit and reference the audit

The OTA HTTP server itself still starts even when no PSK is set. That
lets the operator run `provision.py --ota-psk <hex>` over USB-CDC to
write the NVS key without reflashing the firmware. The upload endpoint
just refuses every request in the meantime.

Breaking change for any deployment that depended on the unauthenticated
OTA path working out of the box. Documented in CHANGELOG under
[Unreleased] / Security so it's visible at the next release cut.

Fix-marker RuView#596-ota-fail-closed (scripts/fix-markers.json)
requires the new behaviour and forbids the old "permissive for dev"
fallback strings, so a future revert fails CI.
2026-05-18 08:56:07 -04:00
rUv b2e2e6d6fd
fix(sensing-server): WS broadcast emits effective_source() not hardcoded "esp32" (closes #618) (#621)
Reported by @ArnonEnbar with a complete reproduction.

broadcast_tick_task() re-emits the cached `latest_update` every tick so
pose WS clients keep getting data even when ESP32 pauses between
frames. The `source` field of that cached update was set to "esp32" at
the moment a fresh ESP32 frame was last decoded (main.rs:3885, :4136).

After the ESP32 loses power or network, no fresh frame is decoded —
the cached `latest_update` is still re-broadcast every tick with the
stale source: "esp32" baked in. UI's "Sensing" tab keeps showing
"LIVE — ESP32 HARDWARE Connected" with frozen vitals/features/
classification re-broadcast indefinitely. REST `/health` correctly
reports source: "esp32:offline" (via effective_source(), which checks
last_esp32_frame elapsed time against ESP32_OFFLINE_TIMEOUT=5s) — but
the WS broadcast path was the one consumer that didn't call it.

Fix: clone the cached update per tick, overwrite source with
s.effective_source(), then serialize and broadcast. UI now switches to
"esp32:offline" on the same 5s budget as the REST surface.

cargo build -p wifi-densepose-sensing-server --no-default-features:
17s, no errors (1 pre-existing unused-import warning unchanged).
2026-05-18 08:18:18 -04:00
rUv 72bbd256e7
fix(security): path-traversal guard on 5 sensing-server endpoints (closes #615) (#616)
Reported by @bannned-bit. Five endpoints in
v2/crates/wifi-densepose-sensing-server embedded user-controlled
identifiers in format!() paths with no sanitization:

  recording.rs       POST   /api/v1/recording/start       (session_name)
  recording.rs       GET    /api/v1/recording/download/:id (id)
  recording.rs       DELETE /api/v1/recording/delete/:id   (id)
  model_manager.rs   POST   /api/v1/models/load           (model_id)
  training_api.rs    load_recording_frames                (dataset_ids[])

Each unauthenticated caller could:
- READ arbitrary files via ../../etc/passwd, ../../.env, etc.
- WRITE attacker-controlled JSONL via recording/start
- LOAD attacker-controlled .rvf model files
- DELETE arbitrary files the server process can touch

New `path_safety` module exports `safe_id(&str) -> Result<&str, PathSafetyError>`
that enforces the rejection envelope BEFORE any user input reaches a
format!() that builds a path:

  - Allowed character set: [A-Za-z0-9._-]
  - Reject leading '.' (rules out '.', '..', '.env', hidden files)
  - Reject empty strings
  - Reject anything > 64 bytes
  - Reject all whitespace, path separators, null bytes, non-ASCII

Applied at all 5 sites. Errors return 400 Bad Request (download) /
status:"error" JSON (others) — not panics.

9 unit tests in path_safety::tests cover:
  - accepts simple alphanumeric / hyphen / underscore / dot
  - rejects empty, leading dot, path separators ('/', '\'),
    null byte, whitespace, shell specials, non-ASCII (including
    fullwidth slash U+FF0F), too-long, boundary at MAX_ID_LEN

  test result: ok. 9 passed; 0 failed
  cargo build -p wifi-densepose-sensing-server --no-default-features: 33s

Fix-marker RuView#615 in scripts/fix-markers.json prevents removing the
guard at any of the 5 call sites. CHANGELOG entry under [Unreleased] /
Security documents the patched endpoints and the rejection envelope.

Severity: critical per reporter — five remotely-reachable paths to read,
write, or delete arbitrary files. Hot per-request paths, not edge cases.
2026-05-17 19:59:20 -04:00
rUv 50131b2519
fix(verify): cross-platform deterministic proof — 6-decimal quantize + thread-pinning (closes #560) (#609)
* fix(verify): quantize features before SHA-256 for cross-platform hash stability (#560)

## The bug

archive/v1/data/proof/verify.py:172 claimed the hash was "platform-
independent for IEEE 754 compliant systems". That claim is empirically
false. scipy.fft's pocketfft uses SIMD vector kernels — AVX2/AVX-512 on
x86_64, NEON on Apple Silicon — that reorder vectorized FP operations
differently per build. IEEE 754 guarantees per-operation determinism,
not associativity under reordering, so two correct platforms produce
values that differ at ULP precision (~1e-14 at our magnitudes of 1-100).

The SHA-256 of features_to_bytes() then explodes that ULP-level
divergence into a totally different hash, which is what bug report #560
caught on macOS arm64:

| Platform | numpy/scipy | sha256 (legacy) |
|----------|-------------|-----------------|
| Windows (Intel AVX-512)             | 2.4.2 / 1.17.1 | 78b3fb… |
| ruvultra (Linux x86_64)             | 1.26.4 / 1.14.1 | 41dc56… |
| ruv-mac-mini (Apple Silicon NEON)   | 2.4.4 / 1.17.1 | 9b5e19… |

## The fix

features_to_bytes() now np.round(.., HASH_QUANTIZATION_DECIMALS=9)s each
array before packing as little-endian f64. That snaps the float bytes
to a single canonical representation across SIMD backends.

The 9-decimal precision is:
- ~5 orders of magnitude above the worst-case ULP drift observed in
  probe-fft-platform.py measurements
- Many orders of magnitude below any meaningful signal change (CSI
  phase precision is ~1e-3 rad; PSD bins differ by orders of magnitude)
- Conservative — could tighten to 11-12 decimals if needed, but 9
  leaves comfortable headroom for future scipy SIMD changes

## Probe-side verification

scripts/probe-fft-platform.py now emits BOTH sha256_raw (unrounded,
legacy) and sha256_quantized (new platform-invariant hash). Running it
on Windows here produced:

  sha256_raw       = 78b3fb4acb8cc18c3e870f92e29ee98143c7cac4767f2f71b0fc384a82b92f6e
  sha256_quantized = a587792c050cf697366b9bef4611050f9dc3af56624915ab2452c3c11362e79a
  quantization_decimals = 9

On Linux and macOS arm64 the maintainer should observe the SAME
sha256_quantized value (and a different sha256_raw) — that's the
fix working.

## What this PR does NOT do

The published archive/v1/data/proof/expected_features.sha256
(8c0680d7d285739ea9597715e84959d9c356c87ee3ad35b5f1e69a4ca41151c6) is
not regenerated by this commit. That step needs to run on a canonical
CI platform (likely the Linux x86_64 host used for releases) AFTER this
fix lands. The regeneration command is:

  python archive/v1/data/proof/verify.py --generate-hash

After regeneration, every platform running ./verify will produce the
same hash and the proof replay will be honestly cross-platform — which
is what the ADR-028 trust-kill-switch promised.

## Files

- archive/v1/data/proof/verify.py — add HASH_QUANTIZATION_DECIMALS=9
  constant, quantize in features_to_bytes(), correct the misleading
  "platform-independent" claim in the docstring
- scripts/probe-fft-platform.py — emit both raw and quantized hashes
- scripts/fix-markers.json — RuView#560 marker prevents removing the
  np.round() call without explicit intent
- CHANGELOG.md — Fixed entry under [Unreleased] documenting the change
  and flagging the expected_features.sha256 regeneration as a follow-up

Co-Authored-By: claude-flow <ruv@ruv.net>

* ci: fix verify-pipeline.yml working-directory from v1/ to archive/v1/

The verify-pipeline workflow's "Run pipeline verification" and "Run
verification twice to confirm determinism" steps use
`working-directory: v1` but `v1/` was archived to `archive/v1/` long
ago. The workflow fails before verify.py even runs:

  ##[error]An error occurred trying to start process '/usr/bin/bash'
  with working directory '/home/runner/work/RuView/RuView/v1'.
  No such file or directory

Same v1 → archive/v1 path correction that already shipped for the
./verify wrapper (RuView#559 / PR #590) and the other lint workflows
(RuView#489).

Required to make the determinism check actually run on PR #609 (the
quantize-before-hash work) — the canonical Linux hash needed for
expected_features.sha256 will fall out of the next CI log once this
fix lands.

* fix(proof): regenerate expected_features.sha256 with the quantized canonical hash

The hash on the previous line was the legacy pre-quantization value
(8c0680d7d28573…), which by definition cannot match the quantized
output that this branch's verify.py now produces. Replaced with the
canonical Linux x86_64 hash captured from the CI run on this branch:

    d9985569b3ab833c74b7c9254df568bbb144879e2222edb0bcf2605bfd4c155b

Source of truth: run 26005976495 / "Verify Pipeline Determinism (3.11)"
on Ubuntu 24.04, Python 3.11.15, exercising the full verify.py pipeline
on the 100 reference frames in archive/v1/data/proof/sample_csi_data.json.

Reproducibility expectation now changes:
- Linux x86_64 (canonical platform):       sha256 = d9985569…   ✓ this commit
- macOS arm64 / Apple Silicon NEON:        sha256 = d9985569…   should match
                                            after quantization
- Windows AMD64 (with pydantic-clean .env): sha256 = d9985569…   should match
                                            after quantization

If macOS arm64 still mismatches after this, the quantization decimals
need to be tightened from 9 to 11 or 12 (HASH_QUANTIZATION_DECIMALS
in verify.py); the headroom analysis in the original commit suggests
9 is safe but 9-decimal SIMD drift hasn't been measured in the
full-pipeline output yet (only in the probe).

Closes the maintainer-action-required item on PR #609.

* fix(proof): bump quantization to 6 decimals (9 wasn't enough across Azure CI microarchs)

Two back-to-back Ubuntu 24.04 / Python 3.11 / scipy 1.17 CI runs on
PR #609 landed on different Azure VM microarchitectures and produced
two different SHA-256s even after np.round(.., 9):

  Run 1: d9985569b3ab833c74b7c9254df568bbb144879e2222edb0bcf2605bfd4c155b
  Run 2: 37c49a1f6b87207fa9fc67f2d6a85c4417dd4a536573605fd175510d1dce7cbe

Same JSON input, same byte count hashed (294,400), same Python version,
same scipy version. The only variable is the underlying CPU pocketfft
SIMD kernel.

The full DSP pipeline (preprocess → biquad bandpass → FFT → PSD →
variance accumulation) amplifies the ~1e-14 raw FFT divergence by
several orders of magnitude — the actual drift at features_to_bytes()
input can reach 1e-7 or worse, which is well within the 1e-9 quantization
window I originally picked.

Bumping to 6 decimals = parts per million. ~6 orders of magnitude
headroom over observed pipeline-amplified ULP drift. Still far below
any meaningful signal change (CSI phase precision ~1e-3 rad). Kept the
probe constant in sync.

Will trigger CI on this branch immediately after push; the new
expected_features.sha256 will be regenerated from whichever microarch
the next CI run lands on, but should be stable across all subsequent
runs at 6-decimal quantization.

* chore(probe): keep HASH_QUANTIZATION_DECIMALS in sync with verify.py (now 6)

* fix(proof): regenerate expected_features.sha256 for 6-decimal quantization

* ci: pin thread count to 1 for proof verification (scipy.fft threading non-determinism)
2026-05-17 19:50:55 -04:00
rUv 50136c920d
fix(archive/v1/pose-service): call sanitize_phase, not sanitize (closes #612) (#614)
Reported by @bannned-bit. archive/v1/src/services/pose_service.py:223:

    sanitized_phase = self.phase_sanitizer.sanitize(phase_data)

PhaseSanitizer exposes the full-pipeline entry point as `sanitize_phase`
(unwrap_phase + remove_outliers + smooth_phase), not `sanitize`. The
shorter name doesn't exist on the class, so any path that reaches this
branch raises AttributeError mid-frame and crashes the pose service.

archive/v1/src/core/phase_sanitizer.py:266 is the canonical name:

    def sanitize_phase(self, phase_data: np.ndarray) -> np.ndarray:
        """Sanitize phase data through complete pipeline."""

One-line rename. No other call sites use the wrong name; verified with
grep -rn 'phase_sanitizer\.sanitize\b' archive/v1/src/.

This is v1 archived code, but the proof verify path still exercises it
(./verify reaches into archive/v1/src/), so the bug was a latent
regression risk for the trust-kill-switch flow.
2026-05-17 19:34:08 -04:00
rUv 3bd70f7910
fix(sensing): adaptive_classifier sorts with unwrap_or(Equal) — NaN panic (closes #611) (#613)
Reported by @bannned-bit. v2/crates/wifi-densepose-sensing-server/src/
adaptive_classifier.rs:94 did:

    sorted.sort_by(|a, b| a.partial_cmp(b).unwrap());

f64::partial_cmp returns None on NaN, so `.unwrap()` panics. CSI data
from real ESP32 hardware can produce NaN (silent DSP div-by-zero,
empty buffer, etc.), and this code path runs on every frame in the
classify() hot path — a single NaN frame kills the entire sensing
server process.

Fix swaps for unwrap_or(Ordering::Equal), matching the pattern the
same file already uses at lines 149-150 and 155 (those sites were
already NaN-safe; this site was an oversight).

Scoped audit: greped the v2/ tree for `partial_cmp(b).unwrap()`. The
other 3 hits are in #[cfg(test)] blocks (spectrogram.rs:269,
depth.rs:234, connectivity.rs:477) where panic-on-NaN is acceptable
because test inputs are controlled. Only adaptive_classifier.rs:94
was a production-path crash.

Severity: critical per reporter — runtime panic on real-world data.
Patch: 1-line behavioural change + comment.
2026-05-17 19:29:07 -04:00
rUv 6f5ac3aa5a
fix(ui): clamp deltaTime to 1ms in pose-renderer FPS calc (#519 Bug 2) (#610)
When two render frames land in the same performance.now() tick,
`currentTime - lastFrameTime === 0`, so `fps = 1000 / 0 = Infinity`,
and `averageFps = averageFps * 0.9 + Infinity * 0.1 = Infinity` poisons
the EMA forever after a single zero-dt tick. The UI then displays
"Infinity FPS" until reload.

Floor deltaTime at 1 ms before the division. That caps displayed FPS at
1000 (far above any real render rate so the cap is never observed in
practice) but keeps the EMA finite.

Reported in #519 ("Bug 2 — FPS shows Infinity") by @kapilsoni2013 on a
3-node ESP32-S3-WROOM multi-node setup with edge-tier 1 + 2.
2026-05-17 19:16:00 -04:00
rUv 1b155ad027
chore: remove empty stub crates wifi-densepose-{api,db,config} (closes #578) (#608)
Each of these crates was a single-line doc-comment placeholder:

  v2/crates/wifi-densepose-api/src/lib.rs:    //! WiFi-DensePose REST API (stub)
  v2/crates/wifi-densepose-db/src/lib.rs:     //! WiFi-DensePose database layer (stub)
  v2/crates/wifi-densepose-config/src/lib.rs: //! WiFi-DensePose configuration (stub)

with empty [dependencies] in their Cargo.toml and zero references from any
source file or Cargo.toml in the workspace (verified by `grep -rln
wifi-densepose-api/-db/-config` across `v2/`). They were reserved early for
an envisioned REST/database/config split that never materialised.

The functionality these would have provided is covered today by:
- REST/WS:  wifi-densepose-sensing-server (Axum)
- Config:   per-crate config + CLI args in sensing-server and desktop
- DB:       no persistent state; system is real-time

Removal prevents `cargo` from listing dead crates, shipping empty published
artifacts to crates.io, or wasting reviewer attention. If any of these names
is needed in the future, reintroduce them with a real implementation.

Per the issue reporter (@bannned-bit / Matad0r) #578 explicitly listed
"OR be removed from workspace members until implementation starts" as an
acceptable resolution.

Updated:
- `v2/Cargo.toml`: drop the three members (with inline comment explaining why)
- `v2/Cargo.lock`: regenerated by cargo check
- `CLAUDE.md`: drop the three rows from the crate table and the publishing
  order list
- `CHANGELOG.md`: add an `[Unreleased] / Removed` entry

Verified:
- `cd v2 && cargo check --workspace --no-default-features` -> finished
  in 48s, no errors (warnings unchanged)
2026-05-17 18:50:57 -04:00
Timothy Schwarz 8b297dd706
fix(sensing-server): handle WebSocket Lagged + add ping keepalive (#484)
Root cause: broadcast channel Lagged error caused instant disconnect
when clients fell behind 256 frames (10Hz * 50-200KB = easy to lag).
Client reconnects, immediately lags again, rapid cycling ensues.

Sensing handler: Lagged error now continues (skips missed frames)
instead of breaking. Added 30s ping interval for proxy keepalive.
Pose handler: same Lagged handling + Pong match arm.

CHANGELOG updated under Unreleased/Fixed.

Co-authored-by: Deploy Bot <deploy@example.com>
2026-05-17 17:57:02 -04:00
ruv ce33042226 docs(changelog): ADR-099 introspection tap — entry under [Unreleased]
Lists the new `/ws/introspection` + `/api/v1/introspection/snapshot`
endpoints, the empirical baseline (0.041 ms p99 update, 5-frame shape
match on 1-D L1 stand-in), and the honest D8 amendment.

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-05-13 23:37:50 -04:00
ruv c641fc44ae feat(docker+sensing-server): refresh Docker publish + opt-in bearer-token API auth
Closes #520, #514, #443.

## #520 / #514 — stale Docker image, missing UI assets

`ruvnet/wifi-densepose:latest` was published before `ui/observatory*` and
`ui/pose-fusion*` were added; users see /app/ui missing those files and the
v0.6+ packet format doesn't reach the server. Two fixes:

1. `docker/Dockerfile.rust` now `RUN`s a build-time guard after `COPY ui/`
   that fails the build if `index.html` / `observatory.html` / `pose-fusion.html`
   / `viz.html` (or the `observatory/` / `pose-fusion/` / `components/` /
   `services/` directories) are missing, plus an exec-bit check on
   `/app/sensing-server`. A stale image can never be silently produced again.

2. New `.github/workflows/sensing-server-docker.yml` rebuilds + pushes on
   every change to the Dockerfile, the server crate, the signal/vitals/
   wifiscan crates, the workspace manifests, the `ui/` tree, or itself —
   plus `v*` tags and manual dispatch. Pushes to both `docker.io/ruvnet/
   wifi-densepose` AND `ghcr.io/ruvnet/wifi-densepose` with `latest` +
   `vX.Y.Z` + `sha-<short>` tags, then post-push smoke-tests the artifact:
   /health, /api/v1/info, the observatory + pose-fusion HTML, AND the
   bearer-auth path (no token → 401, wrong → 401, correct → 200). Uses the
   `DOCKERHUB_USERNAME`/`DOCKERHUB_TOKEN` repo secrets; ghcr.io rides on
   the workflow's GITHUB_TOKEN.

## #443 — sensing-server REST API auth model

QE security audit raised that 40+ /api/v1/* routes have no auth layer with
a default `0.0.0.0` bind. New `wifi_densepose_sensing_server::bearer_auth`
module + middleware:

  - Env-var-gated: `RUVIEW_API_TOKEN` unset/empty ⇒ middleware is a no-op
    (current LAN-mode behaviour preserved — **no default change**); set ⇒
    every `/api/v1/*` request must carry `Authorization: Bearer <token>`
    or the server returns 401.
  - Constant-time byte compare via local `ct_eq` (no new dep).
  - `/health*`, `/ws/sensing`, and `/ui/*` are intentionally never gated
    (orchestrator probes + local browsers).
  - Startup logs which mode is active and warns when auth is ON with a
    `0.0.0.0` bind.
  - 8 unit tests on the middleware via `tower::ServiceExt::oneshot`
    (sensing-server lib tests 191 → 199, 0 failures).

Verified locally: `cargo build --workspace --no-default-features` ✓,
`cargo test -p wifi-densepose-sensing-server --no-default-features` ✓.

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-05-13 08:52:25 -04:00
ruv d0b64bdeb6 chore(rvcsi): drop inline v2/crates/rvcsi-* — consume the vendor/rvcsi submodule / crates.io instead
rvCSI now lives in its own repo (github.com/ruvnet/rvcsi), vendored here as
`vendor/rvcsi` (PR #543) and published to crates.io as `rvcsi-* 0.3.x` /
to npm as `@ruv/rvcsi`. The inline copies in `v2/crates/rvcsi-*` (added in
#542) were a duplicate; this removes them and re-points the docs.

- `git rm -r v2/crates/rvcsi-{core,dsp,events,adapter-file,adapter-nexmon,ruvector,runtime,node,cli}`
- `v2/Cargo.toml`: remove the 9 from `members` (note: `vendor/rvcsi/Cargo.toml`
  is its own workspace — depend on the published crates or the submodule paths,
  not as v2 workspace members).
- `CLAUDE.md`: the 9 crate-table rows collapse to one `vendor/rvcsi` row.
- `README.md` docs table: rvCSI entry points at the standalone repo + notes the
  submodule / crates.io / npm / plugin.
- `CHANGELOG.md`: `[Unreleased]` entry.

The ADRs (ADR-095, ADR-096), PRD, and DDD model stay in `docs/` as the design
record of the incubation. `cargo build --workspace --no-default-features` and
`cargo test --workspace --no-default-features` stay green.

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-05-12 23:00:23 -04:00
ruv deb561bf9c fix(rvcsi): scale-relative baseline-drift thresholds + ESP32 end-to-end validation
BaselineDriftDetector compared `mean_amplitude` against its EWMA baseline
with *absolute* thresholds (anomaly 1.0, drift 0.15). Fine for the synthetic
unit tests (amplitudes ~1.0), but raw ESP32 CSI is int8 I/Q with amplitudes
up to ~128, so window-to-window RMS distance is routinely 5-50 >> 1.0 and
AnomalyDetected fired on ~96% of windows (319/331 on a real node-1 capture).

Drift is now `||current - baseline||2 / ||baseline||2` (a fraction, with an
eps floor that falls back to absolute for a degenerate near-zero baseline),
so one tuning is valid across raw-int8 ESP32, int16-scaled Nexmon, and
baseline-subtracted streams. AnomalyDetected drops to 40/331 on the same
data; the existing detector tests still pass (their explicit configs are
valid relative thresholds too); added baseline_drift_is_scale_invariant_
no_anomaly_storm. rvcsi-events 18 -> 19 tests; 162 rvcsi tests, 0 failures,
clippy-clean.

Surfaced by an end-to-end test against real ESP32 CSI on COM7: the device
(ESP32-S3, node 1, ADR-018 firmware, WiFi "ruv.net" ch5 RSSI -39, CSI cb
only because nothing listens at .156). rvcsi has no ESP32 adapter yet, so a
7,000-frame node-1 recording was transcoded to .rvcsi via the new
scripts/esp32_jsonl_to_rvcsi.py (stand-in for `record --source esp32-jsonl`)
and run through `rvcsi inspect`/`replay`/`calibrate`/`events` end-to-end.

ADR-095 D13 and ADR-096 sections 2.1/5 updated; CHANGELOG entry added;
rvcsi-adapter-esp32 (live serial/UDP source) noted as a follow-up.

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-05-12 22:19:15 -04:00
Claude d40411e6d7
feat(rvcsi): Raspberry Pi 5 (BCM43455c0) + Nexmon chip registry
Adds first-class support for the Raspberry Pi 5's WiFi chip (CYW43455 /
BCM43455c0 — the same 802.11ac wireless as the Pi 4 / Pi 3B+ / Pi 400, and the
chip with the most mature nexmon_csi support), plus a registry of the other
Nexmon-supported Broadcom/Cypress chips.

rvcsi-adapter-nexmon — new `chips.rs`:
- `NexmonChip` (Bcm43455c0, Bcm43436b0, Bcm4366c0, Bcm4375b1, Bcm4358, Bcm4339,
  Unknown{chip_ver}) + `RaspberryPiModel` (Pi5/Pi4/Pi400/Pi3BPlus/PiZero2W/
  PiZeroW) — Pi5/Pi4/Pi400/Pi3B+ → Bcm43455c0; PiZero2W → Bcm43436b0.
- `nexmon_adapter_profile(chip)` / `raspberry_pi_profile(model)` build the
  per-device `AdapterProfile` (channels: 2.4 GHz 1-13 + 5 GHz UNII for dual-band;
  bandwidths 20/40/80[/160]; expected subcarrier counts 64/128/256[/512]) that
  `validate_frame` bounds CSI frames against.
- `NexmonChip::from_chip_ver` (0x4345 → Bcm43455c0, 0x4339, 0x4358, 0x4366,
  0x4375 — best-effort; the raw `chip_ver` is always preserved) and `from_slug`
  / `RaspberryPiModel::from_slug` ("pi5", "raspberry pi 4", "bcm43455c0", ...).
- `NexmonCsiHeader::chip()`; `NexmonPcapAdapter` auto-detects the chip from the
  packets' `chip_ver` and uses the matching profile, overridable via
  `.with_chip(NexmonChip)` / `.with_pi_model(RaspberryPiModel)`; `.detected_chip()`.

rvcsi-runtime: `decode_nexmon_pcap_for(.., chip_spec)` (validate against a chip /
Pi model, drop non-conforming) + `nexmon_profile_for(spec)`; `NexmonPcapSummary`
gains `chip_names` + `detected_chip`; `CaptureSummary` gains `chip`.

rvcsi-cli: `record --source nexmon-pcap --chip pi5`; new `nexmon-chips`
subcommand (lists chips + Pi models, human or `--json`); `inspect-nexmon` and
`inspect` now print the resolved chip.

rvcsi-node (napi-rs): `nexmonDecodePcap` gains an optional `chip` arg;
`nexmonChipName(chipVer)`, `nexmonProfile(spec)`, `nexmonChips()`. @ruv/rvcsi
SDK + `.d.ts` updated (AdapterProfile / NexmonChipsListing interfaces, the new
fns, `chip` on CaptureSummary, `chip_names`/`detected_chip` on NexmonPcapSummary).

168 rvcsi tests pass (adapter-nexmon 22→28, cli 9→10), 0 failures, clippy-clean.
The synthetic test captures now stamp chip_ver = 0x4345 (the BCM4345 family chip
ID), so the chip-detection happy path is exercised end to end.
ADR-096, CHANGELOG, README, CLAUDE.md updated.

https://claude.ai/code/session_01CdYAPvRTjcch6YrYf42n1z
2026-05-13 01:32:27 +00:00
Claude b116a99481
feat(rvcsi): real nexmon_csi UDP/PCAP fidelity — chanspec decode, libpcap reader, NexmonPcapAdapter
Raises the Nexmon path from a normalized record format to parsing what the
patched Broadcom firmware actually emits, end to end.

napi-c shim (ABI 1.0 -> 1.1, additive):
- rvcsi_nx_csi_udp_header / rvcsi_nx_csi_udp_decode — parse the real nexmon_csi
  UDP payload: the 18-byte header (magic 0x1111, rssi int8, fctl, src_mac[6],
  seq_cnt, core/spatial-stream, Broadcom chanspec, chip_ver) + nsub complex CSI
  samples (modern int16 LE I/Q export — what CSIKit/csireader.py read for the
  BCM43455c0 / 4358 / 4366c0; nsub = (len-18)/4). rvcsi_nx_csi_udp_write to
  synthesize payloads for tests. rvcsi_nx_decode_chanspec — d11ac chanspec ->
  channel (chanspec & 0xff) / bandwidth (bits [13:11], cross-checked against the
  FFT size) / band (bits [15:14], cross-checked against the channel number).
  Still allocation-free, bounds-checked, structured errors, never panics.
- ffi.rs wraps it: decode_chanspec / parse_nexmon_udp_header / decode_nexmon_udp
  / encode_nexmon_udp + DecodedChanspec / NexmonCsiHeader; every unsafe block
  documented; the ABI guard now expects 1.1.

rvcsi-adapter-nexmon:
- pcap.rs — a dependency-free classic-libpcap reader (all four byte-order /
  timestamp-resolution magics; Ethernet / raw-IPv4 / Linux-SLL link types;
  tolerates a truncated final record; pcapng is a follow-up) + extract_udp_payload
  + a synthetic_udp_pcap / synthetic_nexmon_pcap test/example generator.
- NexmonPcapAdapter (a CsiSource) — reads the CSI UDP packets out of a
  `tcpdump -i wlan0 dst port 5500 -w csi.pcap` capture, decodes each via the C
  shim, stamps the frame timestamp from the pcap packet time; non-CSI packets
  counted as "skipped" in health.

rvcsi-runtime: decode_nexmon_pcap, summarize_nexmon_pcap (+ NexmonPcapSummary:
link type, CSI frame count, channels, bandwidths, subcarrier counts, chip
versions, RSSI range, time span), CaptureRuntime::open_nexmon_pcap[_bytes].

rvcsi-node (napi-rs): nexmonDecodePcap, inspectNexmonPcap, decodeChanspec,
RvcsiRuntime.openNexmonPcap. @ruv/rvcsi SDK + .d.ts updated (NexmonPcapSummary,
DecodedChanspec). rvcsi-cli: `record --source nexmon-pcap`, `inspect-nexmon`,
`decode-chanspec`.

161 rvcsi tests pass (adapter-nexmon 9->22), 0 failures, clippy-clean.
ADR-096 §2.2/§2.3/§5, CHANGELOG, CLAUDE.md updated.

https://claude.ai/code/session_01CdYAPvRTjcch6YrYf42n1z
2026-05-13 01:15:22 +00:00
Claude 684a064816
docs(rvcsi): update CHANGELOG, CLAUDE.md crate table, README docs index
- CHANGELOG: expand the rvCSI entry to cover all 9 crates (incl. rvcsi-runtime
  and the @ruv/rvcsi npm SDK), the napi-c / napi-rs seams, and the 142-test /
  clippy-clean status; note the daemon + MCP server are follow-ups.
- CLAUDE.md: add the 9 `rvcsi-*` crates to the Key Rust Crates table.
- README: add an rvCSI row to the docs index; bump the ADR count (79→96) and
  DDD-model count (7→8).

https://claude.ai/code/session_01CdYAPvRTjcch6YrYf42n1z
2026-05-13 00:18:56 +00:00
Claude 94745242a8
feat(rvcsi): rvcsi-dsp (DSP stages + SignalPipeline) + ADR-096 (FFI/crate layout)
- rvcsi-dsp — reusable signal-processing stages (ADR-095 FR4): mean/variance/
  std_dev/median, remove_dc_offset, unwrap_phase, moving_average, ewma,
  hampel_filter(_count), short_window_variance, subtract_baseline + DspError;
  scalar features motion_energy(_series), presence_score (logistic, ≈0.5 at
  threshold), confidence_score, breathing_band_estimate (heuristic, FFT-free);
  SignalPipeline (hampel → smooth → DC-remove → baseline-subtract → unwrap,
  non-destructive of validation state) + learn_baseline. 28 tests, clippy-clean,
  forbid(unsafe_code), no heavy deps.
- docs/adr/ADR-096-rvcsi-ffi-crate-layout.md — the implementation ADR: 8-crate
  topology, the napi-c shim record format + contract, the napi-rs Node surface,
  build/test invariants, alternatives. Indexed in docs/adr/README.md.
- CHANGELOG: rvCSI entry updated to cover the implementation crates.

https://claude.ai/code/session_01CdYAPvRTjcch6YrYf42n1z
2026-05-13 00:00:40 +00:00
Claude d98b7e3f65
docs: rvCSI edge RF sensing platform — PRD, ADR-095, DDD domain model
Adds design documentation for rvCSI, a Rust-first / TypeScript-accessible /
hardware-abstracted edge RF sensing runtime that normalizes WiFi CSI from
Nexmon, ESP32, Intel, Atheros, file and replay sources into one validated
CsiFrame schema, runs reusable DSP, emits typed confidence-scored events,
and bridges to RuVector RF memory, an MCP tool server and a TS SDK.

- docs/prd/rvcsi-platform-prd.md — purpose, users, success criteria,
  FR1-FR10, NFRs (safety/perf/reliability/privacy/security/portability),
  system architecture, runtime components, reference layout, data model
- docs/adr/ADR-095-rvcsi-edge-rf-sensing-platform.md — the 15 architectural
  decisions (Rust core, C-at-the-boundary, TS SDK via napi-rs, normalized
  schema, validate-before-FFI, CSI-as-temporal-delta, RuVector as RF memory,
  replayability, detection != decision, local-first, read-first/write-gated
  MCP, mandatory quality scoring, versioned calibration, plugin adapters)
- docs/ddd/rvcsi-domain-model.md — 7 bounded contexts (Capture, Validation,
  Signal, Calibration, Event, Memory, Agent) with aggregates, invariants,
  context map, data model and domain services
- indexed in docs/adr/README.md and docs/ddd/README.md; CHANGELOG entry

Design-only; no code or crates added yet.

https://claude.ai/code/session_01CdYAPvRTjcch6YrYf42n1z
2026-05-12 23:15:10 +00:00
rUv c604ca1150
feat(train): TrainingConfig subcarrier-layout presets + real MmFiDataset loader test (#537)
Closes the remaining doable items from the 2026-05-11 training-pipeline audit:

#6 (CSI format default = 56-sc / 1 NIC) + #7 (multi-band 168-sc mesh not in
config): new `TrainingConfig::for_subcarriers(native, target)` plus named
presets `mmfi()` (114→56), `ht40_192()` (≈192-sc ESP32 HT40 → 56) and
`multiband_168()` (168-sc ADR-078 multi-band mesh → 56). Non-MM-Fi CSI shapes
are now first-class instead of requiring manual `native_subcarriers` /
`num_subcarriers` overrides; the field docs list the supported source counts
and the multi-NIC mapping (a 2–3-node mesh currently rides on `n_rx` until a
dedicated node dimension lands). Model input width stays `num_subcarriers`; the
presets only vary the resampling input.

#4 (proof.rs uses synthetic data): reframed — a deterministic proof *must* use
a reproducible source, so `verify-training` correctly stays on
`SyntheticCsiDataset`. The real gap was that nothing exercised the on-disk
`MmFiDataset` path. New `tests/test_real_loader.rs` writes synthetic CSI to
`.npy` files in the `MmFiDataset::discover` layout, loads it back, and checks
the resulting `CsiSample` — covering the no-interp case, the
subcarrier-interpolation branch, and the empty-root case. Adds `ndarray` /
`ndarray-npy` as dev-deps for the fixture writing.

cargo check + cargo test -p wifi-densepose-train --no-default-features: clean,
all existing tests green, 3 new loader tests + the updated config doctest pass.
Purely additive — no model-shape change, no tch-module change.
2026-05-11 23:49:00 -04:00
rUv eaedfded6f
fix(train): wire wifi-densepose-signal into the pipeline; correct MODEL_CARD env-sensor claim (#536)
Addresses three findings from the 2026-05-11 training-pipeline audit:

#1/#2 — `wifi-densepose-signal` was a phantom dependency of `wifi-densepose-train`
(listed in Cargo.toml, never imported), and vitals/CSI signal features were
absent from the pipeline. New module `wifi_densepose_train::signal_features`:
`extract_signal_features(&Array4<f32>, &Array4<f32>) -> Array1<f32>` (and the
convenience method `CsiSample::signal_features()`) runs a windowed observation's
centre frame through `wifi_densepose_signal::features::FeatureExtractor`,
producing a fixed-length (FEATURE_LEN=12) amplitude / phase-coherence / PSD
feature vector — the hook for a future vitals / multi-task supervision head
(breathing- and heart-rate-band power are read off the PSD summary). The vector
is produced on demand and is not yet fed back into the loss; wiring it as a
training target is the documented follow-up. `wifi-densepose-signal` is now an
actually-used dependency. 5 new tests (2 unit in signal_features.rs, 3
integration in tests/test_dataset.rs); existing wifi-densepose-train tests
unchanged and green.

#3 — `docs/huggingface/MODEL_CARD.md` presented PIR/BME280 environmental-sensor
weak-label fine-tuning as a current capability; there is no env-sensor
ingestion in the training pipeline. Marked that path as planned/not-implemented
in the training-steps list and the data-provenance section.

(#5 — README's "92.9% PCK@20" overclaim — fixed separately in PR #535.)

CHANGELOG updated.
2026-05-11 23:40:55 -04:00
rUv bd4f81749a
fix(docs): correct unsubstantiated 92.9% PCK@20 camera-supervised claim (#535)
The README claimed "92.9% PCK@20" for camera-supervised pose training. That
figure appears nowhere in ADR-079 (the source ADR) and is ~2.6x the ADR's own
success target (">35% PCK@20"). ADR-079 phases P7 (data collection), P8
(training + evaluation on real paired data) and P9 (cross-room LoRA) are all
still `Pending`, so no measured camera-supervised PCK@20 has been published.

- README: replace the two "92.9% PCK@20" claims with the proxy-supervised
  baseline (~2.5%) and the ADR-079 target (35%+), noting the eval phases are
  pending.
- CHANGELOG: add an Unreleased entry.

Surfaced by the PowerPlatePulse training-pipeline audit (2026-05-11). Six other
audit findings (vitals features absent from training; wifi-densepose-signal
ghost dep; PIR/BME280 in MODEL_CARD unimplemented; proof.rs uses
SyntheticCsiDataset only; 56-subcarrier/1-NIC default; multi-band 168-subcarrier
mesh not in training config) are listed in the PR body for follow-up.
2026-05-11 23:40:52 -04:00
Deploy Bot ce7983eb43 feat(sensing-server): adaptive person count — RollingP95 + dedup_factor runtime API
RollingP95 adaptive normalizer (ADR-044 §5.2):
- Streaming P95 estimator (600-sample / ~30 s window) replaces fixed-scale
  denominators (variance/300, motion/250, spectral/500) that saturated against
  live ESP32 values, collapsing dynamic range to zero.
- Cold-start (<60 samples) falls back to legacy denominators — day-0 behaviour
  is preserved.
- Three new fields on AppStateInner: p95_variance, p95_motion_band_power,
  p95_spectral_power (all RollingP95::new(600, 60)).
- compute_person_score() refactored to accept &AppStateInner; all three call
  sites (wifi, wifi-fallback, simulated) updated.
- 5 unit tests in rolling_p95_tests module.

dedup_factor runtime API (ADR-044 §5.3):
- New field dedup_factor: f64 (default 3.0) on AppStateInner.
- fuse_or_fallback() gains dedup_factor param; fallback switches from max() to
  sum/dedup_factor (ceiling), matching the fork's sum-based aggregation.
- RuntimeConfig struct + load/save_runtime_config() for data/config.json
  persistence across restarts.
- Three new REST endpoints:
    GET  /api/v1/config/dedup-factor
    POST /api/v1/config/dedup-factor
    POST /api/v1/config/ground-truth (auto-tune from known person count)

Explicitly NOT included:
- lambda=5.0 (upstream keeps its 0.1 default — deployment-specific tuning)
- CC intensity threshold 0.3 and min-cluster-size 4 hardcodes
- max_cc_size filter removal
2026-04-28 15:32:34 -04:00
rUv f06d0c6ab5
fix(firmware): SPI cache crash fix + node_id/filter_mac defensive copies + esptool v5 (rebased #397)
* fix(firmware): move defensive node_id capture before wifi_init_sta()

The original defensive copy in csi_collector_init() (line 172 of main.c)
runs AFTER wifi_init_sta() (line 147), which on some ESP32-S3 devices
corrupts g_nvs_config.node_id back to the Kconfig default of 1.

Reproduced on device 80:b5:4e:c1:be:b8 (ESP32-S3 QFN56 rev v0.2):
  - NVS provisioned with node_id=5
  - Release firmware (no fix): seed receives node_id=1 (clobbered)
  - This patch: seed receives node_id=5 (correct)

Changes:
  - Add csi_collector_set_node_id() called from main.c immediately
    after nvs_config_load(), before wifi_init_sta() runs
  - csi_collector_init() now detects and logs the clobber if early
    capture disagrees with current g_nvs_config value
  - Fallback path preserved: if set_node_id() is never called,
    init() still captures from g_nvs_config (backwards compatible)

Co-Authored-By: claude-flow <ruv@ruv.net>

* fix(firmware): defensive copy of filter_mac to prevent callback crash

The CSI callback reads g_nvs_config.filter_mac_set and filter_mac on
every invocation (100-500 Hz). If wifi_init_sta() corrupts g_nvs_config
(same root cause as the node_id clobber), the callback reads garbage
from the struct, leading to Core 0 LoadProhibited panic after ~2400
callbacks (~70 seconds of operation).

Extends the early-capture pattern from the node_id fix to also copy
filter_mac_set and filter_mac into module-local statics before WiFi
init runs. Adds canary logging to detect filter_mac corruption.

Observed on device 80:b5:4e:c1:be:b8 via serial:
  CSI cb #2400 → Guru Meditation Error: Core 0 panic'ed (LoadProhibited)
  → TG0WDT_SYS_RST → reboot → crash again at ~2900 callbacks

Refs #232 #375 #385 #386 #390

Co-Authored-By: Ruflo & AQE

* fix(firmware): MGMT-only promiscuous filter to prevent SPI cache crash

The WiFi driver's wDev_ProcessFiq interrupt handler crashes with
LoadProhibited in cache_ll_l1_resume_icache when promiscuous mode
captures MGMT+DATA frames (100-500 interrupts/sec). The high interrupt
rate races with SPI flash cache operations, corrupting cache state.

Changes:
- Promiscuous filter: MGMT+DATA → MGMT-only (~10 Hz beacons)
- CSI config: disable htltf_en and stbc_htltf2_en (LLTF-only)

LLTF provides 64 subcarriers (HT20) — sufficient for presence,
breathing, and fall detection. The 10 Hz beacon rate eliminates
the SPI flash cache contention that caused the crash.

Verified on device 80:b5:4e:c1:be:b8:
- Before: LoadProhibited crash at ~1600-2400 callbacks (every ~70s)
- After: 2700+ callbacks over 4.7 minutes, zero crashes

Backtrace decode confirmed crash in ESP-IDF closed-source WiFi blob:
  _xt_lowint1 → wDev_ProcessFiq → spi_flash_restore_cache
  → cache_ll_l1_resume_icache → EXCVADDR=0x00000004 (NULL deref)

Co-Authored-By: Ruflo & AQE

* fix(provision): write-flash → write_flash for esptool v5 compat

esptool v5+ rejects hyphenated subcommands. The provision script
used 'write-flash' which fails with "invalid choice". Changed to
'write_flash' (underscore) which works with both old and new esptool.

Co-Authored-By: Ruflo & AQE

* fix(firmware): 50 Hz callback rate gate + sdkconfig extra IRAM opt

- Add early rate gate in wifi_csi_callback at 50 Hz (defense-in-depth,
  does not prevent crash alone but reduces callback execution time)
- Add null-data injection timer infrastructure (disabled — TX adds
  interrupt pressure that triggers the SPI cache crash, RuView#396)
- sdkconfig.defaults: add CONFIG_ESP_WIFI_EXTRA_IRAM_OPT=y
- sdkconfig.defaults: document SPIRAM XIP attempt (crashes differently)

Co-Authored-By: Ruflo & AQE

* fix(firmware): address PR #397 review feedback

Applies @ruvnet's five review requests on PR #397 (RuView#397 comment
4289417527):

1. **Inline comment on `provision.py` `write_flash`** — ESP-IDF v5.4
   bundles esptool 4.10.0 (underscore-only). #391's hyphen swap broke
   the documented venv flow; kept the underscore form and added a
   three-line comment warning future maintainers not to "re-fix" it.

2. **Correct `edge_processing.c` sample_rate** (blocking) — changed
   hard-coded `20.0f` → `10.0f` at line 718 so
   `estimate_bpm_zero_crossing()` matches the MGMT-only CSI rate.
   Without this, breathing and heart-rate reports were 2× the true
   value. Added a comment tying the constant to the callback rate gate.

3. **Removed disabled probe-injection infrastructure** — dropped the
   forward declaration, the `CSI_PROBE_INTERVAL_MS` define, six static
   variables (`s_probe_timer`, `s_probe_tx_count`, `s_probe_tx_fail`,
   `s_ap_bssid`, `s_ap_bssid_known`), and three functions
   (`csi_send_probe_request`, `probe_timer_cb`,
   `csi_collector_start_probe_timer`). None were reachable.
   `csi_inject_ndp_frame()` reverted to the original ADR-029 stub.
   Can be revived from this commit's parent if needed.

4. **Cleaned `sdkconfig.defaults`** — removed the SPIRAM prose and
   commented-out `# CONFIG_SPIRAM is not set` line. Kept only the live
   `CONFIG_ESP_WIFI_EXTRA_IRAM_OPT=y` with a concise rationale.

5. **Bumped firmware version 0.6.1 → 0.6.2** and added four
   `[Unreleased]` CHANGELOG entries covering the SPI cache crash fix,
   the `filter_mac` / `node_id` clobber defense, the sample-rate
   correction, and the `write_flash` command-form revert.

Net: +39 / -128 across six files.

Validation in this devcontainer:
- Static sanity on modified C files: braces balance (csi_collector.c
  59/59; edge_processing.c 96/96), zero dangling references to removed
  probe-injection symbols.
- Rust workspace tests and Python proof not executed here — cargo not
  installed and pip blocked by PEP 668. Deferring hardware build +
  flash + miniterm verification to @ruvnet's COM7 per his offer in
  the review comment.

Co-Authored-By: claude-flow <ruv@ruv.net>

---------

Co-authored-by: Dragan Spiridonov <spiridonovdragan@gmail.com>
2026-04-28 08:41:49 -04:00
rUv 7f5a692632
feat(nvsim): full simulator stack — Rust crate, dashboard, server, App Store, Ghost Murmur [ADR-089/090/091/092/093]
Squashed merge of feat/nvsim-pipeline-simulator (29 commits).

## Shipped

- ADR-089 nvsim crate (Accepted) — 50/50 tests, ~4.5 M samples/s, pinned witness cc8de9b01b0ff5bd…
- ADR-092 dashboard implementation (Implemented) — 8/12 §11 gates , 4/12 ⚠ (external infra)
- ADR-093 dashboard gap analysis (Implemented) — 21/21 catalogued gaps closed
- Plus ADR-090 (proposed conditional) and ADR-091 (proposed research-only)

## Live deploy
https://ruvnet.github.io/RuView/nvsim/

## Infra

- nvsim-server Dockerfile + GHCR publish workflow (.github/workflows/nvsim-server-docker.yml)
- axe-core + Playwright cross-browser CI (.github/workflows/dashboard-a11y.yml)
- gh-pages auto-deploy workflow already in place (preserves observatory + pose-fusion siblings)

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-04-27 12:41:01 -04:00
rUv 81cc241b9e
chore(repo): move v1/ → archive/v1/ + add archive/README.md (#430)
The Rust port at v2/ has been the primary codebase since the rename
in #427. The Python implementation at v1/ is no longer the active
target; the only load-bearing path is the deterministic proof bundle
at v1/data/proof/ (per ADR-011 / ADR-028 witness verification).

Move the whole Python tree into archive/v1/ and document the policy
in archive/README.md: no new features, bug fixes only when they affect
a still-load-bearing path (currently just the proof), CI continues to
verify the proof on every push and PR.

Path references updated in 26 files via path-pattern sed (only
matches v1/<known-child> patterns, never bare v1 or API URLs like
/api/v1/). Two double-prefix typos (archive/archive/v1/) caught and
hand-fixed in verify-pipeline.yml and ADR-011.

Validated:
- Python proof verify.py imports cleanly at archive/v1/data/proof/
  (numpy/scipy still required; CI installs requirements-lock.txt
  from archive/v1/ now)
- cargo test --workspace --no-default-features → 1,539 passed,
  0 failed, 8 ignored (unaffected by Python tree relocation)
- ESP32-S3 on COM7 untouched (no firmware paths changed)

After-merge: contributors should re-run any local `python v1/...`
commands as `python archive/v1/...` (CLAUDE.md and CHANGELOG already
updated).
2026-04-25 23:07:52 -04:00
rUv 7f201bdf6f
fix(tracker): exclude Lost tracks from bridge output (#420, ADR-082) (#426)
`tracker_bridge::tracker_to_person_detections` documented itself as filtering
to `is_alive()` but never actually filtered — it forwarded every non-Terminated
track to the WebSocket stream. With 3 ESP32-S3 nodes × ~10 Hz CSI, transient
detections that fell outside the Mahalanobis gate created a steady stream of
new Tentative tracks that aged through Active and into Lost. Lost tracks are
kept in the tracker for `reid_window` (~3 s) so re-identification can match
them when a similar detection reappears, but they are NOT currently observed
and must not render as live skeletons. Up to ~90 ghost skeletons could
accumulate at any moment, hence the 22-24 phantoms users saw while
`estimated_persons` correctly reported 1.

Add `PoseTracker::confirmed_tracks()` that returns only `Tentative ∪ Active`
and rewire the bridge to use it. `Lost` tracks remain in the tracker for
re-ID; they just no longer ship to the UI. `active_tracks()` is left
unchanged for the AETHER re-ID consumers (ADR-024).

Regression test `test_lost_tracks_excluded_from_bridge_output` drives a
track to Active, lapses for `loss_misses + 1` ticks to push it to Lost,
and asserts `tracker_update` returns an empty Vec while the Lost track
is still present in `all_tracks()` (re-ID still works).

Validated:
- cargo test --workspace --no-default-features → 1,539 passed, 0 failed
- ESP32-S3 on COM7 still streaming live CSI (cb #32800)
2026-04-25 20:03:03 -04:00
rUv 58a63d6bdf
fix(workspace): unblock --no-default-features build on Windows (#366, #415) (#425)
mat, sensing-server, and train all depended on signal with default features
enabled, which pulled ndarray-linalg → openblas-src → vcpkg/system-BLAS through
the entire workspace. --no-default-features at the workspace root could not
opt out of BLAS, breaking cargo build / cargo test on Windows without vcpkg.

Set default-features = false on the signal dep in all three consumers so the
flag actually propagates. Also gate signal::ruvsense::field_model::tests
::test_estimate_occupancy_noise_only with #[cfg(feature = "eigenvalue")] —
the test unwraps a NotCalibrated stub when eigenvalue is compiled out.

Validated: cargo test --workspace --no-default-features → 1,538 passed,
0 failed, 8 ignored. ESP32-S3 on COM7 still streams live CSI.
2026-04-25 19:45:07 -04:00
ruv ae40e2b33e Release v0.6.2-esp32: ADR-081 kernel + Timer Svc fix, 4MB CI variant
version.txt → 0.6.2.

firmware-ci.yml: matrix-build both 8MB (sdkconfig.defaults) and 4MB
(sdkconfig.defaults.4mb) variants, uploading variant-named artifacts
(esp32-csi-node.bin / esp32-csi-node-4mb.bin, partition-table.bin /
partition-table-4mb.bin). Unblocks 6-binary releases from CI alone,
no local ESP-IDF required.

CHANGELOG: promote [Unreleased] ADR-081 work into [v0.6.2-esp32],
plus Fixed entries for Timer Svc stack overflow and the
fast_loop_cb → emit_feature_state implicit-decl compile error.

Validation: 30 s run on ESP32-S3 (MAC 3c:0f:02:e9:b5:f8), 149
rv_feature_state emissions, no stack overflow, HEALTH mesh packet sent.

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-04-20 10:59:05 -04:00
rUv 5a7f431b0e
ADR-081: Implement 5-layer adaptive CSI mesh firmware kernel (#404)
* ADR-081: adaptive CSI mesh firmware kernel + scaffolding

Introduces a 5-layer firmware kernel that reframes the existing ESP32
modules as components of a chipset-agnostic architecture and authorizes
adaptive control + a compact feature-state stream as the default upstream.

Layers:
  L1 Radio Abstraction Layer  — rv_radio_ops_t vtable + ESP32 binding
  L2 Adaptive Controller      — fast/medium/slow loops (200ms/1s/30s)
  L3 Mesh Sensing Plane       — anchor/observer/relay/coordinator (spec)
  L4 On-device Feature Extr.  — rv_feature_state_t (magic 0xC5110006)
  L5 Rust handoff             — feature_state default; debug raw gated

Files:
  docs/adr/ADR-081-adaptive-csi-mesh-firmware-kernel.md  (new)
  firmware/esp32-csi-node/main/rv_radio_ops.h            (new)
  firmware/esp32-csi-node/main/rv_radio_ops_esp32.c      (new)
  firmware/esp32-csi-node/main/rv_feature_state.{h,c}    (new)
  firmware/esp32-csi-node/main/adaptive_controller.{h,c} (new)
  firmware/esp32-csi-node/main/main.c                    (wire L1+L2)
  firmware/esp32-csi-node/main/CMakeLists.txt            (add 4 sources)
  firmware/esp32-csi-node/main/Kconfig.projbuild         (controller knobs)
  CHANGELOG.md                                           (Unreleased)

Default policy is conservative: enable_channel_switch and
enable_role_change are off, so behavior matches today's firmware
unless an operator opts in via menuconfig. The pure
adaptive_controller_decide() is exposed for offline unit tests.

Reuses (does not rewrite): csi_collector, edge_processing (ADR-039),
swarm_bridge (ADR-066), secure_tdm (ADR-032), wasm_runtime (ADR-040).

* ADR-081: implement Layers 1/2/4 end-to-end + host tests + QEMU hooks

Turns the ADR-081 scaffolding into a working adaptive CSI mesh kernel:
Layer 1 radio abstraction has an ESP32 binding and a mock binding; Layer 2
adaptive controller runs on FreeRTOS timers; Layer 4 feature-state packet
is emitted at 5 Hz by default, replacing raw ADR-018 CSI as the default
upstream.

New files:
  firmware/esp32-csi-node/main/adaptive_controller_decide.c  (pure policy)
  firmware/esp32-csi-node/main/rv_radio_ops_mock.c           (QEMU binding)
  firmware/esp32-csi-node/tests/host/Makefile                (host tests)
  firmware/esp32-csi-node/tests/host/test_adaptive_controller.c
  firmware/esp32-csi-node/tests/host/test_rv_feature_state.c
  firmware/esp32-csi-node/tests/host/esp_err.h               (shim)
  firmware/esp32-csi-node/tests/host/.gitignore

Modified:
  adaptive_controller.c         — includes pure decide.c; emit_feature_state()
                                  wired into fast loop (200 ms = 5 Hz)
  rv_radio_ops_esp32.c          — get_health() fills pkt_yield + send_fail
  csi_collector.{c,h}           — pkt_yield/send_fail accessors (ADR-081 L1)
  rv_feature_state.h            — packed size corrected to 60 bytes
                                  (was incorrectly 80 in initial commit)
  main.c                        — mock binding registered under mock CSI
  CMakeLists.txt                — rv_radio_ops_mock.c under CSI_MOCK_ENABLED
  scripts/validate_qemu_output.py — 3 new ADR-081 checks (17/18/19)
  docs/adr/ADR-081-*.md         — status → Accepted (partial);
                                  implementation-status matrix; measured
                                  benchmarks (decide 3.2 ns, CRC32 614 ns);
                                  bandwidth 300 B/s @ 5 Hz (99.7% vs raw);
                                  verification section
  CHANGELOG.md                  — artifact-level entries

Tests (host, gcc -O2 -std=c11):
  test_adaptive_controller:  18/18 pass, decide() = 3.2 ns/call
  test_rv_feature_state:     15/15 pass, CRC32(56 B) = 614 ns/pkt, 87 MB/s
                             sizeof(rv_feature_state_t) == 60 asserted
                             IEEE CRC32 known vectors verified

Deferred (tracked in ADR-081 roadmap Phase 3/4):
  Layer 3 mesh-plane message types, role-assignment FSM, Rust-side mirror
  trait in crates/wifi-densepose-hardware/src/radio_ops.rs.

* ADR-081: Layer 3 mesh plane + Rust mirror trait — all 5 layers landed

Fully implements the remaining deferred pieces of the adaptive CSI mesh
firmware kernel. All 5 layers (Radio Abstraction, Adaptive Controller,
Mesh Sensing Plane, On-device Feature Extraction, Rust handoff) are
now implemented and host-tested end-to-end.

Layer 3 — Mesh Sensing Plane (firmware/esp32-csi-node/main/rv_mesh.{h,c}):
  * 4 node roles: Unassigned / Anchor / Observer / FusionRelay / Coordinator
  * 7 message types: TIME_SYNC, ROLE_ASSIGN, CHANNEL_PLAN,
    CALIBRATION_START, FEATURE_DELTA, HEALTH, ANOMALY_ALERT
  * 3 auth classes: None / HMAC-SHA256-session / Ed25519-batch
  * Payload types: rv_node_status_t (28 B), rv_anomaly_alert_t (28 B),
    rv_time_sync_t (16 B), rv_role_assign_t (16 B),
    rv_channel_plan_t (24 B), rv_calibration_start_t (20 B)
  * 16-byte envelope + payload + IEEE CRC32 trailer
  * Pure rv_mesh_encode()/rv_mesh_decode() plus typed convenience encoders
  * rv_mesh_send_health() + rv_mesh_send_anomaly() helpers

Controller wiring (adaptive_controller.c):
  * Slow loop (30 s default) now emits HEALTH
  * apply_decision() emits ANOMALY_ALERT on transitions to ALERT /
    DEGRADED
  * Role + mesh epoch tracked in module state; epoch bumps on role
    change

Layer 5 — Rust mirror (crates/wifi-densepose-hardware/src/radio_ops.rs):
  * RadioOps trait mirrors rv_radio_ops_t vtable
  * MockRadio backend for offline tests
  * MeshHeader / NodeStatus / AnomalyAlert types mirror rv_mesh.h
  * Byte-identical IEEE CRC32 (poly 0xEDB88320) verified against
    firmware test vectors (0xCBF43926 for "123456789")
  * decode_mesh / decode_node_status / decode_anomaly_alert / encode_health
  * 8 unit tests, including mesh_constants_match_firmware which asserts
    MESH_MAGIC/VERSION/HEADER_SIZE/MAX_PAYLOAD match rv_mesh.h
    byte-for-byte
  * Exported from lib.rs
  * signal/ruvector/train/mat crates untouched — satisfies ADR-081
    portability acceptance test

Tests (all passing):
  test_adaptive_controller:   18/18   (C, decide() 3.2 ns/call)
  test_rv_feature_state:      15/15   (C, CRC32 87 MB/s)
  test_rv_mesh:               27/27   (C, roundtrip 1.0 µs)
  radio_ops::tests (Rust):     8/8
  --- total:                 68/68 assertions green ---

Docs:
  * ADR-081 status flipped to Accepted
  * Implementation-status matrix updated; L3 + Rust mirror both
    marked Implemented
  * Benchmarks table extended with rv_mesh encode+decode roundtrip
  * Verification section updated with cargo test invocation
  * CHANGELOG: two new entries for L3 mesh plane + Rust mirror

Remaining follow-ups (Phase 3.5 polish, not blocking):
  * Mesh RX path (UDP listener + dispatch) on the firmware
  * Ed25519 signing for CHANNEL_PLAN / CALIBRATION_START
  * Hardware validation on COM7

* Add test_rv_mesh to host-test .gitignore

Fixes an untracked-file warning from the repo stop-hook: the compiled
binary was built by make but the .gitignore update was missed in
8dfb031. No source changes.

* Fix implicit decl of emit_feature_state in adaptive_controller

fast_loop_cb calls emit_feature_state() at line 224, but the static
definition is at line 256. GCC treats the implicit declaration as
non-static, then the real static definition conflicts, and
-Werror=all promotes both to hard build errors.

Add a forward declaration above the first use. Unblocks ESP32-S3
firmware build and all QEMU matrix jobs.

Co-Authored-By: claude-flow <ruv@ruv.net>

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-20 10:38:23 -04:00