registry

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 19 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 registry loads and validates the provider, surface and spend registries (YAML validated by JSON Schema) from the embedded snapshot or a refreshed copy.

Registry YAML is the only source of patterns, verify requests and links: there are no provider-specific code paths. Load validates a registry file system and reports every problem as "registry/<file>:<line>: <field>: <message>"; Default serves the snapshot embedded in the binary. Lookups return copies and iterate in id order.

Index

Constants

View Source
const (

	// SpendMetered is the default spend kind: model or API spend priced per unit.
	SpendMetered = "metered"
	// SpendDataAccess marks providers with no metered model spend; they price at zero.
	SpendDataAccess = "data-access"

	// LimitTokens and LimitRequests are the limit units a tier may use.
	LimitTokens   = "tokens"
	LimitRequests = "requests"
)

Paths and kinds of the spend registry.

View Source
const (
	ParseJSON         = "json"
	ParseJSONC        = "jsonc"
	ParseTOML         = "toml"
	ParseYAML         = "yaml"
	ParseINI          = "ini"
	ParseDotenv       = "dotenv"
	ParseShellHistory = "shell-history"
	ParseJSONL        = "jsonl"
	ParseIPYNB        = "ipynb"
)

Parse formats a surface entry may name. Go parsers exist for some of them only; the surface source skips the others with a warning.

View Source
const (
	// CodeEntrySkipped marks a registry file that was skipped while the rest of the
	// snapshot loaded.
	CodeEntrySkipped = model.CodeRegistryEntrySkipped

	// DetailUnknownAuthScheme: the file names a verify auth scheme this binary does
	// not implement.
	DetailUnknownAuthScheme = "unknown_auth_scheme"
)

Warning codes and detail codes. Warnings carry codes and a location only (AD-3): no error text and no file content.

View Source
const (

	// DetailUnknownParseFormat: the file names a parse format this binary does not
	// know, so the surface is skipped.
	DetailUnknownParseFormat = "unknown_parse_format"
)

Paths of the surface registry.

View Source
const SchemaVersion = 1

SchemaVersion is the registry schema version this binary reads.

Variables

View Source
var TemplateLabel = regexp.MustCompile(`^[a-z0-9-]{1,63}$`)

TemplateLabel is the constraint on any value filling a verify URL placeholder: one lowercase DNS label. It equals the schema's $defs.template_label pattern.

Functions

func AuthSchemes

func AuthSchemes() []string

AuthSchemes returns the implemented verify auth schemes, sorted.

func Default

func Default() (*Registry, []Warning, error)

Default returns the registry embedded in the binary. It is loaded and validated once; later calls return the same Registry and a copy of the warnings.

func Load

func Load(fsys fs.FS) (*Registry, []Warning, error)

