html

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package html provides HTML session viewer generation. It converts stored sessions into self-contained HTML files for viewing agent conversation history in a browser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeFallbackDuration

func ComputeFallbackDuration(messages []MessageView) (duration time.Duration, first, last time.Time)

ComputeFallbackDuration derives duration from message timestamps when metadata times are missing. Returns zero values if no valid timestamps found.

func CountDiffLines

func CountDiffLines(output string) (added, removed int)

CountDiffLines counts added and removed lines in a unified diff output. Lines starting with "+" (not "+++") are counted as added. Lines starting with "-" (not "---") are counted as removed.

func ExtractFilePathFromInput

func ExtractFilePathFromInput(input string) string

ExtractFilePathFromInput parses tool input (JSON or raw) to find a file_path field.

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration creates a human-readable duration string.

func FormatToolSummary

func FormatToolSummary(tool *ToolCallView) string

FormatToolSummary creates a compact summary for tool calls. Examples: "Edit(file.go) -- +5 / -3 lines", "Read(config.yaml)", "Bash"

func IsDiffOutput

func IsDiffOutput(output string) bool

IsDiffOutput detects whether the output string looks like a unified diff. Checks for common diff markers: lines starting with @@, +++, or ---.

func RenderDiffHTML

func RenderDiffHTML(output string) template.HTML

RenderDiffHTML wraps diff lines in colored spans for HTML display. Lines are HTML-escaped first, then wrapped:

  • Lines starting with "+" (not "+++") get class="diff-add"
  • Lines starting with "-" (not "---") get class="diff-remove"
  • Lines starting with "@@" get class="diff-header"

Returns raw HTML safe for template rendering.

func RenderMarkdown

func RenderMarkdown(text string) template.HTML

RenderMarkdown converts markdown text to template.HTML via goldmark. Goldmark's default behavior strips raw HTML tags for XSS safety, so <script> and similar tags are silently removed from output. HardWraps mode converts single newlines to <br> for plain-text readability. Returns empty HTML for empty input.

func StripANSI

func StripANSI(s string) string

StripANSI removes ANSI escape sequences from text.

Types

type AhaMomentView

type AhaMomentView struct {
	Seq       int    // message sequence number for navigation
	Role      string // user, assistant, system
	Type      string // question, insight, decision, breakthrough, synthesis
	Highlight string // the key text/quote
	Why       string // why this moment was important
}

AhaMomentView represents a pivotal conversation moment for display. Documents collaborative intelligence between human and AI.

type BrandColors

type BrandColors struct {
	Primary   string // sage green
	Secondary string // copper gold
	Accent    string // forest green
	Text      string
	TextDim   string
	BgDark    string
	BgCard    string
	Border    string
	Error     string
	Info      string
}

BrandColors defines the SageOx brand color palette for CSS variable injection.

func DefaultBrandColors

func DefaultBrandColors() BrandColors

DefaultBrandColors returns the SageOx brand color palette from the theme.

type Generator

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

Generator creates HTML session viewers from stored sessions.

func NewGenerator

func NewGenerator() (*Generator, error)

NewGenerator creates a generator with embedded templates. The template is parsed once and reused for multiple Generate calls.

func (*Generator) Generate

func (g *Generator) Generate(t *session.StoredSession) ([]byte, error)

Generate creates HTML bytes from a StoredSession.

func (*Generator) GenerateToFile

func (g *Generator) GenerateToFile(t *session.StoredSession, outputPath string) error

GenerateToFile writes HTML to a file. TODO(server-side): move to server-side for MVP+1; client should not write to ledger directly.

func (*Generator) GenerateToFileWithSummary

func (g *Generator) GenerateToFileWithSummary(t *session.StoredSession, summary *SummaryView, outputPath string) error

GenerateToFileWithSummary writes HTML to a file with a summary section. TODO(server-side): move to server-side for MVP+1; client should not write to ledger directly.

func (*Generator) GenerateWithSummary

func (g *Generator) GenerateWithSummary(t *session.StoredSession, summary *SummaryView) ([]byte, error)

GenerateWithSummary creates HTML bytes from a StoredSession with a summary.

type MessageView

type MessageView struct {
	ID          int
	Type        string // user, assistant, system, tool
	SenderLabel string // display name (e.g., "user", "assistant")
	Timestamp   time.Time
	Content     template.HTML // markdown rendered to HTML via goldmark (server-side)
	ToolCall    *ToolCallView
	IsAhaMoment bool           // true if this message is a key insight moment
	AhaMomentID int            // aha moment index (1-based) for navigation
	AhaMoment   *AhaMomentView // full aha moment details for inline display
}

MessageView represents a single session entry for display.

type MetadataView

type MetadataView struct {
	AgentType    string
	AgentVersion string
	Model        string
	Username     string
	StartedAt    time.Time
	EndedAt      time.Time
}

MetadataView holds session metadata for display.

type SageoxInsightView

type SageoxInsightView struct {
	Seq     int    // message sequence number for navigation
	Topic   string // domain area (e.g., "react-patterns")
	Insight string // what guidance was applied
	Impact  string // the value it provided
}

SageoxInsightView represents a moment where SageOx guidance provided value.

type StatsView

type StatsView struct {
	TotalMessages int
	UserMessages  int
}

StatsView holds session statistics for display.

type SummaryView

type SummaryView struct {
	Text           string              // one paragraph executive summary
	KeyActions     []string            // bullet points of key actions taken
	Outcome        string              // success/partial/failed
	TopicsFound    []string            // topics detected during session
	FinalPlan      string              // final plan/architecture from session
	Diagrams       []string            // extracted mermaid diagrams (raw mermaid code)
	SageoxInsights []SageoxInsightView // moments where SageOx guidance provided value
}

SummaryView holds LLM-generated session summary for display.

type TemplateData

type TemplateData struct {
	Title          string
	Summary        *SummaryView // LLM-generated summary (may be nil)
	Metadata       *MetadataView
	Messages       []MessageView
	AhaMoments     []AhaMomentView     // pivotal moments of collaborative intelligence
	SageoxInsights []SageoxInsightView // moments where SageOx guidance provided value
	Statistics     *StatsView
	BrandColors    BrandColors
	Styles         template.CSS // CSS content (safe)
	Scripts        template.JS  // JS content (safe)
}

TemplateData is the root view model for the HTML template.

type ToolCallView

type ToolCallView struct {
	Name           string
	Summary        string        // compact summary like "Edit(file.go) -- +5 / -3 lines"
	FormattedInput template.HTML // pre-rendered compact command (e.g., ">_ Bash git status")
	IsSimple       bool          // true = render inline (no collapsible details)
	Input          string
	Output         string
}

ToolCallView holds tool invocation details for display.

Jump to

Keyboard shortcuts

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