Documentation
¶
Overview ¶
Package output provides output formatting and dispatching.
Index ¶
- Constants
- type CodeBlock
- type CodeChange
- type CodeGenerator
- func (g *CodeGenerator) AddBlock(filePath, language, content string) *CodeGenerator
- func (g *CodeGenerator) AddBlockWithLines(filePath, language, content string, startLine, endLine int) *CodeGenerator
- func (g *CodeGenerator) AddCreate(filePath, content, description string) *CodeGenerator
- func (g *CodeGenerator) AddDelete(filePath, oldContent, description string) *CodeGenerator
- func (g *CodeGenerator) AddModify(filePath, oldContent, newContent, description string) *CodeGenerator
- func (g *CodeGenerator) Build() *CodeOutput
- func (g *CodeGenerator) WithSummary(summary string) *CodeGenerator
- type CodeOutput
- type DiffLine
- type DiffStats
- type Dispatcher
- type FileDiff
- type Format
- type Formatter
- type JSONFormatter
- type MarkdownFormatter
- type OutputDispatcher
- type TextFormatter
Constants ¶
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 ¶
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.
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 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.
type MarkdownFormatter ¶
type MarkdownFormatter struct{}
MarkdownFormatter formats output as Markdown.
func NewMarkdownFormatter ¶
func NewMarkdownFormatter() *MarkdownFormatter
NewMarkdownFormatter creates a new Markdown formatter.
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.