codeskim

package
v0.46.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2025 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxASTDepth prevents stack overflow from deeply nested code
	MaxASTDepth = 500
	// MaxASTNodes prevents memory exhaustion from large ASTs
	MaxASTNodes = 100000
)

Variables

This section is empty.

Functions

func GetBodyNodeTypes

func GetBodyNodeTypes(lang Language) []string

GetBodyNodeTypes returns the node types that represent function/method bodies

func GetTreeSitterLanguage

func GetTreeSitterLanguage(lang Language) *sitter.Language

GetTreeSitterLanguage returns the tree-sitter language for a given language

func GetTreeSitterLanguageForTSX

func GetTreeSitterLanguageForTSX() *sitter.Language

GetTreeSitterLanguageForTSX returns the TSX-specific tree-sitter language

func ResolveFiles

func ResolveFiles(source any) ([]string, error)

ResolveFiles resolves the source parameter to a list of files to process Handles: - Single file path - Directory path (recursively finds all supported files) - Glob pattern - Array of any combination of the above

Types

type CodeSkimTool

type CodeSkimTool struct{}

CodeSkimTool implements the tools.Tool interface for code transformation

func (*CodeSkimTool) Definition

func (t *CodeSkimTool) Definition() mcp.Tool

Definition returns the tool's definition for MCP registration

func (*CodeSkimTool) Execute

func (t *CodeSkimTool) Execute(ctx context.Context, logger *logrus.Logger, cache *sync.Map, args map[string]any) (*mcp.CallToolResult, error)

Execute executes the code skim tool

func (*CodeSkimTool) ProvideExtendedInfo

func (t *CodeSkimTool) ProvideExtendedInfo() *tools.ExtendedHelp

ProvideExtendedInfo implements the ExtendedHelpProvider interface

type FileResult

type FileResult struct {
	Path                string   `json:"path"`
	Transformed         string   `json:"transformed"`
	Language            Language `json:"language"`
	FromCache           bool     `json:"from_cache"`
	Truncated           bool     `json:"truncated,omitempty"`
	TotalLines          *int     `json:"total_lines,omitempty"`
	ReturnedLines       *int     `json:"returned_lines,omitempty"`
	NextStartingLine    *int     `json:"next_starting_line,omitempty"`
	ReductionPercentage *int     `json:"reduction_percentage,omitempty"`
	MatchedItems        *int     `json:"matched_items,omitempty"`
	TotalItems          *int     `json:"total_items,omitempty"`
	FilteredItems       *int     `json:"filtered_items,omitempty"`
	Error               string   `json:"error,omitempty"`
}

FileResult represents the result for a single file

type Language

type Language string

Language represents supported programming languages

const (
	LanguagePython     Language = "python"
	LanguageGo         Language = "go"
	LanguageJavaScript Language = "javascript"
	LanguageTypeScript Language = "typescript"
	LanguageRust       Language = "rust"
	LanguageC          Language = "c"
	LanguageCPP        Language = "cpp"
	LanguageBash       Language = "bash"
	LanguageHTML       Language = "html"
	LanguageCSS        Language = "css"
	LanguageSwift      Language = "swift"
	LanguageJava       Language = "java"
	LanguageYAML       Language = "yaml"
	LanguageHCL        Language = "hcl"
)

func DetectLanguage

func DetectLanguage(filePath string) (Language, error)

DetectLanguage detects the programming language from a file path

func ValidateLanguage

func ValidateLanguage(lang string) (Language, error)

ValidateLanguage checks if a language string is valid

type NodeTypes

type NodeTypes struct {
	Function string
	Method   string
	Class    string
}

NodeTypes represents language-specific AST node type names

func GetNodeTypes

func GetNodeTypes(lang Language) NodeTypes

GetNodeTypes returns the language-specific node types for AST traversal

type SkimRequest

type SkimRequest struct {
	Source       any  `json:"source"` // String or array of strings: file path(s), directory path(s), or glob pattern(s)
	ClearCache   bool `json:"clear_cache,omitempty"`
	StartingLine int  `json:"starting_line,omitempty"` // Line number to start from (1-based)
	Filter       any  `json:"filter,omitempty"`        // String or array of strings: glob pattern(s) to filter function/method/class names (prefix with ! for inverse)
}

SkimRequest represents a request to transform code

type SkimResponse

type SkimResponse struct {
	Files            []FileResult `json:"files"`
	TotalFiles       int          `json:"total_files"`
	ProcessedFiles   int          `json:"processed_files"`
	FailedFiles      int          `json:"failed_files"`
	ProcessingTimeMs *int64       `json:"processing_time_ms,omitempty"`
}

SkimResponse represents the response from a code transformation

type TransformResult

type TransformResult struct {
	Transformed   string
	MatchedItems  int
	TotalItems    int
	FilteredItems int
}

TransformResult contains transformation output and metadata

func Transform

func Transform(ctx context.Context, source string, lang Language, isTSX bool) (*TransformResult, error)

Transform transforms source code by removing implementation details

func TransformWithFilter

func TransformWithFilter(ctx context.Context, source string, lang Language, isTSX bool, filterPatterns []string) (*TransformResult, error)

TransformWithFilter transforms source code and optionally filters by name pattern(s) filterPatterns is an array of glob patterns (e.g., ["handle_*", "!temp_*"]) Pass nil or empty slice for no filtering

Jump to

Keyboard shortcuts

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