scrollback

package
v1.46.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForkScrollback

func ForkScrollback(srcPath string, upToSeq uint64, dstPath string) error

ForkScrollback copies scrollback entries with sequence numbers <= upToSeq from srcPath to dstPath. The destination is always written as uncompressed JSONL regardless of whether the source is compressed. Entries are copied in order, preserving original timestamps and sequence numbers so the forked session can resume playback from any point.

If srcPath does not exist (session has no scrollback yet), dstPath is created as an empty file. If upToSeq is 0, an empty file is created (no entries qualify). If upToSeq exceeds the maximum sequence in src, all entries are copied.

Types

type CircularBuffer

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

CircularBuffer implements a thread-safe fixed-size circular buffer for terminal scrollback. When the buffer is full, new entries overwrite the oldest entries.

func NewCircularBuffer

func NewCircularBuffer(maxSize int) *CircularBuffer

NewCircularBuffer creates a new circular buffer with the specified maximum size.

func (*CircularBuffer) Append

func (b *CircularBuffer) Append(data []byte) (ScrollbackEntry, bool)

Append adds new data to the buffer. Returns the created entry and whether an old entry was evicted.

func (*CircularBuffer) Clear

func (b *CircularBuffer) Clear()

Clear removes all entries from the buffer.

func (*CircularBuffer) CurrentSequence

func (b *CircularBuffer) CurrentSequence() uint64

CurrentSequence returns the current sequence number (last assigned).

func (*CircularBuffer) GetAll

func (b *CircularBuffer) GetAll() []ScrollbackEntry

GetAll retrieves all entries in the buffer. Returns entries in chronological order (oldest first).

func (*CircularBuffer) GetLastN

func (b *CircularBuffer) GetLastN(n int) []ScrollbackEntry

GetLastN retrieves the last N entries from the buffer. Returns entries in chronological order (oldest first).

func (*CircularBuffer) GetNewestSequence

func (b *CircularBuffer) GetNewestSequence() uint64

GetNewestSequence returns the sequence number of the newest entry in the buffer. Returns 0 if buffer is empty.

func (*CircularBuffer) GetOldestSequence

func (b *CircularBuffer) GetOldestSequence() uint64

GetOldestSequence returns the sequence number of the oldest entry in the buffer. Returns 0 if buffer is empty.

func (*CircularBuffer) GetRange

func (b *CircularBuffer) GetRange(fromSeq uint64, limit int) []ScrollbackEntry

GetRange retrieves entries starting from the specified sequence number, up to limit entries. Returns entries in chronological order (oldest first).

func (*CircularBuffer) IsDirty

func (b *CircularBuffer) IsDirty() bool

IsDirty returns whether the buffer has unsaved changes.

func (*CircularBuffer) MarkClean

func (b *CircularBuffer) MarkClean()

MarkClean marks the buffer as having no unsaved changes.

func (*CircularBuffer) MaxSize

func (b *CircularBuffer) MaxSize() int

MaxSize returns the maximum capacity of the buffer.

func (*CircularBuffer) Size

func (b *CircularBuffer) Size() int

Size returns the current number of entries in the buffer.

type FileScrollbackStorage

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

FileScrollbackStorage implements ScrollbackStorage using line-delimited JSON files.

func NewFileScrollbackStorage

func NewFileScrollbackStorage(basePath string, compressionType string, compressionLevel int) *FileScrollbackStorage

NewFileScrollbackStorage creates a new file-based storage instance.

func (*FileScrollbackStorage) Delete

func (s *FileScrollbackStorage) Delete(sessionID string) error

Delete removes the scrollback file for the session.

func (*FileScrollbackStorage) Read

func (s *FileScrollbackStorage) Read(sessionID string, fromSeq uint64, limit int) ([]ScrollbackEntry, error)

Read retrieves entries starting from the specified sequence number.

func (*FileScrollbackStorage) ReadTail

func (s *FileScrollbackStorage) ReadTail(sessionID string, bytes int64) ([]byte, error)

ReadTail retrieves the last N bytes from the scrollback file.

func (*FileScrollbackStorage) Size

func (s *FileScrollbackStorage) Size(sessionID string) (int64, error)

Size returns the current size of the scrollback file.

func (*FileScrollbackStorage) Truncate

func (s *FileScrollbackStorage) Truncate(sessionID string, keepBytes int64) error

Truncate removes old entries to keep file size under limit.

func (*FileScrollbackStorage) Write

func (s *FileScrollbackStorage) Write(sessionID string, entries []ScrollbackEntry) error

Write appends entries to the scrollback file.

type ScrollbackConfig

