shared

package
v0.9.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CodeStatsCompactLabels = map[string]string{
	"composer_lines_added":   "added",
	"composer_lines_removed": "removed",
	"composer_files_changed": "files",
	"scored_commits":         "commits",
	"total_prompts":          "prompts",
	"ai_code_percentage":     "ai %",
}

CodeStatsCompactLabels are compact (tile pill) labels for code stats metrics.

View Source
var CodeStatsMetricLabels = map[string]string{
	"composer_lines_added":   "Lines Added",
	"composer_lines_removed": "Lines Removed",
	"composer_files_changed": "Files Changed",
	"scored_commits":         "Commits",
	"total_prompts":          "Prompts",
	"ai_code_percentage":     "AI Code",
}

CodeStatsMetricLabels are display labels shared across coding-tool providers.

View Source
var ErrHookUnsupported = errors.New("hook parsing not supported")

Functions

func AnyPathModifiedAfter added in v0.8.0

func AnyPathModifiedAfter(paths []string, since time.Time) bool

AnyPathModifiedAfter returns true if any of the given paths has an mtime after since. Paths that don't exist or can't be stat'd are silently skipped.

func ApplyStandardRateLimits

func ApplyStandardRateLimits(resp *http.Response, snap *core.UsageSnapshot)

func CodingToolHidePrefixes added in v0.5.8

func CodingToolHidePrefixes() []string

CodingToolHidePrefixes returns the set of metric prefixes hidden by most coding-tool providers.

func CodingToolSectionOrder added in v0.5.8

func CodingToolSectionOrder() []core.DashboardStandardSection

CodingToolSectionOrder returns the standard section order used by coding-tool providers.

func CollectFilesByExt

func CollectFilesByExt(roots []string, exts map[string]bool) ([]string, error)

func CollectFilesWithStat added in v0.8.0

func CollectFilesWithStat(roots []string, exts map[string]bool) (map[string]os.FileInfo, error)

CollectFilesWithStat is like CollectFilesByExt but returns os.FileInfo for each file, enabling mtime+size cache invalidation.

func CreateStandardRequest

func CreateStandardRequest(ctx context.Context, baseURL, endpoint, apiKey string, headers map[string]string) (*http.Request, error)

func DefaultCodeStatsConfig added in v0.5.8

func DefaultCodeStatsConfig() core.CodeStatsConfig

DefaultCodeStatsConfig returns the standard CodeStatsConfig used by coding-tool providers.

func ExpandHome

func ExpandHome(path string) string

func ExtractFilePathsFromPayload added in v0.6.3

func ExtractFilePathsFromPayload(input any) []string

ExtractFilePathsFromPayload walks a JSON-like structure and extracts file path candidates from values stored under path-related keys. This is used by telemetry adapters to extract tool target file paths for language inference.

func FetchJSON added in v0.7.0

func FetchJSON(ctx context.Context, url, apiKey string, out any, client *http.Client) (int, http.Header, error)

FetchJSON performs an authenticated GET request and decodes the JSON response body into out. Returns the HTTP status code and response headers on success. For non-200 responses, returns an error with the status code. If client is nil a default client with a 30-second timeout is used.

func FinalizeStatus

func FinalizeStatus(snap *core.UsageSnapshot)

func FirstPathNumber added in v0.6.7

func FirstPathNumber(root map[string]any, paths ...[]string) *float64

FirstPathNumber tries multiple JSON paths and returns the first numeric value found (supports float64, float32, int, int64, int32, json.Number, string).

func FirstPathString added in v0.6.7

func FirstPathString(root map[string]any, paths ...[]string) string

FirstPathString tries multiple JSON paths and returns the first non-empty string value found (supports string and json.Number types).

func FlexParseTime

func FlexParseTime(value string) time.Time

func FormatTokenCount added in v0.6.3

func FormatTokenCount(value int) string

FormatTokenCount returns a human-readable string for a token count (e.g. "1.5K", "2.3M", "1.0B").

func FormatTokenCountF added in v0.6.3

func FormatTokenCountF(value float64) string

FormatTokenCountF is like FormatTokenCount but takes a float64.

func NormalizeLooseClientName added in v0.9.0

func NormalizeLooseClientName(name string) string

func NormalizeLooseModelName added in v0.9.0

func NormalizeLooseModelName(name string) string

func NumberFromAny added in v0.6.7

func NumberFromAny(value any) (float64, bool)

NumberFromAny converts various numeric types to float64.

func NumberToFloat64Ptr added in v0.6.7

func NumberToFloat64Ptr(v *float64) *float64

NumberToFloat64Ptr returns nil for nil input, otherwise a copy of the value.

func NumberToInt64Ptr added in v0.6.7

func NumberToInt64Ptr(v *float64) *int64

