Documentation
¶
Index ¶
- type Cache
- func (c *Cache) Filter(term string) []SearchResult
- func (c *Cache) GetFrecencyScore(slug string) float64
- func (c *Cache) IsDirty() bool
- func (c *Cache) IsStale() bool
- func (c *Cache) RecordAccess(slug string)
- func (c *Cache) Search(term string) []SearchResult
- func (c *Cache) Write(provider CachePathProvider) error
- func (c *Cache) WriteIfDirty(provider CachePathProvider) error
- type CachePathProvider
- type ErrAmbiguous
- type ErrNotFound
- type FrecencyData
- type ProgressFunc
- type Repo
- type RepoFetcher
- type SearchResult
- type UpdateConfig
- type UpdateOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
Repositories []Repo `json:"repositories"`
LastUpdated time.Time `json:"last_updated"`
Frecency map[string]FrecencyData `json:"frecency"`
// contains filtered or unexported fields
}
Cache holds the full repository cache with frecency data.
func BuildUpdatedCache ¶
func BuildUpdatedCache(repos []Repo, existingFrecency map[string]FrecencyData) *Cache
BuildUpdatedCache creates a new cache from a fresh list of repos, preserving frecency data from the existing cache for repos that still exist. Frecency entries for repos no longer present are garbage collected.
func Read ¶
func Read(provider CachePathProvider) *Cache
Read loads the cache from disk. If the file is missing, corrupted, or unreadable, it returns an empty cache so auto-update can recreate it.
func Update ¶
func Update(cfg UpdateConfig, existing *Cache, opts UpdateOptions) (*Cache, error)
Update performs a full cache refresh across all configured domains. For each domain it fetches personal repos and org repos (applying filters and favorites), then rebuilds the cache preserving frecency data from existing. The new cache is written to disk.
func (*Cache) Filter ¶
func (c *Cache) Filter(term string) []SearchResult
Filter finds repositories using substring matching only — no fuzzy, no frecency ranking. Used by `work list --filter`.
func (*Cache) GetFrecencyScore ¶
GetFrecencyScore computes the frecency score for a repository slug. Score = access_count * recency_multiplier. Returns 0 if the slug has never been accessed.
func (*Cache) IsStale ¶
IsStale returns true if the cache was last updated more than 24 hours ago or has never been updated (zero time).
func (*Cache) RecordAccess ¶
RecordAccess updates frecency data for the given slug and marks the cache as dirty.
func (*Cache) Search ¶
func (c *Cache) Search(term string) []SearchResult
Search finds repositories matching the given term using tiered scoring: exact match (100), substring (50), fuzzy (normalized). Results are ranked by matchScore + frecencyScore, limited to 20.
func (*Cache) Write ¶
func (c *Cache) Write(provider CachePathProvider) error
Write serializes the cache to disk, creating parent directories as needed.
func (*Cache) WriteIfDirty ¶
func (c *Cache) WriteIfDirty(provider CachePathProvider) error
WriteIfDirty writes the cache to disk only if it has been modified since the last read or write.
type CachePathProvider ¶
type CachePathProvider interface {
CacheFile() string
}
CachePathProvider is the interface needed from config to locate the cache file.
type ErrAmbiguous ¶
type ErrAmbiguous struct {
Query string
Suggestions []SearchResult
}
ErrAmbiguous is returned when multiple repositories match and there is no single exact match to disambiguate.
func (*ErrAmbiguous) Error ¶
func (e *ErrAmbiguous) Error() string
type ErrNotFound ¶
type ErrNotFound struct {
Query string
}
ErrNotFound is returned when no repositories match the query.
func (*ErrNotFound) Error ¶
func (e *ErrNotFound) Error() string
type FrecencyData ¶
type FrecencyData struct {
AccessCount int `json:"access_count"`
LastAccess time.Time `json:"last_access"`
}
FrecencyData tracks access frequency and recency for a repository.
type ProgressFunc ¶
type ProgressFunc func(msg string)
ProgressFunc is called to report status during cache update.
type Repo ¶
type Repo struct {
Slug string `json:"slug"`
CloneURL string `json:"clone_url"`
Domain string `json:"domain"`
}
Repo represents a single cached repository.
func Resolve ¶
func Resolve(results []SearchResult, query string) (*Repo, error)
Resolve takes search results and returns the single best match.
Resolution rules:
- 0 results → ErrNotFound
- 1 result → use it
- 1 exact match among many → use the exact match
- multiple with no single exact → ErrAmbiguous with suggestions
type RepoFetcher ¶
type RepoFetcher interface {
ListUserOrgs(ctx context.Context) ([]ghclient.Org, error)
ListOrgRepos(ctx context.Context, org string) ([]ghclient.Repo, error)
ListPersonalRepos(ctx context.Context) ([]ghclient.Repo, error)
}
RepoFetcher abstracts GitHub API calls needed for cache updates.
type SearchResult ¶
type SearchResult struct {
Repo Repo
MatchScore float64
FrecencyAdd float64
TotalScore float64
IsExactMatch bool
}
SearchResult holds a matched repo with its combined score.
type UpdateConfig ¶
type UpdateConfig interface {
CachePathProvider
// DomainNames returns the configured domain hostnames.
DomainNames() []string
// DomainFavorites returns the favorite org names for the given domain.
DomainFavorites(domain string) []string
// ShouldIncludeOrg determines whether an org passes the global include/exclude filters.
ShouldIncludeOrg(org string) bool
}
UpdateConfig provides configuration needed for cache updates. This is a narrow interface consistent with CachePathProvider and RepoFetcher — callers pass only what Update needs rather than the full *config.Config.
type UpdateOptions ¶
type UpdateOptions struct {
// AllOrgs ignores per-domain favorite_orgs, fetching all orgs.
AllOrgs bool
// Progress is called with status messages during update. May be nil.
Progress ProgressFunc
// ClientFactory creates a RepoFetcher for a domain. If nil, uses github.NewClient.
ClientFactory func(domain, token string) RepoFetcher
// TokenFunc resolves auth tokens for a domain. Required.
TokenFunc func(domain string) (string, error)
}
UpdateOptions controls cache update behavior.