sensitive

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 12 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 sensitive decides which of a pull request's changed files deserve a closer look before anyone reviews, merges, or opens an agent on it: files that run on CI with the repository's token and secrets, files a coding agent loads or runs, files that run on the reviewer's machine, files that change who must review, and files that bring in third-party code.

Only pull requests from outside the repository are checked: every pull request from a fork, from someone who is not the repository's owner, an org member, or a collaborator, and from a bot not on the trusted list. Collaborators' pull requests are checked too unless the user narrows the scope. The repository's own people, the trusted bots, and the signed-in user are never checked.

A check reads each changed file's path, and a renamed file's previous path, never its content. A path is sensitive when it matches a pattern of an enabled category: the built-in categories, in the order Categories returns them, then the user's own patterns. A file is reported under the first category that matches it.

Patterns follow .gitignore, matched without regard to case, since a case-insensitive file system, as macOS uses by default, opens .Claude/Settings.json for .claude/settings.json:

  • A pattern without a slash matches a file or folder of that name at any depth: CLAUDE.md, *.sh.
  • A pattern with a slash at its start or in its middle is matched from the repository's root: .github/workflows, /Makefile.
  • A pattern that ends with a slash matches only a folder: .claude/.
  • A pattern that matches a folder matches everything inside it.
  • * matches any run of characters within one name, ? one character, [abc] one of a set, and ** any number of folders: deploy/**/*.tf.

The settings are kept in the prefs table under the files.* keys, which the settings service writes and the inbox and the launcher read. A missing or unreadable value falls back to its default.

Index

Constants

View Source
const (
	// StatusPending is a pull request not checked since its last push: new to the inbox,
	// newly in scope, or pushed since its last check.
	StatusPending = "pending"

	// StatusFailed is a check that could not finish; the next refresh tries again.
	StatusFailed = "failed"

	// StatusFlagged is a pull request that changes sensitive files.
	StatusFlagged = "flagged"

	// StatusPartial is a pull request GitHub listed only some of the changed files of,
	// none of them sensitive.
	StatusPartial = "partial"

	// StatusClear is a pull request whose every changed file was checked, none of them
	// sensitive.
	StatusClear = "clear"
)

Check statuses.

View Source
const (
	ChangeAdded    = "added"
	ChangeRemoved  = "removed"
	ChangeModified = "modified"
	ChangeRenamed  = "renamed"
	ChangeCopied   = "copied"
	ChangeChanged  = "changed"
)

File changes, as GitHub's REST API names them.

View Source
const (
	// CategoryAgent is what coding agents load or run: settings, hooks, MCP servers, and
	// instructions. It is always on, because launches are held back by it.
	CategoryAgent = "agent"

	// CategoryWorkflows is what runs on CI with the repository's token and secrets.
	CategoryWorkflows = "workflows"

	// CategoryTooling is what runs on the reviewer's machine: build scripts, git hooks,
	// editor and container settings.
	CategoryTooling = "tooling"

	// CategoryReview is what decides who must review, and what merges or updates on its
	// own.
	CategoryReview = "review"

	// CategoryDependencies is what brings in third-party code or changes where it comes
	// from.
	CategoryDependencies = "dependencies"

	// CategoryCustom holds the user's own patterns.
	CategoryCustom = "custom"
)

Category IDs. The built-in ones are listed by Categories; CategoryCustom holds the user's own patterns.

View Source
const (
	// LevelDanger is for files that run, or steer an agent, without anyone choosing to
	// run them.
	LevelDanger = "danger"

	// LevelWarning is for files that change what the project trusts or depends on.
	LevelWarning = "warning"
)

Levels say how closely a category's files deserve a look.

View Source
const (
	// ScopeOutside checks every pull request from a fork, from outside contributors, and
	// from bots not on the trusted list.
	ScopeOutside = "outside"

	// ScopeCollaborators also checks collaborators' pull requests: people with access to
	// the repository who are not its owner or members of its org.
	ScopeCollaborators = "collaborators"
)

Scopes say whose pull requests are checked.

View Source
const (
	// PrefScope is ScopeOutside or ScopeCollaborators.
	PrefScope = "files.scope"

	// PrefOff lists the built-in categories turned off, as a JSON array of IDs.
	PrefOff = "files.off"

	// PrefPatterns lists the user's patterns, as a JSON array of strings.
	PrefPatterns = "files.patterns"
)

