tinker-agent 1.0.15 → 1.0.16

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 +21 -19
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinker-agent",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "Tinker Agent Runner",
5
5
  "bin": {
6
6
  "tinker-agent": "./run-tinker-agent.rb"
package/setup-agent.rb CHANGED
@@ -246,9 +246,6 @@ def setup_github_auth!
246
246
  puts "🔐 Configuring GitHub App authentication..."
247
247
 
248
248
  # Create helper script
249
- helper_path = "/usr/local/bin/git-auth-helper"
250
-
251
- # We embed the helper script content here
252
249
  helper_content = <<~RUBY
253
250
  #!/usr/bin/env ruby
254
251
  require 'openssl'
@@ -308,27 +305,32 @@ def setup_github_auth!
308
305
  puts cached_token(app_id, installation_id, key_path)
309
306
  RUBY
310
307
 
311
- # Only write if we have permission (we should as root or if /usr/local/bin is writable)
312
- # If not, write to /tmp and use that
313
- if File.writable?("/usr/local/bin")
314
- File.write(helper_path, helper_content)
315
- File.chmod(0755, helper_path)
316
- else
317
- helper_path = "/tmp/git-auth-helper"
318
- File.write(helper_path, helper_content)
319
- File.chmod(0755, helper_path)
320
- end
308
+ # Install helper via sudo to /usr/local/bin
309
+ helper_path = "/usr/local/bin/git-auth-helper"
310
+ File.write("/tmp/git-auth-helper", helper_content)
311
+ system("sudo mv /tmp/git-auth-helper #{helper_path}")
312
+ system("sudo chmod +x #{helper_path}")
321
313
 
322
314
  # Configure git
323
315
  system("git config --global credential.helper '!f() { test \"$1\" = get && echo \"protocol=https\" && echo \"host=github.com\" && echo \"username=x-access-token\" && echo \"password=$(#{helper_path})\"; }; f'")
324
316
 
325
- # Configure gh CLI
326
- token = `#{helper_path}`.strip
327
- if token.empty?
328
- puts "❌ Failed to generate GitHub App token"
317
+ # Configure gh CLI wrapper for auto-refresh
318
+ real_gh_path = "/usr/bin/gh"
319
+ if File.exist?(real_gh_path)
320
+ wrapper_path = "/usr/local/bin/gh"
321
+ wrapper_content = <<~BASH
322
+ #!/bin/bash
323
+ # Auto-refresh GitHub token using git-auth-helper
324
+ export GH_TOKEN=$(#{helper_path})
325
+ exec #{real_gh_path} "$@"
326
+ BASH
327
+
328
+ File.write("/tmp/gh-wrapper", wrapper_content)
329
+ system("sudo mv /tmp/gh-wrapper #{wrapper_path}")
330
+ system("sudo chmod +x #{wrapper_path}")
331
+ puts "✅ GitHub App authentication configured (with auto-refresh)"
329
332
  else
330
- IO.popen("gh auth login --with-token 2>/dev/null", "w") { |io| io.puts token }
331
- puts "✅ GitHub App authentication configured"
333
+ puts "⚠️ Could not find 'gh' at #{real_gh_path}, skipping wrapper"
332
334
  end
333
335
 
334
336
  elsif ENV["GH_TOKEN"] && !ENV["GH_TOKEN"].empty?