feat(scripts): implement Phase 15 — Scripts & Developer Tools
Add 7 scripts for development, debugging, and deployment:
- run_dev.py: multiprocessing dev server with graceful shutdown
- run_capture.py: standalone webcam test with face detection, FPS, quality
- setup_ssh_tunnel.sh: SSH tunnel to gwhiz1 with health check, auto-reconnect
- run_llm_server.py: remote vLLM and local Ollama management
- calibrate.py: 2-min baseline capture with simulation mode
- replay_session.py: JSONL session replay with state visualization
- seed_config.py: config seeder with storage dirs, .env, baselines
50 tests, 488 total passing.
da1e77d
feat(intervention): implement Phase 11 — Intervention Engine with trigger, snapshot, planner, executor, restore
- trigger.py: Trigger evaluation with level selection (overlay/simplified/guided), cooldown, adaptive thresholds, quiet mode
- snapshot.py: Pre-intervention workspace snapshot capture (editor folds, browser tabs, terminal scroll)
- planner.py: Plan validation (destructive check, headline length, step count) + hide_targets to adapter command mapping
- executor.py: Dispatches commands to workspace adapters, tracks mutations with reversal support
- restore.py: Manages intervention lifecycle with auto-timeout (5 min), recovery detection (FLOW >0.70 for 15s), outcome logging
- 58 tests including full trigger→snapshot→validate→execute→restore cycle (438 total passing)
b0091bc
feat(llm): implement Phase 10 — LLM Engine with remote Qwen client, Ollama fallback, prompt templates
- client.py: LLMClient protocol, LLMError, rule-based fallback plan builder
- remote_qwen.py: SSH tunnel management, OpenAI-compatible API via httpx, 2x retry
- local_ollama.py: Local Ollama REST fallback with same retry/fallback pattern
- prompts.py: 5 prompt templates with mode-based selection, system prompt with JSON schema
- parser.py: Fault-tolerant JSON parsing (missing braces, trailing commas, markdown, preamble)
- cache.py: LRU cache by context hash with configurable TTL (5 min default)
- 59 tests covering parsing, validation, prompts, cache, both clients (380 total passing)
42a79d1
feat(context): implement Phase 9 — Context Engine with workspace adapters, complexity scoring
- app_classifier.py: app detection (vscode/chrome/terminal/other), workspace mode classification (coding_debugging, reading_docs, browsing, terminal_errors, mixed), tab type classification (stackoverflow, documentation, search, code_host, social)
- editor_adapter.py: VS Code WebSocket adapter with CONTEXT_REQUEST/RESPONSE protocol, payload parsing, graceful fallback
- browser_adapter.py: Chrome extension WebSocket adapter, tab auto-classification from URLs, content truncation (≤2000 tokens)
- terminal_adapter.py: rolling history, Python traceback extraction, shell error detection, repeated command tracking
- assembler.py: context assembly from all adapters, 7-factor complexity scoring (error density, visual clutter, tab overload, window thrashing, code size, diagnostic severity, document density)
- 45 tests covering all components, 321 total tests passing
186c5b5
feat(api): implement Phase 8 — API Gateway with FastAPI routes, WebSocket server
- app.py: FastAPI setup with CORS, lifespan events, ServiceRegistry for DI
- routes.py: all 11 REST endpoints (capture, features, state, context, llm, intervention, status, health)
- websocket_server.py: WebSocket on ws://localhost:9473, STATE_UPDATE broadcast, INTERVENTION_TRIGGER dispatch, USER_ACTION reception, client management
- 32 tests covering all endpoints, registry, WS messages, module imports
- 276 total tests passing
2e931bd
feat(state): implement Phase 7 — State Engine with feature fusion, rule scoring, EMA smoothing, trigger policy
- feature_fusion.py: multi-channel fusion (physio + kinematics + telemetry → 12-dim FeatureVector), staleness penalty, per-channel signal quality
- rule_scorer.py: 7 weighted sub-scores for HYPER (pulse elevation, HRV drop, blink suppression, posture collapse, mouse thrash, window switching, workspace complexity), plus HYPO/FLOW/RECOVERY scoring
- smoother.py: EMA (α=0.3), hysteresis (entry 0.85, exit 0.70), dwell time enforcement (HYPER 8s, HYPO 15s, FLOW 15s), state transition recording
- trigger_policy.py: intervention trigger conditions, 60s cooldown, dismissal tracking, adaptive thresholds (+0.05/dismissal), quiet mode (3 dismissals in 5 min → 30-min)
- 43 tests covering all components, 244 total tests passing
2997851
feat(telemetry): implement Phase 6 — Telemetry Engine with input hooks, window tracker, feature aggregator
Input hooks: pynput mouse/keyboard listeners with rate-limited sampling,
thread-safe event buffers, manual recording API for testing, privacy-first
key classification (no raw content stored).
Window tracker: platform-specific active window detection (macOS pyobjc,
Linux xlib, Windows ctypes) with polling and deduplication.
Feature aggregator: computes all 12 TelemetryFeatures from raw events —
mouse velocity/jerk, click/keyboard bursts, backspace density, inactivity,
window switch rate, scroll reversals. 201/201 tests passing.
6945e33
feat(kinematics): implement Phase 5 — Kinematics Engine with blink, head pose, posture
Blink detector: EAR-based blink detection from FaceMesh landmarks with
rolling 60s blink rate, suppression score, and baseline delta tracking.
Head pose: solvePnP pitch/yaw/roll estimation with jitter and freeze detection.
Posture: shoulder drop ratio, forward lean angle, slump score with
auto-calibration and FaceMesh-only fallback mode. 157/157 tests passing.
7791b6f
feat(physio): implement Phase 4 — Physio Engine with rPPG HR/HRV extraction
Implements the complete rPPG physiological sensing pipeline:
- ROI Extractor: extracts mean RGB traces from forehead, left/right cheek
regions using MediaPipe landmark-defined convex hull polygons, with
pixel-count-weighted averaging and dynamic ROI selection
- rPPG Algorithms: three BVP extraction methods:
* POS (Plane Orthogonal to Skin) — primary, overlap-add windowing
* CHROM (Chrominance-Based) — better cross-skin-tone performance
* Green-channel — simplest baseline reference
- Pulse Estimator: bandpass filtering → Welch PSD HR estimation →
IBI peak detection → RMSSD HRV computation → HR delta trending
- Quality Scorer: SNR-based signal quality assessment with automatic
algorithm switching (POS → CHROM → Green) when quality degrades
31 unit tests (all passing) covering ROI extraction, all three rPPG
algorithms, pulse estimation accuracy (±5 BPM), and quality scoring.
All 116 unit tests passing.
b1de954
chore: add .gitignore and remove cached __pycache__ files
ca73e21
feat(capture): implement Phase 3 — Capture Service with webcam, face tracking, quality scoring
Implements the complete capture pipeline for the Cortex biofeedback engine:
- WebcamCapture: threaded OpenCV VideoCapture with stable FPS targeting,
monotonic timestamps, and async queue publishing
- FaceTracker: MediaPipe FaceLandmarker Tasks API for 478-landmark face
tracking with face lost/reacquire hysteresis (5-frame tolerance)
- FrameQualityScorer: brightness (mean intensity), blur (Laplacian variance),
and motion (nose tip jitter) quality scoring with composite quality gate
- CapturePipeline: integrated webcam → face → quality → output pipeline
- AdaptiveFrameSkipper: dynamic frame skip when processing falls behind
Also includes:
- 37 unit tests (all passing) covering all components with mocked webcam
- MediaPipe FaceLandmarker model file for face detection
- Phase 1+2 codebase files (previously uncommitted)
All 85 unit tests passing.
d94c3cd
Initial Ralph project setup
bbcf91f