Skip to content

Business operating system for Claude Code — 57 skills, 21 agents, smart daemon. Unified inbox (WhatsApp/Email/Slack/Telegram), autonomous PR merge, full-AWS monitoring, revenue (Stripe+RevenueCat), e-commerce (Shopify), marketing (Klaviyo/Meta/GA4), voice (Bland/ElevenLabs), APM (Datadog/NewRelic/OTEL), YOLO mode.

fix(crs): restore accountProxyConfig export in crs-pool-config.mjs (#689)

Aurora Capitald1f15292b2c4
diff --git a/claude-ops/scripts/account-rotation/crs-pool-config.mjs b/claude-ops/scripts/account-rotation/crs-pool-config.mjs
index 15fa102b..a45fc1c0 100644
--- a/claude-ops/scripts/account-rotation/crs-pool-config.mjs
+++ b/claude-ops/scripts/account-rotation/crs-pool-config.mjs
@@ -113,3 +113,84 @@ export function vaultLookupKeysForEmail(email, accounts = []) {
}
return [...keys];
}
+
+/**
+ * Resolve a per-account rotation-proxy descriptor.
+ *
+ * Returns null when the rotation proxy is disabled (no override, no
+ * `CLAUDE_ROTATION_PROXY_ENABLED=1`, or the provider URL is missing). When
+ * enabled, parses `EFG_PROXY_URL` / `BRIGHTDATA_PROXY_URL` for the active
+ * provider (`CLAUDE_ROTATION_PROXY_PROVIDER`, defaults to `brightdata`) and
+ * returns a `{ type, host, port }` object that downstream `oauthFetch` and
+ * `curl --proxy` callers consume.
+ *
+ * Signature: `accountProxyConfig(config, account, env?)`
+ * - `config`: loaded rotation config (from `loadRotationConfig()`)
+ * - `account`: account row (currently unused for routing; kept for future
+ * per-account overrides)
+ * - `env`: optional env-override object (defaults to `process.env`)
+ *
+ * Provider URL formats accepted:
+ * - `socks5://host:port`
+ * - `socks5h://host:port`
+ * - `http://host:port` → type=`http`
+ * - `https://host:port` → type=`http`
+ * - `host:port` (bare) → type=`http`
+ *
+ * @param {{accounts?:Array, crs?:object}} _config
+ * @param {{email?:string, label?:string}} _account
+ * @param {Record<string,string|undefined>} [env]
+ * @returns {{type:string, host:string, port:number} | null}
+ */
+export function accountProxyConfig(_config, _account, env = process.env) {
+ if (!env || typeof env !== 'object') return null;
+ if (env.CLAUDE_ROTATION_PROXY_ENABLED !== '1') return null;
+
+ const provider = String(env.CLAUDE_ROTATION_PROXY_PROVIDER || 'brightdata')
+ .trim()
+ .toLowerCase();
+
+ const urlKey = provider === 'efg' ? 'EFG_PROXY_URL' : 'BRIGHTDATA_PROXY_URL';
+ const raw = env[urlKey];
+ if (!raw || typeof raw !== 'string') return null;
+
+ const parsed = parseProxyUrl(raw.trim());
+ return parsed;
+}
+
+function parseProxyUrl(raw) {
+ if (!raw) return null;
+ // Strip trailing slash, accept bare host:port
+ let s = raw.replace(/\/+$/, '');
+ let type = 'http';
+ if (s.startsWith('socks5://')) {
+ type = 'socks5';
+ s = s.slice('socks5://'.length);
+ } else if (s.startsWith('socks5h://')) {
+ type = 'socks5';
+ s = s.slice('socks5h://'.length);
+ } else if (s.startsWith('https://')) {
+ type = 'http';
+ s = s.slice('https://'.length);
+ } else if (s.startsWith('http://')) {
+ type = 'http';
+ s = s.slice('http://'.length);
+ } else {
+ // Reject unsupported schemes (e.g. ftp://, ssh://, file://). Bare
+ // host:port (no scheme, no path/query/fragment) is still allowed.
+ if (/[/?#]/.test(s)) return null;
+ }
+ // Now s is host[:port] (may have userinfo@host)
+ const at = s.lastIndexOf('@');
+ if (at >= 0) s = s.slice(at + 1);
+ const colon = s.lastIndexOf(':');
+ if (colon < 0) return null;
+ const host = s.slice(0, colon).trim();
+ const portStr = s.slice(colon + 1).trim();
+ // Reject anything that isn't pure decimal digits after the colon — guards
+ // against `host:3128/path`, `host:3128junk`, `host:3128?x=1`, etc.
+ if (!host || /[\s/?#]/.test(host) || !/^\d+$/.test(portStr)) return null;
+ const port = Number.parseInt(portStr, 10);
+ if (!Number.isInteger(port) || port <= 0 || port > 65535) return null;
+ return { type, host, port };
+}
diff --git a/claude-ops/scripts/account-rotation/crs-pool-config.test.mjs b/claude-ops/scripts/account-rotation/crs-pool-config.test.mjs
index 4a941aa2..6fc89dd3 100644
--- a/claude-ops/scripts/account-rotation/crs-pool-config.test.mjs
+++ b/claude-ops/scripts/account-rotation/crs-pool-config.test.mjs
@@ -1,6 +1,6 @@
import test from 'node:test';
import assert from 'node:assert/strict';
-import { buildCrsNameMaps, crsPolicy } from './crs-pool-config.mjs';
+import { buildCrsNameMaps, crsPolicy, accountProxyConfig } from './crs-pool-config.mjs';
test('buildCrsNameMaps uses crsAccountName and nameByVaultKey', () => {
const config = {
@@ -17,3 +17,137 @@ test('crsPolicy defaults to conservative', () => {
assert.equal(crsPolicy({ crs: {} }), 'conservative');
assert.equal(crsPolicy({ crs: { policy: 'max-out' } }), 'max-out');
});
+
+test('accountProxyConfig returns null when proxy is disabled', () => {
+ assert.equal(accountProxyConfig({}, {}, { CLAUDE_ROTATION_PROXY_ENABLED: '0' }), null);
+ assert.equal(accountProxyConfig({}, {}, { CLAUDE_ROTATION_PROXY_PROVIDER: 'efg' }), null);
+ assert.equal(accountProxyConfig({}, {}, {}), null);
+});
+
+test('accountProxyConfig returns null when provider URL is missing', () => {
+ assert.equal(
+ accountProxyConfig({}, {}, { CLAUDE_ROTATION_PROXY_ENABLED: '1', CLAUDE_ROTATION_PROXY_PROVIDER: 'efg' }),
+ null,
+ );
+ assert.equal(
+ accountProxyConfig(
+ {},
+ {},
+ {
+ CLAUDE_ROTATION_PROXY_ENABLED: '1',
+ EFG_PROXY_URL: '',
+ },
+ ),
+ null,
+ );
+});
+
+test('accountProxyConfig parses socks5:// url for efg provider', () => {
+ // Exact contract from crs-parity-regression.test.mjs.
+ assert.deepEqual(
+ accountProxyConfig(
+ {},
+ {},
+ {
+ CLAUDE_ROTATION_PROXY_ENABLED: '1',
+ CLAUDE_ROTATION_PROXY_PROVIDER: 'efg',
+ EFG_PROXY_URL: 'socks5://127.0.0.1:1087',
+ CLAUDE_ROTATION_ENV_FILE: '/nonexistent',
+ },
+ ),
+ { type: 'socks5', host: '127.0.0.1', port: 1087 },
+ );
+});
+
+test('accountProxyConfig defaults to brightdata when no provider env set', () => {
+ assert.deepEqual(
+ accountProxyConfig(
+ {},
+ {},
+ {
+ CLAUDE_ROTATION_PROXY_ENABLED: '1',
+ BRIGHTDATA_PROXY_URL: 'http://proxy.example.com:3128',
+ },
+ ),
+ { type: 'http', host: 'proxy.example.com', port: 3128 },
+ );
+});
+
+test('accountProxyConfig accepts bare host:port for brightdata', () => {
+ assert.deepEqual(
+ accountProxyConfig(
+ {},
+ {},
+ {
+ CLAUDE_ROTATION_PROXY_ENABLED: '1',
+ CLAUDE_ROTATION_PROXY_PROVIDER: 'brightdata',
+ BRIGHTDATA_PROXY_URL: '10.0.0.1:1080',
+ },
+ ),
+ { type: 'http', host: '10.0.0.1', port: 1080 },
+ );
+});
+
+test('accountProxyConfig returns null on malformed URL', () => {
+ assert.equal(
+ accountProxyConfig(
+ {},
+ {},
+ {
+ CLAUDE_ROTATION_PROXY_ENABLED: '1',
+ CLAUDE_ROTATION_PROXY_PROVIDER: 'efg',
+ EFG_PROXY_URL: 'not a url',
+ },
+ ),
+ null,
+ );
+ assert.equal(
+ accountProxyConfig(
+ {},
+ {},
+ {
+ CLAUDE_ROTATION_PROXY_ENABLED: '1',
+ CLAUDE_ROTATION_PROXY_PROVIDER: 'efg',
+ EFG_PROXY_URL: 'socks5://host',
+ },
+ ),
+ null,
+ );
+ // Unsupported scheme + path/suffix must also return null.
+ assert.equal(
+ accountProxyConfig(
+ {},
+ {},
+ {
+ CLAUDE_ROTATION_PROXY_ENABLED: '1',
+ CLAUDE_ROTATION_PROXY_PROVIDER: 'efg',
+ EFG_PROXY_URL: 'ftp://proxy.example.com:21',
+ },
+ ),
+ null,
+ );
+ assert.equal(
+ accountProxyConfig(
+ {},
+ {},
+ {
+ CLAUDE_ROTATION_PROXY_ENABLED: '1',
+ CLAUDE_ROTATION_PROXY_PROVIDER: 'efg',
+ EFG_PROXY_URL: 'socks5://127.0.0.1:1087/path',
+ },
+ ),
+ null,
+ );
+ assert.equal(
+ accountProxyConfig(
+ {},
+ {},
+ {
+ CLAUDE_ROTATION_PROXY_ENABLED: '1',
+ CLAUDE_ROTATION_PROXY_PROVIDER: 'efg',
+ EFG_PROXY_URL: 'socks5://127.0.0.1:abc',
+ },
+ ),
+ null,
+ );
+});