Class: Ace::Support::Models::Organisms::ProviderSyncOrchestrator

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/support/models/organisms/provider_sync_orchestrator.rb

Overview

Orchestrates the provider config synchronization workflow Coordinates reading configs, generating diffs, applying changes, and committing

Constant Summary collapse

PROVIDER_SYNC_CACHE_MAX_AGE =

7 days

86_400 * 7

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cache_manager: nil, output: $stdout) ⇒ ProviderSyncOrchestrator

Initialize orchestrator

Parameters:

  • cache_manager (Molecules::CacheManager, nil) (defaults to: nil)

    Cache manager

  • output (IO) (defaults to: $stdout)

    Output stream for messages



19
20
21
22
23
# File 'lib/ace/support/models/organisms/provider_sync_orchestrator.rb', line 19

def initialize(cache_manager: nil, output: $stdout)
  @cache_manager = cache_manager || Molecules::CacheManager.new
  @diff_generator = Molecules::ProviderSyncDiff.new(cache_manager: @cache_manager)
  @output = output
end

Instance Attribute Details

#diff_generatorObject (readonly)

Returns the value of attribute diff_generator.



14
15
16
# File 'lib/ace/support/models/organisms/provider_sync_orchestrator.rb', line 14

def diff_generator
  @diff_generator
end

#outputObject (readonly)

Returns the value of attribute output.



14
15
16
# File 'lib/ace/support/models/organisms/provider_sync_orchestrator.rb', line 14

def output
  @output
end

Instance Method Details

#format_result(result) ⇒ String

Format diff results for display

Parameters:

  • result (Hash)

    Sync result

Returns:

  • (String)

    Formatted output



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/ace/support/models/organisms/provider_sync_orchestrator.rb', line 88

def format_result(result)
  lines = []
  lines << "Syncing provider configs with models.dev..."

  # Show date filter info
  if result[:show_all]
    lines << "(Showing all models)"
  elsif result[:since_date]
    lines << "(Showing models released after #{result[:since_date]})"
  end

  lines << ""

  result[:diff].each do |provider_name, diff|
    lines << format_provider_diff(provider_name, diff)
  end

  # Add summary
  summary = result[:summary]
  lines << ""
  lines << "Summary: #{summary[:added]} added, #{summary[:removed]} removed, " \
           "#{summary[:unchanged]} unchanged across #{summary[:providers_synced]} providers"

  if summary[:deprecated] > 0
    lines << "  (#{summary[:deprecated]} deprecated models flagged)"
  end

  if summary[:providers_skipped] > 0
    lines << "  (#{summary[:providers_skipped]} providers not found in models.dev)"
  end

  # Add action hints
  lines << ""
  if result[:changes_detected]
    if result[:applied]
      lines << "Changes applied to config files."
      lines << if result[:committed]
        "Changes committed."
      else
        "Run with --commit to commit changes."
      end
    else
      lines << "Run with --apply to update config files."
    end
  else
    lines << "All providers are up to date."
  end

  unless result[:show_all]
    lines << "Run with --all to see all models (not just new releases)."
  end

  lines.join("\n")
end

#sync(config_dir: nil, provider: nil, apply: false, commit: false, show_all: false, since: nil) ⇒ Hash

Run the sync-providers workflow

Parameters:

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

    Override config directory

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

    Limit to specific provider

  • apply (Boolean) (defaults to: false)

    Apply changes to files

  • commit (Boolean) (defaults to: false)

    Commit changes via ace-git-commit

  • show_all (Boolean) (defaults to: false)

    Show all models regardless of release date

  • since (String, Date, nil) (defaults to: nil)

    Only show models released after this date

Returns:

  • (Hash)

    Result with status and details



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/ace/support/models/organisms/provider_sync_orchestrator.rb', line 33

def sync(config_dir: nil, provider: nil, apply: false, commit: false, show_all: false, since: nil)
  # Ensure cache is fresh
  ensure_cache_fresh

  # Read current provider configs
  current_configs = Atoms::ProviderConfigReader.read_all(config_dir: config_dir)

  if current_configs.empty?
    return {
      status: :error,
      message: "No provider configs found. Check config directory."
    }
  end

  # Parse since date if provided
  since_date = parse_since_date(since)

  # Generate diff
  diff_results = @diff_generator.generate(
    current_configs,
    provider_filter: provider,
    since_date: since_date,
    show_all: show_all
  )

  # Build result
  result = {
    status: :ok,
    diff: diff_results,
    summary: @diff_generator.summary(diff_results),
    changes_detected: @diff_generator.any_changes?(diff_results),
    applied: false,
    committed: false,
    show_all: show_all,
    since_date: since_date
  }

  # Apply changes if requested
  if apply && result[:changes_detected]
    apply_result = apply_changes(diff_results, current_configs)
    result[:applied] = apply_result[:success]
    result[:apply_errors] = apply_result[:errors] if apply_result[:errors].any?

    # Commit if requested and apply succeeded
    if commit && result[:applied]
      result[:committed] = commit_changes(result[:summary])
    end
  end

  result
end