transcript

package
v1.20.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	FormatAsciicast = "asciicast-v2"
	DefaultMaxBytes = 50 * 1024 * 1024
)

Variables

View Source
var ErrTornTail = errors.New("transcript tail is incomplete")

ErrTornTail reports a transcript whose final line is incomplete or unparseable (crash, ENOSPC, power loss mid-write). The Recording returned alongside it carries every frame parsed before the tear, so callers can errors.Is(err, ErrTornTail) and continue with a warning.

Functions

func Clean

func Clean(value string) string

Clean strips terminal escape sequences from recorded output and normalizes carriage returns to newlines. Transcript frames are untrusted (a hostile remote, or an imported bundle, controls the bytes), so it removes the full ESC grammar via termstyle.Strip (the single ECMA-48 scanner shared with the UI) and then drops raw control characters that survive as literal bytes — C0 (except newline and tab), DEL, and the C1 range U+0080–U+009F, where U+009B is CSI to xterm-class terminals — so cleaned text printed to a real terminal cannot carry an escape introducer.

func ExportAsciicast

func ExportAsciicast(w io.Writer, rec Recording) error

func ParseSize

func ParseSize(value string) (int64, error)

func Path

func Path(stateDir string, id string) string

func PathForRecord

func PathForRecord(stateDir string, record state.SessionRecord) string

func Replay

func Replay(w io.Writer, rec Recording, speed float64, noDelay bool) error

func Text

func Text(rec Recording, opts TextOptions) string

Types

type BundleExportResult

type BundleExportResult struct {
	Path     string         `json:"path"`
	Manifest BundleManifest `json:"manifest"`
	Bytes    int64          `json:"bytes"`
	Warning  string         `json:"warning,omitempty"`
}

func ExportBundle

func ExportBundle(stateDir string, record state.SessionRecord, identity state.MachineIdentity, outputPath string, now time.Time) (BundleExportResult, error)

type BundleImportResult

type BundleImportResult struct {
	Record         state.SessionRecord `json:"record"`
	Manifest       BundleManifest      `json:"manifest"`
	OriginClass    string              `json:"origin_class"`
	BundleSHA256   string              `json:"bundle_sha256"`
	TranscriptPath string              `json:"transcript_path"`
	Warning        string              `json:"warning,omitempty"`
}

func ImportBundle

func ImportBundle(stateDir string, bundlePath string, identity state.MachineIdentity, now time.Time) (BundleImportResult, error)

type BundleManifest

type BundleManifest struct {
	BundleVersion       int       `json:"bundle_version"`
	ExportedAt          time.Time `json:"exported_at"`
	ExportedByMachineID string    `json:"exported_by_machine_id,omitempty"`
	SourceMachineID     string    `json:"source_machine_id,omitempty"`
	SourceSessionID     string    `json:"source_session_id"`
	Target              string    `json:"target,omitempty"`
	Route               []string  `json:"route,omitempty"`
	TranscriptSHA256    string    `json:"transcript_sha256"`
	RecordSHA256        string    `json:"record_sha256"`
	// TranscriptTornTail flags a transcript whose final line is incomplete
	// (the recorder crashed or ran out of disk). Additive to bundle_version 1.
	TranscriptTornTail bool `json:"transcript_torn_tail,omitempty"`
}

type BundlePreview

type BundlePreview struct {
	Manifest     BundleManifest `json:"manifest"`
	BundleSHA256 string         `json:"bundle_sha256"`
	Bytes        int64          `json:"bytes"`
}

func PreviewBundle

func PreviewBundle(bundlePath string) (BundlePreview, error)

type Frame

type Frame struct {
	Offset float64
	Stream string
	Data   string
}
type Header struct {
	Version   int               `json:"version"`
	Width     int               `json:"width,omitempty"`
	Height    int               `json:"height,omitempty"`
	Timestamp int64             `json:"timestamp,omitempty"`
	Command   string            `json:"command,omitempty"`
	Title     string            `json:"title,omitempty"`
	Env       map[string]string `json:"env,omitempty"`
}

type Match

type Match struct {
	LineNo int     `json:"line"`
	Offset float64 `json:"offset"`
	Text   string  `json:"text"`
}

func Grep

func Grep(rec Recording, pattern string, ignoreCase bool) ([]Match, error)

type Recording

type Recording struct {
	Header Header
	Frames []Frame
	// SkippedLines counts mid-file lines that could not be parsed and were
	// skipped during read.
	SkippedLines int
}

func Read

func Read(path string) (Recording, error)

type TextOptions

type TextOptions struct {
	Raw     bool
	Stream  string
	Tail    int
	Since   time.Duration
	Context int
}

type Writer

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

func OpenWriter

func OpenWriter(opts WriterOptions) (*Writer, state.TranscriptSpec, error)

func (*Writer) Close

func (w *Writer) Close(ended time.Time) (state.TranscriptSpec, error)

func (*Writer) Snapshot

func (w *Writer) Snapshot() state.TranscriptSpec

func (*Writer) StopReason added in v1.10.0

func (w *Writer) StopReason() string

StopReason reports why recording stopped early: "" while healthy, "size limit reached" once MaxBytes is hit, or "write error: ..." after an I/O failure. The same text is appended to the cast as a final marker.

func (*Writer) WriteInput

func (w *Writer) WriteInput(at time.Time, data []byte)

func (*Writer) WriteMarker

func (w *Writer) WriteMarker(at time.Time, message string)

func (*Writer) WriteOutput

func (w *Writer) WriteOutput(at time.Time, data []byte)

type WriterOptions

type WriterOptions struct {
	Path     string
	Started  time.Time
	Header   Header
	MaxBytes int64
}

Jump to

Keyboard shortcuts

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