Documentation
¶
Overview ¶
Package genes provides an OPTIONAL, file-based "crystallized logic" extension for learned Datalog rules — genes — that are applied to the policy engine through its official source channel (sdk.Client.LoadPolicy).
Design guardrails (ADR-003):
- This package is an extension: core, sdk, and adapters never import it.
- A gene NEVER enters the enforcement path via an interface hook (the old genome parameter is gone). Applying a gene means compiling it to Datalog source and loading it as policy — auditable, diffable, reloadable, rollback-able like any other policy change.
- Integrity: gene rules are SHA-256 signed over their canonical form; compilation refuses tampered or unsigned genes by default.
- Promotion: genes carrying hard tiers (T0/T1, which can BLOCK) are refused unless the caller passes WithAllowHardTiers — modeling the human-review step that promotes learned (advisory T2/T3) rules into governance. Advisory rules follow the tier semantics of the gate (see docs/context/governance/datalog-policies.md).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyTo ¶
ApplyTo compiles the given genes and loads them into the client's policy program via the official source channel (Client.LoadPolicy — additive, auto-merges std.dl Decls where needed). Nothing is applied unless the whole compiled program passes every check; on error the client's policy is unchanged for genes that failed (load happens after full compilation).
Note: compiled genes belong to the USER program — a later ReloadPolicy/ReloadPolicySource replaces them (see the runtime's persistent units for engine builtins). Persist the gene manifest as the source of truth and re-apply after reloads, or bake the genes into the policy file.
func Compile ¶
func Compile(genes []Gene, opts ...CompileOption) (string, error)
Compile renders genes into a single self-contained Datalog program that can be loaded through the policy channel (sdk.Client.LoadPolicy / ReloadPolicySource). Each gene is signature-verified first; hard tiers require WithAllowHardTiers (see CompileOptions).
Compile does NOT rewrite rule text — gene rules carry their own halt/3 tiers and must be consistent with the declared gene tier. A mismatch (e.g. a T2 gene whose rules emit halt(..., "T1")) is rejected: the compiler refuses to be the place where tiers silently disagree.
Types ¶
type CompileOption ¶
type CompileOption func(*CompileOptions)
CompileOption mutates CompileOptions.
func WithAllowHardTiers ¶
func WithAllowHardTiers() CompileOption
WithAllowHardTiers allows T0/T1 genes through the compiler.
type CompileOptions ¶
type CompileOptions struct {
// AllowHardTiers permits genes carrying blocking tiers (T0/T1) to be
// compiled. Without it, compilation refuses them — the explicit opt-in
// models human review promoting learned rules into governance.
AllowHardTiers bool
}
CompileOptions controls the promotion discipline applied to genes.
type Gene ¶
type Gene struct {
// Name uniquely identifies the gene within a manifest.
Name string `yaml:"name"`
// Tier is the governance tier the gene's rules are meant to carry
// (core.TierT0_Axiom..TierT3_User). Hard tiers require explicit opt-in
// at compile time (WithAllowHardTiers).
Tier core.Tier `yaml:"tier"`
// Source documents provenance, e.g. "mkit gen 2026-09-09, review #12".
Source string `yaml:"source"`
// Intents the gene applies to; empty means "all intents".
Intents []string `yaml:"intents"`
// Rules is self-contained Datalog source (facts and/or rules).
Rules string `yaml:"rules"`
// Signature is the SHA-256 over the canonical form (see Sign).
Signature [32]byte `yaml:"-"`
// Signed records whether a signature was produced/verified.
Signed bool `yaml:"-"`
}
Gene is a signed unit of Datalog logic with tiered governance intent.
func (*Gene) SetSignatureHex ¶
SetSignatureHex parses a hex signature into the gene.
func (Gene) SignatureHex ¶
SignatureHex returns the hex-encoded signature (manifest representation).
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is an immutable, signature-verified set of genes.
func LoadPoolFile ¶
LoadPoolFile reads and validates a YAML manifest from path. Every gene must be present, signed, and signature-intact — a corrupted pool fails closed.