Help us shape the future of Go! Take the 2026 Go Developer Survey

evolution

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RecordKindTask    RecordKind = "task"
	RecordKindPattern RecordKind = "pattern"

	// Deprecated: use RecordKindTask.
	RecordKindCase = RecordKindTask
	// Deprecated: use RecordKindPattern.
	RecordKindRule = RecordKindPattern
)

Variables

View Source
var ErrApplyDraftFailed = errors.New("apply draft failed")

Functions

func ApplyLifecycleState

func ApplyLifecycleState(paths Paths, profile SkillProfile, next SkillStatus) error

func SaveAppliedProfile

func SaveAppliedProfile(store *Store, workspace string, draft SkillDraft, now time.Time) error

func ValidateDraft

func ValidateDraft(draft SkillDraft) []string

Types

type Applier

type Applier struct {
	// contains filtered or unexported fields
}

func NewApplier

func NewApplier(paths Paths, now func() time.Time) *Applier

func (*Applier) ApplyDraft

func (a *Applier) ApplyDraft(ctx context.Context, workspace string, draft SkillDraft) error

type AttemptTrail

type AttemptTrail struct {
	AttemptedSkills       []string               `json:"attempted_skills,omitempty"`
	FinalSuccessfulPath   []string               `json:"final_successful_path,omitempty"`
	SkillContextSnapshots []SkillContextSnapshot `json:"skill_context_snapshots,omitempty"`
}

type CaseWriter

type CaseWriter struct {
	// contains filtered or unexported fields
}

func NewCaseWriter

func NewCaseWriter(paths Paths) *CaseWriter

func (*CaseWriter) AppendCase

func (w *CaseWriter) AppendCase(ctx context.Context, record LearningRecord) error

type ChangeKind

type ChangeKind string
const (
	ChangeKindCreate  ChangeKind = "create"
	ChangeKindAppend  ChangeKind = "append"
	ChangeKindReplace ChangeKind = "replace"
	ChangeKindMerge   ChangeKind = "merge"
)

type ColdPathRunner

type ColdPathRunner struct {
	// contains filtered or unexported fields
}

func NewColdPathRunner

func NewColdPathRunner(runtime coldPathRuntime) *ColdPathRunner

func NewColdPathRunnerWithErrorHandler

func NewColdPathRunnerWithErrorHandler(runtime coldPathRuntime, onError func(error)) *ColdPathRunner

func (*ColdPathRunner) Close

func (r *ColdPathRunner) Close() error

func (*ColdPathRunner) Trigger

func (r *ColdPathRunner) Trigger(workspace string) bool

type DefaultDraftGenerator

type DefaultDraftGenerator struct {
	// contains filtered or unexported fields
}

func NewDefaultDraftGenerator

func NewDefaultDraftGenerator(workspace string) *DefaultDraftGenerator

func (*DefaultDraftGenerator) GenerateDraft

func (g *DefaultDraftGenerator) GenerateDraft(
	_ context.Context,
	rule LearningRecord,
	matches []skills.SkillInfo,
) (SkillDraft, error)

func (*DefaultDraftGenerator) GenerateDraftWithEvidence

func (g *DefaultDraftGenerator) GenerateDraftWithEvidence(
	_ context.Context,
	rule LearningRecord,
	matches []skills.SkillInfo,
	evidence DraftEvidence,
) (SkillDraft, error)

type DraftEvidence

type DraftEvidence struct {
	TaskRecords []LearningRecord
}

type DraftGenerator

type DraftGenerator interface {
	GenerateDraft(ctx context.Context, rule LearningRecord, matches []skills.SkillInfo) (SkillDraft, error)
}

func NewDraftGeneratorForWorkspace

func NewDraftGeneratorForWorkspace(workspace string, provider providers.LLMProvider, modelID string) DraftGenerator

type DraftPreview

type DraftPreview struct {
	CurrentBody  string
	RenderedBody string
	DiffPreview  string
}

