analytics

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterRoutes

func RegisterRoutes(api huma.API, store *Store)

RegisterRoutes wires up all analytics-related HTTP endpoints onto the provided Huma API.

Types

type ActivationSummary

type ActivationSummary struct {
	TotalCount    int            `json:"total_count"`
	UniqueDevs    int            `json:"unique_devs"`
	LastTriggered *time.Time     `json:"last_triggered"`
	ByAgent       map[string]int `json:"by_agent"`
}

ActivationSummary summarises activations for a specific skill over a time window.

type AgentDailyCount

type AgentDailyCount struct {
	Date   string         `json:"date"`
	Agents map[string]int `json:"-"`
}

AgentDailyCount holds per-agent activation counts for a single day.

func (AgentDailyCount) MarshalJSON

func (a AgentDailyCount) MarshalJSON() ([]byte, error)

MarshalJSON produces a flat object: {"date":"2026-05-20","claude-code":5,"cursor":2}

type DailyCount

type DailyCount struct {
	Date  string `json:"date"`
	Count int    `json:"count"`
}

DailyCount holds the activation count for a single day.

type Event

type Event struct {
	SkillName     string `json:"skill_name"`
	Agent         string `json:"agent"`
	TriggerType   string `json:"trigger_type"`
	ProjectHash   string `json:"project_hash"`
	DeveloperHash string `json:"developer_hash"`
}

Event represents a single skill activation telemetry record.

type OverviewData

type OverviewData struct {
	TotalSkills      int             `json:"total_skills"`
	ActiveSkills     int             `json:"active_skills"`
	TotalActivations int             `json:"total_activations"`
	UnreviewedSkills int             `json:"unreviewed_skills"`
	Security         SecuritySummary `json:"security"`
}

OverviewData holds top-level KPI metrics for the analytics overview strip.

type SecuritySummary

type SecuritySummary struct {
	Clean    int `json:"clean"`
	Warning  int `json:"warning"`
	Critical int `json:"critical"`
}

SecuritySummary aggregates skill security statuses. The scanner produces "warn" and "high" status strings; both are counted under the Warning field. "critical" maps to Critical. Everything else (including "clean", "info", and skills with no scan results) maps to Clean.

type SkillAnalytics

type SkillAnalytics struct {
	Name           string     `json:"name"`
	Description    string     `json:"description"`
	Tags           []string   `json:"tags"`
	Author         string     `json:"author"`
	SpecCompliance string     `json:"spec_compliance"`
	Activations    int        `json:"activations"`
	UniqueDevs     int        `json:"unique_devs"`
	LastTriggered  *time.Time `json:"last_triggered"`
	SecurityStatus string     `json:"security_status"`
	ReviewedAt     *time.Time `json:"reviewed_at"`
	LatestVersion  int        `json:"latest_version"`
	UpdatedAt      time.Time  `json:"updated_at"`
}

SkillAnalytics holds per-skill analytics data for the table view.

type SkillsQuery added in v0.4.0

type SkillsQuery struct {
	Limit  int
	Offset int
	Sort   string // "activations" (default) | "name" | "updated"
	Query  string // case-insensitive substring on name/description
	Tag    string // frontmatter tag membership
}

GetSkillsAnalytics returns per-skill analytics for all skills over the last `days` days, ordered by activation count descending. SkillsQuery holds optional list filters/pagination for GetSkillsAnalytics.

type Store

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

Store handles Postgres persistence for skill_events.

func NewStore

func NewStore(pool *pgxpool.Pool) *Store

NewStore constructs a Store backed by the given connection pool.

func (*Store) CleanupOldEvents added in v0.7.0

func (s *Store) CleanupOldEvents(ctx context.Context, retentionDays int) (int64, error)

CleanupOldEvents deletes events older than retentionDays and returns the number of rows removed. Pass 0 to disable (caller should check before calling).

func (*Store) DismissSkill

func (s *Store) DismissSkill(ctx context.Context, name string) error

DismissSkill inserts a name into dismissed_skills. Idempotent.

func (*Store) GetActivations

func (s *Store) GetActivations(ctx context.Context, skillName string, days int) (*ActivationSummary, error)

GetActivations returns an ActivationSummary for the given skill over the last `days` days. Returns a zero-value summary (no error) when no events exist.

func (*Store) GetAllTags added in v0.4.0

func (s *Store) GetAllTags(ctx context.Context) ([]string, error)

GetAllTags returns the distinct, sorted set of tags across all skills.

func (*Store) GetOverview

func (s *Store) GetOverview(ctx context.Context, days int) (*OverviewData, error)

GetOverview returns aggregate KPI data covering the last `days` days.

func (*Store) GetSkillTimeSeries

func (s *Store) GetSkillTimeSeries(ctx context.Context, skillName string, days int) ([]AgentDailyCount, error)

GetSkillTimeSeries returns daily per-agent activation counts for a specific skill over the last `days` days. Days with zero activations are included.

func (*Store) GetSkillsAnalytics

func (s *Store) GetSkillsAnalytics(ctx context.Context, days int, opts SkillsQuery) ([]SkillAnalytics, int, error)

func (*Store) GetTimeSeries

func (s *Store) GetTimeSeries(ctx context.Context, days int) ([]DailyCount, error)

GetTimeSeries returns daily activation counts for the last `days` days. Days with zero activations are included (filled with 0).

func (*Store) GetUnregisteredSkills

func (s *Store) GetUnregisteredSkills(ctx context.Context, days int) ([]UnregisteredSkill, error)

GetUnregisteredSkills returns skill names from events that don't exist in the skills table or dismissed_skills table, with activation stats.

func (*Store) Insert

func (s *Store) Insert(ctx context.Context, e Event) error

Insert writes a single activation event into skill_events.

type UnregisteredSkill

type UnregisteredSkill struct {
	Name          string     `json:"name"`
	Activations   int        `json:"activations"`
	UniqueDevs    int        `json:"unique_devs"`
	LastTriggered *time.Time `json:"last_triggered"`
	FirstSeen     *time.Time `json:"first_seen"`
}

UnregisteredSkill represents a skill name found in events but not in the registry.

Jump to

Keyboard shortcuts

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