Files
breakpilot-compliance/ai-compliance-sdk/internal/maximizer/scoring.go
Benjamin Admin 1ac716261c
Some checks failed
Build + Deploy / build-admin-compliance (push) Successful in 1m45s
Build + Deploy / build-backend-compliance (push) Successful in 4m42s
Build + Deploy / build-ai-sdk (push) Successful in 46s
Build + Deploy / build-developer-portal (push) Successful in 1m6s
Build + Deploy / build-tts (push) Successful in 1m14s
Build + Deploy / build-document-crawler (push) Successful in 31s
Build + Deploy / build-dsms-gateway (push) Successful in 24s
CI / branch-name (push) Has been skipped
CI / guardrail-integrity (push) Has been skipped
CI / loc-budget (push) Failing after 15s
CI / secret-scan (push) Has been skipped
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / nodejs-build (push) Successful in 2m27s
CI / dep-audit (push) Has been skipped
CI / sbom-scan (push) Has been skipped
CI / test-go (push) Failing after 37s
CI / test-python-backend (push) Successful in 42s
CI / test-python-document-crawler (push) Successful in 25s
CI / test-python-dsms-gateway (push) Successful in 23s
CI / validate-canonical-controls (push) Successful in 18s
Build + Deploy / trigger-orca (push) Successful in 4m35s
feat: Compliance Maximizer — Regulatory Optimization Engine
Neues Modul das den regulatorischen Spielraum fuer KI-Use-Cases
deterministisch berechnet und optimale Konfigurationen vorschlaegt.

Kernfeatures:
- 13-Dimensionen Constraint-Space (DSGVO + AI Act)
- 3-Zonen-Analyse: Verboten / Eingeschraenkt / Erlaubt
- Deterministische Optimizer-Engine (kein LLM im Kern)
- 28 Constraint-Regeln aus DSGVO, AI Act, EDPB Guidelines
- 28 Tests (Golden Suite + Meta-Tests)
- REST API: /sdk/v1/maximizer/* (9 Endpoints)
- Frontend: 3-Zonen-Visualisierung, Dimension-Form, Score-Gauges

[migration-approved]

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-23 09:10:20 +02:00

85 lines
2.2 KiB
Go

package maximizer
// ScoreWeights controls the balance between safety and business utility.
type ScoreWeights struct {
Safety float64 `json:"safety"`
Utility float64 `json:"utility"`
}
// DefaultWeights prioritizes business utility slightly over safety margin
// since the optimizer already ensures compliance.
var DefaultWeights = ScoreWeights{Safety: 0.4, Utility: 0.6}
// dimensionBusinessWeight indicates how much business value each dimension
// contributes. Higher = more costly to change for the business.
var dimensionBusinessWeight = map[string]int{
"automation_level": 15,
"decision_binding": 12,
"deployment_scope": 10,
"model_type": 8,
"decision_impact": 7,
"explainability": 5,
"data_type": 5,
"human_in_loop": 5,
"legal_basis": 4,
"domain": 3,
"risk_classification": 3,
"transparency_required": 2,
"logging_required": 2,
}
// ComputeSafetyScore returns 0-100 where 100 = completely safe (no restrictions).
// Decreases with each RESTRICTED or FORBIDDEN zone.
func ComputeSafetyScore(eval *EvaluationResult) int {
if eval == nil {
return 0
}
total := len(allDimensions)
safe := 0
for _, zi := range eval.ZoneMap {
if zi.Zone == ZoneSafe {
safe++
}
}
if total == 0 {
return 100
}
return (safe * 100) / total
}
// ComputeUtilityScore returns 0-100 where 100 = no changes from original.
// Decreases based on the business weight of each changed dimension.
func ComputeUtilityScore(original, variant *DimensionConfig) int {
if original == nil || variant == nil {
return 0
}
deltas := original.Diff(variant)
if len(deltas) == 0 {
return 100
}
maxCost := 0
for _, w := range dimensionBusinessWeight {
maxCost += w
}
cost := 0
for _, d := range deltas {
w := dimensionBusinessWeight[d.Dimension]
if w == 0 {
w = 3 // default
}
cost += w
}
if cost >= maxCost {
return 0
}
return 100 - (cost*100)/maxCost
}
// ComputeCompositeScore combines safety and utility into a single ranking score.
func ComputeCompositeScore(safety, utility int, weights ScoreWeights) float64 {
return weights.Safety*float64(safety) + weights.Utility*float64(utility)
}