banlist

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 16 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 banlist is abcd's two-layer banned-names store (itd-74, spc-20). It never prints and never exits — front doors under internal/surface/* format its results. Its I/O is reads and writes under a caller-supplied repo root, plus two subprocesses it must run to tell the truth about a pattern: `git check-ignore`, to refuse a private store git would track, and `grep`, to ask the private layer's ENFORCING engine whether an expression is usable there.

The two layers differ in visibility, and that difference is the whole design:

  • The PRIVATE layer is a gitignored per-machine file under the local tier (PrivateRelPath). Its FIRST line declares its format — keyed (KEY<space-or-tab>PATTERN) or legacy (one whole-line pattern per line) — and the key is the only part any surface ever renders: a name that must never appear in public content cannot be written into public config to ban it there. The committed .githooks/pre-commit guard is the enforcement point, so this package's job is the store, the format, and validation against that guard's engine — parse, add, remove, list — not the matching.
  • The PUBLIC layer is the banned_tokens family of the committed docs-lint config (PublicConfigRelPath), enforced deterministically in CI with a per-line escape. There is exactly one banned-token primitive: the hand-curated families already in that file and the entries these verbs write are the same mechanism, and verb-written entries are namespaced under PublicIDPrefix so ownership is legible.

Neither layer's writer ever rewrites a whole file from a decoded structure: the private store is edited line-wise and the public one by byte surgery on the located array, so hand-written comments, ordering, and formatting survive an edit and a review diff shows only the entry that changed.

Index

Constants

View Source
const (
	SeverityBlocker = "blocker"
	SeverityWarn    = "warn"
)

Severity values a public entry may carry.

View Source
const PrivateDirRelPath = ".abcd/.work.local"

PrivateDirRelPath is the local-ephemeral tier that holds the private store and its lock, repo-relative and slash-separated (an os.Root path).

View Source
const PrivateReachNote = "CI cannot enforce this layer — it protects only machines that have opted in, " +
	"and only the commits git runs a hook for (e.g. a fast-forward `git pull`, a rebase, `git am`, " +
	"`git revert` or a cherry-pick bypasses it, as does --no-verify)"

PrivateReachNote is the one sentence every surface that describes the private layer must state (AC7). It lives here, once, because the statement is a property of the layer rather than of any one renderer: a status board, a verb, and a JSON envelope that worded it differently would let a reader believe one of them meant something weaker. It is not a limitation awaiting a fix — a pattern written into CI config is a published pattern, which is the whole reason this layer is local.

It names the SECOND limit too, because "machines that have opted in" is necessary and not sufficient. A pre-commit hook sees the commits git asks it about, and a fast-forward `git pull` creates no commit at all — the commonest uncovered path of the lot, and the one a reader is least likely to think of. git runs no hook for a rebase, `git am`, `git revert` or a cherry-pick either, `--no-verify` switches it off, and a merge commit needs the separate pre-merge-commit half.

The list is explicitly non-exhaustive ("e.g.") and carries nothing that is actually covered: `git stash pop` followed by a commit runs pre-commit like any other commit, and a bypass list naming a covered path teaches a reader to distrust the rest of it. A sentence that stopped at opt-in would leave them believing an opted-in machine is fully covered, which is the belief that gets a name committed.

View Source
const PrivateRelPath = ".abcd/.work.local/private-names.txt"

PrivateRelPath is the gitignored per-machine private banlist, repo-relative. It sits in the local-ephemeral tier, which the three-tier layout gitignores as a whole — the one placement where a private pattern is safe from a `git add -A`.

View Source
const PublicConfigRelPath = ".abcd/docs-lint.json"

PublicConfigRelPath is the committed docs-lint config that holds the public layer, repo-relative.

View Source
const PublicIDPrefix = "names/"

