Repository navigation
feat: integrate empirical firmware oracle verdicts and lookup tool - #14
Merged
Merged
Conversation
- Add FirmwareOracle engine loading results/mcp_index.json from own-firmware-oracle - Implement get_oracle_index_path with 3-tier fallback (env var -> sibling checkout -> bundled data) - Bundle reference oracle_index.json (89 frames across MH200N & MyHomeServer1 firmwares) - Enrich parse_and_validate_frame with empirical firmware oracle verification - Add dedicated lookup_firmware_verdict tool for direct, low-latency firmware ground truth - Add oracle://index diagnostic resource and update rescan_documentation - Add comprehensive test suites with 100% coverage on firmware_oracle.py
- Verify canonical JSON SHA-256 hash at load time and report hash integrity status - Track and report index discovery source tier (env, sibling, bundled, explicit) - Clearly distinguish between oracle load failure and unverified frames - Isolate oracle lookup in parse_and_validate_frame to degrade gracefully without failing grammar validation - Invalidate _oracle_cache during rescan_documentation - Handle reply '-' as No client reply and explain OUT (Bus) vs SILENT (Drop) verdicts - Correct MyHomeServer1 firmware version to 028206 in docs and docstrings - Log warning when OPENWEBNET_ORACLE_INDEX points to non-existent path - Expand unit test suite with 100% coverage on firmware_oracle.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR integrates direct, low-latency empirical firmware verification into
openwebnet-mcp, grounding OpenWebNet frame validation and agent queries in verified ground truth from the own-firmware-oracle project.In own-firmware-oracle, OpenWebNet frames are executed inside QEMU-emulated physical gateways (BTicino MH200N firmware
010108and MyHomeServer1 firmware028206), capturing exact client session replies (ACK/NACK/SILENT/No reply), bus telegram emissions (hex bytes), and SHA-256 target hashes.This PR equips
openwebnet-mcpto serve these empirical verdicts directly to AI agents and developers during tool calls.Changes
1. Multi-Tier Path Discovery with Provenance Tracking (
src/openwebnet_mcp/_paths.py)resolve_oracle_index() -> tuple[Path | None, str]andget_oracle_index_path() -> Path | Nonewith 3-tier discovery:OPENWEBNET_ORACLE_INDEXenvironment variable (explicit file path, logs warning if invalid)../own-firmware-oracle/results/mcp_index.jsonsrc/openwebnet_mcp/data/oracle_index.jsonsource_tier("env","sibling","bundled","explicit").2. Bundled Reference Index (
src/openwebnet_mcp/data/oracle_index.json)mcp_index.jsoncovering 89 unique frames across MH200N (010108) and MyHomeServer1 (028206) firmwares. Ensures standalone distributions (uvx, isolated containers) have immediate out-of-the-box access without requiring a local clone ofown-firmware-oracle.3. Firmware Oracle Engine with Cryptographic Verification (
src/openwebnet_mcp/firmware_oracle.py)FirmwareOracle:load()/reload(): Fast JSON parser with format compatibility checking.verdicts(sort_keys=True, separators=(",", ":")) and compares withverdicts_sha256recorded in the index. Exposeshash_verifiedin diagnostics and reports status (verified/MISMATCH).lookup(frame): Exact match lookup with fallback to normalized frame (normalize_frame).format_verdict_markdown(frame, verdicts): Renders a structured markdown table with Gateway, Firmware, Reply (ACK (*#*1##),NACK (*#*0##),SILENT,*No client reply*), Verdict (OUT (Bus),SILENT (Drop)), Bus Frames Emitted, Emitted OWN, Suite, Target SHA, followed by a detailed Ground Truth Analysis section and provenance/integrity footer.*⚠️ Oracle index unavailable: ...*) and unverified frames (*Frame has not yet been replayed...*).status(): Diagnostic information on loaded index, gateway targets, verdict counts, source tier, and cryptographic hash verification status.4. FastMCP Tool & Resource Augmentation (
src/openwebnet_mcp/server.py)parse_and_validate_frame(frame)now includes a## 🛡️ Empirical Firmware Oracle Verificationsection showing replay behavior on tested gateways whenever available. The oracle call is isolated in its own exception block so that any oracle error degrades gracefully without failing grammar validation.@mcp.tool() async def lookup_firmware_verdict(frame: str) -> strbacked by_oracle_cache(10 min TTL) for direct programmatic queries.@mcp.resource("oracle://index")returning diagnostic status and metadata.rescan_documentationflushes_oracle_cachein addition to other caches, ensuring reloaded indexes take effect immediately.rescan_manager.pyreloads the oracle index uponrescan_documentation.@mcp.prompt("boost")to direct agents to empirical verification tools.Testing & Verification
tests/test_firmware_oracle.pytesting frame normalization, index loading, canonical hash verification (success and mismatch), verdict lookups, markdown generation (ACK, NACK, silent, custom, no client reply), status reporting, format version warning, cache reload, and corrupt/missing file resilience.tests/test_paths.pytesting 3-tier oracle path resolution hierarchy, source tiers, and invalid environment variable warning.tests/test_rescan_manager.pyverifying oracle reload during rescan.tests/test_server.pyverifyinglookup_firmware_verdict, enrichedparse_and_validate_frame, graceful oracle degradation on error,_oracle_cacheinvalidation on rescan, andoracle://indexresource.firmware_oracle.py, 100% onrescan_manager.py, 99% on_paths.py, 95% onserver.py, 96% repo-wide.