localize

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package localize implements hierarchical fault localization inspired by OpenAutoCoder/Agentless. Given a bug description or task, it narrows down the location of relevant code in three stages:

  1. File-level -- identify the most relevant files by keyword matching against file paths and directory structure.
  2. Symbol-level -- within those files, extract functions/types/methods via regex-based parsing and rank them against the query.
  3. Edit-level -- extract the code blocks for the top symbols with surrounding context so the caller knows exactly where to edit.

The package has zero external dependencies (only stdlib) and works across Go, Python, TypeScript, JavaScript, Rust, and Java.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CodeBlock

type CodeBlock struct {
	File      string // relative path
	StartLine int    // first line (1-based, inclusive)
	EndLine   int    // last line (1-based, inclusive)
	Content   string // the source text (including context lines)
}

CodeBlock is a snippet of source code extracted in Stage 3.

type FileMatch

type FileMatch struct {
	Path   string  // relative to the repo root
	Score  float64 // higher = more relevant
	Reason string  // human-readable explanation of the score
}

FileMatch represents a file identified as relevant in Stage 1.

type Localization

type Localization struct {
	Files   []FileMatch   // Stage 1: ranked files
	Symbols []SymbolMatch // Stage 2: ranked symbols within those files
	Context []CodeBlock   // Stage 3: code blocks for top symbols
}

Localization holds the results of a three-stage localization pass.

func Localize

func Localize(rootDir string, query string, opts ...Option) (*Localization, error)

Localize runs hierarchical fault localization on rootDir for the given query. It returns results from all three stages.

func (*Localization) FormatSummary

func (loc *Localization) FormatSummary() string

FormatSummary returns a human-readable summary of the localization result.

type Option

type Option func(*config)

Option configures a Localize call using the functional-options pattern.

func WithContextLines

func WithContextLines(n int) Option

WithContextLines sets the number of surrounding lines included in Stage 3 CodeBlocks.

func WithLanguage

func WithLanguage(lang string) Option

WithLanguage restricts symbol extraction to a single language. Valid values: "go", "python", "typescript", "javascript", "rust", "java". An empty string means auto-detect from extension (the default).

func WithMaxFiles

func WithMaxFiles(n int) Option

WithMaxFiles sets the maximum number of files returned from Stage 1.

func WithMaxSymbols

func WithMaxSymbols(n int) Option

WithMaxSymbols sets the maximum number of symbols returned from Stage 2.

type SymbolMatch

type SymbolMatch struct {
	File      string  // relative path to the file
	Name      string  // symbol name (e.g. "Localize", "Session.Send")
	Kind      string  // "function", "method", "type", "const", "var", "class"
	StartLine int     // first line of the symbol definition
	EndLine   int     // estimated last line
	Score     float64 // higher = more relevant
}

SymbolMatch represents a symbol identified as relevant in Stage 2.

Jump to

Keyboard shortcuts

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