type ScrollbackConfig struct {
	MaxLines         int           // Maximum lines per session (default: 10000)
	MaxSizeBytes     int64         // Maximum storage size per session (default: 10MB)
	FlushInterval    time.Duration // How often to flush to disk (default: 5s)
	CompressionType  string        // "none", "zstd", or "gzip" (default: "zstd")
	CompressionLevel int           // Compression level (zstd: 1-19, default: 3)
	StoragePath      string        // Base path for storage (default: ~/.stapler-squad/sessions)
}

ScrollbackConfig configures scrollback behavior.

func DefaultScrollbackConfig

func DefaultScrollbackConfig() ScrollbackConfig

DefaultScrollbackConfig returns the default configuration.

type ScrollbackEntry

type ScrollbackEntry struct {
	Timestamp time.Time
	Data      []byte
	Sequence  uint64
}

ScrollbackEntry represents a single entry in the scrollback buffer.

type ScrollbackManager

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

ScrollbackManager manages scrollback buffers for multiple sessions.

func NewScrollbackManager

func NewScrollbackManager(config ScrollbackConfig) *ScrollbackManager

NewScrollbackManager creates a new scrollback manager.

func (*ScrollbackManager) AppendOutput

func (m *ScrollbackManager) AppendOutput(sessionID string, data []byte) error

AppendOutput adds terminal output to the session's scrollback.

func (*ScrollbackManager) ClearScrollback

func (m *ScrollbackManager) ClearScrollback(sessionID string) error

ClearScrollback removes all scrollback for the session.

func (*ScrollbackManager) Close

func (m *ScrollbackManager) Close() error

Close stops the manager and flushes all buffers.

func (*ScrollbackManager) CurrentSequence

func (m *ScrollbackManager) CurrentSequence(sessionID string) uint64

CurrentSequence returns the highest scrollback sequence number written so far for the given session. Returns 0 if the session has no scrollback yet. Implements the scrollbackSequencer interface used by SessionService.CreateCheckpoint.

func (*ScrollbackManager) FlushAll

func (m *ScrollbackManager) FlushAll() error

FlushAll flushes all dirty buffers to storage.

func (*ScrollbackManager) FlushSession

func (m *ScrollbackManager) FlushSession(sessionID string) error

FlushSession flushes a specific session's buffer to storage.

func (*ScrollbackManager) GetRecentBytes

func (m *ScrollbackManager) GetRecentBytes(sessionID string, bytes int64) ([]byte, error)

GetRecentBytes retrieves the last N bytes from scrollback.

func (*ScrollbackManager) GetRecentLines

func (m *ScrollbackManager) GetRecentLines(sessionID string, lines int) ([]byte, error)

GetRecentLines retrieves the last N lines from scrollback.

func (*ScrollbackManager) GetScrollback

func (m *ScrollbackManager) GetScrollback(sessionID string, fromSeq uint64, limit int) ([]ScrollbackEntry, error)

GetScrollback retrieves scrollback entries starting from the specified sequence.

func (*ScrollbackManager) GetScrollbackBefore added in v1.35.0

func (m *ScrollbackManager) GetScrollbackBefore(sessionID string, beforeSeq uint64, limit int) ([]ScrollbackEntry, error)

GetScrollbackBefore retrieves the `limit` most recent scrollback entries with Sequence strictly less than beforeSeq. Returns entries in chronological order (oldest first).

func (*ScrollbackManager) GetStats

func (m *ScrollbackManager) GetStats(sessionID string) (ScrollbackStats, error)

GetStats returns statistics about scrollback usage.

type ScrollbackStats

type ScrollbackStats struct {
	SessionID      string
	MemoryLines    int
	StorageBytes   int64
	OldestSequence uint64
	NewestSequence uint64
}

ScrollbackStats provides information about scrollback usage.

type ScrollbackStorage

type ScrollbackStorage interface {
	// Write appends entries to storage
	Write(sessionID string, entries []ScrollbackEntry) error

	// Read retrieves entries starting from the specified sequence number
	Read(sessionID string, fromSeq uint64, limit int) ([]ScrollbackEntry, error)

	// ReadTail retrieves the last N bytes from storage
	ReadTail(sessionID string, bytes int64) ([]byte, error)

	// Truncate removes old entries, keeping only the specified number of bytes
	Truncate(sessionID string, keepBytes int64) error

	// Delete removes all storage for the session
	Delete(sessionID string) error

	// Size returns the current storage size in bytes
	Size(sessionID string) (int64, error)
}

ScrollbackStorage defines the interface for persistent scrollback storage.

Jump to

Keyboard shortcuts

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