Separate reconciliation preparation and proposal assessment from native execution

This commit is contained in:
2026-11-22 00:07:05 +00:00
parent 92c2382806
commit 2348730820
17 changed files with 327 additions and 1138 deletions

View File

@@ -1,12 +1,10 @@
package semanticreconcile
import (
"encoding/json"
"fmt"
"sort"
"strings"
"unicode/utf8"
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
)
// ProposalResponse is the complete private structured response contract.
@@ -14,6 +12,17 @@ type ProposalResponse struct {
DuplicateGroups []DuplicateGroup `json:"duplicate_groups"`
}
// DecodeProposal reads an already structurally validated native response.
// Native execution errors and failed validation must be handled before this
// function; decoding never requests another structural repair or execution.
func DecodeProposal(output string) (ProposalResponse, error) {
var response ProposalResponse
if err := json.Unmarshal([]byte(output), &response); err != nil {
return ProposalResponse{}, fmt.Errorf("decode semantic reconciliation proposal: %w", err)
}
return response, nil
}
// DuplicateGroup proposes supplied request-local candidate numbers that may
// denote one entity and identifies one supplied member as canonical.
type DuplicateGroup struct {
@@ -121,39 +130,6 @@ func CorrectionDetails(issues []Issue, numberRange CandidateNumberRange) ([]stri
return details, nil
}
// CorrectionGuidance builds one bounded request for a complete corrected
// proposal. Additional details let a typed owner append a domain rule without
// weakening or duplicating the shared protocol guidance.
func CorrectionGuidance(issues []Issue, numberRange CandidateNumberRange, additionalDetails ...string) (string, error) {
details, err := CorrectionDetails(issues, numberRange)
if err != nil {
return "", err
}
for _, detail := range additionalDetails {
if !utf8.ValidString(detail) {
return "", fmt.Errorf("semantic reconciliation additional correction detail has invalid UTF-8")
}
detail = strings.TrimSpace(detail)
if detail == "" {
return "", fmt.Errorf("semantic reconciliation additional correction detail must not be blank")
}
details = append(details, detail)
}
if len(details) == 0 {
return "", fmt.Errorf("semantic reconciliation correction guidance requires at least one detail")
}
parts := make([]string, 0, len(details)+2)
parts = append(parts, "The previous semantic-duplicate proposal was invalid.")
parts = append(parts, details...)
parts = append(parts, "Return one complete corrected JSON response that follows the original instructions; do not return a patch or commentary.")
guidance := strings.Join(parts, " ")
if len(guidance) > contracts.MaxNormalizeRetryCorrectionGuidanceBytes {
return "", fmt.Errorf("semantic reconciliation correction guidance exceeds maximum length")
}
return guidance, nil
}
func validateCorrectionRange(numberRange CandidateNumberRange) error {
if numberRange.First != 1 || numberRange.Last < 2 {
return fmt.Errorf("semantic reconciliation correction candidate-number range must start at 1 and include at least two candidates")
@@ -251,8 +227,8 @@ func (assessment Assessment) DiscardedGroupCount() int {
return assessment.discardedGroupCount
}
// RetryRequired reports whether any response group was discarded.
func (assessment Assessment) RetryRequired() bool {
// HasDiscardedGroups reports whether the proposal contains unsafe groups.
func (assessment Assessment) HasDiscardedGroups() bool {
return assessment.discardedGroupCount > 0
}