2026-08-05 19:13:37 +00:00
// Package locationregistry normalizes merged D&D location-registry candidates conservatively.
package locationregistry
2026-08-04 00:07:47 +00:00
import (
"context"
2026-08-09 02:26:49 +00:00
"encoding/json"
2026-08-04 00:07:47 +00:00
"fmt"
"reflect"
"sort"
"strconv"
"strings"
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
2026-08-09 16:51:29 +00:00
"gitea.maximumdirect.net/eric/notarius/internal/framework/semanticreconcile"
2026-08-04 00:07:47 +00:00
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/locations/identity"
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/shared"
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/shared/diagnostics"
)
const (
2026-08-09 16:51:29 +00:00
Key = "dnd/location-registry"
PromptID = "dnd.location_registry.normalize"
PromptVersion = "v1"
2026-08-28 18:25:00 +00:00
normalizationPolicy = "dnd.location_registry.normalize.v4"
2026-08-09 16:51:29 +00:00
NormalizationPolicy = normalizationPolicy
2026-08-04 00:07:47 +00:00
ReasonCodeLocationFieldsNormalized = "location_fields_normalized"
ReasonCodeLocationIDRecomputed = "location_id_recomputed"
ReasonCodeSourceReferencesNormalized = "source_references_normalized"
ReasonCodeDuplicateLocationCollapsed = "duplicate_location_collapsed"
ReasonCodeLocationSemanticProposalInvalid = "location_semantic_proposal_invalid"
ReasonCodeLocationSemanticReconciliationExhausted = "location_semantic_reconciliation_exhausted"
)
var requiredCapabilities = [ ] string { "merged" }
var providedCapabilities = [ ] string { "normalized" }
2026-08-05 19:05:42 +00:00
var _ contracts . Normalizer [ dnd . LocationRegistry ] = ( * Normalizer ) ( nil )
2026-08-04 00:07:47 +00:00
var _ contracts . ManifestMetadataProvider = ( * Normalizer ) ( nil )
var _ pipeline . CheckpointFingerprintProvider = ( * Normalizer ) ( nil )
type Options struct { }
type Normalizer struct {
2026-08-09 16:51:29 +00:00
engine * semanticreconcile . Engine
2026-08-04 00:07:47 +00:00
}
func New ( llmClient contracts . StructuredLLMClient , _ Options ) ( * Normalizer , error ) {
if llmClient == nil {
return nil , normalizerErrorf ( "LLM client must not be nil" )
}
promptSHA , err := promptAssetMetadata ( )
if err != nil {
return nil , normalizerErrorf ( "load prompt metadata: %w" , err )
}
2026-08-09 16:51:29 +00:00
engine , err := semanticreconcile . NewEngine ( llmClient , semanticreconcile . PromptSpec {
ID : PromptID , Version : PromptVersion , SHA256 : promptSHA ,
} , semanticreconcile . DefaultLimits ( ) )
2026-08-04 00:07:47 +00:00
if err != nil {
2026-08-09 16:51:29 +00:00
return nil , normalizerErrorf ( "construct semantic reconciliation engine: %w" , err )
2026-08-04 00:07:47 +00:00
}
2026-08-09 16:51:29 +00:00
return & Normalizer { engine : engine } , nil
2026-08-04 00:07:47 +00:00
}
func ( n * Normalizer ) Key ( ) string { return Key }
func ( n * Normalizer ) ReferenceSlots ( ) [ ] contracts . ReferenceSlot { return nil }
func ( n * Normalizer ) ManifestMetadata ( ) map [ string ] any {
2026-08-09 16:51:29 +00:00
if n == nil || n . engine == nil {
2026-08-04 00:07:47 +00:00
return nil
}
2026-08-09 16:51:29 +00:00
metadata := n . engine . ManifestMetadata ( )
metadata [ "identity_policy" ] = identity . Policy
metadata [ "normalization_policy" ] = normalizationPolicy
return metadata
2026-08-04 00:07:47 +00:00
}
func ( n * Normalizer ) CheckpointFingerprints ( ) [ ] pipeline . CheckpointFingerprint {
2026-08-09 16:51:29 +00:00
if n == nil || n . engine == nil {
2026-08-04 00:07:47 +00:00
return nil
}
2026-08-09 16:51:29 +00:00
fingerprints := n . engine . CheckpointFingerprints ( )
return append ( fingerprints ,
pipeline . CheckpointFingerprint { Name : "identity_policy" , Value : identity . Policy } ,
pipeline . CheckpointFingerprint { Name : "normalization_policy" , Value : normalizationPolicy } ,
)
2026-08-04 00:07:47 +00:00
}
2026-08-05 19:05:42 +00:00
func ( n * Normalizer ) Normalize ( ctx context . Context , req contracts . TypedNormalizeRequest [ dnd . LocationRegistry ] ) ( contracts . TypedNormalizeResult [ dnd . LocationRegistry ] , error ) {
2026-08-04 00:07:47 +00:00
if n == nil {
2026-08-05 19:05:42 +00:00
return contracts . TypedNormalizeResult [ dnd . LocationRegistry ] { } , normalizerErrorf ( "normalizer must not be nil" )
2026-08-04 00:07:47 +00:00
}
2026-08-09 16:51:29 +00:00
if n . engine == nil {
return contracts . TypedNormalizeResult [ dnd . LocationRegistry ] { } , normalizerErrorf ( "semantic reconciliation engine must not be nil" )
2026-08-04 00:07:47 +00:00
}
if ctx == nil {
2026-08-05 19:05:42 +00:00
return contracts . TypedNormalizeResult [ dnd . LocationRegistry ] { } , normalizerErrorf ( "context must not be nil" )
2026-08-04 00:07:47 +00:00
}
if err := ctx . Err ( ) ; err != nil {
2026-08-05 19:05:42 +00:00
return contracts . TypedNormalizeResult [ dnd . LocationRegistry ] { } , normalizerErrorf ( "context error before normalize: %w" , err )
2026-08-04 00:07:47 +00:00
}
2026-08-09 18:30:32 +00:00
if req . Source == nil {
return contracts . TypedNormalizeResult [ dnd . LocationRegistry ] { } , normalizerErrorf ( "source document must not be nil" )
}
2026-08-04 00:07:47 +00:00
order := shared . NewSourceRefOrder ( req . Source )
2026-08-27 15:57:29 +00:00
records , findings := preprocessRecords ( req . MergeOutput . Value , order )
2026-08-04 00:07:47 +00:00
deterministic := recordList ( records )
2026-08-09 18:30:32 +00:00
if len ( records ) < 2 {
2026-08-27 15:57:29 +00:00
return normalizationResult ( deterministic , findings , nil )
2026-08-09 16:51:29 +00:00
}
candidates , envelopes , err := reconciliationInputs ( records )
if err != nil {
return contracts . TypedNormalizeResult [ dnd . LocationRegistry ] { } , normalizerErrorf ( "prepare semantic reconciliation inputs: %w" , err )
}
reconciliation , err := n . engine . Reconcile ( ctx , semanticreconcile . Request {
StageName : Key , Source : req . Source , Candidates : candidates ,
2026-08-27 00:08:05 +00:00
ProfileID : req . LLMProfile , SessionID : req . SessionID , StructuredOutputRepairAttempts : req . StructuredOutputRepairAttempts , Correction : req . Correction ,
2026-08-09 16:51:29 +00:00
} )
2026-08-04 00:07:47 +00:00
if err != nil {
2026-08-09 16:51:29 +00:00
return contracts . TypedNormalizeResult [ dnd . LocationRegistry ] { } , normalizerErrorf ( "reconcile semantic duplicates: %w" , err )
2026-08-04 00:07:47 +00:00
}
2026-08-09 16:51:29 +00:00
switch reconciliation . Disposition ( ) {
case semanticreconcile . SkippedInsufficientCandidates :
2026-08-27 15:57:29 +00:00
return normalizationResult ( deterministic , findings , nil )
2026-08-09 16:51:29 +00:00
case semanticreconcile . SkippedLimitExceeded :
2026-08-28 18:25:00 +00:00
return fallbackResult ( deterministic , findings , semanticFallbackFinding ( - 1 , "the candidate set exceeded the configured semantic-reconciliation limits" ) )
2026-08-09 16:51:29 +00:00
case semanticreconcile . RetryableInvalidStructuredOutput :
2026-08-27 15:57:29 +00:00
return n . invalidStructuredResult ( deterministic , findings )
2026-08-09 16:51:29 +00:00
case semanticreconcile . Complete , semanticreconcile . RetryableDiscardedProposalGroups :
default :
return contracts . TypedNormalizeResult [ dnd . LocationRegistry ] { } , normalizerErrorf ( "unknown semantic reconciliation disposition %d" , reconciliation . Disposition ( ) )
2026-08-04 00:07:47 +00:00
}
2026-08-27 15:57:29 +00:00
applied , semanticFindings , err := applyReconciliationPlan ( reconciliation . Plan ( ) , records , envelopes , order )
2026-08-09 16:51:29 +00:00
if err != nil {
return contracts . TypedNormalizeResult [ dnd . LocationRegistry ] { } , normalizerErrorf ( "apply semantic reconciliation plan: %w" , err )
2026-08-04 00:07:47 +00:00
}
2026-08-27 15:57:29 +00:00
findings = append ( findings , semanticFindings ... )
2026-08-09 16:51:29 +00:00
if reconciliation . Disposition ( ) == semanticreconcile . Complete {
2026-08-27 15:57:29 +00:00
return normalizationResult ( recordList ( applied ) , findings , reconciliation . ModelCandidate ( ) )
2026-08-04 00:07:47 +00:00
}
2026-08-27 15:57:29 +00:00
return retryResult ( recordList ( applied ) , findings , reconciliation )
2026-08-04 00:07:47 +00:00
}
2026-08-27 16:40:17 +00:00
func ( n * Normalizer ) invalidStructuredResult ( value dnd . LocationRegistry , findings [ ] diagnostics . Finding ) ( contracts . TypedNormalizeResult [ dnd . LocationRegistry ] , error ) {
2026-08-28 18:25:00 +00:00
return retryResultWithFallback ( value , findings , nil , "" , "semantic proposal requires retry: invalid structured output" , semanticFallbackFinding ( - 1 , "the final model response did not satisfy the structured-output contract" ) )
2026-08-04 00:07:47 +00:00
}
2026-08-27 16:40:17 +00:00
func retryResult ( value dnd . LocationRegistry , findings [ ] diagnostics . Finding , reconciliation semanticreconcile . Result ) ( contracts . TypedNormalizeResult [ dnd . LocationRegistry ] , error ) {
2026-08-28 18:25:00 +00:00
issues := reconciliation . Issues ( )
2026-08-29 03:16:24 +00:00
correctionDetails , err := reconciliation . CorrectionDetails ( )
2026-08-28 18:25:00 +00:00
if err != nil {
return contracts . TypedNormalizeResult [ dnd . LocationRegistry ] { } , normalizerErrorf ( "build semantic correction details: %w" , err )
}
2026-08-29 03:16:24 +00:00
correctionGuidance , err := reconciliation . CorrectionGuidance ( )
2026-08-28 18:25:00 +00:00
if err != nil {
return contracts . TypedNormalizeResult [ dnd . LocationRegistry ] { } , normalizerErrorf ( "build semantic correction guidance: %w" , err )
}
return retryResultWithFallback ( value , findings , reconciliation . ModelCandidate ( ) , correctionGuidance , diagnostics . Aggregate ( "semantic proposal requires retry" , semanticreconcile . IssueDetails ( issues ) ) , semanticFallbackFinding ( reconciliation . DiscardedGroupCount ( ) , correctionDetails ... ) )
2026-08-04 00:07:47 +00:00
}
2026-08-28 18:25:00 +00:00
func semanticFallbackFinding ( discarded int , details ... string ) diagnostics . Finding {
message := "semantic reconciliation could not be completed; all affected candidates were preserved separately"
2026-08-04 00:07:47 +00:00
if discarded >= 0 {
2026-08-28 18:25:00 +00:00
message = fmt . Sprintf ( "%d proposal group(s) omitted from the final semantic proposal; all affected candidates were preserved separately" , discarded )
}
if len ( details ) > 0 {
message = diagnostics . Aggregate ( message , details )
2026-08-04 00:07:47 +00:00
}
2026-08-27 16:40:17 +00:00
return diagnostics . Finding { Scope : "locations" , ReasonCode : ReasonCodeLocationSemanticReconciliationExhausted , Message : message }
2026-08-04 00:07:47 +00:00
}
2026-08-27 16:40:17 +00:00
func normalizationResult ( value dnd . LocationRegistry , findings [ ] diagnostics . Finding , candidate * contracts . ModelCandidate ) ( contracts . TypedNormalizeResult [ dnd . LocationRegistry ] , error ) {
2026-08-27 15:57:29 +00:00
diagnosticGroups , err := diagnostics . Collect ( findings , contracts . DiagnosticDispositionObservation , contracts . DiagnosticCategoryNormalization )
if err != nil {
return contracts . TypedNormalizeResult [ dnd . LocationRegistry ] { } , normalizerErrorf ( "collect normalization diagnostics: %w" , err )
}
return contracts . TypedNormalizeResult [ dnd . LocationRegistry ] { Value : value , Diagnostics : diagnosticGroups , ModelCandidate : candidate } , nil
2026-08-04 00:07:47 +00:00
}
2026-08-27 16:40:17 +00:00
func fallbackResult ( value dnd . LocationRegistry , findings [ ] diagnostics . Finding , fallback diagnostics . Finding ) ( contracts . TypedNormalizeResult [ dnd . LocationRegistry ] , error ) {
2026-08-27 15:57:29 +00:00
result , err := normalizationResult ( value , findings , nil )
if err != nil {
return contracts . TypedNormalizeResult [ dnd . LocationRegistry ] { } , err
2026-08-04 00:07:47 +00:00
}
2026-08-27 16:40:17 +00:00
fallbackGroups , err := diagnostics . Collect ( [ ] diagnostics . Finding { fallback } , contracts . DiagnosticDispositionWarning , contracts . DiagnosticCategoryFallback )
2026-08-27 15:57:29 +00:00
if err != nil {
return contracts . TypedNormalizeResult [ dnd . LocationRegistry ] { } , normalizerErrorf ( "collect fallback diagnostic: %w" , err )
2026-08-04 00:07:47 +00:00
}
2026-08-27 15:57:29 +00:00
result . Diagnostics = append ( result . Diagnostics , fallbackGroups ... )
return result , nil
2026-08-04 00:07:47 +00:00
}
2026-08-28 18:25:00 +00:00
func retryResultWithFallback ( value dnd . LocationRegistry , findings [ ] diagnostics . Finding , candidate * contracts . ModelCandidate , correctionGuidance , message string , fallback diagnostics . Finding ) ( contracts . TypedNormalizeResult [ dnd . LocationRegistry ] , error ) {
2026-08-27 15:57:29 +00:00
result , err := normalizationResult ( value , findings , candidate )
if err != nil {
return contracts . TypedNormalizeResult [ dnd . LocationRegistry ] { } , err
}
2026-08-27 16:40:17 +00:00
fallbackGroups , err := diagnostics . Collect ( [ ] diagnostics . Finding { fallback } , contracts . DiagnosticDispositionWarning , contracts . DiagnosticCategoryFallback )
2026-08-27 15:57:29 +00:00
if err != nil {
return contracts . TypedNormalizeResult [ dnd . LocationRegistry ] { } , normalizerErrorf ( "collect fallback diagnostic: %w" , err )
}
2026-08-28 18:25:00 +00:00
result . Retry = & contracts . NormalizeRetry { ReasonCode : ReasonCodeLocationSemanticProposalInvalid , Message : message , CorrectionGuidance : correctionGuidance , FallbackDiagnostics : fallbackGroups }
2026-08-27 15:57:29 +00:00
return result , nil
2026-08-09 16:51:29 +00:00
}
2026-08-04 00:07:47 +00:00
type normalizedRecord struct {
location dnd . Location
inputIndexes [ ] int
earliest int
}
2026-08-27 16:40:17 +00:00
func preprocessRecords ( input dnd . LocationRegistry , order shared . SourceRefOrder ) ( [ ] normalizedRecord , [ ] diagnostics . Finding ) {
2026-08-04 00:07:47 +00:00
if input . Locations == nil {
return nil , nil
}
records := make ( [ ] normalizedRecord , len ( input . Locations ) )
2026-08-27 18:41:59 +00:00
findings := make ( [ ] diagnostics . Finding , 0 )
2026-08-04 00:07:47 +00:00
for index , inputLocation := range input . Locations {
location , fieldsChanged , refsChanged := normalizeRecord ( inputLocation , order )
records [ index ] = normalizedRecord { location : location , inputIndexes : [ ] int { index } , earliest : index }
if fieldsChanged {
2026-08-27 18:41:59 +00:00
findings = append ( findings , diagnostics . Finding { Scope : locationScope ( index ) , ReasonCode : ReasonCodeLocationFieldsNormalized , Message : fmt . Sprintf ( "input index %d: location name normalized for %s" , index , diagnostics . Quote ( inputLocation . Name ) ) } )
2026-08-04 00:07:47 +00:00
}
if refsChanged {
2026-08-27 18:41:59 +00:00
findings = append ( findings , diagnostics . Finding { Scope : locationScope ( index ) , ReasonCode : ReasonCodeSourceReferencesNormalized , Message : fmt . Sprintf ( "input index %d: source references normalized (original count %d, final count %d)" , index , len ( inputLocation . SourceRefs ) , len ( location . SourceRefs ) ) } )
2026-08-04 00:07:47 +00:00
}
if inputLocation . ID != location . ID {
2026-08-27 18:41:59 +00:00
findings = append ( findings , diagnostics . Finding { Scope : locationScope ( index ) , ReasonCode : ReasonCodeLocationIDRecomputed , Message : fmt . Sprintf ( "input index %d: location ID recomputed from %s" , index , diagnostics . Quote ( location . Name ) ) } )
2026-08-04 00:07:47 +00:00
}
}
groups := exactDuplicateGroups ( records )
output := make ( [ ] normalizedRecord , 0 , len ( groups ) )
for _ , members := range groups {
retained := cloneRecord ( records [ members [ 0 ] ] )
for _ , member := range members [ 1 : ] {
retained . inputIndexes = append ( retained . inputIndexes , records [ member ] . inputIndexes ... )
}
retained . inputIndexes = sortedUniqueIndexes ( retained . inputIndexes )
output = append ( output , retained )
if len ( members ) > 1 {
2026-08-27 18:41:59 +00:00
findings = append ( findings , duplicateFinding ( retained . earliest , memberInputIndexes ( records , members [ 1 : ] ) ) )
2026-08-04 00:07:47 +00:00
}
}
2026-08-27 18:41:59 +00:00
return output , findings
2026-08-04 00:07:47 +00:00
}
func normalizeRecord ( input dnd . Location , order shared . SourceRefOrder ) ( dnd . Location , bool , bool ) {
output := cloneLocation ( input )
output . Name = identity . NormalizeDisplay ( input . Name )
output . SourceRefs = order . Canonicalize ( input . SourceRefs )
output . ID = identity . DeriveID ( output . Name , output . SourceRefs )
return output , input . Name != output . Name , ! reflect . DeepEqual ( input . SourceRefs , output . SourceRefs )
}
func exactDuplicateGroups ( records [ ] normalizedRecord ) [ ] [ ] int {
groups := make ( [ ] [ ] int , 0 , len ( records ) )
2026-08-09 02:26:49 +00:00
groupPositions := make ( map [ string ] [ ] int , len ( records ) )
2026-08-04 00:07:47 +00:00
for index , record := range records {
2026-08-09 02:26:49 +00:00
key := exactDuplicateKey ( record . location )
comparisonName := identity . ComparisonKey ( record . location . Name )
matched := false
for _ , groupIndex := range groupPositions [ key ] {
first := records [ groups [ groupIndex ] [ 0 ] ]
if identity . ComparisonKey ( first . location . Name ) == comparisonName && reflect . DeepEqual ( first . location . SourceRefs , record . location . SourceRefs ) {
2026-08-04 00:07:47 +00:00
groups [ groupIndex ] = append ( groups [ groupIndex ] , index )
2026-08-09 02:26:49 +00:00
matched = true
2026-08-04 00:07:47 +00:00
break
}
}
2026-08-09 02:26:49 +00:00
if matched {
continue
2026-08-04 00:07:47 +00:00
}
2026-08-09 02:26:49 +00:00
groupPositions [ key ] = append ( groupPositions [ key ] , len ( groups ) )
groups = append ( groups , [ ] int { index } )
2026-08-04 00:07:47 +00:00
}
return groups
}
2026-08-09 02:26:49 +00:00
type duplicateKey struct {
ComparisonName string ` json:"comparison_name" `
SourceRefs [ ] source . SourceRef ` json:"source_refs" `
}
func exactDuplicateKey ( location dnd . Location ) string {
encoded , err := json . Marshal ( duplicateKey {
ComparisonName : identity . ComparisonKey ( location . Name ) ,
SourceRefs : location . SourceRefs ,
} )
if err != nil {
panic ( "encode location duplicate key" )
}
return string ( encoded )
}
2026-08-04 00:07:47 +00:00
func cloneLocation ( input dnd . Location ) dnd . Location {
input . SourceRefs = cloneSourceRefs ( input . SourceRefs )
return input
}
func cloneRecord ( input normalizedRecord ) normalizedRecord {
input . location = cloneLocation ( input . location )
input . inputIndexes = append ( [ ] int ( nil ) , input . inputIndexes ... )
return input
}
func cloneSourceRefs ( input [ ] source . SourceRef ) [ ] source . SourceRef {
if input == nil {
return nil
}
return append ( [ ] source . SourceRef ( nil ) , input ... )
}
func sortedUniqueIndexes ( indexes [ ] int ) [ ] int {
if len ( indexes ) == 0 {
return nil
}
out := append ( [ ] int ( nil ) , indexes ... )
sort . Ints ( out )
write := 1
for _ , index := range out [ 1 : ] {
if index != out [ write - 1 ] {
out [ write ] = index
write ++
}
}
return out [ : write ]
}
func memberInputIndexes ( records [ ] normalizedRecord , members [ ] int ) [ ] int {
indexes := make ( [ ] int , 0 , len ( members ) )
for _ , member := range members {
indexes = append ( indexes , records [ member ] . inputIndexes ... )
}
return sortedUniqueIndexes ( indexes )
}
func recordValues ( records [ ] normalizedRecord ) [ ] dnd . Location {
if records == nil {
return nil
}
values := make ( [ ] dnd . Location , len ( records ) )
for index , record := range records {
values [ index ] = cloneLocation ( record . location )
}
return values
}
2026-08-05 19:05:42 +00:00
func recordList ( records [ ] normalizedRecord ) dnd . LocationRegistry {
2026-08-04 00:07:47 +00:00
if records == nil {
2026-08-05 19:05:42 +00:00
return dnd . LocationRegistry { }
2026-08-04 00:07:47 +00:00
}
2026-08-05 19:05:42 +00:00
return dnd . LocationRegistry { Locations : recordValues ( records ) }
2026-08-04 00:07:47 +00:00
}
2026-08-27 18:41:59 +00:00
func duplicateFinding ( retainedIndex int , removed [ ] int ) diagnostics . Finding {
2026-08-04 00:07:47 +00:00
const maxDisplayedIndices = 20
displayed := removed
if len ( displayed ) > maxDisplayedIndices {
displayed = displayed [ : maxDisplayedIndices ]
}
indices := make ( [ ] string , len ( displayed ) )
for index , removedIndex := range displayed {
indices [ index ] = strconv . Itoa ( removedIndex )
}
message := fmt . Sprintf ( "retained input index %d; removed input indices [%s]" , retainedIndex , strings . Join ( indices , ", " ) )
if omitted := len ( removed ) - len ( displayed ) ; omitted > 0 {
message += fmt . Sprintf ( "; %d additional removed input indices omitted" , omitted )
}
2026-08-27 16:40:17 +00:00
return diagnostics . Finding { Scope : locationScope ( retainedIndex ) , ReasonCode : ReasonCodeDuplicateLocationCollapsed , Message : message }
2026-08-04 00:07:47 +00:00
}
func locationScope ( index int ) string { return fmt . Sprintf ( "locations[%d]" , index ) }
func ModuleSpec ( ) pipeline . ModuleSpec {
2026-08-27 00:08:05 +00:00
return pipeline . ModuleSpec { Key : Key , Stage : pipeline . StageNormalize , ExecutionClass : contracts . ExecutionClassLLMBacked , CorrectionProtocol : contracts . CorrectionProtocolSingleResponseV1 , Requires : append ( [ ] string ( nil ) , requiredCapabilities ... ) , Provides : append ( [ ] string ( nil ) , providedCapabilities ... ) , ArtifactKind : dnd . LocationRegistryKind }
2026-08-04 00:07:47 +00:00
}
func Register ( registry * pipeline . NormalizerRegistry ) error {
2026-08-05 19:05:42 +00:00
return pipeline . RegisterNormalizerBuilder ( registry , ModuleSpec ( ) , validateOptions , func ( request pipeline . BuildRequest ) ( contracts . Normalizer [ dnd . LocationRegistry ] , error ) {
2026-08-04 00:07:47 +00:00
options , err := DecodeOptions ( request . Options )
if err != nil {
return nil , err
}
return New ( request . Dependencies . LLM , options )
} )
}
func validateOptions ( options map [ string ] any ) error { _ , err := DecodeOptions ( options ) ; return err }
func DecodeOptions ( options map [ string ] any ) ( Options , error ) {
if err := pipeline . RejectUnknownOptions ( options ) ; err != nil {
return Options { } , normalizerErrorf ( "%w" , err )
}
return Options { } , nil
}
func normalizerErrorf ( format string , args ... any ) error {
2026-08-05 19:13:37 +00:00
return fmt . Errorf ( "dnd location registry normalizer: " + format , args ... )
2026-08-04 00:07:47 +00:00
}