PublicIDPrefix namespaces the banned_tokens entries these verbs own. Entries outside it (the hand-curated harness/* and present_tense/* families) are listed but never edited or removed by a verb: the prefix is the ownership boundary.

Variables

View Source
var (
	// ErrNoStore reports that the layer's file does not exist. It is never
	// flattened into an empty success: "no store" and "no entries" are different
	// states, and conflating them makes silence look like protection.
	ErrNoStore = errors.New("banlist store is absent")
	// ErrInvalidKey rejects a key outside the portable key charset.
	ErrInvalidKey = errors.New("invalid banlist key")
	// ErrInvalidPattern rejects an empty or uncompilable pattern.
	ErrInvalidPattern = errors.New("invalid banlist pattern")
	// ErrInvalidSeverity rejects a severity outside blocker|warn.
	ErrInvalidSeverity = errors.New("invalid banlist severity")
	// ErrDuplicateKey rejects a key the layer already carries.
	ErrDuplicateKey = errors.New("banlist key already exists")
	// ErrUnknownKey reports a key the layer does not carry.
	ErrUnknownKey = errors.New("unknown banlist key")
	// ErrNotManaged reports an entry outside the verb-owned id namespace.
	ErrNotManaged = errors.New("banlist entry is not verb-managed")
	// ErrMalformedStore reports a store whose bytes cannot be read as this layer's
	// format at all (as opposed to one unusable line, which is reported by number).
	ErrMalformedStore = errors.New("banlist store is malformed")
	// ErrLegacyStore reports a private store with no format declaration and at
	// least one entry. Its lines are whole-line patterns, so a verb may not write a
	// keyed line into it: doing so would change what every other line means.
	ErrLegacyStore = errors.New("banlist store predates the keyed format")
	// ErrStoreNotIgnored reports a private store at a path git would track. The
	// layer's whole safety rests on the file being untracked.
	ErrStoreNotIgnored = errors.New("banlist private store is not gitignored")
	// ErrStoreLocked reports that another process holds the store's lock.
	ErrStoreLocked = errors.New("banlist store is locked by another process")
)

Sentinel errors. A message never contains a pattern value: on the private layer the pattern is the secret, and an error is output like any other.

Functions

This section is empty.

Types

type AddPrivateRequest

type AddPrivateRequest struct {
	RepoRoot string
	Key      string
	Pattern  string
}

AddPrivateRequest adds one private entry.

type AddPublicRequest

type AddPublicRequest struct {
	RepoRoot  string
	Key       string
	Pattern   string
	Severity  string
	Successor string
}

AddPublicRequest adds one public entry. Severity defaults to blocker; Successor defaults to defaultSuccessor.

type Entry

type Entry struct {
	Key  string `json:"key"`
	Line int    `json:"line"`
}

Entry is one private banlist entry as any surface may see it: the key and the line it sits on. There is deliberately NO pattern field — the type is the redaction, so no future rendering can leak the value by accident (AC2/AC6).

type PrivateReport

type PrivateReport struct {
	// Path is the store's repo-relative location (reported whether or not it exists).
	Path string `json:"path"`
	// Present distinguishes "this machine has not opted in" from "opted in with no
	// entries" — the layer is local by construction, so its absence is a fact a
	// surface must be able to state plainly.
	Present bool `json:"present"`
	// Keyed reports the store's format: true when its first line declares the
	// keyed format, false for a legacy whole-line-pattern store. It changes what
	// every other line MEANS, so a diagnostic that hid it would be unreadable.
	Keyed bool `json:"keyed"`
	// Entries are the keys, in file order. A line that does not parse contributes
	// none: it has no key, and its text may be the secret.
	Entries []Entry `json:"entries"`
	// Malformed lists the 1-based line numbers the enforcement engine cannot use —
	// a line that does not parse in this store's format, or a pattern grep refuses.
	// The guard refuses every commit until they are fixed. Line numbers only: the
	// content of such a line is withheld like any other.
	Malformed []int `json:"malformed_lines"`
	// Inert lists the 1-based line numbers whose pattern the engine ACCEPTS but
	// reads differently from the language it was written in (a Perl-style escape,
	// an inline flag group). The guard does not refuse these — grep may read them
	// differently than written, which is the more dangerous failure and a different
	// remedy.
	Inert []int `json:"inert_lines"`
	// NotIgnored reports a present store at a path git does NOT ignore — the whole
	// layer rests on the file being untracked, so a not-ignored store is one
	// `git add -A` from committing the very patterns it exists to keep out of
	// history. The read path surfaces it (AddPrivate refuses outright); it is only
	// meaningful when the store is Present and inside a git repo.
	NotIgnored bool `json:"not_ignored"`
	// Reach is the one-sentence statement of what the private layer does and does
	// not protect (PrivateReachNote), carried on the report unconditionally. It is
	// on the struct rather than added by a renderer so a surface that only
	// summarises the JSON can relay the caveat verbatim rather than paraphrase a
	// reach that CI cannot enforce — matching the ahoy status board, which carries
	// the same note as `banlist.reach`.
	Reach string `json:"reach"`
}

PrivateReport is the private layer's state.

func ListPrivate

func ListPrivate(repoRoot string) (PrivateReport, error)

ListPrivate reports the private layer: its format, its keys, the lines the enforcement engine cannot use, the lines it accepts but reads differently, and whether this machine has opted in at all.

type PrivateResult

type PrivateResult struct {
	Path    string `json:"path"`
	Key     string `json:"key"`
	Entries int    `json:"entries"`
}

PrivateResult is the outcome of a private-layer mutation.

func AddPrivate

func AddPrivate(req AddPrivateRequest) (PrivateResult, error)

AddPrivate appends one entry, creating the store (and the local tier directory) when absent. Every check happens before the write, and the load-modify-write runs under the store's lock so a concurrent add or an out-of-band refresh cannot drop an entry.

func RemovePrivate

func RemovePrivate(repoRoot, key string) (PrivateResult, error)

RemovePrivate drops the entry with the given key. The edit is a line deletion — every other byte of the store survives, so comments and alignment are preserved.

type PrivateSummary

type PrivateSummary struct {
	// Present distinguishes "this machine has not opted in" from "opted in with no
	// entries" — the two check exactly as much, and both must be visible as distinct.
	Present bool `json:"present"`
	// Keyed reports the declared format, which decides what every line means.
	Keyed bool `json:"keyed"`
	// Entries counts the lines a reader can use. Unparsed counts the rest — the
	// guard refuses every commit while any exists.
	Entries  int `json:"entries"`
	Unparsed int `json:"unparsed"`
}

PrivateSummary is the private layer's SHAPE without its content: what a status board may say about it. Every field is non-secret by construction — a count, a format flag, and git's ignore verdict — and there is no way to reach a pattern from here.

It exists because ListPrivate is a diagnostic, not a status: ListPrivate asks the ENFORCEMENT engine about every entry, which is one grep subprocess per line. That is the right price for `abcd banlist list --private` during an incident and the wrong one for a detection pass that runs on every `abcd ahoy` and on the session hooks. The parser is shared, so the two cannot disagree about what an entry is; only the engine question is skipped, and Unparsed therefore counts lines that do not PARSE, not lines grep would refuse.

func SummarisePrivate

func SummarisePrivate(repoRoot string) (PrivateSummary, error)

SummarisePrivate reports the private layer's shape for a status surface. An absent store is a zero-value summary and NO error: not opting in is a state, not a fault. A store that cannot be read for what it is — a damaged declaration, an unreadable file — is an error, because a status board must not render it as healthy.

It asks git NOTHING. The ignore question belongs to the caller, which is usually asking it about several paths at once and can batch them into one subprocess; a summariser that spawned its own would multiply forks across a detection pass that runs on every status render.

type PublicEntry

type PublicEntry struct {
	ID       string `json:"id"`
	Pattern  string `json:"pattern"`
	Severity string `json:"severity"`
	// Key is the id with the managed prefix stripped, empty for an entry outside
	// the verb-owned namespace.
	Key string `json:"key"`
	// Managed marks the entries these verbs own and may remove.
	Managed bool `json:"managed"`
}

PublicEntry is one entry of the public banned-token family. Public entries render IN FULL: they are committed, reviewable config, and the pattern is the reviewable part (AC6).

type PublicReport

type PublicReport struct {
	Path    string        `json:"path"`
	Present bool          `json:"present"`
	Entries []PublicEntry `json:"entries"`
}

PublicReport is the public layer's state.

func ListPublic

func ListPublic(repoRoot string) (PublicReport, error)

ListPublic reports the whole banned_tokens family — the hand-curated entries as well as the verb-managed ones. There is one primitive, so a list that hid the hand-curated half would misrepresent what gates the repo.

type PublicResult

type PublicResult struct {
	Path  string      `json:"path"`
	Entry PublicEntry `json:"entry"`
}

PublicResult is the outcome of a public-layer mutation.

func AddPublic

func AddPublic(req AddPublicRequest) (PublicResult, error)

AddPublic inserts one entry into the banned_tokens family. The edit is byte surgery on the located array — one inserted line — so unrelated keys, entry order, and the file's formatting survive byte-for-byte and a review diff shows only the new entry.

func RemovePublic

func RemovePublic(repoRoot, key string) (PublicResult, error)

RemovePublic drops the verb-managed entry with the given key. Entries outside the managed namespace are refused: the hand-curated families are edited in the config by a human, in a reviewable commit, never by a verb.

type Report

type Report struct {
	Private PrivateReport `json:"private"`
	Public  PublicReport  `json:"public"`
}

Report is both layers at once, for the read-only render.

func List

func List(repoRoot string) (Report, error)

List reports both layers. It is the read-only status render's single call.

Jump to

Keyboard shortcuts

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