evidence

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package evidence implements the command-safety classifier's read-only evidence-tool pack (design doc §13.2): bounded filesystem inspection (path.go), bounded Git repository inspection (git.go), an injectable repository-visibility seam (visibility.go), and the catalog that wires them into Harness's tool.Definition/hustle.EvidenceToolPolicy contracts (catalog.go).

Every tool in this package is built exclusively from tool.EvidenceFactoryBindings.ReadWorkspace — a single canonical, consumer-supplied root directory. Harness's own evidence runner (internal/hustleruntime/evidence_runner.go, not part of this module) independently re-verifies containment via a consumer-supplied EvidenceContainmentVerifier before any call executes; that is the authoritative boundary. This package's own containment logic exists anyway, as defense in depth against TOCTOU between that check and this tool's actual filesystem access (design §13.4): every access to the filesystem funnels through *os.Root (Go's syscall-level, symlink-aware root confinement primitive), never through unconfined os/filepath calls on attacker-influenced paths.

Index

Constants

View Source
const (
	// KindFilesystemStat covers canonical path resolution, lstat-style
	// metadata (not following the final symlink), and resolved-target
	// metadata. It never reads file contents.
	KindFilesystemStat = "evidence.filesystem.stat"
	// KindFilesystemList covers bounded, single-level directory listing.
	KindFilesystemList = "evidence.filesystem.list"
	// KindFilesystemRead covers bounded file content reading.
	KindFilesystemRead = "evidence.filesystem.read"
	// KindFilesystemGlob covers bounded filename pattern matching. It
	// reports paths only, never file contents.
	KindFilesystemGlob = "evidence.filesystem.glob"
	// KindFilesystemGrep covers bounded file-content pattern search.
	KindFilesystemGrep = "evidence.filesystem.grep"
)

Requirement.Kind constants for the filesystem evidence pack. These are exported and stable: a consumer's evidence-tool access allowlist (tool.EvidenceContainmentVerifier's caller, per design §13.1) configures trust by exact kind string, so renaming these is a breaking change for every consumer.

View Source
const KindGitRead = "evidence.git.read"

KindGitRead is the single Requirement.Kind shared by every Git evidence tool in this pack (repository/worktree state, status, diff metadata, remotes, branch/upstream/default-branch, and remote-visibility hints). They share one kind deliberately: from an access-control perspective they are uniformly read-only metadata queries scoped to the review workspace's repository, with no differentiated risk tier that would justify a finer split (unlike the filesystem pack, where stat/list/read/glob/grep expose meaningfully different amounts of information). It is exported and stable: a consumer's evidence access allowlist configures trust by this exact string (design §13.1).

Variables

This section is empty.

Functions

func Definitions

func Definitions(limits Limits, resolver VisibilityResolver) []tool.Definition

Definitions returns the complete command-safety evidence pack: the filesystem definition followed by the Git definition.

func FilesystemDefinition

func FilesystemDefinition(limits Limits) tool.Definition

FilesystemDefinition returns the sealed evidence definition for the five filesystem tools (stat/list/read/glob/grep), bounded by limits.

func GitDefinition

func GitDefinition(limits Limits, resolver VisibilityResolver) tool.Definition

GitDefinition returns the sealed evidence definition for the four Git tools (repository status, diff, remotes, branch), bounded by limits, with visibility optionally resolved through resolver (nil is a safe, network-free default — see VisibilityResolver).

func RemoteVisibilityHint

func RemoteVisibilityHint(remoteURL string) string

RemoteVisibilityHint derives a best-effort, purely LOCAL, non-network description of a remote URL's hosting family (e.g. "github.com", "local filesystem") for display alongside Visibility. It is a hint about WHERE the remote is hosted, never a verdict on public/private access — that distinction always requires VisibilityResolver, and is VisibilityUnknown without one.

func RequirementKinds

func RequirementKinds() []string

RequirementKinds returns a fresh copy of every tool.Requirement.Kind value this package's evidence tools declare. See requirementKinds for why this is the package's sole introspection point for that set.

Types

type Limits

type Limits struct {
	// MaxListEntries bounds evidence_filesystem_list's returned entry count.
	MaxListEntries int
	// MaxReadBytes bounds evidence_filesystem_read's default read size when
	// a call does not specify its own (smaller-or-equal) limit.
	MaxReadBytes int
	// MaxGlobMatches bounds evidence_filesystem_glob's returned match count.
	MaxGlobMatches int
	// MaxGrepMatches bounds evidence_filesystem_grep's returned match count.
	MaxGrepMatches int
	// MaxGrepFileBytes bounds how many bytes of any one file
	// evidence_filesystem_grep scans.
	MaxGrepFileBytes int
	// MaxStatusBytes bounds evidence_git_repository_status's status text.
	MaxStatusBytes int
	// MaxDiffBytes bounds evidence_git_diff's diff text.
	MaxDiffBytes int
}

Limits bounds every evidence tool's output AT THE SOURCE: each tool truncates while it reads/lists/searches, never after buffering an unbounded result. Zero (or a value exceeding the package's internal hard ceiling) falls back to a safe default — see (Limits).normalize.

func DefaultLimits

func DefaultLimits() Limits

DefaultLimits returns conservative, non-zero defaults comfortably inside every hard ceiling this package enforces internally.

type Visibility

type Visibility string

Visibility is the closed classification of a Git remote's visibility, as reported by the evidence_git_remotes tool.

The default and safe outcome is VisibilityUnknown: this package never makes an outbound network call (design §13.3 forbids evidence tools from accessing arbitrary network resources), so a real public/private/internal answer can only ever come from a consumer-injected VisibilityResolver wired to a real, governed, read-only hosting API. Nothing in this package ever infers VisibilityPublic or VisibilityPrivate from the remote URL text alone — a familiar hostname is not evidence of access control.

const (
	VisibilityUnknown  Visibility = "unknown"
	VisibilityPublic   Visibility = "public"
	VisibilityPrivate  Visibility = "private"
	VisibilityInternal Visibility = "internal"
)

type VisibilityResolver

type VisibilityResolver interface {
	ResolveVisibility(ctx context.Context, remoteURL string) (Visibility, error)
}

VisibilityResolver is the explicitly configured, read-only network identity source design §13.2 calls for ("repository visibility evidence through an explicitly configured, read-only network identity source"). It is OPTIONAL — StandardEvidence accepts a nil resolver, in which case every remote is reported VisibilityUnknown. This package supplies no implementation that performs network I/O: injecting a real one (e.g. backed by a hosting provider's repository-visibility endpoint) is a consumer decision, made by a party that can govern its egress, auth, and rate limits. A configured resolver MUST be read-only, MUST NOT mutate any remote state, and is expected to perform at most one bounded lookup per call; ResolveVisibility failing or returning an unrecognized value is always treated as VisibilityUnknown, never as an error that aborts the review (see resolveVisibility).

Jump to

Keyboard shortcuts

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