Class: RubynCode::SubAgents::Catalog

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyn_code/sub_agents/catalog.rb

Overview

Resolves sub-agent types by name. Ships the built-in ‘explore` and `worker` agents and discovers user-defined ones from markdown files, mirroring Claude Code’s ‘.claude/agents/*.md`:

<project>/.rubyn-code/agents/*.md   (project-local, takes priority)
~/.rubyn-code/agents/*.md           (user-global)

Frontmatter (all optional except a sensible default name):

name: reviewer
description: Reviews a diff for bugs
tools: read_file, grep, glob, bash   # omit → access-based default set
access: read                         # read | write (default: write)

The markdown body becomes the agent’s system prompt.

Constant Summary collapse

FRONTMATTER =
/\A---\s*\n(.+?\n)---\s*\n(.*)\z/m
NAME =
/\A[a-z0-9][a-z0-9_-]*\z/i
BASE_PROMPT =
'You are a Rubyn sub-agent. Complete your task efficiently and ' \
'return a clear summary of what you found or did.'
EXPLORE_PROMPT =
"#{BASE_PROMPT}\nYou have read-only access. Search, read files, and analyze. " \
'Do NOT attempt to write or modify anything.'.freeze
WORKER_PROMPT =
"#{BASE_PROMPT}\nYou have full read/write access. Make the changes needed, " \
'run tests if appropriate, and report what you did.'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(project_root: nil, home_dir: Config::Defaults::HOME_DIR) ⇒ Catalog

Returns a new instance of Catalog.



31
32
33
34
35
# File 'lib/rubyn_code/sub_agents/catalog.rb', line 31

def initialize(project_root: nil, home_dir: Config::Defaults::HOME_DIR)
  @project_root = project_root
  @home_dir = home_dir
  @custom = load_custom
end

Instance Method Details

#allArray<AgentType>

Returns all known agents (built-ins first).

Returns:

  • (Array<AgentType>)

    all known agents (built-ins first)



45
46
47
# File 'lib/rubyn_code/sub_agents/catalog.rb', line 45

def all
  builtin.values + @custom.values
end

#custom_namesArray<String>

Returns:

  • (Array<String>)


50
# File 'lib/rubyn_code/sub_agents/catalog.rb', line 50

def custom_names = @custom.keys

#get(name) ⇒ AgentType?

Parameters:

  • name (String, Symbol)

Returns:



39
40
41
42
# File 'lib/rubyn_code/sub_agents/catalog.rb', line 39

def get(name)
  key = name.to_s
  builtin[key] || @custom[key]
end