Documentation
¶
Index ¶
- Constants
- Variables
- func ValidateRecipe(recipe Recipe) error
- type AgentQuery
- type AtomicWriteConfig
- type AtomicWriter
- type CodeMatch
- type ConfidenceFactor
- type ConfidenceScore
- type FileLock
- type FileMatch
- type FileProcessor
- func (fp *FileProcessor) Cleanup()
- func (fp *FileProcessor) EnableSafety(enabled bool)
- func (fp *FileProcessor) GenerateChecksum(filePath string) (string, error)
- func (fp *FileProcessor) IsSafetyEnabled() bool
- func (fp *FileProcessor) QueryFiles(ctx context.Context, scope FileScope, query AgentQuery) ([]FileMatch, error)
- func (fp *FileProcessor) SetSafety(safety FileSafety)
- func (fp *FileProcessor) SetTransactionLogDir(dir string)
- func (fp *FileProcessor) TransformFiles(ctx context.Context, op FileTransformOp) (*FileTransformResult, error)
- func (fp *FileProcessor) ValidateChanges(details []FileTransformDetail) error
- type FileSafety
- type FileScope
- type FileTransformDetail
- type FileTransformOp
- type FileTransformResult
- type FileWalker
- type Location
- type Match
- type Provider
- type ProviderRegistry
- type QueryResult
- type Recipe
- type RecipeProcessor
- type RecipeResult
- type RecipeStep
- type RecipeStepResult
- type Rule
- type TransactionLog
- type TransactionManager
- func (tm *TransactionManager) AddOperation(opType, filePath string) (*TransactionOperation, error)
- func (tm *TransactionManager) BeginTransaction(description string) (*TransactionLog, error)
- func (tm *TransactionManager) CleanupOldTransactions(olderThan time.Duration) error
- func (tm *TransactionManager) CommitTransaction() error
- func (tm *TransactionManager) CompleteOperation(filePath string, err error) error
- func (tm *TransactionManager) ListPendingTransactions() ([]TransactionLog, error)
- func (tm *TransactionManager) LoadTransaction(txID string) (*TransactionLog, error)
- func (tm *TransactionManager) RollbackTransaction() error
- type TransactionOperation
- type TransformOp
- type TransformResult
- type WalkResult
Constants ¶
const DefaultRecipeMinConfidence = 0.85
Variables ¶
var ErrNoMatchesFound = errors.New("no matches found for target")
ErrNoMatchesFound indicates that a transform query did not match anything in the current source. Batch file operations treat this as a no-op, not a failure, because most files in a scope will legitimately have zero matches.
Functions ¶
func ValidateRecipe ¶ added in v0.2.0
ValidateRecipe checks a recipe before execution.
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
Attributes map[string]string `json:"attributes,omitempty"` // extra constraints, such as type
}
AgentQuery represents a natural language query for code elements
func ParseAgentQueryPayload ¶ added in v0.3.0
func ParseAgentQueryPayload(raw json.RawMessage, dsl string) (AgentQuery, error)
ParseAgentQueryPayload parses either a JSON AgentQuery payload or a DSL selector. A non-empty DSL selector takes precedence and lets callers support both public surfaces without duplicating parsing rules.
func ParseDSL ¶ added in v0.3.0
func ParseDSL(dsl string) (AgentQuery, error)
ParseDSL parses the compact Morfx selector syntax into AgentQuery.
Supported syntax:
- func:Handle*
- !func:Test*
- struct:* > field:Secret string
- field:Secret type=string visibility=private
- (func:* | method:*) > call:os.Getenv
- func:* & import:fmt
func ParseOptionalAgentQueryPayload ¶ added in v0.3.0
func ParseOptionalAgentQueryPayload(raw json.RawMessage, dsl string) (AgentQuery, bool, error)
ParseOptionalAgentQueryPayload parses an optional JSON or DSL query. The bool return value reports whether any query was provided.
type AtomicWriteConfig ¶
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 ¶
func DefaultAtomicConfig() AtomicWriteConfig
DefaultAtomicConfig provides sensible defaults
type AtomicWriter ¶
type AtomicWriter struct {
// contains filtered or unexported fields
}
AtomicWriter handles atomic file operations with locking
func NewAtomicWriter ¶
func NewAtomicWriter(config AtomicWriteConfig) *AtomicWriter
NewAtomicWriter creates a new atomic writer
func (*AtomicWriter) Cleanup ¶
func (aw *AtomicWriter) Cleanup()
Cleanup removes all locks (call on shutdown)
func (*AtomicWriter) WriteFile ¶
func (aw *AtomicWriter) WriteFile(path, content string) (err error)
WriteFile atomically writes content to file with optional locking
type CodeMatch ¶
type CodeMatch struct {
Name string `json:"name"` // Extracted name/identifier
Type string `json:"type"` // Query type that matched
NodeType string `json:"node_type"` // AST node type
StartByte uint32 `json:"start_byte"`
EndByte uint32 `json:"end_byte"`
Line uint32 `json:"line"`
Column uint32 `json:"column"`
}
CodeMatch represents a specific code element match with precise location
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 ¶
type FileLock struct {
// contains filtered or unexported fields
}
FileLock represents a file lock for concurrent access control
type FileMatch ¶
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 ¶
type FileProcessor struct {
// contains filtered or unexported fields
}
FileProcessor handles file-based transformations using providers
func NewFileProcessor ¶
func NewFileProcessor(providerRegistry ProviderRegistry) *FileProcessor
NewFileProcessor creates a new file processor
func NewFileProcessorWithSafety ¶
func NewFileProcessorWithSafety( providerRegistry ProviderRegistry, safetyEnabled bool, atomicConfig AtomicWriteConfig, ) *FileProcessor
NewFileProcessorWithSafety creates a processor with configurable safety settings
func (*FileProcessor) Cleanup ¶
func (fp *FileProcessor) Cleanup()
Cleanup releases all resources and locks
func (*FileProcessor) EnableSafety ¶
func (fp *FileProcessor) EnableSafety(enabled bool)
EnableSafety enables/disables safety features at runtime
func (*FileProcessor) GenerateChecksum ¶
func (fp *FileProcessor) GenerateChecksum(filePath string) (string, error)
GenerateChecksum creates SHA256 hash of file content for integrity checking
func (*FileProcessor) IsSafetyEnabled ¶
func (fp *FileProcessor) IsSafetyEnabled() bool
IsSafetyEnabled returns current safety status
func (*FileProcessor) QueryFiles ¶
func (fp *FileProcessor) QueryFiles(ctx context.Context, scope FileScope, query AgentQuery) ([]FileMatch, error)
QueryFiles searches for code elements across multiple files
func (*FileProcessor) SetSafety ¶
func (fp *FileProcessor) SetSafety(safety FileSafety)
SetSafety configures an optional safety delegate that can enforce policy checks.
func (*FileProcessor) SetTransactionLogDir ¶
func (fp *FileProcessor) SetTransactionLogDir(dir string)
SetTransactionLogDir overrides the directory used for file transaction logs.
func (*FileProcessor) TransformFiles ¶
func (fp *FileProcessor) TransformFiles(ctx context.Context, op FileTransformOp) (*FileTransformResult, error)
TransformFiles applies transformations across multiple files
func (*FileProcessor) ValidateChanges ¶
func (fp *FileProcessor) ValidateChanges(details []FileTransformDetail) error
ValidateChanges verifies that all transformations are valid
type FileSafety ¶
type FileSafety interface {
ValidateBatch(scope FileScope, files []WalkResult) error
ValidateFileChange(file WalkResult, confidence ConfidenceScore) error
}
FileSafety allows higher-level safety systems to enforce policy before modifications.
type FileScope ¶
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 ¶
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 ¶
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 ¶
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
Errors []string `json:"errors,omitempty"` // Non-fatal errors encountered during processing
Error error `json:"-"`
}
FileTransformResult represents the result of file-based transformations
type FileWalker ¶
type FileWalker struct {
// contains filtered or unexported fields
}
FileWalker provides high-performance parallel file system traversal
func NewFileWalker ¶
func NewFileWalker() *FileWalker
NewFileWalker creates a new file walker optimized for performance
func (*FileWalker) GetLanguageStats ¶
func (fw *FileWalker) GetLanguageStats(ctx context.Context, scope FileScope) (map[string]int, error)
GetLanguageStats returns statistics about discovered files by language
func (*FileWalker) Walk ¶
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 ¶
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 ¶
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 Recipe ¶ added in v0.2.0
type Recipe struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
DryRun bool `json:"dry_run,omitempty"`
MinConfidence float64 `json:"min_confidence,omitempty"`
Steps []RecipeStep `json:"steps"`
}
Recipe is a named, repeatable transformation made from Morfx primitives.
type RecipeProcessor ¶ added in v0.2.0
type RecipeProcessor interface {
TransformFiles(context.Context, FileTransformOp) (*FileTransformResult, error)
}
RecipeProcessor is the file transformation boundary used by recipes.
type RecipeResult ¶ added in v0.2.0
type RecipeResult struct {
Name string `json:"name"`
DryRun bool `json:"dry_run"`
StepsRun int `json:"steps_run"`
FilesScanned int `json:"files_scanned"`
FilesModified int `json:"files_modified"`
TotalMatches int `json:"total_matches"`
TransactionIDs []string `json:"transaction_ids,omitempty"`
Steps []RecipeStepResult `json:"steps"`
}
RecipeResult is the aggregate execution result for a recipe.
func ExecuteRecipe ¶ added in v0.2.0
func ExecuteRecipe(ctx context.Context, processor RecipeProcessor, recipe Recipe) (*RecipeResult, error)
ExecuteRecipe preflights every apply-mode step before mutating files.
type RecipeStep ¶ added in v0.2.0
type RecipeStep struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Method string `json:"method"`
Scope FileScope `json:"scope"`
Target AgentQuery `json:"target"`
TargetDSL string `json:"target_dsl,omitempty"`
Replacement string `json:"replacement,omitempty"`
Content string `json:"content,omitempty"`
MinConfidence float64 `json:"min_confidence,omitempty"`
Backup bool `json:"backup,omitempty"`
}
RecipeStep defines one query plus transform operation over a file scope.
type RecipeStepResult ¶ added in v0.2.0
type RecipeStepResult struct {
Name string `json:"name"`
Method string `json:"method"`
DryRun bool `json:"dry_run"`
MinConfidence float64 `json:"min_confidence"`
Result *FileTransformResult `json:"result"`
AppliedResult *FileTransformResult `json:"applied_result,omitempty"`
}
RecipeStepResult records the preflight/apply outcome for one recipe step.
type TransactionLog ¶
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 ¶
type TransactionManager struct {
// contains filtered or unexported fields
}
TransactionManager handles transaction logging and rollback
func NewTransactionManager ¶
func NewTransactionManager(logDir string, atomicWriter *AtomicWriter) *TransactionManager
NewTransactionManager creates a new transaction manager
func (*TransactionManager) AddOperation ¶
func (tm *TransactionManager) AddOperation(opType, filePath string) (*TransactionOperation, error)
AddOperation records a file operation in the current transaction
func (*TransactionManager) BeginTransaction ¶
func (tm *TransactionManager) BeginTransaction(description string) (*TransactionLog, error)
BeginTransaction starts a new transaction
func (*TransactionManager) CleanupOldTransactions ¶
func (tm *TransactionManager) CleanupOldTransactions(olderThan time.Duration) error
CleanupOldTransactions removes old completed transaction logs
func (*TransactionManager) CommitTransaction ¶
func (tm *TransactionManager) CommitTransaction() error
CommitTransaction marks transaction as successfully completed
func (*TransactionManager) CompleteOperation ¶
func (tm *TransactionManager) CompleteOperation(filePath string, err error) error
CompleteOperation marks an operation as completed
func (*TransactionManager) ListPendingTransactions ¶
func (tm *TransactionManager) ListPendingTransactions() ([]TransactionLog, error)
ListPendingTransactions returns all pending transactions
func (*TransactionManager) LoadTransaction ¶
func (tm *TransactionManager) LoadTransaction(txID string) (*TransactionLog, error)
LoadTransaction loads a transaction from log file
func (*TransactionManager) RollbackTransaction ¶
func (tm *TransactionManager) RollbackTransaction() error
RollbackTransaction reverts all operations in current transaction
type TransactionOperation ¶
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