artifacts

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package artifacts provides enhanced metadata structures for artifact generation.

Package artifacts handles persistent storage of execution run data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateLineStats

func CalculateLineStats(beforeContent, afterContent string) (added, removed, modified int)

CalculateLineStats calculates line statistics from before/after content.

func DetectFileType

func DetectFileType(path string) string

DetectFileType categorizes file into broad type.

func DetectLanguage

func DetectLanguage(path string) string

DetectLanguage detects programming language from file path/extension.

func IsTestFile

func IsTestFile(path string) bool

IsTestFile determines if a file is a test file.

Types

type AggregatedChanges

type AggregatedChanges struct {
	// Overall statistics
	TotalFiles        int   `json:"total_files"`
	TotalLinesAdded   int   `json:"total_lines_added"`
	TotalLinesRemoved int   `json:"total_lines_removed"`
	TotalLinesChanged int   `json:"total_lines_changed"` // Sum of added + removed
	TotalCharsAdded   int   `json:"total_chars_added"`
	TotalCharsRemoved int   `json:"total_chars_removed"`
	TotalSizeDelta    int64 `json:"total_size_delta"` // Net size change in bytes

	// File categorization
	FilesCreated int `json:"files_created"`
	FilesUpdated int `json:"files_updated"`
	FilesDeleted int `json:"files_deleted"`

	// File type breakdown
	FilesByLanguage  map[string]int `json:"files_by_language"` // Language -> count
	FilesByType      map[string]int `json:"files_by_type"`     // Type -> count
	TestFilesCount   int            `json:"test_files_count"`
	CodeFilesCount   int            `json:"code_files_count"`
	ConfigFilesCount int            `json:"config_files_count"`

	// Directory-level summaries
	DirectoriesAffected []string       `json:"directories_affected"`
	ChangesByDirectory  map[string]int `json:"changes_by_directory"` // Directory -> file count

	// Top changed files (sorted by lines changed)
	TopChangedFiles []FileChangeSummary `json:"top_changed_files,omitempty"`
}

AggregatedChanges represents high-level statistics across all file changes.

func AggregateChanges

func AggregateChanges(files []DetailedFileChange) AggregatedChanges

AggregateChanges creates aggregated statistics from detailed file changes.

type ArtifactMetadata