func BuildDraftPreview

func BuildDraftPreview(workspace string, draft SkillDraft) (DraftPreview, error)

type DraftReviewResult

type DraftReviewResult struct {
	Status      DraftStatus
	Findings    []string
	ReviewNotes []string
}

func ReviewDraft

func ReviewDraft(draft SkillDraft) DraftReviewResult

type DraftStatus

type DraftStatus string
const (
	DraftStatusCandidate   DraftStatus = "candidate"
	DraftStatusQuarantined DraftStatus = "quarantined"
	DraftStatusAccepted    DraftStatus = "accepted"
)

type DraftType

type DraftType string
const (
	DraftTypeWorkflow DraftType = "workflow"
	DraftTypeShortcut DraftType = "shortcut"
)

type EvidenceAwareDraftGenerator

type EvidenceAwareDraftGenerator interface {
	GenerateDraftWithEvidence(
		ctx context.Context,
		rule LearningRecord,
		matches []skills.SkillInfo,
		evidence DraftEvidence,
	) (SkillDraft, error)
}

type HeuristicPatternClusterer

type HeuristicPatternClusterer struct {
	// contains filtered or unexported fields
}

func NewHeuristicPatternClusterer

func NewHeuristicPatternClusterer(minCaseCount int, now func() time.Time) *HeuristicPatternClusterer

func (*HeuristicPatternClusterer) BuildPatterns

func (c *HeuristicPatternClusterer) BuildPatterns(
	_ context.Context,
	workspace string,
	tasks []LearningRecord,
	existing []LearningRecord,
) ([]LearningRecord, []string, error)

type HeuristicSuccessJudge

type HeuristicSuccessJudge struct{}

func (*HeuristicSuccessJudge) JudgeTaskRecord

func (j *HeuristicSuccessJudge) JudgeTaskRecord(
	_ context.Context,
	record LearningRecord,
) (TaskSuccessDecision, error)

type LLMDraftGenerator

type LLMDraftGenerator struct {
	// contains filtered or unexported fields
}

func NewLLMDraftGenerator

func NewLLMDraftGenerator(provider providers.LLMProvider, model string, fallback DraftGenerator) *LLMDraftGenerator

func (*LLMDraftGenerator) GenerateDraft

func (g *LLMDraftGenerator) GenerateDraft(
	ctx context.Context,
	rule LearningRecord,
	matches []skills.SkillInfo,
) (SkillDraft, error)

func (*LLMDraftGenerator) GenerateDraftWithEvidence

func (g *LLMDraftGenerator) GenerateDraftWithEvidence(
	ctx context.Context,
	rule LearningRecord,
	matches []skills.SkillInfo,
	evidence DraftEvidence,
) (SkillDraft, error)

type LLMPatternClusterer

type LLMPatternClusterer struct {
	// contains filtered or unexported fields
}

func NewLLMPatternClusterer

func NewLLMPatternClusterer(
	provider providers.LLMProvider,
	model string,
	fallback PatternClusterer,
	minCount int,
	now func() time.Time,
) *LLMPatternClusterer

func (*LLMPatternClusterer) BuildPatterns

func (c *LLMPatternClusterer) BuildPatterns(
	ctx context.Context,
	workspace string,
	tasks []LearningRecord,
	existing []LearningRecord,
) ([]LearningRecord, []string, error)

func (*LLMPatternClusterer) BuildPatternsWithEvidence

func (c *LLMPatternClusterer) BuildPatternsWithEvidence(
	ctx context.Context,
	workspace string,
	successfulTasks []LearningRecord,
	evidenceTasks []LearningRecord,
	existing []LearningRecord,
	minSuccessRatio float64,
) ([]LearningRecord, []string, error)

type LLMTaskSuccessJudge

type LLMTaskSuccessJudge struct {
	// contains filtered or unexported fields
}

func NewLLMTaskSuccessJudge

