Module: Clacky::Utils::WorkspaceRules
- Defined in:
- lib/clacky/utils/workspace_rules.rb
Overview
Discovers .clackyrules files in the workspace. Used by both SystemPromptBuilder (rules injection) and WelcomeBanner (UI display).
Constant Summary collapse
- RULES_FILENAMES =
[".clackyrules", ".cursorrules", "CLAUDE.md"].freeze
- SUB_PROJECT_SUMMARY_LINES =
5
Class Method Summary collapse
-
.find_main(dir) ⇒ Hash?
Find the main rules file in the given directory.
-
.find_sub_projects(dir) ⇒ Array<Hash>
Find all sub-project .clackyrules in immediate subdirectories.
Class Method Details
.find_main(dir) ⇒ Hash?
Find the main rules file in the given directory.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/clacky/utils/workspace_rules.rb', line 14 def self.find_main(dir) RULES_FILENAMES.each do |filename| path = File.join(dir, filename) next unless File.exist?(path) content = File.read(path).strip return { path: path, name: filename, content: content } unless content.empty? end nil end |
.find_sub_projects(dir) ⇒ Array<Hash>
Find all sub-project .clackyrules in immediate subdirectories.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/clacky/utils/workspace_rules.rb', line 28 def self.find_sub_projects(dir) Dir.glob(File.join(dir, "*", ".clackyrules")).sort.filter_map do |rules_path| content = File.read(rules_path).strip next if content.empty? sub_name = File.basename(File.dirname(rules_path)) summary = content.lines.first(SUB_PROJECT_SUMMARY_LINES).map(&:chomp).join("\n") { sub_name: sub_name, relative_path: "#{sub_name}/.clackyrules", content: content, summary: summary } end end |