Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e7b32be1e0 | ||
|
|
d4640d7617 | ||
|
|
29b20bc5b0 | ||
|
|
071adb5ecb |
@@ -218,6 +218,34 @@ func (r *CapabilityRepository) SaveCapabilityUsageObservation(ctx context.Contex
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *CapabilityRepository) SaveSkillProfile(ctx context.Context, value capability.SkillProfile) error {
|
||||
tx, err := r.pool.Begin(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() { _ = tx.Rollback(ctx) }()
|
||||
_, err = tx.Exec(ctx, `INSERT INTO capability.skill_profiles (
|
||||
skill_profile_id,revision,name,description,applicable_context,implementation_ref,implementation_version,status,
|
||||
supporting_experience_refs,known_failure_experience_refs,confidence_millis,last_validated_unix_millis,
|
||||
observed_failure_count,observed_correction_count,recorded_at_unix_millis)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15) ON CONFLICT DO NOTHING`,
|
||||
value.ID, value.Revision, value.Name, value.Description, value.ApplicableContext, value.ImplementationRef,
|
||||
value.ImplementationVersion, value.Status, value.SupportingExperienceRefs, value.KnownFailureExperienceRefs,
|
||||
value.ConfidenceMillis, value.LastValidatedUnixMillis, value.ObservedFailureCount, value.ObservedCorrectionCount,
|
||||
value.RecordedAtUnixMillis)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec(ctx, `INSERT INTO capability.skill_profile_heads(skill_profile_id,revision,status)
|
||||
VALUES ($1,$2,$3)
|
||||
ON CONFLICT (skill_profile_id) DO UPDATE SET revision=EXCLUDED.revision,status=EXCLUDED.status,updated_at=CURRENT_TIMESTAMP
|
||||
WHERE capability.skill_profile_heads.revision < EXCLUDED.revision`, value.ID, value.Revision, value.Status)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.Commit(ctx)
|
||||
}
|
||||
|
||||
func (r *CapabilityRepository) LoadBinding(ctx context.Context, id capability.CapabilityBindingID, revision int64) (capability.Binding, error) {
|
||||
var binding capability.Binding
|
||||
err := r.pool.QueryRow(ctx, `SELECT binding_id,capability_id,owner_principal_id,revision,state,https_origin,delivery_path,receipt_path,
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"git.cin.su/m/Assistant/contracts/epistemics"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
type EpistemicsRepository struct{ pool *pgxpool.Pool }
|
||||
|
||||
func OpenEpistemics(ctx context.Context, config ContinuityConfig) (*EpistemicsRepository, error) {
|
||||
dsn := fmt.Sprintf("host=%s port=%s dbname=%s user=%s password=%s", config.Host, config.Port, config.Database, config.User, config.Password)
|
||||
pool, err := pgxpool.New(ctx, dsn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &EpistemicsRepository{pool: pool}, nil
|
||||
}
|
||||
|
||||
func (r *EpistemicsRepository) Close() { r.pool.Close() }
|
||||
|
||||
func (r *EpistemicsRepository) SaveSystemExpectation(ctx context.Context, value epistemics.SystemExpectation) error {
|
||||
_, err := r.pool.Exec(ctx, `INSERT INTO epistemics.system_expectations (
|
||||
expectation_id, original_intent_id, source_utterance_id, expected_outcome, expected_effect,
|
||||
confidence_millis, evidence_basis, recorded_at_unix_millis)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8) ON CONFLICT DO NOTHING`,
|
||||
value.ID, value.OriginalIntentID, value.SourceUtteranceID, value.ExpectedOutcome, value.ExpectedEffect,
|
||||
value.ConfidenceMillis, value.EvidenceBasis, value.RecordedAtUnixMillis)
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *EpistemicsRepository) SaveExperienceRecord(ctx context.Context, value epistemics.ExperienceRecord) error {
|
||||
_, err := r.pool.Exec(ctx, `INSERT INTO epistemics.experience_records (
|
||||
experience_id, source_kind, original_intent_id, source_utterance_id, context_refs, help_method, help_method_ref,
|
||||
capability_implementation_ref, capability_usage_observation_ref, capability_gap_ref, skill_ref, expectation_id,
|
||||
expected_outcome, actual_outcome, outcome_ref, outcome_detail, human_response_ref, correction_utterance_id,
|
||||
verification_evidence, confidence_millis, recorded_at_unix_millis)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21) ON CONFLICT DO NOTHING`,
|
||||
value.ID, value.SourceKind, value.OriginalIntentID, value.SourceUtteranceID, value.ContextRefs, value.HelpMethod, value.HelpMethodRef,
|
||||
value.CapabilityImplementationRef, value.CapabilityUsageObservationRef, value.CapabilityGapRef, value.SkillRef, value.ExpectationID,
|
||||
value.ExpectedOutcome, value.ActualOutcome, value.OutcomeRef, value.OutcomeDetail, value.HumanResponseRef, value.CorrectionUtteranceID,
|
||||
value.VerificationEvidence, value.ConfidenceMillis, value.RecordedAtUnixMillis)
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *EpistemicsRepository) SaveReflectionCandidate(ctx context.Context, value epistemics.ReflectionCandidate) error {
|
||||
_, err := r.pool.Exec(ctx, `INSERT INTO epistemics.reflection_candidates (
|
||||
reflection_candidate_id, trigger, state, source_experience_id, original_intent_id, source_utterance_id,
|
||||
summary, evidence_refs, requires_cognition, recorded_at_unix_millis, revision)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11) ON CONFLICT DO NOTHING`,
|
||||
value.ID, value.Trigger, value.State, value.SourceExperienceID, value.OriginalIntentID, value.SourceUtteranceID,
|
||||
value.Summary, value.EvidenceRefs, value.RequiresCognition, value.RecordedAtUnixMillis, value.Revision)
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
# ADR-0016 — Experience, Reflection and Skill Evolution Foundation V1
|
||||
|
||||
Status: Accepted
|
||||
|
||||
Task: DEV-000067
|
||||
|
||||
## Context
|
||||
|
||||
Domovoy can now receive human utterances, interpret intent, optionally plan work, resolve capabilities, perform narrow actions through existing owner boundaries, observe outcomes and accept human responses. The next architecture step is to preserve what happened and why, so repeated successful understanding may become reusable skill while failures, corrections and drift can return the system to broader thinking.
|
||||
|
||||
This must not introduce a giant learning manager, self-modifying loop, prompt optimizer or permanent hand-coded user profile. Learning evidence must remain historical and revisable.
|
||||
|
||||
## Decision
|
||||
|
||||
1. Do not create a new canonical owner for DEV-000067.
|
||||
2. `epistemics` owns provider-neutral experience, expectation, outcome and reflection-candidate semantics because these are evidence/provenance about what happened and why. It stores typed references to Interaction, Continuity, Work and Capability records rather than copying their canonical state.
|
||||
3. `capability` owns skill-profile and fast-path lifecycle semantics because Skill V1 is a reusable capability/implementation pattern derived from evidence, not a new authority or profession category.
|
||||
4. A `SystemExpectation` records what the system expected from meaningful help before outcome is known. "Model returned text" and "HTTP 200" are not sufficient success semantics.
|
||||
5. `ExperienceRecord` links original human intent/utterance, context refs, selected help method, capability/implementation refs, expectation, outcome class, human response/correction refs and verification evidence.
|
||||
6. `ReflectionCandidate` is append-only evidence that broader reflection may be warranted. It may be deterministic or routed through the Cognitive Gateway, but model output cannot directly mutate canonical beliefs, skills, authority, Go source or deployment.
|
||||
7. Skill lifecycle is explicit: `CANDIDATE`, `EVALUATING`, `VALIDATED`, `DEGRADED`, `SUSPENDED`, `RETIRED`. Replacing or suspending a skill never deletes source observations, experiences, corrections, outcomes, beliefs or original human intent history.
|
||||
8. Fast paths are optimizations, not truth. Every optimized path must be able to return `NOT_APPLICABLE`, `LOW_CONFIDENCE`, `OUT_OF_DISTRIBUTION`, `CONFLICT` or `STALE` and escalate to broader reasoning/clarification.
|
||||
9. User corrections are strong learning evidence but are not automatically permanent rules. They create experience/reflection evidence and may later support revisable beliefs or skill changes.
|
||||
|
||||
## Boundaries
|
||||
|
||||
- Interaction remains canonical owner of conversations, utterances, original human intent and corrections.
|
||||
- Continuity remains canonical owner of HumanResponse, Attention and ProspectiveItem continuation state.
|
||||
- Capability remains canonical owner of capability implementations, gaps, usage observations and skill profiles.
|
||||
- Epistemics records evidence/reflection using typed refs only; it does not mutate other owners.
|
||||
- No external mutation, new authority, new provider adapter, deployment authority expansion or self-modifying code path is introduced.
|
||||
- Cognitive reflection, if later used, must go through Cognitive Gateway/Router and structured validation.
|
||||
|
||||
## Non-goals
|
||||
|
||||
- No LearningManager, reinforcement-learning platform, autonomous curriculum, skill dashboard, universal user profile, plugin marketplace or self-modifying development loop.
|
||||
- No automatic activation/promotion of cognitive models or capability implementations.
|
||||
- No new canonical owner.
|
||||
|
||||
## Consequences
|
||||
|
||||
- Production evidence such as reminder acceptance, human correction, capability gaps, cognitive advisory outcomes and repeated capability failures can be represented consistently.
|
||||
- Validated fast paths can stay cheap, while stale/low-confidence/out-of-distribution cases can return to thinking instead of being forced into old rules.
|
||||
- Knowledge and experience survive skill implementation replacement.
|
||||
@@ -84,7 +84,10 @@
|
||||
"Observation",
|
||||
"Claim",
|
||||
"Belief",
|
||||
"Provenance"
|
||||
"Provenance",
|
||||
"SystemExpectation",
|
||||
"ExperienceRecord",
|
||||
"ReflectionCandidate"
|
||||
],
|
||||
"database_schema": "epistemics",
|
||||
"boundary_class": "remote_capable",
|
||||
@@ -122,7 +125,10 @@
|
||||
"CapabilitySelection",
|
||||
"CapabilityGap",
|
||||
"AcquisitionStrategyCandidate",
|
||||
"CapabilityUsageObservation"
|
||||
"CapabilityUsageObservation",
|
||||
"SkillProfile",
|
||||
"SkillEvidence",
|
||||
"FastPathDecision"
|
||||
],
|
||||
"database_schema": "capability",
|
||||
"boundary_class": "remote_capable",
|
||||
|
||||
@@ -34,7 +34,7 @@ modules:
|
||||
|
||||
epistemics:
|
||||
id: mod.epistemics
|
||||
owns: [Observation, Claim, Belief, Provenance]
|
||||
owns: [Observation, Claim, Belief, Provenance, SystemExpectation, ExperienceRecord, ReflectionCandidate]
|
||||
database_schema: epistemics
|
||||
boundary_class: remote_capable
|
||||
may_depend_on: [contracts.identity, contracts.artifact, platform.events]
|
||||
@@ -48,7 +48,7 @@ modules:
|
||||
|
||||
capability:
|
||||
id: mod.capability
|
||||
owns: [Capability, CapabilityBinding, CapabilityHealth, CapabilityImplementation, CapabilityResolution, CapabilitySelection, CapabilityGap, AcquisitionStrategyCandidate, CapabilityUsageObservation]
|
||||
owns: [Capability, CapabilityBinding, CapabilityHealth, CapabilityImplementation, CapabilityResolution, CapabilitySelection, CapabilityGap, AcquisitionStrategyCandidate, CapabilityUsageObservation, SkillProfile, SkillEvidence, FastPathDecision]
|
||||
database_schema: capability
|
||||
boundary_class: remote_capable
|
||||
may_depend_on: [contracts.identity, contracts.authority, contracts.artifact]
|
||||
|
||||
@@ -9,6 +9,8 @@ type CapabilityImplementationID ids.ID
|
||||
type CapabilityResolutionID ids.ID
|
||||
type CapabilityGapID ids.ID
|
||||
type CapabilityUsageObservationID ids.ID
|
||||
type SkillProfileID ids.ID
|
||||
type SkillEvidenceRef string
|
||||
type RequirementRef string
|
||||
type OriginalIntentRef string
|
||||
type SourceUtteranceRef string
|
||||
@@ -21,6 +23,9 @@ type CapabilityResolutionStatus string
|
||||
type GapReason string
|
||||
type AcquisitionStrategyKind string
|
||||
type UsageOutcomeClass string
|
||||
type SkillLifecycleStatus string
|
||||
type FastPathDecisionState string
|
||||
type FastPathDeclineReason string
|
||||
|
||||
const (
|
||||
ImplementationInternalFunction ImplementationKind = "INTERNAL_FUNCTION"
|
||||
@@ -61,6 +66,24 @@ const (
|
||||
UsageFailed UsageOutcomeClass = "FAILED"
|
||||
UsageSkipped UsageOutcomeClass = "SKIPPED"
|
||||
UsageUnknown UsageOutcomeClass = "UNKNOWN"
|
||||
|
||||
SkillCandidate SkillLifecycleStatus = "CANDIDATE"
|
||||
SkillEvaluating SkillLifecycleStatus = "EVALUATING"
|
||||
SkillValidated SkillLifecycleStatus = "VALIDATED"
|
||||
SkillDegraded SkillLifecycleStatus = "DEGRADED"
|
||||
SkillSuspended SkillLifecycleStatus = "SUSPENDED"
|
||||
SkillRetired SkillLifecycleStatus = "RETIRED"
|
||||
|
||||
FastPathApplied FastPathDecisionState = "APPLIED"
|
||||
FastPathDeclined FastPathDecisionState = "DECLINED"
|
||||
FastPathEscalate FastPathDecisionState = "ESCALATE_TO_THINK"
|
||||
|
||||
FastPathNotApplicable FastPathDeclineReason = "NOT_APPLICABLE"
|
||||
FastPathLowConfidence FastPathDeclineReason = "LOW_CONFIDENCE"
|
||||
FastPathOutOfDistribution FastPathDeclineReason = "OUT_OF_DISTRIBUTION"
|
||||
FastPathConflict FastPathDeclineReason = "CONFLICT"
|
||||
FastPathStale FastPathDeclineReason = "STALE"
|
||||
FastPathImplementationDown FastPathDeclineReason = "IMPLEMENTATION_UNAVAILABLE"
|
||||
)
|
||||
|
||||
// CapabilityDescriptor names what Domovoy can obtain or do. CapabilityKind is
|
||||
@@ -160,3 +183,41 @@ type CapabilityUsageObservation struct {
|
||||
LatencyMillis *int64
|
||||
ObservedAtUnixMillis int64
|
||||
}
|
||||
|
||||
// SkillProfile describes a reusable approach/pattern/capability composition.
|
||||
// It is derived from evidence and is never authority by itself.
|
||||
type SkillProfile struct {
|
||||
ID SkillProfileID
|
||||
Revision int64
|
||||
Name string
|
||||
Description string
|
||||
ApplicableContext []string
|
||||
ImplementationRef string
|
||||
ImplementationVersion string
|
||||
Status SkillLifecycleStatus
|
||||
SupportingExperienceRefs []SkillEvidenceRef
|
||||
KnownFailureExperienceRefs []SkillEvidenceRef
|
||||
ConfidenceMillis int64
|
||||
LastValidatedUnixMillis int64
|
||||
ObservedFailureCount int64
|
||||
ObservedCorrectionCount int64
|
||||
RecordedAtUnixMillis int64
|
||||
}
|
||||
|
||||
type SkillOutcomeObservation struct {
|
||||
ExperienceRef SkillEvidenceRef
|
||||
Outcome UsageOutcomeClass
|
||||
UserCorrected bool
|
||||
ObservedAtUnixMillis int64
|
||||
}
|
||||
|
||||
// FastPathDecision is an explicit optimization decision. Decline/escalation is
|
||||
// successful safety behavior, not a failure to answer.
|
||||
type FastPathDecision struct {
|
||||
SkillProfileID SkillProfileID
|
||||
Decision FastPathDecisionState
|
||||
DeclineReason FastPathDeclineReason
|
||||
RequiresCognition bool
|
||||
Explanation string
|
||||
ObservedAtUnixMillis int64
|
||||
}
|
||||
|
||||
@@ -5,8 +5,25 @@ import "git.cin.su/m/Assistant/platform/ids"
|
||||
type ObservationID ids.ID
|
||||
type ClaimID ids.ID
|
||||
type BeliefID ids.ID
|
||||
type SystemExpectationID ids.ID
|
||||
type ExperienceRecordID ids.ID
|
||||
type ReflectionCandidateID ids.ID
|
||||
type VerificationState string
|
||||
type ClaimSourceKind string
|
||||
type EvidenceRef string
|
||||
type ContextRef string
|
||||
type OriginalIntentRef string
|
||||
type SourceUtteranceRef string
|
||||
type HumanResponseRef string
|
||||
type CapabilityImplementationRef string
|
||||
type CapabilityUsageObservationRef string
|
||||
type CapabilityGapRef string
|
||||
type SkillRef string
|
||||
type ExperienceSourceKind string
|
||||
type HelpMethodKind string
|
||||
type OutcomeClass string
|
||||
type ReflectionTriggerKind string
|
||||
type ReflectionCandidateState string
|
||||
|
||||
const (
|
||||
VerificationUnverified VerificationState = "UNVERIFIED"
|
||||
@@ -17,4 +34,101 @@ const (
|
||||
|
||||
ClaimSourceAuthenticatedHuman ClaimSourceKind = "AUTHENTICATED_HUMAN"
|
||||
ClaimSourceTrustedObservation ClaimSourceKind = "TRUSTED_OBSERVATION"
|
||||
|
||||
ExperienceSourceInteraction ExperienceSourceKind = "INTERACTION"
|
||||
ExperienceSourceContinuity ExperienceSourceKind = "CONTINUITY"
|
||||
ExperienceSourceCapability ExperienceSourceKind = "CAPABILITY"
|
||||
ExperienceSourceCognitiveAdvisory ExperienceSourceKind = "COGNITIVE_ADVISORY"
|
||||
|
||||
HelpMethodDeterministicFastPath HelpMethodKind = "DETERMINISTIC_FAST_PATH"
|
||||
HelpMethodCapabilityExecution HelpMethodKind = "CAPABILITY_EXECUTION"
|
||||
HelpMethodCognitiveAdvisory HelpMethodKind = "COGNITIVE_ADVISORY"
|
||||
HelpMethodClarification HelpMethodKind = "CLARIFICATION"
|
||||
HelpMethodFallback HelpMethodKind = "FALLBACK"
|
||||
|
||||
OutcomeSuccess OutcomeClass = "SUCCESS"
|
||||
OutcomePartialSuccess OutcomeClass = "PARTIAL_SUCCESS"
|
||||
OutcomeFailed OutcomeClass = "FAILED"
|
||||
OutcomeUnknown OutcomeClass = "UNKNOWN"
|
||||
OutcomeUserCorrected OutcomeClass = "USER_CORRECTED"
|
||||
OutcomeUnexpected OutcomeClass = "UNEXPECTED_OUTCOME"
|
||||
OutcomeNotApplicable OutcomeClass = "NOT_APPLICABLE"
|
||||
OutcomeLowConfidence OutcomeClass = "LOW_CONFIDENCE"
|
||||
OutcomeOutOfDistribution OutcomeClass = "OUT_OF_DISTRIBUTION"
|
||||
OutcomeConflict OutcomeClass = "CONFLICT"
|
||||
OutcomeStale OutcomeClass = "STALE"
|
||||
|
||||
ReflectionUnexpectedOutcome ReflectionTriggerKind = "UNEXPECTED_OUTCOME"
|
||||
ReflectionFailure ReflectionTriggerKind = "FAILURE"
|
||||
ReflectionUserCorrection ReflectionTriggerKind = "USER_CORRECTION"
|
||||
ReflectionContradiction ReflectionTriggerKind = "CONTRADICTION"
|
||||
ReflectionLowConfidence ReflectionTriggerKind = "LOW_CONFIDENCE"
|
||||
ReflectionRepeatedDegradation ReflectionTriggerKind = "REPEATED_DEGRADATION"
|
||||
ReflectionEnvironmentChange ReflectionTriggerKind = "ENVIRONMENT_CHANGE"
|
||||
ReflectionImplementationChanged ReflectionTriggerKind = "IMPLEMENTATION_CHANGED"
|
||||
ReflectionStaleSkill ReflectionTriggerKind = "STALE_SKILL"
|
||||
ReflectionSampledAudit ReflectionTriggerKind = "SAMPLED_AUDIT"
|
||||
|
||||
ReflectionCandidateOpen ReflectionCandidateState = "OPEN"
|
||||
ReflectionCandidateEvaluating ReflectionCandidateState = "EVALUATING"
|
||||
ReflectionCandidateSuperseded ReflectionCandidateState = "SUPERSEDED"
|
||||
ReflectionCandidateResolved ReflectionCandidateState = "RESOLVED"
|
||||
)
|
||||
|
||||
// SystemExpectation records what Domovoy expected a meaningful help path to
|
||||
// accomplish before the outcome was known. It is evidence context, not a
|
||||
// commitment or verified fact.
|
||||
type SystemExpectation struct {
|
||||
ID SystemExpectationID
|
||||
OriginalIntentID OriginalIntentRef
|
||||
SourceUtteranceID SourceUtteranceRef
|
||||
ExpectedOutcome OutcomeClass
|
||||
ExpectedEffect string
|
||||
ConfidenceMillis int64
|
||||
EvidenceBasis []EvidenceRef
|
||||
RecordedAtUnixMillis int64
|
||||
}
|
||||
|
||||
// ExperienceRecord is append-only evidence about an interaction/help episode.
|
||||
// It stores typed references to other owners and never copies their canonical
|
||||
// state or grants authority.
|
||||
type ExperienceRecord struct {
|
||||
ID ExperienceRecordID
|
||||
SourceKind ExperienceSourceKind
|
||||
OriginalIntentID OriginalIntentRef
|
||||
SourceUtteranceID SourceUtteranceRef
|
||||
ContextRefs []ContextRef
|
||||
HelpMethod HelpMethodKind
|
||||
HelpMethodRef string
|
||||
CapabilityImplementationRef CapabilityImplementationRef
|
||||
CapabilityUsageObservationRef CapabilityUsageObservationRef
|
||||
CapabilityGapRef CapabilityGapRef
|
||||
SkillRef SkillRef
|
||||
ExpectationID SystemExpectationID
|
||||
ExpectedOutcome OutcomeClass
|
||||
ActualOutcome OutcomeClass
|
||||
OutcomeRef string
|
||||
OutcomeDetail string
|
||||
HumanResponseRef HumanResponseRef
|
||||
CorrectionUtteranceID SourceUtteranceRef
|
||||
VerificationEvidence []EvidenceRef
|
||||
ConfidenceMillis int64
|
||||
RecordedAtUnixMillis int64
|
||||
}
|
||||
|
||||
// ReflectionCandidate records that broader reflection may be warranted.
|
||||
// Cognitive reflection, if used, must go through Cognitive Gateway/Router and
|
||||
// produce candidates only; it cannot directly rewrite canonical state.
|
||||
type ReflectionCandidate struct {
|
||||
ID ReflectionCandidateID
|
||||
Trigger ReflectionTriggerKind
|
||||
State ReflectionCandidateState
|
||||
SourceExperienceID ExperienceRecordID
|
||||
OriginalIntentID OriginalIntentRef
|
||||
SourceUtteranceID SourceUtteranceRef
|
||||
Summary string
|
||||
EvidenceRefs []EvidenceRef
|
||||
RequiresCognition bool
|
||||
RecordedAtUnixMillis int64
|
||||
Revision int64
|
||||
}
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
BEGIN;
|
||||
|
||||
SET ROLE epistemics_role;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS epistemics.system_expectations (
|
||||
expectation_id TEXT PRIMARY KEY,
|
||||
original_intent_id TEXT NOT NULL,
|
||||
source_utterance_id TEXT NOT NULL,
|
||||
expected_outcome TEXT NOT NULL,
|
||||
expected_effect TEXT NOT NULL,
|
||||
confidence_millis BIGINT NOT NULL,
|
||||
evidence_basis TEXT[] NOT NULL DEFAULT ARRAY[]::TEXT[],
|
||||
recorded_at_unix_millis BIGINT NOT NULL,
|
||||
recorded_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
CHECK (expectation_id <> ''),
|
||||
CHECK (original_intent_id <> ''),
|
||||
CHECK (source_utterance_id <> ''),
|
||||
CHECK (expected_outcome IN ('SUCCESS','PARTIAL_SUCCESS','FAILED','UNKNOWN','USER_CORRECTED','UNEXPECTED_OUTCOME','NOT_APPLICABLE','LOW_CONFIDENCE','OUT_OF_DISTRIBUTION','CONFLICT','STALE')),
|
||||
CHECK (expected_effect <> ''),
|
||||
CHECK (confidence_millis BETWEEN 0 AND 1000),
|
||||
CHECK (recorded_at_unix_millis > 0)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS epistemics.experience_records (
|
||||
experience_id TEXT PRIMARY KEY,
|
||||
source_kind TEXT NOT NULL,
|
||||
original_intent_id TEXT NOT NULL,
|
||||
source_utterance_id TEXT NOT NULL,
|
||||
context_refs TEXT[] NOT NULL DEFAULT ARRAY[]::TEXT[],
|
||||
help_method TEXT NOT NULL,
|
||||
help_method_ref TEXT NOT NULL DEFAULT '',
|
||||
capability_implementation_ref TEXT NOT NULL DEFAULT '',
|
||||
capability_usage_observation_ref TEXT NOT NULL DEFAULT '',
|
||||
capability_gap_ref TEXT NOT NULL DEFAULT '',
|
||||
skill_ref TEXT NOT NULL DEFAULT '',
|
||||
expectation_id TEXT NOT NULL DEFAULT '',
|
||||
expected_outcome TEXT NOT NULL,
|
||||
actual_outcome TEXT NOT NULL,
|
||||
outcome_ref TEXT NOT NULL DEFAULT '',
|
||||
outcome_detail TEXT NOT NULL DEFAULT '',
|
||||
human_response_ref TEXT NOT NULL DEFAULT '',
|
||||
correction_utterance_id TEXT NOT NULL DEFAULT '',
|
||||
verification_evidence TEXT[] NOT NULL DEFAULT ARRAY[]::TEXT[],
|
||||
confidence_millis BIGINT NOT NULL,
|
||||
recorded_at_unix_millis BIGINT NOT NULL,
|
||||
recorded_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
CHECK (experience_id <> ''),
|
||||
CHECK (source_kind IN ('INTERACTION','CONTINUITY','CAPABILITY','COGNITIVE_ADVISORY')),
|
||||
CHECK (original_intent_id <> ''),
|
||||
CHECK (source_utterance_id <> ''),
|
||||
CHECK (help_method IN ('DETERMINISTIC_FAST_PATH','CAPABILITY_EXECUTION','COGNITIVE_ADVISORY','CLARIFICATION','FALLBACK')),
|
||||
CHECK (expected_outcome IN ('SUCCESS','PARTIAL_SUCCESS','FAILED','UNKNOWN','USER_CORRECTED','UNEXPECTED_OUTCOME','NOT_APPLICABLE','LOW_CONFIDENCE','OUT_OF_DISTRIBUTION','CONFLICT','STALE')),
|
||||
CHECK (actual_outcome IN ('SUCCESS','PARTIAL_SUCCESS','FAILED','UNKNOWN','USER_CORRECTED','UNEXPECTED_OUTCOME','NOT_APPLICABLE','LOW_CONFIDENCE','OUT_OF_DISTRIBUTION','CONFLICT','STALE')),
|
||||
CHECK (confidence_millis BETWEEN 0 AND 1000),
|
||||
CHECK (recorded_at_unix_millis > 0)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS epistemics.reflection_candidates (
|
||||
reflection_candidate_id TEXT PRIMARY KEY,
|
||||
trigger TEXT NOT NULL,
|
||||
state TEXT NOT NULL,
|
||||
source_experience_id TEXT NOT NULL,
|
||||
original_intent_id TEXT NOT NULL,
|
||||
source_utterance_id TEXT NOT NULL,
|
||||
summary TEXT NOT NULL,
|
||||
evidence_refs TEXT[] NOT NULL DEFAULT ARRAY[]::TEXT[],
|
||||
requires_cognition BOOLEAN NOT NULL,
|
||||
recorded_at_unix_millis BIGINT NOT NULL,
|
||||
revision BIGINT NOT NULL,
|
||||
recorded_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
CHECK (reflection_candidate_id <> ''),
|
||||
CHECK (trigger IN ('UNEXPECTED_OUTCOME','FAILURE','USER_CORRECTION','CONTRADICTION','LOW_CONFIDENCE','REPEATED_DEGRADATION','ENVIRONMENT_CHANGE','IMPLEMENTATION_CHANGED','STALE_SKILL','SAMPLED_AUDIT')),
|
||||
CHECK (state IN ('OPEN','EVALUATING','SUPERSEDED','RESOLVED')),
|
||||
CHECK (source_experience_id <> ''),
|
||||
CHECK (original_intent_id <> ''),
|
||||
CHECK (source_utterance_id <> ''),
|
||||
CHECK (summary <> ''),
|
||||
CHECK (recorded_at_unix_millis > 0),
|
||||
CHECK (revision > 0)
|
||||
);
|
||||
|
||||
RESET ROLE;
|
||||
|
||||
SET ROLE capability_role;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS capability.skill_profiles (
|
||||
skill_profile_id TEXT NOT NULL,
|
||||
revision BIGINT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
applicable_context TEXT[] NOT NULL DEFAULT ARRAY[]::TEXT[],
|
||||
implementation_ref TEXT NOT NULL DEFAULT '',
|
||||
implementation_version TEXT NOT NULL DEFAULT '',
|
||||
status TEXT NOT NULL,
|
||||
supporting_experience_refs TEXT[] NOT NULL DEFAULT ARRAY[]::TEXT[],
|
||||
known_failure_experience_refs TEXT[] NOT NULL DEFAULT ARRAY[]::TEXT[],
|
||||
confidence_millis BIGINT NOT NULL,
|
||||
last_validated_unix_millis BIGINT NOT NULL DEFAULT 0,
|
||||
observed_failure_count BIGINT NOT NULL DEFAULT 0,
|
||||
observed_correction_count BIGINT NOT NULL DEFAULT 0,
|
||||
recorded_at_unix_millis BIGINT NOT NULL,
|
||||
recorded_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (skill_profile_id, revision),
|
||||
CHECK (skill_profile_id <> ''),
|
||||
CHECK (revision > 0),
|
||||
CHECK (name <> ''),
|
||||
CHECK (description <> ''),
|
||||
CHECK (status IN ('CANDIDATE','EVALUATING','VALIDATED','DEGRADED','SUSPENDED','RETIRED')),
|
||||
CHECK (confidence_millis BETWEEN 0 AND 1000),
|
||||
CHECK (last_validated_unix_millis >= 0),
|
||||
CHECK (observed_failure_count >= 0),
|
||||
CHECK (observed_correction_count >= 0),
|
||||
CHECK (recorded_at_unix_millis > 0)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS capability.skill_profile_heads (
|
||||
skill_profile_id TEXT PRIMARY KEY,
|
||||
revision BIGINT NOT NULL,
|
||||
status TEXT NOT NULL,
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
CHECK (revision > 0),
|
||||
CHECK (status IN ('CANDIDATE','EVALUATING','VALIDATED','DEGRADED','SUSPENDED','RETIRED'))
|
||||
);
|
||||
|
||||
INSERT INTO capability.skill_profiles(
|
||||
skill_profile_id, revision, name, description, applicable_context, implementation_ref, implementation_version,
|
||||
status, supporting_experience_refs, known_failure_experience_refs, confidence_millis, last_validated_unix_millis,
|
||||
observed_failure_count, observed_correction_count, recorded_at_unix_millis)
|
||||
VALUES (
|
||||
'skill-obvious-reminder-response-v1',
|
||||
1,
|
||||
'Resolve obvious reminder continuation',
|
||||
'Use a recent unambiguous reminder/attention target for complete/snooze/cancel without cognition, while declining ambiguous or unsupported cases.',
|
||||
ARRAY['continuity:reminder-response'],
|
||||
'continuity:human-response-target-resolver-v1',
|
||||
'1',
|
||||
'VALIDATED',
|
||||
ARRAY['continuity:human-response-live-acceptance-dev-000066'],
|
||||
ARRAY[]::TEXT[],
|
||||
850,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1
|
||||
)
|
||||
ON CONFLICT DO NOTHING;
|
||||
|
||||
INSERT INTO capability.skill_profile_heads(skill_profile_id, revision, status)
|
||||
VALUES ('skill-obvious-reminder-response-v1', 1, 'VALIDATED')
|
||||
ON CONFLICT (skill_profile_id) DO NOTHING;
|
||||
|
||||
RESET ROLE;
|
||||
COMMIT;
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"task_file": "dev/tasks/DEV-000066-human-response-continuation-semantics.json",
|
||||
"task_id": "DEV-000066",
|
||||
"task_file": "dev/tasks/DEV-000067-experience-reflection-skill-evolution.json",
|
||||
"task_id": "DEV-000067",
|
||||
"task_revision": 1
|
||||
}
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
{
|
||||
"task_id": "DEV-000067",
|
||||
"task_revision": 1,
|
||||
"architecture_revision": "ADR-0016",
|
||||
"base_repo_revision": "d4640d7617ed579a9b0852fb336905f777f80de6",
|
||||
"risk_tier": "E",
|
||||
"intent": "Add provider-neutral Experience, Reflection and Skill Evolution foundation without creating a LearningManager or new canonical owner.",
|
||||
"requirement_ids": [
|
||||
"ADR-0016",
|
||||
"INV-OWN-001",
|
||||
"INV-EPI-001",
|
||||
"Experience preserves original intent, expectation, outcome and correction evidence",
|
||||
"Fast paths can decline and return to broader reasoning",
|
||||
"Skill replacement does not delete evidence"
|
||||
],
|
||||
"allowed_change_scope": {
|
||||
"modules": [
|
||||
"epistemics",
|
||||
"capability",
|
||||
"interaction",
|
||||
"continuity"
|
||||
],
|
||||
"paths": [
|
||||
"architecture/adrs/ADR-0016-experience-reflection-skill-evolution.md",
|
||||
"architecture/architecture-registry.yaml",
|
||||
"architecture/architecture-registry.json",
|
||||
"contracts/epistemics/**",
|
||||
"contracts/capability/**",
|
||||
"modules/epistemics/**",
|
||||
"modules/capability/**",
|
||||
"adapters/postgres/**",
|
||||
"database/migrations/**",
|
||||
"cmd/core-runtime/**",
|
||||
"cmd/creator-web/**",
|
||||
"tests/owner_acl/**",
|
||||
"tests/cognitive_advisory/**",
|
||||
"docs/PROJECT_STATUS.md",
|
||||
"dev/ACTIVE_TASK.json",
|
||||
"dev/tasks/DEV-000067-experience-reflection-skill-evolution.json"
|
||||
]
|
||||
},
|
||||
"forbidden_change_scope": {
|
||||
"paths": [
|
||||
"architecture/ARCHITECTURE_CONSTITUTION.md",
|
||||
"modules/authority/**",
|
||||
"modules/commit/**",
|
||||
"cmd/commit-runtime/**",
|
||||
"security/**",
|
||||
"ci/**",
|
||||
".gitea/**"
|
||||
]
|
||||
},
|
||||
"allowed_architecture_delta": {
|
||||
"new_cross_module_dependencies": 0,
|
||||
"new_canonical_owners": 0,
|
||||
"new_privileges": 0,
|
||||
"new_third_party_dependencies": 0,
|
||||
"new_provider_adapters": 0
|
||||
},
|
||||
"contracts": {
|
||||
"consume": [
|
||||
"Interaction HumanUtterance / OriginalHumanIntent / correction refs",
|
||||
"Continuity HumanResponse / Attention / ProspectiveItem refs",
|
||||
"Capability CapabilityUsageObservation / CapabilityGap refs",
|
||||
"Cognitive Gateway / Router for future reflection reasoning only"
|
||||
],
|
||||
"may_change": [
|
||||
"contracts/epistemics@v1",
|
||||
"contracts/capability@v1"
|
||||
]
|
||||
},
|
||||
"semantic_owner": "epistemics",
|
||||
"canonical_state": [
|
||||
"SystemExpectation",
|
||||
"ExperienceRecord",
|
||||
"ReflectionCandidate",
|
||||
"SkillProfile",
|
||||
"SkillEvidence",
|
||||
"FastPathDecision"
|
||||
],
|
||||
"state_transitions": [
|
||||
"successful target resolution + accepted human response -> positive experience evidence",
|
||||
"user correction -> USER_CORRECTED outcome and reflection candidate",
|
||||
"fast path outside supported semantics -> NOT_APPLICABLE/OUT_OF_DISTRIBUTION and escalation",
|
||||
"repeated capability/skill failure evidence -> DEGRADED skill profile without deleting history"
|
||||
],
|
||||
"side_effects_and_privileges": [
|
||||
"No external mutation is introduced",
|
||||
"No cognitive model is required for LLM-free tests",
|
||||
"No model output can directly rewrite skills, beliefs, source, deployment or authority",
|
||||
"Docker-test remains prohibited"
|
||||
],
|
||||
"persistence_and_migrations": [
|
||||
"epistemics.system_expectations append-only table",
|
||||
"epistemics.experience_records append-only table",
|
||||
"epistemics.reflection_candidates append-only table",
|
||||
"capability.skill_profiles revisioned table",
|
||||
"capability.skill_profile_heads projection table",
|
||||
"no cross-owner FK",
|
||||
"no cross-owner SQL join dependency"
|
||||
],
|
||||
"failure_retry_restart": [
|
||||
"Experience/reflection rows are append-only historical evidence",
|
||||
"Fast path decline is a valid non-failure decision and preserves return-to-thinking path",
|
||||
"DEGRADED/SUSPENDED/RETIRED skill profiles preserve supporting/failure evidence refs"
|
||||
],
|
||||
"assumptions": [
|
||||
"DEV-000066 is production baseline",
|
||||
"Existing owners are sufficient; no new canonical owner is needed",
|
||||
"V1 records evidence and lifecycle primitives, not autonomous self-improvement"
|
||||
],
|
||||
"acceptance_scenarios": [
|
||||
"Target resolver selected the right recent reminder and user accepted -> positive experience evidence",
|
||||
"User correction of wrong interpretation/target -> USER_CORRECTED outcome and reflection candidate",
|
||||
"Known deterministic path receives unsupported input -> fast path declines and escalates rather than guessing",
|
||||
"Capability implementation fails repeatedly -> related skill confidence/status can degrade without deleting history",
|
||||
"Deleting/replacing/disabling a skill implementation does not delete source observations, experience, corrections, outcomes or original human intent history",
|
||||
"LLM-free operation passes"
|
||||
],
|
||||
"required_tests": [
|
||||
"go test ./...",
|
||||
"go vet ./...",
|
||||
"go run ./cmd/devctl preflight -active dev/ACTIVE_TASK.json",
|
||||
"go run ./cmd/devctl check-architecture",
|
||||
"go run ./cmd/devctl check-diff -active dev/ACTIVE_TASK.json",
|
||||
"tests/cognitive_advisory/cognitive_worker_env_policy_test.ps1",
|
||||
"tests/owner_acl/verify.ps1 -DockerContext docker-prod -PostgresContainer assistant-postgres-1",
|
||||
"production /chat verification if runtime deployment is required"
|
||||
],
|
||||
"terminal_gap_states": [
|
||||
"BLOCKED_BY_ARCHITECTURE_GAP",
|
||||
"BLOCKED_BY_SPEC_GAP",
|
||||
"BLOCKED_BY_MISSING_CAPABILITY",
|
||||
"BLOCKED_BY_CONFLICT"
|
||||
]
|
||||
}
|
||||
+20
-4
@@ -1,10 +1,25 @@
|
||||
# Assistant project status
|
||||
|
||||
Audit date: 2026-08-17. Active implementation: DEV-000066 revision 1.
|
||||
Audit date: 2026-08-17. Active implementation: DEV-000067 revision 1.
|
||||
|
||||
## DEV-000067 checkpoint
|
||||
|
||||
- `DEV_000067_STATUS = IN_PROGRESS_LOCAL_FOUNDATION`
|
||||
- `LAST_COMPLETED = ADR-0016 accepted; no new Learning owner; Epistemics-owned SystemExpectation / ExperienceRecord / ReflectionCandidate contracts; Capability-owned SkillProfile / FastPathDecision lifecycle contracts; append-only migration 023; owner-local regression tests for positive reminder experience, user correction reflection, fast-path decline, and repeated failure skill degradation`
|
||||
- `ADR_STATUS = ADR-0016 accepted`
|
||||
- `OWNERSHIP_STATUS = no new owner; Experience/Expectation/Reflection belong to Epistemics; Skill/FastPath lifecycle belongs to Capability; Interaction/Continuity/Work/Capability state is referenced by typed refs only`
|
||||
- `LEARNING_BOUNDARY_STATUS = no LearningManager, no self-modifying loop, no prompt optimizer, no automatic source/deployment/Authority mutation`
|
||||
- `EXPERIENCE_STATUS = can represent OriginalHumanIntent, HumanUtterance, context refs, help method, capability usage/gap refs, expectation, actual outcome, HumanResponse/correction refs, verification evidence`
|
||||
- `REFLECTION_STATUS = deterministic ReflectionCandidate foundation exists; future cognitive reflection must route through Cognitive Gateway/Router and produce validated candidates only`
|
||||
- `SKILL_STATUS = SkillProfile lifecycle CANDIDATE/EVALUATING/VALIDATED/DEGRADED/SUSPENDED/RETIRED; fast path can decline with NOT_APPLICABLE/LOW_CONFIDENCE/OUT_OF_DISTRIBUTION/CONFLICT/STALE and return to thinking`
|
||||
- `EVIDENCE_RETENTION_STATUS = skill degradation/replacement preserves supporting and failure experience refs; no source evidence deletion path introduced`
|
||||
- `RUNTIME_STATUS = persistence foundation is present; production runtime credential wiring for Epistemics writes is intentionally not expanded in this checkpoint`
|
||||
- `ACTIVE_COGNITIVE_BINDINGS = none; CPU CANARY unchanged`
|
||||
- `OPENAI_REAL_CREDENTIAL = not required / not activated`
|
||||
|
||||
## DEV-000066 checkpoint
|
||||
|
||||
- `DEV_000066_STATUS = IMPLEMENTED_NOT_PROMOTED`
|
||||
- `DEV_000066_STATUS = PRODUCTION_ACTIVE`
|
||||
- `LAST_COMPLETED = ADR-0015 accepted; Continuity-owned HumanResponse contract foundation; ResponseTargetResolution semantics; append-only human_responses migration; Attention response projection fields; deterministic COMPLETE/SNOOZE/CANCEL/DISMISS interpretation; Creator Web response buttons over ordinary /chat; ActiveProjectFocus leak regression under Interaction semantics`
|
||||
- `ADR_STATUS = ADR-0015 accepted`
|
||||
- `OWNERSHIP_STATUS = no new owner; HumanResponse and response target resolution belong to Continuity; Interaction remains utterance/original-intent owner`
|
||||
@@ -14,8 +29,9 @@ Audit date: 2026-08-17. Active implementation: DEV-000066 revision 1.
|
||||
- `AUTHORITY_STATUS = no new external mutation authority; human reported completion is not verified world truth`
|
||||
- `LLM_FREE_STATUS = obvious response operations are deterministic and do not require cognitive model`
|
||||
- `TESTS_PASS = go test ./...; go vet ./...; go run ./cmd/devctl preflight -active dev/ACTIVE_TASK.json; go run ./cmd/devctl check-architecture; go run ./cmd/devctl check-diff -active dev/ACTIVE_TASK.json; tests/cognitive_advisory/cognitive_worker_env_policy_test.ps1; tests/owner_acl/verify.ps1 -DockerContext docker-prod -PostgresContainer assistant-postgres-1`
|
||||
- `LIVE_ACCEPTANCE = pending production deployment`
|
||||
- `PRODUCTION_STATUS = pending promotion/deployment`
|
||||
- `LIVE_ACCEPTANCE = PASS: external /chat created real reminders; SNOOZE after delivery re-armed the same ProspectiveItem and redelivered once without duplicate AttentionItem; COMPLETE after delivery closed Attention as USER_REPORTED_COMPLETE; CANCEL before delivery suppressed ProspectiveItem and produced no AttentionItem after due window; stale UPO ActiveProjectFocus cleared`
|
||||
- `PRODUCTION_STATUS = healthy`
|
||||
- `PRODUCTION_REVISION = 071adb5ecbf31325678a557c371c512c486d8274`
|
||||
- `ACTIVE_COGNITIVE_BINDINGS = none; CPU CANARY unchanged`
|
||||
- `OPENAI_REAL_CREDENTIAL = not required / not activated`
|
||||
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"git.cin.su/m/Assistant/contracts/capability"
|
||||
)
|
||||
|
||||
var ErrInvalidSkillProfile = errors.New("invalid skill profile")
|
||||
var ErrInvalidFastPathInput = errors.New("invalid fast path input")
|
||||
|
||||
func ValidateSkillProfile(value capability.SkillProfile) error {
|
||||
if value.ID == "" || value.Revision < 1 || strings.TrimSpace(value.Name) == "" ||
|
||||
strings.TrimSpace(value.Description) == "" || value.Status == "" ||
|
||||
value.ConfidenceMillis < 0 || value.ConfidenceMillis > 1000 || value.RecordedAtUnixMillis < 1 {
|
||||
return ErrInvalidSkillProfile
|
||||
}
|
||||
switch value.Status {
|
||||
case capability.SkillCandidate, capability.SkillEvaluating, capability.SkillValidated, capability.SkillDegraded, capability.SkillSuspended, capability.SkillRetired:
|
||||
default:
|
||||
return ErrInvalidSkillProfile
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ObserveSkillOutcome(profile capability.SkillProfile, observation capability.SkillOutcomeObservation) (capability.SkillProfile, error) {
|
||||
if err := ValidateSkillProfile(profile); err != nil {
|
||||
return capability.SkillProfile{}, err
|
||||
}
|
||||
if observation.ExperienceRef == "" || observation.ObservedAtUnixMillis < 1 {
|
||||
return capability.SkillProfile{}, ErrInvalidSkillProfile
|
||||
}
|
||||
next := profile
|
||||
next.Revision++
|
||||
next.RecordedAtUnixMillis = observation.ObservedAtUnixMillis
|
||||
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, capability.UsageUnknown:
|
||||
next.KnownFailureExperienceRefs = appendEvidenceRef(next.KnownFailureExperienceRefs, observation.ExperienceRef)
|
||||
next.ObservedFailureCount++
|
||||
next.ConfidenceMillis = clampConfidence(next.ConfidenceMillis - 150)
|
||||
case capability.UsageSkipped:
|
||||
next.KnownFailureExperienceRefs = appendEvidenceRef(next.KnownFailureExperienceRefs, observation.ExperienceRef)
|
||||
next.ConfidenceMillis = clampConfidence(next.ConfidenceMillis - 25)
|
||||
default:
|
||||
return capability.SkillProfile{}, ErrInvalidSkillProfile
|
||||
}
|
||||
if observation.UserCorrected {
|
||||
next.ObservedCorrectionCount++
|
||||
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) {
|
||||
next.Status = capability.SkillDegraded
|
||||
}
|
||||
if next.Status == capability.SkillDegraded && next.ConfidenceMillis < 250 {
|
||||
next.Status = capability.SkillSuspended
|
||||
}
|
||||
return next, nil
|
||||
}
|
||||
|
||||
func DecideFastPath(profile capability.SkillProfile, supported bool, confidenceMillis int64, environmentVersionChanged bool, conflict bool, observedAtUnixMillis int64) (capability.FastPathDecision, error) {
|
||||
if err := ValidateSkillProfile(profile); err != nil {
|
||||
return capability.FastPathDecision{}, err
|
||||
}
|
||||
if confidenceMillis < 0 || confidenceMillis > 1000 || observedAtUnixMillis < 1 {
|
||||
return capability.FastPathDecision{}, ErrInvalidFastPathInput
|
||||
}
|
||||
decision := capability.FastPathDecision{
|
||||
SkillProfileID: profile.ID,
|
||||
Decision: capability.FastPathApplied,
|
||||
Explanation: "validated fast path applied",
|
||||
ObservedAtUnixMillis: observedAtUnixMillis,
|
||||
}
|
||||
switch {
|
||||
case profile.Status == capability.SkillSuspended || profile.Status == capability.SkillRetired:
|
||||
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
|
||||
case conflict:
|
||||
return decline(decision, capability.FastPathConflict, "input conflicts with known fast-path assumptions"), nil
|
||||
case !supported:
|
||||
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:
|
||||
return decline(decision, capability.FastPathNotApplicable, "skill is not validated"), nil
|
||||
default:
|
||||
return decision, nil
|
||||
}
|
||||
}
|
||||
|
||||
func decline(decision capability.FastPathDecision, reason capability.FastPathDeclineReason, explanation string) capability.FastPathDecision {
|
||||
decision.Decision = capability.FastPathEscalate
|
||||
decision.DeclineReason = reason
|
||||
decision.RequiresCognition = true
|
||||
decision.Explanation = explanation
|
||||
return decision
|
||||
}
|
||||
|
||||
func appendEvidenceRef(values []capability.SkillEvidenceRef, ref capability.SkillEvidenceRef) []capability.SkillEvidenceRef {
|
||||
for _, value := range values {
|
||||
if value == ref {
|
||||
return values
|
||||
}
|
||||
}
|
||||
return append(values, ref)
|
||||
}
|
||||
|
||||
func clampConfidence(value int64) int64 {
|
||||
if value < 0 {
|
||||
return 0
|
||||
}
|
||||
if value > 1000 {
|
||||
return 1000
|
||||
}
|
||||
return value
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.cin.su/m/Assistant/contracts/capability"
|
||||
)
|
||||
|
||||
func TestRepeatedCapabilityFailuresDegradeSkillWithoutDeletingHistory(t *testing.T) {
|
||||
profile := skillProfile()
|
||||
profile.SupportingExperienceRefs = []capability.SkillEvidenceRef{"experience:success-1"}
|
||||
for _, ref := range []capability.SkillEvidenceRef{"experience:failure-1", "experience:failure-2", "experience:failure-3"} {
|
||||
next, err := ObserveSkillOutcome(profile, capability.SkillOutcomeObservation{ExperienceRef: ref, Outcome: capability.UsageFailed, ObservedAtUnixMillis: profile.RecordedAtUnixMillis + 100})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
profile = next
|
||||
}
|
||||
if profile.Status != capability.SkillDegraded {
|
||||
t.Fatalf("expected degraded skill, got %#v", profile)
|
||||
}
|
||||
if len(profile.SupportingExperienceRefs) != 1 || len(profile.KnownFailureExperienceRefs) != 3 {
|
||||
t.Fatalf("skill degradation must preserve success/failure evidence: %#v", profile)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFastPathDeclinesUnsupportedInputAndEscalatesToThinking(t *testing.T) {
|
||||
decision, err := DecideFastPath(skillProfile(), false, 900, false, false, 2000)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if decision.Decision != capability.FastPathEscalate || decision.DeclineReason != capability.FastPathOutOfDistribution || !decision.RequiresCognition {
|
||||
t.Fatalf("unexpected fast path decision: %#v", decision)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidatedSkillCanApplyFastPathWhenFreshAndConfident(t *testing.T) {
|
||||
decision, err := DecideFastPath(skillProfile(), true, 950, false, false, 2000)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if decision.Decision != capability.FastPathApplied || decision.RequiresCognition {
|
||||
t.Fatalf("unexpected fast path decision: %#v", decision)
|
||||
}
|
||||
}
|
||||
|
||||
func skillProfile() capability.SkillProfile {
|
||||
return capability.SkillProfile{
|
||||
ID: "skill-obvious-reminder-response-v1",
|
||||
Revision: 1,
|
||||
Name: "Resolve obvious reminder continuation",
|
||||
Description: "Use a recent unambiguous reminder/attention target for complete/snooze/cancel without cognition.",
|
||||
ApplicableContext: []string{"continuity:reminder-response"},
|
||||
ImplementationRef: "continuity:human-response-target-resolver-v1",
|
||||
ImplementationVersion: "1",
|
||||
Status: capability.SkillValidated,
|
||||
ConfidenceMillis: 850,
|
||||
LastValidatedUnixMillis: 1000,
|
||||
RecordedAtUnixMillis: 1000,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"git.cin.su/m/Assistant/contracts/epistemics"
|
||||
"git.cin.su/m/Assistant/platform/ids"
|
||||
)
|
||||
|
||||
var ErrInvalidExperience = errors.New("invalid experience")
|
||||
var ErrInvalidExpectation = errors.New("invalid expectation")
|
||||
var ErrInvalidReflectionCandidate = errors.New("invalid reflection candidate")
|
||||
|
||||
func NewSystemExpectation(value epistemics.SystemExpectation) (epistemics.SystemExpectation, error) {
|
||||
if value.ID == "" {
|
||||
id, err := ids.New()
|
||||
if err != nil {
|
||||
return epistemics.SystemExpectation{}, err
|
||||
}
|
||||
value.ID = epistemics.SystemExpectationID(id)
|
||||
}
|
||||
if value.OriginalIntentID == "" || value.SourceUtteranceID == "" || value.ExpectedOutcome == "" ||
|
||||
strings.TrimSpace(value.ExpectedEffect) == "" || value.ConfidenceMillis < 0 || value.ConfidenceMillis > 1000 ||
|
||||
value.RecordedAtUnixMillis < 1 {
|
||||
return epistemics.SystemExpectation{}, ErrInvalidExpectation
|
||||
}
|
||||
return value, nil
|
||||
}
|
||||
|
||||
func NewExperienceRecord(value epistemics.ExperienceRecord) (epistemics.ExperienceRecord, error) {
|
||||
if value.ID == "" {
|
||||
id, err := ids.New()
|
||||
if err != nil {
|
||||
return epistemics.ExperienceRecord{}, err
|
||||
}
|
||||
value.ID = epistemics.ExperienceRecordID(id)
|
||||
}
|
||||
if value.SourceKind == "" || value.OriginalIntentID == "" || value.SourceUtteranceID == "" ||
|
||||
value.HelpMethod == "" || value.ExpectedOutcome == "" || value.ActualOutcome == "" ||
|
||||
value.ConfidenceMillis < 0 || value.ConfidenceMillis > 1000 || value.RecordedAtUnixMillis < 1 {
|
||||
return epistemics.ExperienceRecord{}, ErrInvalidExperience
|
||||
}
|
||||
return value, nil
|
||||
}
|
||||
|
||||
func ReflectionForExperience(value epistemics.ExperienceRecord) (epistemics.ReflectionCandidate, bool, error) {
|
||||
if _, err := NewExperienceRecord(value); err != nil {
|
||||
return epistemics.ReflectionCandidate{}, false, err
|
||||
}
|
||||
trigger, ok := reflectionTrigger(value)
|
||||
if !ok {
|
||||
return epistemics.ReflectionCandidate{}, false, nil
|
||||
}
|
||||
id, err := ids.New()
|
||||
if err != nil {
|
||||
return epistemics.ReflectionCandidate{}, false, err
|
||||
}
|
||||
candidate := epistemics.ReflectionCandidate{
|
||||
ID: epistemics.ReflectionCandidateID(id),
|
||||
Trigger: trigger,
|
||||
State: epistemics.ReflectionCandidateOpen,
|
||||
SourceExperienceID: value.ID,
|
||||
OriginalIntentID: value.OriginalIntentID,
|
||||
SourceUtteranceID: value.SourceUtteranceID,
|
||||
Summary: reflectionSummary(trigger, value),
|
||||
EvidenceRefs: reflectionEvidence(value),
|
||||
RequiresCognition: trigger == epistemics.ReflectionContradiction || trigger == epistemics.ReflectionRepeatedDegradation,
|
||||
RecordedAtUnixMillis: value.RecordedAtUnixMillis,
|
||||
Revision: 1,
|
||||
}
|
||||
if err := ValidateReflectionCandidate(candidate); err != nil {
|
||||
return epistemics.ReflectionCandidate{}, false, err
|
||||
}
|
||||
return candidate, true, nil
|
||||
}
|
||||
|
||||
func ValidateReflectionCandidate(value epistemics.ReflectionCandidate) error {
|
||||
if value.ID == "" || value.Trigger == "" || value.State == "" || value.SourceExperienceID == "" ||
|
||||
value.OriginalIntentID == "" || value.SourceUtteranceID == "" || strings.TrimSpace(value.Summary) == "" ||
|
||||
value.RecordedAtUnixMillis < 1 || value.Revision < 1 {
|
||||
return ErrInvalidReflectionCandidate
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func FastPathDeclineExperience(intent epistemics.OriginalIntentRef, utterance epistemics.SourceUtteranceRef, skill epistemics.SkillRef, reason string, millis int64) (epistemics.ExperienceRecord, error) {
|
||||
outcome := epistemics.OutcomeNotApplicable
|
||||
switch reason {
|
||||
case string(epistemics.OutcomeLowConfidence):
|
||||
outcome = epistemics.OutcomeLowConfidence
|
||||
case string(epistemics.OutcomeOutOfDistribution):
|
||||
outcome = epistemics.OutcomeOutOfDistribution
|
||||
case string(epistemics.OutcomeConflict):
|
||||
outcome = epistemics.OutcomeConflict
|
||||
case string(epistemics.OutcomeStale):
|
||||
outcome = epistemics.OutcomeStale
|
||||
}
|
||||
return NewExperienceRecord(epistemics.ExperienceRecord{
|
||||
SourceKind: epistemics.ExperienceSourceInteraction,
|
||||
OriginalIntentID: intent,
|
||||
SourceUtteranceID: utterance,
|
||||
HelpMethod: epistemics.HelpMethodDeterministicFastPath,
|
||||
SkillRef: skill,
|
||||
ExpectedOutcome: epistemics.OutcomeSuccess,
|
||||
ActualOutcome: outcome,
|
||||
OutcomeDetail: "fast path declined and returned to broader reasoning: " + reason,
|
||||
ConfidenceMillis: 1000,
|
||||
RecordedAtUnixMillis: millis,
|
||||
VerificationEvidence: []epistemics.EvidenceRef{"fast-path-decline"},
|
||||
})
|
||||
}
|
||||
|
||||
func reflectionTrigger(value epistemics.ExperienceRecord) (epistemics.ReflectionTriggerKind, bool) {
|
||||
switch value.ActualOutcome {
|
||||
case epistemics.OutcomeUserCorrected:
|
||||
return epistemics.ReflectionUserCorrection, true
|
||||
case epistemics.OutcomeUnexpected:
|
||||
return epistemics.ReflectionUnexpectedOutcome, true
|
||||
case epistemics.OutcomeFailed:
|
||||
return epistemics.ReflectionFailure, true
|
||||
case epistemics.OutcomeLowConfidence:
|
||||
return epistemics.ReflectionLowConfidence, true
|
||||
case epistemics.OutcomeOutOfDistribution, epistemics.OutcomeConflict, epistemics.OutcomeStale:
|
||||
return epistemics.ReflectionSampledAudit, true
|
||||
default:
|
||||
return "", false
|
||||
}
|
||||
}
|
||||
|
||||
func reflectionSummary(trigger epistemics.ReflectionTriggerKind, value epistemics.ExperienceRecord) string {
|
||||
if value.OutcomeDetail != "" {
|
||||
return string(trigger) + ": " + value.OutcomeDetail
|
||||
}
|
||||
return string(trigger) + " for experience " + string(value.ID)
|
||||
}
|
||||
|
||||
func reflectionEvidence(value epistemics.ExperienceRecord) []epistemics.EvidenceRef {
|
||||
refs := append([]epistemics.EvidenceRef{}, value.VerificationEvidence...)
|
||||
if value.HumanResponseRef != "" {
|
||||
refs = append(refs, epistemics.EvidenceRef("continuity:human-response:"+value.HumanResponseRef))
|
||||
}
|
||||
if value.CorrectionUtteranceID != "" {
|
||||
refs = append(refs, epistemics.EvidenceRef("interaction:correction:"+value.CorrectionUtteranceID))
|
||||
}
|
||||
if value.CapabilityUsageObservationRef != "" {
|
||||
refs = append(refs, epistemics.EvidenceRef("capability:usage:"+value.CapabilityUsageObservationRef))
|
||||
}
|
||||
if value.CapabilityGapRef != "" {
|
||||
refs = append(refs, epistemics.EvidenceRef("capability:gap:"+value.CapabilityGapRef))
|
||||
}
|
||||
return refs
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.cin.su/m/Assistant/contracts/epistemics"
|
||||
)
|
||||
|
||||
func TestAcceptedReminderResponseCreatesPositiveExperienceWithoutReflection(t *testing.T) {
|
||||
experience, err := NewExperienceRecord(epistemics.ExperienceRecord{
|
||||
SourceKind: epistemics.ExperienceSourceContinuity,
|
||||
OriginalIntentID: "intent-1",
|
||||
SourceUtteranceID: "utterance-1",
|
||||
ContextRefs: []epistemics.ContextRef{"continuity:attention:attention-1"},
|
||||
HelpMethod: epistemics.HelpMethodDeterministicFastPath,
|
||||
SkillRef: "skill:obvious-reminder-response-v1",
|
||||
ExpectedOutcome: epistemics.OutcomeSuccess,
|
||||
ActualOutcome: epistemics.OutcomeSuccess,
|
||||
OutcomeRef: "continuity:prospective:p1",
|
||||
HumanResponseRef: "response-1",
|
||||
VerificationEvidence: []epistemics.EvidenceRef{"target-resolver:single-recent-reminder", "human-response:complete"},
|
||||
ConfidenceMillis: 950,
|
||||
RecordedAtUnixMillis: 1000,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, ok, err := ReflectionForExperience(experience); err != nil || ok {
|
||||
t.Fatalf("positive accepted experience should not force reflection: ok=%v err=%v", ok, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUserCorrectionCreatesReflectionCandidate(t *testing.T) {
|
||||
experience, err := NewExperienceRecord(epistemics.ExperienceRecord{
|
||||
SourceKind: epistemics.ExperienceSourceInteraction,
|
||||
OriginalIntentID: "intent-1",
|
||||
SourceUtteranceID: "utterance-2",
|
||||
HelpMethod: epistemics.HelpMethodClarification,
|
||||
ExpectedOutcome: epistemics.OutcomeSuccess,
|
||||
ActualOutcome: epistemics.OutcomeUserCorrected,
|
||||
OutcomeDetail: "user corrected wrong target/project interpretation",
|
||||
CorrectionUtteranceID: "utterance-2",
|
||||
ConfidenceMillis: 1000,
|
||||
RecordedAtUnixMillis: 1100,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
candidate, ok, err := ReflectionForExperience(experience)
|
||||
if err != nil || !ok {
|
||||
t.Fatalf("expected reflection candidate, ok=%v err=%v", ok, err)
|
||||
}
|
||||
if candidate.Trigger != epistemics.ReflectionUserCorrection || candidate.State != epistemics.ReflectionCandidateOpen || len(candidate.EvidenceRefs) == 0 {
|
||||
t.Fatalf("unexpected reflection candidate: %#v", candidate)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFastPathDeclineReturnsToThinkingInsteadOfGuessing(t *testing.T) {
|
||||
experience, err := FastPathDeclineExperience("intent-1", "utterance-1", "skill:obvious-reminder-response-v1", string(epistemics.OutcomeOutOfDistribution), 1200)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if experience.ActualOutcome != epistemics.OutcomeOutOfDistribution || experience.HelpMethod != epistemics.HelpMethodDeterministicFastPath {
|
||||
t.Fatalf("unexpected fast path decline experience: %#v", experience)
|
||||
}
|
||||
candidate, ok, err := ReflectionForExperience(experience)
|
||||
if err != nil || !ok || candidate.Trigger != epistemics.ReflectionSampledAudit {
|
||||
t.Fatalf("decline should preserve reflection/escalation evidence, candidate=%#v ok=%v err=%v", candidate, ok, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user