()
| 3518 | } |
| 3519 | |
| 3520 | function syncAntigravityPool() { |
| 3521 | const namespace = 'google.antigravity'; |
| 3522 | const profileDir = path.join(AUTH_PROFILES_DIR, namespace); |
| 3523 | |
| 3524 | // Collect accounts from multiple sources |
| 3525 | const allAccounts = []; |
| 3526 | |
| 3527 | // Source 1: antigravity-accounts.json (antigravity plugin format) |
| 3528 | const antigravityAccounts = listAntigravityAccounts(); |
| 3529 | antigravityAccounts.forEach(acc => { |
| 3530 | if (acc.email) allAccounts.push({ email: acc.email, source: 'antigravity' }); |
| 3531 | }); |
| 3532 | |
| 3533 | // Source 2: CLIProxyAPI auth directory (~/.cli-proxy-api/) |
| 3534 | const CLIPROXY_AUTH_DIR = path.join(HOME_DIR, '.cli-proxy-api'); |
| 3535 | if (fs.existsSync(CLIPROXY_AUTH_DIR)) { |
| 3536 | try { |
| 3537 | const files = fs.readdirSync(CLIPROXY_AUTH_DIR).filter(f => f.endsWith('.json') && f.startsWith('antigravity-')); |
| 3538 | files.forEach(f => { |
| 3539 | // Format: antigravity-email_at_gmail_com.json |
| 3540 | const parts = f.replace('.json', '').split('-'); |
| 3541 | if (parts.length > 1) { |
| 3542 | const emailPart = parts.slice(1).join('-'); |
| 3543 | // Convert underscore notation back to email |
| 3544 | const email = emailPart.replace(/_/g, '.').replace('.gmail.com', '@gmail.com').replace('.googlemail.com', '@googlemail.com'); |
| 3545 | if (email && !allAccounts.find(a => a.email === email)) { |
| 3546 | allAccounts.push({ email, source: 'cliproxy', file: f }); |
| 3547 | } |
| 3548 | } |
| 3549 | }); |
| 3550 | } catch (e) { |
| 3551 | console.error('[Pool] Error reading CLIProxy auth dir:', e.message); |
| 3552 | } |
| 3553 | } |
| 3554 | |
| 3555 | if (!allAccounts.length) { |
| 3556 | return; |
| 3557 | } |
| 3558 | |
| 3559 | if (!fs.existsSync(profileDir)) fs.mkdirSync(profileDir, { recursive: true }); |
| 3560 | |
| 3561 | const metadata = loadPoolMetadata(); |
| 3562 | if (!metadata[namespace]) metadata[namespace] = {}; |
| 3563 | |
| 3564 | const seen = new Set(); |
| 3565 | allAccounts.forEach((account, idx) => { |
| 3566 | const name = account.email || `account-${idx + 1}`; |
| 3567 | seen.add(name); |
| 3568 | const profilePath = path.join(profileDir, `${name}.json`); |
| 3569 | if (!fs.existsSync(profilePath)) { |
| 3570 | atomicWriteFileSync(profilePath, JSON.stringify({ email: account.email, source: account.source }, null, 2)); |
| 3571 | } |
| 3572 | if (!metadata[namespace][name]) { |
| 3573 | metadata[namespace][name] = { |
| 3574 | email: account.email || null, |
| 3575 | createdAt: Date.now(), |
| 3576 | lastUsed: 0, |
| 3577 | usageCount: 0 |
no test coverage detected