Prefs keys for the settings.

View Source
const (
	// MaxPatterns caps how many patterns the user can add.
	MaxPatterns = 100

	// MaxPatternLength caps one pattern, in bytes.
	MaxPatternLength = 200
)

Bounds on the user's patterns.

View Source
const DefaultScope = ScopeCollaborators

DefaultScope is the scope of a fresh database.

Variables

View Source
var (
	// ErrInvalidScope is returned for a scope that is not one of the choices.
	ErrInvalidScope = errors.New("unknown scope")

	// ErrUnknownCategory is returned for a category ID that is not built in.
	ErrUnknownCategory = errors.New("unknown category")

	// ErrLockedCategory is returned when turning off a category that is always on.
	ErrLockedCategory = errors.New("this category is always on")

	// ErrInvalidPattern is returned for a pattern that cannot be used.
	ErrInvalidPattern = errors.New("invalid pattern")

	// ErrTooManyPatterns is returned for more than MaxPatterns patterns.
	ErrTooManyPatterns = errors.New("too many patterns")

	// ErrNotChecked is returned for an item whose files are not checked: an issue, or a
	// pull request from the repository's own people, a trusted bot, or the signed-in user.
	ErrNotChecked = errors.New("this item's files are not checked")
)

Functions

func Checked

func Checked(scope, class, association string, mine bool) bool

Checked reports whether a pull request's files are checked under scope: every pull request whose trust class is trust.ClassOutside, and a collaborator's under ScopeCollaborators, but never one the signed-in user opened (mine).

func DiffURL

func DiffURL(prURL, filePath string) string

DiffURL returns the address of a file's diff in a pull request on GitHub: the files page, at the anchor GitHub names after the SHA-256 of the file's path. It is "" for a page that is not on GitHub.

func EncodeList

func EncodeList(list []string) string

EncodeList writes a list for PrefOff or PrefPatterns.

func NormalizePatterns

func NormalizePatterns(patterns []string) ([]string, error)

NormalizePatterns cleans the user's patterns as entered: each is trimmed, empty ones and repeats (ignoring case) are dropped, and the order is kept. A pattern that cannot be used is an ErrInvalidPattern naming it, and more than MaxPatterns is ErrTooManyPatterns.

func SetCategory

func SetCategory(off []string, id string, on bool) ([]string, error)

SetCategory returns off with a built-in category turned on or off, sorted, for PrefOff. A locked category cannot be turned off.

func ValidScope

func ValidScope(scope string) bool

ValidScope reports whether scope is one of the choices.

Types

type Category

type Category struct {
	// ID is what the settings store, such as "workflows".
	ID string `json:"id"`

	// Label names the category in full, and Short on a card.
	Label string `json:"label"`
	Short string `json:"short"`

	// Description says why its files deserve a look.
	Description string `json:"description"`

	// Level is LevelDanger or LevelWarning.
	Level string `json:"level"`

	// Locked reports a category that cannot be turned off.
	Locked bool `json:"locked"`

	// Patterns are the category's patterns, in the syntax the package describes.
	Patterns []string `json:"patterns"`
}

Category is one kind of sensitive file. Every field is a plain value.

func Categories

func Categories() []Category

Categories returns the built-in categories, in the order a file is matched against them.

type Check

type Check struct {
	// Status is one of the Status* values.
	Status string `json:"status"`

	// Head is the head commit the files were checked at, or "" before any check.
	Head string `json:"head"`

	// Checked is how many files were checked, and Total how many the pull request
	// changes; Complete reports that every one was checked.
	Checked  int  `json:"checked"`
	Total    int  `json:"total"`
	Complete bool `json:"complete"`

	// Groups are the sensitive files by category, in matching order, each sorted by
	// path. It is empty unless Status is StatusFlagged.
	Groups []Group `json:"groups"`

	// CheckedAt is when the files were checked, as RFC 3339, or "".
	CheckedAt string `json:"checkedAt"`

	// Error says why the last check failed, or is "".
	Error string `json:"error"`
}

Check is what checking a pull request's changed files found, as the UI shows it. Every field is a plain value.

func (Check) Category

func (c Check) Category(id string) (Group, bool)