func NewLLMTaskSuccessJudge(provider providers.LLMProvider, model string, fallback SuccessJudge) *LLMTaskSuccessJudge

func (*LLMTaskSuccessJudge) JudgeTaskRecord

func (j *LLMTaskSuccessJudge) JudgeTaskRecord(
	ctx context.Context,
	record LearningRecord,
) (TaskSuccessDecision, error)

type LearningRecord

type LearningRecord struct {
	ID                   string                `json:"id"`
	Kind                 RecordKind            `json:"kind"`
	WorkspaceID          string                `json:"workspace_id"`
	CreatedAt            time.Time             `json:"created_at"`
	UpdatedAt            *time.Time            `json:"updated_at,omitempty"`
	SessionKey           string                `json:"session_key,omitempty"`
	TaskHash             string                `json:"task_hash,omitempty"`
	Summary              string                `json:"summary"`
	UserGoal             string                `json:"user_goal,omitempty"`
	FinalOutput          string                `json:"final_output,omitempty"`
	Source               map[string]any        `json:"source,omitempty"`
	Status               RecordStatus          `json:"status"`
	Success              *bool                 `json:"success,omitempty"`
	ToolKinds            []string              `json:"tool_kinds,omitempty"`
	ToolExecutions       []ToolExecutionRecord `json:"tool_executions,omitempty"`
	InitialSkillNames    []string              `json:"initial_skill_names,omitempty"`
	AddedSkillNames      []string              `json:"added_skill_names,omitempty"`
	UsedSkillNames       []string              `json:"used_skill_names,omitempty"`
	AllLoadedSkillNames  []string              `json:"all_loaded_skill_names,omitempty"`
	ActiveSkillNames     []string              `json:"active_skill_names,omitempty"`
	AttemptTrail         *AttemptTrail         `json:"attempt_trail,omitempty"`
	Signals              []string              `json:"signals,omitempty"`
	SourceRecordIDs      []string              `json:"source_record_ids,omitempty"`
	TaskRecordIDs        []string              `json:"task_record_ids,omitempty"`
	Label                string                `json:"label,omitempty"`
	ClusterReason        string                `json:"cluster_reason,omitempty"`
	EventCount           int                   `json:"event_count,omitempty"`
	SuccessRate          float64               `json:"success_rate,omitempty"`
	MaturityScore        float64               `json:"maturity_score,omitempty"`
	WinningPath          []string              `json:"winning_path,omitempty"`
	LateAddedSkills      []string              `json:"late_added_skills,omitempty"`
	FinalSnapshotTrigger string                `json:"final_snapshot_trigger,omitempty"`
	MatchedSkillNames    []string              `json:"matched_skill_names,omitempty"`
}

type LifecycleRunSummary

type LifecycleRunSummary struct {
	EvaluatedProfiles    int
	TransitionedProfiles int
	DeletedSkills        int
}

func RunLifecycleOnce

func RunLifecycleOnce(store *Store, paths Paths, workspace string, now time.Time) (LifecycleRunSummary, error)

type Organizer

type Organizer struct {
	// contains filtered or unexported fields
}

func NewOrganizer

func NewOrganizer(opts OrganizerOptions) *Organizer

func (*Organizer) BuildRules

func (o *Organizer) BuildRules(records []LearningRecord) ([]LearningRecord, error)

type OrganizerOptions

type OrganizerOptions struct {
	MinCaseCount   int
	MinSuccessRate float64
	Now            func() time.Time
}

type Paths

type Paths struct {
	Workspace       string
	RootDir         string
	LearningRecords string
	TaskRecords     string
	PatternRecords  string
	SkillDrafts     string
	ProfilesDir     string
	BackupsDir      string
}

func NewPaths

func NewPaths(workspace, override string) Paths

type PatternClusterer

type PatternClusterer interface {
	BuildPatterns(
		ctx context.Context,
		workspace string,
		tasks []LearningRecord,
		existing []LearningRecord,
	) ([]LearningRecord, []string, error)
}

