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
- Variables
- func AuthSchemes() []string
- func Default() (*Registry, []Warning, error)
- func Load(fsys fs.FS) (*Registry, []Warning, error)
- func ParseFormats() []string
- func ValidLabel(s string) bool
- type Auth
- type Cents
- type Credential
- type CredentialPart
- type Detector
- type Entropy
- type Extract
- type Extractor
- type Issue
- type LoadError
- type Matcher
- type Pattern
- type Provider
- type Rate
- type Registry
- func (r *Registry) Detector(id string) (Detector, bool)
- func (r *Registry) Detectors() []Detector
- func (r *Registry) Provider(id string) (Provider, bool)
- func (r *Registry) Providers() []Provider
- func (r *Registry) Snapshot() Snapshot
- func (r *Registry) Spend(provider string) (Spend, bool)
- func (r *Registry) SpendEntries() []Spend
- func (r *Registry) Surface(id string) (Surface, bool)
- func (r *Registry) Surfaces() []Surface
- type Snapshot
- type SnapshotLinks
- type Spend
- type SpendTier
- type Surface
- type SurfacePaths
- type TestMarker
- type Verify
- type Warning
Constants ¶
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.
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.
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.
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.
const SchemaVersion = 1
SchemaVersion is the registry schema version this binary reads.
Variables ¶
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 ¶
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 ¶
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 ¶
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 ¶
Float returns c in dollars. Use it only at the boundary to model.USD; spend maths stays in integer cents.
func (Cents) MarshalJSON ¶
MarshalJSON marshals c as a number with exactly two decimals.
func (*Cents) UnmarshalJSON ¶
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 ¶
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 ¶
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 ¶
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.
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"`
// EnvVars are the conventional environment variable names of the key, one per
// credential part in part order for a multi-part credential; empty when the
// provider has no convention.
EnvVars []string `json:"env_vars,omitempty"`
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 ¶
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 ¶
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.
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 ¶
Detector returns the detector "<provider>.<pattern>". A provider alias also resolves: "<alias>.<pattern>" returns the current detector.
func (*Registry) SpendEntries ¶
SpendEntries returns every spend entry, sorted by provider 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"`
// Links are project links shown to users, for example in fix plans.
Links SnapshotLinks `json:"links"`
}
Snapshot describes the loaded registry snapshot (registry/snapshot.yaml).
type SnapshotLinks ¶ added in v0.2.0
type SnapshotLinks struct {
// ScopeKeeper is the https URL of ScopeKeeper, the last step of every fix plan.
ScopeKeeper string `json:"scopekeeper"`
}
SnapshotLinks are the project links of a snapshot. They are registry data, so a maintainer can change them without a release.
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).
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.
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 ¶
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 ¶
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 ¶
Placeholders returns the placeholder names of the URL ("resource" for "https://<resource>.openai.azure.com/"), in order of appearance.