@yitom/acp-client 0.1.6 → 0.1.7

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/dist/index.js CHANGED
@@ -1,3 +1,6 @@
1
+ import { createRequire } from "node:module";
2
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
3
+
1
4
  // src/contracts/index.ts
2
5
  function isCancelled(error) {
3
6
  return error.code === "CANCELLED";
@@ -159,7 +162,7 @@ function findBuiltinAcpRuntime(id) {
159
162
  return BUILTIN_ACP_RUNTIMES.find((item) => item.id === id);
160
163
  }
161
164
  // src/version.ts
162
- var ACP_CLIENT_VERSION = "0.1.6";
165
+ var ACP_CLIENT_VERSION = "0.1.7";
163
166
  // src/session/available-commands.ts
164
167
  function normalizeCommand(raw) {
165
168
  if (!raw || typeof raw !== "object")
@@ -463,8 +466,8 @@ function decodeJwtPayload(token) {
463
466
  }
464
467
  }
465
468
  var cachedDynamicResult = null;
466
- async function queryCodexAppServer(timeoutMs = 4000) {
467
- if (cachedDynamicResult && Date.now() - cachedDynamicResult.time < 15000) {
469
+ async function queryCodexAppServer(timeoutMs = 1e4) {
470
+ if (cachedDynamicResult && Date.now() - cachedDynamicResult.time < 120000) {
468
471
  return cachedDynamicResult.res;
469
472
  }
470
473
  return new Promise((resolve) => {
@@ -489,7 +492,8 @@ async function queryCodexAppServer(timeoutMs = 4000) {
489
492
  };
490
493
  timer = setTimeout(() => cleanup(null), timeoutMs);
491
494
  try {
492
- proc = spawn("codex", ["app-server"], {
495
+ const cmd = process.platform === "win32" ? "codex" : existsSync2("/mnt/c/Users") ? "codex.exe" : "codex";
496
+ proc = spawn(cmd, ["app-server"], {
493
497
  stdio: ["pipe", "pipe", "pipe"],
494
498
  shell: process.platform === "win32",
495
499
  windowsHide: true
@@ -590,7 +594,7 @@ async function probeCodexQuota(options) {
590
594
  isLoggedIn = true;
591
595
  accountPlan = "API Key (Env)";
592
596
  }
593
- const dynamic = await queryCodexAppServer(4000);
597
+ const dynamic = await queryCodexAppServer(1e4);
594
598
  if (dynamic) {
595
599
  isLoggedIn = true;
596
600
  if (dynamic.account?.email)
@@ -1023,6 +1027,8 @@ var copilotAdapter = {
1023
1027
  // src/runtimes/opencode/quota.ts
1024
1028
  import { existsSync as existsSync8, readFileSync as readFileSync4 } from "node:fs";
1025
1029
  import { execFile as execFile2 } from "node:child_process";
1030
+ import * as os from "node:os";
1031
+ import * as path from "node:path";
1026
1032
  function resolveOpencodeAuthPath() {
1027
1033
  const candidates = resolveOpencodeAuthCandidates();
1028
1034
  for (const c of candidates) {
@@ -1069,10 +1075,166 @@ async function queryOpencodeAuthList(timeoutMs = 1200) {
1069
1075
  }
1070
1076
  });
1071
1077
  }
1078
+ function readLocalOpencodeCredentials() {
1079
+ const home = os.homedir();
1080
+ const dbPaths = [
1081
+ path.join(home, ".local", "share", "opencode", "opencode.db"),
1082
+ process.env.LOCALAPPDATA ? path.join(process.env.LOCALAPPDATA, "opencode", "opencode.db") : null,
1083
+ path.join(home, ".config", "opencode", "opencode.db")
1084
+ ].filter(Boolean);
1085
+ for (const dbPath of dbPaths) {
1086
+ if (!existsSync8(dbPath))
1087
+ continue;
1088
+ try {
1089
+ let rows = [];
1090
+ if (typeof process.versions?.bun !== "undefined") {
1091
+ const { Database } = __require("bun:sqlite");
1092
+ const db = new Database(dbPath, { readonly: true });
1093
+ rows = db.query("SELECT integration_id, value FROM credential").all();
1094
+ db.close();
1095
+ } else {
1096
+ const { DatabaseSync } = __require("node:sqlite");
1097
+ const db = new DatabaseSync(dbPath, { readOnly: true });
1098
+ rows = db.prepare("SELECT integration_id, value FROM credential").all();
1099
+ db.close();
1100
+ }
1101
+ const opencodeCred = rows.find((r) => r.integration_id === "opencode");
1102
+ if (opencodeCred?.value) {
1103
+ const parsed = JSON.parse(opencodeCred.value);
1104
+ const meta = parsed.metadata || {};
1105
+ return {
1106
+ email: meta.email || undefined,
1107
+ name: meta.email ? meta.email.split("@")[0] : meta.orgName || undefined,
1108
+ token: parsed.access || undefined,
1109
+ orgId: meta.orgID || undefined,
1110
+ accountId: meta.accountID || undefined
1111
+ };
1112
+ }
1113
+ } catch {
1114
+ try {
1115
+ const buf = readFileSync4(dbPath, "utf8");
1116
+ const emailMatch = buf.match(/"email"\s*:\s*"([^"]+)"/);
1117
+ const tokenMatch = buf.match(/"access"\s*:\s*"(st_[a-zA-Z0-9_\\-]+)"/);
1118
+ const orgMatch = buf.match(/"orgID"\s*:\s*"(wrk_[a-zA-Z0-9_\\-]+)"/);
1119
+ const accMatch = buf.match(/"accountID"\s*:\s*"(acc_[a-zA-Z0-9_\\-]+)"/);
1120
+ if (emailMatch || tokenMatch) {
1121
+ return {
1122
+ email: emailMatch?.[1],
1123
+ name: emailMatch?.[1]?.split("@")[0],
1124
+ token: tokenMatch?.[1],
1125
+ orgId: orgMatch?.[1],
1126
+ accountId: accMatch?.[1]
1127
+ };
1128
+ }
1129
+ } catch {}
1130
+ }
1131
+ }
1132
+ return {};
1133
+ }
1134
+ async function probeOpencodeGoOnlineQuota(creds, runtimeId = "opencode") {
1135
+ if (!creds.token || !creds.orgId)
1136
+ return null;
1137
+ try {
1138
+ const res = await fetch("https://opencode.ai/console/api/go/status", {
1139
+ headers: {
1140
+ Authorization: `Bearer ${creds.token}`,
1141
+ "x-opencode-org-id": creds.orgId,
1142
+ "x-opencode-account-id": creds.accountId || ""
1143
+ },
1144
+ signal: AbortSignal.timeout(3500)
1145
+ });
1146
+ if (!res.ok)
1147
+ return null;
1148
+ const data = await res.json();
1149
+ const meters = data?.access?.meters;
1150
+ if (!meters)
1151
+ return null;
1152
+ const formatReset = (isoStr) => {
1153
+ if (!isoStr)
1154
+ return;
1155
+ const diffMs = new Date(isoStr).getTime() - Date.now();
1156
+ if (diffMs <= 0)
1157
+ return "已重置";
1158
+ const totalMins = Math.floor(diffMs / 60000);
1159
+ const hours = Math.floor(totalMins / 60);
1160
+ const days = Math.floor(hours / 24);
1161
+ if (days > 0) {
1162
+ const remH = hours % 24;
1163
+ return `Resets in ${days}d ${remH}h`;
1164
+ }
1165
+ const remM = totalMins % 60;
1166
+ return `Resets in ${hours}h ${remM}m`;
1167
+ };
1168
+ const calcWindow = (m, label, durMins) => {
1169
+ if (!m || !m.limitMicroCents)
1170
+ return;
1171
+ const limit = Number(m.limitMicroCents);
1172
+ const used = Number(m.usedMicroCents || 0);
1173
+ const usedPercent = limit > 0 ? Math.round(used / limit * 100) : 0;
1174
+ const percentLeft = Math.max(0, 100 - usedPercent);
1175
+ return {
1176
+ label,
1177
+ usedPercent,
1178
+ percentLeft,
1179
+ windowDurationMins: durMins,
1180
+ resetsAt: formatReset(m.resetsAt)
1181
+ };
1182
+ };
1183
+ const rolling = calcWindow(meters.fiveHour, "Rolling", 300);
1184
+ const weekly = calcWindow(meters.week, "Weekly", 10080);
1185
+ const monthly = calcWindow(meters.month, "Monthly", 43200);
1186
+ let creditBalance = "$0.00";
1187
+ try {
1188
+ const bRes = await fetch("https://opencode.ai/console/api/billing/status", {
1189
+ headers: {
1190
+ Authorization: `Bearer ${creds.token}`,
1191
+ "x-opencode-org-id": creds.orgId,
1192
+ "x-opencode-account-id": creds.accountId || ""
1193
+ },
1194
+ signal: AbortSignal.timeout(2000)
1195
+ });
1196
+ if (bRes.ok) {
1197
+ const bData = await bRes.json();
1198
+ const availMicro = Number(bData.availableMicroCents || 0);
1199
+ creditBalance = `$${(availMicro / 1e8).toFixed(2)}`;
1200
+ }
1201
+ } catch {}
1202
+ const quota = {
1203
+ runtimeId,
1204
+ provider: "OpenCode",
1205
+ account: {
1206
+ email: creds.email,
1207
+ name: creds.name || "OpenCode User",
1208
+ plan: "OpenCode Go",
1209
+ type: "opencode"
1210
+ },
1211
+ primaryWindow: rolling,
1212
+ secondaryWindow: weekly,
1213
+ extraWindows: monthly ? [monthly] : undefined,
1214
+ credits: {
1215
+ balance: creditBalance,
1216
+ currency: "USD",
1217
+ unlimited: false
1218
+ },
1219
+ status: "ok",
1220
+ updatedAt: Date.now()
1221
+ };
1222
+ return quota;
1223
+ } catch {
1224
+ return null;
1225
+ }
1226
+ }
1072
1227
  async function probeOpencodeQuota(runtimeId = "opencode") {
1228
+ const dbCreds = readLocalOpencodeCredentials();
1229
+ if (dbCreds.token) {
1230
+ const goQuota = await probeOpencodeGoOnlineQuota(dbCreds, runtimeId);
1231
+ if (goQuota)
1232
+ return goQuota;
1233
+ }
1073
1234
  const authPath = resolveOpencodeAuthPath();
1074
- let isLoggedIn = false;
1075
- let accountEmail;
1235
+ let isLoggedIn = Boolean(dbCreds.token || dbCreds.email);
1236
+ let accountEmail = dbCreds.email;
1237
+ let accountName = dbCreds.name;
1076
1238
  let plan = "OpenCode Community";
1077
1239
  if (authPath && existsSync8(authPath)) {
1078
1240
  try {
@@ -1096,7 +1258,9 @@ async function probeOpencodeQuota(runtimeId = "opencode") {
1096
1258
  if (authList.length > 0) {
1097
1259
  isLoggedIn = true;
1098
1260
  const providers = authList.map((l) => l.split(/\s{2,}/)[0]).filter(Boolean);
1099
- if (providers.length > 0) {
1261
+ if (providers.some((p) => p.toLowerCase().includes("go"))) {
1262
+ plan = "OpenCode Go";
1263
+ } else if (providers.length > 0) {
1100
1264
  plan = `OpenCode (${providers.join(", ")})`;
1101
1265
  }
1102
1266
  }
@@ -1115,7 +1279,7 @@ async function probeOpencodeQuota(runtimeId = "opencode") {
1115
1279
  let credits;
1116
1280
  if (stats && typeof stats.cost === "number") {
1117
1281
  credits = {
1118
- balance: stats.cost > 0 ? `$${stats.cost.toFixed(2)} spent` : "0.00"
1282
+ balance: stats.cost > 0 ? `$${stats.cost.toFixed(2)} spent` : "$0.00"
1119
1283
  };
1120
1284
  }
1121
1285
  return {
@@ -1123,6 +1287,7 @@ async function probeOpencodeQuota(runtimeId = "opencode") {
1123
1287
  provider: "OpenCode",
1124
1288
  account: {
1125
1289
  email: accountEmail,
1290
+ name: accountName,
1126
1291
  plan,
1127
1292
  type: "provider_oauth"
1128
1293
  },
@@ -1134,15 +1299,15 @@ async function probeOpencodeQuota(runtimeId = "opencode") {
1134
1299
 
1135
1300
  // src/runtimes/opencode/index.ts
1136
1301
  import { existsSync as existsSync9, readFileSync as readFileSync5 } from "node:fs";
1137
- import { homedir as homedir7 } from "node:os";
1138
- import { dirname, join as join10 } from "node:path";
1302
+ import { homedir as homedir8 } from "node:os";
1303
+ import { dirname, join as join11 } from "node:path";
1139
1304
  function pickEnv(env, key) {
1140
1305
  return env?.[key]?.trim() ?? "";
1141
1306
  }
1142
1307
  function resolveOpencodeAuthCandidates(overrides) {
1143
1308
  const platform = overrides?.platform ?? process.platform;
1144
1309
  const env = overrides?.env ?? process.env;
1145
- const home = overrides?.home ?? homedir7();
1310
+ const home = overrides?.home ?? homedir8();
1146
1311
  const seen = new Set;
1147
1312
  const out = [];
1148
1313
  const push = (p) => {
@@ -1153,21 +1318,21 @@ function resolveOpencodeAuthCandidates(overrides) {
1153
1318
  };
1154
1319
  const xdg = pickEnv(env, "XDG_DATA_HOME");
1155
1320
  if (xdg)
1156
- push(join10(xdg, "opencode", "auth.json"));
1321
+ push(join11(xdg, "opencode", "auth.json"));
1157
1322
  if (platform === "win32") {
1158
- const localAppData = pickEnv(env, "LOCALAPPDATA") || (pickEnv(env, "USERPROFILE") ? join10(pickEnv(env, "USERPROFILE"), "AppData", "Local") : "");
1323
+ const localAppData = pickEnv(env, "LOCALAPPDATA") || (pickEnv(env, "USERPROFILE") ? join11(pickEnv(env, "USERPROFILE"), "AppData", "Local") : "");
1159
1324
  if (localAppData)
1160
- push(join10(localAppData, "opencode", "auth.json"));
1325
+ push(join11(localAppData, "opencode", "auth.json"));
1161
1326
  const userProfile = pickEnv(env, "USERPROFILE") || home;
1162
1327
  if (userProfile)
1163
- push(join10(userProfile, ".local", "share", "opencode", "auth.json"));
1328
+ push(join11(userProfile, ".local", "share", "opencode", "auth.json"));
1164
1329
  } else if (home) {
1165
- push(join10(home, ".local", "share", "opencode", "auth.json"));
1330
+ push(join11(home, ".local", "share", "opencode", "auth.json"));
1166
1331
  }
1167
1332
  return out;
1168
1333
  }
1169
1334
  function resolveOpencodeAuthFile() {
1170
- return resolveOpencodeAuthCandidates()[0] ?? join10(homedir7(), ".local", "share", "opencode", "auth.json");
1335
+ return resolveOpencodeAuthCandidates()[0] ?? join11(homedir8(), ".local", "share", "opencode", "auth.json");
1171
1336
  }
1172
1337
  function isValidOpencodeAuthFile(authFile) {
1173
1338
  try {
@@ -1264,14 +1429,14 @@ async function probeCursorQuota() {
1264
1429
  // src/runtimes/cursor/index.ts
1265
1430
  import { spawnSync } from "node:child_process";
1266
1431
  import { existsSync as existsSync10, readFileSync as readFileSync6 } from "node:fs";
1267
- import { homedir as homedir8 } from "node:os";
1268
- import { delimiter, dirname as dirname2, join as join11 } from "node:path";
1432
+ import { homedir as homedir9 } from "node:os";
1433
+ import { delimiter, dirname as dirname2, join as join12 } from "node:path";
1269
1434
  function cursorLocalAppData(env) {
1270
1435
  const local = env.LOCALAPPDATA?.trim();
1271
1436
  if (local)
1272
1437
  return local;
1273
1438
  const profile = env.USERPROFILE?.trim();
1274
- return profile ? join11(profile, "AppData", "Local") : "";
1439
+ return profile ? join12(profile, "AppData", "Local") : "";
1275
1440
  }
1276
1441
  function isOnPath(command, env, platform) {
1277
1442
  const pathValue = env.PATH ?? env.Path ?? "";
@@ -1283,7 +1448,7 @@ function isOnPath(command, env, platform) {
1283
1448
  if (!trimmed)
1284
1449
  continue;
1285
1450
  try {
1286
- if (existsSync10(join11(trimmed, command)))
1451
+ if (existsSync10(join12(trimmed, command)))
1287
1452
  return true;
1288
1453
  } catch {}
1289
1454
  }
@@ -1292,15 +1457,15 @@ function isOnPath(command, env, platform) {
1292
1457
  function resolveDirectCursorCommand(platform, env, home) {
1293
1458
  if (platform === "win32") {
1294
1459
  const localAppData = cursorLocalAppData(env);
1295
- return localAppData ? join11(localAppData, "cursor-agent", "agent.cmd") : "";
1460
+ return localAppData ? join12(localAppData, "cursor-agent", "agent.cmd") : "";
1296
1461
  }
1297
- return home ? join11(home, ".local", "bin", "agent") : "";
1462
+ return home ? join12(home, ".local", "bin", "agent") : "";
1298
1463
  }
1299
1464
  function resolveCursorCommand(overrides) {
1300
1465
  const args = ["acp"];
1301
1466
  const platform = overrides?.platform ?? process.platform;
1302
1467
  const env = overrides?.env ?? process.env;
1303
- const home = overrides?.home ?? homedir8();
1468
+ const home = overrides?.home ?? homedir9();
1304
1469
  if (platform === "win32") {
1305
1470
  const directCmd = resolveDirectCursorCommand(platform, env, home);
1306
1471
  if (directCmd && existsSync10(directCmd)) {
@@ -1318,7 +1483,7 @@ function resolveCursorSpawnCommand(overrides) {
1318
1483
  const args = ["acp"];
1319
1484
  const platform = overrides?.platform ?? process.platform;
1320
1485
  const env = overrides?.env ?? process.env;
1321
- const home = overrides?.home ?? homedir8();
1486
+ const home = overrides?.home ?? homedir9();
1322
1487
  const binary = platform === "win32" ? "agent.cmd" : "agent";
1323
1488
  const direct = resolveDirectCursorCommand(platform, env, home);
1324
1489
  try {
@@ -1344,12 +1509,12 @@ function cursorRoamingAppData(env, home) {
1344
1509
  if (roaming)
1345
1510
  return roaming;
1346
1511
  const profile = pickEnv2(env, "USERPROFILE") || home;
1347
- return profile ? join11(profile, "AppData", "Roaming") : "";
1512
+ return profile ? join12(profile, "AppData", "Roaming") : "";
1348
1513
  }
1349
1514
  function resolveCursorAuthCandidates(overrides) {
1350
1515
  const platform = overrides?.platform ?? process.platform;
1351
1516
  const env = overrides?.env ?? process.env;
1352
- const home = overrides?.home ?? homedir8();
1517
+ const home = overrides?.home ?? homedir9();
1353
1518
  const seen = new Set;
1354
1519
  const out = [];
1355
1520
  const push = (p) => {
@@ -1360,16 +1525,16 @@ function resolveCursorAuthCandidates(overrides) {
1360
1525
  };
1361
1526
  const xdg = pickEnv2(env, "XDG_CONFIG_HOME");
1362
1527
  if (xdg)
1363
- push(join11(xdg, "cursor", "auth.json"));
1528
+ push(join12(xdg, "cursor", "auth.json"));
1364
1529
  if (platform === "win32") {
1365
1530
  const profile = pickEnv2(env, "USERPROFILE") || home;
1366
1531
  if (profile)
1367
- push(join11(profile, ".config", "cursor", "auth.json"));
1532
+ push(join12(profile, ".config", "cursor", "auth.json"));
1368
1533
  const roaming = cursorRoamingAppData(env, home);
1369
1534
  if (roaming)
1370
- push(join11(roaming, "Cursor", "User", "globalStorage", "storage.json"));
1535
+ push(join12(roaming, "Cursor", "User", "globalStorage", "storage.json"));
1371
1536
  } else if (home) {
1372
- push(join11(home, ".config", "cursor", "auth.json"));
1537
+ push(join12(home, ".config", "cursor", "auth.json"));
1373
1538
  }
1374
1539
  return out;
1375
1540
  }
@@ -1418,7 +1583,7 @@ function isValidCursorCandidate(authFile) {
1418
1583
  }
1419
1584
  function probeCursorAuth(overrides) {
1420
1585
  const env = overrides?.env ?? process.env;
1421
- const home = overrides?.home ?? homedir8();
1586
+ const home = overrides?.home ?? homedir9();
1422
1587
  const hasApiKeyEnv = Boolean(env.CURSOR_API_KEY?.trim() || env.CURSOR_AUTH_TOKEN?.trim());
1423
1588
  const candidates = resolveCursorAuthCandidates(overrides);
1424
1589
  let firstExisting = null;
@@ -1438,7 +1603,7 @@ function probeCursorAuth(overrides) {
1438
1603
  if (isValidCursorCandidate(candidate))
1439
1604
  validFile = candidate;
1440
1605
  }
1441
- const fallback = home ? join11(home, ".config", "cursor", "auth.json") : "";
1606
+ const fallback = home ? join12(home, ".config", "cursor", "auth.json") : "";
1442
1607
  const authFile = validFile ?? firstExisting ?? candidates[0] ?? fallback;
1443
1608
  const authDir = authFile ? dirname2(authFile) : "";
1444
1609
  let hasCodexHome = false;
@@ -1578,23 +1743,242 @@ var deepseekAdapter = {
1578
1743
  };
1579
1744
 
1580
1745
  // src/runtimes/agy/quota.ts
1581
- import { existsSync as existsSync11 } from "node:fs";
1582
- import { join as join12 } from "node:path";
1746
+ import { existsSync as existsSync11, readFileSync as readFileSync7, readdirSync, statSync } from "node:fs";
1747
+ import { join as join13 } from "node:path";
1748
+ import { execFileSync } from "node:child_process";
1749
+ import * as os2 from "node:os";
1583
1750
  function resolveGeminiHome2() {
1584
1751
  const home = process.env.USERPROFILE || process.env.HOME || "";
1585
- return join12(home, ".gemini");
1752
+ return join13(home, ".gemini");
1753
+ }
1754
+ function resolveAntigravityAccount() {
1755
+ if (process.env.GOOGLE_ACCOUNT?.trim()) {
1756
+ const email = process.env.GOOGLE_ACCOUNT.trim();
1757
+ return { email, name: email.split("@")[0] };
1758
+ }
1759
+ if (process.env.ANTIGRAVITY_ACCOUNT?.trim()) {
1760
+ const email = process.env.ANTIGRAVITY_ACCOUNT.trim();
1761
+ return { email, name: email.split("@")[0] };
1762
+ }
1763
+ const home = process.env.USERPROFILE || process.env.HOME || os2.homedir() || "";
1764
+ const candidates = [
1765
+ process.env.APPDATA ? join13(process.env.APPDATA, "Antigravity", "app_storage.json") : null,
1766
+ join13(home, ".config", "Antigravity", "app_storage.json"),
1767
+ join13(home, "Library", "Application Support", "Antigravity", "app_storage.json")
1768
+ ].filter(Boolean);
1769
+ for (const file of candidates) {
1770
+ try {
1771
+ if (existsSync11(file)) {
1772
+ const raw = readFileSync7(file, "utf8");
1773
+ const json = JSON.parse(raw);
1774
+ const username = json["jetski.onboarding.lastLoginUsername"];
1775
+ if (username && typeof username === "string" && username.trim()) {
1776
+ const u = username.trim();
1777
+ return {
1778
+ email: u,
1779
+ name: u.includes("@") ? u.split("@")[0] : u
1780
+ };
1781
+ }
1782
+ }
1783
+ } catch {}
1784
+ }
1785
+ const osUser = process.env.USERNAME || process.env.USER;
1786
+ if (osUser?.trim()) {
1787
+ return { name: osUser.trim() };
1788
+ }
1789
+ return {};
1790
+ }
1791
+ function resolveAntigravityLanguageServer() {
1792
+ const home = process.env.USERPROFILE || process.env.HOME || os2.homedir() || "";
1793
+ const appData = process.env.APPDATA || (process.platform === "win32" ? join13(home, "AppData", "Roaming") : "");
1794
+ const baseDirs = [
1795
+ appData ? join13(appData, "Antigravity IDE", "logs") : null,
1796
+ appData ? join13(appData, "Antigravity", "logs") : null,
1797
+ join13(home, ".config", "Antigravity IDE", "logs"),
1798
+ join13(home, ".config", "Antigravity", "logs"),
1799
+ join13(home, "Library", "Application Support", "Antigravity IDE", "logs"),
1800
+ join13(home, "Library", "Application Support", "Antigravity", "logs")
1801
+ ].filter(Boolean);
1802
+ for (const base of baseDirs) {
1803
+ try {
1804
+ if (!existsSync11(base))
1805
+ continue;
1806
+ const sessionDirs = readdirSync(base).map((d) => {
1807
+ try {
1808
+ return { name: d, time: statSync(join13(base, d)).mtimeMs };
1809
+ } catch {
1810
+ return null;
1811
+ }
1812
+ }).filter((d) => Boolean(d)).sort((a, b) => b.time - a.time);
1813
+ for (const s of sessionDirs) {
1814
+ const logFile = join13(base, s.name, "ls-main.log");
1815
+ if (existsSync11(logFile)) {
1816
+ const content = readFileSync7(logFile, "utf8");
1817
+ const csrfMatch = content.match(/--csrf_token\s+([a-f0-9\-]+)/);
1818
+ const portMatch = content.match(/LS started on port\s+(\d+)/) || content.match(/--https_server_port\s+(\d+)/);
1819
+ if (csrfMatch && portMatch) {
1820
+ return {
1821
+ port: parseInt(portMatch[1], 10),
1822
+ csrfToken: csrfMatch[1]
1823
+ };
1824
+ }
1825
+ }
1826
+ }
1827
+ } catch {}
1828
+ }
1829
+ try {
1830
+ let out = "";
1831
+ if (process.platform === "win32") {
1832
+ out = execFileSync("powershell", [
1833
+ "-NoProfile",
1834
+ "-Command",
1835
+ `Get-CimInstance Win32_Process -Filter "Name like '%language_server%'" | Select-Object -ExpandProperty CommandLine`
1836
+ ], { encoding: "utf8", timeout: 4000, windowsHide: true });
1837
+ } else {
1838
+ out = execFileSync("ps", ["aux"], { encoding: "utf8", timeout: 4000 });
1839
+ }
1840
+ const lines = out.split(/\r?\n/);
1841
+ for (const l of lines) {
1842
+ const portMatch = l.match(/--https_server_port\s+(\d+)/);
1843
+ const csrfMatch = l.match(/--csrf_token\s+([a-f0-9\-]+)/);
1844
+ if (portMatch && csrfMatch) {
1845
+ return { port: parseInt(portMatch[1], 10), csrfToken: csrfMatch[1] };
1846
+ }
1847
+ }
1848
+ } catch {}
1849
+ return null;
1586
1850
  }
1587
1851
  async function probeAgyQuota(options) {
1852
+ const acc = resolveAntigravityAccount();
1853
+ const lsInfo = resolveAntigravityLanguageServer();
1854
+ if (lsInfo) {
1855
+ try {
1856
+ let data = null;
1857
+ const prevReject = process.env.NODE_TLS_REJECT_UNAUTHORIZED;
1858
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
1859
+ try {
1860
+ const res = await fetch(`https://127.0.0.1:${lsInfo.port}/exa.language_server_pb.LanguageServerService/RetrieveUserQuotaSummary`, {
1861
+ method: "POST",
1862
+ headers: {
1863
+ "Content-Type": "application/json",
1864
+ "x-codeium-csrf-token": lsInfo.csrfToken
1865
+ },
1866
+ body: JSON.stringify({}),
1867
+ signal: AbortSignal.timeout(4000),
1868
+ tls: { rejectUnauthorized: false }
1869
+ });
1870
+ if (res.ok) {
1871
+ data = await res.json();
1872
+ }
1873
+ } catch {
1874
+ try {
1875
+ const raw = execFileSync(process.platform === "win32" ? "curl.exe" : "curl", [
1876
+ "-k",
1877
+ "-s",
1878
+ "-X",
1879
+ "POST",
1880
+ "-H",
1881
+ "Content-Type: application/json",
1882
+ "-H",
1883
+ `x-codeium-csrf-token: ${lsInfo.csrfToken}`,
1884
+ "-d",
1885
+ "{}",
1886
+ `https://127.0.0.1:${lsInfo.port}/exa.language_server_pb.LanguageServerService/RetrieveUserQuotaSummary`
1887
+ ], { encoding: "utf8", timeout: 4000 });
1888
+ data = JSON.parse(raw);
1889
+ } catch {}
1890
+ } finally {
1891
+ if (prevReject !== undefined) {
1892
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = prevReject;
1893
+ } else {
1894
+ delete process.env.NODE_TLS_REJECT_UNAUTHORIZED;
1895
+ }
1896
+ }
1897
+ if (data?.response?.groups) {
1898
+ const groups = data.response.groups;
1899
+ const formatReset = (isoStr, fallbackDesc) => {
1900
+ if (fallbackDesc && fallbackDesc.includes("it will fully refresh in ")) {
1901
+ const m = fallbackDesc.match(/it will fully refresh in (.+?)\.?$/);
1902
+ if (m?.[1])
1903
+ return `Resets in ${m[1].trim()}`;
1904
+ }
1905
+ if (!isoStr)
1906
+ return;
1907
+ const diffMs = new Date(isoStr).getTime() - Date.now();
1908
+ if (diffMs <= 0)
1909
+ return "已重置";
1910
+ const totalMins = Math.floor(diffMs / 60000);
1911
+ const hours = Math.floor(totalMins / 60);
1912
+ const days = Math.floor(hours / 24);
1913
+ if (days > 0)
1914
+ return `Resets in ${days}d ${hours % 24}h`;
1915
+ return `Resets in ${hours}h ${totalMins % 60}m`;
1916
+ };
1917
+ const toWindow = (b, groupName, label, durMins) => {
1918
+ if (!b)
1919
+ return;
1920
+ const frac = typeof b.remainingFraction === "number" ? b.remainingFraction : 1;
1921
+ const percentLeft = Math.max(0, Math.min(100, Math.round(frac * 100)));
1922
+ const usedPercent = 100 - percentLeft;
1923
+ return {
1924
+ label,
1925
+ group: groupName,
1926
+ percentLeft,
1927
+ usedPercent,
1928
+ windowDurationMins: durMins,
1929
+ resetsAt: formatReset(b.resetTime, b.description)
1930
+ };
1931
+ };
1932
+ const geminiGroup = groups.find((g) => g.displayName?.toLowerCase().includes("gemini"));
1933
+ const thirdPartyGroup = groups.find((g) => g.displayName?.toLowerCase().includes("claude") || g.displayName?.toLowerCase().includes("gpt"));
1934
+ const gemini5h = geminiGroup?.buckets?.find((b) => b.displayName?.toLowerCase().includes("five hour") || b.bucketId?.includes("5h") || b.window === "5h");
1935
+ const geminiWeekly = geminiGroup?.buckets?.find((b) => b.displayName?.toLowerCase().includes("weekly") || b.bucketId?.includes("weekly") || b.window === "weekly");
1936
+ const tp5h = thirdPartyGroup?.buckets?.find((b) => b.displayName?.toLowerCase().includes("five hour") || b.bucketId?.includes("5h") || b.window === "5h");
1937
+ const tpWeekly = thirdPartyGroup?.buckets?.find((b) => b.displayName?.toLowerCase().includes("weekly") || b.bucketId?.includes("weekly") || b.window === "weekly");
1938
+ const primaryWindow = toWindow(gemini5h, "Gemini Models", "5-Hour limit", 300) || {
1939
+ label: "5-Hour limit",
1940
+ group: "Gemini Models",
1941
+ percentLeft: 100,
1942
+ usedPercent: 0,
1943
+ windowDurationMins: 300
1944
+ };
1945
+ const secondaryWindow = toWindow(geminiWeekly, "Gemini Models", "Weekly limit", 10080);
1946
+ const extraWindows = [
1947
+ toWindow(tp5h, "Claude and GPT models", "5-Hour limit", 300),
1948
+ toWindow(tpWeekly, "Claude and GPT models", "Weekly limit", 10080)
1949
+ ].filter(Boolean);
1950
+ return {
1951
+ runtimeId: "agy",
1952
+ provider: "Google Antigravity",
1953
+ account: {
1954
+ email: acc.email,
1955
+ name: acc.name || "Google Developer",
1956
+ plan: "Google AI Pro",
1957
+ type: "gemini"
1958
+ },
1959
+ primaryWindow,
1960
+ secondaryWindow,
1961
+ extraWindows: extraWindows.length > 0 ? extraWindows : undefined,
1962
+ credits: {
1963
+ unlimited: true,
1964
+ balance: "unlimited"
1965
+ },
1966
+ status: "ok",
1967
+ updatedAt: Date.now()
1968
+ };
1969
+ }
1970
+ } catch {}
1971
+ }
1588
1972
  const geminiHome = resolveGeminiHome2();
1589
- const hasAgyDir = existsSync11(join12(geminiHome, "antigravity")) || existsSync11(join12(geminiHome, "antigravity-cli"));
1973
+ const hasAgyDir = existsSync11(join13(geminiHome, "antigravity")) || existsSync11(join13(geminiHome, "antigravity-cli"));
1590
1974
  const hasApiKey = Boolean(process.env.GEMINI_API_KEY || process.env.GOOGLE_API_KEY);
1591
- const isAvailable = hasAgyDir || hasApiKey;
1975
+ const isAvailable = hasAgyDir || hasApiKey || Boolean(acc.email || acc.name);
1592
1976
  if (!isAvailable) {
1593
1977
  return {
1594
1978
  runtimeId: "agy",
1595
1979
  provider: "Google Antigravity",
1596
1980
  status: "unauthorized",
1597
- message: "wenjianlingu antigravity cli",
1981
+ message: "未检测到 Antigravity 登录凭据",
1598
1982
  updatedAt: Date.now()
1599
1983
  };
1600
1984
  }
@@ -1602,21 +1986,41 @@ async function probeAgyQuota(options) {
1602
1986
  runtimeId: "agy",
1603
1987
  provider: "Google Antigravity",
1604
1988
  account: {
1605
- plan: "Antigravity / Gemini",
1989
+ email: acc.email,
1990
+ name: acc.name || "Google Developer",
1991
+ plan: "Google AI Pro",
1606
1992
  type: "gemini"
1607
1993
  },
1608
1994
  primaryWindow: {
1609
1995
  label: "5-Hour limit",
1996
+ group: "Gemini Models",
1610
1997
  percentLeft: 100,
1611
1998
  usedPercent: 0,
1612
1999
  windowDurationMins: 300
1613
2000
  },
1614
2001
  secondaryWindow: {
1615
2002
  label: "Weekly limit",
2003
+ group: "Gemini Models",
1616
2004
  percentLeft: 100,
1617
2005
  usedPercent: 0,
1618
2006
  windowDurationMins: 10080
1619
2007
  },
2008
+ extraWindows: [
2009
+ {
2010
+ label: "5-Hour limit",
2011
+ group: "Claude and GPT models",
2012
+ percentLeft: 100,
2013
+ usedPercent: 0,
2014
+ windowDurationMins: 300
2015
+ },
2016
+ {
2017
+ label: "Weekly limit",
2018
+ group: "Claude and GPT models",
2019
+ percentLeft: 100,
2020
+ usedPercent: 0,
2021
+ windowDurationMins: 10080
2022
+ }
2023
+ ],
1620
2024
  credits: {
1621
2025
  unlimited: true,
1622
2026
  balance: "unlimited"
@@ -2641,7 +3045,7 @@ class AcpTerminalManager {
2641
3045
  // src/client/acp-proxy-service.ts
2642
3046
  import { mkdir as mkdir4, readFile as readFile3, writeFile as writeFile4 } from "node:fs/promises";
2643
3047
  import { existsSync as existsSync12 } from "node:fs";
2644
- import { join as join13 } from "node:path";
3048
+ import { join as join14 } from "node:path";
2645
3049
  var DEFAULT_ACP_PROXY_SETTINGS = {
2646
3050
  enabled: false,
2647
3051
  host: "127.0.0.1",
@@ -2650,7 +3054,7 @@ var DEFAULT_ACP_PROXY_SETTINGS = {
2650
3054
  var PROXY_ENV_KEYS = ["HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY"];
2651
3055
  var LOWERCASE_PROXY_ENV_KEYS = ["http_proxy", "https_proxy", "all_proxy", "no_proxy"];
2652
3056
  function proxyFilePath(dir) {
2653
- return join13(dir, "agent", "proxy.json");
3057
+ return join14(dir, "agent", "proxy.json");
2654
3058
  }
2655
3059
  function validate2(settings) {
2656
3060
  if (!settings.host.trim())
@@ -2684,7 +3088,7 @@ async function saveAcpProxySettings(payload, dir = getDefaultAgentDataDir()) {
2684
3088
  host: payload.host.trim() || DEFAULT_ACP_PROXY_SETTINGS.host,
2685
3089
  port: payload.port
2686
3090
  };
2687
- await mkdir4(join13(dir, "agent"), { recursive: true });
3091
+ await mkdir4(join14(dir, "agent"), { recursive: true });
2688
3092
  await writeFile4(proxyFilePath(dir), JSON.stringify(stored, null, 2), "utf8");
2689
3093
  return ok(stored);
2690
3094
  }