core

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentQuery

type AgentQuery struct {
	Type     string       `json:"type"`               // function, struct, class, etc
	Name     string       `json:"name,omitempty"`     // name pattern with wildcards
	Contains *AgentQuery  `json:"contains,omitempty"` // nested queries
	Operator string       `json:"operator,omitempty"` // AND, OR, NOT
	Operands []AgentQuery `json:"operands,omitempty"` // for compound queries
}

AgentQuery represents a natural language query for code elements

type AtomicWriteConfig added in v1.2.0

type AtomicWriteConfig struct {
	UseFsync       bool          // Force fsync for durability
	LockTimeout    time.Duration // Max time to wait for file lock
	TempSuffix     string        // Suffix for temporary files
	BackupOriginal bool          // Create backup before writing
}

AtomicWriteConfig controls atomic writing behavior

func DefaultAtomicConfig added in v1.2.0

func DefaultAtomicConfig() AtomicWriteConfig

DefaultAtomicConfig provides sensible defaults

type AtomicWriter added in v1.2.0

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

AtomicWriter handles atomic file operations with locking

func NewAtomicWriter added in v1.2.0

func NewAtomicWriter(config AtomicWriteConfig) *AtomicWriter

NewAtomicWriter creates a new atomic writer

func (*AtomicWriter) Cleanup added in v1.2.0

func (aw *AtomicWriter) Cleanup()

Cleanup removes all locks (call on shutdown)

func (*AtomicWriter) WriteFile added in v1.2.0

func (aw *AtomicWriter) WriteFile(path, content string) error

WriteFile atomically writes content to file with optional locking

type ConfidenceFactor

type ConfidenceFactor struct {
	Name   string  `json:"name"`
	Impact float64 `json:"impact"` // -1.0 to 1.0
	Reason string  `json:"reason"`
}

ConfidenceFactor explains score calculation

type ConfidenceScore

type ConfidenceScore struct {
	Score   float64            `json:"score"` // 0.0 to 1.0
	Level   string             `json:"level"` // high, medium, low
	Factors []ConfidenceFactor `json:"factors"`
}

ConfidenceScore for transformations

type FileLock added in v1.2.0

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

FileLock represents a file lock for concurrent access control

type FileMatch added in v1.2.0

type FileMatch struct {
	Match           // Embedded base match
	FilePath string `json:"file_path"` // Absolute file path
	FileSize int64  `json:"file_size"` // File size in bytes
	ModTime  int64  `json:"mod_time"`  // Last modification time (Unix timestamp)
	Language string `json:"language"`  // Detected language
}

FileMatch represents a code match with file information

type FileProcessor added in v1.2.0

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

FileProcessor handles file-based transformations using providers

func NewFileProcessor added in v1.2.0

func NewFileProcessor(providerRegistry ProviderRegistry) *FileProcessor

NewFileProcessor creates a new file processor

func NewFileProcessorWithSafety added in v1.2.0

func NewFileProcessorWithSafety(
	providerRegistry ProviderRegistry,
	safetyEnabled bool,
	atomicConfig AtomicWriteConfig,
) *FileProcessor

NewFileProcessorWithSafety creates a processor with configurable safety settings

func (*FileProcessor) Cleanup added in v1.2.0

func (fp *FileProcessor) Cleanup()

Cleanup releases all resources and locks

func (*FileProcessor) EnableSafety added in v1.2.0

func (fp *FileProcessor) EnableSafety(enabled bool)

EnableSafety enables/disables safety features at runtime

func (*FileProcessor) GenerateChecksum added in v1.2.0

func (fp *FileProcessor) GenerateChecksum(filePath string) (string, error)

GenerateChecksum creates SHA256 hash of file content for integrity checking

func (*FileProcessor) IsSafetyEnabled added in v1.2.0

func (fp *FileProcessor) IsSafetyEnabled() bool

IsSafetyEnabled returns current safety status

func (*FileProcessor) QueryFiles added in v1.2.0

func (fp *FileProcessor) QueryFiles(ctx context.Context, scope FileScope, query AgentQuery) ([]FileMatch, error)

QueryFiles searches for code elements across multiple files

func (*FileProcessor) TransformFiles added in v1.2.0

func (fp *FileProcessor) TransformFiles(ctx context.Context, op FileTransformOp) (*FileTransformResult, error)

