tinker-agent 1.0.27 โ 1.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/run-tinker-agent.rb +70 -18
package/package.json
CHANGED
package/run-tinker-agent.rb
CHANGED
|
@@ -12,11 +12,18 @@
|
|
|
12
12
|
# - tinker.env.rb in project root (gitignored)
|
|
13
13
|
|
|
14
14
|
require "json"
|
|
15
|
+
require "fileutils"
|
|
15
16
|
|
|
16
17
|
# Load agent configs
|
|
17
18
|
require_relative "agents"
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
def image_name(config)
|
|
21
|
+
if config["project_id"]
|
|
22
|
+
"tinker-sandbox-#{config['project_id']}"
|
|
23
|
+
else
|
|
24
|
+
"tinker-sandbox"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
20
27
|
|
|
21
28
|
AGENT_TYPES = AGENT_CONFIGS.keys.freeze
|
|
22
29
|
|
|
@@ -84,7 +91,7 @@ def check_dockerfile!
|
|
|
84
91
|
end
|
|
85
92
|
end
|
|
86
93
|
|
|
87
|
-
def build_docker_image
|
|
94
|
+
def build_docker_image(config)
|
|
88
95
|
check_dockerfile!
|
|
89
96
|
|
|
90
97
|
user_id = `id -u`.strip
|
|
@@ -92,14 +99,42 @@ def build_docker_image
|
|
|
92
99
|
|
|
93
100
|
puts "๐๏ธ Building Docker image..."
|
|
94
101
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
102
|
+
# Handle .dockerignore.sandbox
|
|
103
|
+
dockerignore_sandbox = ".dockerignore.sandbox"
|
|
104
|
+
dockerignore_original = ".dockerignore"
|
|
105
|
+
dockerignore_backup = ".dockerignore.bak"
|
|
106
|
+
|
|
107
|
+
has_sandbox_ignore = File.exist?(dockerignore_sandbox)
|
|
108
|
+
has_original_ignore = File.exist?(dockerignore_original)
|
|
109
|
+
|
|
110
|
+
if has_sandbox_ignore
|
|
111
|
+
puts "๐ฆ Swapping .dockerignore with .dockerignore.sandbox..."
|
|
112
|
+
if has_original_ignore
|
|
113
|
+
FileUtils.mv(dockerignore_original, dockerignore_backup)
|
|
114
|
+
end
|
|
115
|
+
FileUtils.cp(dockerignore_sandbox, dockerignore_original)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
success = false
|
|
119
|
+
begin
|
|
120
|
+
success = system(
|
|
121
|
+
"docker", "build",
|
|
122
|
+
"--build-arg", "USER_ID=#{user_id}",
|
|
123
|
+
"--build-arg", "GROUP_ID=#{group_id}",
|
|
124
|
+
"-t", image_name(config),
|
|
125
|
+
"-f", "Dockerfile.sandbox",
|
|
126
|
+
"."
|
|
127
|
+
)
|
|
128
|
+
ensure
|
|
129
|
+
if has_sandbox_ignore
|
|
130
|
+
# Restore original state
|
|
131
|
+
FileUtils.rm(dockerignore_original) if File.exist?(dockerignore_original)
|
|
132
|
+
if has_original_ignore
|
|
133
|
+
FileUtils.mv(dockerignore_backup, dockerignore_original)
|
|
134
|
+
end
|
|
135
|
+
puts "๐งน Restored original .dockerignore"
|
|
136
|
+
end
|
|
137
|
+
end
|
|
103
138
|
|
|
104
139
|
unless success
|
|
105
140
|
puts "โ Failed to build Docker image"
|
|
@@ -194,7 +229,15 @@ def run_agent(agent_type, config)
|
|
|
194
229
|
local_setup_script = File.join(File.dirname(__FILE__), "setup-agent.rb")
|
|
195
230
|
|
|
196
231
|
# Check for local agent-bridge binaries (for development)
|
|
197
|
-
|
|
232
|
+
# Priority:
|
|
233
|
+
# 1. Linux binary matching host arch (for proper container execution)
|
|
234
|
+
# 2. Legacy bin/agent-bridge if it's a binary (not script)
|
|
235
|
+
|
|
236
|
+
arch = `uname -m`.strip
|
|
237
|
+
linux_arch = (arch == "x86_64") ? "amd64" : "arm64"
|
|
238
|
+
linux_bridge = File.join(Dir.pwd, "tinker-public", "bin", "agent-bridge-linux-#{linux_arch}")
|
|
239
|
+
|
|
240
|
+
local_bridge_default = File.join(Dir.pwd, "bin", "agent-bridge")
|
|
198
241
|
local_tmux = File.join(File.dirname(__FILE__), "bin", "agent-bridge-tmux")
|
|
199
242
|
|
|
200
243
|
mounts = []
|
|
@@ -203,9 +246,18 @@ def run_agent(agent_type, config)
|
|
|
203
246
|
mounts += ["-v", "#{File.expand_path(local_setup_script)}:/tmp/setup-agent.rb:ro"]
|
|
204
247
|
end
|
|
205
248
|
|
|
206
|
-
if File.exist?(
|
|
207
|
-
puts "๐ง Using local
|
|
208
|
-
mounts += ["-v", "#{
|
|
249
|
+
if File.exist?(linux_bridge)
|
|
250
|
+
puts "๐ง Using local linux binary: #{linux_bridge}"
|
|
251
|
+
mounts += ["-v", "#{linux_bridge}:/tmp/agent-bridge:ro"]
|
|
252
|
+
elsif File.exist?(local_bridge_default)
|
|
253
|
+
# Check if it's a binary or script
|
|
254
|
+
is_script = File.read(local_bridge_default, 4) == "#!/b"
|
|
255
|
+
if is_script
|
|
256
|
+
puts "โ ๏ธ bin/agent-bridge is a host wrapper script. Please run 'bin/build-bridge' to generate linux binaries."
|
|
257
|
+
else
|
|
258
|
+
puts "๐ง Using local agent-bridge binary"
|
|
259
|
+
mounts += ["-v", "#{local_bridge_default}:/tmp/agent-bridge:ro"]
|
|
260
|
+
end
|
|
209
261
|
end
|
|
210
262
|
|
|
211
263
|
if File.exist?(local_tmux)
|
|
@@ -215,9 +267,9 @@ def run_agent(agent_type, config)
|
|
|
215
267
|
docker_cmd += mounts
|
|
216
268
|
|
|
217
269
|
if File.exist?(local_setup_script)
|
|
218
|
-
docker_cmd += [
|
|
270
|
+
docker_cmd += [image_name(config), "ruby", "/tmp/setup-agent.rb"]
|
|
219
271
|
else
|
|
220
|
-
docker_cmd += [
|
|
272
|
+
docker_cmd += [image_name(config)]
|
|
221
273
|
end
|
|
222
274
|
|
|
223
275
|
success = system(*docker_cmd)
|
|
@@ -248,7 +300,7 @@ def attach_to_agent(agent_type, config)
|
|
|
248
300
|
|
|
249
301
|
if running.empty?
|
|
250
302
|
puts "โ ๏ธ #{agent_type} agent is not running. Auto-starting..."
|
|
251
|
-
build_docker_image
|
|
303
|
+
build_docker_image(config)
|
|
252
304
|
run_agent(agent_type, config)
|
|
253
305
|
sleep 3
|
|
254
306
|
end
|
|
@@ -312,6 +364,6 @@ if command == "attach"
|
|
|
312
364
|
attach_to_agent(agent_type, config)
|
|
313
365
|
else
|
|
314
366
|
config = load_config
|
|
315
|
-
build_docker_image
|
|
367
|
+
build_docker_image(config)
|
|
316
368
|
run_agent(command, config)
|
|
317
369
|
end
|