Class: RosettAi::Thor::Tasks::BackfillUserYml

Inherits:
Thor
  • Object
show all
Defined in:
lib/rosett_ai/thor/tasks/backfill_user_yml.rb

Overview

Backfill user.yml from the live Claude Code settings.json.

Reads ~/.claude/settings.json and merges any permission entries or env vars not yet covered by the engine's user.yml source file. Shows a summary and prompts for confirmation before writing — never auto-applies unless --yes is given. Idempotent: re-running when nothing is uncovered is a no-op.

Constant Summary collapse

SETTINGS_PATH =
File.expand_path('~/.claude/settings.json')

Instance Method Summary collapse

Instance Method Details

#backfillvoid

This method returns an undefined value.

Run the backfill.

Raises:

  • (::Thor::Error)


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
84
85
86
87
# File 'lib/rosett_ai/thor/tasks/backfill_user_yml.rb', line 49

def backfill
  target_path = resolve_target
  raise ::Thor::Error, "settings.json not found at #{SETTINGS_PATH}" unless File.exist?(SETTINGS_PATH)

  unless File.exist?(target_path)
    raise ::Thor::Error,
          "user.yml not found at #{target_path}. Specify --target or install the engine."
  end

  settings  = JSON.parse(File.read(SETTINGS_PATH))
  user_yml  = YAML.safe_load_file(target_path)
  compiled  = extract_compiled_stub(user_yml)
  uncovered = find_uncovered(compiled, settings)

  if uncovered.empty?
    puts Rainbow('Nothing to backfill — user.yml already covers all entries.').green
    return
  end

  total = count_leaves(uncovered)
  say "Target : #{target_path}"
  say "Found #{total} entr#{total == 1 ? 'y' : 'ies'} not in user.yml:\n"
  print_uncovered(uncovered)
  say

  unless options[:yes]
    answer = ask("Apply #{total} entr#{total == 1 ? 'y' : 'ies'} to user.yml? [y/N]")
    unless answer.strip.downcase == 'y'
      say 'Aborted — no changes written.'
      return
    end
  end

  apply_uncovered!(user_yml, uncovered)
  warn_unmapped(uncovered)
  File.write(target_path, user_yml.to_yaml)
  say Rainbow("Wrote #{target_path} (#{total} entr#{total == 1 ? 'y' : 'ies'} added).").green
  say 'Run `raictl config compile --simulate --verbose` to preview compiled output.'
end