type RecordKind

type RecordKind string

type RecordStatus

type RecordStatus string

type Runtime

type Runtime struct {
	// contains filtered or unexported fields
}

func NewRuntime

func NewRuntime(opts RuntimeOptions) (*Runtime, error)

func (*Runtime) FinalizeTurn

func (rt *Runtime) FinalizeTurn(ctx context.Context, input TurnCaseInput) error

func (*Runtime) RunColdPathOnce

func (rt *Runtime) RunColdPathOnce(ctx context.Context, workspace string) error

type RuntimeOptions

type RuntimeOptions struct {
	Config              config.EvolutionConfig
	Now                 func() time.Time
	Store               *Store
	Organizer           *Organizer
	PatternClusterer    PatternClusterer
	SuccessJudge        SuccessJudge
	SkillsRecaller      *SkillsRecaller
	DraftGenerator      DraftGenerator
	GeneratorFactory    func(workspace string) DraftGenerator
	SuccessJudgeFactory func(workspace string) SuccessJudge
	Applier             *Applier
	ApplierFactory      func(workspace string) *Applier
}

type SkillContextSnapshot

type SkillContextSnapshot struct {
	Sequence   int      `json:"sequence"`
	Trigger    string   `json:"trigger"`
	SkillNames []string `json:"skill_names,omitempty"`
}

type SkillDraft

type SkillDraft struct {
	ID                 string      `json:"id"`
	WorkspaceID        string      `json:"workspace_id"`
	CreatedAt          time.Time   `json:"created_at"`
	UpdatedAt          *time.Time  `json:"updated_at,omitempty"`
	SourceRecordID     string      `json:"source_record_id"`
	TargetSkillName    string      `json:"target_skill_name"`
	MatchedSkillRefs   []string    `json:"matched_skill_refs,omitempty"`
	DraftType          DraftType   `json:"draft_type"`
	ChangeKind         ChangeKind  `json:"change_kind"`
	HumanSummary       string      `json:"human_summary"`
	IntendedUseCases   []string    `json:"intended_use_cases,omitempty"`
	PreferredEntryPath []string    `json:"preferred_entry_path,omitempty"`
	AvoidPatterns      []string    `json:"avoid_patterns,omitempty"`
	BodyOrPatch        string      `json:"body_or_patch"`
	Status             DraftStatus `json:"status"`
	ReviewNotes        []string    `json:"review_notes,omitempty"`
	ScanFindings       []string    `json:"scan_findings,omitempty"`
}

type SkillProfile

type SkillProfile struct {
	SkillName          string              `json:"skill_name"`
	WorkspaceID        string              `json:"workspace_id"`
	CurrentVersion     string              `json:"current_version"`
	Status             SkillStatus         `json:"status"`
	Origin             string              `json:"origin"`
	HumanSummary       string              `json:"human_summary"`
	ChangeReason       string              `json:"change_reason,omitempty"`
	IntendedUseCases   []string            `json:"intended_use_cases,omitempty"`
	PreferredEntryPath []string            `json:"preferred_entry_path,omitempty"`
	AvoidPatterns      []string            `json:"avoid_patterns,omitempty"`
	LastUsedAt         time.Time           `json:"last_used_at"`
	UseCount           int                 `json:"use_count"`
	RetentionScore     float64             `json:"retention_score"`
	VersionHistory     []SkillVersionEntry `json:"version_history"`
}

type SkillStatus

type SkillStatus string
const (
	SkillStatusActive   SkillStatus = "active"
	SkillStatusCold     SkillStatus = "cold"
	SkillStatusArchived SkillStatus = "archived"
	SkillStatusDeleted  SkillStatus = "deleted"
)

func NextLifecycleState

func NextLifecycleState(profile SkillProfile, now time.Time) SkillStatus

type SkillVersionEntry

