frecency

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package frecency provides frequency and recency-based scoring for workflow history.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CachePath

func CachePath() string

CachePath returns the path to the frecency cache file. Migrates from old gh-wfd directory to lazydispatch if needed.

func Score

func Score(entry HistoryEntry) float64

Score calculates the frecency score for an entry. Higher scores indicate more frequently and recently used entries.

func SortByFrecency

func SortByFrecency(entries []HistoryEntry)

SortByFrecency sorts entries by frecency score in descending order.

Types

type ChainStepResult

type ChainStepResult struct {
	Workflow   string `json:"workflow"`
	Status     string `json:"status"`
	Conclusion string `json:"conclusion"`
	RunID      int64  `json:"run_id"`
}

ChainStepResult represents the result of a single step in a chain run.

type EntryType

type EntryType string

EntryType distinguishes between workflow and chain entries.

const (
	EntryTypeWorkflow EntryType = "workflow"
	EntryTypeChain    EntryType = "chain"
)

History entry types.

type HistoryEntry

type HistoryEntry struct {
	LastRunAt   time.Time         `json:"last_run_at"`
	Inputs      map[string]string `json:"inputs"`
	Type        EntryType         `json:"type"`
	Workflow    string            `json:"workflow"`
	ChainName   string            `json:"chain_name,omitempty"`
	Branch      string            `json:"branch"`
	StepResults []ChainStepResult `json:"step_results,omitempty"`
	RunCount    int               `json:"run_count"`
}

HistoryEntry represents a single workflow or chain run in history.

func FilterByType

func FilterByType(entries []HistoryEntry, entryType EntryType) []HistoryEntry

FilterByType returns entries matching the given entry type. Empty type "" is treated as workflow for backward compatibility.

func FilterByWorkflow

func FilterByWorkflow(entries []HistoryEntry, workflow string) []HistoryEntry

FilterByWorkflow returns entries matching the given workflow filename. Only filters workflow-type entries (chains are excluded).

type Store

type Store struct {
	Entries map[string][]HistoryEntry `json:"entries"`
}

Store holds frecency history keyed by repository (org/repo).

func Load

func Load() (*Store, error)

Load reads the store from disk, returning empty store if not found.

func LoadFrom

func LoadFrom(path string) (*Store, error)

LoadFrom reads the store from a specific path.

func NewStore

func NewStore() *Store

NewStore creates an empty Store.

func (*Store) Record

func (s *Store) Record(repo, workflow, branch string, inputs map[string]string)

Record adds or updates a workflow history entry for the given repo.

func (*Store) RecordChain

func (s *Store) RecordChain(repo, chainName, branch string, inputs map[string]string, stepResults []ChainStepResult)

RecordChain adds or updates a chain history entry for the given repo.

func (*Store) Save

func (s *Store) Save() error

Save writes the store to disk.

func (*Store) SaveTo

func (s *Store) SaveTo(path string) error

SaveTo writes the store to a specific path.

func (*Store) TopForRepo

func (s *Store) TopForRepo(repo, workflowFilter string, limit int) []HistoryEntry

TopForRepo returns the top entries for a repo, optionally filtered by workflow.

Jump to

Keyboard shortcuts

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