Commit graph

258 commits

Author SHA1 Message Date
jedarden
af0dc8a5b5 docs: document Phase 7 completion - presence prediction implementation
Document the complete presence prediction system implementation
for Home Assistant integration with:

- Per-person transition probability tracking with Laplace smoothing
- Per-zone occupancy patterns from historical data
- Time-slot based predictions via Monte Carlo simulation
- HA sensor exposure with auto-discovery (3 sensors per person)
- Accuracy tracking targeting >75% at 15-minute horizon

All acceptance criteria for presence prediction have been met.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 10:17:32 -04:00
Argo Workflows CI
f2cad74c1f ci: auto-bump version to 0.1.100 2026-04-09 14:06:14 +00:00
jedarden
af8800caef feat: add self-improving localization REST API
Implement REST API endpoints for managing learned weights and tracking
improvement in the self-improving localization system.

- Add LocalizationHandler with endpoints for:
  - GET /api/localization/weights - get all learned link weights
  - GET /api/localization/weights/{linkID} - get specific link weight
  - POST /api/localization/weights/reset - reset all weights to default
  - GET /api/localization/spatial-weights - get spatial weights per zone
  - GET /api/localization/groundtruth/* - ground truth sample management
  - GET /api/localization/accuracy/* - position accuracy tracking
  - GET /api/localization/learning/* - learning progress and history

- Integrate spatial weight learner into fusion engine:
  - Add AddLinkInfluenceWithSpatialWeights to grid.go for per-cell weight application
  - Update Fuse() in fusion.go to use spatial weight functions when available
  - Apply both sigma adjustments and spatial weights for Fresnel zone computation

- Add comprehensive table-driven tests for all API endpoints

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 10:06:06 -04:00
Argo Workflows CI
5c474bb6ce ci: auto-bump version to 0.1.99 2026-04-09 13:59:50 +00:00
jedarden
ef75a823fc feat: implement presence prediction REST API endpoints
Implemented prediction API handler with comprehensive REST endpoints:

- GET /api/predictions - Get all predictions (optional filter by person/horizon)
- GET /api/predictions/stats - Get prediction statistics and data age
- POST /api/predictions/recompute - Force probability recomputation
- GET /api/predictions/accuracy - Get accuracy stats for all people
- GET /api/predictions/accuracy/overall - Get overall system accuracy
- GET /api/predictions/accuracy/{personID} - Get person-specific accuracy
- GET /api/predictions/pending - Get pending prediction count
- GET /api/predictions/patterns/zones - Get zone occupancy patterns
- GET /api/predictions/patterns/zones/{zoneID} - Get pattern for specific zone
- POST /api/predictions/patterns/compute - Compute zone occupancy patterns
- GET /api/predictions/horizon - Get Monte Carlo horizon predictions
- GET /api/predictions/horizon/{personID} - Get horizon prediction for person

The implementation includes:
- Proper error handling with appropriate HTTP status codes
- Query parameter support for filtering (person, horizon)
- JSON responses for all endpoints
- Helper function for logging prediction accuracy
- Table-driven tests for all endpoints

HA sensor exposure for predictions was already implemented in the MQTT
client via PublishPredictionSensors() and UpdatePredictionState() methods.

Accepts the 75% accuracy target at 15-minute horizon per specification.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 09:59:42 -04:00
Argo Workflows CI
c826077499 ci: auto-bump version to 0.1.98 2026-04-09 13:49:01 +00:00
jedarden
15c491ffea feat: implement anomaly detection and security mode
Implements comprehensive anomaly detection system that learns normal household
patterns over 7+ days and alerts on deviations. Transforms spaxel into a basic
home security system.

Core features:
- Normal behaviour model: statistical tracking of occupancy patterns per
  (hour_of_week, zone_id) slot with expected occupancy, typical person count,
  and typical BLE devices
- Four anomaly types: unusual hour presence, unknown BLE device, motion during
  away mode, unusual dwell duration
- Security mode: lowered thresholds, immediate alerts, bypasses quiet hours
- Auto-away/disarm: automatic security mode activation based on BLE device
  presence (15min absence, auto-disarm on device return)
- Alert chain: staged notifications (dashboard → push → webhook → escalation)
- WebSocket integration: real-time anomaly broadcasts to dashboard

API endpoints:
- GET/POST /api/mode: system mode control (home/away/sleep)
- GET /api/security/status: current security state

Tests cover all anomaly types, alert chain timing, security mode thresholds,
auto-away/disarm, acknowledgement flow, and cooldown deduplication.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 09:48:44 -04:00
Argo Workflows CI
6705826f92 ci: auto-bump version to 0.1.97 2026-04-09 13:04:47 +00:00
jedarden
54653c9404 feat: verify diurnal adaptive baseline implementation complete
Verified the diurnal adaptive baseline system is fully implemented:
- 24 hourly slots per link per subcarrier
- 7-day learning phase with >=300 samples/slot requirement
- Motion-gated updates with outlier protection
- 15-minute crossfade at hour boundaries
- SQLite persistence with diurnal_baselines table
- 24-hour polar chart dashboard visualization
- REST API endpoints for diurnal data
- Comprehensive test coverage (45+ tests)

All acceptance criteria met:
- Baseline correctly crossfades at hour boundaries (±60s)
- Motion events during learning do not corrupt slots
- Polar chart renders for links with >=1 ready slot
- No performance regression: baseline lookup remains O(1)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 09:04:37 -04:00
Argo Workflows CI
7a4c1c484b ci: auto-bump version to 0.1.96 2026-04-09 12:53:50 +00:00
jedarden
50856415b3 feat: add diurnal baseline REST API endpoints
Add REST API for diurnal baseline data:
- GET /api/diurnal/status - learning status for all links
- GET /api/diurnal/slots/{linkID} - slot data for specific link

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 08:53:31 -04:00
Argo Workflows CI
f6a5d560cb ci: auto-bump version to 0.1.95 2026-04-09 12:37:16 +00:00
jedarden
281bbefb57 feat: complete floor plan dashboard UI
- Floor plan upload panel with image selection and preview
- Two-point calibration UI with pixel distance measurement
- Real-world distance input for scale computation
- Pixel-to-meter scale factor calculation and storage
- Fixed floor plan image serving at /floorplan/image.png
- Integration with Viz3D ground plane texture
- CSS styling for floor plan setup panel
- Image persists across server restart via SQLite

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 08:37:08 -04:00
Argo Workflows CI
602b68645b ci: auto-bump version to 0.1.94 2026-04-09 12:17:06 +00:00
jedarden
3ff80c294d chore: update tracking files after rebase
Update .beads/issues.jsonl and .needle-predispatch-sha after
remote rebase to maintain tracking state.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 08:16:53 -04:00
Argo Workflows CI
8fa8fd4e55 ci: auto-bump version to 0.1.93 2026-04-09 12:16:32 +00:00
jedarden
3ecf5648c2 chore: anomaly detection & security mode implementation tracking
Update tracking files to reflect completed implementation of:
- 7-day pattern learning algorithm with Welford's online algorithm
- Anomaly scoring against learned patterns (time score, zone score, composite)
- Security mode integration (Armed, Disarmed, ArmedStay states)
- Alert chain with timers (dashboard → webhook → escalation)
- REST API endpoints for security mode and anomaly management
- Database persistence for patterns and anomaly events
- Cooldown deduplication and outlier protection

All acceptance criteria met:
- System detects deviations from learned patterns via multiple anomaly types
- Accuracy improves measurably through feedback loop integration

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 08:16:19 -04:00
Argo Workflows CI
e2c6b53729 ci: auto-bump version to 0.1.92 2026-04-09 12:06:50 +00:00
jedarden
3da0c32ba3 feat: dashboard PIN change flow
- Backend: Add POST /api/auth/change-pin endpoint
  - Requires valid session; body: {old_pin, new_pin}
  - Verifies old PIN against bcrypt hash; returns 403 on mismatch
  - Hashes new PIN with bcrypt cost=12
  - Existing sessions remain valid after PIN change
  - Returns {ok:true} on success

- Dashboard: Security section in settings panel
  - Add "Security" section with Change PIN button
  - Modal form: old PIN → new PIN → confirm new PIN → Submit
  - Inline error display for incorrect current PIN (403)
  - Success toast notification on PIN change
  - Validation: 4-8 digits, numeric only, PINs must match, new ≠ old

- Tests: Add comprehensive tests for change PIN endpoint
  - Success case: old PIN verified, new PIN works
  - Wrong old PIN: returns 403, original PIN still works
  - Unauthenticated: returns 401
  - Invalid new PIN: validation for length, digits, etc.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 08:05:35 -04:00
Argo Workflows CI
93d3faceee ci: auto-bump version to 0.1.91 2026-04-09 11:55:31 +00:00
jedarden
747940f932 firmware: LED identify blink command - already implemented
All components complete:
- Firmware: LED blink at 5Hz via FreeRTOS task, configurable GPIO
- Mothership: POST /api/nodes/{mac}/identify endpoint, WebSocket sending
- Dashboard: Identify button in fleet panel and 3D view context menu

Acceptance criteria met:
✓ LED blinks at ~5 Hz for specified duration
✓ Blink stops automatically when duration_ms expires
✓ REST endpoint returns 404 for disconnected nodes
✓ LED GPIO configurable via sdkconfig (default GPIO8)
✓ Dashboard integration complete
2026-04-09 07:55:21 -04:00
Argo Workflows CI
5c85118f1d ci: auto-bump version to 0.1.90 2026-04-09 11:46:39 +00:00
jedarden
68334a9b78 feat: dashboard identify buttons for fleet status and 3D view
- Fleet status page now has 'Identify' button per row that POSTs to /api/nodes/{mac}/identify
- 3D view right-click context menu has 'Identify (blink LED)' option for nodes
- Both options trigger LED blink on the selected node for identification

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 07:46:29 -04:00
Argo Workflows CI
235b69067c ci: auto-bump version to 0.1.89 2026-04-09 11:41:48 +00:00
jedarden
47e8fa7999 feat: add identify button to fleet status page and 3D view context menu
- Add 'Identify' button to fleet health panel role list for online nodes
- Add CSS styling for fleet identify button
- Add identifyNode function to FleetPanel public API
- 3D view context menu with 'Identify (blink LED)' already implemented

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 07:41:18 -04:00
Argo Workflows CI
35bfb85e2e ci: auto-bump version to 0.1.88 2026-04-09 11:32:01 +00:00
jedarden
519b5cbe09 feat: add Identify context menu to 3D view
Add 'Identify (blink LED)' option to the right-click context menu
in the 3D view that POSTs to /api/nodes/{mac}/identify.

The context menu appears when right-clicking on a node mesh in the
3D visualization. Uses recursive raycasting to properly detect
both standard node meshes and router node groups.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 07:31:35 -04:00
Argo Workflows CI
1fccf4beff ci: auto-bump version to 0.1.87 2026-04-09 11:27:01 +00:00
jedarden
1266c4c0b1 test: add comprehensive tests for auto-away/disarm and system mode endpoints
Added tests for:
- Auto-away activation when all registered BLE devices absent for 15+ minutes
- Auto-disarm triggering when registered BLE device returns with strong RSSI
- Manual override pausing auto-away detection
- System mode GET/PUT REST API endpoints
- Edge cases: no registered devices, weak BLE signals, unregistered devices

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 07:26:34 -04:00
Argo Workflows CI
2ddf784ba4 ci: auto-bump version to 0.1.86 2026-04-09 11:17:42 +00:00
jedarden
7559f1964e feat: add Identify button to fleet status page
Adds a lightning bolt () Identify button per node row in the
fleet status page that POSTs to /api/nodes/{mac}/identify.

- Added CSS styling for .node-identify-btn with hover/active states
- Implemented identifyNode() function that sends identify command
- Button only shows for online nodes
- Toast notifications for success/failure feedback

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 07:17:13 -04:00
Argo Workflows CI
dbff011a44 ci: auto-bump version to 0.1.85 2026-04-09 11:15:42 +00:00
jedarden
72e155391f feat: implement REST API endpoint for node identify
- POST /api/nodes/{mac}/identify endpoint with {duration_ms: 5000} body
- Forwards identify message as WebSocket JSON to target node
- Returns 404 if node not connected; 200 on success
- Includes table-driven tests for all edge cases

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 07:15:20 -04:00
Argo Workflows CI
1b891b5e59 ci: auto-bump version to 0.1.84 2026-04-09 11:01:59 +00:00
jedarden
0aa6046f82 feat: implement firmware LED blink handler for identify command
- Add led_init() call during firmware initialization in app_main()
- Add led_stop_blink() call on WebSocket disconnect
- LED GPIO configurable via CONFIG_SPAXEL_LED_GPIO (default GPIO8)
- Blink runs in FreeRTOS task at ~5Hz (100ms on/100ms off)
- Any running blink is cancelled when new identify message received

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 07:01:42 -04:00
Argo Workflows CI
20fa0040d3 ci: auto-bump version to 0.1.83 2026-04-09 10:42:05 +00:00
jedarden
5b351d188b feat: implement OUI code generator for IEEE MAC address lookup
- Created mothership/internal/oui/gen.go with //go:generate directive
- Downloads IEEE OUI registry at generate time from standards-oui.ieee.org
- Parses OUI entries (hex format) and generates oui_data.go map
- Generated oui_data.go contains 39,195 OUI entries (>5000 required)
- Removed redundant Python generator (gen_data.py)
- Updated test cases with correct manufacturer names from IEEE registry

Acceptance criteria met:
- go generate produces non-empty oui_data.go with >5000 entries
- oui_data.go compiles without errors
- Manual trigger only (no automatic regeneration)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 06:41:58 -04:00
Argo Workflows CI
0c5f7ed843 ci: auto-bump version to 0.1.82 2026-04-09 10:36:15 +00:00
jedarden
24e652a389 feat: integrate OUI lookup into passive radar AP detection
- Add manufacturer display to AP detection banner
- Show "your router (Manufacturer)" when OUI is known
- Show "your router" as fallback when OUI unknown
- Expand OUI database with more manufacturer entries

The AP detection banner now shows the router manufacturer
when available from OUI lookup, making it easier for users
to identify their router during the onboarding process.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 06:35:44 -04:00
Argo Workflows CI
b75e86ff1c ci: auto-bump version to 0.1.81 2026-04-09 10:27:54 +00:00
jedarden
14c69ad3a3 feat: implement OUI lookup function
Create mothership/internal/oui/oui.go with LookupOUI function:
- Accepts net.HardwareAddr (MAC address)
- Extracts first 3 bytes as uint32 in big-endian order (OUI)
- Returns manufacturer name from ouiMap or empty string if not found
- Handles edge cases gracefully (short MAC returns "", no panic)

Acceptance criteria met:
- LookupOUI returns correct vendor for known OUIs
- Unknown OUI returns empty string (no panic)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 06:27:26 -04:00
Argo Workflows CI
c800a67f95 ci: auto-bump version to 0.1.80 2026-04-09 10:06:57 +00:00
jedarden
636f3efba2 feat: complete anomaly detection & security mode dashboard UI
- Add anomaly.css and sleep.css to dashboard includes
- Add sleep.js for sleep quality monitoring
- Implement analytics API handler (flow, dwell, corridors)
- Add tracks API and tests for time-based data queries
- Add sleep monitor tests
- AnomalyDetector initialized and running in main()
- Anomaly events broadcast via WebSocket to dashboard
- Security mode arm/disarm persists across restarts (learning_state table)
- Learning progress tracking and display
- Alert banner with acknowledge functionality
- All API endpoints wired: /api/anomalies, /api/security/*, /api/analytics/*

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 05:59:54 -04:00
jedarden
89898731c5 feat: extract evaluate() from EndIteration for testable load shedding state machine
The load shedding system was already fully implemented with 4 levels,
rolling average timing, and all integration points wired. This change
extracts the state machine evaluation into a separate evaluate() method
so tests can inject controlled timing values without depending on wall
clock time, and fixes the recovery counter reset test accordingly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 05:59:54 -04:00
Argo Workflows CI
78f5d0172b ci: auto-bump version to 0.1.79 2026-04-07 19:50:51 +00:00
jedarden
0491965ce1 feat: complete anomaly detection & security mode dashboard UI
Wire anomaly detection backend into dashboard WebSocket feed as
typed 'anomaly_detected' and 'alert' messages. Add security mode
state to snapshot/delta broadcasts via SecurityStateProvider.
Include load shedding integration for crowd flow, detection event
logging, identity matching improvements, and sleep integration
updates. All acceptance criteria met: arm/disarm persists,
learning progress refreshes, alert banner <2s, acknowledge flow.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 15:50:25 -04:00
Argo Workflows CI
d7f490e591 ci: auto-bump version to 0.1.78 2026-04-07 19:22:32 +00:00
jedarden
35b274aab5 fix(e2e): use correct auth status endpoint /api/auth/status
The shell script was using GET /api/auth/setup to check auth status,
but that endpoint only accepts POST requests. The correct endpoint for
checking auth status is /api/auth/status which returns the
pin_configured field.

This fix ensures the E2E test properly detects when PIN authentication
is enabled and configures it accordingly.
2026-04-07 15:22:13 -04:00
Argo Workflows CI
dcc9064492 ci: auto-bump version to 0.1.77 2026-04-07 19:09:58 +00:00
jedarden
b1c2218146 feat: wire anomaly detection & security mode API endpoints
AnomalyDetector initialized in main() with periodic model updates.
Anomaly events broadcast to dashboard WS as 'alert' messages via
BroadcastAlert. GET /api/anomalies?since=24h lists recent events.
POST /api/security/arm and /api/security/disarm manage security mode.
GET /api/security/status returns armed state, learning progress, and
24h anomaly count. Arm/disarm state persisted to learning_state table
and restored on restart.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 15:09:34 -04:00