Class: SpaceArchitect::Harness::OpenCodeHarness

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

Instance Method Summary collapse

Constructor Details

#initialize(model:, max_turns:, bin: nil, config_dir:, effort: nil) ⇒ OpenCodeHarness

Returns a new instance of OpenCodeHarness.



81
82
83
84
85
86
87
# File 'lib/space_architect/harness.rb', line 81

def initialize(model:, max_turns:, bin: nil, config_dir:, effort: nil)
  @model      = model
  @max_turns  = max_turns
  @bin        = bin || ENV.fetch("ARCHITECT_OPENCODE_BIN", "opencode")
  @config_dir = Pathname.new(config_dir)
  @effort     = effort
end

Instance Method Details

#builder_configObject

Returns the agent config hash (deterministic, unit-testable).



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/space_architect/harness.rb', line 90

def builder_config
  cfg = {
    "agent" => {
      "builder" => {
        "steps" => @max_turns,
        "permission" => {
          "bash" => {
            "git commit *"   => "deny",
            "git push *"     => "deny",
            "git reset *"    => "deny",
            "git rebase *"   => "deny",
            "git checkout *" => "deny",
            "*"              => "allow"
          }
        }
      }
    }
  }
  cfg.merge!(reasoning_provider_config) if @effort
  cfg
end

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



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/space_architect/harness.rb', line 112

def run(prompt_path:, run_log_path:, chdir:)
  prompt_path  = Pathname.new(prompt_path)
  run_log_path = Pathname.new(run_log_path)
  config_path  = write_config

  env = {
    "OPENCODE_CONFIG"                 => config_path.to_s,
    "OPENCODE_DISABLE_PROJECT_CONFIG" => "1"
  }

  File.open(prompt_path, "r") do |prompt_io|
    File.open(run_log_path, "w") do |log|
      status = Sync do
        Async::Process.spawn(env, *argv(chdir),
                             chdir: chdir.to_s, in: prompt_io, out: log, err: log)
      end
      status.exitstatus
    end
  end
end