Files
audita/internal/framework/proposals/proposal.go

53 lines
1.6 KiB
Go
Raw Normal View History

2026-05-11 13:18:13 +00:00
package proposals
import (
"fmt"
"gitea.maximumdirect.net/eric/audita/v3/internal/core/schema"
2026-05-11 13:18:13 +00:00
)
// CorrectionProposal is the base proposal emitted by correction modules.
type CorrectionProposal struct {
TargetSegmentID int `json:"id"`
OriginalText string `json:"original_text"`
CorrectedText string `json:"corrected_text"`
2026-05-11 13:18:13 +00:00
}
// ProposalMetadata is framework-enriched execution metadata for a proposal.
type ProposalMetadata struct {
ProposalIndex int `json:"proposal_index"`
ModuleKey string `json:"module_key"`
ModuleInstance string `json:"module_instance"`
SectionIndex *int `json:"section_index,omitempty"`
}
// EnrichedCorrectionProposal combines module-emitted proposal data with
// framework execution metadata.
type EnrichedCorrectionProposal struct {
CorrectionProposal
ProposalMetadata
}
// Validate checks only basic structural integrity of the proposal.
// Semantic checks (staleness, span presence, replacement behavior) are handled
// by proposal preview/application and validator execution.
2026-05-11 13:18:13 +00:00
func (p CorrectionProposal) Validate() error {
if p.TargetSegmentID <= 0 {
return fmt.Errorf("proposal id must be positive")
}
if p.OriginalText == "" {
2026-05-11 13:18:13 +00:00
return fmt.Errorf("proposal original_text must not be empty")
}
return nil
}
// SegmentIDAtReference maps a one-based model reference in the supplied
// section to the transcript's segment ID. Zero represents an invalid reference.
func SegmentIDAtReference(section *schema.Transcript, reference int) int {
if section == nil || reference <= 0 || reference > len(section.Segments) {
return 0
}
return section.Segments[reference-1].ID
}