Documentation
¶
Overview ¶
Package learning defines lessons accepted from governed evidence.
Index ¶
- Constants
- Variables
- func Digest(lesson Lesson) (string, error)
- func ValidateContent(domain, statement string, applicability, contraindications []string) error
- func ValidateProvenance(provenance run.ExecutionProvenance) error
- func ValidatePurpose(purpose run.ExecutionPurpose, state run.State, status verification.Status) error
- func ValidateSnapshot(lesson Lesson, snapshot verification.ResultSnapshot, at time.Time) error
- type AcceptRequest
- type Action
- type Authorizer
- type DeletionRequest
- type EvidenceClass
- type Guard
- func (g *Guard) Accept(ctx context.Context, request AcceptRequest) (Publication, error)
- func (g *Guard) AcceptResult(ctx context.Context, request AcceptRequest, ...) (PublicationSummary, error)
- func (g *Guard) Authorize(ctx context.Context, action Action, identifier id.ID, domain string) error
- func (g *Guard) Delete(ctx context.Context, request DeletionRequest) (Tombstone, error)
- func (g *Guard) Publications(ctx context.Context, after string, limit int) (PublicationReviewPage, error)
- func (g *Guard) Resolve(ctx context.Context, ref Ref) (Lesson, error)
- func (g *Guard) Retry(ctx context.Context, identifier id.ID, revision, generation int64) error
- func (g *Guard) Review(ctx context.Context, identifier id.ID) (LessonSummary, error)
- func (g *Guard) Revoke(ctx context.Context, request RevokeRequest) (Publication, error)
- func (g *Guard) WithLesson(ctx context.Context, ref Ref, action Action, ...) (Lesson, error)
- type GuardConfig
- type Lesson
- type LessonSummary
- type Page
- type Publication
- type PublicationPage
- type PublicationReviewPage
- type PublicationSummary
- type Publisher
- type Query
- type Receipt
- type Ref
- type ReportRef
- type Repository
- type Resource
- type RetentionStore
- type RevokeRequest
- type Sink
- type Store
- type Tombstone
- type TombstonePage
Constants ¶
const PrefixLesson id.Prefix = "lesson"
PrefixLesson identifies lessons accepted from ordinary verified runs.
Variables ¶
var ( ErrInvalid = errors.New("cortex: learning: invalid lesson") ErrDenied = errors.New("cortex: learning: access denied") ErrConflict = errors.New("cortex: learning: conflicting lesson revision") ErrNotFound = errors.New("cortex: learning: lesson not found") ErrIneligible = errors.New("cortex: learning: evidence is not eligible") )
Stable errors distinguish unavailable authority, stale evidence and conflicts.
Functions ¶
func ValidateContent ¶
ValidateContent bounds lesson text without asserting that its claim is true.
func ValidateProvenance ¶
func ValidateProvenance(provenance run.ExecutionProvenance) error
ValidateProvenance rejects recalled lessons as independent evidence, including legacy source markers. Callers must supply the authoritative saved run.
func ValidatePurpose ¶
func ValidatePurpose(purpose run.ExecutionPurpose, state run.State, status verification.Status) error
ValidatePurpose permits only completed, passed ordinary runs as lesson sources.
func ValidateSnapshot ¶
func ValidateSnapshot(lesson Lesson, snapshot verification.ResultSnapshot, at time.Time) error
ValidateSnapshot reuses committed-result and report freshness validation. Ordinary lessons preserve the exact verified output; a derived claim needs its own verification. Source lessons cannot attest themselves through recall.
Types ¶
type AcceptRequest ¶
type AcceptRequest struct {
ID id.ID `json:"id"`
Domain string `json:"domain"`
Applicability []string `json:"applicability"`
Contraindications []string `json:"contraindications"`
Result verification.ResultReadRequest `json:"result"`
ExpiresAt time.Time `json:"expires_at"`
Actor string `json:"actor"`
Corrects *Ref `json:"corrects,omitempty"`
}
AcceptRequest proposes applicability for one current verified output. The repository supplies the statement and report digests from the saved result.
type Action ¶
type Action string
Action names the host grant needed for a lesson operation.
const ActionDelete Action = "delete"
ActionDelete requires a host grant separate from ordinary publication ownership.
type Authorizer ¶
Authorizer resolves the caller's current lesson grants. It supplies no default.
type DeletionRequest ¶
DeletionRequest removes local lesson payloads, including historical outboxes. Reason is a bounded policy code, never deleted source content.
type EvidenceClass ¶
type EvidenceClass string
EvidenceClass separates observations from claims supported by verification.
const ( EvidenceValidated EvidenceClass = "validated" EvidenceContrastive EvidenceClass = "contrastive" EvidenceExploratory EvidenceClass = "exploratory" EvidenceObservation EvidenceClass = "observation" EvidenceFailedApproach EvidenceClass = "failed_approach" )
func ClassifyActivity ¶
func ClassifyActivity(state run.State) EvidenceClass
ClassifyActivity labels an ordinary lifecycle observation. Completion alone never establishes a validated result, even if a caller mentions verification.
type Guard ¶
type Guard struct {
// contains filtered or unexported fields
}
Guard rechecks local eligibility and source authority around each operation.
func NewGuard ¶
func NewGuard(config GuardConfig) (*Guard, error)
NewGuard requires explicit host authority and a synchronous revision fence.
func (*Guard) Accept ¶
func (g *Guard) Accept(ctx context.Context, request AcceptRequest) (Publication, error)
Accept commits lesson eligibility and its outbox while source grants are held.
func (*Guard) AcceptResult ¶
func (g *Guard) AcceptResult(ctx context.Context, request AcceptRequest, source verification.ResultContentRequest) (PublicationSummary, error)
AcceptResult derives the private receipt reference from current storage. You supply applicability and a stable lesson ID, never replacement answer text. Leave request.Result empty; source selects the governed result to accept.
func (*Guard) Authorize ¶
func (g *Guard) Authorize(ctx context.Context, action Action, identifier id.ID, domain string) error
Authorize checks exact caller scope before any model-visible lesson lookup.
func (*Guard) Publications ¶
func (g *Guard) Publications(ctx context.Context, after string, limit int) (PublicationReviewPage, error)
Publications returns delivery metadata under current lesson grants. Source content is available only through Resolve and its result-evidence fence.
func (*Guard) Retry ¶
Retry requests one new delivery cycle at the exact retained generation. It does not restore eligibility, extend retention or bypass delivery-time grants.
func (*Guard) Review ¶
Review returns metadata even after withdrawal, without restoring eligibility.
func (*Guard) Revoke ¶
func (g *Guard) Revoke(ctx context.Context, request RevokeRequest) (Publication, error)
Revoke withdraws local eligibility even when source evidence has expired.
func (*Guard) WithLesson ¶
func (g *Guard) WithLesson(ctx context.Context, ref Ref, action Action, operation func(context.Context, Lesson) error) (Lesson, error)
WithLesson holds current source authority around external delivery or hydration. It rechecks local withdrawal after the callback before returning any content.
type GuardConfig ¶
type GuardConfig struct {
Repository Repository
Results verification.ResultContentStore
ContentAuthority verification.ResultContentAuthorizer
Authority Authorizer
Fence verification.CommitFence
Clock verification.Clock
}
GuardConfig supplies existing result provenance and current host fences.
type Lesson ¶
type Lesson struct {
ID id.ID `json:"id"`
Scope cortex.Scope `json:"scope"`
Domain string `json:"domain"`
HarnessSchema int `json:"harness_schema"`
Statement string `json:"statement"`
Applicability []string `json:"applicability"`
Contraindications []string `json:"contraindications"`
DecisionIDs []id.ID `json:"decision_ids"`
TrialIDs []id.ID `json:"trial_ids"`
EvidenceClass EvidenceClass `json:"evidence_class"`
Revision int64 `json:"revision"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt time.Time `json:"expires_at"`
RevokedAt time.Time `json:"revoked_at"`
RevocationReason string `json:"revocation_reason,omitempty"`
Result *verification.ResultReadRequest `json:"result,omitempty"`
SourceReports []ReportRef `json:"source_reports,omitempty"`
Corrects *Ref `json:"corrects,omitempty"`
SupersededBy *Ref `json:"superseded_by,omitempty"`
}
Lesson retains local eligibility even if remote publication or revocation fails.
type LessonSummary ¶
type LessonSummary struct {
Ref Ref `json:"ref"`
Domain string `json:"domain"`
EvidenceClass EvidenceClass `json:"evidence_class"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt time.Time `json:"expires_at"`
RevokedAt time.Time `json:"revoked_at"`
SourceRunID id.AgentRunID `json:"source_run_id"`
SourceResultID id.ID `json:"source_result_id"`
Corrects *Ref `json:"corrects,omitempty"`
SupersededBy *Ref `json:"superseded_by,omitempty"`
}
LessonSummary exposes identity and lifecycle without disclosing retained text. Read the source result through its current authorized publication path.
type Publication ¶
type Publication struct {
LessonID id.ID `json:"lesson_id"`
Revision int64 `json:"revision"`
SourceID id.ID `json:"source_id"`
Operation string `json:"operation"`
Payload Lesson `json:"payload"`
PayloadDigest string `json:"payload_digest"`
AggregateID string `json:"aggregate_id"`
AcceptanceDigest string `json:"acceptance_digest"`
Actor string `json:"actor"`
Generation int64 `json:"generation"`
Attempts int `json:"attempts"`
Owner string `json:"owner"`
LeaseUntil time.Time `json:"lease_until"`
NextAttempt time.Time `json:"next_attempt"`
ErrorCode string `json:"error_code"`
Receipt *Receipt `json:"receipt,omitempty"`
}
Publication keeps one accepted payload and visible durable delivery progress.
type PublicationPage ¶
type PublicationPage struct {
Items []Publication
After string
}
PublicationPage is a bounded exact-scope scan of durable publication work.
type PublicationReviewPage ¶
type PublicationReviewPage struct {
Items []PublicationSummary `json:"items"`
After string `json:"after,omitempty"`
}
PublicationReviewPage preserves the store's bounded exact-scope cursor.
type PublicationSummary ¶
type PublicationSummary struct {
LessonID id.ID `json:"lesson_id"`
Revision int64 `json:"revision"`
Domain string `json:"domain"`
Operation string `json:"operation"`
PayloadDigest string `json:"payload_digest"`
Generation int64 `json:"generation"`
Attempts int `json:"attempts"`
LeaseUntil time.Time `json:"lease_until"`
NextAttempt time.Time `json:"next_attempt"`
ErrorCode string `json:"error_code,omitempty"`
Acknowledged bool `json:"acknowledged"`
}
PublicationSummary excludes lesson text, actor input and retained result bytes. Acknowledged describes destination delivery, not current recall eligibility.
type Publisher ¶
type Publisher struct {
// contains filtered or unexported fields
}
Publisher drains one bounded page of exact-scope durable publication work. A host schedules repeated calls and supplies the worker's current authority.
func NewPublisher ¶
NewPublisher requires durable storage and a guarded destination adapter.
type Query ¶
type Query struct {
Scope cortex.Scope `json:"scope"`
Domain string `json:"domain"`
HarnessSchema int `json:"harness_schema"`
Query string `json:"query"`
Cutoff time.Time `json:"cutoff"`
Limit int `json:"limit"`
Cursor string `json:"cursor,omitempty"`
}
Query fixes exact scope, domain, schema and cutoff before semantic recall.
type Receipt ¶
type Receipt struct {
LessonID id.ID `json:"lesson_id"`
PayloadDigest string `json:"payload_digest"`
AggregateID string `json:"aggregate_id"`
Version int64 `json:"version"`
AcknowledgedAt time.Time `json:"acknowledged_at"`
}
Receipt binds one destination aggregate revision to the exact lesson payload.
type Ref ¶
type Ref struct {
ID id.ID `json:"id"`
Revision int64 `json:"revision"`
Digest string `json:"digest"`
}
Ref freezes local eligibility and content at experiment creation.
type Repository ¶
type Repository interface {
AcceptLesson(context.Context, AcceptRequest) (Publication, error)
GetLesson(context.Context, id.ID) (Lesson, error)
ResolveLesson(context.Context, Ref) (Lesson, error)
RevokeLesson(context.Context, RevokeRequest) (Publication, error)
GetLessonPublication(context.Context, id.ID, int64) (Publication, error)
ListLessonPublications(context.Context, string, int) (PublicationPage, error)
ClaimLessonPublication(context.Context, id.ID, int64, string) (Publication, error)
CompleteLessonPublication(context.Context, Publication, *Receipt, string) error
RetryLessonPublication(context.Context, id.ID, int64, int64) error
}
Repository is an optional persistence capability shared by all root backends. Acceptance and its outbox commit together under the source run's transaction.
type RetentionStore ¶
type RetentionStore interface {
DeleteLesson(context.Context, DeletionRequest) (Tombstone, error)
GetLessonTombstone(context.Context, id.ID) (Tombstone, error)
ListLessonTombstones(context.Context, string, int) (TombstonePage, error)
}
RetentionStore erases local payloads and retains minimal exact-scope audit data. Remote event history has its own destination retention policy.
type RevokeRequest ¶
type RevokeRequest struct {
ID id.ID `json:"id"`
ExpectedRevision int64 `json:"expected_revision"`
Actor string `json:"actor"`
Reason string `json:"reason"`
}
RevokeRequest withdraws local eligibility at one expected revision.
type Sink ¶
type Sink interface {
Deliver(context.Context, Publication) (Receipt, error)
}
Sink reconciles an accepted publication against authoritative remote state.
type Store ¶
type Store interface {
Publish(context.Context, Lesson) (Receipt, error)
Recall(context.Context, Query) (Page, error)
Revoke(context.Context, RevokeRequest) error
}
Store is a governed destination. Publish requires an accepted durable outbox.
type Tombstone ¶
type Tombstone struct {
ID id.ID `json:"id"`
Scope cortex.Scope `json:"scope"`
Revision int64 `json:"revision"`
Digest string `json:"digest"`
AggregateID string `json:"aggregate_id"`
Actor string `json:"actor"`
Reason string `json:"reason"`
DeletedAt time.Time `json:"deleted_at"`
}
Tombstone reserves an erased lesson identity without retaining its content.
type TombstonePage ¶
TombstonePage is a bounded scan for restartable destination cleanup.