feat(iace): cross-domain precision overhaul + component review + schema reconcile

Engine precision (stop foreign-machine patterns leaking into a project):
- Wire project.MachineType into the engine machine-type gate (empty input no
  longer fires every machine class — press/cnc/excavator/crane/medical...).
- Capability-domain gating extended by 7 domains (outdoor, ventilation,
  machining, bulk, palletizer, playground, fitness) so domain-specific hazards
  only fire when the narrative names that domain; emitted via keyword_dictionary.
- Relevance backstop moved into iace (single gating contract, testable), and its
  dominant false-anchor class removed (a long pattern word no longer matches a
  short common token; prepositions/leitung added to the generic stoplist).
- New guard tests: TestCrossDomainPrecision (full pipeline, 0 foreign per GT) and
  TestPatternReachability now asserts 0 dead patterns. Both GTs keep coverage 1.0.

Reachability fix: the 51 dead patterns required electrical/pneumatic/hydraulic
tags nothing produced — renamed to the canonical electrical_energy/
pneumatic_pressure/hydraulic_pressure/hydraulic_part.

Component review (negation is best-effort + expert-correctable):
- Parser surfaces negated components (ComponentMatch.Negated) instead of dropping
  them; negated contribute no tags/energy → no phantom hazards.
- presence_status (vorhanden|nicht_vorhanden|geloescht) + ce_marked on components;
  only `vorhanden` feed matching. CE+safety-relevant flags the PL/SIL obligation.
- Force re-seed preserves the expert's component decisions instead of wiping them.
- Tag-based component→hazard assignment (was: all on the first component).
- Negation-aware narrative parsing ("keine Pneumatik" no longer extracts it).

Local-dev DB: ai-sdk sets search_path=compliance,core,public; reconcile migrations
152-156 bring the consolidated local iace tables to the current schema + add the
presence_status/ce_marked columns. Machine-type vocabulary endpoint for the form.

[migration-approved]

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-06-10 17:15:55 +02:00
parent 3bd4e0aaaf
commit afb3f83f30
47 changed files with 1275 additions and 169 deletions
@@ -128,7 +128,7 @@ func GetTextileAgriPatterns() []HazardPattern {
HarmDE: "Amputation, schwere Schnittverletzungen", AffectedDE: "Bediener, Wartungspersonal", ZoneDE: "Schneidwerksbereich",
DefaultSeverity: 5, DefaultExposure: 3},
{ID: "HP1568", NameDE: "Hydraulik-Leitungsriss unter Hochdruck", NameEN: "Hydraulic hose burst",
RequiredComponentTags: []string{"hydraulic"}, GeneratedHazardCats: []string{"pneumatic_hydraulic"},
RequiredComponentTags: []string{"hydraulic_part"}, GeneratedHazardCats: []string{"pneumatic_hydraulic"},
SuggestedMeasureIDs: []string{"M466", "M234"}, SuggestedEvidenceIDs: []string{"E01"},
Priority: 88, MachineTypes: []string{"agricultural", "tractor", "harvester"},
OperationalStates: []string{"automatic_operation"},
@@ -191,7 +191,7 @@ func GetTextileAgriPatterns() []HazardPattern {
AffectedDE: "Fahrer", ZoneDE: "Fahrersitz",
DefaultSeverity: 3, DefaultExposure: 5},
{ID: "HP1575", NameDE: "Quetschung durch absenkenden Dreipunktanbau", NameEN: "Crushing by lowering three-point hitch",
RequiredComponentTags: []string{"hydraulic"}, GeneratedHazardCats: []string{"mechanical_hazard"},
RequiredComponentTags: []string{"hydraulic_part"}, GeneratedHazardCats: []string{"mechanical_hazard"},
SuggestedMeasureIDs: []string{"M461", "M474"}, SuggestedEvidenceIDs: []string{"E01", "E08"},
Priority: 90, MachineTypes: []string{"agricultural", "tractor"},
OperationalStates: []string{"manual_operation", "maintenance"}, HumanRoles: []string{"operator", "maintenance_tech"},