llm

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package llm handles LLM-based generation tasks: prompt rendering, template embedding, runner invocation, and output parsing. Finders (read side) and handlers (write side) both consume this package — it owns the "call an LLM with a structured prompt" concern.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputePromptHash

func ComputePromptHash(prompt string) string

ComputePromptHash returns the hex-encoded SHA-256 hash of the rendered prompt. Uses the first 16 bytes (32 hex chars) — enough for collision avoidance.

func FormatEntryForPrompt

func FormatEntryForPrompt(e *model.Entry) string

FormatEntryForPrompt formats an entry as readable text for inclusion in a prompt.

func RenderSummaryPrompt

func RenderSummaryPrompt(entry *model.Entry, graph *model.Graph) (string, error)

RenderSummaryPrompt renders the summary prompt for an entry.

Types

type Finding

type Finding struct {
	Severity    Severity
	Category    string
	Observation string
}

Finding is a single observation from pre-flight validation.

type LLMMetadata

type LLMMetadata struct {
	TotalCostUSD      float64
	InputTokens       int
	OutputTokens      int
	CacheReadTokens   int
	CacheCreateTokens int
	NumTurns          int
	Duration          time.Duration
	DurationAPI       time.Duration
	Models            map[string]ModelUsage
}

LLMMetadata holds agent-neutral per-call metrics from the LLM provider.

type ModelUsage

type ModelUsage struct {
	InputTokens       int
	OutputTokens      int
	CacheReadTokens   int
	CacheCreateTokens int
	CostUSD           float64
}

ModelUsage holds per-model token and cost metrics.

type PreflightResult

type PreflightResult struct {
	Findings []Finding
}

PreflightResult holds the parsed findings from a pre-flight validator run. An empty Findings slice means the validator reported no findings.

func Preflight

func Preflight(ctx context.Context, runner Runner, entry *model.Entry, graph *model.Graph) (*PreflightResult, error)

Preflight runs the pre-flight validator against the given entry and graph. Returns the parsed result regardless of finding severity. Returns an error only for infrastructure failures (runner error, template error, parse error).

func (*PreflightResult) HasBlocking

func (r *PreflightResult) HasBlocking() bool

HasBlocking reports whether any finding blocks entry creation. Currently only SeverityHigh blocks.

type RunResult

type RunResult struct {
	Text string
	Meta *LLMMetadata
}

RunResult holds the LLM response text and optional metadata.

type Runner

type Runner interface {
	Run(ctx context.Context, prompt string) (*RunResult, error)
}

Runner executes a rendered prompt string against an LLM and returns the response with metadata. The implementation decides which model and transport to use. Injected so tests can substitute fakes.

type Severity

type Severity string

Severity classifies a pre-flight finding. Mirrored in the query package; templates describe severity in purely semantic terms.

const (
	SeverityHigh   Severity = "high"
	SeverityMedium Severity = "medium"
	SeverityLow    Severity = "low"
)

type SummarizeResult

type SummarizeResult struct {
	Summary     string
	SummaryHash string
}

SummarizeResult holds the generated summary and its prompt hash.

func Summarize

func Summarize(ctx context.Context, runner Runner, entry *model.Entry, graph *model.Graph, force bool) (*SummarizeResult, error)

Summarize generates a summary for a single entry using the LLM runner. Returns nil if the entry's stored SummaryHash matches the computed hash (skip). Set force to regenerate regardless.

Directories

Path Synopsis
Package claude implements llm.Runner by invoking the Claude CLI.
Package claude implements llm.Runner by invoking the Claude CLI.

Jump to

Keyboard shortcuts

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