TransformFiles applies transformations across multiple files

func (*FileProcessor) ValidateChanges added in v1.2.0

func (fp *FileProcessor) ValidateChanges(details []FileTransformDetail) error

ValidateChanges verifies that all transformations are valid

type FileScope added in v1.2.0

type FileScope struct {
	Path           string   `json:"path"`                // Root path to scan
	Include        []string `json:"include,omitempty"`   // File patterns to include (*.go, **/*.ts)
	Exclude        []string `json:"exclude,omitempty"`   // File patterns to exclude
	MaxDepth       int      `json:"max_depth,omitempty"` // Max directory depth (0 = unlimited)
	MaxFiles       int      `json:"max_files,omitempty"` // Max files to process (0 = unlimited)
	FollowSymlinks bool     `json:"follow_symlinks"`     // Follow symbolic links
	Language       string   `json:"language,omitempty"`  // Auto-detect by extension if empty
}

FileScope defines which files to process in filesystem operations

type FileTransformDetail added in v1.2.0

type FileTransformDetail struct {
	FilePath     string          `json:"file_path"`
	Language     string          `json:"language"`
	MatchCount   int             `json:"match_count"`
	Modified     bool            `json:"modified"`
	Diff         string          `json:"diff,omitempty"`
	Confidence   ConfidenceScore `json:"confidence"`
	Error        string          `json:"error,omitempty"`
	BackupPath   string          `json:"backup_path,omitempty"`
	OriginalSize int64           `json:"original_size"`
	ModifiedSize int64           `json:"modified_size"`
}

FileTransformDetail represents the transformation result for a single file

type FileTransformOp added in v1.2.0

type FileTransformOp struct {
	TransformOp           // Embedded base operation
	Scope       FileScope `json:"scope"`    // Files to operate on
	DryRun      bool      `json:"dry_run"`  // Preview only, don't modify files
	Backup      bool      `json:"backup"`   // Create .bak files before modifying
	Parallel    bool      `json:"parallel"` // Use parallel processing
}

FileTransformOp represents a file-based transformation operation

type FileTransformResult added in v1.2.0

type FileTransformResult struct {
	FilesScanned      int                   `json:"files_scanned"`            // Total files processed
	FilesModified     int                   `json:"files_modified"`           // Files actually changed
	TotalMatches      int                   `json:"total_matches"`            // Total matches across all files
	ScanDuration      int64                 `json:"scan_duration_ms"`         // Time spent scanning (ms)
	TransformDuration int64                 `json:"transform_duration_ms"`    // Time spent transforming (ms)
	Files             []FileTransformDetail `json:"files"`                    // Per-file results
	Confidence        ConfidenceScore       `json:"confidence"`               // Overall confidence
	TransactionID     string                `json:"transaction_id,omitempty"` // Transaction ID for rollback
	Error             error                 `json:"-"`
}

FileTransformResult represents the result of file-based transformations

type FileWalker added in v1.2.0

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

FileWalker provides high-performance parallel file system traversal

func NewFileWalker added in v1.2.0

func NewFileWalker() *FileWalker

NewFileWalker creates a new file walker optimized for performance

func (*FileWalker) FastScan added in v1.2.0

func (fw *FileWalker) FastScan(ctx context.Context, scope FileScope) ([]string, error)

FastScan performs ultra-fast file discovery without full stat() calls

func (*FileWalker) GetLanguageStats added in v1.2.0

func (fw *FileWalker) GetLanguageStats(ctx context.Context, scope FileScope) (map[string]int, error)

GetLanguageStats returns statistics about discovered files by language

func (*FileWalker) Walk added in v1.2.0

func (fw *FileWalker) Walk(ctx context.Context, scope FileScope) (<-chan WalkResult, error)

Walk performs parallel directory traversal with pattern matching

type Location

type Location struct {
	File      string `json:"file,omitempty"`
	Line      int    `json:"line"`
	Column    int    `json:"column"`
	EndLine   int    `json:"end_line,omitempty"`
	EndColumn int    `json:"end_column,omitempty"`
}

Location in source code

type Match

type Match struct {
	Type     string   `json:"type"`
	Name     string   `json:"name"`
	Location Location `json:"location"`
	Content  string   `json:"content,omitempty"`
	Scope    string   `json:"scope,omitempty"`  // file, function, class
	Parent   string   `json:"parent,omitempty"` // parent element name
}

