Documentation
¶
Overview ¶
Package tpacorpus builds the embedded TPA signature bundle from per-signature sources and enforces the corpus policy (spec 101 US2): provenance, licence allowlist, class vocabulary and the eval pair every gating signature owes.
The load-time integrity checks (referential integrity, gating derivation) live in the scanner package so operators can still load private corpora; the checks here run at build and in CI only.
Index ¶
Constants ¶
const ManifestFile = "manifest.json"
ManifestFile is the builder's per-corpus settings file inside the source tree.
Variables ¶
var Classes = []string{
"tpa_hidden_instruction_block",
"tpa_comment_directive",
"tpa_tool_shadowing",
"tpa_cross_server_override",
"tpa_exfil_redirect",
"tpa_sensitive_file_coaxing",
"tpa_credential_harvesting",
"tpa_persistence_implant",
"tpa_rug_pull_phrasing",
"tpa_instruction_override",
"tpa_conversation_exfil",
"tpa_preference_manipulation",
"tpa_concealment_directive",
"tpa_invisible_text",
"tpa_payload_execution",
"tpa_schema_injection",
}
Classes is the signature class vocabulary: the value of signatures[].category and the suffix of the eval dataset's hard-negative id prefix hn_<class>_. No class may be a prefix of another, or hn_<class>_ prefixes would collide.
tpa_persistence_implant holds the deterministic negative control (spec 101 D-US2-7): the gate must breach when its control signature is removed.
var LicenceAllowlist = []string{"CC0-1.0", "CC-BY-4.0", "MIT", "Apache-2.0"}
LicenceAllowlist is the set of SPDX ids a signature may carry (FR-012). CC-BY-SA-4.0 is deliberately absent: its share-alike terms could attach to the MIT-licensed binary that embeds the corpus.
Functions ¶
func Build ¶
Build compiles a source tree (manifest.json plus one TPA-YYYY-NNNN.json per signature) into the bundle bytes. The output is deterministic: rules[] sort by (id, detector), signatures[] by id, object keys alphabetically, and generated_at comes from a pinned epoch, never the wall clock. It refuses signatures without provenance or with a licence outside the allowlist or an unknown class, and the result must pass the production loader.
func HardNegativePrefix ¶
HardNegativePrefix is the id prefix hard negatives of a class must carry.
func ValidatePolicy ¶
ValidatePolicy checks a built bundle against the eval dataset (spec 101 D-US2-3, policy layer). It reports every violation at once:
- the bundle has a non-empty signatures[] section (the runtime loader stays lenient about legacy bundles without one; the shipped corpus may not);
- the class vocabulary has no prefix collisions, and every signature uses a known class and an allowlisted licence;
- every dataset tpa_id resolves to a signature and its entry is a malicious sample of that signature's class;
- every gating signature has at least one such malicious sample;
- every class with a gating signature has at least one hard negative (id hn_<class>_*, category hard_negative, resembles == class) and exactly one canonical sample.
Whether the gate scores a class (categoryCheck) is closed by a scan-eval test, because categoryCheck lives in that package.
Types ¶
type Options ¶
type Options struct {
// Exclude drops the named signatures (and their rules and skipped entries)
// from the output; signature_count is recomputed. Used by the gate's negative
// control. An id that matches no source is an error.
Exclude []string
// SourceDateEpoch, when set, overrides the manifest's source_date_epoch pin
// (the CLI feeds the SOURCE_DATE_EPOCH environment variable through here).
// The build never reads the wall clock.
SourceDateEpoch *int64
}
Options tune a build.