Class: Aidp::Harness::DeprecationCache
- Inherits:
-
Object
- Object
- Aidp::Harness::DeprecationCache
- 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.)
This class is designed to be extractable to the agent-harness gem. It uses dependency injection for logging to decouple from AIDP.
Defined Under Namespace
Classes: CacheError
Constant Summary collapse
- COMPONENT =
Component name for logging
"deprecation_cache"
Instance Attribute Summary collapse
-
#cache_path ⇒ Object
readonly
Returns the value of attribute cache_path.
Instance Method Summary collapse
-
#add_deprecated_model(provider:, model_id:, replacement: nil, reason: nil) ⇒ Object
Add a deprecated model to the cache.
-
#clear! ⇒ Object
Clear all cached deprecations.
-
#deprecated?(provider:, model_id:) ⇒ Boolean
Check if a model is deprecated.
-
#deprecated_models(provider:) ⇒ Array<String>
Get all deprecated models for a provider.
-
#info(provider:, model_id:) ⇒ Hash?
Get full deprecation info for a model.
-
#initialize(cache_path: nil, root_dir: nil, logger: nil) ⇒ DeprecationCache
constructor
Initialize the deprecation cache.
-
#remove_deprecated_model(provider:, model_id:) ⇒ Object
Remove a model from the deprecated cache Useful if a model comes back or was incorrectly marked.
-
#replacement_for(provider:, model_id:) ⇒ String?
Get replacement model for a deprecated model.
-
#stats ⇒ Hash
Get cache statistics.
Constructor Details
#initialize(cache_path: nil, root_dir: nil, logger: nil) ⇒ DeprecationCache
Initialize the deprecation cache.
All parameters are optional for backward compatibility. Existing callers that don't pass a logger will use AIDP's built-in logging.
31 32 33 34 35 36 37 |
# File 'lib/aidp/harness/deprecation_cache.rb', line 31 def initialize(cache_path: nil, root_dir: nil, logger: nil) @root_dir = root_dir || safe_root_dir @cache_path = cache_path || default_cache_path @cache_data = nil @logger = logger ensure_cache_directory end |
Instance Attribute Details
#cache_path ⇒ Object (readonly)
Returns the value of attribute cache_path.
20 21 22 |
# File 'lib/aidp/harness/deprecation_cache.rb', line 20 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
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/aidp/harness/deprecation_cache.rb', line 44 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 log_info("added_deprecated_model", provider: provider, model: model_id, replacement: replacement) end |
#clear! ⇒ Object
Clear all cached deprecations
109 110 111 112 113 |
# File 'lib/aidp/harness/deprecation_cache.rb', line 109 def clear! @cache_data = default_cache_structure save_cache log_info("cleared_all_deprecations") end |
#deprecated?(provider:, model_id:) ⇒ Boolean
Check if a model is deprecated
62 63 64 65 |
# File 'lib/aidp/harness/deprecation_cache.rb', line 62 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
79 80 81 82 |
# File 'lib/aidp/harness/deprecation_cache.rb', line 79 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
103 104 105 106 |
# File 'lib/aidp/harness/deprecation_cache.rb', line 103 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
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/aidp/harness/deprecation_cache.rb', line 88 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 log_info("removed_deprecated_model", provider: provider, model: model_id) end |
#replacement_for(provider:, model_id:) ⇒ String?
Get replacement model for a deprecated model
71 72 73 74 |
# File 'lib/aidp/harness/deprecation_cache.rb', line 71 def replacement_for(provider:, model_id:) load_cache unless @cache_data @cache_data.dig("providers", provider, model_id, "replacement") end |
#stats ⇒ Hash
Get cache statistics
117 118 119 120 121 122 123 124 |
# File 'lib/aidp/harness/deprecation_cache.rb', line 117 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 |