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
- func PrintEvents(w io.Writer, events []types.AgentEvent) int
- func PrintFollow(ctx context.Context, w io.Writer, v *Viewer) error
- func PrintSnapshot(w io.Writer, v *Viewer) int
- func ServeWeb(ctx context.Context, v *Viewer, opts WebOptions) error
- type Viewer
- func (v *Viewer) Bootstrap() error
- func (v *Viewer) DetailPayload() map[string]any
- func (v *Viewer) Events() []types.AgentEvent
- func (v *Viewer) Follow(ctx context.Context) error
- func (v *Viewer) NDJSONAfter(after int64) []byte
- func (v *Viewer) Offset() int64
- func (v *Viewer) ReadLinesFromOffset(after int64, onLine func(line string) error) error
- func (v *Viewer) SessionSummary() map[string]any
- func (v *Viewer) Subscribe() (ch <-chan struct{}, cancel func())
- type WebOptions
Constants ¶
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 ¶
PrintFollow prints the current snapshot, then streams new events until ctx is done.
func PrintSnapshot ¶
PrintSnapshot prints a header and all events currently in the viewer.
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 ¶
Open resolves a Grok session and prepares an empty converter. Call Bootstrap to load existing updates.jsonl content.
func (*Viewer) Bootstrap ¶
Bootstrap reads existing updates.jsonl from offset 0 into memory. Missing file is OK (empty transcript; Follow can wait for creation).
func (*Viewer) DetailPayload ¶
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 ¶
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 ¶
NDJSONAfter returns virtual events.jsonl bytes after the given offset.
func (*Viewer) ReadLinesFromOffset ¶
ReadLinesFromOffset walks virtual NDJSON after byte offset and calls onLine with each complete line (without trailing newline).
func (*Viewer) SessionSummary ¶
SessionSummary is the agent-run SessionSummary-compatible meta for the SPA.
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.