Documentation
¶
Overview ¶
Package source is the first pipeline stage: adapters read files, staged changes, git history, images, notebooks, agent surfaces, stdin and forge orgs, and emit content chunks with their Location. Sources never detect keys themselves.
Index ¶
- Constants
- func ReadLimited(r io.Reader, limit int64) (data []byte, tooLarge bool, err error)
- func Register(name string, f Factory)
- func SniffBinary(r io.Reader) (head []byte, binary bool, err error)
- func Stopped(ctx context.Context) error
- type BinaryReporter
- type Factory
- type HistoryReporter
- type Source
- type Spec
- type SurfaceReporter
- type SurfaceShare
Constants ¶
const ( // ScopeMachine reads the per-user files of agents under the home directory. ScopeMachine = "machine" // ScopeProject reads the project-tier files of agents below the scan root. ScopeProject = "project" )
Surface scopes.
const BinarySniffBytes = 8 << 10
BinarySniffBytes is how many leading bytes of a file are searched for a NUL byte to decide that the file is binary.
const DefaultMaxBytes = 10 << 20
DefaultMaxBytes is the file size limit when Spec.MaxBytes is not set (10 MiB).
const DetailSizeLimit = "size_limit"
DetailSizeLimit is the detail code of a file_too_large warning.
Variables ¶
This section is empty.
Functions ¶
func ReadLimited ¶
ReadLimited reads r up to limit bytes. It reports tooLarge, with no data, when r holds more than limit bytes. A limit at or above math.MaxInt64 reads as math.MaxInt64 - 1 so that limit+1 cannot overflow.
func SniffBinary ¶
SniffBinary reads up to BinarySniffBytes from r and reports whether they hold a NUL byte. head is what was read; the caller continues with io.MultiReader(bytes.NewReader(head), r).
Types ¶
type BinaryReporter ¶
type BinaryReporter interface {
// BinarySkipped returns how many files were skipped as binary so far. It is safe to
// call while Scan runs.
BinarySkipped() int
}
BinaryReporter is implemented by a source that skips binary files. The engine sums the counts into Meta.BinarySkipped after the sources finish.
type Factory ¶
Factory builds a Source from a Spec. It returns an error when the spec cannot be scanned at all (for example a path that does not exist).
type HistoryReporter ¶
type HistoryReporter interface {
// History reports whether the history walk actually ran (git started) and how many
// commits it has walked so far. It is safe to call while Scan runs.
History() (ran bool, commits int)
}
HistoryReporter is implemented by a source that walks git history. The engine reads it after the sources finish to fill Meta.HistoryScanned and Meta.CommitsScanned.
type Source ¶
type Source interface {
Scan(ctx context.Context, emit func(candidate.Chunk) bool, warn func(model.Warning)) error
Name() string
Target() model.Target
}
Source is the source stage interface. Scan reads its target and calls emit once per chunk of content. emit returns false when the scan is stopping; Scan then returns ctx.Err() (the engine marks the source incomplete). Per-item failures go to warn and the scan continues; Scan returns a non-nil error only when it stopped early.
Name is the display name used in warnings about the whole source (for example a timeout), and Target is the target every emitted Location carries.
type Spec ¶
type Spec struct {
// Path is a directory or file (fs adapter).
Path string
// Name is the display name and Location path of a stream (stdin adapter).
Name string
// Reader is the stream to read (stdin adapter).
Reader io.Reader
// FS replaces the operating system file system rooted at Path (tests only).
FS fs.FS
// MaxBytes is the largest file or stream read; larger ones are skipped with a
// file_too_large warning. 0 or less means DefaultMaxBytes.
MaxBytes int64
// Scope is "machine" or "project" (surface adapter): machine surfaces read the
// per-user files under Home, project surfaces read files below Root.
Scope string
// Home is the home directory of a machine surface scan; empty means the OS home.
Home string
// Root is the scan root of a project surface scan; empty means Path.
Root string
// MaxWalkEntries is the entry budget of one surface file walk (0: the default).
MaxWalkEntries int
// GOOS and Getenv replace runtime.GOOS and os.Getenv when resolving surface paths
// (tests only).
GOOS string
Getenv func(string) string
// Registry supplies the surface entries (surface adapter); nil means the embedded
// snapshot.
Registry *registry.Registry
// dedupe of files); nil gives the source its own.
Share *SurfaceShare
// IncludeIgnored makes the fs adapter walk every file instead of listing what git
// would commit when the root is inside a git work tree.
IncludeIgnored bool
// Since limits the git-history adapter to commits reachable from HEAD but not
// from this ref; empty means the whole history. It is validated by the adapter.
Since string
// GitConfig is the proxy and CA configuration handed to git.
GitConfig gitx.Config
}
Spec says what a source adapter reads.
type SurfaceReporter ¶
type SurfaceReporter interface {
// Surfaces returns the status of every surface the source looks for, sorted by
// surface id. It is safe to call while Scan runs.
Surfaces() []model.SurfaceStatus
}
SurfaceReporter is implemented by a source that looks for agent surfaces. The engine reads it after the sources finish and merges the statuses of every source into Report.SurfacesChecked.
type SurfaceShare ¶
type SurfaceShare struct {
// contains filtered or unexported fields
}
SurfaceShare is the state the surface sources of one run share, so that the machine and project scopes spend one walk-entry budget and read each file once.
func NewSurfaceShare ¶
func NewSurfaceShare() *SurfaceShare
NewSurfaceShare returns an empty SurfaceShare.
func (*SurfaceShare) Entry ¶
func (s *SurfaceShare) Entry(limit int) bool
Entry counts one walked directory entry and reports whether the budget of limit entries still holds.
func (*SurfaceShare) First ¶
func (s *SurfaceShare) First(abs string, info os.FileInfo) bool
First reports whether the file at abs, opened with the given info, has not been claimed yet, and claims it. Files are compared by their resolved path (symbolic links evaluated); when the path cannot be resolved, by os.SameFile. The first reader wins.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package fs is the working tree source adapter ("fs"): it walks a directory, or reads one file, and emits each regular file as one chunk.
|
Package fs is the working tree source adapter ("fs"): it walks a directory, or reads one file, and emits each regular file as one chunk. |
|
Package git holds the git source adapters.
|
Package git holds the git source adapters. |
|
Package stdin is the stream source adapter ("stdin"): it reads one stream, such as standard input, whole and emits it as one chunk with Location kind stdin and target {stdin, stdin, unknown}.
|
Package stdin is the stream source adapter ("stdin"): it reads one stream, such as standard input, whole and emits it as one chunk with Location kind stdin and target {stdin, stdin, unknown}. |
|
Package surface is the agent surface source adapter ("surface"): it reads the files coding agents keep on disk (settings, allowlists, MCP config, transcripts) as the registry describes them, parses each with the format's structure-aware parser and emits one chunk per extracted entry with a Location of kind surface (surface id, path, field) so that credentials in one entry pair under same-surface-entry.
|
Package surface is the agent surface source adapter ("surface"): it reads the files coding agents keep on disk (settings, allowlists, MCP config, transcripts) as the registry describes them, parses each with the format's structure-aware parser and emits one chunk per extracted entry with a Location of kind surface (surface id, path, field) so that credentials in one entry pair under same-surface-entry. |
|
parse
Package parse reads the file formats of agent surfaces (json, jsonc, jsonl, toml, yaml, ini, dotenv, shell-history and ipynb) into a small tree that keeps the 1-based source line of every value, and selects string values from it with field selectors.
|
Package parse reads the file formats of agent surfaces (json, jsonc, jsonl, toml, yaml, ini, dotenv, shell-history and ipynb) into a small tree that keeps the 1-based source line of every value, and selects string values from it with field selectors. |