digest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: MIT Imports: 18 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MinimalTreeConfig = TreeConfig{
	MaxDepth:              8,
	MaxEntries:            32,
	MaxEntriesPerLevel:    0.5,
	EntryConnector:        " ",
	LastEntryConnector:    " ",
	ContinuationConnector: " ",
}

MinimalTreeConfig creates a small, token-efficient tree.

View Source
var ReplaceEmails = regexp.MustCompile(`[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}`).ReplaceAllString

ReplaceEmails tries to detect email addresses in the subject string and then replaces them.

Functions

func GetTree

func GetTree(fsys fs.FS, cfg TreeConfig) ([]string, error)

GetTree returns a slice of strings representing the tree structure.

func RemoveComments

func RemoveComments(name, content string) string

RemoveComments attempts to remove comments from supported file types.

func ReplaceSecrets

func ReplaceSecrets(s, replacement string) string

ReplaceSecrets detects and replaces secrets in the subject string, e.g. with "[REDACTED]".

Types

type Config

type Config struct {
	DisableGitIgnore bool     // Disable parsing .gitignore files.
	IgnoreFiles      []string // Other "gitignore" file patterns to ignore.
	ReadFiles        []string // Files to read in the project.
	MaxFileLength    int      // Truncate file contents beyond this length.

	Rulesets  []rules.RulesetSpec // Rules to run in each directory.
	ExprCache eval.Cache          // The expression cache.
}

func DefaultConfig

func DefaultConfig() (*Config, error)

type Digest

type Digest struct {
	Tree          string              `json:"tree"`
	Reports       map[string][]Report `json:"reports"` // Grouped by path
	SelectedFiles []FileData          `json:"selected_files"`
}

type Digester

type Digester struct {
	// contains filtered or unexported fields
}

func NewDigester

func NewDigester(fsys fs.FS, cnf *Config) (*Digester, error)

func (*Digester) GetDigest

func (d *Digester) GetDigest(_ context.Context) (*Digest, error)

type FileData

type FileData struct {
	Name      string `json:"name"`
	Content   string `json:"content"`
	Truncated bool   `json:"truncated,omitempty"`
	Cleaned   bool   `json:"cleaned,omitempty"`
	Size      int64  `json:"size,omitempty"`
}

FileData wraps file data to pass to a template.

func Clean

func Clean(files []FileData) []FileData

Clean removes comments and redacts secrets in a list of files.

func ReadMultiple

func ReadMultiple(fsys fs.FS, maxLength int, patterns ...string) ([]FileData, error)

ReadMultiple reads the given files, specified by glob patterns, up to a limit of bytes each. It ignores errors resulting from nonexistence, permissions or empty files. It skips any files that are ignored in an ".aiignore" file.

type Report

type Report struct {
	Result  string         `json:"result" yaml:"result"`
	With    map[string]any `json:"metadata,omitempty" yaml:"metadata,omitempty,flow"`
	Ruleset string         `json:"ruleset" yaml:"ruleset"`
	Groups  []string       `json:"groups,omitempty" yaml:"groups,omitempty,flow"`
}

Report is a simpler, more easily serialized, version of rules.Report.

type TreeConfig

type TreeConfig struct {
	MaxDepth           int     // 0 = unlimited depth
	MaxEntries         int     // 0 = unlimited entries
	MaxEntriesPerLevel float64 // 0.0 = no scaling, otherwise multiplied per level (e.g., 0.5 halves each level)

	EntryConnector        string // Entry connector, if empty defaults to "├"
	LastEntryConnector    string // Last entry connector, if empty defaults to "└"
	ContinuationConnector string // Vertical continuation connector, if empty defaults to "│"
	DirectorySuffix       string // Directory suffix, e.g. "/" (defaults to no suffix)

	// DisableGitIgnore disables handling of .gitignore and .git/info/exclude files.
	//
	// The IgnoreDirs setting will still be respected, and certain directories will
	// always be ignored (namely .git and node_modules). Rules that implement the
	// Ignorer interface will also still be respected.
	DisableGitIgnore bool

	IgnoreDirs []string // Additional directory ignore rules, using git's exclude syntax.
}

TreeConfig configures the GetTree behavior.

Jump to

Keyboard shortcuts

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