clean

package
v1.39.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

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

func CleanSource(source, language string, opts CleanOpts) string

CleanSource applies the configured transformations to the source code string and returns the cleaned version.

Transformations are applied in this order:

  1. Comment stripping (language-specific)
  2. Blank line collapsing (run of blanks → single blank)
  3. Long line truncation
  4. File-level truncation

func StripComments

func StripComments(source, language string) string

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.

Jump to

Keyboard shortcuts

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