surface

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

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.

Machine scope reads per-user files by absolute path under the home directory; project scope reads **/ patterns below the scan root, opened only through os.Root. A missing agent gives no output and no warning.

Index

Constants

View Source
const (
	// DetailPartialParse: a tolerant parser (dotenv) skipped some lines and read the rest.
	DetailPartialParse = "partial_parse"
	// DetailWalkLimit: the search for files stopped at the entry budget.
	DetailWalkLimit = "walk_limit"
	// DetailBudget: the surface files read so far reached the byte budget
	// (BytesBudgetFactor times the file size limit); the rest were not read.
	DetailBudget = "budget"
	// DetailNotRegularFile: a surface path exists but is a symlink or another file
	// type, which is never followed.
	DetailNotRegularFile = "not_regular_file"
)

Details of other surface_parse_failed and file_unreadable warnings.

View Source
const BytesBudgetFactor = 64

BytesBudgetFactor times limits.max_file_bytes is the most bytes one surface source reads in total (a derived constant, not a setting). Past it the remaining files are not read and one surface_parse_failed warning, detail budget, is reported.

View Source
const DetailUnsupportedFormat = "unsupported_format"

DetailUnsupportedFormat is the detail of a surface_parse_failed warning for a surface whose parse format has no parser in this binary. Every format the schema accepts has one today; the check stays so a format added to the schema first is skipped with a warning and not with a crash.

View Source
const MaxWalkEntries = 200000

MaxWalkEntries is the most directory entries the walks of one run (the project tier below the scan root and every machine glob, all sharing one budget) visit before they stop with a walk_limit warning.

View Source
const (
	// MinValueBytes is the shortest string value that becomes a chunk on its own: no
	// supported key is shorter. Entries of a map group are kept at any length.
	MinValueBytes = 8
)
View Source
const Name = "surface"

Name is the adapter name.

Variables

View Source
var (
	// ErrScope is returned for a scope that is not machine or project.
	ErrScope = errors.New("surface source: scope must be machine or project")
	// ErrNoRoot is returned for a project scope without a root directory.
	ErrNoRoot = errors.New("surface source: project scope needs a root")
	// ErrNoHome is returned when the home directory cannot be found.
	ErrNoHome = errors.New("surface source: no home directory")
	// ErrUnknownSurface is returned for a files scope naming no registry surface.
	ErrUnknownSurface = errors.New("surface source: unknown surface id")
	// ErrNoFiles is returned for a files scope without files.
	ErrNoFiles = errors.New("surface source: files scope needs files")
)

Errors returned by New.

View Source
var MachineTarget = model.Target{Kind: model.TargetMachine, ID: "local", Visibility: model.VisibilityUnknown}

MachineTarget is the target of every machine surface.

Functions

func DisplayPath

func DisplayPath(abs, home string, windows bool) (string, bool)

DisplayPath returns the "~/"-prefixed, forward-slash path of abs (an absolute path with forward slashes) relative to home, or false when abs is not below home.

func MatchComponents

func MatchComponents(pat, name []string, foldCase bool) bool

MatchComponents reports whether the name components match the pattern components: "**" matches any number of components (also none) and other components are path.Match patterns. On Windows matching ignores case.

func New

func New(spec source.Spec) (source.Source, error)

New returns the surface source for spec.Scope. Surfaces come from spec.Registry (the embedded snapshot when nil).

Types

type Env

type Env struct {
	// GOOS is "darwin", "linux" or "windows".
	GOOS string
	// Home is the home directory of the user.
	Home string
	// Getenv reads an environment variable (Windows entries use USERPROFILE, APPDATA
	// and LOCALAPPDATA).
	Getenv func(string) string
}

Env is what path resolution needs from the machine, injected so tests cover every operating system.

type Pattern

type Pattern struct {
	Tier Tier
	// Prefix is the literal directory or file a machine pattern starts at: an
	// absolute path for the OS, for example "/home/u/.claude/projects" or
	// "C:/Users/u/.claude.json". Empty for the project tier.
	Prefix string
	// Rest are the pattern components below Prefix; empty when Prefix is the file.
	// A "**" component matches any number of directories.
	Rest []string
}

Pattern is a resolved path pattern. Components use forward slashes on every OS.

func Resolve

func Resolve(pattern string, env Env) (Pattern, bool)

Resolve resolves one registry path pattern for env. It returns false, and the caller skips the pattern silently, when the pattern does not resolve to an absolute path for the OS (an unset variable, a variable that is not allowed, a relative result), when it has a ".." component or when it belongs to neither tier.

A pattern starting with ~ (the home directory) or % (a Windows variable) is machine tier. A pattern starting with **/ is project tier, matched below the scan root. ** only expands below the literal prefix of its pattern, never up or outside it.

func (Pattern) Glob

func (p Pattern) Glob() bool

Glob reports whether the pattern names more than one possible file.

type Source

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

Source reads the surfaces of one scope.

func (*Source) BinarySkipped

func (s *Source) BinarySkipped() int

BinarySkipped returns how many files were skipped as binary (a NUL byte in the first 8 KiB). It is safe to call while Scan runs.

func (*Source) Name

func (s *Source) Name() string

Name returns the display name: "surfaces" for the machine scope, the surface id for the files scope, the scan root for the project scope.

func (*Source) Scan

func (s *Source) Scan(ctx context.Context, emit func(candidate.Chunk) bool, warn func(model.Warning)) error

Scan reads every surface file of the scope and emits the extracted entries. Every per-file failure is a warning and the scan continues.

func (*Source) Surfaces

func (s *Source) Surfaces() []model.SurfaceStatus

Surfaces returns the status of every surface this scope looks for, sorted by id.

func (*Source) Target

func (s *Source) Target() model.Target

Target returns the target of the scope's Locations.

type Tier

type Tier int

Tier says where a surface path pattern is read.

const (
	// TierMachine patterns start with ~ or % and name per-user files.
	TierMachine Tier = iota + 1
	// TierProject patterns start with **/ and match files below the scan root.
	TierProject
)

Path tiers.

Directories

Path Synopsis
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.

Jump to

Keyboard shortcuts

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