insights

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package insights provides AI-powered project analytics and recommendations. It analyzes task completion patterns, velocity, risk, and generates actionable insights.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CrossInsightPrompt

func CrossInsightPrompt(m *CrossMetrics) string

CrossInsightPrompt builds the AI prompt for cross-project analysis.

func InsightPrompt

func InsightPrompt(goal, instructions string, plan *pm.Plan, m *Metrics) string

InsightPrompt builds the prompt for AI-powered project analysis.

Types

type CrossInsightReport

type CrossInsightReport struct {
	Metrics         *CrossMetrics
	VelocityTrends  string
	FailurePatterns string
	ProviderPerf    string
	Recommendations string
	GeneratedAt     time.Time
}

CrossInsightReport is the full result of a cross-project analysis.

func GenerateCross

func GenerateCross(ctx context.Context, p provider.Provider, model string, timeout time.Duration, snaps []*ProjectSnapshot) (*CrossInsightReport, error)

GenerateCross runs AI analysis on cross-project metrics and returns a structured report.

type CrossMetrics

type CrossMetrics struct {
	Projects []ProjectSnapshot

	TotalProjects     int
	ActiveProjects    int // projects with at least one task
	TotalTasksAcross  int
	TotalDoneAcross   int
	TotalFailedAcross int

	AvgCompletionRate float64 // mean completion % across projects

	TopTags            []TagCount
	TopRoles           []TagCount
	TopFailureKeywords []TagCount

	ProviderCounts map[string]int

	VelocityMin  float64
	VelocityMax  float64
	VelocityMean float64
}

CrossMetrics aggregates metrics across multiple projects.

func AggregateProjects

func AggregateProjects(snaps []*ProjectSnapshot) *CrossMetrics

AggregateProjects computes cross-project metrics from a list of snapshots.

type InsightReport

type InsightReport struct {
	Metrics     *Metrics
	AIAnalysis  string
	GeneratedAt time.Time
}

InsightReport is the full AI-generated analysis.

func Generate

func Generate(ctx context.Context, p provider.Provider, s *state.ProjectState, model string, timeout time.Duration) (*InsightReport, error)

Generate calls the AI provider to produce a full insight report.

type Metrics

type Metrics struct {
	TotalTasks      int
	DoneTasks       int
	FailedTasks     int
	SkippedTasks    int
	InProgressTasks int
	PendingTasks    int
	BlockedTasks    int // permanently blocked by failed deps

	// Velocity: tasks completed per day (based on CompletedAt timestamps)
	VelocityPerDay float64

	// AvgTaskDuration is the mean duration of completed tasks.
	AvgTaskDuration time.Duration

	// EstimatedDaysRemaining is a rough forecast based on velocity.
	// -1 means not enough data.
	EstimatedDaysRemaining float64

	// RiskScore is 0-100 (0 = low risk, 100 = critical).
	RiskScore int

	// RiskFactors lists what contributed to the risk score.
	RiskFactors []string

	// RoleBreakdown maps role name to counts {done, total}.
	RoleBreakdown map[string][2]int

	// TokenCost tracks session token usage.
	InputTokens  int
	OutputTokens int
}

Metrics holds computed project health metrics.

func Analyze

func Analyze(s *state.ProjectState) *Metrics

Analyze computes metrics from the current project state.

func (*Metrics) CompletionPct

func (m *Metrics) CompletionPct() int

CompletionPct returns percentage of tasks done or skipped.

func (*Metrics) RiskLabel

func (m *Metrics) RiskLabel() string

RiskLabel returns a human-readable risk level.

type ProjectSnapshot

type ProjectSnapshot struct {
	Name            string
	Path            string
	Goal            string
	Provider        string
	TotalTasks      int
	DoneTasks       int
	FailedTasks     int
	SkippedTasks    int
	PendingTasks    int
	CompletionPct   float64
	Tags            []string // deduplicated tags from all tasks
	Roles           []string // deduplicated roles from all tasks
	FailureReasons  []string // short failure summaries from task results
	VelocityPerDay  float64
	AvgTaskDuration time.Duration
	LastUpdated     time.Time
	Error           string // non-empty if loading failed
}

ProjectSnapshot holds the metrics collected from a single project.

func CollectFromProject

func CollectFromProject(name, path string) *ProjectSnapshot

CollectFromProject reads one project's state and builds a ProjectSnapshot. Returns a snapshot with Error set if loading failed (non-fatal).

func CollectFromWorkspaces

func CollectFromWorkspaces(wsFile string) ([]*ProjectSnapshot, error)

CollectFromWorkspaces loads all registered workspaces and returns per-project snapshots. Uses wsFile if non-empty, otherwise the global workspace registry.

type TagCount

type TagCount struct {
	Label string
	Count int
}

TagCount pairs a label with its frequency.

Jump to

Keyboard shortcuts

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