Documentation
¶
Overview ¶
ansi_to_html.go (pi: core/export-html/ansi-to-html.ts, v0.86.0)
ANSI escape code to HTML converter.
Converts terminal ANSI color/style codes to HTML with inline styles. Supports:
- Standard foreground colors (30-37) and bright variants (90-97)
- Standard background colors (40-47) and bright variants (100-107)
- 256-color palette (38;5;N and 48;5;N)
- RGB true color (38;2;R;G;B and 48;2;R;G;B)
- Text styles: bold (1), dim (2), italic (3), underline (4)
- Reset (0)
Package exporthtml implements the HTML session export (pi: core/export-html/*, v0.86.0).
pi's export-html/index.ts mixes two halves: template/theme/HTML generation and session-manager access. Go forbids the import cycle that would arise (package codingagent/core must call this package for AgentSession.ExportToHtml, while this package needs core's SessionManager/SessionEntry types), so the session-facing half lives in codingagent/core/export_html.go (pi index.ts's exportSessionToHtml / exportFromFile / preRenderCustomTools) and this package keeps the template half: ExportOptions, the ToolHtmlRenderer interface, SessionData, theme color derivation, and generateHtml (pi index.go's parseColor/getLuminance/adjustBrightness/deriveExportColors/ generateThemeVars/generateHtml).
The template assets (template.html/css/js + vendored marked and highlight.js) are embedded verbatim from pi (pig ships a single static binary; pi reads them from disk next to the executable — declared deviation).
tool_renderer.go (pi: core/export-html/tool-renderer.ts, v0.86.0)
Tool HTML renderer for custom tools in HTML export.
Renders custom tool calls and results to HTML by invoking their TUI renderers and converting the ANSI output to HTML.
Index ¶
- func AnsiLinesToHtml(lines []string) string
- func AnsiToHtml(text string) string
- func GenerateHtml(sessionData SessionData, themeName string) (string, error)
- func IsTemplateRenderedTool(name string) bool
- type ExportColors
- type ExportOptions
- type RenderedToolHtml
- type SessionData
- type ToolHtmlRenderer
- type ToolHtmlRendererDeps
- type ToolSummary
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnsiLinesToHtml ¶
AnsiLinesToHtml converts an array of ANSI-escaped lines to HTML. Each line is wrapped in a div element.
func AnsiToHtml ¶
AnsiToHtml converts ANSI-escaped text to HTML with inline styles.
func GenerateHtml ¶
func GenerateHtml(sessionData SessionData, themeName string) (string, error)
GenerateHtml is the core HTML generation logic shared by both export functions (pi: generateHtml).
func IsTemplateRenderedTool ¶
IsTemplateRenderedTool reports whether the named tool is rendered by the HTML template itself (pig addition: the set is module-private in pi, but the session-facing half lives in codingagent/core and needs the lookup).
Types ¶
type ExportColors ¶
ExportColors is the derived export background colors (pi: deriveExportColors's { pageBg, cardBg, infoBg }).
type ExportOptions ¶
type ExportOptions struct {
// OutputPath is the target file; "" = a default next to the session
// file (pi: outputPath?).
OutputPath string
// ThemeName resolves the theme for the exported page (pi: themeName?).
ThemeName string
// ToolRenderer renders custom tools to HTML (pi: toolRenderer?).
ToolRenderer ToolHtmlRenderer
}
ExportOptions parameterizes HTML export (pi: ExportOptions).
type RenderedToolHtml ¶
type RenderedToolHtml struct {
CallHTML string `json:"callHtml,omitempty"`
ResultHTMLCollapsed string `json:"resultHtmlCollapsed,omitempty"`
ResultHTMLExpanded string `json:"resultHtmlExpanded,omitempty"`
}
RenderedToolHtml is pre-rendered HTML for a custom tool call and result (pi: RenderedToolHtml).
type SessionData ¶
type SessionData struct {
Header any `json:"header"` // *core.SessionHeader or nil (pi: SessionHeader | null)
// Entries is the []core.SessionEntry slice (pi: SessionEntry[]).
Entries any `json:"entries"`
// LeafID is the current branch leaf (pi: leafId: string | null).
LeafID *string `json:"leafId"`
// SystemPrompt is the agent's current system prompt (pi: systemPrompt?,
// omitted when empty).
SystemPrompt string `json:"systemPrompt,omitempty"`
// Tools are the agent's active tools (pi: tools?). Pointer (pig
// serialization seam): pi's map over an empty array emits "tools": [],
// while Go's omitempty would drop an empty slice — nil = absent,
// non-nil (even empty) = present.
Tools *[]ToolSummary `json:"tools,omitempty"`
// RenderedTools is pre-rendered custom tool HTML keyed by tool call ID
// (pi: renderedTools?).
RenderedTools map[string]RenderedToolHtml `json:"renderedTools,omitempty"`
}
SessionData is the session payload embedded into the exported page (pi: SessionData). Header/Entries hold the typed session values from codingagent/core (marshaling goes through their pi-compatible JSON tags); they are typed `any` here so this package does not import codingagent/core.
type ToolHtmlRenderer ¶
type ToolHtmlRenderer interface {
// RenderCall renders a tool call to HTML (pi: renderCall).
RenderCall(toolCallID string, toolName string, args any) string
// RenderResult renders a tool result to collapsed/expanded HTML (pi:
// renderResult). ok=false when the tool has no custom renderer.
RenderResult(toolCallID string, toolName string, result []types.Content, details any, isError bool) (collapsed, expanded string, ok bool)
}
ToolHtmlRenderer renders custom tools to HTML (pi: ToolHtmlRenderer in index.ts). Used by agent-session to pre-render extension tool output.
"" returns mean "no custom renderer" (pi: undefined); RenderResult's collapsed string is "" when it equals expanded or is empty (pi: the collapsed key is spread in conditionally).
func CreateToolHtmlRenderer ¶
func CreateToolHtmlRenderer(deps ToolHtmlRendererDeps) ToolHtmlRenderer
CreateToolHtmlRenderer creates a tool HTML renderer.
The renderer looks up tool definitions and invokes their RenderCall/RenderResult methods, converting the resulting TUI component output (ANSI) to HTML. pi wraps every renderer call in try/catch and returns undefined on error so HTML export falls back to structured result rendering; pig recovers panics to the same effect.
type ToolHtmlRendererDeps ¶
type ToolHtmlRendererDeps struct {
// GetToolDefinition looks up a tool definition by name (pi:
// getToolDefinition).
GetToolDefinition func(name string) *coretools.ToolDefinition
// ThemeFunc resolves the theme for styling (pi: theme). pi passes the
// live theme proxy, which throws lazily on first access when
// uninitialized — inside the renderers' try/catch, so export silently
// falls back to structured rendering. pig resolves it through this
// lazy accessor inside the same recover-guarded calls (an eager
// *Theme would move the "Theme not initialized" panic to renderer
// construction, a behavior change).
ThemeFunc func() *theme.Theme
// Cwd is the working directory for the render context.
Cwd string
// Width is the terminal width for rendering (pi: width?, default 100).
Width int
}
ToolHtmlRendererDeps parameterizes CreateToolHtmlRenderer (pi: ToolHtmlRendererDeps).
type ToolSummary ¶
type ToolSummary struct {
Name string `json:"name"`
Description string `json:"description"`
Parameters json.RawMessage `json:"parameters"`
}
ToolSummary is the tools payload entry (pi: state.tools mapped to { name, description, parameters }).