Documentation
¶
Overview ¶
Package fuzzy implements a pure line-based fuzzy text matcher with a 4-strategy cascade (exact, whitespace-normalized, indentation-flexible, fail-with-diff), ellipsis segmentation, and Aider-style indentation reflow. It performs no I/O — callers read source, invoke Match, and decide whether to write.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrAmbiguous = errors.New("fuzzy: ambiguous match")
ErrAmbiguous is the sentinel for fuzzy.Match's ambiguity refusal (CONTEXT.md S4: when a strategy returns N>1 candidates, the cascade halts and the engine returns an error rather than silently picking one). Use errors.Is(err, fuzzy.ErrAmbiguous) to detect this branch. Phase 53 D-10: classifier maps this sentinel to outcome="ambiguous_match".
var ErrNoMatch = errors.New("fuzzy: no match")
ErrNoMatch is the sentinel for fuzzy.Match's "no fuzzy match found" failure (StrategyFailed — the cascade exhausted all four tiers without producing a unique match). Use errors.Is(err, fuzzy.ErrNoMatch) to detect this branch from callers that need to distinguish it from ambiguity or other invalid argument errors. Phase 53 D-10: classifier maps this sentinel to outcome="no_match" and strategy="none" (Q-4: failed is never emitted as a strategy label value).
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// Replacement is the text the engine will reflow onto the matched
// region's indentation and return via Result.ReplacementText.
Replacement string
// AllowEllipsis opts into "..."-on-own-line segmentation (FUZZ-08).
// When false, "..." lines are treated as literal text.
AllowEllipsis bool
}
Options configures a single call to Match. Zero-value is valid: Replacement="" means the caller is probing for a match without substituting; AllowEllipsis=false disables "..." segmentation.
type Result ¶
type Result struct {
// Strategy is the tier that produced the match.
Strategy Strategy
// Score is the discrete tier value: 1.0 / 0.95 / 0.85 / 0.0.
Score float64
// StartByte is the inclusive byte offset of the matched region in source.
StartByte int
// EndByte is the exclusive byte offset of the matched region in source.
EndByte int
// MatchedText is source[StartByte:EndByte] — the original region.
MatchedText string
// ReplacementText is Options.Replacement after common-prefix dedent and
// reapplication of the matched region's leading whitespace. Empty
// replacement lines are preserved as empty (no trailing whitespace).
ReplacementText string
}
Result reports a successful match. All byte offsets are relative to the `source` string passed to Match (not file offsets).
func Match ¶
Match runs the 4-strategy cascade over source and search, returning a Result on success or an error on ambiguity / no-match / invalid input. The engine is pure -- it performs no I/O. Callers read source, invoke Match, inspect the Result, and decide whether to write.
Cascade (CONTEXT.md S2, locked):
- Exact (score 1.0)
- Whitespace (score 0.95) -- TrimSpace per line
- IndentFlex (score 0.85) -- TrimLeft(" \t") per line
- Failed (score 0.0) -- serr.InvalidArgs with unified-diff-style detail
At any strategy, N > 1 hits returns serr.InvalidArgs immediately and does NOT cascade -- add anchor context to disambiguate (CONTEXT.md S4).
type Strategy ¶
type Strategy string
Strategy enumerates the match strategies in the 4-tier cascade. The string values are part of the public contract: they are reported back to agents in tool responses (FUZZ-02) and MUST NOT change without a coordinated update to downstream consumers.
const ( // StrategyExact is byte-for-byte line equality. Score tier: 1.0. StrategyExact Strategy = "exact" // StrategyWhitespace trims leading/trailing whitespace per line before // comparing. Internal whitespace inside a line still must match. // Score tier: 0.95. StrategyWhitespace Strategy = "whitespace_normalized" // StrategyIndentationFlex strips leading " \t" per line before comparing. // Internal whitespace inside a line still must match. Score tier: 0.85. StrategyIndentationFlex Strategy = "indentation_flexible" // StrategyFailed indicates no strategy produced a unique match; Match // returns serr.InvalidArgs with a unified-diff-style payload. // Score tier: 0.0. StrategyFailed Strategy = "failed" )