Documentation
¶
Index ¶
- func AstGrepBinary() (string, error)
- func CalculateHash(filePath string) (string, error)
- func CleanComment(raw string) string
- func CompactPath(path string) string
- func CountLines(s string) int
- func EstimateTokens(s string) int
- func ExtractCodeBlock(s string) string
- func ExtractJSON(s string) string
- func ExtractLines(filePath string, startLine, endLine int) (string, error)
- func ExtractList(text, header string) []string
- func FormatTokens(n int) string
- func GetRepoName(ctx context.Context) string
- func GetRepoRoot() (string, error)
- func HashString(s string) string
- func OkConfirmation(action, detail string) string
- func ParseRating(s string) (float64, error)
- func RestoreFile(ctx context.Context, path string) error
- func SafeCommand(ctx context.Context, name string, args ...string) (*exec.Cmd, error)
- func SafeUintToInt(u uint) (int, error)
- func SanitizeFTS(q string) string
- func SerializeFloat32(vector []float32) ([]byte, error)
- func StringHash(s string) string
- func StripANSI(s string) string
- func SymbolSignatureHash(symbol, path, signature string) string
- func Truncate(s string, max int) string
- func ValidatePath(path string) (string, error)
- type DiffRange
- type LazyRegex
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AstGrepBinary ¶ added in v1.4.0
AstGrepBinary returns the name of the installed ast-grep executable, or an error when no candidate is on PATH.
It deliberately returns the bare name rather than the resolved absolute path: SafeCommand validates its binary against a closed allow-list of names, so a path would be rejected there and every structural refactor would fail on the machines that install only `ast-grep`.
func CalculateHash ¶
CalculateHash computes the SHA-256 hash of a file. It uses io.Copy to stream the file into the hasher to minimize memory usage.
func CleanComment ¶
CleanComment strips comment markers and normalizes docstrings across Go, TS, and Python.
func CompactPath ¶
CompactPath strips common prefixes like src/, lib/, internal/ from a path.
func EstimateTokens ¶
EstimateTokens estimates token count using ~4 chars/token heuristic.
func ExtractCodeBlock ¶
ExtractCodeBlock isolates code from Markdown blocks or returns the raw string if no blocks found. Unlike ExtractJSON, it does not attempt to match braces, making it safe for Go code.
func ExtractJSON ¶
ExtractJSON isolates a JSON block from potentially conversational text.
func ExtractLines ¶
ExtractLines reads a file and returns the content between startLine and endLine (inclusive, 1-indexed).
func ExtractList ¶
ExtractList extracts a bulleted list following a specific header.
func FormatTokens ¶
FormatTokens formats a token count for display: "1.2M", "59.2K", "694".
func GetRepoName ¶
GetRepoName returns the name of the repository (e.g., "scouter") from origin remote.
func GetRepoRoot ¶
GetRepoRoot locates the dynamic anchor of the project (go.mod or .git).
func HashString ¶
HashString computes the SHA-256 hash of a string.
func OkConfirmation ¶
OkConfirmation produces a compact confirmation message.
func ParseRating ¶
ParseRating extracts a rating like "8.5 / 10" from text.
func RestoreFile ¶
RestoreFile executes 'git restore <file>' to revert changes in a specific file.
func SafeCommand ¶
SafeCommand creates a validated *exec.Cmd from the allow-listed binaries. It rejects any binary outside allowedBinaries, any argument carrying a character from dangerousChars, and any flag that is not allow-listed for that binary. It never wraps its input in a shell.
func SafeUintToInt ¶
SafeUintToInt safely converts a uint to an int, preventing overflow on 32-bit systems.
func SanitizeFTS ¶
SanitizeFTS sanitizes a raw search string for safe use in SQLite FTS5 MATCH expressions. It escapes double quotes and wraps the query in double quotes to neutralize control characters.
func SerializeFloat32 ¶ added in v1.4.0
SerializeFloat32 serializes a float32 slice to little-endian bytes for sqlite-vec.
func StringHash ¶
StringHash computes the SHA-256 hash of a string.
func SymbolSignatureHash ¶
func ValidatePath ¶
ValidatePath implements "Project Jail" (CWE-22 prevention) with absolute signal.
Types ¶
type LazyRegex ¶
type LazyRegex struct {
// contains filtered or unexported fields
}
LazyRegex compiles a regex pattern on first use and caches the result.
func NewLazyRegex ¶
NewLazyRegex creates a LazyRegex that will compile pattern on first use.