genes

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 11 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 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

func ApplyTo(ctx context.Context, client *sdk.Client, genes []Gene, opts ...CompileOption) error

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.

func WritePool

func WritePool(w io.Writer, genes []Gene) error

WritePool serializes genes (each must be signed) to a manifest.

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

func (g *Gene) SetSignatureHex(s string) error

SetSignatureHex parses a hex signature into the gene.

func (*Gene) Sign

func (g *Gene) Sign()

Sign computes and attaches the integrity signature.

func (Gene) SignatureHex

func (g Gene) SignatureHex() string

SignatureHex returns the hex-encoded signature (manifest representation).

func (Gene) Verify

func (g Gene) Verify() error

Verify recomputes the signature over the current field values.

type Pool

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

Pool is an immutable, signature-verified set of genes.

func LoadPool

func LoadPool(r io.Reader) (*Pool, error)

LoadPool reads and validates a YAML manifest from r.

func LoadPoolFile

func LoadPoolFile(path string) (*Pool, error)

LoadPoolFile reads and validates a YAML manifest from path. Every gene must be present, signed, and signature-intact — a corrupted pool fails closed.

func (*Pool) Active

func (p *Pool) Active(intent string) []Gene

Active returns genes matching an intent (a gene with no Intents matches all).

func (*Pool) Genes

func (p *Pool) Genes() []Gene

Genes returns genes sorted by name (deterministic compile order).

Jump to

Keyboard shortcuts

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