type ArtifactMetadata struct {
	// Basic info
	Name        string `json:"name"`
	CaptureTime string `json:"capture_time"` // ISO8601 timestamp
	RunID       string `json:"run_id,omitempty"`

	// Executed plan (for LLM agent audit trail)
	Plan        *EmbeddedPlan `json:"plan,omitempty"`         // Full plan for short plans
	PlanSummary string        `json:"plan_summary,omitempty"` // Brief summary for large plans

	// Aggregated statistics
	Summary AggregatedChanges `json:"summary"`

	// Detailed per-file changes
	Files []DetailedFileChange `json:"files"`

	// Validation results (if artifact.validate was run)
	Validated      bool                  `json:"validated,omitempty"`
	ValidationPass bool                  `json:"validation_pass,omitempty"`
	Violations     []ValidationViolation `json:"violations,omitempty"`

	// Additional metadata
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

ArtifactMetadata represents complete metadata for an artifact capture.

type Config

type Config struct {
	BaseDir        string // Base directory for artifacts (e.g., ".mooncake")
	CaptureStdout  bool   // Whether to capture full stdout
	CaptureStderr  bool   // Whether to capture full stderr
	MaxOutputBytes int    // Max bytes per step in results.json
	MaxOutputLines int    // Max lines per step in results.json
	MaxStdoutBytes int    // Max bytes for stdout.log
	MaxStderrBytes int    // Max bytes for stderr.log
}

Config holds configuration for artifact writer.

type DetailedFileChange

type DetailedFileChange struct {
	// Basic information
	Path      string `json:"path"`
	Operation string `json:"operation"` // "created", "updated", "deleted", "template"
	StepID    string `json:"step_id,omitempty"`
	StepName  string `json:"step_name,omitempty"`

	// Size information
	SizeBefore int64 `json:"size_before,omitempty"`
	SizeAfter  int64 `json:"size_after,omitempty"`
	SizeDelta  int64 `json:"size_delta,omitempty"` // Positive = grew, negative = shrunk

	// Checksums
	ChecksumBefore string `json:"checksum_before,omitempty"`
	ChecksumAfter  string `json:"checksum_after,omitempty"`

	// Line statistics
	LinesAdded    int `json:"lines_added"`
	LinesRemoved  int `json:"lines_removed"`
	LinesModified int `json:"lines_modified"`
	LinesTotal    int `json:"lines_total"` // Total lines after change

	// Character/token statistics
	CharsAdded   int `json:"chars_added,omitempty"`
	CharsRemoved int `json:"chars_removed,omitempty"`

	// Diff information
	DiffFile    string   `json:"diff_file,omitempty"`    // Relative path to diff file
	HunkCount   int      `json:"hunk_count,omitempty"`   // Number of hunks in diff
	HunkSummary []string `json:"hunk_summary,omitempty"` // Brief description of each hunk

	// Language/file type detection
	Language   string `json:"language,omitempty"`  // Detected language (e.g., "go", "python", "javascript")
	FileType   string `json:"file_type,omitempty"` // Category (e.g., "code", "test", "config", "docs")
	IsTestFile bool   `json:"is_test_file"`

	// Content (optional, can be large)
	ContentBefore string `json:"content_before,omitempty"`
	ContentAfter  string `json:"content_after,omitempty"`
}

DetailedFileChange represents comprehensive metadata about a file modification.

func EnhanceFileChange

func EnhanceFileChange(fc *FileChange, beforeContent, afterContent string) *DetailedFileChange

EnhanceFileChange enriches a basic FileChange with detailed metadata.

type EmbeddedPlan

type EmbeddedPlan struct {
	StepCount   int                    `json:"step_count"`
	Steps       []config.Step          `json:"steps"`
	InitialVars map[string]interface{} `json:"initial_vars,omitempty"`
}

EmbeddedPlan represents the plan that was executed during artifact capture.

type FileChange

type FileChange struct {
	Path           string `json:"path"`
	Operation      string `json:"operation"` // "created", "updated", "template"
	SizeBytes      int64  `json:"size_bytes"`
	ChecksumBefore string `json:"checksum_before,omitempty"` // SHA256 before modification
	ChecksumAfter  string `json:"checksum_after,omitempty"`  // SHA256 after modification
	DiffFile       string `json:"diff_file,omitempty"`       // Path to unified diff file
	StepID         string `json:"step_id,omitempty"`         // Step that made the change
}

FileChange records a file that was created or modified.

type FileChangeSummary

type FileChangeSummary struct {
	Path         string `json:"path"`
	LinesChanged int    `json:"lines_changed"`
	Operation    string `json:"operation"`
}

FileChangeSummary is a brief summary of a file change for top-N lists.

type FileSnapshot

type FileSnapshot struct {
	Path     string
	Content  string
	Checksum string
}

FileSnapshot holds file state at a point in time.

type RunSummary

type RunSummary struct {
	RunID        string    `json:"run_id"`
	RootFile     string    `json:"root_file"`
	StartTime    time.Time `json:"start_time"`
	EndTime      time.Time `json:"end_time"`
	DurationMs   int64     `json:"duration_ms"`
	TotalSteps   int       `json:"total_steps"`
	SuccessSteps int       `json:"success_steps"`
	FailedSteps  int       `json:"failed_steps"`
	SkippedSteps int       `json:"skipped_steps"`
	ChangedSteps int       `json:"changed_steps"`
	Success      bool      `json:"success"`
	ErrorMessage string    `json:"error_message,omitempty"`
}

RunSummary contains overall run information.

type StepResult

type StepResult struct {
	StepID       string                 `json:"step_id"`
	Name         string                 `json:"name"`
	Action       string                 `json:"action"`
	Level        int                    `json:"level"`
	DurationMs   int64                  `json:"duration_ms"`
	Changed      bool                   `json:"changed"`
	Status       string                 `json:"status"` // "success", "failed", "skipped"
	ErrorMessage string                 `json:"error_message,omitempty"`
	OutputLines  int                    `json:"output_lines,omitempty"`
	OutputBytes  int                    `json:"output_bytes,omitempty"`
	Truncated    bool                   `json:"truncated,omitempty"`
	Result       map[string]interface{} `json:"result,omitempty"`
	FilesChanged []string               `json:"files_changed,omitempty"` // Paths of files modified in this step
	DiffFiles    []string               `json:"diff_files,omitempty"`    // Paths to diff files for this step
}

StepResult holds result data for a single step.

type ValidationViolation

type ValidationViolation struct {
	Constraint string `json:"constraint"` // e.g., "max_files", "max_lines_changed"
	Expected   string `json:"expected"`   // Expected value/constraint
	Actual     string `json:"actual"`     // Actual value
	Message    string `json:"message"`    // Human-readable message
}

ValidationViolation represents a validation constraint that was violated.

type Writer

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

Writer writes execution artifacts to disk.

func NewWriter

func NewWriter(cfg Config, planData *plan.Plan, systemFacts *facts.Facts) (*Writer, error)

NewWriter creates a new artifact writer.

func (*Writer) CaptureFileStateAfter

func (w *Writer) CaptureFileStateAfter(before *FileSnapshot, stepID string, operation string) *FileChange

CaptureFileStateAfter captures file state after modification and generates diff. Writes diff and checksum files to artifacts directory.

func (*Writer) CaptureFileStateBefore

func (w *Writer) CaptureFileStateBefore(path string) *FileSnapshot

CaptureFileStateBefore captures file state before a modification. Returns a snapshot that can be used with CaptureFileStateAfter.

func (*Writer) Close

func (w *Writer) Close()

Close closes all open files.

func (*Writer) GetFileChanges

func (w *Writer) GetFileChanges() []FileChange

GetFileChanges returns a copy of all file changes tracked so far. This is used by artifact_capture to collect changes from wrapped steps.

func (*Writer) OnEvent

func (w *Writer) OnEvent(event events.Event)

OnEvent processes events and writes to artifacts.

func (*Writer) RecordFileChecksums

func (w *Writer) RecordFileChecksums(stepID, filePath, checksumBefore, checksumAfter string) string

RecordFileChecksums records before/after checksums for a file operation. Returns the checksum file path.

func (*Writer) RecordFileDiff

func (w *Writer) RecordFileDiff(stepID, filePath, beforeContent, afterContent string) string

RecordFileDiff records a file diff with before/after content. This should be called by action handlers that want to provide diff information. Returns the path to the generated diff file.

Jump to

Keyboard shortcuts

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