Class: RubynCode::CLI::Commands::CustomCommand
- Inherits:
-
Object
- Object
- RubynCode::CLI::Commands::CustomCommand
- Defined in:
- lib/rubyn_code/cli/commands/custom_command.rb
Overview
A slash command defined by a user markdown file (loaded by CustomLoader). Unlike the built-in commands — which are registered as classes — this is a ready instance: the Registry dispatches it directly.
Executing it renders the template (argument / bash substitution) and sends the result to the agent as a normal prompt.
Instance Attribute Summary collapse
-
#allowed_tools ⇒ Array<String>?
readonly
Tool names the command restricts to.
-
#argument_hint ⇒ String?
readonly
Argument hint shown next to the name in /help.
-
#description ⇒ String
readonly
One-line description for /help.
-
#model ⇒ String?
readonly
Model override for this prompt.
-
#name ⇒ String
readonly
Command name without the leading slash.
-
#source ⇒ String?
readonly
Originating file path.
Instance Method Summary collapse
- #aliases ⇒ Object
- #all_names ⇒ Object
- #command_name ⇒ Object
- #execute(args, ctx) ⇒ nil
-
#help_label ⇒ Object
Render the help label, including [hint] when frontmatter provides one.
- #hidden? ⇒ Boolean
-
#initialize(name:, description:, body:, source: nil, argument_hint: nil, allowed_tools: nil, model: nil) ⇒ CustomCommand
constructor
rubocop:disable Metrics/ParameterLists -- explicit kwargs document the frontmatter surface.
-
#overrides_model? ⇒ Boolean
True if the frontmatter overrode the model.
-
#restricts_tools? ⇒ Boolean
True if the frontmatter restricted the tool set.
Constructor Details
#initialize(name:, description:, body:, source: nil, argument_hint: nil, allowed_tools: nil, model: nil) ⇒ CustomCommand
rubocop:disable Metrics/ParameterLists -- explicit kwargs document the frontmatter surface
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 26 def initialize(name:, description:, body:, # rubocop:disable Metrics/ParameterLists -- explicit kwargs document the frontmatter surface source: nil, argument_hint: nil, allowed_tools: nil, model: nil) @name = name @description = description @template = CommandTemplate.new(body) @argument_hint = argument_hint @allowed_tools = allowed_tools @model = model @source = source end |
Instance Attribute Details
#allowed_tools ⇒ Array<String>? (readonly)
Returns tool names the command restricts to.
20 21 22 |
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 20 def allowed_tools @allowed_tools end |
#argument_hint ⇒ String? (readonly)
Returns argument hint shown next to the name in /help.
18 19 20 |
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 18 def argument_hint @argument_hint end |
#description ⇒ String (readonly)
Returns one-line description for /help.
16 17 18 |
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 16 def description @description end |
#model ⇒ String? (readonly)
Returns model override for this prompt.
22 23 24 |
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 22 def model @model end |
#name ⇒ String (readonly)
Returns command name without the leading slash.
14 15 16 |
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 14 def name @name end |
#source ⇒ String? (readonly)
Returns originating file path.
24 25 26 |
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 24 def source @source end |
Instance Method Details
#aliases ⇒ Object
39 |
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 39 def aliases = [].freeze |
#all_names ⇒ Object
41 |
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 41 def all_names = [command_name].freeze |
#command_name ⇒ Object
38 |
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 38 def command_name = "/#{@name}" |
#execute(args, ctx) ⇒ nil
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 64 def execute(args, ctx) rendered = @template.render(args) if restricts_tools? ctx.with_allowed_tools(@allowed_tools) do ctx.with_optional_model(@model) do ctx.(rendered) end end elsif overrides_model? ctx.with_optional_model(@model) do ctx.(rendered) end else ctx.(rendered) end nil end |
#help_label ⇒ Object
Render the help label, including [hint] when frontmatter provides one. The argument_hint is expected to be the placeholder text already wrapped in [ ] (e.g. "[env]") — we don't add another set of brackets.
46 47 48 49 |
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 46 def help_label hint = @argument_hint.to_s.strip hint.empty? ? description : "#{description} #{hint}" end |
#hidden? ⇒ Boolean
40 |
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 40 def hidden? = false |
#overrides_model? ⇒ Boolean
Returns true if the frontmatter overrode the model.
57 58 59 |
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 57 def overrides_model? !@model.to_s.strip.empty? end |
#restricts_tools? ⇒ Boolean
Returns true if the frontmatter restricted the tool set.
52 53 54 |
# File 'lib/rubyn_code/cli/commands/custom_command.rb', line 52 def restricts_tools? !@allowed_tools.nil? && !@allowed_tools.empty? end |