Module: RosettAi::Init::FileCopier

Defined in:
lib/rosett_ai/init/file_copier.rb

Overview

Helper module for copying files during initialization

Class Method Summary collapse

Class Method Details

.copy_conf_assets(source_root, conf_base, copied) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rosett_ai/init/file_copier.rb', line 35

def copy_conf_assets(source_root, conf_base, copied)
  FileUtils.mkdir_p(File.join(conf_base, 'behaviour'))
  FileUtils.mkdir_p(File.join(conf_base, 'schemas'))
  # Copy template behaviours (not internal conf/behaviour/ files)
  copy_glob_files(source_root.join('share', 'templates', 'behaviour'),
                  File.join(conf_base, 'behaviour'), '*.yml', 'conf/behaviour', copied)
  copy_glob_files(source_root.join('conf', 'schemas'),
                  File.join(conf_base, 'schemas'), '*.json', 'conf/schemas', copied)
  copy_if_new(source_root.join('conf', 'adopt_redactions.yml'),
              File.join(conf_base, 'adopt_redactions.yml'),
              copied, 'conf/adopt_redactions.yml')
end

.copy_directory(source, target, copied, name) ⇒ Object



63
64
65
66
67
68
# File 'lib/rosett_ai/init/file_copier.rb', line 63

def copy_directory(source, target, copied, name)
  return unless Dir.exist?(source)

  FileUtils.cp_r("#{source}/.", target)
  copied << name
end

.copy_executable(source, target, copied, name) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/rosett_ai/init/file_copier.rb', line 55

def copy_executable(source, target, copied, name)
  return unless File.exist?(source)

  FileUtils.cp(source, target)
  FileUtils.chmod(0o755, target)
  copied << name
end

.copy_glob_files(source_dir, target_dir, pattern, prefix, copied) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/rosett_ai/init/file_copier.rb', line 70

def copy_glob_files(source_dir, target_dir, pattern, prefix, copied)
  return unless Dir.exist?(source_dir)

  Dir.glob(File.join(source_dir, pattern)).each do |file|
    basename = File.basename(file)
    target = File.join(target_dir, basename)

    if File.exist?(target)
      warn "  skipped #{prefix}/#{basename} (already exists)"
      next
    end

    FileUtils.cp(file, target)
    copied << "#{prefix}/#{basename}"
  end
end

.copy_global_assets(base_dir) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rosett_ai/init/file_copier.rb', line 14

def copy_global_assets(base_dir)
  root = RosettAi.root
  copied = []
  copy_single_file(root.join('settings.json'), File.join(base_dir, 'settings.json'), copied,
                   'settings.json')
  copy_executable(root.join('bin', 'rai'), File.join(base_dir, 'bin', 'rai'), copied, 'bin/raictl')
  copy_directory(root.join('lib', 'rosett_ai'), File.join(base_dir, 'lib', 'rosett_ai'), copied, 'lib/rosett_ai/')
  # Conf assets (behaviours, schemas) go to XDG-compliant ~/.config/rosett-ai/conf/
  xdg_conf = RosettAi.paths.rai_conf_dir.to_s
  copy_conf_assets(root, xdg_conf, copied)
  copy_glob_files(root.join('doc'), File.join(base_dir, 'doc'), '*.md', 'doc', copied)
  copied
end

.copy_if_new(source, target, copied, name) ⇒ Object



87
88
89
90
91
92
# File 'lib/rosett_ai/init/file_copier.rb', line 87

def copy_if_new(source, target, copied, name)
  return unless File.exist?(source) && !File.exist?(target)

  FileUtils.cp(source, target)
  copied << name
end

.copy_local_assets(base_dir) ⇒ Object



28
29
30
31
32
33
# File 'lib/rosett_ai/init/file_copier.rb', line 28

def copy_local_assets(base_dir)
  copied = []
  # Local scope copies to .claude/conf/ (not XDG)
  copy_conf_assets(RosettAi.root, File.join(base_dir, 'conf'), copied)
  copied
end

.copy_single_file(source, target, copied, name) ⇒ Object



48
49
50
51
52
53
# File 'lib/rosett_ai/init/file_copier.rb', line 48

def copy_single_file(source, target, copied, name)
  return if File.exist?(target) || !File.exist?(source)

  FileUtils.cp(source, target)
  copied << name
end