Class: Space::Architect::Harness::ClaudeCodeHarness

Inherits:
Object
  • Object
show all
Defined in:
lib/space_architect/harness.rb

Constant Summary collapse

ALLOWED_TOOLS =
"Read,Edit,Write,Grep,Glob,Bash,WebSearch,WebFetch"
DISALLOWED_TOOLS =
[
  "Bash(git commit:*)", "Bash(git push:*)", "Bash(git reset:*)",
  "Bash(git merge:*)",  "Bash(git rebase:*)", "Bash(git checkout:*)",
  "Bash(git branch:*)"
].join(",")

Instance Method Summary collapse

Constructor Details

#initialize(model:, max_turns:, bin: nil, allowed_tools: ALLOWED_TOOLS, disallowed_tools: DISALLOWED_TOOLS) ⇒ ClaudeCodeHarness

Returns a new instance of ClaudeCodeHarness.



48
49
50
51
52
53
54
55
# File 'lib/space_architect/harness.rb', line 48

def initialize(model:, max_turns:, bin: nil,
               allowed_tools: ALLOWED_TOOLS, disallowed_tools: DISALLOWED_TOOLS)
  @model            = model
  @max_turns        = max_turns
  @bin              = bin || ENV.fetch("ARCHITECT_CLAUDE_BIN", "claude")
  @allowed_tools    = allowed_tools
  @disallowed_tools = disallowed_tools
end

Instance Method Details

#run(prompt_path:, run_log_path:, chdir:, push_url: nil, push_token: nil, push_client: nil) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/space_architect/harness.rb', line 57

def run(prompt_path:, run_log_path:, chdir:, push_url: nil, push_token: nil, push_client: nil)
  prompt_path  = Pathname.new(prompt_path)
  run_log_path = Pathname.new(run_log_path)

  File.open(prompt_path, "r") do |prompt_io|
    File.open(run_log_path, "w") do |log|
      r, w = IO.pipe
      Sync do
        child = Async::Process::Child.new(*argv, chdir: chdir.to_s, in: prompt_io, out: w, err: log)
        w.close
        tasks = start_tee(r, log, push_url: push_url, push_token: push_token, push_client: push_client)
        status = child.wait
        tasks.each(&:wait)
        status.exitstatus
      end
    end
  end
end

#run_detached(prompt_path:, run_log_path:, chdir:) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/space_architect/harness.rb', line 76

def run_detached(prompt_path:, run_log_path:, chdir:)
  prompt_path  = Pathname.new(prompt_path)
  run_log_path = Pathname.new(run_log_path)

  prompt_io = File.open(prompt_path, "r")
  log       = File.open(run_log_path, "w")
  begin
    pid = Process.spawn(*argv, chdir: chdir.to_s, pgroup: true,
                        in: prompt_io, out: log, err: log)
    Process.detach(pid)
  ensure
    prompt_io.close
    log.close
  end
  pid
end