extract

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package extract provides LLM-based observation extraction and XML validation for session backfill.

Index

Constants

View Source
const ChunkExtractionSystemPrompt = `` /* 2223-byte string literal not displayed */

ChunkExtractionSystemPrompt is the category-based extraction prompt for session chunks. Used by both backfill (multi-exchange chunks) and live SDK processor (single-exchange).

View Source
const ChunkExtractionUserTemplate = `` /* 782-byte string literal not displayed */

ChunkExtractionUserTemplate is the user prompt template for chunk extraction. Format args: projectPath, exchangeCount, chunkInfo, transcript

View Source
const FeedbackImportSystemPrompt = `` /* 927-byte string literal not displayed */

FeedbackImportSystemPrompt converts feedback_*.md files into structured TRIGGER→RULE→REASON observations.

View Source
const RetrospectiveSystemPrompt = `` /* 815-byte string literal not displayed */

RetrospectiveSystemPrompt is the session-level retrospective prompt. Processes full session holistically after chunk extraction.

View Source
const RetrospectiveUserTemplate = `` /* 1194-byte string literal not displayed */

RetrospectiveUserTemplate is the user prompt template for session retrospective. Format args: project, durationMin, totalExchanges, userMessages, commits, filesModified, alreadyExtracted, sessionOpening, sessionClosing

View Source
const SystemPrompt = `` /* 1398-byte string literal not displayed */

SystemPrompt is the frozen poc-v1 extraction prompt for historical sessions.

View Source
const UserPromptTemplate = `` /* 1055-byte string literal not displayed */

UserPromptTemplate is the template for building user prompts. Format args: projectPath, gitBranch, durationMin, exchangeCount, chunkInfo, alreadyExtracted, transcript.

Variables

View Source
var ValidCategories = map[string]bool{
	"decision": true, "correction": true, "debugging": true,
	"gotcha": true, "pattern": true, "user_behavior": true,
}

ValidCategories contains allowed observation category values.

View Source
var ValidOutcomes = map[string]bool{
	"active_pattern": true, "failed_experiment": true, "superseded": true,
}

ValidOutcomes contains allowed outcome classification values.

View Source
var ValidTypes = map[string]bool{
	"decision": true, "bugfix": true, "feature": true,
	"refactor": true, "discovery": true, "change": true, "design": true,
}

ValidTypes contains allowed observation type values.

Functions

func BuildAlreadyExtracted

func BuildAlreadyExtracted(titles []string) string

BuildAlreadyExtracted builds the <already_extracted> context block for multi-chunk dedup.

func BuildChunkUserPrompt added in v1.6.0

func BuildChunkUserPrompt(projectPath string, exchangeCount int, chunkInfo, transcript string) string

BuildChunkUserPrompt constructs the user prompt using ChunkExtractionUserTemplate. Transcript content is sanitized to prevent XML tag injection (AG06-005).

func BuildUserPrompt

func BuildUserPrompt(projectPath, gitBranch string, durationMin, exchangeCount int, chunkInfo, alreadyExtracted, transcript string) string

BuildUserPrompt constructs the user prompt for LLM extraction. Transcript content is sanitized to prevent XML tag injection (AG06-005).

func ConvertToObservation

func ConvertToObservation(xo XMLObservation, project string) *models.ParsedObservation

ConvertToObservation converts an XMLObservation to a ParsedObservation.

Types

type SessionRetrospective added in v1.6.0

type SessionRetrospective struct {
	Summary             SessionSummary   `xml:"summary"`
	SessionObservations []XMLObservation `xml:"session_observations>observation"`
}

SessionRetrospective represents the parsed output of the retrospective prompt.

func ParseRetrospective added in v1.6.0

func ParseRetrospective(raw string) *SessionRetrospective

ParseRetrospective extracts a SessionRetrospective from raw LLM XML output. Returns nil if the output is empty or unparseable.

type SessionSummary added in v1.6.0

type SessionSummary struct {
	Request   string `xml:"request"`
	Completed string `xml:"completed"`
	Learned   string `xml:"learned"`
	NextSteps string `xml:"next_steps"`
	Outcome   string `xml:"outcome"` // shipped|partial|blocked|investigation_only
}

SessionSummary contains the structured session summary fields.

type ValidationResult

type ValidationResult struct {
	ObservationCount int
	ValidCount       int
	Errors           []string
	IsNoObservations bool
	IsMalformedXML   bool
	Observations     []XMLObservation
}

ValidationResult holds the result of validating LLM XML output.

func ValidateXML

func ValidateXML(raw string) ValidationResult

ValidateXML parses and validates the XML output from the LLM.

type XMLObservation

type XMLObservation struct {
	Category  string      `xml:"category"` // decision|correction|debugging|gotcha|pattern|user_behavior
	Type      string      `xml:"type"`
	Outcome   string      `xml:"outcome"`
	Title     string      `xml:"title"`
	Narrative string      `xml:"narrative"`
	Concepts  xmlConcepts `xml:"concepts"`
	Files     xmlFiles    `xml:"files"`
}

XMLObservation represents a single observation parsed from LLM XML output.

func ParseSingleObservation added in v1.6.0

func ParseSingleObservation(raw string) *XMLObservation

ParseSingleObservation extracts a single observation from XML that may contain a bare <observation>...</observation> element (without a wrapper <observations> element). Returns nil if parsing fails or the input is empty.

Jump to

Keyboard shortcuts

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