view

package
v0.0.79 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package view loads Grok CLI sessions, converts updates.jsonl to AgentEvents fully in memory, and supports print / follow / read-only web viewing.

Index

Constants

View Source
const (
	DefaultViewPort  = 61781
	ViewPortAttempts = 100
)

DefaultViewPort is the preferred listen port for grok session view --web. If busy, ServeWeb tries the next ports up to ViewPortAttempts total.

Variables

This section is empty.

Functions

func PrintEvents

func PrintEvents(w io.Writer, events []types.AgentEvent) int

PrintEvents writes human-readable events to w using agent/event/print FormatState for assistant/tool/think streams. User messages are rendered as separate USER blocks so they are not coalesced into ASSISTANT output.

func PrintFollow

func PrintFollow(ctx context.Context, w io.Writer, v *Viewer) error

PrintFollow prints the current snapshot, then streams new events until ctx is done.

func PrintSnapshot

func PrintSnapshot(w io.Writer, v *Viewer) int

PrintSnapshot prints a header and all events currently in the viewer.

func ServeWeb

func ServeWeb(ctx context.Context, v *Viewer, opts WebOptions) error

ServeWeb starts an agent-run-compatible API + SPA for one in-memory session. It bootstraps the viewer, follows updates.jsonl, blocks until interrupted.

Types

type Viewer

type Viewer struct {
	Info        *sessions.SessionInfo
	UpdatesPath string
	GrokHome    string
	// contains filtered or unexported fields
}

Viewer holds an in-memory conversion of one Grok session. It never writes agent-run storage.

func Open

func Open(grokHome, sessionID string) (*Viewer, error)

Open resolves a Grok session and prepares an empty converter. Call Bootstrap to load existing updates.jsonl content.

func (*Viewer) Bootstrap

func (v *Viewer) Bootstrap() error

Bootstrap reads existing updates.jsonl from offset 0 into memory. Missing file is OK (empty transcript; Follow can wait for creation).

func (*Viewer) DetailPayload

func (v *Viewer) DetailPayload() map[string]any

DetailPayload is agent-run SessionDetail JSON.

func (*Viewer) Events

func (v *Viewer) Events() []types.AgentEvent

Events returns a copy of converted events so far.

func (*Viewer) Follow

func (v *Viewer) Follow(ctx context.Context) error

Follow tails updates.jsonl with logs.WatchLine and converts new lines in memory. Blocks until ctx is cancelled. Flushes converter on exit.

func (*Viewer) NDJSONAfter

func (v *Viewer) NDJSONAfter(after int64) []byte

NDJSONAfter returns virtual events.jsonl bytes after the given offset.

func (*Viewer) Offset

func (v *Viewer) Offset() int64

Offset returns the virtual NDJSON byte length (agent-run events_offset).

func (*Viewer) ReadLinesFromOffset

func (v *Viewer) ReadLinesFromOffset(after int64, onLine func(line string) error) error

ReadLinesFromOffset walks virtual NDJSON after byte offset and calls onLine with each complete line (without trailing newline).

func (*Viewer) SessionSummary

func (v *Viewer) SessionSummary() map[string]any

SessionSummary is the agent-run SessionSummary-compatible meta for the SPA.

func (*Viewer) Subscribe

func (v *Viewer) Subscribe() (ch <-chan struct{}, cancel func())

Subscribe registers for change notifications. Call cancel when done.

type WebOptions

type WebOptions struct {
	// Port is the preferred listen port. Zero or negative uses DefaultViewPort.
	// If that port is taken, the next free port is tried (up to ViewPortAttempts).
	Port int
	// Open opens the session URL in a browser. Default is false (print URL only).
	Open bool
	// Stderr receives status lines (listen URL). Defaults to os.Stderr.
	Stderr io.Writer
}

WebOptions configures the read-only local viewer.

Jump to

Keyboard shortcuts

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