Documentation
¶
Overview ¶
Package clean provides smart code cleaning for LLM consumption.
Cleaning transforms raw source code into a compact representation suitable for feeding into LLM context windows while preserving semantic meaning. Strategies include: comment stripping (preserving doc comments and TODOs), whitespace normalization, base64/binary content truncation, and boilerplate removal for well-known patterns (auto-generated files, test data, etc.).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanSource ¶
CleanSource applies the configured transformations to the source code string and returns the cleaned version.
Transformations are applied in this order:
- Comment stripping (language-specific)
- Blank line collapsing (run of blanks → single blank)
- Long line truncation
- File-level truncation
func StripComments ¶
StripComments removes all comments from source code for the given language. It delegates to the internal stripComments implementation.
Types ¶
type CleanOpts ¶
type CleanOpts struct {
// StripComments removes inline and block comments.
// Doc comments (/** ... */ or // ...) immediately before exported symbols are preserved.
StripComments bool
// StripBlankLines collapses consecutive blank lines into a single blank line.
StripBlankLines bool
// TruncateLongLines shortens lines longer than MaxLineChars by removing the tail.
TruncateLongLines bool
// MaxLineChars is the line length limit when TruncateLongLines is true.
MaxLineChars int
// TruncateBase64 shortens base64 or hex string literals that exceed 80 chars.
TruncateBase64 bool
// MaxFileChars is the total character limit for the output.
// Content is truncated with a marker if it exceeds this limit. 0 = no limit.
MaxFileChars int
}
CleanOpts controls which cleaning transformations are applied.
func DefaultOpts ¶
func DefaultOpts() CleanOpts
DefaultOpts returns sensible defaults for LLM-targeted cleaning.