output

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package output provides output formatting and dispatching.

Index

Constants

View Source
const (
	// MaxDiffLines is the maximum number of lines to process in a diff.
	// Files larger than this will be truncated with a warning.
	MaxDiffLines = 10000

	// MaxDiffOutputLines is the maximum number of diff output lines to generate.
	MaxDiffOutputLines = 5000
)

Limits for diff generation to prevent resource exhaustion.

Variables

This section is empty.

Functions

This section is empty.

Types

type CodeBlock

type CodeBlock struct {
	FilePath    string `json:"file_path"`
	Language    string `json:"language"`
	Content     string `json:"content"`
	StartLine   int    `json:"start_line,omitempty"`
	EndLine     int    `json:"end_line,omitempty"`
	Description string `json:"description,omitempty"`
}

CodeBlock represents a generated code block.

type CodeChange

type CodeChange struct {
	FilePath    string `json:"file_path"`
	ChangeType  string `json:"change_type"` // "create", "modify", "delete"
	OldContent  string `json:"old_content,omitempty"`
	NewContent  string `json:"new_content"`
	Description string `json:"description,omitempty"`
}

CodeChange represents a file modification.

type CodeGenerator

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

CodeGenerator produces structured code output.

func NewCodeGenerator

func NewCodeGenerator() *CodeGenerator

NewCodeGenerator creates a new code generator.

func (*CodeGenerator) AddBlock

func (g *CodeGenerator) AddBlock(filePath, language, content string) *CodeGenerator

AddBlock adds a code block to the output.

func (*CodeGenerator) AddBlockWithLines

func (g *CodeGenerator) AddBlockWithLines(filePath, language, content string, startLine, endLine int) *CodeGenerator

AddBlockWithLines adds a code block with line range.

func (*CodeGenerator) AddCreate

func (g *CodeGenerator) AddCreate(filePath, content, description string) *CodeGenerator

AddCreate adds a file creation change.

func (*CodeGenerator) AddDelete

func (g *CodeGenerator) AddDelete(filePath, oldContent, description string) *CodeGenerator

AddDelete adds a file deletion change.

func (*CodeGenerator) AddModify

func (g *CodeGenerator) AddModify(filePath, oldContent, newContent, description string) *CodeGenerator

AddModify adds a file modification change.

func (*CodeGenerator) Build

func (g *CodeGenerator) Build() *CodeOutput

Build generates the final output.

func (*CodeGenerator) WithSummary

func (g *CodeGenerator) WithSummary(summary string) *CodeGenerator

WithSummary sets the output summary.

type CodeOutput

type CodeOutput struct {
	Blocks  []CodeBlock  `json:"blocks,omitempty"`
	Changes []CodeChange `json:"changes,omitempty"`
	Diffs   []FileDiff   `json:"diffs,omitempty"`
	Summary string       `json:"summary,omitempty"`
}

CodeOutput contains structured code generation output.

func (*CodeOutput) FormatJSON

func (o *CodeOutput) FormatJSON() ([]byte, error)

FormatJSON formats the output as JSON (via standard marshaling).

func (*CodeOutput) FormatMarkdown

func (o *CodeOutput) FormatMarkdown() string

FormatMarkdown formats the output as markdown.

type DiffLine

type DiffLine struct {
	Type    string `json:"type"` // "context", "add", "remove"
	LineNum int    `json:"line_num,omitempty"`
	Content string `json:"content"`
}

DiffLine represents a single line in a diff.

type DiffStats

type DiffStats struct {
	Additions int `json:"additions"`
	Deletions int `json:"deletions"`
	Changes   int `json:"changes"`
}

DiffStats contains diff statistics.

type Dispatcher

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

Dispatcher handles output formatting and writing.

func NewDispatcher

func NewDispatcher() *Dispatcher

NewDispatcher creates a new output dispatcher.

func (*Dispatcher) Format

func (d *Dispatcher) Format(ctx context.Context, result any, format Format) (string, error)

Format formats the result using the specified format. If formatting fails, falls back to text format and logs a warning.

func (*Dispatcher) RegisterFormatter

func (d *Dispatcher) RegisterFormatter(f Formatter)

RegisterFormatter registers a formatter.

func (*Dispatcher) Write

func (d *Dispatcher) Write(ctx context.Context, result any, format Format, dest string) error

Write writes the formatted output to the specified destination. If dest is empty or "-", writes to stdout.

type FileDiff

type FileDiff struct {
	FilePath   string     `json:"file_path"`
	ChangeType string     `json:"change_type"`
	Lines      []DiffLine `json:"lines"`
	Stats      DiffStats  `json:"stats"`
}

FileDiff represents a unified diff for a file.

type Format

type Format string

Format represents an output format.

const (
	// FormatJSON outputs JSON.
	FormatJSON Format = "json"

	// FormatMarkdown outputs Markdown.
	FormatMarkdown Format = "markdown"

	// FormatText outputs plain text.
	FormatText Format = "text"
)

type Formatter

type Formatter interface {
	// Format formats the result.
	Format(ctx context.Context, result any) (string, error)

	// Name returns the formatter name.
	Name() Format
}

Formatter formats output.

type JSONFormatter

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

JSONFormatter formats output as JSON.

func NewJSONFormatter

func NewJSONFormatter(indent bool) *JSONFormatter

NewJSONFormatter creates a new JSON formatter.

func (*JSONFormatter) Format

func (f *JSONFormatter) Format(ctx context.Context, result any) (string, error)

Format formats the result as JSON.

func (*JSONFormatter) Name

func (f *JSONFormatter) Name() Format

Name returns the formatter name.

type MarkdownFormatter

type MarkdownFormatter struct{}

MarkdownFormatter formats output as Markdown.

func NewMarkdownFormatter

func NewMarkdownFormatter() *MarkdownFormatter

NewMarkdownFormatter creates a new Markdown formatter.

func (*MarkdownFormatter) Format

func (f *MarkdownFormatter) Format(ctx context.Context, result any) (string, error)

Format formats the result as Markdown.

func (*MarkdownFormatter) Name

func (f *MarkdownFormatter) Name() Format

Name returns the formatter name.

type OutputDispatcher added in v0.3.0

type OutputDispatcher interface {
	RegisterFormatter(f Formatter)
	Format(ctx context.Context, result any, format Format) (string, error)
	Write(ctx context.Context, result any, format Format, dest string) error
}

OutputDispatcher defines the contract for output formatting and writing.

type TextFormatter

type TextFormatter struct{}

TextFormatter formats output as plain text.

func NewTextFormatter

func NewTextFormatter() *TextFormatter

NewTextFormatter creates a new text formatter.

func (*TextFormatter) Format

func (f *TextFormatter) Format(ctx context.Context, result any) (string, error)

Format formats the result as plain text.

func (*TextFormatter) Name

func (f *TextFormatter) Name() Format

Name returns the formatter name.

Jump to

Keyboard shortcuts

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