grep

package
v0.17.0 Latest Latest
Warning

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

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

Documentation

Overview

Package grep implements a generic, language-agnostic TOON-emitting search across a project tree, built on the same walker + matcher + enclosing infrastructure as this toolkit's other structural tools. Useful when the AI needs any substring or regex hit (class names, SQL fragments, magic strings) surfaced in a token-cheap, structured form.

Index

Constants

This section is empty.

Variables

View Source
var DefaultIgnoreDirs = []string{
	"vendor", "node_modules", "var", ".git", ".idea", ".vscode",
	".svn", ".hg", "dist", "build", "target", "__pycache__",
}

DefaultIgnoreDirs are the directories every project's grep should skip by default (heavy, machine-managed). Extra entries can be added via Options.ExtraIgnore. Exported so `sf code`'s directory expansion walks the same tree grep does, rather than drifting with a second copy.

Functions

func NewCommand

func NewCommand() *cobra.Command

NewCommand returns the `sf grep` Cobra command.

func Run

func Run(opts Options, w io.Writer) error

Run executes the scan and renders the result to w.

Types

type Hit

type Hit struct {
	File      string `json:"file"`
	Line      int    `json:"line"`
	Col       int    `json:"col"`
	Enclosing string `json:"enclosing,omitempty"`
	Text      string `json:"text"`
}

type Options

type Options struct {
	Root          string
	Patterns      []string
	Format        string // "toon" | "md" | "json"
	CaseSensitive bool
	WordBound     bool
	Regex         bool
	Exts          []string // file extensions to include (".php" etc.); empty = all
	ExtraIgnore   []string // extra directory names to skip in addition to defaults
	MaxPerPattern int      // 0 = unlimited
}

type PatternResult

type PatternResult struct {
	Pattern string `json:"pattern"`
	Files   int    `json:"files"`
	Hits    []Hit  `json:"hits"`
}

type Result

type Result struct {
	Patterns []*PatternResult `json:"patterns"`
	Empty    []string         `json:"empty,omitempty"`
	Skipped  int              `json:"skipped,omitempty"` // files skipped: binary or over-long lines
}

func Scan added in v0.11.0

func Scan(opts Options) (*Result, error)

Scan runs the search and returns the structured result without rendering or logging anything — the building block a caller that wants to post-process hits (group them by layer, feed another tool) uses instead of Run, which renders and writes telemetry. It shares the same unexported scan Run drives, so the two never drift.

Jump to

Keyboard shortcuts

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