feat(gen2): add experience skill reflex lifecycle

This commit is contained in:
m
2026-08-30 21:56:33 +03:00
parent a07aba056d
commit 8ec7c7419f
17 changed files with 523 additions and 32 deletions
+51 -8
View File
@@ -9,6 +9,7 @@ import (
var ErrInvalidSkillProfile = errors.New("invalid skill profile")
var ErrInvalidFastPathInput = errors.New("invalid fast path input")
var ErrInsufficientSkillEvidence = errors.New("insufficient independent skill evidence")
func ValidateSkillProfile(value capability.SkillProfile) error {
if value.ID == "" || value.Revision < 1 || strings.TrimSpace(value.Name) == "" ||
@@ -17,13 +18,59 @@ func ValidateSkillProfile(value capability.SkillProfile) error {
return ErrInvalidSkillProfile
}
switch value.Status {
case capability.SkillCandidate, capability.SkillEvaluating, capability.SkillValidated, capability.SkillDegraded, capability.SkillSuspended, capability.SkillRetired:
case capability.SkillCandidate, capability.SkillEvaluating, capability.SkillValidated, capability.SkillActive, capability.SkillDegraded, capability.SkillSuspended, capability.SkillRetired:
default:
return ErrInvalidSkillProfile
}
return nil
}
// CandidateFromVerifiedExperience starts a reusable approach but deliberately
// does not validate or activate it. Evidence stays in Epistemics by reference.
func CandidateFromVerifiedExperience(profile capability.SkillProfile, experience capability.SkillEvidenceRef, verified bool, recordedAt int64) (capability.SkillProfile, error) {
if err := ValidateSkillProfile(profile); err != nil || experience == "" || !verified || recordedAt < 1 {
return capability.SkillProfile{}, ErrInvalidSkillProfile
}
next := profile
next.Revision++
next.Status = capability.SkillCandidate
next.SupportingExperienceRefs = appendEvidenceRef(next.SupportingExperienceRefs, experience)
next.VerifiedOutcomeCount++
next.RecordedAtUnixMillis = recordedAt
return next, nil
}
// ValidateSkill requires repeatable verified outcomes plus evidence produced by
// an evaluator other than the candidate creator. It never activates a Skill.
func ValidateSkill(profile capability.SkillProfile, evaluation capability.SkillEvidenceRef, independent bool, mustNotWorsen bool, recordedAt int64) (capability.SkillProfile, error) {
if err := ValidateSkillProfile(profile); err != nil || evaluation == "" || !independent || !mustNotWorsen || recordedAt < 1 {
return capability.SkillProfile{}, ErrInsufficientSkillEvidence
}
if profile.VerifiedOutcomeCount < 2 || len(profile.SupportingExperienceRefs) < 2 {
return capability.SkillProfile{}, ErrInsufficientSkillEvidence
}
next := profile
next.Revision++
next.Status = capability.SkillValidated
next.ValidationEvidenceRefs = appendEvidenceRef(next.ValidationEvidenceRefs, evaluation)
next.IndependentEvaluationRefs = appendEvidenceRef(next.IndependentEvaluationRefs, evaluation)
next.MustNotWorsenSatisfied = true
next.LastValidatedUnixMillis = recordedAt
next.RecordedAtUnixMillis = recordedAt
return next, nil
}
func ActivateSkill(profile capability.SkillProfile, recordedAt int64) (capability.SkillProfile, error) {
if err := ValidateSkillProfile(profile); err != nil || profile.Status != capability.SkillValidated || len(profile.IndependentEvaluationRefs) == 0 || !profile.MustNotWorsenSatisfied || recordedAt < 1 {
return capability.SkillProfile{}, ErrInsufficientSkillEvidence
}
next := profile
next.Revision++
next.Status = capability.SkillActive
next.RecordedAtUnixMillis = recordedAt
return next, nil
}
func ObserveSkillOutcome(profile capability.SkillProfile, observation capability.SkillOutcomeObservation) (capability.SkillProfile, error) {
if err := ValidateSkillProfile(profile); err != nil {
return capability.SkillProfile{}, err
@@ -37,10 +84,6 @@ func ObserveSkillOutcome(profile capability.SkillProfile, observation capability
switch observation.Outcome {
case capability.UsageSucceeded:
next.SupportingExperienceRefs = appendEvidenceRef(next.SupportingExperienceRefs, observation.ExperienceRef)
if next.Status == capability.SkillCandidate || next.Status == capability.SkillEvaluating {
next.Status = capability.SkillValidated
}
next.LastValidatedUnixMillis = observation.ObservedAtUnixMillis
next.ConfidenceMillis = clampConfidence(next.ConfidenceMillis + 25)
case capability.UsageFailed:
next.KnownFailureExperienceRefs = appendEvidenceRef(next.KnownFailureExperienceRefs, observation.ExperienceRef)
@@ -57,7 +100,7 @@ func ObserveSkillOutcome(profile capability.SkillProfile, observation capability
next.KnownFailureExperienceRefs = appendEvidenceRef(next.KnownFailureExperienceRefs, observation.ExperienceRef)
next.ConfidenceMillis = clampConfidence(next.ConfidenceMillis - 200)
}
if next.Status == capability.SkillValidated && (next.ObservedFailureCount >= 3 || next.ObservedCorrectionCount >= 2 || next.ConfidenceMillis < 500) {
if (next.Status == capability.SkillValidated || next.Status == capability.SkillActive) && (next.ObservedFailureCount >= 3 || next.ObservedCorrectionCount >= 2 || next.ConfidenceMillis < 500) {
next.Status = capability.SkillDegraded
}
if next.Status == capability.SkillDegraded && next.ConfidenceMillis < 250 {
@@ -80,7 +123,7 @@ func DecideFastPath(profile capability.SkillProfile, supported bool, confidenceM
ObservedAtUnixMillis: observedAtUnixMillis,
}
switch {
case profile.Status == capability.SkillSuspended || profile.Status == capability.SkillRetired:
case profile.Status == capability.SkillSuspended || profile.Status == capability.SkillRetired || profile.Status == capability.SkillDegraded:
return decline(decision, capability.FastPathStale, "skill profile is not eligible for fast-path use"), nil
case environmentVersionChanged:
return decline(decision, capability.FastPathStale, "environment or implementation version changed since validation"), nil
@@ -90,7 +133,7 @@ func DecideFastPath(profile capability.SkillProfile, supported bool, confidenceM
return decline(decision, capability.FastPathOutOfDistribution, "input is outside supported semantics"), nil
case confidenceMillis < 700 || profile.ConfidenceMillis < 700:
return decline(decision, capability.FastPathLowConfidence, "confidence is too low for optimized path"), nil
case profile.Status != capability.SkillValidated:
case profile.Status != capability.SkillActive:
return decline(decision, capability.FastPathNotApplicable, "skill is not validated"), nil
default:
return decision, nil