Category returns the group of a category's files, if it has any.

func (Check) Summary

func (c Check) Summary() string

Summary names the sensitive files for a prompt, in matching order: each path with its category's short label, and where a moved file came from, as in ".github/workflows/ci.yml (Workflows)" or "docs/old.yml (Workflows, moved from .github/workflows/ci.yml)". It names at most 20, then says how many more, and is "" when no file is sensitive.

type Config

type Config struct {
	// Scope is ScopeOutside or ScopeCollaborators.
	Scope string `json:"scope"`

	// Off lists the built-in categories turned off, sorted. A locked category is never
	// in it.
	Off []string `json:"off"`

	// Patterns are the user's own patterns, in the order they were added.
	Patterns []string `json:"patterns"`
}

Config is what the user chose. Every field is a plain value.

func DecodeConfig

func DecodeConfig(prefs map[string]string) Config

DecodeConfig reads the stored settings; each one missing or unreadable falls back to its default. A stored category that is unknown or locked, or a pattern that is no longer valid, is dropped.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig is the configuration of a fresh database: collaborators checked too, every category on, and no patterns of the user's.

func (Config) Enabled

func (c Config) Enabled(id string) bool

Enabled reports whether a built-in category is on.

type File

type File struct {
	// Path is the file's path in the repository, after the change.
	Path string

	// PreviousPath is a renamed or copied file's path before the change, or "".
	PreviousPath string

	// Change is one of the Change* values.
	Change string
}

File is one changed file of a pull request.

type Finding

type Finding struct {
	Path string `json:"path"`

	// PreviousPath is a renamed or copied file's path before the change, or "". A file
	// moved out of a sensitive folder is reported for the path it left.
	PreviousPath string `json:"previousPath"`

	// Change is how the file changed: added, removed, modified, renamed, copied, or
	// changed.
	Change string `json:"change"`

	// Pattern is the pattern the file matched.
	Pattern string `json:"pattern"`

	// URL opens the file's diff in the pull request on GitHub, or is "".
	URL string `json:"url"`
}

Finding is one sensitive file. Every field is a plain value.

type Group

type Group struct {
	Category    string    `json:"category"`
	Label       string    `json:"label"`
	Short       string    `json:"short"`
	Description string    `json:"description"`
	Level       string    `json:"level"`
	Files       []Finding `json:"files"`
}

Group is a category's sensitive files. Every field is a plain value.

type Matcher

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

Matcher matches paths against the enabled categories' patterns and the user's own.

func NewMatcher

func NewMatcher(cfg Config) *Matcher

NewMatcher compiles the patterns of every category cfg enables, the built-in ones in matching order and then the user's. A user's pattern that no longer compiles is skipped.

func (*Matcher) Evaluate

func (m *Matcher) Evaluate(r *Result, head, prURL string) Check

Evaluate turns a stored result into a Check for a pull request whose head is now head ("" when unknown) and whose page is prURL. A nil result, or one for another head, is pending; a failed one stays failed whatever its head, so the failure shows until a check succeeds.

func (*Matcher) Match

func (m *Matcher) Match(p string) (Category, string, bool)

Match returns the category and the pattern of the first rule a path matches.

type PathMatch

type PathMatch struct {
	// Sensitive reports that the path matched a pattern.
	Sensitive bool `json:"sensitive"`

	// Category, Label, and Level describe the category it matched, and Pattern the
	// pattern; all are "" when it matched none.
	Category string `json:"category"`
	Label    string `json:"label"`
	Level    string `json:"level"`
	Pattern  string `json:"pattern"`
}

PathMatch says whether a path is sensitive under a configuration, and why. Every field is a plain value.

func Lookup

func Lookup(cfg Config, filePath string) PathMatch

Lookup reports whether a path is sensitive under cfg, for trying patterns out.

type Result

type Result struct {
	// Head is the head commit the files were listed at.
	Head string

	// Total is how many files GitHub says the pull request changes.
	Total int

	// Files are the files GitHub listed.
	Files []File

	// Complete reports that Files holds every changed file.
	Complete bool

	// Error says why the check failed, or is "".
	Error string

	// CheckedAt is when the check ran.
	CheckedAt time.Time
}

Result is one stored check of a pull request's changed files.

Jump to

Keyboard shortcuts

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