Class: TheLocal::TriggerWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/the_local/trigger_writer.rb

Overview

Writes the mandatory delegation trigger — the standing rule, read at the start of every session, that tells the host agent to delegate to its locals rather than work from memory. Generated from the registry’s providers, filtered to the host’s allowed gems. Plain Ruby; the Rails generator wraps it.

Constant Summary collapse

BEGIN_MARKER =
"<!-- the_local:begin -->"
END_MARKER =
"<!-- the_local:end -->"

Instance Method Summary collapse

Constructor Details

#initialize(registry:, destination:, allowed_gems:, filename: "CLAUDE.md") ⇒ TriggerWriter

Returns a new instance of TriggerWriter.



12
13
14
15
16
17
# File 'lib/the_local/trigger_writer.rb', line 12

def initialize(registry:, destination:, allowed_gems:, filename: "CLAUDE.md")
  @registry = registry
  @destination = destination
  @allowed_gems = allowed_gems
  @filename = filename
end

Instance Method Details

#callObject



19
20
21
22
23
# File 'lib/the_local/trigger_writer.rb', line 19

def call
  path = File.join(@destination, @filename)
  existing = File.exist?(path) ? File.read(path) : ""
  File.write(path, "#{merge(existing)}\n")
end

#ruleObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/the_local/trigger_writer.rb', line 25

def rule
  <<~MARKDOWN.chomp
    #{BEGIN_MARKER}
    ## Delegate to your locals

    This project has installed expert subagents. Before doing work yourself,
    check whether a local owns it and delegate — never work from memory on
    something a local covers:

    #{bullets.join("\n")}

    See each agent's description for specifics.
    #{END_MARKER}
  MARKDOWN
end