Class: RosettAi::Project::DriftDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/project/drift_detector.rb

Overview

Detects configuration drift in rosett-ai-managed projects.

Supports two drift types:

  • Forward drift: source YAML differs from compiled native config
  • Template drift: project config differs from template baseline

Author:

  • hugo

  • claude

Constant Summary collapse

DRIFT_TYPES =
['forward', 'template'].freeze

Instance Method Summary collapse

Constructor Details

#initialize(project_root:) ⇒ DriftDetector

Returns a new instance of DriftDetector.

Parameters:

  • project_root (Pathname)

    root directory of the project



23
24
25
26
# File 'lib/rosett_ai/project/drift_detector.rb', line 23

def initialize(project_root:)
  @project_root = project_root
  @project_dir = project_root.join('.rosett-ai')
end

Instance Method Details

#detect(type: nil) ⇒ Hash

Detects drift of the specified type.

Parameters:

  • type (String, nil) (defaults to: nil)

    'forward', 'template', or nil (both)

Returns:

  • (Hash)

    drift results with :forward and/or :template keys



32
33
34
35
36
37
38
39
40
# File 'lib/rosett_ai/project/drift_detector.rb', line 32

def detect(type: nil)
  results = {}

  results[:forward] = detect_forward_drift if type.nil? || type == 'forward'

  results[:template] = detect_template_drift if type.nil? || type == 'template'

  results
end

#drifted?(type: nil) ⇒ Boolean

Returns true if any drift detected.

Returns:

  • (Boolean)

    true if any drift detected



43
44
45
46
# File 'lib/rosett_ai/project/drift_detector.rb', line 43

def drifted?(type: nil)
  results = detect(type: type)
  results.values.any?(&:any?)
end