scope

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package scope resolves the analysis scope: the repo root, changed files (delta mode), and the mode (full vs delta) for a run.

Package scope resolves the analysis scope: the repo root, changed files (delta mode), and the mode (full vs delta) for a run.

Index

Constants

This section is empty.

Variables

View Source
var DefaultExclusions = []string{
	"**/.archfit-cache/**",
	"**/.archfit-baseline.json",
	"**/.gitnexus/**",
	"**/.codegraph/**",
	"**/reports/**",
	"**/.venv/**",
	"**/node_modules/**",
	"**/vendor/**",
	"**/pkg/mod/**",
	"**/dist/**",
	"**/build/**",

	"**/testdata/**",
}

DefaultExclusions are tool-artifact, cache, and dependency directories archfit never analyses: measuring them yields non-deterministic or irrelevant facts — a vendored tree's complexity, a generated index, or a report written back into the scanned repo (the OpenAI study's self-scan "instability"). They are MERGED with — never replace — the config `exclusions` (see MergeExclusions). Kept here in the core ring as pure data so scope stays free of I/O. Globs use doublestar `**/<name>/**` form so they match the directory at the repo root and at any nested depth without over-matching siblings (e.g. `reports.go`).

Functions

func MergeExclusions added in v0.5.0

func MergeExclusions(configured []string) []string

MergeExclusions returns the effective exclusion globs: DefaultExclusions supplemented by the configured ones, de-duplicated and sorted so a double-run stays byte-identical regardless of config order. A configured entry prefixed with "!" re-includes a default — it removes the matching default from the result and is itself dropped, so extractors never see the negation marker. "!reports", "!.archfit-baseline.json", and the exact "!**/reports/**" all remove their default. Pure: no filesystem access.

Types

type Resolver

type Resolver interface {
	// RepoRoot returns the absolute repository root.
	RepoRoot(ctx context.Context) (string, error)
	// HeadRef returns the resolved HEAD SHA.
	HeadRef(ctx context.Context) (string, error)
	// Changed returns the repo-relative files changed between base and head.
	Changed(ctx context.Context, base, head string) ([]string, error)
}

Resolver supplies the version-control queries scope resolution needs. cmd wires the concrete git implementation; tests use an in-memory fake. scope itself stays free of process and tool dependencies.

type Scope

type Scope struct {
	// Base is the git ref used as the diff base in delta mode; empty in full mode.
	Base string
	// Head is the resolved HEAD SHA in delta mode; empty in full mode.
	Head string
	// Changed is the sorted list of repo-relative files changed since Base.
	// Nil/empty in full mode.
	Changed []string
	// Root is the absolute path of the analysis boundary (ScanRoot). All
	// extractors walk this directory. Equal to GitRoot when --root is absent.
	Root string
	// GitRoot is the absolute path to the git repository toplevel, or empty
	// when the directory is not inside a git repository (non-git full-mode runs).
	// Git operations (history, diff) use this as their working root.
	GitRoot string
	// SubtreePrefix is the GitRoot-relative path from GitRoot to Root
	// (filepath.Rel(GitRoot, Root)). Empty when Root equals GitRoot, or when
	// GitRoot is empty (non-git). Git history consumers use this to scope
	// commands to the subtree (Task 3).
	SubtreePrefix string
	// Mode indicates whether this is a delta or full-repo run.
	Mode ScopeMode
}

Scope carries the resolved analysis scope for a single run.

func Resolve

func Resolve(ctx context.Context, cfg view.ScopeConfig, r Resolver) (Scope, error)

Resolve determines the Scope for a run.

It resolves the git root via the Resolver. In full mode a failing resolver (e.g. non-git directory) is non-fatal: GitRoot is set to "" and analysis continues. In delta mode a failing resolver is a hard error (no git → no diff).

The analysis boundary (Scope.Root) is set from cfg.Root when non-empty; otherwise it falls back to the git root; when both are empty it falls back to cfg.WorkDir. Changed files are sorted here so scope's determinism contract does not depend on resolver discipline.

type ScopeMode

type ScopeMode string

ScopeMode distinguishes full-repo analysis from delta (diff-based) analysis. The name is intentionally ScopeMode (not Mode) to match the design contract shared across packages; the stutter is acceptable here.

const (
	// ModeDelta analyses only files changed between Base and Head.
	ModeDelta ScopeMode = "delta"
	// ModeFull analyses the entire repository.
	ModeFull ScopeMode = "full"
)

Jump to

Keyboard shortcuts

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