tinker-agent 1.0.31 → 1.0.33
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/bin/install-agent.sh +0 -10
- package/package.json +1 -1
- package/setup-agent.rb +25 -8
package/bin/install-agent.sh
CHANGED
|
@@ -78,16 +78,6 @@ sudo chown -R ${AGENT_USER}:${GROUP_NAME} ${AGENT_HOME} || echo "⚠️ Failed t
|
|
|
78
78
|
# This ensures the agent can write CLAUDE.md and .mcp.json
|
|
79
79
|
sudo chown ${AGENT_USER}:${GROUP_NAME} $(pwd) || echo "⚠️ Failed to chown project root"
|
|
80
80
|
|
|
81
|
-
# Set GitHub App Key Path if not set
|
|
82
|
-
if [ -z "\$GITHUB_APP_PRIVATE_KEY_PATH" ]; then
|
|
83
|
-
export GITHUB_APP_PRIVATE_KEY_PATH="${AGENT_HOME}/.github-app-privkey.pem"
|
|
84
|
-
else
|
|
85
|
-
# If it was set to /home/claude/... but we are /home/node, fix it
|
|
86
|
-
if [[ "\$GITHUB_APP_PRIVATE_KEY_PATH" == *"/home/claude/"* ]] && [ "${AGENT_HOME}" != "/home/claude" ]; then
|
|
87
|
-
export GITHUB_APP_PRIVATE_KEY_PATH="${AGENT_HOME}/.github-app-privkey.pem"
|
|
88
|
-
fi
|
|
89
|
-
fi
|
|
90
|
-
|
|
91
81
|
# Execute command as agent user
|
|
92
82
|
exec sudo -E -u ${AGENT_USER} env "HOME=${AGENT_HOME}" "\$@"
|
|
93
83
|
EOF
|
package/package.json
CHANGED
package/setup-agent.rb
CHANGED
|
@@ -213,7 +213,15 @@ end
|
|
|
213
213
|
def setup_github_auth!
|
|
214
214
|
app_id = ENV["GITHUB_APP_ID"] || ENV["GITHUB_APP_CLIENT_ID"]
|
|
215
215
|
|
|
216
|
-
|
|
216
|
+
# Check for private key in typical locations
|
|
217
|
+
# 1. In the home directory (copied by entrypoint)
|
|
218
|
+
# 2. In /tmp (mounted by docker)
|
|
219
|
+
private_key_path = [
|
|
220
|
+
File.expand_path("~/.github-app-privkey.pem"),
|
|
221
|
+
"/tmp/github-app-privkey.pem"
|
|
222
|
+
].find { |path| File.exist?(path) }
|
|
223
|
+
|
|
224
|
+
if app_id && ENV["GITHUB_APP_INSTALLATION_ID"] && private_key_path
|
|
217
225
|
puts "🔐 Configuring GitHub App authentication..."
|
|
218
226
|
|
|
219
227
|
# Create helper script
|
|
@@ -226,11 +234,13 @@ def setup_github_auth!
|
|
|
226
234
|
require 'base64'
|
|
227
235
|
require 'time'
|
|
228
236
|
|
|
229
|
-
|
|
230
|
-
|
|
237
|
+
PRIVATE_KEY_PATH = "#{private_key_path}"
|
|
238
|
+
|
|
239
|
+
def generate_jwt(app_id)
|
|
240
|
+
private_key = OpenSSL::PKey::RSA.new(File.read(PRIVATE_KEY_PATH))
|
|
231
241
|
payload = {
|
|
232
242
|
iat: Time.now.to_i - 60,
|
|
233
|
-
exp: Time.now.to_i +
|
|
243
|
+
exp: Time.now.to_i + 480, # 8 minutes to handle clock skew
|
|
234
244
|
iss: app_id
|
|
235
245
|
}
|
|
236
246
|
header = { alg: 'RS256', typ: 'JWT' }
|
|
@@ -251,17 +261,25 @@ def setup_github_auth!
|
|
|
251
261
|
request = Net::HTTP::Post.new(uri)
|
|
252
262
|
request['Authorization'] = "Bearer \#{jwt}"
|
|
253
263
|
request['Accept'] = 'application/vnd.github+json'
|
|
264
|
+
|
|
254
265
|
response = http.request(request)
|
|
255
266
|
data = JSON.parse(response.body)
|
|
267
|
+
|
|
268
|
+
unless response.is_a?(Net::HTTPSuccess)
|
|
269
|
+
STDERR.puts "❌ Error getting installation token: \#{response.code} \#{response.message}"
|
|
270
|
+
STDERR.puts " Response: \#{response.body}"
|
|
271
|
+
exit 1
|
|
272
|
+
end
|
|
273
|
+
|
|
256
274
|
{ token: data['token'], expires_at: Time.parse(data['expires_at']) }
|
|
257
275
|
end
|
|
258
276
|
|
|
259
|
-
def find_or_create_cached_token(app_id, installation_id
|
|
277
|
+
def find_or_create_cached_token(app_id, installation_id)
|
|
260
278
|
cache_file = '/tmp/github-app-token-cache'
|
|
261
279
|
cached_token = read_cached_token(cache_file)
|
|
262
280
|
return cached_token if cached_token
|
|
263
281
|
|
|
264
|
-
jwt = generate_jwt(app_id
|
|
282
|
+
jwt = generate_jwt(app_id)
|
|
265
283
|
token_data = get_installation_token(jwt, installation_id)
|
|
266
284
|
File.write(cache_file, token_data.to_json)
|
|
267
285
|
token_data[:token]
|
|
@@ -278,9 +296,8 @@ def setup_github_auth!
|
|
|
278
296
|
|
|
279
297
|
app_id = ENV['GITHUB_APP_CLIENT_ID'] || ENV['GITHUB_APP_ID']
|
|
280
298
|
installation_id = ENV['GITHUB_APP_INSTALLATION_ID']
|
|
281
|
-
key_path = ENV['GITHUB_APP_PRIVATE_KEY_PATH']
|
|
282
299
|
|
|
283
|
-
puts find_or_create_cached_token(app_id, installation_id
|
|
300
|
+
puts find_or_create_cached_token(app_id, installation_id)
|
|
284
301
|
RUBY
|
|
285
302
|
|
|
286
303
|
# Install helper via sudo to /usr/local/bin
|