Class: Agent::Workspace::Container

Inherits:
Local
  • Object
show all
Defined in:
app/services/agent/workspace.rb

Overview

EXPERIMENTAL — written against the cage model; needs a host with Docker to exercise. Git stays host-side; only the agent process is jailed.

Constant Summary collapse

WORKDIR =
"/workspace/repo"

Constants inherited from Local

Local::ROOT

Instance Attribute Summary

Attributes inherited from Local

#card, #path

Instance Method Summary collapse

Methods inherited from Local

#ahead_of_default?, attach, #commit_all!, #commits_since, #head, #initialize, provision, #provision, #push!, #salvage_dirty_tree!

Constructor Details

This class inherits a constructor from Agent::Workspace::Local

Instance Method Details

#agent_spawn(cmd) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'app/services/agent/workspace.rb', line 127

def agent_spawn(cmd)
  docker = ["docker", "run", "--rm", "-i",
            "--name", container_name,
            "--label", "cardinal=agent",
            "-v", "#{path}:#{WORKDIR}",
            "-w", WORKDIR]
  # Value-embedded because the runner nils the key in the client env
  # (visible in ps on the host — acceptable for the experimental tier).
  # Instance OAuth token (cardinal up account link) or raw API key —
  # whichever this instance runs on.
  docker += ["-e", "ANTHROPIC_API_KEY=#{ENV["ANTHROPIC_API_KEY"]}"] if ENV["ANTHROPIC_API_KEY"].present?
  docker += ["-e", "CLAUDE_CODE_OAUTH_TOKEN=#{ENV["CLAUDE_CODE_OAUTH_TOKEN"]}"] if ENV["CLAUDE_CODE_OAUTH_TOKEN"].present?
  [docker + [image] + cmd, {}]
end

#container_nameObject



125
# File 'app/services/agent/workspace.rb', line 125

def container_name = "cardinal-card-#{card.number}"

#imageObject



124
# File 'app/services/agent/workspace.rb', line 124

def image = ENV.fetch("CARDINAL_AGENT_IMAGE", "cardinal-agent:latest")

#teardownObject



142
143
144
# File 'app/services/agent/workspace.rb', line 142

def teardown
  Open3.capture2e("docker", "rm", "-f", container_name)
end