Module: RailsAiContext::LegacyCleanup

Defined in:
lib/rails_ai_context/legacy_cleanup.rb

Overview

One-time cleanup for files that were removed in a breaking release. Handles v5.0.0’s removal of design-system UI pattern rules and accessibility rule files. Never deletes without explicit user consent; in non-TTY environments prints a warning instead of prompting.

Constant Summary collapse

LEGACY_FILES =

Each entry: { path: relative_path, ai_tool: :claude|:cursor|:copilot }

[
  { path: ".claude/rules/rails-ui-patterns.md",                          ai_tool: :claude  },
  { path: ".cursor/rules/rails-ui-patterns.mdc",                         ai_tool: :cursor  },
  { path: ".github/instructions/rails-ui-patterns.instructions.md",      ai_tool: :copilot },
  { path: ".claude/rules/rails-accessibility.md",                        ai_tool: :claude  }
].freeze

Class Method Summary collapse

Class Method Details

.prompt_legacy_files(ai_tools, root:, io: $stderr, warn_only: false) ⇒ Object

Parameters:

  • ai_tools (Array<Symbol>, nil)

    formats user has selected; nil means all

  • root (String, Pathname)

    project root directory

  • io (IO) (defaults to: $stderr)

    stream for output (stderr by default)

  • warn_only (Boolean) (defaults to: false)

    skip prompt even if TTY, only print warning



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rails_ai_context/legacy_cleanup.rb', line 23

def prompt_legacy_files(ai_tools, root:, io: $stderr, warn_only: false)
  allowed = ai_tools ? Array(ai_tools).map(&:to_sym).to_set : nil

  present = LEGACY_FILES.filter_map do |entry|
    next if allowed && !allowed.include?(entry[:ai_tool])
    full = File.join(root.to_s, entry[:path])
    [ entry[:path], full ] if File.exist?(full)
  end
  return if present.empty?

  io.puts ""
  io.puts "Legacy files detected (removed in v5.0.0):"
  present.each { |(rel, _)| io.puts "  #{rel}" }
  io.puts ""
  io.puts "These files are no longer regenerated and contain stale guidance."

  if warn_only || !$stdin.tty?
    io.puts "Delete manually when ready:"
    io.puts "  rm -f #{present.map(&:first).join(' ')}"
    return
  end

  io.print "Delete them? [y/N]: "
  input = $stdin.gets&.strip&.downcase || "n"

  if input == "y" || input == "yes"
    require "fileutils"
    present.each do |(rel, full)|
      FileUtils.rm_f(full)
      io.puts "  Removed #{rel}"
    end
  else
    io.puts "  Kept. Delete manually when ready:"
    io.puts "    rm -f #{present.map(&:first).join(' ')}"
  end
end