feat: implement hardware repair domain guidance engine (#150) - #183
feat: implement hardware repair domain guidance engine (#150)#183Subhra-Nandi wants to merge 4 commits into
Conversation
…features (sahoo-tech#150) Safety bug fix: - Replace if/elif/elif chain with independent if blocks so ALL hazards in a single frame are reported; old code silently dropped any rule after the first matching elif (e.g. power_tool warning invisible when circuit_board also present) New features: - Implement _check_soldering_proximity(): Euclidean bbox-centre distance; fires specific component name when iron within 150px threshold; graceful fallback when no bbox data provided - Implement _select_template(): scores each template by keyword matches against detected_classes; returns best match in active_template field - Add active_template field to GuidanceInstruction dataclass - Implement _parse_ocr(): extracts repair step numbers and P/N part numbers from OCR text; appended as WARNING-level guidance notes - Document hand_results parameter (reserved for future gesture rules) Tests: 4 → 24 - Keep all 4 original tests; all still pass unchanged - Add TestCircuitBoardRule, TestPowerToolRule, TestSolderingIronRule positive and negative path tests - Add TestMultipleSimultaneousHazards: regression tests for the elif bug - Add TestTemplateSelection: all 4 templates + no-match case - Add TestOCRIntegration: step number, part number, empty string - Add TestComponentIdentification: mapping, unknown, deduplication - Add TestEdgeCases: empty list, uppercase class, missing key, None Docs: - Expand docs/physical_domain.md: component dictionary table, step templates table, safety rules with trigger conditions and exact messages, status codes, OCR integration, GuidanceInstruction fields
|
After reviewing the PR, it does not currently meet the required project standards and therefore cannot be accepted at this stage. You may either work on improving the implementation and retry with the necessary changes, or choose another available issue to contribute to. Please ensure that future submissions follow the project guidelines, coding standards, and required implementation quality before raising a PR for review |
|
Hi @sahoo-tech, Thank you for the detailed review and feedback. I see that the regression tests are failing, which I missed before submitting. I am currently working on fixing the implementation to ensure all project standards and regression tests pass successfully. I'll update this thread or re-raise the PR once the fixes are ready for another look! |
Summary
Closes #150 — Hardware Repair Domain Guidance Engine
Files changed
core/physical/domains/hardware_engine.pytests/test_hardware_engine.pydocs/physical_domain.mdBugs fixed since original submission
🔴 elif safety bug (silent hazard drop)
The original
if / elif / elifchain meant only one safety rule could everfire per frame. If a circuit board AND a power tool were both visible without
their respective safety equipment, only the first matching rule fired —
the other hazard was silently invisible to the user.
Fix: Three independent
ifblocks. All triggered messages are collectedinto lists and joined into one
" | "-separated message. No hazard is eversuppressed.
🔴 self.templates unused
self.templateswas assigned in__init__but never read inanalyze().The feature requirement ("built-in step templates") was unfulfilled.
Fix:
_select_template()scores each template by counting keyword matchesagainst detected classes and returns the best match in the new
GuidanceInstruction.active_templatefield.🔴 Soldering proximity left as a comment
The issue required proximity detection. The original code had:
# For strict proximity, you would calculate distance herebut did not implement it.
Fix:
_check_soldering_proximity()computes Euclidean distance betweenbounding box centres. Fires when iron centre is within 150 px of any
non-target component. Falls back to
None(generic warning) when nobboxdata is present.
🟡 ocr_text never read
Accepted as parameter, never used.
Fix:
_parse_ocr()extracts step numbers (Step 3:) and part numbers(
P/N: AB-5678) and appends them asWARNING-level notes.Issue checklist
HardwareEngine.analyze(detections, hand_results, ocr_text)implementedcircuit_boardwithoutesd_strap→CRITICAL_WARNINGsoldering_ironproximity to non-target component →WARNING(with real bbox math)power_toolwithoutsafety_glasses→CRITICAL_WARNING"Unknown: <class>"docs/physical_domain.mddocuments component dictionary, templates,rules, status codes, OCR integration, and GuidanceInstruction fields