type SkillVersionEntry struct {
	Version        string    `json:"version"`
	Action         string    `json:"action"`
	Timestamp      time.Time `json:"timestamp"`
	DraftID        string    `json:"draft_id,omitempty"`
	Summary        string    `json:"summary"`
	Rollback       bool      `json:"rollback,omitempty"`
	RollbackReason string    `json:"rollback_reason,omitempty"`
}

type SkillsRecaller

type SkillsRecaller struct {
	// contains filtered or unexported fields
}

func NewSkillsRecaller

func NewSkillsRecaller(workspace string) *SkillsRecaller

func (*SkillsRecaller) RecallSimilarSkills

func (r *SkillsRecaller) RecallSimilarSkills(rule LearningRecord) ([]skills.SkillInfo, error)

type Store

type Store struct {
	// contains filtered or unexported fields
}

func NewStore

func NewStore(paths Paths) *Store

func (*Store) AppendLearningRecord

func (s *Store) AppendLearningRecord(ctx context.Context, record LearningRecord) error

func (*Store) AppendLearningRecords

func (s *Store) AppendLearningRecords(records []LearningRecord) error

func (*Store) AppendPatternRecords

func (s *Store) AppendPatternRecords(records []LearningRecord) error

func (*Store) AppendTaskRecord

func (s *Store) AppendTaskRecord(ctx context.Context, record LearningRecord) error

func (*Store) AppendTaskRecords

func (s *Store) AppendTaskRecords(ctx context.Context, records []LearningRecord) error

func (*Store) LoadDrafts

func (s *Store) LoadDrafts() ([]SkillDraft, error)

func (*Store) LoadLearningRecords

func (s *Store) LoadLearningRecords() ([]LearningRecord, error)

func (*Store) LoadPatternRecords

func (s *Store) LoadPatternRecords() ([]LearningRecord, error)

func (*Store) LoadProfile

func (s *Store) LoadProfile(skillName string) (SkillProfile, error)

func (*Store) LoadProfiles

func (s *Store) LoadProfiles() ([]SkillProfile, error)

func (*Store) LoadTaskRecords

func (s *Store) LoadTaskRecords() ([]LearningRecord, error)

func (*Store) MarkTaskRecordsClustered

func (s *Store) MarkTaskRecordsClustered(ids []string) error

func (*Store) MergePatternRecords

func (s *Store) MergePatternRecords(records []LearningRecord) error

func (*Store) SaveDrafts

func (s *Store) SaveDrafts(drafts []SkillDraft) error

func (*Store) SavePatternRecords

func (s *Store) SavePatternRecords(records []LearningRecord) error

func (*Store) SaveProfile

func (s *Store) SaveProfile(profile SkillProfile) error

func (*Store) SaveTaskRecords

func (s *Store) SaveTaskRecords(records []LearningRecord) error

func (*Store) UpdateProfile

func (s *Store) UpdateProfile(
	workspaceID, skillName string,
	update func(profile *SkillProfile, exists bool) error,
) error

type SuccessJudge

type SuccessJudge interface {
	JudgeTaskRecord(ctx context.Context, record LearningRecord) (TaskSuccessDecision, error)
}

type TaskSuccessDecision

type TaskSuccessDecision struct {
	Success bool
	Reason  string
}

type ToolExecutionRecord

type ToolExecutionRecord struct {
	Name         string   `json:"name"`
	Success      bool     `json:"success"`
	ErrorSummary string   `json:"error_summary,omitempty"`
	SkillNames   []string `json:"skill_names,omitempty"`
}

type TurnCaseInput

type TurnCaseInput struct {
	Workspace             string
	WorkspaceID           string
	TurnID                string
	SessionKey            string
	AgentID               string
	Status                string
	UserMessage           string
	FinalContent          string
	ToolKinds             []string
	ToolExecutions        []ToolExecutionRecord
	ActiveSkillNames      []string
	AttemptedSkillNames   []string
	FinalSuccessfulPath   []string
	SkillContextSnapshots []SkillContextSnapshot
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL