session

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package session parses Claude Code session JSONL files to extract tool usage patterns for adoption and discovery analytics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodedPath

func EncodedPath(repoRoot string) string

EncodedPath converts a repo path to Claude Code's encoded directory name. "/Users/kehoe/Repositories/myproject" -> "-Users-kehoe-Repositories-myproject"

func FormatDiscoverSummary

func FormatDiscoverSummary(result *DiscoverResult) string

FormatDiscoverSummary produces the human-readable discover output.

func FormatSessionSummary

func FormatSessionSummary(sessions []SessionInfo) string

FormatSessionSummary produces the human-readable session adoption output.

func ListSessions

func ListSessions(repoRoot string, since time.Time, limit int) ([]string, error)

ListSessions returns session JSONL files for the given repo, sorted by modification time (newest first).

func ParseSession

func ParseSession(path string, repoRoot string) ([]EditEvent, []ContextEvent, error)

ParseSession extracts edit and context events from a session JSONL file.

func SessionDir

func SessionDir() string

SessionDir returns the Claude Code projects directory.

Types

type ContextEvent

type ContextEvent struct {
	FilePath  string
	Timestamp time.Time
}

ContextEvent represents a get_context call from a session.

type DiscoverResult

type DiscoverResult struct {
	SessionsScanned  int          `json:"sessions_scanned"`
	FilesEdited      int          `json:"files_edited"`
	ContextRequested int          `json:"context_requested"`
	Coverage         float64      `json:"coverage"`
	MissedFiles      []MissedFile `json:"missed_files,omitempty"`
}

DiscoverResult contains the output of the discover analysis.

func Discover

func Discover(repoRoot string, since time.Time, includeTests bool, isSupportedExt func(string) bool, usageLog ...UsageLogQuerier) (*DiscoverResult, error)

Discover analyzes sessions to find files edited without get_context being called. If usageLog is non-nil, it also checks the usage_log table for hook-injected context that doesn't appear in session JSONL files.

type EditEvent

type EditEvent struct {
	FilePath  string
	Tool      string // "Edit" or "Write"
	Timestamp time.Time
}

EditEvent represents a file edit extracted from a session.

type MissedFile

type MissedFile struct {
	File         string `json:"file"`
	EditCount    int    `json:"edit_count"`
	ContextCount int    `json:"context_count"`
	IsTest       bool   `json:"is_test,omitempty"`
}

MissedFile represents a file edited without get_context being called.

type SessionInfo

type SessionInfo struct {
	ID       string    `json:"id"`
	Date     time.Time `json:"date"`
	Edits    int       `json:"edits"`
	Contexts int       `json:"contexts"`
	Coverage float64   `json:"coverage"` // contexts / editable files edited
}

SessionInfo contains metadata about a parsed session.

func GetSessionStats

func GetSessionStats(repoRoot string, since time.Time, limit int, isSupportedExt func(string) bool, usageLog ...UsageLogQuerier) ([]SessionInfo, error)

GetSessionStats returns adoption stats per session. If usageLog is provided, it also checks the usage_log table for hook-injected context.

type UsageLogQuerier

type UsageLogQuerier interface {
	// FilesWithUsage returns the set of files that have usage_log entries since the given time.
	FilesWithUsage(since time.Time) (map[string]bool, error)
}

UsageLogQuerier can check whether a file has been analyzed via the usage_log table.

Jump to

Keyboard shortcuts

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