compile

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

internal/compile/backend.go

internal/compile/llm.go

internal/compile/tiered.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildGraphWithIR added in v0.2.1

func BuildGraphWithIR(events []ingest.Event, matcher *ir.Matcher) *trace.TraceGraph

BuildGraphWithIR constructs a TraceGraph using IR matching for Bash commands.

func BuildPrompt

func BuildPrompt(promptTemplate string, cfg config.Config, globalSkillsDir string) string

BuildPrompt takes a prompt template string and replaces config variables.

func CountEventsSinceMarker added in v0.1.7

func CountEventsSinceMarker(paths config.Paths) (int, time.Time, error)

CountEventsSinceMarker counts events in log files newer than the compile marker without loading them into memory. Returns the count and marker time.

func GatherAllLogs added in v0.1.9

func GatherAllLogs(paths config.Paths, maxLines int) ([]ingest.Event, error)

GatherAllLogs reads all JSONL events from log files regardless of the compile marker. Returns events sorted by timestamp, capped at maxLines.

func GatherUnprocessedLogs

func GatherUnprocessedLogs(paths config.Paths, maxLines int) ([]ingest.Event, error)

GatherUnprocessedLogs reads all JSONL events from log files newer than the last compile marker. Returns events sorted by timestamp, capped at maxLines.

func ReadMarker

func ReadMarker(path string) (time.Time, error)

ReadMarker reads the timestamp from the compile marker file. Returns zero time if file doesn't exist.

func RunCompile

func RunCompile(paths config.Paths, cfg config.Config, promptTemplate string) error

RunCompile executes the full compilation sequence.

func WriteMarker

func WriteMarker(path string, t time.Time) error

WriteMarker writes a timestamp to the compile marker file.

Types

type CompilerBackend added in v0.1.8

type CompilerBackend interface {
	// Name returns the backend's identifier (e.g. "aj-deterministic", "aj-llm").
	Name() string

	// Compile takes parameterized patterns and produces skills.
	Compile(ctx context.Context, patterns []trace.Pattern) ([]SkillResult, error)
}

CompilerBackend is the interface for pluggable compilation strategies.

type DeterministicBackend added in v0.1.8

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

DeterministicBackend compiles parameterized patterns into deterministic shell scripts (bash + PowerShell) rather than relying on an LLM.

func NewDeterministicBackend added in v0.1.8

func NewDeterministicBackend(paths config.Paths, platform string) *DeterministicBackend

NewDeterministicBackend creates a new deterministic codegen backend.

func (*DeterministicBackend) Compile added in v0.1.8

func (b *DeterministicBackend) Compile(ctx context.Context, patterns []trace.Pattern) ([]SkillResult, error)

Compile iterates patterns and produces a skill for each.

func (*DeterministicBackend) Name added in v0.1.8

func (b *DeterministicBackend) Name() string

Name returns the backend identifier.

type LLMBackend added in v0.1.8

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

LLMBackend delegates compilation to Claude via the existing RunCompile flow.

func NewLLMBackend added in v0.1.8

func NewLLMBackend(cfg LLMBackendConfig) *LLMBackend

NewLLMBackend creates a new LLM compiler backend.

func (*LLMBackend) Compile added in v0.1.8

func (b *LLMBackend) Compile(ctx context.Context, patterns []trace.Pattern) ([]SkillResult, error)

Compile invokes the existing Claude-based compilation for the given patterns. In the LLM backend, patterns are informational — the LLM does its own pattern detection from logs. This method runs the full RunCompile flow.

func (*LLMBackend) Name added in v0.1.8

func (b *LLMBackend) Name() string

Name returns the backend identifier.

type LLMBackendConfig added in v0.1.8

type LLMBackendConfig struct {
	Paths          config.Paths
	Cfg            config.Config
	PromptTemplate string
}

LLMBackendConfig holds configuration for the LLM-based compiler backend.

type Manifest

type Manifest struct {
	LogsDir       string           `json:"logs_dir"`
	SkillsDir     string           `json:"skills_dir"`
	TotalSessions int              `json:"total_sessions"`
	TotalEvents   int              `json:"total_events"`
	DateRange     [2]string        `json:"date_range"`
	Sessions      []SessionSummary `json:"sessions"`
}

Manifest is the concise overview given to the compiler.

func BuildManifest

func BuildManifest(paths config.Paths) (Manifest, error)

BuildManifest scans log directories and produces a lightweight manifest instead of loading all events into memory.

type ROI added in v0.1.8

type ROI struct {
	StochasticTokensPerRun int `json:"stochastic_tokens_per_run"`
	DeterministicOverhead  int `json:"deterministic_overhead"`
	TokensSavedPerRun      int `json:"tokens_saved_per_run"`
}

ROI holds the return-on-investment estimate for a deterministic skill.

type SessionSummary

type SessionSummary struct {
	SessionID        string   `json:"session_id"`
	Date             string   `json:"date"`
	FilePath         string   `json:"file_path"`
	EventCount       int      `json:"event_count"`
	ToolNames        []string `json:"tool_names"`
	WorkingDirectory string   `json:"working_directory"`
}

SessionSummary is a lightweight summary of a single session log file.

type SkillResult added in v0.1.8

type SkillResult struct {
	Name      string // skill directory name
	Path      string // full path to the skill directory
	CreatedBy string // backend name that produced this skill
}

SkillResult represents a skill produced by a compiler backend.

type TieredCompiler added in v0.1.8

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

TieredCompiler routes patterns to deterministic or LLM backends based on confidence scoring.

func NewTieredCompiler added in v0.1.8

func NewTieredCompiler(deterministic, llm CompilerBackend, threshold float64) *TieredCompiler

NewTieredCompiler creates a compiler that routes patterns by confidence score.

func (*TieredCompiler) Compile added in v0.1.8

func (tc *TieredCompiler) Compile(ctx context.Context, patterns []trace.Pattern) ([]SkillResult, error)

Compile routes patterns to the appropriate backend and merges results.

type TraceAnalysisResult added in v0.1.8

type TraceAnalysisResult struct {
	PatternsFound      int
	DeterministicCount int
	LLMCount           int
	SkillsCreated      []SkillResult
}

TraceAnalysisResult holds the outcome of the trace pre-pass.

func RunTraceAnalysis added in v0.1.8

func RunTraceAnalysis(paths config.Paths, cfg config.Config) (TraceAnalysisResult, error)

RunTraceAnalysis performs the deterministic trace analysis pre-pass. It gathers unprocessed events, builds a trace graph, finds hot paths, parameterizes them, and compiles confident patterns deterministically.

type Trigger

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

Trigger evaluates whether the compilation should fire.

func NewTrigger

func NewTrigger(cfg config.Config) *Trigger

NewTrigger creates a Trigger with the given config.

func (*Trigger) IsRunning

func (tr *Trigger) IsRunning() bool

IsRunning returns whether a compilation is currently running.

func (*Trigger) MarkFired

func (tr *Trigger) MarkFired()

MarkFired records that a compile was just triggered.

func (*Trigger) SetRunning

func (tr *Trigger) SetRunning(running bool)

SetRunning marks the compilation as currently running (prevents concurrent runs).

func (*Trigger) ShouldFire

func (tr *Trigger) ShouldFire(eventsSinceCompile int64, now time.Time) bool

ShouldFire returns true if the compile sequence should be triggered based on the current mode, event count since last compile, and current time.

Jump to

Keyboard shortcuts

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