tinker-agent 1.0.16 → 1.0.18

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/setup-agent.rb +33 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinker-agent",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "description": "Tinker Agent Runner",
5
5
  "bin": {
6
6
  "tinker-agent": "./run-tinker-agent.rb"
package/setup-agent.rb CHANGED
@@ -285,24 +285,31 @@ def setup_github_auth!
285
285
  { token: data['token'], expires_at: Time.parse(data['expires_at']) }
286
286
  end
287
287
 
288
- def cached_token(app_id, installation_id, key_path)
288
+ def find_or_create_cached_token(app_id, installation_id, key_path)
289
289
  cache_file = '/tmp/github-app-token-cache'
290
- if File.exist?(cache_file)
291
- cache = JSON.parse(File.read(cache_file))
292
- expires_at = Time.parse(cache['expires_at'])
293
- return cache['token'] if expires_at > Time.now + 300
294
- end
290
+ cached_token = read_cached_token(cache_file)
291
+ return cached_token if cached_token
292
+
295
293
  jwt = generate_jwt(app_id, key_path)
296
294
  token_data = get_installation_token(jwt, installation_id)
297
295
  File.write(cache_file, token_data.to_json)
298
296
  token_data[:token]
299
297
  end
300
298
 
299
+ def read_cached_token(cache_file)
300
+ return nil unless File.exist?(cache_file)
301
+ cache = JSON.parse(File.read(cache_file))
302
+ expires_at = Time.parse(cache['expires_at'])
303
+ return cache['token'] if expires_at > Time.now + 300
304
+ nil
305
+ rescue
306
+ end
307
+
301
308
  app_id = ENV['GITHUB_APP_CLIENT_ID'] || ENV['GITHUB_APP_ID']
302
309
  installation_id = ENV['GITHUB_APP_INSTALLATION_ID']
303
310
  key_path = ENV['GITHUB_APP_PRIVATE_KEY_PATH']
304
311
 
305
- puts cached_token(app_id, installation_id, key_path)
312
+ puts find_or_create_cached_token(app_id, installation_id, key_path)
306
313
  RUBY
307
314
 
308
315
  # Install helper via sudo to /usr/local/bin
@@ -341,6 +348,24 @@ def setup_github_auth!
341
348
  end
342
349
  end
343
350
 
351
+ def setup_git_config!
352
+ # Configure identity if provided
353
+ if ENV["GIT_USER_NAME"] && !ENV["GIT_USER_NAME"].empty?
354
+ system("git config --global user.name \"#{ENV['GIT_USER_NAME']}\"")
355
+ puts "✅ Git user.name configured"
356
+ end
357
+
358
+ if ENV["GIT_USER_EMAIL"] && !ENV["GIT_USER_EMAIL"].empty?
359
+ system("git config --global user.email \"#{ENV['GIT_USER_EMAIL']}\"")
360
+ puts "✅ Git user.email configured"
361
+ end
362
+
363
+ # Force HTTPS instead of SSH to ensure our token auth works
364
+ # This fixes "Permission denied (publickey)" when the repo uses git@github.com remote
365
+ system("git config --global url.\"https://github.com/\".insteadOf \"git@github.com:\"")
366
+ puts "✅ Git configured to force HTTPS for GitHub"
367
+ end
368
+
344
369
  def download_agent_bridge!
345
370
  # Detect architecture
346
371
  arch = `uname -m`.strip
@@ -426,5 +451,6 @@ setup_mcp_config!
426
451
  setup_claude_config!
427
452
  setup_claude_md!
428
453
  setup_github_auth!
454
+ setup_git_config!
429
455
  bin_dir = download_agent_bridge!
430
456
  run_agent!(bin_dir)