utils

package
v1.2.23 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TuskDirName    = ".tusk"
	TracesSubDir   = "traces"
	LogsSubDir     = "logs"
	ConfigFileName = "config.yaml"
)
View Source
const NoWrapMarker = "\x00NOWRAP\x00"

Variables

View Source
var PossibleTraceDirs = []string{
	".tusk/traces",
	"traces",
	"tmp",
	".",
}

List of directories to search for trace files

Functions

func CopyToClipboard

func CopyToClipboard(text string) error

CopyToClipboard copies text to the system clipboard. It tries OSC52 first (for remote terminals), then falls back to OS clipboard.

func EnsureDir

func EnsureDir(dir string) error

EnsureDir creates a directory if it doesn't exist

func EnvDefault

func EnvDefault(k, def string) string

func FindTraceFile

func FindTraceFile(traceID string, filename string) (string, error)

FindTraceFile searches for a JSONL trace file containing the given trace ID. If filename is provided, it tries that first before searching

func FindTuskRoot added in v0.1.1

func FindTuskRoot() string

FindTuskRoot traverses up the directory tree looking for a .tusk directory Returns the directory containing .tusk, or empty string if not found

func FormatJSONDiff added in v0.1.4

func FormatJSONDiff(expected, actual any) string

FormatJSONDiff creates a git-style unified diff between two JSON values

func FormatJSONForDiff added in v0.1.4

func FormatJSONForDiff(v any) string

FormatJSONForDiff formats a JSON value with proper indentation for diff display

func GenerateDeterministicHash

func GenerateDeterministicHash(value any) string

GenerateDeterministicHash creates a deterministic hash of any JSON-serializable value

func GenerateSchemaAndHash

func GenerateSchemaAndHash(value any) (schema any, valueHash string, schemaHash string)

GenerateSchemaAndHash generates JSON schema and deterministic hash for any value

func GetLogsDir

func GetLogsDir() string

GetLogsDir returns the logs directory path

func GetPossibleTraceDirs

func GetPossibleTraceDirs() []string

GetPossibleTraceDirs returns the list of directories to search for trace files, preferring override first.

func GetTracesDir

func GetTracesDir() string

GetTracesDir returns the traces directory path

func GetTuskDir

func GetTuskDir() string

GetTuskDir returns the .tusk directory path (either local or in home directory)

func GetTuskRoot added in v0.1.1

func GetTuskRoot() string

GetTuskRoot returns the root directory containing .tusk, or current directory if not found

func IsTerminal

func IsTerminal() bool

func MarkNonWrappable added in v0.1.4

func MarkNonWrappable(text string) string

MarkNonWrappable adds an invisible marker to indicate text should not be wrapped

func ParseProtobufSpanFromJSON

func ParseProtobufSpanFromJSON(jsonData []byte) (*core.Span, error)

ParseProtobufSpanFromJSON parses a JSON line into a protobuf Span

func ParseSpansFromFile

func ParseSpansFromFile(filename string, filter SpanFilter) ([]*core.Span, error)

ParseSpansFromFile reads a JSONL trace file and returns spans matching the filter. If the file is malformed, it returns an error.

func ReduceByMatchImportance

func ReduceByMatchImportance(value any, schema *core.JsonSchema) any

ReduceByMatchImportance returns a copy of 'value' keeping only fields with matchImportance != 0. Schema is a JsonSchema proto with optional per-field "matchImportance": 0|1 (default 1). Supports nested objects and arrays (uses 'items' schema for arrays if present).

func ReduceSchemaByMatchImportance added in v0.1.6

func ReduceSchemaByMatchImportance(schema *core.JsonSchema) *core.JsonSchema

ReduceSchemaByMatchImportance returns a copy of the schema with only fields that have matchImportance != 0 Theoretically match importance could be a decimal, but we don't support that yet.

func RemoveHeadersFromInputValue

func RemoveHeadersFromInputValue(inputValue any) any

RemoveHeadersFromInputValue removes non-critical headers for header-agnostic matching but preserves headers that affect response format like Accept and Content-Type

func RenderMarkdown

func RenderMarkdown(markdown string) string

func ResolveTuskPath added in v0.1.1

func ResolveTuskPath(path string) string

ResolveTuskPath resolves a path relative to the tusk root if it's relative, or returns it as-is if it's already absolute

func SetTracesDirOverride

func SetTracesDirOverride(dir string)

SetTracesDirOverride sets an explicit traces directory to use.

func StripNoWrapMarker added in v0.1.4

func StripNoWrapMarker(text string) string

StripNoWrapMarker removes the non-wrappable marker from text before display

func TruncateWithEllipsis added in v0.1.16

func TruncateWithEllipsis(text string, maxWidth int) string

func WrapLine

func WrapLine(text string, maxWidth int) []string

WrapLine wraps a single line of text to the specified width, trying to break at word boundaries This function is ANSI-aware and preserves color codes It avoids wrapping lines that appear to be formatted output (like diffs)

func WrapText

func WrapText(content string, maxWidth int) string

WrapLogs wraps multiple lines of log content to fit within the specified width

Types

type ProgressBar added in v0.1.13

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

ProgressBar shows a progress bar based on current/total counts

func NewProgressBar added in v0.1.13

func NewProgressBar(message string) *ProgressBar

NewProgressBar creates a new progress bar that outputs to stderr

func (*ProgressBar) Add added in v0.1.13

func (p *ProgressBar) Add(count int)

Add increments the current count by the given amount

func (*ProgressBar) Finish added in v0.1.13

func (p *ProgressBar) Finish(finalMessage string)

Finish stops the progress bar and shows a completion message

func (*ProgressBar) SetCurrent added in v0.1.13

func (p *ProgressBar) SetCurrent(current int)

SetCurrent sets the current count directly

func (*ProgressBar) SetTotal added in v0.1.13

func (p *ProgressBar) SetTotal(total int)

SetTotal sets the total count for the progress bar

func (*ProgressBar) Start added in v0.1.13

func (p *ProgressBar) Start()

Start initializes the progress bar (shows empty bar)

func (*ProgressBar) Stop added in v0.1.13

func (p *ProgressBar) Stop()

Stop clears the progress bar without a final message

type ProgressTracker added in v0.1.14

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

ProgressTracker handles progress reporting for paginated fetches

func NewProgressTracker added in v0.1.14

func NewProgressTracker(message string, interactive, quiet bool) *ProgressTracker

func (*ProgressTracker) Finish added in v0.1.14

func (pt *ProgressTracker) Finish(finalMessage string)

func (*ProgressTracker) SetTotal added in v0.1.14

func (pt *ProgressTracker) SetTotal(total int)

func (*ProgressTracker) Stop added in v0.1.14

func (pt *ProgressTracker) Stop()

func (*ProgressTracker) Update added in v0.1.14

func (pt *ProgressTracker) Update(current int)

type SpanFilter

type SpanFilter func(*core.Span) bool

SpanFilter is a function type for filtering spans during parsing

Jump to

Keyboard shortcuts

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