yatfa 1.0.97 → 1.0.98
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/README.md +4 -4
- package/lib/yatfa_agent/command_builder.rb +22 -4
- package/lib/yatfa_agent/config.rb +10 -23
- package/lib/yatfa_agent/docker.rb +6 -1
- package/package.json +1 -1
- package/setup/git_credential_helper.rb +60 -2
- package/setup/setup-agent.rb +20 -34
- package/setup/setup-claw-agent.rb +7 -2
- package/setup/setup-github.rb +16 -18
- package/setup/url_helper.rb +86 -0
package/README.md
CHANGED
|
@@ -79,9 +79,9 @@ Example `yatfa.env.rb`:
|
|
|
79
79
|
| Variable | Required | Description |
|
|
80
80
|
|----------|----------|-------------|
|
|
81
81
|
| `AGENT_TYPE` | ✅ | `worker`, `planner`, `reviewer`, or `researcher` |
|
|
82
|
-
| `
|
|
83
|
-
| `
|
|
84
|
-
| `GH_TOKEN` | | GitHub token for git operations |
|
|
82
|
+
| `YATFA_API_KEY` | ✅ | MCP API key (get from YATFA dashboard) |
|
|
83
|
+
| `YATFA_URL` | | Yatfa platform URL (defaults to `https://yatfa.com`; `YATFA_API_URL` & `YATFA_WS_URL` are derived from this) |
|
|
84
|
+
| `GH_TOKEN` | | GitHub token for git operations (fallback; backend token auth is preferred) |
|
|
85
85
|
|
|
86
86
|
## Agent Types
|
|
87
87
|
|
|
@@ -199,7 +199,7 @@ YATFA_API_KEY=your_api_key_here
|
|
|
199
199
|
AGENT_TYPE=worker
|
|
200
200
|
```
|
|
201
201
|
|
|
202
|
-
Note: `YATFA_API_URL` and `YATFA_WS_URL` are derived from `
|
|
202
|
+
Note: `YATFA_URL` is optional and defaults to `https://yatfa.com` (the hosted deployment works with zero URL configuration; self-hosted installs set it to their server). `YATFA_API_URL` (`/api/v1`) and `YATFA_WS_URL` (`/cable`, scheme-adjusted) are always derived from it — you never need to set them. The git credential helper derives `YATFA_API_URL` itself, so even a bare `docker exec` shell with no other env can authenticate. Project is automatically determined by the API key.
|
|
203
203
|
|
|
204
204
|
### Agent Self-Update
|
|
205
205
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "json"
|
|
4
|
+
require_relative "../../setup/url_helper"
|
|
4
5
|
|
|
5
6
|
module YatfaAgent
|
|
6
7
|
# Docker command assembly.
|
|
@@ -68,10 +69,12 @@ module YatfaAgent
|
|
|
68
69
|
docker_cmd += ["-e", "OPENCLAW_TELEGRAM_BOT_TOKEN=#{agent_config['telegram_bot_token']}"]
|
|
69
70
|
end
|
|
70
71
|
|
|
71
|
-
# Pass YATFA_URL if configured (optional for claw)
|
|
72
|
+
# Pass YATFA_URL if configured (optional for claw). The API URL is
|
|
73
|
+
# derived via the shared UrlHelper so an explicit override is honored
|
|
74
|
+
# and the /api/v1 suffix rule stays in one place (YATFA-3018).
|
|
72
75
|
if config["yatfa_url"]
|
|
73
76
|
docker_cmd += ["-e", "YATFA_URL=#{config['yatfa_url']}"]
|
|
74
|
-
docker_cmd += ["-e", "YATFA_API_URL=#{config
|
|
77
|
+
docker_cmd += ["-e", "YATFA_API_URL=#{YatfaAgent::UrlHelper.api_url(config)}"]
|
|
75
78
|
end
|
|
76
79
|
|
|
77
80
|
# Pass MCP API key if configured (for future MCP integration)
|
|
@@ -80,14 +83,29 @@ module YatfaAgent
|
|
|
80
83
|
end
|
|
81
84
|
|
|
82
85
|
else
|
|
83
|
-
# Standard agent setup (worker, planner, reviewer, researcher)
|
|
86
|
+
# Standard agent setup (worker, planner, reviewer, researcher).
|
|
87
|
+
# Inject all three URLs as container-wide -e env (matching the claw
|
|
88
|
+
# branch) so any shell in the container — including `docker exec` shells
|
|
89
|
+
# that are not children of the setup process — sees a consistent
|
|
90
|
+
# YATFA_API_URL. YATFA_URL defaults to https://yatfa.com; API/WS URLs are
|
|
91
|
+
# derived from it via the shared UrlHelper (YATFA-3018). Previously only
|
|
92
|
+
# YATFA_URL + YATFA_API_KEY were injected here, leaving YATFA_API_URL
|
|
93
|
+
# empty outside the setup process and breaking git auth.
|
|
94
|
+
#
|
|
95
|
+
# An operator may override any URL via the env block; those overrides
|
|
96
|
+
# are already injected above as -e flags, so skip them here to avoid
|
|
97
|
+
# clobbering (the last -e flag for a key wins in docker). Derivation
|
|
98
|
+
# uses the effective source so env-block YATFA_URL flows into API/WS.
|
|
99
|
+
url_source = config.merge(merged_env)
|
|
84
100
|
docker_cmd += [
|
|
85
101
|
"-e", "YATFA_VERSION=main",
|
|
86
102
|
"-e", "SKILLS=#{agent_def[:skills]&.join(',')}",
|
|
87
103
|
"-e", "AGENT_TYPE=#{agent_type}",
|
|
88
|
-
"-e", "YATFA_URL=#{YatfaAgent::Config.yatfa_url(config)}",
|
|
89
104
|
"-e", "YATFA_API_KEY=#{agent_config['mcp_api_key']}"
|
|
90
105
|
]
|
|
106
|
+
docker_cmd += ["-e", "YATFA_URL=#{YatfaAgent::UrlHelper.base_url(url_source)}"] unless merged_env["YATFA_URL"]
|
|
107
|
+
docker_cmd += ["-e", "YATFA_API_URL=#{YatfaAgent::UrlHelper.api_url(url_source)}"] unless merged_env["YATFA_API_URL"]
|
|
108
|
+
docker_cmd += ["-e", "YATFA_WS_URL=#{YatfaAgent::UrlHelper.ws_url(url_source)}"] unless merged_env["YATFA_WS_URL"]
|
|
91
109
|
|
|
92
110
|
add_github_auth!(docker_cmd, config)
|
|
93
111
|
add_git_config!(docker_cmd, config)
|
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
require "json"
|
|
4
4
|
require "digest"
|
|
5
5
|
require_relative "http"
|
|
6
|
+
# Single source of truth for URL→{api,ws} derivation + the hosted default.
|
|
7
|
+
# Loaded here (not duplicated) so the host-side launcher routes ALL URL
|
|
8
|
+
# derivation through YatfaAgent::UrlHelper — the same module the in-container
|
|
9
|
+
# setup scripts use. See YATFA-3018.
|
|
10
|
+
require_relative "../../setup/url_helper"
|
|
6
11
|
|
|
7
12
|
module YatfaAgent
|
|
8
13
|
module Config
|
|
@@ -88,27 +93,6 @@ module YatfaAgent
|
|
|
88
93
|
JSON.parse(JSON.generate(config))
|
|
89
94
|
end
|
|
90
95
|
|
|
91
|
-
def self.yatfa_url(config)
|
|
92
|
-
config["yatfa_url"] || config["rails_api_url"]
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def self.api_url(config)
|
|
96
|
-
# Derive API URL from yatfa_url
|
|
97
|
-
yatfa_base = yatfa_url(config)
|
|
98
|
-
|
|
99
|
-
# If yatfa_url already includes /api/v1, return as-is
|
|
100
|
-
return yatfa_base if yatfa_base.end_with?("/api/v1") || yatfa_base.end_with?("/api/")
|
|
101
|
-
|
|
102
|
-
# Otherwise, assume it's the base URL and append /api/v1
|
|
103
|
-
"#{yatfa_base}/api/v1"
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
def self.ws_url(config)
|
|
107
|
-
# Derive WebSocket URL from yatfa_url by replacing protocol and adding /cable endpoint
|
|
108
|
-
api_base = yatfa_url(config)
|
|
109
|
-
"#{api_base.sub(/^https:\/\//, "wss://").sub(/^http:\/\//, "ws://")}/cable"
|
|
110
|
-
end
|
|
111
|
-
|
|
112
96
|
# Extract the first available agent MCP API key from the config.
|
|
113
97
|
# Returns nil when no key is configured.
|
|
114
98
|
def self.agent_api_key(config)
|
|
@@ -123,8 +107,11 @@ module YatfaAgent
|
|
|
123
107
|
end
|
|
124
108
|
|
|
125
109
|
def self.fetch_repositories!(config)
|
|
126
|
-
#
|
|
127
|
-
|
|
110
|
+
# Derive the API URL through the shared single source of truth
|
|
111
|
+
# (YatfaAgent::UrlHelper) so this host-side path honors an explicit
|
|
112
|
+
# YATFA_API_URL override and the hosted default exactly like the
|
|
113
|
+
# launcher and in-container setup scripts. See YATFA-3018.
|
|
114
|
+
api_base = YatfaAgent::UrlHelper.api_url(config)
|
|
128
115
|
|
|
129
116
|
return unless api_base
|
|
130
117
|
|
|
@@ -49,7 +49,12 @@ module YatfaAgent
|
|
|
49
49
|
# be identified, the API is unreachable, or no such config is stored.
|
|
50
50
|
# Never raises — a missing remote config is a normal "fall back to error" case.
|
|
51
51
|
def self.fetch_remote_dockerfile(config)
|
|
52
|
-
|
|
52
|
+
# Derive the API URL through the shared single source of truth
|
|
53
|
+
# (YatfaAgent::UrlHelper) rather than the legacy Config.api_url, which
|
|
54
|
+
# neither honored an explicit YATFA_API_URL override nor applied the
|
|
55
|
+
# hosted default and could raise NoMethodError on an unconfigured URL.
|
|
56
|
+
# YatfaAgent::UrlHelper is loaded transitively via config.rb. See YATFA-3018.
|
|
57
|
+
api_base = YatfaAgent::UrlHelper.api_url(config)
|
|
53
58
|
project_id = config["project_id"]
|
|
54
59
|
api_key = Config.agent_api_key(config)
|
|
55
60
|
|
package/package.json
CHANGED
|
@@ -36,6 +36,41 @@ require "uri"
|
|
|
36
36
|
require "time"
|
|
37
37
|
require "fileutils"
|
|
38
38
|
|
|
39
|
+
# Self-healing URL derivation (YATFA-3018). This helper runs in isolation as
|
|
40
|
+
# /usr/local/bin/git-auth-helper (copied there by setup-github.rb alongside
|
|
41
|
+
# url_helper.rb), so it derives YATFA_API_URL from YATFA_URL itself — defaulting
|
|
42
|
+
# to https://yatfa.com — rather than bailing when YATFA_API_URL is empty (the
|
|
43
|
+
# exact failure operators hit in `docker exec` shells outside the setup
|
|
44
|
+
# process). Load the shared module: in-tree via require_relative (tests / setup/),
|
|
45
|
+
# or from the absolute install path when running as the copied binary. A
|
|
46
|
+
# last-resort inline mirror keeps auth working even if the sibling file is
|
|
47
|
+
# missing (version skew / half install) — a credential helper must never break
|
|
48
|
+
# on a missing file. Keep the mirror in sync with setup/url_helper.rb.
|
|
49
|
+
begin
|
|
50
|
+
require_relative "url_helper"
|
|
51
|
+
rescue LoadError
|
|
52
|
+
begin
|
|
53
|
+
require "/usr/local/bin/url_helper"
|
|
54
|
+
rescue LoadError
|
|
55
|
+
module YatfaAgent
|
|
56
|
+
module UrlHelper
|
|
57
|
+
DEFAULT_YATFA_URL = "https://yatfa.com"
|
|
58
|
+
|
|
59
|
+
module_function
|
|
60
|
+
|
|
61
|
+
def api_url(source = ENV)
|
|
62
|
+
explicit = source["YATFA_API_URL"].to_s.strip
|
|
63
|
+
return explicit unless explicit.empty?
|
|
64
|
+
|
|
65
|
+
base = source["YATFA_URL"].to_s.strip
|
|
66
|
+
base = DEFAULT_YATFA_URL if base.empty?
|
|
67
|
+
base.end_with?("/api/v1") || base.end_with?("/api/") ? base : "#{base}/api/v1"
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
39
74
|
module YatfaAgent
|
|
40
75
|
module GitCredentialHelper
|
|
41
76
|
DEFAULT_CACHE_DIR = "/tmp/github-token-cache"
|
|
@@ -116,9 +151,11 @@ module YatfaAgent
|
|
|
116
151
|
# using the per-installation cache and falling back to the default token
|
|
117
152
|
# when a repo-scoped fetch fails (older backend, unregistered repo, etc.).
|
|
118
153
|
def resolve_token(repo, cache_dir:, env:, http_fetch:)
|
|
119
|
-
|
|
154
|
+
# Self-heal: derive YATFA_API_URL from YATFA_URL (default https://yatfa.com)
|
|
155
|
+
# when not explicitly set, so a bare `docker exec` shell with no manual
|
|
156
|
+
# export can still auth. An explicit YATFA_API_URL override is honored.
|
|
157
|
+
api_url = YatfaAgent::UrlHelper.api_url(env)
|
|
120
158
|
api_key = env["YATFA_API_KEY"]
|
|
121
|
-
return nil if api_url.nil? || api_url.to_s.empty?
|
|
122
159
|
return nil if api_key.nil? || api_key.to_s.empty?
|
|
123
160
|
|
|
124
161
|
cached = read_cached_token(repo, cache_dir)
|
|
@@ -134,6 +171,19 @@ module YatfaAgent
|
|
|
134
171
|
data["token"]
|
|
135
172
|
end
|
|
136
173
|
|
|
174
|
+
# When required config is missing, return a specific diagnostic naming the
|
|
175
|
+
# offending variable; otherwise nil. The API URL is self-healed (derived
|
|
176
|
+
# from YATFA_URL, default https://yatfa.com), so the only hard requirement
|
|
177
|
+
# is the YATFA_API_KEY secret — previously this surfaced as the opaque
|
|
178
|
+
# "failed to obtain GitHub token" (YATFA-3018).
|
|
179
|
+
def missing_config_message(env_hash, repo: nil)
|
|
180
|
+
api_key = env_hash["YATFA_API_KEY"]
|
|
181
|
+
return nil unless api_key.nil? || api_key.to_s.empty?
|
|
182
|
+
|
|
183
|
+
repo_suffix = repo ? " for #{repo}" : ""
|
|
184
|
+
"git-auth-helper: YATFA_API_KEY is not set — cannot mint a GitHub token#{repo_suffix}"
|
|
185
|
+
end
|
|
186
|
+
|
|
137
187
|
# Dispatch entry point. Returns a process exit code (0 success, 1 failure).
|
|
138
188
|
def run(argv, stdin: $stdin, stdout: $stdout, stderr: $stderr,
|
|
139
189
|
cache_dir: DEFAULT_CACHE_DIR, env: nil, http_fetch: nil)
|
|
@@ -145,6 +195,10 @@ module YatfaAgent
|
|
|
145
195
|
if action == "get"
|
|
146
196
|
attrs = parse_input(read_stdin(stdin))
|
|
147
197
|
repo = normalize_path(attrs["path"])
|
|
198
|
+
if (msg = missing_config_message(env_hash, repo: repo))
|
|
199
|
+
stderr.puts(msg)
|
|
200
|
+
return 1
|
|
201
|
+
end
|
|
148
202
|
token = resolve_token(repo, cache_dir: cache_dir, env: env_hash, http_fetch: fetch)
|
|
149
203
|
if token.nil?
|
|
150
204
|
stderr.puts("git-auth-helper: failed to obtain GitHub token" + (repo ? " for #{repo}" : ""))
|
|
@@ -160,6 +214,10 @@ module YatfaAgent
|
|
|
160
214
|
end
|
|
161
215
|
|
|
162
216
|
# Token-only mode (e.g. the `gh` wrapper): print just the default token.
|
|
217
|
+
if (msg = missing_config_message(env_hash))
|
|
218
|
+
stderr.puts(msg)
|
|
219
|
+
return 1
|
|
220
|
+
end
|
|
163
221
|
token = resolve_token(nil, cache_dir: cache_dir, env: env_hash, http_fetch: fetch)
|
|
164
222
|
if token.nil?
|
|
165
223
|
stderr.puts("git-auth-helper: failed to obtain GitHub token")
|
package/setup/setup-agent.rb
CHANGED
|
@@ -36,6 +36,7 @@ require "time"
|
|
|
36
36
|
require "socket"
|
|
37
37
|
require "timeout"
|
|
38
38
|
require_relative "http_client"
|
|
39
|
+
require_relative "url_helper"
|
|
39
40
|
require_relative "setup-github"
|
|
40
41
|
require_relative "repositories"
|
|
41
42
|
require_relative "agent_bridge"
|
|
@@ -52,47 +53,32 @@ YATFA_RAW_URL = "#{YATFA_SCRIPTS_BASE_URL}/#{YATFA_VERSION}"
|
|
|
52
53
|
VALID_AGENT_TYPES = %w[planner worker reviewer researcher claw]
|
|
53
54
|
|
|
54
55
|
def check_env!
|
|
55
|
-
agent_type = ENV["AGENT_TYPE"]
|
|
56
|
-
|
|
57
56
|
# Note: claw agents have a separate entry point in setup-claw-agent.rb
|
|
58
57
|
# which calls check_env_claw! directly. This method only handles standard agent types.
|
|
59
58
|
|
|
60
|
-
required
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
puts ""
|
|
65
|
-
puts "
|
|
66
|
-
puts "
|
|
59
|
+
# YATFA_API_KEY is the single required secret — the agent cannot authenticate
|
|
60
|
+
# to the backend or mint GitHub tokens without it. Fail fast with a specific
|
|
61
|
+
# message rather than starting a half-working agent (YATFA-3018).
|
|
62
|
+
if ENV["YATFA_API_KEY"].to_s.empty?
|
|
63
|
+
puts "❌ Missing required environment variable: YATFA_API_KEY"
|
|
64
|
+
puts " YATFA_API_KEY is the MCP API key for this agent (from the Yatfa dashboard)."
|
|
65
|
+
puts " The agent needs it to authenticate to the backend and to mint GitHub tokens."
|
|
67
66
|
puts ""
|
|
68
|
-
puts "
|
|
69
|
-
puts " YATFA_API_URL
|
|
70
|
-
puts " YATFA_API_KEY - MCP API key"
|
|
71
|
-
puts " GH_TOKEN - GitHub token"
|
|
67
|
+
puts "YATFA_URL is optional (defaults to https://yatfa.com);"
|
|
68
|
+
puts " YATFA_API_URL / YATFA_WS_URL are derived from it."
|
|
72
69
|
exit 1
|
|
73
70
|
end
|
|
74
71
|
|
|
75
|
-
# Derive
|
|
76
|
-
#
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
end
|
|
86
|
-
puts "📡 Derived YATFA_API_URL: #{ENV['YATFA_API_URL']}"
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
# Derive YATFA_WS_URL: replace protocol with ws/wss and add /cable endpoint
|
|
90
|
-
# IMPORTANT: Use original yatfa_url before any modifications
|
|
91
|
-
original_yatfa_url = ENV["YATFA_URL"]
|
|
92
|
-
unless ENV["YATFA_WS_URL"]
|
|
93
|
-
ENV["YATFA_WS_URL"] = "#{original_yatfa_url.sub(/^https:\/\//, 'wss://').sub(/^http:\/\//, 'ws://')}/cable"
|
|
94
|
-
puts "📡 Derived YATFA_WS_URL: #{ENV['YATFA_WS_URL']}"
|
|
95
|
-
end
|
|
72
|
+
# Derive the three URLs via the shared UrlHelper (YATFA-3018). YATFA_URL
|
|
73
|
+
# defaults to https://yatfa.com when unset; YATFA_API_URL (/api/v1) and
|
|
74
|
+
# YATFA_WS_URL (scheme-swapped /cable) are derived from it. Explicit
|
|
75
|
+
# overrides for any of the three are honored (backwards compatible).
|
|
76
|
+
ENV["YATFA_URL"] = YatfaAgent::UrlHelper.base_url
|
|
77
|
+
ENV["YATFA_API_URL"] = YatfaAgent::UrlHelper.api_url
|
|
78
|
+
ENV["YATFA_WS_URL"] = YatfaAgent::UrlHelper.ws_url
|
|
79
|
+
puts "📡 YATFA_URL: #{ENV['YATFA_URL']}"
|
|
80
|
+
puts "📡 YATFA_API_URL: #{ENV['YATFA_API_URL']}"
|
|
81
|
+
puts "📡 YATFA_WS_URL: #{ENV['YATFA_WS_URL']}"
|
|
96
82
|
|
|
97
83
|
agent_type = ENV["AGENT_TYPE"]
|
|
98
84
|
if agent_type && !VALID_AGENT_TYPES.include?(agent_type)
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
# - fetch_llm_credentials! is defined by the parent setup-agent.rb
|
|
15
15
|
# - Standard library requires (json, fileutils, pathname, etc.) are loaded
|
|
16
16
|
# by setup-agent.rb before this file is required
|
|
17
|
+
# - YatfaAgent::UrlHelper is provided by setup/url_helper.rb
|
|
18
|
+
|
|
19
|
+
require_relative "url_helper" unless defined?(YatfaAgent::UrlHelper)
|
|
17
20
|
|
|
18
21
|
def check_env_claw!
|
|
19
22
|
required = %w[OPENCLAW_TELEGRAM_BOT_TOKEN]
|
|
@@ -37,9 +40,11 @@ def check_env_claw!
|
|
|
37
40
|
exit 1
|
|
38
41
|
end
|
|
39
42
|
|
|
40
|
-
# Derive YATFA_API_URL from YATFA_URL
|
|
43
|
+
# Derive YATFA_API_URL from YATFA_URL via the shared helper (optional for
|
|
44
|
+
# claw — yatfa integration is opt-in, so only when YATFA_URL is set). The
|
|
45
|
+
# /api/v1 suffix rule lives in one place (YATFA-3018).
|
|
41
46
|
if ENV["YATFA_URL"] && !ENV["YATFA_API_URL"]
|
|
42
|
-
ENV["YATFA_API_URL"] =
|
|
47
|
+
ENV["YATFA_API_URL"] = YatfaAgent::UrlHelper.with_api_suffix(ENV["YATFA_URL"])
|
|
43
48
|
end
|
|
44
49
|
|
|
45
50
|
puts "✅ Claw environment validated"
|
package/setup/setup-github.rb
CHANGED
|
@@ -4,26 +4,14 @@
|
|
|
4
4
|
# Extracted from setup-agent.rb for modularity
|
|
5
5
|
|
|
6
6
|
def setup_github_auth!
|
|
7
|
-
rails_api_url = ENV["YATFA_API_URL"]
|
|
8
7
|
rails_api_key = ENV["YATFA_API_KEY"]
|
|
9
8
|
|
|
10
|
-
# Derive YATFA_API_URL
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# Validate YATFA_API_URL format before proceeding
|
|
20
|
-
if rails_api_url && !rails_api_url.empty? && !rails_api_url.include?('/api/v1')
|
|
21
|
-
puts "⚠️ Warning: YATFA_API_URL must include /api/v1 path"
|
|
22
|
-
puts " Current: #{rails_api_url}"
|
|
23
|
-
puts " Expected: https://example.com/api/v1"
|
|
24
|
-
puts " Falling back to alternative authentication..."
|
|
25
|
-
rails_api_url = nil # Clear it to fall through to other methods
|
|
26
|
-
end
|
|
9
|
+
# Derive YATFA_API_URL via the shared UrlHelper (YATFA-3018): honors an
|
|
10
|
+
# explicit override, else derives /api/v1 from YATFA_URL (default
|
|
11
|
+
# https://yatfa.com). check_env! already set this for standard agents, but
|
|
12
|
+
# re-derive defensively so a re-run / partial flow is consistent.
|
|
13
|
+
ENV["YATFA_API_URL"] = YatfaAgent::UrlHelper.api_url
|
|
14
|
+
rails_api_url = ENV["YATFA_API_URL"]
|
|
27
15
|
|
|
28
16
|
# New method: Get token from Rails backend (preferred)
|
|
29
17
|
if rails_api_url && !rails_api_url.empty? && rails_api_key && !rails_api_key.empty?
|
|
@@ -38,6 +26,16 @@ def setup_github_auth!
|
|
|
38
26
|
system("sudo", "mv", "/tmp/git-auth-helper", helper_path)
|
|
39
27
|
system("sudo", "chmod", "+x", helper_path)
|
|
40
28
|
|
|
29
|
+
# Install the shared URL helper alongside the credential helper. The helper
|
|
30
|
+
# runs in isolation as /usr/local/bin/git-auth-helper and loads it via
|
|
31
|
+
# `require_relative "url_helper"` to self-heal YATFA_API_URL from YATFA_URL
|
|
32
|
+
# (default https://yatfa.com) in bare `docker exec` shells (YATFA-3018).
|
|
33
|
+
url_helper_src = File.join(__dir__, "url_helper.rb")
|
|
34
|
+
if File.exist?(url_helper_src)
|
|
35
|
+
File.write("/tmp/url_helper", File.read(url_helper_src))
|
|
36
|
+
system("sudo", "mv", "/tmp/url_helper", "/usr/local/bin/url_helper.rb")
|
|
37
|
+
end
|
|
38
|
+
|
|
41
39
|
# Wire the helper into git. useHttpPath=true makes git send the repo path on
|
|
42
40
|
# stdin so the helper can request a repo-scoped token (?repo=owner/repo).
|
|
43
41
|
# Array form avoids shell interpolation of the helper path.
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# YATFA URL derivation — the single source of truth.
|
|
4
|
+
#
|
|
5
|
+
# `YATFA_URL` is the only URL variable an operator ever configures. The API URL
|
|
6
|
+
# (`<base>/api/v1`) and the WebSocket URL (`<scheme-adjusted base>/cable`) are
|
|
7
|
+
# ALWAYS derived from it. Both the host-side launcher (lib/yatfa_agent/) and the
|
|
8
|
+
# in-container setup scripts (setup/*) load this module so the derivation lives
|
|
9
|
+
# in exactly one place.
|
|
10
|
+
#
|
|
11
|
+
# Rules (see YATFA-3018):
|
|
12
|
+
# 1. `YATFA_URL` defaults to `https://yatfa.com` when unset/blank, so the
|
|
13
|
+
# hosted deployment works with zero URL configuration.
|
|
14
|
+
# 2. `YATFA_API_URL` / `YATFA_WS_URL`, when explicitly set, are honored as
|
|
15
|
+
# overrides (backwards compatible) — never re-derived.
|
|
16
|
+
# 3. The API URL appends `/api/v1` unless the base already carries an `/api`
|
|
17
|
+
# path; the WS URL swaps the scheme (http→ws, https→wss) and appends
|
|
18
|
+
# `/cable`.
|
|
19
|
+
#
|
|
20
|
+
# Every method takes an optional +source+ — any hash-like object (ENV, or a
|
|
21
|
+
# string-keyed config hash) — so the same logic serves the launcher (config
|
|
22
|
+
# hash) and the container scripts (ENV).
|
|
23
|
+
|
|
24
|
+
module YatfaAgent
|
|
25
|
+
module UrlHelper
|
|
26
|
+
DEFAULT_YATFA_URL = "https://yatfa.com"
|
|
27
|
+
API_SUFFIX = "/api/v1"
|
|
28
|
+
WS_SUFFIX = "/cable"
|
|
29
|
+
|
|
30
|
+
module_function
|
|
31
|
+
|
|
32
|
+
# Resolve the base platform URL, applying the hosted default when unset.
|
|
33
|
+
# Reads +YATFA_URL+ (ENV convention) then +yatfa_url+ / +rails_api_url+
|
|
34
|
+
# (config-hash convention).
|
|
35
|
+
def base_url(source = ENV)
|
|
36
|
+
value = source_value(source, "YATFA_URL") ||
|
|
37
|
+
source_value(source, "yatfa_url") ||
|
|
38
|
+
source_value(source, "rails_api_url")
|
|
39
|
+
value = value.to_s.strip
|
|
40
|
+
value.empty? ? DEFAULT_YATFA_URL : value
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Derive the API URL. An explicit +YATFA_API_URL+ override wins; otherwise
|
|
44
|
+
# the suffix is appended to the resolved base URL.
|
|
45
|
+
def api_url(source = ENV)
|
|
46
|
+
explicit = source_value(source, "YATFA_API_URL").to_s.strip
|
|
47
|
+
return explicit unless explicit.empty?
|
|
48
|
+
|
|
49
|
+
with_api_suffix(base_url(source))
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Derive the WebSocket URL. An explicit +YATFA_WS_URL+ override wins;
|
|
53
|
+
# otherwise the base scheme is swapped (http→ws, https→wss) and +/cable+
|
|
54
|
+
# is appended.
|
|
55
|
+
def ws_url(source = ENV)
|
|
56
|
+
explicit = source_value(source, "YATFA_WS_URL").to_s.strip
|
|
57
|
+
return explicit unless explicit.empty?
|
|
58
|
+
|
|
59
|
+
"#{to_ws_scheme(base_url(source))}#{WS_SUFFIX}"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Append +/api/v1+ to +base+ unless it already ends with +/api/v1+ or
|
|
63
|
+
# +/api/+. Shared with YatfaAgent::Config so the suffix rule is defined once.
|
|
64
|
+
def with_api_suffix(base)
|
|
65
|
+
base = base.to_s
|
|
66
|
+
return base if base.end_with?("/api/v1") || base.end_with?("/api/")
|
|
67
|
+
|
|
68
|
+
"#{base}#{API_SUFFIX}"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Swap the scheme of +base+ to its WebSocket equivalent. Already-ws schemes
|
|
72
|
+
# are left untouched.
|
|
73
|
+
def to_ws_scheme(base)
|
|
74
|
+
base.to_s.sub(/\Ahttps:\/\//, "wss://").sub(/\Ahttp:\/\//, "ws://")
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Safely read +key+ from a hash-like +source+ (ENV or a config Hash).
|
|
78
|
+
def source_value(source, key)
|
|
79
|
+
return nil unless source.respond_to?(:[])
|
|
80
|
+
|
|
81
|
+
source[key]
|
|
82
|
+
rescue StandardError
|
|
83
|
+
nil
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|