Class: Aidp::Harness::DeprecationCache

Inherits:
Object
  • Object
show all
Defined in:
lib/aidp/harness/deprecation_cache.rb

Overview

Manages a dynamic cache of deprecated models detected at runtime When deprecation errors are detected from provider APIs, models are added to this cache with metadata (replacement, detected date, etc.)

Defined Under Namespace

Classes: CacheError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cache_path: nil, root_dir: nil) ⇒ DeprecationCache

Returns a new instance of DeprecationCache.



16
17
18
19
20
21
# File 'lib/aidp/harness/deprecation_cache.rb', line 16

def initialize(cache_path: nil, root_dir: nil)
  @root_dir = root_dir || safe_root_dir
  @cache_path = cache_path || default_cache_path
  @cache_data = nil
  ensure_cache_directory
end

Instance Attribute Details

#cache_pathObject (readonly)

Returns the value of attribute cache_path.



14
15
16
# File 'lib/aidp/harness/deprecation_cache.rb', line 14

def cache_path
  @cache_path
end

Instance Method Details

#add_deprecated_model(provider:, model_id:, replacement: nil, reason: nil) ⇒ Object

Add a deprecated model to the cache

Parameters:

  • provider (String)

    Provider name (e.g., “anthropic”)

  • model_id (String)

    Deprecated model ID

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

    Replacement model ID (if known)

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

    Deprecation reason/message



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/aidp/harness/deprecation_cache.rb', line 28

def add_deprecated_model(provider:, model_id:, replacement: nil, reason: nil)
  load_cache unless @cache_data

  @cache_data["providers"][provider] ||= {}
  @cache_data["providers"][provider][model_id] = {
    "deprecated_at" => Time.now.iso8601,
    "replacement" => replacement,
    "reason" => reason
  }.compact

  save_cache
  Aidp.log_info("deprecation_cache", "Added deprecated model",
    provider: provider, model: model_id, replacement: replacement)
end

#clear!Object

Clear all cached deprecations



95
96
97
98
99
# File 'lib/aidp/harness/deprecation_cache.rb', line 95

def clear!
  @cache_data = default_cache_structure
  save_cache
  Aidp.log_info("deprecation_cache", "Cleared all deprecations")
end

#deprecated?(provider:, model_id:) ⇒ Boolean

Check if a model is deprecated

Parameters:

  • provider (String)

    Provider name

  • model_id (String)

    Model ID to check

Returns:

  • (Boolean)


47
48
49
50
# File 'lib/aidp/harness/deprecation_cache.rb', line 47

def deprecated?(provider:, model_id:)
  load_cache unless @cache_data
  @cache_data.dig("providers", provider, model_id) != nil
end

#deprecated_models(provider:) ⇒ Array<String>

Get all deprecated models for a provider

Parameters:

  • provider (String)

    Provider name

Returns:

  • (Array<String>)

    List of deprecated model IDs



64
65
66
67
# File 'lib/aidp/harness/deprecation_cache.rb', line 64

def deprecated_models(provider:)
  load_cache unless @cache_data
  (@cache_data.dig("providers", provider) || {}).keys
end

#info(provider:, model_id:) ⇒ Hash?

Get full deprecation info for a model

Parameters:

  • provider (String)

    Provider name

  • model_id (String)

    Model ID

Returns:

  • (Hash, nil)

    Deprecation metadata or nil



89
90
91
92
# File 'lib/aidp/harness/deprecation_cache.rb', line 89

def info(provider:, model_id:)
  load_cache unless @cache_data
  @cache_data.dig("providers", provider, model_id)
end

#remove_deprecated_model(provider:, model_id:) ⇒ Object

Remove a model from the deprecated cache Useful if a model comes back or was incorrectly marked

Parameters:

  • provider (String)

    Provider name

  • model_id (String)

    Model ID to remove



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/aidp/harness/deprecation_cache.rb', line 73

def remove_deprecated_model(provider:, model_id:)
  load_cache unless @cache_data
  return unless @cache_data.dig("providers", provider, model_id)

  @cache_data["providers"][provider].delete(model_id)
  @cache_data["providers"].delete(provider) if @cache_data["providers"][provider].empty?

  save_cache
  Aidp.log_info("deprecation_cache", "Removed deprecated model",
    provider: provider, model: model_id)
end

#replacement_for(provider:, model_id:) ⇒ String?

Get replacement model for a deprecated model

Parameters:

  • provider (String)

    Provider name

  • model_id (String)

    Deprecated model ID

Returns:

  • (String, nil)

    Replacement model ID or nil



56
57
58
59
# File 'lib/aidp/harness/deprecation_cache.rb', line 56

def replacement_for(provider:, model_id:)
  load_cache unless @cache_data
  @cache_data.dig("providers", provider, model_id, "replacement")
end

#statsHash

Get cache statistics

Returns:

  • (Hash)

    Statistics about cached deprecations



103
104
105
106
107
108
109
110
# File 'lib/aidp/harness/deprecation_cache.rb', line 103

def stats
  load_cache unless @cache_data
  {
    providers: @cache_data["providers"].keys.sort,
    total_deprecated: @cache_data["providers"].sum { |_, models| models.size },
    by_provider: @cache_data["providers"].transform_values(&:size)
  }
end