Class: RosettAi::Migration::XdgMigrator
- Inherits:
-
Object
- Object
- RosettAi::Migration::XdgMigrator
- Defined in:
- lib/rosett_ai/migration/xdg_migrator.rb
Overview
Migrates behaviour/schema files from legacy ~/.claude/conf/ to XDG-compliant ~/.config/rosett-ai/conf/.
Created after WP#943: global compile scope was reading from the installation directory because init placed files at ~/.claude/conf/ instead of the XDG path specified in scope_hierarchy.yml.
Constant Summary collapse
- LEGACY_CONF =
File.('~/.claude/conf')
- MIGRATED_SUFFIX =
'.migrated-to-xdg'
Instance Attribute Summary collapse
-
#legacy_dir ⇒ Object
readonly
Returns the value of attribute legacy_dir.
-
#migrated ⇒ Object
readonly
Returns the value of attribute migrated.
-
#xdg_dir ⇒ Object
readonly
Returns the value of attribute xdg_dir.
Instance Method Summary collapse
-
#initialize ⇒ XdgMigrator
constructor
A new instance of XdgMigrator.
-
#migrate! ⇒ Array<String>
Performs the migration: copy files, then rename legacy directory.
-
#migration_needed? ⇒ Boolean
Detects whether migration is needed.
-
#warning_message ⇒ String
Returns a user-facing warning message about the pending migration.
Constructor Details
#initialize ⇒ XdgMigrator
Returns a new instance of XdgMigrator.
22 23 24 25 26 |
# File 'lib/rosett_ai/migration/xdg_migrator.rb', line 22 def initialize @legacy_dir = Pathname.new(LEGACY_CONF) @xdg_dir = RosettAi.paths.rai_conf_dir @migrated = [] end |
Instance Attribute Details
#legacy_dir ⇒ Object (readonly)
Returns the value of attribute legacy_dir.
20 21 22 |
# File 'lib/rosett_ai/migration/xdg_migrator.rb', line 20 def legacy_dir @legacy_dir end |
#migrated ⇒ Object (readonly)
Returns the value of attribute migrated.
20 21 22 |
# File 'lib/rosett_ai/migration/xdg_migrator.rb', line 20 def migrated @migrated end |
#xdg_dir ⇒ Object (readonly)
Returns the value of attribute xdg_dir.
20 21 22 |
# File 'lib/rosett_ai/migration/xdg_migrator.rb', line 20 def xdg_dir @xdg_dir end |
Instance Method Details
#migrate! ⇒ Array<String>
Performs the migration: copy files, then rename legacy directory.
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rosett_ai/migration/xdg_migrator.rb', line 45 def migrate! @migrated = [] FileUtils.mkdir_p(xdg_dir.join('behaviour')) FileUtils.mkdir_p(xdg_dir.join('schemas')) migrate_directory('behaviour', '*.yml') migrate_directory('schemas', '*.json') migrate_file('adopt_redactions.yml') mark_legacy_migrated @migrated end |
#migration_needed? ⇒ Boolean
Detects whether migration is needed.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rosett_ai/migration/xdg_migrator.rb', line 31 def migration_needed? return false unless legacy_dir.join('behaviour').exist? return false if legacy_dir.basename.to_s.end_with?(MIGRATED_SUFFIX) legacy_files = Dir.glob(legacy_dir.join('behaviour', '*.yml')) return false if legacy_files.empty? xdg_files = xdg_dir.join('behaviour').exist? ? Dir.glob(xdg_dir.join('behaviour', '*.yml')) : [] xdg_files.empty? || legacy_has_newer_files?(legacy_files, xdg_files) end |
#warning_message ⇒ String
Returns a user-facing warning message about the pending migration.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rosett_ai/migration/xdg_migrator.rb', line 61 def legacy_count = Dir.glob(legacy_dir.join('behaviour', '*.yml')).size <<~MSG.strip [MIGRATION] Found #{legacy_count} behaviour file(s) at legacy path: #{legacy_dir}/behaviour/ These will be migrated to XDG-compliant path: #{xdg_dir}/behaviour/ Original files will be preserved at #{legacy_dir}#{MIGRATED_SUFFIX}/ MSG end |