intel

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package intel provides analytical intelligence over Claude Code session data. It transforms raw discovery data into actionable summaries and reports.

Index

Constants

View Source
const (
	ActivityUserRequest = "user_request"
	ActivityFileEdit    = "file_edit"
	ActivityBashCommand = "bash_command"
	ActivityGitOp       = "git_op"
	ActivityError       = "error"
	ActivityToolCall    = "tool_call"
)

Activity type constants.

Variables

This section is empty.

Functions

func CalculateBurnRate added in v0.9.0

func CalculateBurnRate(path string) float64

CalculateBurnRate reads the last 10 minutes of assistant messages from a transcript and returns the estimated cost per hour in USD. Returns 0.0 if there are no assistant messages in the last 10 minutes (session is idle).

Pricing blended ~$45/M tokens (Opus: $15 input + $75 output average).

func CalculateMomentum

func CalculateMomentum(metrics DayMetrics) (score float64, components map[string]float64)

CalculateMomentum computes the Momentum score from Codex's recommendation. Four components: Outcome, Validation, Flow, Drag.

func EnrichBrief added in v1.0.0

func EnrichBrief(brief *DailyBrief, projectsDir, sessionsDir string, since time.Time)

EnrichBrief populates the secretary-format fields on an existing DailyBrief: waiting sessions, git branch/dirty state, cost estimates, and last-active times. It re-scans sessions to determine live state. This is a separate pass so the core GenerateBrief stays fast and testable without filesystem side effects.

func FormatBrief

func FormatBrief(summary SessionSummary) string

FormatBrief renders a single SessionSummary as a human-readable text block.

func FormatComparison

func FormatComparison(cmp DayComparison) string

FormatComparison renders a day comparison as a readable report.

func FormatCostReport added in v0.5.0

func FormatCostReport(report CostReport) string

FormatCostReport renders a cost report as human-readable text.

func FormatDailyBrief

func FormatDailyBrief(brief DailyBrief) string

FormatDailyBrief renders a DailyBrief in the secretary format -- concise, action-oriented, suitable for a CEO who needs to know what to do next.

func FormatDailyBriefVerbose added in v1.0.0

func FormatDailyBriefVerbose(brief DailyBrief) string

FormatDailyBriefVerbose renders a DailyBrief as a detailed plaintext report. This is the original format, kept for the --verbose flag.

func FormatMomentum

func FormatMomentum(score float64, components map[string]float64) string

FormatMomentum renders the Momentum score as a brief display.

func ParseSinceFlag

func ParseSinceFlag(value string) (time.Time, error)

ParseSinceFlag parses the --since flag value into a time.Time. Supported formats:

  • "" (empty) -> 24 hours ago (default)
  • "24h", "12h", "48h" etc -> duration ago
  • "yesterday" -> yesterday at 9:00 AM local time

func RunAIBrief added in v0.5.0

func RunAIBrief()

RunAIBrief generates a structured brief, then uses claude -p to produce a natural language summary. This is opt-in because it costs tokens.

func RunCostReport added in v0.5.0

func RunCostReport()

RunCostReport is the entrypoint for the `opsdeck costs` subcommand. It tries ccusage first (accurate pricing from LiteLLM), falls back to built-in estimation if ccusage is not installed.

func RunMetricsReport

func RunMetricsReport()

RunMetricsReport generates and prints the full metrics comparison report.

func SummarizeActivities

func SummarizeActivities(activities []Activity) []string

SummarizeActivities condenses a list of raw activities into at most 5 human-readable bullet points suitable for an executive summary.

The algorithm:

  1. User requests appear verbatim (they are what the user asked for).
  2. File edits are grouped: "Edited N files (a.go, b.go, ...)"
  3. Bash commands are grouped: "Ran N commands"
  4. Git operations are grouped: "Committed and pushed changes" / "Created PR"
  5. Errors are grouped: "Encountered N errors"
  6. Tool calls (Grep, Glob, etc.) are omitted -- they are noise.

Results are capped at 5 items with user requests taking priority.

func SummarizeOneLine added in v1.0.0

func SummarizeOneLine(activities []Activity) string

SummarizeOneLine condenses a list of activities into a single short line suitable for the secretary brief. It prioritizes user requests for context, then falls back to describing what tools did.

Types

type Activity

type Activity struct {
	Timestamp   time.Time
	Type        string // one of the Activity* constants
	Description string
}

Activity represents a single discrete event extracted from a transcript.

type CostReport added in v0.5.0

type CostReport struct {
	Sessions    []SessionCost
	TotalCost   float64
	TotalTokens int64
	Period      string
}

CostReport holds the full cost report across all sessions.

func GenerateCostReport added in v0.5.0

func GenerateCostReport(projectsDir, sessionsDir string, since time.Time) (CostReport, error)

GenerateCostReport scans all sessions and produces a cost report.

type DailyBrief

type DailyBrief struct {
	GeneratedAt    time.Time
	Period         string // "Last 24 hours" or "Since yesterday 9am"
	Projects       []ProjectBrief
	TotalSessions  int
	ActiveSessions int
	TotalEdits     int
	TotalCommands  int
	Highlights     []string // top 3-5 most notable things
	Attention      []string // things that need the user's attention
	CostEstimate   float64  // estimated spend in USD for the period
}

DailyBrief is the top-level daily report summarizing all Claude Code sessions.