Match represents a found code element

type Provider added in v1.2.0

type Provider interface {
	Language() string
	Query(source string, query AgentQuery) QueryResult
	Transform(source string, op TransformOp) TransformResult
}

Provider interface for language-specific operations

type ProviderRegistry added in v1.2.0

type ProviderRegistry interface {
	Get(language string) (Provider, bool)
}

ProviderRegistry interface for provider lookup

type QueryResult

type QueryResult struct {
	Matches []Match `json:"matches"`
	Total   int     `json:"total"`
	Error   error   `json:"-"`
}

QueryResult from provider

type TransactionLog added in v1.2.0

type TransactionLog struct {
	ID          string                 `json:"id"`
	Started     time.Time              `json:"started"`
	Completed   time.Time              `json:"completed"`
	Operations  []TransactionOperation `json:"operations"`
	Status      string                 `json:"status"` // "pending", "committed", "rolled_back"
	Description string                 `json:"description"`
}

TransactionLog represents a complete transaction

type TransactionManager added in v1.2.0

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

TransactionManager handles transaction logging and rollback

func NewTransactionManager added in v1.2.0

func NewTransactionManager(logDir string, atomicWriter *AtomicWriter) *TransactionManager

NewTransactionManager creates a new transaction manager

func (*TransactionManager) AddOperation added in v1.2.0

func (tm *TransactionManager) AddOperation(opType, filePath string) (*TransactionOperation, error)

AddOperation records a file operation in the current transaction

func (*TransactionManager) BeginTransaction added in v1.2.0

func (tm *TransactionManager) BeginTransaction(description string) (*TransactionLog, error)

BeginTransaction starts a new transaction

func (*TransactionManager) CleanupOldTransactions added in v1.2.0

func (tm *TransactionManager) CleanupOldTransactions(olderThan time.Duration) error

CleanupOldTransactions removes old completed transaction logs

func (*TransactionManager) CommitTransaction added in v1.2.0

func (tm *TransactionManager) CommitTransaction() error

CommitTransaction marks transaction as successfully completed

func (*TransactionManager) CompleteOperation added in v1.2.0

func (tm *TransactionManager) CompleteOperation(filePath string, err error) error

CompleteOperation marks an operation as completed

func (*TransactionManager) ListPendingTransactions added in v1.2.0

func (tm *TransactionManager) ListPendingTransactions() ([]TransactionLog, error)

ListPendingTransactions returns all pending transactions

func (*TransactionManager) LoadTransaction added in v1.2.0

func (tm *TransactionManager) LoadTransaction(txID string) (*TransactionLog, error)

LoadTransaction loads a transaction from log file

func (*TransactionManager) RollbackTransaction added in v1.2.0

func (tm *TransactionManager) RollbackTransaction() error

RollbackTransaction reverts all operations in current transaction

type TransactionOperation added in v1.2.0

type TransactionOperation struct {
	Type       string    `json:"type"` // "modify", "create", "delete"
	FilePath   string    `json:"file_path"`
	BackupPath string    `json:"backup_path"` // For rollback
	Checksum   string    `json:"checksum"`    // Original file checksum
	Timestamp  time.Time `json:"timestamp"`
	Completed  bool      `json:"completed"`
	Error      string    `json:"error,omitempty"`
}

TransactionOperation represents a single operation in a transaction

type TransformOp

type TransformOp struct {
	Method      string     `json:"method"`                // replace, delete, insert_before, etc
	Target      AgentQuery `json:"target"`                // what to find
	Content     string     `json:"content,omitempty"`     // for insert/append
	Replacement string     `json:"replacement,omitempty"` // for replace
}

TransformOp represents a transformation operation

type TransformResult

type TransformResult struct {
	Modified   string          `json:"modified"`
	Diff       string          `json:"diff"`
	Confidence ConfidenceScore `json:"confidence"`
	MatchCount int             `json:"match_count"`        // Number of elements matched/transformed
	Metadata   map[string]any  `json:"metadata,omitempty"` // Additional info (strategy, etc)
	Error      error           `json:"-"`
}

TransformResult from provider

type WalkResult added in v1.2.0

type WalkResult struct {
	Path     string
	Info     fs.FileInfo
	Language string
	Error    error
}

WalkResult represents a discovered file

Jump to

Keyboard shortcuts

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