print

package
v0.0.26 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const TRUNCATE_LINE_MAX = 1024

Variables

This section is empty.

Functions

func FormatAgentEvent added in v0.0.22

func FormatAgentEvent(event eventtypes.AgentEvent) string

FormatAgentEvent formats an AgentEvent into a human-readable string.

func FormatMessage

func FormatMessage(msg types.AgentTraceMessage) string

func FormatMessageCompact

func FormatMessageCompact(msg types.AgentTraceMessage) string

func FormatTraceLine

func FormatTraceLine(line string) string

Types

type Coalescer added in v0.0.23

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

Coalescer tracks consecutive ActionMessage events and skips redundant PhaseEnd events when earlier phases (start/update/instant/end) were already seen for the same message ID.

Non-ActionMessage events always pass through and reset the tracking state.

func (*Coalescer) ShouldSkip added in v0.0.23

func (c *Coalescer) ShouldSkip(event types.AgentEvent) bool

ShouldSkip returns true if the event is a redundant ActionMessage with PhaseEnd that was already shown via prior phases for the same message ID.

type FormatState added in v0.0.26

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

FormatState provides streaming coalescing of consecutive assistant message deltas into a single output block. Use FormatLine for each event line in a loop; it returns a header, body, and a flag indicating the output type. Call Flush after the last line to close any open message block.

Usage:

var state print.FormatState
for _, line := range lines {
    header, body, isMsg := state.FormatLine(line)
    if header == "" && body == "" && !isMsg {
        continue
    }
    if isMsg {
        if header != "" {
            n++
            Logf("[%d]  %s", n, header)
        }
        fmt.Print(body)
    } else {
        n++
        Logf("[%d]  %s", n, header)
        if body != "" {
            fmt.Print(body)
        }
    }
}
state.Flush()

func (*FormatState) Flush added in v0.0.26

func (s *FormatState) Flush()

Flush closes any pending message block by printing a trailing newline.

func (*FormatState) FormatLine added in v0.0.26

func (s *FormatState) FormatLine(line string) (header string, body string, isMsg bool)

FormatLine processes one JSONL event line.

Returns:

  • header: the block header line (e.g. "💬 ASSISTANT", "⚡ RUN", "▶ STEP START")
  • body: the text to print after the header (without trailing newline)
  • isMsg: true if this is an assistant message (first delta or continuation); false for non-message events (tool calls, steps, etc.)

For the first assistant message delta, header and body are both non-empty. For subsequent deltas, only body is non-empty (continuation, no header). For non-message events, header is the formatted block and body is empty. Returns all-empty when nothing to output.

Jump to

Keyboard shortcuts

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