cortex

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package cortex provides content-aware gate system (Claw Compactor's Cortex detection).

Package cortex provides content-aware gate system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ASTProcessor

type ASTProcessor struct{}

ASTProcessor preserves AST structure.

func (*ASTProcessor) Name

func (p *ASTProcessor) Name() string

func (*ASTProcessor) Process

func (p *ASTProcessor) Process(content string) (string, int)

type AlwaysCondition

type AlwaysCondition struct{}

AlwaysCondition always matches.

func (AlwaysCondition) Match

func (c AlwaysCondition) Match(content string, detection DetectionResult) bool

type AnyCondition

type AnyCondition struct {
	Conditions []GateCondition
}

AnyCondition combines conditions with OR logic.

func (AnyCondition) Match

func (c AnyCondition) Match(content string, detection DetectionResult) bool

Match implements GateCondition.

type BudgetProcessor

type BudgetProcessor struct{}

BudgetProcessor enforces token budget.

func (*BudgetProcessor) Name

func (p *BudgetProcessor) Name() string

func (*BudgetProcessor) Process

func (p *BudgetProcessor) Process(content string) (string, int)

type CompositeCondition

type CompositeCondition struct {
	Conditions []GateCondition
}

CompositeCondition combines multiple conditions with AND logic.

func (CompositeCondition) Match

func (c CompositeCondition) Match(content string, detection DetectionResult) bool

Match implements GateCondition.

type ContentStats

type ContentStats struct {
	TotalLines    int
	TotalChars    int
	NonEmptyLines int
	CommentLines  int
	CodeLines     int
	BlankLines    int
	AvgLineLength float64
	HasAnsiCodes  bool
	HasUnicode    bool
	Entropy       float64
}

ContentStats provides statistics about the content.

type ContentType

type ContentType int

ContentType represents the detected content type.

const (
	Unknown ContentType = iota
	SourceCode
	BuildLog
	TestOutput
	StructuredData
	NaturalLanguage
	BinaryData
)

func (ContentType) String

func (c ContentType) String() string

type ContentTypeCondition

type ContentTypeCondition struct {
	Types []ContentType
}

ContentTypeCondition matches by content type.

func (ContentTypeCondition) Match

func (c ContentTypeCondition) Match(content string, detection DetectionResult) bool

Match implements GateCondition.

type ContrastiveProcessor

type ContrastiveProcessor struct{}

ContrastiveProcessor uses contrastive learning.

func (*ContrastiveProcessor) Name

func (p *ContrastiveProcessor) Name() string

func (*ContrastiveProcessor) Process

func (p *ContrastiveProcessor) Process(content string) (string, int)

type DetectionResult

type DetectionResult struct {
	ContentType ContentType
	Language    Language
	Confidence  float64
	Features    map[string]bool
	Stats       ContentStats
}

DetectionResult contains content detection results.

type Detector

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

Detector provides content type detection.

func NewDetector

func NewDetector() *Detector

NewDetector creates a new content detector.

func (*Detector) Detect

func (d *Detector) Detect(content string) DetectionResult

Detect analyzes content and returns detection results.

func (*Detector) DetectFile

func (d *Detector) DetectFile(path string, content string) DetectionResult

DetectFile analyzes a file and returns detection results.

type EntropyProcessor

type EntropyProcessor struct{}

EntropyProcessor reduces high-entropy content.

func (*EntropyProcessor) Name

func (p *EntropyProcessor) Name() string

func (*EntropyProcessor) Process

func (p *EntropyProcessor) Process(content string) (string, int)

type FeatureCondition

type FeatureCondition struct {
	Features map[string]bool
}

FeatureCondition matches by content features.

func (FeatureCondition) Match

func (c FeatureCondition) Match(content string, detection DetectionResult) bool

Match implements GateCondition.

type Gate

type Gate interface {
	// ShouldApply returns true if the layer should be applied.
	ShouldApply(content string, detection DetectionResult) bool
	// Priority returns the gate priority (lower = higher priority).
	Priority() int
	// Name returns the gate name.
	Name() string
}

Gate determines if a layer should be applied to content.

type GateCondition

type GateCondition interface {
	Match(content string, detection DetectionResult) bool
}

GateCondition determines if content matches criteria.

type GateRegistry

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

GateRegistry manages all layer gates.

func NewGateRegistry

func NewGateRegistry() *GateRegistry

NewGateRegistry creates a new gate registry.

func (*GateRegistry) Analyze

func (r *GateRegistry) Analyze(content string) DetectionResult

Analyze returns detection info without processing.

func (*GateRegistry) ApplyGates

func (r *GateRegistry) ApplyGates(content string) (string, int)

ApplyGates runs applicable gates on content and returns processed result.

func (*GateRegistry) GetApplicableGates

func (r *GateRegistry) GetApplicableGates(content string) []string

GetApplicableGates returns list of gates that apply to content.

func (*GateRegistry) Register

func (r *GateRegistry) Register(gate Gate)

Register adds a gate to the registry.

type GistProcessor

type GistProcessor struct{}

GistProcessor creates content gists.

func (*GistProcessor) Name

func (p *GistProcessor) Name() string

func (*GistProcessor) Process

func (p *GistProcessor) Process(content string) (string, int)

type GoalDrivenProcessor

type GoalDrivenProcessor struct{}

GoalDrivenProcessor analyzes query intent.

func (*GoalDrivenProcessor) Name

func (p *GoalDrivenProcessor) Name() string

func (*GoalDrivenProcessor) Process

func (p *GoalDrivenProcessor) Process(content string) (string, int)

type HierarchicalProcessor

type HierarchicalProcessor struct{}

HierarchicalProcessor creates summaries.

func (*HierarchicalProcessor) Name

func (p *HierarchicalProcessor) Name() string

func (*HierarchicalProcessor) Process

func (p *HierarchicalProcessor) Process(content string) (string, int)

type LLMEvalProcessor

type LLMEvalProcessor struct{}

LLMEvalProcessor uses LLM evaluation.

func (*LLMEvalProcessor) Name

func (p *LLMEvalProcessor) Name() string

func (*LLMEvalProcessor) Process

func (p *LLMEvalProcessor) Process(content string) (string, int)

type Language

type Language int

Language represents the detected programming language.

const (
	LangUnknown Language = iota
	LangGo
	LangRust
	LangPython
	LangJavaScript
	LangTypeScript
	LangJava
	LangC
	LangCpp
	LangRuby
	LangShell
	LangSQL
	LangMarkdown
	LangJSON
	LangYAML
	LangXML
)

func (Language) String

func (l Language) String() string

type LanguageCondition

type LanguageCondition struct {
	Languages []Language
}

LanguageCondition matches by programming language.

func (LanguageCondition) Match

func (c LanguageCondition) Match(content string, detection DetectionResult) bool

Match implements GateCondition.

type LayerGate

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

LayerGate is a gate for a specific compression layer.

func DefaultGates

func DefaultGates() []*LayerGate

DefaultGates returns the default set of layer gates.

func NewLayerGate

func NewLayerGate(name string, priority int, condition GateCondition, layer LayerProcessor) *LayerGate

NewLayerGate creates a new layer gate.

func (*LayerGate) Name

func (g *LayerGate) Name() string

Name implements Gate.

func (*LayerGate) Priority

func (g *LayerGate) Priority() int

Priority implements Gate.

func (*LayerGate) Process

func (g *LayerGate) Process(content string) (string, int)

Process applies the layer to content.

func (*LayerGate) ShouldApply

func (g *LayerGate) ShouldApply(content string, detection DetectionResult) bool

ShouldApply implements Gate.

type LayerProcessor

type LayerProcessor interface {
	Process(content string) (string, int)
	Name() string
}

LayerProcessor processes content for a layer.

type NgramProcessor

type NgramProcessor struct{}

NgramProcessor deduplicates n-grams.

func (*NgramProcessor) Name

func (p *NgramProcessor) Name() string

func (*NgramProcessor) Process

func (p *NgramProcessor) Process(content string) (string, int)

type NotCondition

type NotCondition struct {
	Condition GateCondition
}

NotCondition negates a condition.

func (NotCondition) Match

func (c NotCondition) Match(content string, detection DetectionResult) bool

Match implements GateCondition.

type PerplexityProcessor

type PerplexityProcessor struct{}

PerplexityProcessor filters low-perplexity content.

func (*PerplexityProcessor) Name

func (p *PerplexityProcessor) Name() string

func (*PerplexityProcessor) Process

func (p *PerplexityProcessor) Process(content string) (string, int)

type SizeCondition

type SizeCondition struct {
	MinLines  int
	MaxLines  int
	MinChars  int
	MaxChars  int
	MinTokens int
	MaxTokens int
}

SizeCondition matches by content size.

func (SizeCondition) Match

func (c SizeCondition) Match(content string, detection DetectionResult) bool

Match implements GateCondition.

Jump to

Keyboard shortcuts

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