Help us shape the future of Go! Take the 2026 Go Developer Survey

triage

package
v0.3.2-alpha Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package triage sanitizes failures and coordinates bounded repair attempts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildPrompt

func BuildPrompt(context FailureContext) string

BuildPrompt produces a bounded, explicit repair prompt with test-file restrictions.

func ExtractUnifiedDiff

func ExtractUnifiedDiff(rawLLMResponse string) (string, error)

ExtractUnifiedDiff extracts standard unified diff sections, removing prose and markdown fences. Replies without hunks require NormalizeModelResponse.

func LoadDotEnv

func LoadDotEnv(path string) error

LoadDotEnv loads KEY=VALUE pairs without overwriting variables already set by the process. It intentionally supports a small, predictable .env subset.

func NormalizeModelResponse

func NormalizeModelResponse(response, root string, targets []string) (string, error)

NormalizeModelResponse converts supported model response shapes to a canonical unified diff. Full-file replacements are accepted only for one explicitly identified target file within root.

func SanitizeLog

func SanitizeLog(input string) string

SanitizeLog removes common unstable terminal output while preserving stack text.

func ValidatePatch

func ValidatePatch(diff string, allowTestChanges bool) error

ValidatePatch checks unified-diff structure, path traversal, and test-file edits.

func WaitForRetryDelay

func WaitForRetryDelay(ctx context.Context, d time.Duration) error

WaitForRetryDelay is available for callers that add a paced model retry policy.

Types

type ApprovalRequiredError

type ApprovalRequiredError struct{ Reason string }

ApprovalRequiredError stops autonomous retries when policy requires a human.

func (*ApprovalRequiredError) Error

func (e *ApprovalRequiredError) Error() string

type CircuitBreakerError

type CircuitBreakerError struct {
	Attempts int
	Cause    error
}

CircuitBreakerError reports bounded repair-loop exhaustion without implying that any rejected patch was applied to the caller's working tree.

func (*CircuitBreakerError) Error

func (e *CircuitBreakerError) Error() string

func (*CircuitBreakerError) Unwrap

func (e *CircuitBreakerError) Unwrap() error

type DockerSandbox

type DockerSandbox = runner.DockerSandbox

DockerSandbox is kept as a source-compatible alias; its implementation lives with the execution runners in pkg/runner.

type FailureContext

type FailureContext struct {
	Impact           astgraph.ImpactSet
	SourceLocations  []SourceLocation
	SanitizedLog     string
	PreviousPatch    string
	PreviousError    string
	Attempt          int
	MaxAttempts      int
	AllowTestChanges bool
}

FailureContext contains the structural and sanitized data sent to a repair model.

type LLMConfig

type LLMConfig struct{ Endpoint, APIKey, Model string }

LLMConfig contains resolved OpenAI-compatible endpoint credentials.

func ResolveLLMConfig

func ResolveLLMConfig(getenv func(string) string, astrixfileModel string) LLMConfig

ResolveLLMConfig applies Astrix, OpenRouter, then OpenAI key precedence. A custom ASTRIX_LLM_BASE_URL supports self-hosted OpenAI-compatible endpoints.

type Model

type Model interface {
	ProposePatch(context.Context, string) (string, error)
}

Model returns a proposed unified diff for the supplied repair prompt.

type OpenAICompatModel

type OpenAICompatModel struct {
	Endpoint string
	APIKey   string
	Model    string
	Client   *http.Client
}

OpenAICompatModel calls a Chat Completions-compatible endpoint when configured.

func (OpenAICompatModel) ProposePatch

func (m OpenAICompatModel) ProposePatch(ctx context.Context, prompt string) (string, error)

type Patcher

type Patcher struct {
	Model   Model
	Sandbox Sandbox
	// Root is the workspace root used to synthesize diffs from full-file model replies.
	Root             string
	MaxAttempts      int
	AllowTestChanges bool
	Policy           PolicyCheck
}

Patcher coordinates a model, policy gate, and isolated test sandbox.

func (*Patcher) Repair

func (p *Patcher) Repair(ctx context.Context, base FailureContext) (Result, error)

Repair performs at most three repair attempts. It does not modify the caller's tree; the accepted diff is returned for an explicit apply step by the caller.

type PolicyCheck

type PolicyCheck func(context.Context, string) error

PolicyCheck enforces policy on a proposed patch before sandbox execution.

type Result

type Result struct {
	Patch    string
	Attempts int
}

Result contains the first patch that passed validation, policy, and sandbox tests.

type Sandbox

type Sandbox interface {
	ApplyAndTest(context.Context, string) error
}

Sandbox validates and tests a patch in an isolated environment.

type SourceLocation

type SourceLocation struct {
	Path, Symbol       string
	StartLine, EndLine int
	Source             string
}

SourceLocation identifies a non-test source definition in the impact graph.

Jump to

Keyboard shortcuts

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