opencode-studio-server 1.9.5 → 1.9.6

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/index.js +67 -3
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -17,10 +17,24 @@ const atomicWriteFileSync = (filePath, data, options = 'utf8') => {
17
17
  const tempPath = path.join(dir, `.${path.basename(filePath)}.${crypto.randomBytes(6).toString('hex')}.tmp`);
18
18
  try {
19
19
  fs.writeFileSync(tempPath, data, options);
20
- fs.renameSync(tempPath, filePath);
20
+ // Retry rename for Windows file locking issues
21
+ let retries = 5;
22
+ while (retries > 0) {
23
+ try {
24
+ fs.renameSync(tempPath, filePath);
25
+ break;
26
+ } catch (e) {
27
+ if (retries === 1) throw e;
28
+ retries--;
29
+ // Synchronous delay
30
+ const start = Date.now();
31
+ while (Date.now() - start < 50) {}
32
+ }
33
+ }
21
34
  } catch (err) {
22
- // Clean up temp file if rename fails
23
- try { fs.unlinkSync(tempPath); } catch {}
35
+ if (fs.existsSync(tempPath)) {
36
+ try { fs.unlinkSync(tempPath); } catch (e) {}
37
+ }
24
38
  throw err;
25
39
  }
26
40
  };
@@ -1342,6 +1356,7 @@ app.get('/api/auth/providers', (req, res) => {
1342
1356
  });
1343
1357
 
1344
1358
  app.get('/api/auth', (req, res) => {
1359
+ importCurrentGoogleAuthToPool();
1345
1360
  syncAntigravityPool();
1346
1361
  const authCfg = loadAuthConfig() || {};
1347
1362
  const studio = loadStudioConfig();
@@ -1814,6 +1829,55 @@ function listAntigravityAccounts() {
1814
1829
  }));
1815
1830
  }
1816
1831
 
1832
+ function importCurrentGoogleAuthToPool() {
1833
+ const studio = loadStudioConfig();
1834
+ // Only applies if Antigravity is active
1835
+ if (studio.activeGooglePlugin !== 'antigravity') return;
1836
+
1837
+ const authCfg = loadAuthConfig();
1838
+ if (!authCfg || !authCfg.google || !authCfg.google.email) return;
1839
+
1840
+ const namespace = 'google.antigravity';
1841
+ const profileDir = path.join(AUTH_PROFILES_DIR, namespace);
1842
+ if (!fs.existsSync(profileDir)) fs.mkdirSync(profileDir, { recursive: true });
1843
+
1844
+ const email = authCfg.google.email;
1845
+ const profilePath = path.join(profileDir, `${email}.json`);
1846
+
1847
+ // Check if we need to sync (new account or updated tokens)
1848
+ let shouldSync = true;
1849
+ if (fs.existsSync(profilePath)) {
1850
+ try {
1851
+ const current = JSON.parse(fs.readFileSync(profilePath, 'utf8'));
1852
+ if (current.access_token === authCfg.google.access_token) {
1853
+ shouldSync = false;
1854
+ }
1855
+ } catch {
1856
+ // Corrupt file, overwrite
1857
+ }
1858
+ }
1859
+
1860
+ if (shouldSync) {
1861
+ console.log(`[Auth] Syncing Google login for ${email} to Antigravity pool.`);
1862
+ atomicWriteFileSync(profilePath, JSON.stringify(authCfg.google, null, 2));
1863
+
1864
+ const metadata = loadPoolMetadata();
1865
+ if (!metadata[namespace]) metadata[namespace] = {};
1866
+
1867
+ // Only update metadata if it doesn't exist
1868
+ if (!metadata[namespace][email]) {
1869
+ metadata[namespace][email] = {
1870
+ email: email,
1871
+ createdAt: Date.now(),
1872
+ lastUsed: Date.now(),
1873
+ usageCount: 0,
1874
+ imported: true
1875
+ };
1876
+ savePoolMetadata(metadata);
1877
+ }
1878
+ }
1879
+ }
1880
+
1817
1881
  function syncAntigravityPool() {
1818
1882
  const accounts = listAntigravityAccounts();
1819
1883
  const namespace = 'google.antigravity';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-studio-server",
3
- "version": "1.9.5",
3
+ "version": "1.9.6",
4
4
  "description": "Backend server for OpenCode Studio - manages opencode configurations",
5
5
  "main": "index.js",
6
6
  "bin": {