NumberToInt64Ptr converts *float64 to *int64, returning nil for nil input.

func ParseFlexibleTimestamp

func ParseFlexibleTimestamp(value string) (int64, bool)

func ParseTimestampString

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

func PathMap added in v0.6.7

func PathMap(root map[string]any, path ...string) (map[string]any, bool)

PathMap is like PathValue but returns the result as map[string]any.

func PathSlice added in v0.6.7

func PathSlice(root map[string]any, path ...string) ([]any, bool)

PathSlice is like PathValue but returns the result as []any.

func PathValue added in v0.6.7

func PathValue(root map[string]any, path ...string) (any, bool)

PathValue traverses a nested map[string]any by the given path segments, returning the value at the final key or (nil, false) if any step is missing.

func ProbeRateLimits added in v0.6.7

func ProbeRateLimits(ctx context.Context, url, apiKey string, snap *core.UsageSnapshot, client *http.Client) error

ProbeRateLimits performs a GET request to the given URL with Bearer auth, copies redacted headers to snap.Raw, applies standard status code handling (401/403 → StatusAuth, 429 → StatusLimited), and parses standard RPM/TPM rate-limit headers. If client is nil a default client with a 30-second timeout is used.

func ProcessStandardResponse

func ProcessStandardResponse(resp *http.Response, acct core.AccountConfig, providerID string) (core.UsageSnapshot, error)

func RequireAPIKey

func RequireAPIKey(acct core.AccountConfig, providerID string) (string, *core.UsageSnapshot)

func ResolveBaseURL

func ResolveBaseURL(acct core.AccountConfig, defaultURL string) string

func SanitizeMetricName added in v0.9.0

func SanitizeMetricName(name string) string

func SanitizeWorkspace

func SanitizeWorkspace(cwd string) string

func SummarizeCountUsage added in v0.9.0

func SummarizeCountUsage(values map[string]float64, unit string, maxItems int, normalizeLabel func(string) string) string

func SummarizeShareUsage added in v0.9.0

func SummarizeShareUsage(values map[string]float64, maxItems int, normalizeLabel func(string) string) string

func Truncate added in v0.6.3

func Truncate(s string, maxLen int) string

Truncate shortens s to maxLen runes, appending "…" if truncated.

func UnixAuto

func UnixAuto(ts int64) time.Time

Types

type TelemetryChannel

type TelemetryChannel string
const (
	TelemetryChannelHook   TelemetryChannel = "hook"
	TelemetryChannelSSE    TelemetryChannel = "sse"
	TelemetryChannelJSONL  TelemetryChannel = "jsonl"
	TelemetryChannelAPI    TelemetryChannel = "api"
	TelemetryChannelSQLite TelemetryChannel = "sqlite"
)

type TelemetryCollectOptions

type TelemetryCollectOptions struct {
	Paths     map[string]string
	PathLists map[string][]string
}

func (TelemetryCollectOptions) Path

func (o TelemetryCollectOptions) Path(key string, fallback string) string

func (TelemetryCollectOptions) PathsFor

func (o TelemetryCollectOptions) PathsFor(key string, fallback []string) []string

type TelemetryEvent

type TelemetryEvent struct {
	SchemaVersion string
	Channel       TelemetryChannel
	OccurredAt    time.Time
	AccountID     string
	WorkspaceID   string
	SessionID     string
	TurnID        string
	MessageID     string
	ToolCallID    string
	ProviderID    string
	AgentName     string
	EventType     TelemetryEventType
	ModelRaw      string

	core.TokenUsage

	ToolName string
	Status   TelemetryStatus
	Payload  map[string]any
}

type TelemetryEventType

type TelemetryEventType string
const (
	TelemetryEventTypeTurnCompleted TelemetryEventType = "turn_completed"
	TelemetryEventTypeMessageUsage  TelemetryEventType = "message_usage"
	TelemetryEventTypeToolUsage     TelemetryEventType = "tool_usage"
	TelemetryEventTypeRawEnvelope   TelemetryEventType = "raw_envelope"
)

type TelemetrySource

type TelemetrySource interface {
	System() string
	DefaultCollectOptions() TelemetryCollectOptions
	Collect(ctx context.Context, opts TelemetryCollectOptions) ([]TelemetryEvent, error)
	ParseHookPayload(raw []byte, opts TelemetryCollectOptions) ([]TelemetryEvent, error)
}

type TelemetryStatus

type TelemetryStatus string
const (
	TelemetryStatusOK      TelemetryStatus = "ok"
	TelemetryStatusError   TelemetryStatus = "error"
	TelemetryStatusAborted TelemetryStatus = "aborted"
	TelemetryStatusUnknown TelemetryStatus = "unknown"
)

Jump to

Keyboard shortcuts

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