Class: Baid::SubAgentWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/baid/sub_agent_writer.rb

Constant Summary collapse

AGENT_SUB_AGENT_DIRS =
{
  "claude_code" => File.join(".claude", "agents"),
  "cursor" => File.join(".cursor", "agents"),
  "opencode" => File.join(".opencode", "agents")
}.freeze

Class Method Summary collapse

Class Method Details

.write(agent_configs, agents, project_dir = ".") ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/baid/sub_agent_writer.rb', line 11

def self.write(agent_configs, agents, project_dir = ".")
  agents.each do |agent|
    dir_template = AGENT_SUB_AGENT_DIRS[agent[:name]]
    next unless dir_template

    config = agent_configs[agent[:name]]
    next unless config&.dig("sub_agents")

    full_dir = File.join(project_dir, dir_template)
    FileUtils.mkdir_p(full_dir)

    config["sub_agents"].each do |sub_agent|
      filename = File.basename(sub_agent["filename"].to_s)
      next if filename.empty?

      file_path = File.join(full_dir, filename)
      File.write(file_path, sub_agent["content"])
    end
  end
end