kernel

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultEASTConfig = EASTConfig{
	EntropyThreshold: 0.7,
	ChaosThreshold:   0.9,
	SaliencyKeywords: []string{"production", "critical", "security"},
}
View Source
var DefaultTierConfig = TierConfig{
	SystemBudget:     2000,
	GovernanceBudget: 4000,
	PlaybookBudget:   8000,
	UserBudget:       6000,
}

Functions

func CalculateActivity

func CalculateActivity(accessCounts map[string]int) float64

CalculateActivity computes activity based on atom access patterns Hot atoms are frequently accessed, cold atoms are rarely used

func CalculateActivityPredicate

func CalculateActivityPredicate(ctx interface{}, inputs []interface{}) ([][]interface{}, error)

calculate_activity_predicate computes activity from access counts

func CalculateEntropy

func CalculateEntropy(conflicts int) float64

CalculateEntropy computes entropy based on conflict count High entropy = more contradictions in reasoning frame

func CalculateEntropyPredicate

func CalculateEntropyPredicate(ctx interface{}, inputs []interface{}) ([][]interface{}, error)

calculate_entropy_predicate is used to register calculate_entropy in the engine

func CalculateSaliency

func CalculateSaliency(input string, keywords []string) float64

CalculateSaliency determines if input contains high-priority keywords

func CalculateSaliencyPredicate

func CalculateSaliencyPredicate(ctx interface{}, inputs []interface{}) ([][]interface{}, error)

calculate_saliency_predicate checks for keyword matches

func EstimateTokens

func EstimateTokens(atoms []string) int

EstimateTokens estimates token count for atoms (simplified)

func LoadKernel

func LoadKernel() (string, error)

LoadKernel returns all embedded kernel rules concatenated

Types

type AtomScore

type AtomScore struct {
	Subject   string
	Predicate string
	Object    string
	Weight    float64
}

AtomScore holds an atom with its computed weight

func PruneCandidates

func PruneCandidates(atoms []AtomScore, threshold float64) []AtomScore

PruneCandidates returns atoms that should be pruned based on coldness and low weight

type AutoShaveConfig

type AutoShaveConfig struct {
	Enabled       bool
	Strategy      ShaveStrategy
	MinFreeBudget int // Minimum free space to maintain
}

AutoShaveConfig holds configuration for automatic context shaving

func DefaultAutoShaveConfig

func DefaultAutoShaveConfig() AutoShaveConfig

DefaultAutoShaveConfig returns the default auto-shave configuration

type Calculator

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

Calculator provides EAST calculation as a service

func NewEASTCalculator

func NewEASTCalculator() *Calculator

NewEASTCalculator creates a new EAST calculator with default config

func (*Calculator) Calculate

func (c *Calculator) Calculate(frame *EASTFrame) EASTMetrics

Calculate computes EAST metrics for a frame

func (*Calculator) FullAnalysis

func (c *Calculator) FullAnalysis(frame *EASTFrame) (EASTMetrics, PathType)

FullAnalysis returns both metrics and recommended path

func (*Calculator) GetPath

func (c *Calculator) GetPath(metrics EASTMetrics) PathType

GetPath returns the recommended cognitive path

func (*Calculator) WithConfig

func (c *Calculator) WithConfig(cfg EASTConfig) *Calculator

WithConfig sets custom configuration

type EASTConfig

type EASTConfig struct {
	EntropyThreshold float64
	ChaosThreshold   float64
	SaliencyKeywords []string
}

Config holds EAST calculation configuration

type EASTFrame

type EASTFrame struct {
	ConflictCount  int
	AccessCounts   map[string]int
	Input          string
	DecisionSource string
}

EASTFrame contains input data for EAST calculation

type EASTMetrics

type EASTMetrics struct {
	Entropy   float64
	Activity  float64
	Saliency  float64
	Trust     TierLevel
	Conflicts int
}

EASTMetrics contains the four cognitive steering metrics

func CalculateEAST

func CalculateEAST(frame *EASTFrame, cfg EASTConfig) EASTMetrics

CalculateEAST computes all four metrics and returns EASTMetrics

type KernelRules

type KernelRules struct {
	OODA       string
	Agents     string
	Patterns   string
	Validation string
}

KernelRules contains the embedded framework rules

func (*KernelRules) Combine

func (k *KernelRules) Combine() string

Combine concatenates all kernel rules

type Loader

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

Loader handles kernel + profile rule loading

func NewLoader

func NewLoader() (*Loader, error)

NewLoader creates a new kernel loader

func (*Loader) GetKernel

func (l *Loader) GetKernel() string

GetKernel returns the embedded kernel rules

func (*Loader) Merge

