245 lines
9.1 KiB
Go
245 lines
9.1 KiB
Go
package self
|
|
|
|
import "fmt"
|
|
|
|
type AssessmentID string
|
|
type LearningLedgerEntryID string
|
|
type AssessmentState string
|
|
|
|
type LearningSignalKind string
|
|
type DiagnosisClass string
|
|
type EpistemicStatus string
|
|
type InterventionClass string
|
|
type DecisionRegretKind string
|
|
type CandidateState string
|
|
|
|
const (
|
|
SignalVerifiedFailure LearningSignalKind = "VERIFIED_FAILURE"
|
|
SignalUserCorrection LearningSignalKind = "USER_CORRECTION"
|
|
SignalRepeatedMistake LearningSignalKind = "REPEATED_KNOWN_MISTAKE"
|
|
SignalReflexDivergence LearningSignalKind = "REFLEX_DIVERGENCE"
|
|
SignalSkillFallback LearningSignalKind = "SKILL_FALLBACK"
|
|
SignalUnexpectedEscalation LearningSignalKind = "UNEXPECTED_ESCALATION"
|
|
SignalOutcomeMismatch LearningSignalKind = "OUTCOME_MISMATCH"
|
|
SignalRetryFallback LearningSignalKind = "RETRY_FALLBACK"
|
|
SignalStaleDependency LearningSignalKind = "STALE_DEPENDENCY"
|
|
SignalDecisionRegret LearningSignalKind = "DECISION_REGRET"
|
|
SignalBetterSolution LearningSignalKind = "BETTER_SOLUTION"
|
|
DiagnosisMemoryMissing DiagnosisClass = "MEMORY_MISSING"
|
|
DiagnosisMemoryNotRetrieved DiagnosisClass = "MEMORY_NOT_RETRIEVED"
|
|
DiagnosisWrongScope DiagnosisClass = "WRONG_SCOPE"
|
|
DiagnosisStaleKnowledge DiagnosisClass = "STALE_KNOWLEDGE"
|
|
DiagnosisContextSelection DiagnosisClass = "CONTEXT_SELECTION"
|
|
DiagnosisReasoningFailure DiagnosisClass = "REASONING_FAILURE"
|
|
DiagnosisSkillFailure DiagnosisClass = "SKILL_FAILURE"
|
|
DiagnosisReflexFailure DiagnosisClass = "REFLEX_FAILURE"
|
|
DiagnosisToolFailure DiagnosisClass = "TOOL_FAILURE"
|
|
DiagnosisProviderFailure DiagnosisClass = "PROVIDER_FAILURE"
|
|
DiagnosisOutcomeVerificationFailure DiagnosisClass = "OUTCOME_VERIFICATION_FAILURE"
|
|
DiagnosisRoutingInefficiency DiagnosisClass = "ROUTING_INEFFICIENCY"
|
|
DiagnosisUnknown DiagnosisClass = "UNKNOWN_CAUSE"
|
|
EpistemicKnown EpistemicStatus = "KNOWN"
|
|
EpistemicSupported EpistemicStatus = "SUPPORTED"
|
|
EpistemicHypothesis EpistemicStatus = "HYPOTHESIS"
|
|
EpistemicUnknown EpistemicStatus = "UNKNOWN"
|
|
InterventionConfiguration InterventionClass = "CONFIGURATION"
|
|
InterventionSkillReview InterventionClass = "SKILL_REVIEW"
|
|
InterventionReflexReview InterventionClass = "REFLEX_REVIEW"
|
|
InterventionRoutingReview InterventionClass = "ROUTING_REVIEW"
|
|
InterventionProviderReview InterventionClass = "PROVIDER_REVIEW"
|
|
InterventionContextReview InterventionClass = "CONTEXT_REVIEW"
|
|
RegretUnavailableThen DecisionRegretKind = "INFORMATION_UNAVAILABLE_THEN"
|
|
RegretAvailableUnused DecisionRegretKind = "INFORMATION_AVAILABLE_UNUSED"
|
|
RegretIgnoredInContext DecisionRegretKind = "EVIDENCE_IGNORED_IN_CONTEXT"
|
|
CandidateProposed CandidateState = "PROPOSED"
|
|
CandidateEvaluating CandidateState = "EVALUATING"
|
|
CandidateKept CandidateState = "KEPT"
|
|
CandidateRejected CandidateState = "REJECTED"
|
|
CandidateRolledBack CandidateState = "ROLLED_BACK"
|
|
)
|
|
|
|
const (
|
|
AssessmentCandidate AssessmentState = "CANDIDATE"
|
|
AssessmentConfirmed AssessmentState = "CONFIRMED"
|
|
AssessmentMonitoring AssessmentState = "MONITORING"
|
|
AssessmentResolved AssessmentState = "RESOLVED"
|
|
)
|
|
|
|
type CompetenceAssessment struct {
|
|
ID AssessmentID
|
|
PrincipalID string
|
|
SubjectRef SemanticReference
|
|
Revision uint64
|
|
ContextMatcher []string
|
|
QualityMillis int64
|
|
ReliabilityMillis int64
|
|
ConfidenceMillis int64
|
|
EvidenceRefs []SemanticReference
|
|
LastValidatedAt int64
|
|
AssessedAt int64
|
|
SupersedesRef *SemanticReference
|
|
}
|
|
type WeaknessPattern struct {
|
|
ID AssessmentID
|
|
PrincipalID string
|
|
Revision uint64
|
|
PatternKey string
|
|
ContextMatcher []string
|
|
FailureMode string
|
|
DetectionEvidenceRefs []SemanticReference
|
|
State AssessmentState
|
|
RecordedAt int64
|
|
TaskPattern string
|
|
ScopeKey string
|
|
EnvironmentVersion string
|
|
DependencyRefs []SemanticReference
|
|
Frequency int
|
|
LastObservedAt int64
|
|
Severity int
|
|
AffectedComponent string
|
|
AffectedStrategy string
|
|
ConfidenceMillis int64
|
|
EpistemicStatus EpistemicStatus
|
|
}
|
|
type DependencyAssessment struct {
|
|
ID AssessmentID
|
|
SubjectRef SemanticReference
|
|
DependencyRef SemanticReference
|
|
ImpactClass string
|
|
CurrentEffect string
|
|
EvidenceRefs []SemanticReference
|
|
AssessedAt int64
|
|
}
|
|
type ImprovementNeed struct {
|
|
ID AssessmentID
|
|
PrincipalID string
|
|
SubjectRef SemanticReference
|
|
ProblemSummary string
|
|
EvidenceRefs []SemanticReference
|
|
ExpectedBenefit string
|
|
Priority int
|
|
State string
|
|
CreatedAt int64
|
|
Diagnosis DiagnosisClass
|
|
DiagnosisStatus EpistemicStatus
|
|
AffectedComponent string
|
|
ScopeKey string
|
|
Risk string
|
|
Intervention InterventionClass
|
|
Hypothesis string
|
|
EvaluationPlan string
|
|
MustNotWorsen string
|
|
RollbackPlan string
|
|
ResourceCost string
|
|
}
|
|
|
|
type LearningSignal struct {
|
|
ID string
|
|
PrincipalID string
|
|
Kind LearningSignalKind
|
|
TaskPattern string
|
|
ScopeKey string
|
|
SubjectRef SemanticReference
|
|
EvidenceRefs []SemanticReference
|
|
ExpectedOutcome string
|
|
ActualOutcome string
|
|
DependencyRefs []SemanticReference
|
|
EnvironmentVersion string
|
|
ObservedAt int64
|
|
Severity int
|
|
UserImpact int
|
|
CorrectionCount int
|
|
DecisionRegret DecisionRegretKind
|
|
}
|
|
|
|
type Diagnosis struct {
|
|
Class DiagnosisClass
|
|
Status EpistemicStatus
|
|
Rationale string
|
|
EvidenceRefs []SemanticReference
|
|
ConfidenceMillis int64
|
|
}
|
|
|
|
type ImprovementCandidate struct {
|
|
ID string
|
|
PrincipalID string
|
|
NeedRef SemanticReference
|
|
Hypothesis string
|
|
ExpectedEffect string
|
|
EvaluationPlan string
|
|
MustNotWorsen []string
|
|
RollbackPlan string
|
|
ResourceCost string
|
|
Creator string
|
|
IndependentEvaluator string
|
|
State CandidateState
|
|
EvidenceRefs []SemanticReference
|
|
CreatedAt int64
|
|
}
|
|
|
|
type ImprovementEvaluation struct {
|
|
CandidateRef SemanticReference
|
|
Evaluator string
|
|
EvidenceRefs []SemanticReference
|
|
ExpectedQuality int64
|
|
ActualQuality int64
|
|
ExpectedLatency int64
|
|
ActualLatency int64
|
|
MustNotWorsenPass bool
|
|
Decision CandidateState
|
|
EvaluatedAt int64
|
|
}
|
|
type LearningLedgerEntry struct {
|
|
ID LearningLedgerEntryID
|
|
PrincipalID string
|
|
ImprovementNeedRef *SemanticReference
|
|
ObservedProblem string
|
|
EvidenceRefs []SemanticReference
|
|
Diagnosis string
|
|
Hypothesis string
|
|
ProposedChangeRef SemanticReference
|
|
ExpectedImprovement string
|
|
ActualEvaluationRefs []SemanticReference
|
|
DevelopmentGateRef *SemanticReference
|
|
BeforeVersionRefs []SemanticReference
|
|
AfterVersionRefs []SemanticReference
|
|
Decision string
|
|
SideEffects []string
|
|
RollbackRef *SemanticReference
|
|
RecordedAt int64
|
|
}
|
|
|
|
func (a CompetenceAssessment) Validate() error {
|
|
if a.ID == "" || a.PrincipalID == "" || !a.SubjectRef.Valid() || a.Revision < 1 || a.ConfidenceMillis < 0 || a.ConfidenceMillis > 1000 || len(a.EvidenceRefs) == 0 || a.AssessedAt < 1 {
|
|
return fmt.Errorf("competence requires evidence")
|
|
}
|
|
return nil
|
|
}
|
|
func (l LearningLedgerEntry) Validate() error {
|
|
if l.ID == "" || l.PrincipalID == "" || l.ObservedProblem == "" || len(l.EvidenceRefs) == 0 || l.Decision == "" || l.RecordedAt < 1 {
|
|
return fmt.Errorf("learning ledger entry is incomplete")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (s LearningSignal) Validate() error {
|
|
if s.ID == "" || s.PrincipalID == "" || s.Kind == "" || s.TaskPattern == "" || s.ScopeKey == "" || !s.SubjectRef.Valid() || len(s.EvidenceRefs) == 0 || s.ObservedAt < 1 {
|
|
return fmt.Errorf("learning signal is incomplete")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (d Diagnosis) Validate() error {
|
|
if d.Class == "" || d.Status == "" || len(d.EvidenceRefs) == 0 || d.ConfidenceMillis < 0 || d.ConfidenceMillis > 1000 {
|
|
return fmt.Errorf("diagnosis requires bounded evidence")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (c ImprovementCandidate) Validate() error {
|
|
if c.ID == "" || c.PrincipalID == "" || !c.NeedRef.Valid() || c.Hypothesis == "" || c.ExpectedEffect == "" || c.EvaluationPlan == "" || c.MustNotWorsen == nil || c.RollbackPlan == "" || c.Creator == "" || c.IndependentEvaluator == "" || c.Creator == c.IndependentEvaluator || len(c.EvidenceRefs) == 0 || c.CreatedAt < 1 {
|
|
return fmt.Errorf("candidate lacks independent bounded evaluation")
|
|
}
|
|
return nil
|
|
}
|