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:
@@ -17,6 +17,10 @@ import (
|
||||
|
||||
// CreateComponent creates a new component within a project
|
||||
func (s *Store) CreateComponent(ctx context.Context, req CreateComponentRequest) (*Component, error) {
|
||||
status := req.PresenceStatus
|
||||
if status == "" {
|
||||
status = PresencePresent
|
||||
}
|
||||
comp := &Component{
|
||||
ID: uuid.New(),
|
||||
ProjectID: req.ProjectID,
|
||||
@@ -27,6 +31,8 @@ func (s *Store) CreateComponent(ctx context.Context, req CreateComponentRequest)
|
||||
Description: req.Description,
|
||||
IsSafetyRelevant: req.IsSafetyRelevant,
|
||||
IsNetworked: req.IsNetworked,
|
||||
CEMarked: req.CEMarked,
|
||||
PresenceStatus: status,
|
||||
CreatedAt: time.Now().UTC(),
|
||||
UpdatedAt: time.Now().UTC(),
|
||||
}
|
||||
@@ -35,16 +41,16 @@ func (s *Store) CreateComponent(ctx context.Context, req CreateComponentRequest)
|
||||
INSERT INTO iace_components (
|
||||
id, project_id, parent_id, name, component_type,
|
||||
version, description, is_safety_relevant, is_networked,
|
||||
metadata, sort_order, created_at, updated_at
|
||||
ce_marked, presence_status, metadata, sort_order, created_at, updated_at
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5,
|
||||
$6, $7, $8, $9,
|
||||
$10, $11, $12, $13
|
||||
$10, $11, $12, $13, $14, $15
|
||||
)
|
||||
`,
|
||||
comp.ID, comp.ProjectID, comp.ParentID, comp.Name, string(comp.ComponentType),
|
||||
comp.Version, comp.Description, comp.IsSafetyRelevant, comp.IsNetworked,
|
||||
comp.Metadata, comp.SortOrder, comp.CreatedAt, comp.UpdatedAt,
|
||||
comp.CEMarked, comp.PresenceStatus, comp.Metadata, comp.SortOrder, comp.CreatedAt, comp.UpdatedAt,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create component: %w", err)
|
||||
@@ -63,12 +69,12 @@ func (s *Store) GetComponent(ctx context.Context, id uuid.UUID) (*Component, err
|
||||
SELECT
|
||||
id, project_id, parent_id, name, component_type,
|
||||
version, description, is_safety_relevant, is_networked,
|
||||
metadata, sort_order, created_at, updated_at
|
||||
ce_marked, presence_status, metadata, sort_order, created_at, updated_at
|
||||
FROM iace_components WHERE id = $1
|
||||
`, id).Scan(
|
||||
&c.ID, &c.ProjectID, &c.ParentID, &c.Name, &compType,
|
||||
&c.Version, &c.Description, &c.IsSafetyRelevant, &c.IsNetworked,
|
||||
&metadata, &c.SortOrder, &c.CreatedAt, &c.UpdatedAt,
|
||||
&c.CEMarked, &c.PresenceStatus, &metadata, &c.SortOrder, &c.CreatedAt, &c.UpdatedAt,
|
||||
)
|
||||
if err == pgx.ErrNoRows {
|
||||
return nil, nil
|
||||
@@ -89,7 +95,7 @@ func (s *Store) ListComponents(ctx context.Context, projectID uuid.UUID) ([]Comp
|
||||
SELECT
|
||||
id, project_id, parent_id, name, component_type,
|
||||
version, description, is_safety_relevant, is_networked,
|
||||
metadata, sort_order, created_at, updated_at
|
||||
ce_marked, presence_status, metadata, sort_order, created_at, updated_at
|
||||
FROM iace_components WHERE project_id = $1
|
||||
ORDER BY sort_order ASC, created_at ASC
|
||||
`, projectID)
|
||||
@@ -107,7 +113,7 @@ func (s *Store) ListComponents(ctx context.Context, projectID uuid.UUID) ([]Comp
|
||||
err := rows.Scan(
|
||||
&c.ID, &c.ProjectID, &c.ParentID, &c.Name, &compType,
|
||||
&c.Version, &c.Description, &c.IsSafetyRelevant, &c.IsNetworked,
|
||||
&metadata, &c.SortOrder, &c.CreatedAt, &c.UpdatedAt,
|
||||
&c.CEMarked, &c.PresenceStatus, &metadata, &c.SortOrder, &c.CreatedAt, &c.UpdatedAt,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("list components scan: %w", err)
|
||||
@@ -150,6 +156,14 @@ func (s *Store) UpdateComponent(ctx context.Context, id uuid.UUID, updates map[s
|
||||
query += fmt.Sprintf(", is_networked = $%d", argIdx)
|
||||
args = append(args, val)
|
||||
argIdx++
|
||||
case "presence_status":
|
||||
query += fmt.Sprintf(", presence_status = $%d", argIdx)
|
||||
args = append(args, val)
|
||||
argIdx++
|
||||
case "ce_marked":
|
||||
query += fmt.Sprintf(", ce_marked = $%d", argIdx)
|
||||
args = append(args, val)
|
||||
argIdx++
|
||||
case "sort_order":
|
||||
query += fmt.Sprintf(", sort_order = $%d", argIdx)
|
||||
args = append(args, val)
|
||||
|
||||
Reference in New Issue
Block a user