Module: RubynCode::CLI::Commands::CustomLoader
- Defined in:
- lib/rubyn_code/cli/commands/custom_loader.rb
Overview
Discovers user-defined slash commands from markdown files, mirroring Claude Code’s ‘.claude/commands/*.md`:
<project>/.rubyn-code/commands/*.md (project-local, takes priority)
~/.rubyn-code/commands/*.md (user-global)
Each ‘deploy.md` becomes `/deploy`. Optional YAML frontmatter supplies the `description`; otherwise the first non-empty line is used. The body is the prompt template (see CommandTemplate for substitutions).
Constant Summary collapse
- FRONTMATTER =
/\A---\s*\n(.+?\n)---\s*\n(.*)\z/m- NAME =
/\A[a-z0-9][a-z0-9_-]*\z/i
Class Method Summary collapse
-
.load_all(project_root:, home_dir: Config::Defaults::HOME_DIR) ⇒ Array<CustomCommand>
Unique commands (project overrides user).
- .load_dir(dir) ⇒ Object
Class Method Details
.load_all(project_root:, home_dir: Config::Defaults::HOME_DIR) ⇒ Array<CustomCommand>
Returns unique commands (project overrides user).
23 24 25 26 27 28 29 |
# File 'lib/rubyn_code/cli/commands/custom_loader.rb', line 23 def load_all(project_root:, home_dir: Config::Defaults::HOME_DIR) dirs = [ project_root && File.join(project_root, '.rubyn-code', 'commands'), File.join(home_dir, 'commands') ].compact dirs.flat_map { |dir| load_dir(dir) }.uniq(&:command_name) end |
.load_dir(dir) ⇒ Object
31 32 33 34 35 |
# File 'lib/rubyn_code/cli/commands/custom_loader.rb', line 31 def load_dir(dir) return [] unless Dir.exist?(dir) Dir.glob(File.join(dir, '*.md')).filter_map { |path| build(path) } end |