func GenerateBrief

func GenerateBrief(projectsDir, sessionsDir string, since time.Time) (DailyBrief, error)

GenerateBrief scans all sessions and produces a daily brief covering activity since the given time. It reads session files from sessionsDir, locates transcripts under projectsDir, and aggregates per-project summaries.

If directories do not exist, it returns a valid but empty brief.

type DayComparison

type DayComparison struct {
	Today     DayMetrics
	Yesterday DayMetrics
	// Deltas (positive = improvement)
	EditsDelta    int
	CommandsDelta int
	FilesDelta    int
	SessionsDelta int
	ProjectsDelta int
	ErrorsDelta   int
	// Overall trend
	Trend string // "more productive", "similar", "less productive"
}

DayComparison compares two days of metrics.

func CompareDays

func CompareDays(projectsDir, sessionsDir string) DayComparison

CompareDays computes metrics for today and yesterday and returns a comparison.

type DayMetrics

type DayMetrics struct {
	Date           string // "2026-03-22"
	ActiveSessions int    // sessions with any activity
	TotalEdits     int    // file edits across all sessions
	TotalCommands  int    // bash commands across all sessions
	TotalErrors    int    // errors encountered
	FilesChanged   int    // unique files touched
	GitOps         int    // git operations (commits, pushes, PRs)
	Projects       int    // unique projects with activity
	// Per-project breakdown
	ProjectMetrics []ProjectDayMetrics
}

DayMetrics holds quantified productivity metrics for a single day.

func ComputeDayMetrics

func ComputeDayMetrics(projectsDir, sessionsDir string, day time.Time) DayMetrics

ComputeDayMetrics computes metrics for a specific day across all sessions.

type ProjectBrief

type ProjectBrief struct {
	Name            string
	Path            string
	SessionCount    int
	ActiveCount     int // sessions with activity in period
	TotalEdits      int
	TotalCommands   int
	FilesChanged    []string
	KeyActivities   []string // top 5 most important activities
	NeedsAttention  bool     // any session stuck/waiting/errored
	AttentionReason string

	// Secretary brief fields.
	WaitingSessions []WaitingSession // sessions waiting for user input
	OneLine         string           // one-line activity summary
	Branch          string           // git branch name
	IsDirty         bool             // git working tree has changes
	LatestTag       string           // latest git tag (e.g. "v1.0.1")
	LastActive      time.Time        // most recent activity across all sessions
}

ProjectBrief summarizes activity for a single project over a time period.

type ProjectDayMetrics

type ProjectDayMetrics struct {
	Name     string
	Edits    int
	Commands int
	Errors   int
	Files    int
	GitOps   int
	Sessions int // sessions with activity
}

ProjectDayMetrics holds metrics for a single project on a single day.

type SessionCost added in v0.5.0

type SessionCost struct {
	SessionID    string
	Project      string
	Model        string // predominant model (most messages)
	InputTokens  int64
	OutputTokens int64
	CacheWrite   int64
	CacheRead    int64
	TotalTokens  int64
	EstCostUSD   float64
	MessageCount int
}

SessionCost holds token usage and estimated cost for a session.

func ExtractCosts added in v0.5.0

func ExtractCosts(path string, since time.Time) (SessionCost, error)

ExtractCosts reads a transcript JSONL and returns token usage/cost data.

type SessionSummary

type SessionSummary struct {
	SessionID     string
	Project       string
	Activities    []Activity
	FilesChanged  []string
	LastUserMsg   string
	LastAssistMsg string
	TotalMessages int
	ErrorCount    int
	EditCount     int
	BashCount     int
	ReadCount     int
}

SessionSummary holds a complete activity summary for a single session.

func ExtractRecent

func ExtractRecent(path string, since time.Time) (SessionSummary, error)

ExtractRecent reads a transcript and returns a summary of activity after `since`. If the file does not exist, returns an empty summary and no error.

func ExtractSummary

func ExtractSummary(path string) (SessionSummary, error)

ExtractSummary reads an entire transcript and returns a full SessionSummary. If the file does not exist or is empty, returns an empty summary and no error.

type SessionTimeline added in v0.6.0

type SessionTimeline struct {
	SessionID string          `json:"session_id"`
	Project   string          `json:"project"`
	StartedAt time.Time       `json:"started_at"`
	EndedAt   time.Time       `json:"ended_at"`
	Events    []TimelineEvent `json:"events"`
}

SessionTimeline holds the complete timeline for a session.

func ExtractTimeline added in v0.6.0

func ExtractTimeline(path string, since time.Time) (SessionTimeline, error)

ExtractTimeline reads a transcript and builds a timeline of events.

type TimelineEvent added in v0.6.0

type TimelineEvent struct {
	Timestamp time.Time `json:"timestamp"`
	Type      string    `json:"type"` // "user", "tool", "text", "error", "idle"
	Tool      string    `json:"tool,omitempty"`
	Duration  int       `json:"duration"` // seconds until next event
}

TimelineEvent represents a single point on a session timeline.

type WaitingSession added in v1.0.0

type WaitingSession struct {
	SessionID    string
	ProjectName  string
	WaitingSince time.Time // when it started waiting (last activity)
	LastUserMsg  string    // last user message (truncated)
}

WaitingSession describes a session that is waiting for user input.

Jump to

Keyboard shortcuts

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