func (l *Loader) Merge(profile Profile) (string, error)

Merge combines kernel rules with profile rules Profile rules override kernel rules (last predicate wins)

type MemoryManager

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

MemoryManager handles automatic context shaving

func NewMemoryManager

func NewMemoryManager() *MemoryManager

NewMemoryManager creates a memory manager with defaults

func (*MemoryManager) SelectAtomsForPruning

func (m *MemoryManager) SelectAtomsForPruning(atoms map[Tier][]string, strategy ShaveStrategy) []string

SelectAtomsForPruning selects atoms to prune based on strategy

func (*MemoryManager) ShouldShave

func (m *MemoryManager) ShouldShave(ctx context.Context, stats MemoryStats) bool

ShouldShave determines if context needs pruning

func (*MemoryManager) WithAutoShave

func (m *MemoryManager) WithAutoShave(cfg AutoShaveConfig) *MemoryManager

WithAutoShave configures automatic shaving behavior

func (*MemoryManager) WithTierConfig

func (m *MemoryManager) WithTierConfig(cfg TierConfig) *MemoryManager

WithTierConfig sets custom tier configuration

type MemoryStats

type MemoryStats struct {
	SystemUsed     int
	GovernanceUsed int
	PlaybookUsed   int
	UserUsed       int
}

MemoryStats holds current memory usage per tier

func (MemoryStats) Usage

func (s MemoryStats) Usage() int

Usage returns total tokens used

type PathType

type PathType int

PathType determines whether to use fast or slow cognitive path

const (
	PathUnknown PathType = iota
	FastPath
	SlowPath
)

func DeterminePath

func DeterminePath(metrics EASTMetrics, cfg EASTConfig) PathType

DeterminePath decides fast vs slow cognitive path based on EAST metrics

func (PathType) String

func (p PathType) String() string

type Profile

type Profile struct {
	Name     string
	Rules    string
	Metadata map[string]string
}

Profile represents a security/business rules profile from Nexus

func DefaultProfile

func DefaultProfile() Profile

DefaultProfile returns a permissive default profile

type ShaveStrategy

type ShaveStrategy int

ShaveStrategy determines which atoms to prune first

const (
	ShaveUserFirst      ShaveStrategy = iota // Prune T3 before T2 before T1 before T0
	ShaveLowWeightFirst                      // Prune by atom weight regardless of tier
	ShaveOldestFirst                         // Prune by timestamp
)

type Tier

type Tier int
const (
	TierSystem Tier = iota
	TierGovernance
	TierPlaybook
	TierUser
)

func ClassifyAtom

func ClassifyAtom(atom string) Tier

ClassifyAtom determines the tier for a single atom

func MemoryTier

func MemoryTier(predicate string) Tier

MemoryTier determines which tier an atom belongs to

func (Tier) String

func (t Tier) String() string

type TierConfig

type TierConfig struct {
	SystemBudget     int // tokens for T0 (FP32 precision)
	GovernanceBudget int // tokens for T1 (FP32 precision)
	PlaybookBudget   int // tokens for T2 (INT8 precision)
	UserBudget       int // tokens for T3 (INT8 precision)
}

TierConfig holds memory budget per tier

func (TierConfig) TotalBudget

func (c TierConfig) TotalBudget() int

TotalBudget returns the total memory budget

type TierLevel

type TierLevel int
const (
	TierUnknown TierLevel = iota
	T0_Axiom
	T1_Governance
	T2_Playbook
	T3_User
)

func DetermineTrust

func DetermineTrust(decisionSource string) TierLevel

DetermineTrust assigns a tier level based on decision source

func (TierLevel) String

func (t TierLevel) String() string

type TierManager

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

TierManager handles memory allocation per tier

func NewTierManager

func NewTierManager() *TierManager

NewTierManager creates a tier manager with default config

func (*TierManager) ClassifyAtoms

func (m *TierManager) ClassifyAtoms(atoms []string) map[Tier][]string

ClassifyAtoms distributes atoms into tiers based on predicates

func (*TierManager) GetBudget

func (m *TierManager) GetBudget(tier Tier) int

GetBudget returns the budget for a given tier

func (*TierManager) IsWithinBudget

func (m *TierManager) IsWithinBudget(stats MemoryStats) bool

IsWithinBudget checks if current usage is within budget

func (*TierManager) PruneRequired

func (m *TierManager) PruneRequired(stats MemoryStats) map[Tier]int

PruneRequired returns how many tokens need to be pruned per tier

func (*TierManager) WithConfig

func (m *TierManager) WithConfig(cfg TierConfig) *TierManager

WithConfig sets custom tier configuration

Jump to

Keyboard shortcuts

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