Load reads and validates a registry file system laid out like the registry directory: snapshot.yaml, schema/provider.json and providers/*.yaml. Files whose names start with "_" or "." are ignored.

Any invalid file fails the load with a *LoadError listing every issue as "registry/<path>:<line>: <field>: <message>". A provider file naming a verify auth scheme this binary does not implement is skipped with a Warning instead, and the rest of the snapshot loads.

func ParseFormats

func ParseFormats() []string

ParseFormats returns the parse formats of the surface schema, sorted.

func ValidLabel

func ValidLabel(s string) bool

ValidLabel reports whether s may fill a verify URL placeholder.

Types

type Auth

type Auth struct {
	Scheme string `json:"scheme"`
	// Name is the header or query parameter name for the header and query schemes.
	Name string `json:"name,omitempty"`
}

Auth says how the key is attached to the verify request.

type Cents

type Cents int64

Cents is an amount of US dollars kept as integer cents, so spend maths never touches a float. It is read from the number as written ("15.00", "0.5").

func (Cents) Float

func (c Cents) Float() float64

Float returns c in dollars. Use it only at the boundary to model.USD; spend maths stays in integer cents.

func (Cents) MarshalJSON

func (c Cents) MarshalJSON() ([]byte, error)

MarshalJSON marshals c as a number with exactly two decimals.

func (Cents) String

func (c Cents) String() string

String formats c as dollars with two decimals, for example "15.00".

func (*Cents) UnmarshalJSON

func (c *Cents) UnmarshalJSON(b []byte) error

UnmarshalJSON reads a JSON number exactly. Anything with more than two decimals, a negative sign or an exponent that does not resolve to whole cents is an error.

type Credential

type Credential struct {
	Parts   []CredentialPart `json:"parts"`
	Pairing string           `json:"pairing,omitempty"`
}

Credential declares a multi-part credential. Without it a key is a single part.

type CredentialPart

type CredentialPart struct {
	Name    string `json:"name"`
	Pattern string `json:"pattern"`
}

CredentialPart names one part of a credential and the pattern that finds it.

type Detector

type Detector struct {
	ID       string  `json:"id"`
	Provider string  `json:"provider"`
	Pattern  Pattern `json:"pattern"`
	// contains filtered or unexported fields
}

Detector is one pattern of one provider, identified as "<provider>.<pattern>".

func (Detector) FindAllSubmatchIndex

func (d Detector) FindAllSubmatchIndex(b []byte, n int) [][]int

FindAllSubmatchIndex returns the match and submatch offsets of up to n matches in b (all matches when n < 0), as regexp.Regexp.FindAllSubmatchIndex does.

func (Detector) MatchString

func (d Detector) MatchString(s string) bool

MatchString reports whether s contains a match of the detector's regex.

type Entropy

type Entropy struct {
	Min float64 `json:"min"`
}

Entropy is the minimum Shannon entropy, in bits per character, of a match.

type Extract

type Extract struct {
	Tier    *Extractor `json:"tier,omitempty"`
	Org     *Extractor `json:"org,omitempty"`
	Project *Extractor `json:"project,omitempty"`
	Scopes  *Extractor `json:"scopes,omitempty"`
	Limits  *Extractor `json:"limits,omitempty"`
}

Extract lists where evidence is read from a live response.

type Extractor

type Extractor struct {
	JSONPath string `json:"json_path,omitempty"`
	Header   string `json:"header,omitempty"`
}

Extractor reads one value from a JSON path or a response header.

type Issue

type Issue = yamlschema.Issue

Issue is one registry validation problem, printed as "file:line: field: message". Messages are written by this package and internal/yamlschema; they never contain foreign error text.

type LoadError

type LoadError struct {
	Issues []Issue
}

LoadError is returned by Load when any registry file is invalid. It lists every issue found, sorted by file, line and field.

func (*LoadError) Error

func (e *LoadError) Error() string

Error returns one "file:line: field: message" line per issue.

type Matcher

type Matcher struct {
	Status []int `json:"status"`
}

Matcher classifies a verify response.

type Pattern

type Pattern struct {
	Name       string   `json:"name"`
	Regex      string   `json:"regex"`
	Confidence string   `json:"confidence"`
	Prefix     string   `json:"prefix,omitempty"`
	Keywords   []string `json:"keywords,omitempty"`
	// RequiresKeywords drops a match that has no keyword context (a keyword on the
	// match line or an adjacent line). For prefix-less formats.
	RequiresKeywords bool        `json:"requires_keywords,omitempty"`
	Entropy          *Entropy    `json:"entropy,omitempty"`
	SecretGroup      int         `json:"secret_group,omitempty"`
	TestMarker       *TestMarker `json:"test_marker,omitempty"`
	NegativeExamples []string    `json:"negative_examples,omitempty"`
	Deprecated       bool        `json:"deprecated,omitempty"`
	// Verify, when set, replaces the provider verify block for this pattern.
	Verify *Verify `json:"verify,omitempty"`
}

Pattern is one key shape of a provider.

type Provider

type Provider struct {
	ID         string      `json:"id"`
	Name       string      `json:"name"`
	Aliases    []string    `json:"aliases,omitempty"`
	Deprecated bool        `json:"deprecated,omitempty"`
	DocsURL    string      `json:"docs_url"`
	RevokeURL  string      `json:"revoke_url"`
	RotateDoc  string      `json:"rotate_doc"`
	UsageURL   string      `json:"usage_url"`
	Credential *Credential `json:"credential,omitempty"`
	// Patterns keep the order of the YAML file.
	Patterns []Pattern `json:"patterns"`
	Verify   *Verify   `json:"verify,omitempty"`
	// Source is the file the provider was loaded from, for example
	// "registry/providers/openai.yaml".
	Source string `json:"-"`
}

Provider is one provider registry entry. Values returned by a Registry are deep copies: changing them never changes the Registry.

func (Provider) Part

func (p Provider) Part(pattern string) (index int, ok bool)

Part returns the index, in declared order, of the credential part found by the named pattern. ok is false for a provider without a credential block or a pattern that is not a part.

func (Provider) PlaceholderPart

func (p Provider) PlaceholderPart(part string) bool

PlaceholderPart reports whether the credential part named part fills a placeholder of the verify URL of the credential's primary pattern (the first part). Detect discards such a part when its value fails ValidLabel.

func (Provider) VerifyFor

func (p Provider) VerifyFor(pattern string) *Verify

VerifyFor returns a copy of the verify block that applies to the named pattern: the pattern's own block, else the provider's. It returns nil when neither exists.

type Rate

type Rate struct {
	PerSecond float64 `json:"per_second,omitempty"`
	Burst     int     `json:"burst,omitempty"`
}

Rate is a per-provider verify rate limit.

type Registry

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

Registry is a loaded, validated registry snapshot. It is immutable and safe for concurrent use; every lookup returns a copy.

func (*Registry) Detector

func (r *Registry) Detector(id string) (Detector, bool)

Detector returns the detector "<provider>.<pattern>". A provider alias also resolves: "<alias>.<pattern>" returns the current detector.

func (*Registry) Detectors

func (r *Registry) Detectors() []Detector

Detectors returns every detector, sorted by id.

func (*Registry) Provider

func (r *Registry) Provider(id string) (Provider, bool)

Provider returns the provider with the given id or alias.

func (*Registry) Providers

func (r *Registry) Providers() []Provider

Providers returns every provider, sorted by id.

func (*Registry) Snapshot

func (r *Registry) Snapshot() Snapshot

Snapshot returns the snapshot stamp.

func (*Registry) Spend

func (r *Registry) Spend(provider string) (Spend, bool)

Spend returns the spend entry of a provider id or alias.

func (*Registry) SpendEntries

func (r *Registry) SpendEntries() []Spend

SpendEntries returns every spend entry, sorted by provider id.

func (*Registry) Surface

func (r *Registry) Surface(id string) (Surface, bool)

Surface returns the surface with the given id.

func (*Registry) Surfaces

func (r *Registry) Surfaces() []Surface

Surfaces returns every surface, sorted by id.

type Snapshot

type Snapshot struct {
	// Version stamps the registry data, for example "2026.11.13".
	Version string `json:"snapshot_version"`
	// SchemaVersion is the registry schema the snapshot targets.
	SchemaVersion int `json:"schema_version"`
	// MinBinaryVersion is the oldest TokenHound release that can read the snapshot.
	// Exposed only; enforced by registry refresh.
	MinBinaryVersion string `json:"min_binary_version"`
}

Snapshot describes the loaded registry snapshot (registry/snapshot.yaml).

type Spend

type Spend struct {
	Provider  string `json:"provider"`
	AsOf      string `json:"as_of"`
	SourceURL string `json:"source_url"`
	// SpendKind is "metered" or "data-access"; empty means metered.
	SpendKind      string      `json:"spend_kind,omitempty"`
	DataAccessNote string      `json:"data_access_note,omitempty"`
	DefaultTier    string      `json:"default_tier"`
	Tiers          []SpendTier `json:"tiers"`
	// Source is the file the entry was loaded from.
	Source string `json:"-"`
}

Spend is one provider's spend registry file (registry/spend/<provider>.yaml).

func (Spend) Kind

func (s Spend) Kind() string

Kind returns the spend kind, "metered" when unset.

func (Spend) Tier

func (s Spend) Tier(id string) (SpendTier, bool)

Tier returns the tier with the given id.

type SpendTier

type SpendTier struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	LimitPerMin int64  `json:"limit_per_min"`
	LimitUnit   string `json:"limit_unit"`
	// Model is the most expensive model reachable on the tier.
	Model string `json:"model"`
	// UnitPriceUSD is the price of PriceUnitSize limit units.
	UnitPriceUSD Cents `json:"unit_price_usd"`
	// PriceUnitSize is how many limit units UnitPriceUSD buys; 0 means 1.
	PriceUnitSize     int64  `json:"price_unit_size,omitempty"`
	SpendCapUSDPerDay *Cents `json:"spend_cap_usd_per_day,omitempty"`
}

SpendTier is one rate limit tier of a provider.

func (SpendTier) UnitSize

func (t SpendTier) UnitSize() int64

UnitSize returns the number of limit units the tier price covers (at least 1).

type Surface

type Surface struct {
	ID    string       `json:"id"`
	Name  string       `json:"name"`
	Paths SurfacePaths `json:"paths"`
	// Parse is the file format, one of the Parse* constants.
	Parse string `json:"parse"`
	// Fields are the selectors naming the values that can hold a key.
	Fields        []string `json:"fields"`
	DocsURL       string   `json:"docs_url"`
	Note          string   `json:"note,omitempty"`
	TestedVersion string   `json:"tested_version,omitempty"`
	// Source is the file the entry was loaded from.
	Source string `json:"-"`
}

Surface is one agent surface registry entry (registry/surfaces/<id>.yaml). Values returned by a Registry are deep copies.

type SurfacePaths

type SurfacePaths struct {
	MacOS   []string `json:"macos"`
	Linux   []string `json:"linux"`
	Windows []string `json:"windows"`
}

SurfacePaths are the file patterns of a surface per operating system.

func (SurfacePaths) For

func (p SurfacePaths) For(goos string) []string

For returns the patterns of a GOOS value ("darwin", "linux" or "windows"); any other value gives the Linux patterns.

type TestMarker

type TestMarker struct {
	// Position is "start" or "end" (default "end").
	Position string `json:"position,omitempty"`
	// Encoding is "plain" or "hex" (default "plain").
	Encoding string `json:"encoding,omitempty"`
}

TestMarker tells the test key generator where to put the TOKENHOUNDTEST marker.

type Verify

type Verify struct {
	Method string `json:"method"`
	// URL is a literal https URL or a template whose first host label is one
	// placeholder naming a credential part, for example
	// "https://<resource>.openai.azure.com/openai/models".
	URL string `json:"url"`
	// HostSuffixes are the host suffixes a templated URL may resolve to.
	HostSuffixes []string          `json:"host_suffixes,omitempty"`
	Auth         Auth              `json:"auth"`
	Headers      map[string]string `json:"headers,omitempty"`
	LiveWhen     Matcher           `json:"live_when"`
	DeadWhen     Matcher           `json:"dead_when"`
	Extract      *Extract          `json:"extract,omitempty"`
	Rate         *Rate             `json:"rate,omitempty"`
	ReadOnly     bool              `json:"read_only,omitempty"`
	ReadOnlyNote string            `json:"read_only_note,omitempty"`
}

Verify is the read-only request that tells a live key from a dead one.

func (Verify) Expand

func (v Verify) Expand(values map[string]string) (string, bool)

Expand fills every placeholder of the URL from values. It returns false unless every placeholder has a value that passes ValidLabel. A literal URL expands to itself.

func (Verify) HostPatterns

func (v Verify) HostPatterns() []string

HostPatterns returns the hosts the verify request may go to, in the netx allowlist form: the literal host of a literal URL, or "*.<suffix>" for each host suffix of a templated URL.

func (Verify) Placeholders

func (v Verify) Placeholders() []string

Placeholders returns the placeholder names of the URL ("resource" for "https://<resource>.openai.azure.com/"), in order of appearance.

type Warning

type Warning = model.Warning

Warning is a non-fatal loader finding in the AD-3 shape {code, location, detail_code}: the report model's warning.

Jump to

Keyboard shortcuts

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