@yitom/acp-client 0.1.3 → 0.1.5

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/sidecar.cjs CHANGED
@@ -35,6 +35,8 @@ var __toESM = (mod, isNodeMode, target) => {
35
35
  // src/sidecar/main.ts
36
36
  var readline = __toESM(require("node:readline"), 1);
37
37
 
38
+ // src/version.ts
39
+ var ACP_CLIENT_VERSION = "0.1.5";
38
40
  // src/contracts/index.ts
39
41
  function ok(value) {
40
42
  return { ok: true, value };
@@ -81,6 +83,7 @@ var CODEX_ACP_NPM_PACKAGE = "@agentclientprotocol/codex-acp";
81
83
  var CLAUDE_ACP_NPM_PACKAGE = "@agentclientprotocol/claude-agent-acp";
82
84
  var DEEPSEEK_DSH_NPM_PACKAGE = "@deepseek-ai/dsh";
83
85
  var AGY_ACP_NPM_PACKAGE = "@yitom/agy-acp-map";
86
+ var OPENCODE_CLI_NPM_PACKAGE = "@opencode/cli";
84
87
  var DEFAULT_ACP_RUNTIME_ID = "codex-acp";
85
88
  function isWindowsPlatform() {
86
89
  const proc = globalThis.process;
@@ -132,6 +135,15 @@ var BUILTIN_ACP_RUNTIMES = [
132
135
  args: ["acp"],
133
136
  requiredEnvKeys: []
134
137
  },
138
+ {
139
+ id: "opencode-v2",
140
+ name: "OpenCode v2",
141
+ description: "通过 npx 启动独立产品线 @opencode/cli v2(acp);与 1.x 共存,复用 v2 SQLite 登录态",
142
+ authHint: "v2 登录态在 SQLite(auth.json 仅兼容残留);未登录先用 v2 二进制跑 opencode auth login",
143
+ command: "npx",
144
+ args: ["-y", OPENCODE_CLI_NPM_PACKAGE, "acp"],
145
+ requiredEnvKeys: []
146
+ },
135
147
  {
136
148
  id: "cursor-cli",
137
149
  name: "Cursor",
@@ -245,6 +257,161 @@ class AvailableCommandsCache {
245
257
  }
246
258
  }
247
259
 
260
+ // src/session/quota.ts
261
+ function parseRateLimitsFromStatusText(text, runtimeId = "unknown") {
262
+ if (!text || typeof text !== "string")
263
+ return null;
264
+ const lines = text.split(/\r?\n/);
265
+ let account;
266
+ const windows = [];
267
+ let credits;
268
+ let status = "ok";
269
+ let message;
270
+ if (/account (?:disabled|banned|suspended)|suspended|banned/i.test(text)) {
271
+ status = "banned";
272
+ message = "账号已封禁或暂停使用 (Account banned / suspended)";
273
+ } else if (/RESOURCE_EXHAUSTED|quota reached|rate limit exceeded|429/i.test(text)) {
274
+ status = "exhausted";
275
+ message = "额度已用尽 (Quota / Rate limit reached)";
276
+ } else if (/unauthorized|authentication failed|invalid api key/i.test(text)) {
277
+ status = "unauthorized";
278
+ message = "认证失效 (Unauthorized / Invalid credentials)";
279
+ }
280
+ for (const rawLine of lines) {
281
+ const line = rawLine.replace(/\*\*/g, "").trim();
282
+ if (!line)
283
+ continue;
284
+ const accMatch = line.match(/^Account\s*[::]\s*([^()]+?)(?:\s*\(([^)]+)\))?$/i);
285
+ if (accMatch) {
286
+ account = {
287
+ plan: accMatch[1].trim(),
288
+ email: accMatch[2]?.trim()
289
+ };
290
+ continue;
291
+ }
292
+ const credMatch = line.match(/(?:\b|^)(?:[\w\s-]*?credits?)\s*[::]\s*(unlimited|[\d.]+)/i);
293
+ if (credMatch) {
294
+ const val = credMatch[1].trim();
295
+ credits = val.toLowerCase() === "unlimited" ? { unlimited: true, balance: "unlimited" } : { balance: Number(val) || val, unlimited: false };
296
+ continue;
297
+ }
298
+ const winMatch = line.match(/(?:(?:[\w-]+\s+)?([\w\s-]+?(?:limit|spend limit|window)))\s*[::]\s*(\d+(?:\.\d+)?)%\s*(?:left|remaining)(?:\s*\((?:resets\s*(?:at\s*)?([^)]+)|([^)]+))\))?/i);
299
+ if (winMatch) {
300
+ const label = winMatch[1].trim();
301
+ const pct = parseFloat(winMatch[2]);
302
+ const resetsAt = (winMatch[3] || winMatch[4] || "").trim() || undefined;
303
+ let windowDurationMins;
304
+ const lower = label.toLowerCase();
305
+ if (/5h|5-hour/i.test(lower))
306
+ windowDurationMins = 300;
307
+ else if (/week/i.test(lower))
308
+ windowDurationMins = 10080;
309
+ else if (/month/i.test(lower))
310
+ windowDurationMins = 43200;
311
+ else if (/day|24h/i.test(lower))
312
+ windowDurationMins = 1440;
313
+ else if (/(\d+)\s*h/i.test(lower)) {
314
+ const m = lower.match(/(\d+)\s*h/);
315
+ if (m)
316
+ windowDurationMins = parseInt(m[1], 10) * 60;
317
+ }
318
+ windows.push({
319
+ label,
320
+ percentLeft: pct,
321
+ usedPercent: Math.max(0, 100 - pct),
322
+ resetsAt,
323
+ windowDurationMins
324
+ });
325
+ continue;
326
+ }
327
+ const fastMatch = line.match(/(?:fast requests?|requests?)\s*[::]\s*(\d+)\s*\/\s*(\d+)/i);
328
+ if (fastMatch) {
329
+ const used = parseInt(fastMatch[1], 10);
330
+ const total = parseInt(fastMatch[2], 10);
331
+ const left = Math.max(0, total - used);
332
+ const pct = total > 0 ? Math.round(left / total * 100) : 0;
333
+ windows.push({
334
+ label: "Fast requests",
335
+ percentLeft: pct,
336
+ usedPercent: total > 0 ? Math.round(used / total * 100) : 0,
337
+ used,
338
+ total
339
+ });
340
+ continue;
341
+ }
342
+ }
343
+ if (!windows.length && !credits && !account && status === "ok") {
344
+ return null;
345
+ }
346
+ const primary = windows.find((w) => /5h|5-hour|hour|primary|fast/i.test(w.label)) || windows[0];
347
+ const secondary = windows.find((w) => w !== primary && /week|month|secondary/i.test(w.label)) || windows.find((w) => w !== primary);
348
+ const extraWindows = windows.filter((w) => w !== primary && w !== secondary);
349
+ if (primary && primary.percentLeft <= 10 && status === "ok") {
350
+ status = "warning";
351
+ }
352
+ return {
353
+ runtimeId,
354
+ account,
355
+ primaryWindow: primary,
356
+ secondaryWindow: secondary,
357
+ extraWindows: extraWindows.length ? extraWindows : undefined,
358
+ credits,
359
+ status,
360
+ message,
361
+ rawText: text,
362
+ updatedAt: Date.now()
363
+ };
364
+ }
365
+
366
+ class QuotaCache {
367
+ bySession = new Map;
368
+ byRuntime = new Map;
369
+ observe(params, defaultRuntimeId = "unknown") {
370
+ if (!params || typeof params !== "object")
371
+ return null;
372
+ const p = params;
373
+ const sessionId = typeof p.sessionId === "string" ? p.sessionId : undefined;
374
+ let textToParse = "";
375
+ if (p.update?.content && p.update.content.type === "text" && typeof p.update.content.text === "string") {
376
+ textToParse = p.update.content.text;
377
+ } else if (p.update?.message?.content && Array.isArray(p.update.message.content)) {
378
+ textToParse = p.update.message.content.filter((c) => c && c.type === "text" && typeof c.text === "string").map((c) => c.text).join(`
379
+ `);
380
+ }
381
+ if (!textToParse)
382
+ return null;
383
+ if (!/(?:limit|credits?|Account:|5h|resets|banned|suspended|quota)/i.test(textToParse)) {
384
+ return null;
385
+ }
386
+ const quota = parseRateLimitsFromStatusText(textToParse, defaultRuntimeId);
387
+ if (quota) {
388
+ if (sessionId)
389
+ this.bySession.set(sessionId, quota);
390
+ this.byRuntime.set(defaultRuntimeId, quota);
391
+ return quota;
392
+ }
393
+ return null;
394
+ }
395
+ set(quota, sessionId) {
396
+ if (sessionId)
397
+ this.bySession.set(sessionId, quota);
398
+ this.byRuntime.set(quota.runtimeId, quota);
399
+ }
400
+ get(sessionId, runtimeId) {
401
+ if (sessionId && this.bySession.has(sessionId)) {
402
+ return this.bySession.get(sessionId);
403
+ }
404
+ if (runtimeId && this.byRuntime.has(runtimeId)) {
405
+ return this.byRuntime.get(runtimeId);
406
+ }
407
+ return;
408
+ }
409
+ clear() {
410
+ this.bySession.clear();
411
+ this.byRuntime.clear();
412
+ }
413
+ }
414
+
248
415
  // node_modules/@agentclientprotocol/sdk/dist/schema/index.js
249
416
  var AGENT_METHODS = {
250
417
  initialize: "initialize",
@@ -10130,38 +10297,9 @@ var legacyClientNotificationMethods = new Set([
10130
10297
  CLIENT_METHODS.elicitation_complete
10131
10298
  ]);
10132
10299
 
10133
- // src/runtimes/codex/index.ts
10134
- var import_promises2 = require("node:fs/promises");
10135
- var import_node_path4 = require("node:path");
10136
-
10137
- // src/runtimes/codex/codex-provider-home.ts
10138
- var INKDOWN_PROVIDER_ID = "inkdown-custom";
10139
- var INKDOWN_PROVIDER_API_KEY_ENV = "INKDOWN_PROVIDER_API_KEY";
10140
- function tomlEscape(value) {
10141
- return value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
10142
- }
10143
- function buildCustomProviderConfigToml(config) {
10144
- const name = config.name?.trim() || "自定义 API";
10145
- const wireApi = config.wireApi === "responses" ? "responses" : "chat";
10146
- return [
10147
- `model_provider = "${INKDOWN_PROVIDER_ID}"`,
10148
- `model = "${tomlEscape(config.model.trim())}"`,
10149
- "",
10150
- `[model_providers.${INKDOWN_PROVIDER_ID}]`,
10151
- `name = "${tomlEscape(name)}"`,
10152
- `base_url = "${tomlEscape(config.baseUrl.trim())}"`,
10153
- `env_key = "${INKDOWN_PROVIDER_API_KEY_ENV}"`,
10154
- `wire_api = "${wireApi}"`,
10155
- ""
10156
- ].join(`
10157
- `);
10158
- }
10159
- function buildCustomProviderSpawnEnv(config, apiKey, codexHome) {
10160
- return {
10161
- CODEX_HOME: codexHome,
10162
- [INKDOWN_PROVIDER_API_KEY_ENV]: apiKey
10163
- };
10164
- }
10300
+ // src/runtimes/codex/quota.ts
10301
+ var import_node_fs2 = require("node:fs");
10302
+ var import_node_path2 = require("node:path");
10165
10303
 
10166
10304
  // src/runtimes/codex/codex-auth-preflight.ts
10167
10305
  var import_node_fs = require("node:fs");
@@ -10196,14 +10334,114 @@ function probeCodexAuth() {
10196
10334
  };
10197
10335
  }
10198
10336
 
10337
+ // src/runtimes/codex/quota.ts
10338
+ function decodeJwtPayload(token) {
10339
+ try {
10340
+ const parts = token.split(".");
10341
+ if (parts.length < 2)
10342
+ return null;
10343
+ const json = Buffer.from(parts[1], "base64").toString("utf8");
10344
+ return JSON.parse(json);
10345
+ } catch {
10346
+ return null;
10347
+ }
10348
+ }
10349
+ async function probeCodexQuota(options) {
10350
+ const codexHome = resolveCodexHome();
10351
+ const authPath = import_node_path2.join(codexHome, "auth.json");
10352
+ let accountEmail;
10353
+ let accountPlan = "Codex Free / Local";
10354
+ let isLoggedIn = false;
10355
+ if (import_node_fs2.existsSync(authPath)) {
10356
+ try {
10357
+ const authData = JSON.parse(import_node_fs2.readFileSync(authPath, "utf8"));
10358
+ if (authData.OPENAI_API_KEY) {
10359
+ isLoggedIn = true;
10360
+ accountPlan = "OpenAI API Key";
10361
+ }
10362
+ if (authData.tokens?.id_token) {
10363
+ isLoggedIn = true;
10364
+ const payload = decodeJwtPayload(authData.tokens.id_token);
10365
+ if (payload) {
10366
+ if (typeof payload.email === "string")
10367
+ accountEmail = payload.email;
10368
+ const authObj = payload["https://api.openai.com/auth"];
10369
+ if (authObj && typeof authObj.chatgpt_plan_type === "string") {
10370
+ accountPlan = `ChatGPT ${authObj.chatgpt_plan_type}`;
10371
+ }
10372
+ }
10373
+ } else if (authData.tokens?.access_token) {
10374
+ isLoggedIn = true;
10375
+ }
10376
+ } catch {}
10377
+ }
10378
+ if (process.env.CODEX_API_KEY || process.env.OPENAI_API_KEY) {
10379
+ isLoggedIn = true;
10380
+ accountPlan = "API Key (Env)";
10381
+ }
10382
+ if (!isLoggedIn) {
10383
+ return {
10384
+ runtimeId: "codex-acp",
10385
+ provider: "OpenAI / Codex",
10386
+ status: "unauthorized",
10387
+ message: "未登录 Codex (Not logged in)",
10388
+ updatedAt: Date.now()
10389
+ };
10390
+ }
10391
+ return {
10392
+ runtimeId: "codex-acp",
10393
+ provider: "OpenAI / Codex",
10394
+ account: {
10395
+ email: accountEmail,
10396
+ plan: accountPlan,
10397
+ type: "chatgpt"
10398
+ },
10399
+ status: "ok",
10400
+ updatedAt: Date.now()
10401
+ };
10402
+ }
10403
+
10404
+ // src/runtimes/codex/index.ts
10405
+ var import_promises2 = require("node:fs/promises");
10406
+ var import_node_path5 = require("node:path");
10407
+
10408
+ // src/runtimes/codex/codex-provider-home.ts
10409
+ var INKDOWN_PROVIDER_ID = "inkdown-custom";
10410
+ var INKDOWN_PROVIDER_API_KEY_ENV = "INKDOWN_PROVIDER_API_KEY";
10411
+ function tomlEscape(value) {
10412
+ return value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
10413
+ }
10414
+ function buildCustomProviderConfigToml(config) {
10415
+ const name = config.name?.trim() || "自定义 API";
10416
+ const wireApi = config.wireApi === "responses" ? "responses" : "chat";
10417
+ return [
10418
+ `model_provider = "${INKDOWN_PROVIDER_ID}"`,
10419
+ `model = "${tomlEscape(config.model.trim())}"`,
10420
+ "",
10421
+ `[model_providers.${INKDOWN_PROVIDER_ID}]`,
10422
+ `name = "${tomlEscape(name)}"`,
10423
+ `base_url = "${tomlEscape(config.baseUrl.trim())}"`,
10424
+ `env_key = "${INKDOWN_PROVIDER_API_KEY_ENV}"`,
10425
+ `wire_api = "${wireApi}"`,
10426
+ ""
10427
+ ].join(`
10428
+ `);
10429
+ }
10430
+ function buildCustomProviderSpawnEnv(config, apiKey, codexHome) {
10431
+ return {
10432
+ CODEX_HOME: codexHome,
10433
+ [INKDOWN_PROVIDER_API_KEY_ENV]: apiKey
10434
+ };
10435
+ }
10436
+
10199
10437
  // src/runtimes/codex/codex-provider.ts
10200
10438
  var import_promises = require("node:fs/promises");
10201
- var import_node_fs2 = require("node:fs");
10202
- var import_node_path3 = require("node:path");
10439
+ var import_node_fs3 = require("node:fs");
10440
+ var import_node_path4 = require("node:path");
10203
10441
 
10204
10442
  // src/client/acp-paths.ts
10205
10443
  var import_node_os2 = require("node:os");
10206
- var import_node_path2 = require("node:path");
10444
+ var import_node_path3 = require("node:path");
10207
10445
  function getDefaultAgentDataDir() {
10208
10446
  if (process.env.INKDOWN_DATA_DIR) {
10209
10447
  return process.env.INKDOWN_DATA_DIR;
@@ -10212,24 +10450,24 @@ function getDefaultAgentDataDir() {
10212
10450
  return process.env.ACP_DATA_DIR;
10213
10451
  }
10214
10452
  if (process.platform === "win32") {
10215
- return process.env.LOCALAPPDATA || process.env.APPDATA || import_node_path2.join(import_node_os2.homedir(), "AppData", "Local", "inkdown");
10453
+ return process.env.LOCALAPPDATA || process.env.APPDATA || import_node_path3.join(import_node_os2.homedir(), "AppData", "Local", "inkdown");
10216
10454
  }
10217
10455
  if (process.platform === "darwin") {
10218
- return import_node_path2.join(import_node_os2.homedir(), "Library", "Application Support", "inkdown");
10456
+ return import_node_path3.join(import_node_os2.homedir(), "Library", "Application Support", "inkdown");
10219
10457
  }
10220
- return process.env.XDG_DATA_HOME || import_node_path2.join(import_node_os2.homedir(), ".local", "share", "inkdown");
10458
+ return process.env.XDG_DATA_HOME || import_node_path3.join(import_node_os2.homedir(), ".local", "share", "inkdown");
10221
10459
  }
10222
10460
 
10223
10461
  // src/runtimes/codex/codex-provider.ts
10224
10462
  function providerFilePath(dir) {
10225
- return import_node_path3.join(dir, "agent", "provider.json");
10463
+ return import_node_path4.join(dir, "agent", "provider.json");
10226
10464
  }
10227
10465
  function providerHomePath(dir) {
10228
- return import_node_path3.join(dir, "agent", "codex-home");
10466
+ return import_node_path4.join(dir, "agent", "codex-home");
10229
10467
  }
10230
10468
  async function readStoredAcpProvider(dir = getDefaultAgentDataDir()) {
10231
10469
  const file = providerFilePath(dir);
10232
- if (!import_node_fs2.existsSync(file))
10470
+ if (!import_node_fs3.existsSync(file))
10233
10471
  return null;
10234
10472
  try {
10235
10473
  const raw = JSON.parse(await import_promises.readFile(file, "utf8"));
@@ -10255,7 +10493,7 @@ function getAcpProviderCodexHome(dir = getDefaultAgentDataDir()) {
10255
10493
  async function provisionCustomProviderCodexHome(provider, codexHome) {
10256
10494
  try {
10257
10495
  await import_promises2.mkdir(codexHome, { recursive: true });
10258
- await import_promises2.writeFile(import_node_path4.join(codexHome, "config.toml"), buildCustomProviderConfigToml(provider), "utf8");
10496
+ await import_promises2.writeFile(import_node_path5.join(codexHome, "config.toml"), buildCustomProviderConfigToml(provider), "utf8");
10259
10497
  return true;
10260
10498
  } catch (error) {
10261
10499
  console.error("[acp] 自定义供应商 config.toml 写入失败,回落本机登录", error);
@@ -10264,6 +10502,7 @@ async function provisionCustomProviderCodexHome(provider, codexHome) {
10264
10502
  }
10265
10503
  var codexAdapter = {
10266
10504
  id: "codex-acp",
10505
+ probeQuota: async (options) => probeCodexQuota(options),
10267
10506
  probeAuth: () => {
10268
10507
  return probeCodexAuth();
10269
10508
  },
@@ -10280,20 +10519,86 @@ var codexAdapter = {
10280
10519
  }
10281
10520
  };
10282
10521
 
10283
- // src/runtimes/claude/index.ts
10284
- var import_node_fs3 = require("node:fs");
10522
+ // src/runtimes/claude/quota.ts
10523
+ var import_node_fs4 = require("node:fs");
10285
10524
  var import_node_os3 = require("node:os");
10286
- var import_node_path5 = require("node:path");
10525
+ var import_node_path6 = require("node:path");
10526
+ async function probeClaudeQuota(options) {
10527
+ const claudeHome = resolveClaudeHome();
10528
+ const claudeJsonPath = import_node_path6.join(import_node_os3.homedir(), ".claude.json");
10529
+ const credsPath = import_node_path6.join(claudeHome, ".credentials.json");
10530
+ let isLoggedIn = false;
10531
+ let isBanned = false;
10532
+ let accountEmail;
10533
+ let plan = "Claude Free / Default";
10534
+ if (import_node_fs4.existsSync(claudeJsonPath)) {
10535
+ try {
10536
+ const data = JSON.parse(import_node_fs4.readFileSync(claudeJsonPath, "utf8"));
10537
+ if (data.oauthAccount) {
10538
+ isLoggedIn = true;
10539
+ accountEmail = data.oauthAccount.emailAddress;
10540
+ plan = data.oauthAccount.subscriptionTier || "Claude Pro";
10541
+ }
10542
+ if (data.isBanned || data.accountSuspended || data.status === "banned") {
10543
+ isBanned = true;
10544
+ }
10545
+ } catch {}
10546
+ }
10547
+ if (import_node_fs4.existsSync(credsPath)) {
10548
+ try {
10549
+ const creds = JSON.parse(import_node_fs4.readFileSync(credsPath, "utf8"));
10550
+ if (creds.accessToken || creds.sessionKey)
10551
+ isLoggedIn = true;
10552
+ } catch {}
10553
+ }
10554
+ if (process.env.ANTHROPIC_API_KEY || process.env.CLAUDE_CODE_OAUTH_TOKEN) {
10555
+ isLoggedIn = true;
10556
+ plan = "API Key (Env)";
10557
+ }
10558
+ if (isBanned) {
10559
+ return {
10560
+ runtimeId: "claude",
10561
+ provider: "Anthropic / Claude Code",
10562
+ status: "banned",
10563
+ message: "账号已被封禁或暂停使用 (Account suspended / banned)",
10564
+ updatedAt: Date.now()
10565
+ };
10566
+ }
10567
+ if (!isLoggedIn) {
10568
+ return {
10569
+ runtimeId: "claude",
10570
+ provider: "Anthropic / Claude Code",
10571
+ status: "unauthorized",
10572
+ message: "未登录 Claude Code 或凭据无效 (Unauthorized)",
10573
+ updatedAt: Date.now()
10574
+ };
10575
+ }
10576
+ return {
10577
+ runtimeId: "claude",
10578
+ provider: "Anthropic / Claude Code",
10579
+ account: {
10580
+ email: accountEmail,
10581
+ plan
10582
+ },
10583
+ status: "ok",
10584
+ updatedAt: Date.now()
10585
+ };
10586
+ }
10587
+
10588
+ // src/runtimes/claude/index.ts
10589
+ var import_node_fs5 = require("node:fs");
10590
+ var import_node_os4 = require("node:os");
10591
+ var import_node_path7 = require("node:path");
10287
10592
  function resolveClaudeHome() {
10288
10593
  const fromEnv = process.env.CLAUDE_CONFIG_DIR?.trim();
10289
10594
  if (fromEnv)
10290
10595
  return fromEnv;
10291
- return import_node_path5.join(import_node_os3.homedir(), ".claude");
10596
+ return import_node_path7.join(import_node_os4.homedir(), ".claude");
10292
10597
  }
10293
10598
  function probeClaudeAuth() {
10294
10599
  const claudeHome = resolveClaudeHome();
10295
- const hasCodexHome = import_node_fs3.existsSync(claudeHome);
10296
- const hasAuthFile = import_node_fs3.existsSync(import_node_path5.join(import_node_os3.homedir(), ".claude.json")) || import_node_fs3.existsSync(import_node_path5.join(claudeHome, ".credentials.json"));
10600
+ const hasCodexHome = import_node_fs5.existsSync(claudeHome);
10601
+ const hasAuthFile = import_node_fs5.existsSync(import_node_path7.join(import_node_os4.homedir(), ".claude.json")) || import_node_fs5.existsSync(import_node_path7.join(claudeHome, ".credentials.json"));
10297
10602
  const hasApiKeyEnv = Boolean(process.env.ANTHROPIC_API_KEY?.trim() || process.env.CLAUDE_CODE_OAUTH_TOKEN?.trim());
10298
10603
  return {
10299
10604
  codexHome: claudeHome,
@@ -10306,21 +10611,22 @@ function probeClaudeAuth() {
10306
10611
  var claudeAdapter = {
10307
10612
  id: "claude",
10308
10613
  probeAuth: () => probeClaudeAuth(),
10614
+ probeQuota: async (options) => probeClaudeQuota(options),
10309
10615
  orderAuthMethods: (methods) => methods,
10310
10616
  canSkipInteractiveAuth: () => false
10311
10617
  };
10312
10618
 
10313
10619
  // src/runtimes/gemini/index.ts
10314
- var import_node_fs4 = require("node:fs");
10315
- var import_node_os4 = require("node:os");
10316
- var import_node_path6 = require("node:path");
10620
+ var import_node_fs6 = require("node:fs");
10621
+ var import_node_os5 = require("node:os");
10622
+ var import_node_path8 = require("node:path");
10317
10623
  function resolveGeminiHome() {
10318
- return import_node_path6.join(import_node_os4.homedir(), ".gemini");
10624
+ return import_node_path8.join(import_node_os5.homedir(), ".gemini");
10319
10625
  }
10320
10626
  function probeGeminiAuth() {
10321
10627
  const geminiHome = resolveGeminiHome();
10322
- const hasCodexHome = import_node_fs4.existsSync(geminiHome);
10323
- const hasAuthFile = import_node_fs4.existsSync(import_node_path6.join(geminiHome, "oauth_creds.json")) || Boolean(process.env.GOOGLE_APPLICATION_CREDENTIALS?.trim());
10628
+ const hasCodexHome = import_node_fs6.existsSync(geminiHome);
10629
+ const hasAuthFile = import_node_fs6.existsSync(import_node_path8.join(geminiHome, "oauth_creds.json")) || Boolean(process.env.GOOGLE_APPLICATION_CREDENTIALS?.trim());
10324
10630
  const hasApiKeyEnv = Boolean(process.env.GEMINI_API_KEY?.trim() || process.env.GOOGLE_API_KEY?.trim());
10325
10631
  return {
10326
10632
  codexHome: geminiHome,
@@ -10338,18 +10644,18 @@ var geminiAdapter = {
10338
10644
  };
10339
10645
 
10340
10646
  // src/runtimes/copilot/index.ts
10341
- var import_node_fs5 = require("node:fs");
10342
- var import_node_os5 = require("node:os");
10343
- var import_node_path7 = require("node:path");
10647
+ var import_node_fs7 = require("node:fs");
10648
+ var import_node_os6 = require("node:os");
10649
+ var import_node_path9 = require("node:path");
10344
10650
  function resolveCopilotHome() {
10345
10651
  const fromEnv = process.env.COPILOT_HOME?.trim();
10346
10652
  if (fromEnv)
10347
10653
  return fromEnv;
10348
- return import_node_path7.join(import_node_os5.homedir(), ".copilot");
10654
+ return import_node_path9.join(import_node_os6.homedir(), ".copilot");
10349
10655
  }
10350
10656
  function hasCopilotLogin(home) {
10351
10657
  try {
10352
- const raw = import_node_fs5.readFileSync(import_node_path7.join(home, "config.json"), "utf8");
10658
+ const raw = import_node_fs7.readFileSync(import_node_path9.join(home, "config.json"), "utf8");
10353
10659
  const parsed = JSON.parse(raw);
10354
10660
  return Array.isArray(parsed.loggedInUsers) && parsed.loggedInUsers.length > 0;
10355
10661
  } catch {
@@ -10358,7 +10664,7 @@ function hasCopilotLogin(home) {
10358
10664
  }
10359
10665
  function probeCopilotAuth() {
10360
10666
  const copilotHome = resolveCopilotHome();
10361
- const hasCodexHome = import_node_fs5.existsSync(copilotHome);
10667
+ const hasCodexHome = import_node_fs7.existsSync(copilotHome);
10362
10668
  const hasAuthFile = hasCopilotLogin(copilotHome);
10363
10669
  const hasApiKeyEnv = Boolean(process.env.COPILOT_GITHUB_TOKEN?.trim() || process.env.GH_TOKEN?.trim() || process.env.GITHUB_TOKEN?.trim());
10364
10670
  return {
@@ -10376,17 +10682,68 @@ var copilotAdapter = {
10376
10682
  canSkipInteractiveAuth: () => false
10377
10683
  };
10378
10684
 
10685
+ // src/runtimes/opencode/quota.ts
10686
+ var import_node_fs8 = require("node:fs");
10687
+ function resolveOpencodeAuthPath() {
10688
+ const candidates = resolveOpencodeAuthCandidates();
10689
+ for (const c of candidates) {
10690
+ if (import_node_fs8.existsSync(c))
10691
+ return c;
10692
+ }
10693
+ return candidates[0] ?? null;
10694
+ }
10695
+ async function probeOpencodeQuota(runtimeId = "opencode") {
10696
+ const authPath = resolveOpencodeAuthPath();
10697
+ let isLoggedIn = false;
10698
+ let accountEmail;
10699
+ let plan = "OpenCode Community";
10700
+ if (authPath && import_node_fs8.existsSync(authPath)) {
10701
+ try {
10702
+ const data = JSON.parse(import_node_fs8.readFileSync(authPath, "utf8"));
10703
+ if (data && typeof data === "object") {
10704
+ const keys = Object.keys(data);
10705
+ if (keys.length > 0) {
10706
+ isLoggedIn = true;
10707
+ if (data.email)
10708
+ accountEmail = String(data.email);
10709
+ if (data.plan)
10710
+ plan = String(data.plan);
10711
+ }
10712
+ }
10713
+ } catch {}
10714
+ }
10715
+ if (!isLoggedIn) {
10716
+ return {
10717
+ runtimeId,
10718
+ provider: "OpenCode",
10719
+ status: "unauthorized",
10720
+ message: "未检测到 OpenCode 登录凭证 (auth.json / SQLite)",
10721
+ updatedAt: Date.now()
10722
+ };
10723
+ }
10724
+ return {
10725
+ runtimeId,
10726
+ provider: "OpenCode",
10727
+ account: {
10728
+ email: accountEmail,
10729
+ plan
10730
+ },
10731
+ status: "ok",
10732
+ updatedAt: Date.now()
10733
+ };
10734
+ }
10735
+
10379
10736
  // src/runtimes/opencode/index.ts
10380
- var import_node_fs6 = require("node:fs");
10381
- var import_node_os6 = require("node:os");
10382
- var import_node_path8 = require("node:path");
10737
+ var import_node_fs9 = require("node:fs");
10738
+ var import_node_os7 = require("node:os");
10739
+ var import_node_path10 = require("node:path");
10383
10740
  function pickEnv(env, key) {
10384
10741
  return env?.[key]?.trim() ?? "";
10385
10742
  }
10386
10743
  function resolveOpencodeAuthCandidates(overrides) {
10387
10744
  const platform = overrides?.platform ?? process.platform;
10388
10745
  const env = overrides?.env ?? process.env;
10389
- const home = overrides?.home ?? import_node_os6.homedir();
10746
+ const home = overrides?.home ?? import_node_os7.homedir();
10390
10747
  const seen = new Set;
10391
10748
  const out = [];
10392
10749
  const push = (p) => {
@@ -10397,27 +10754,27 @@ function resolveOpencodeAuthCandidates(overrides) {
10397
10754
  };
10398
10755
  const xdg = pickEnv(env, "XDG_DATA_HOME");
10399
10756
  if (xdg)
10400
- push(import_node_path8.join(xdg, "opencode", "auth.json"));
10757
+ push(import_node_path10.join(xdg, "opencode", "auth.json"));
10401
10758
  if (platform === "win32") {
10402
- const localAppData = pickEnv(env, "LOCALAPPDATA") || (pickEnv(env, "USERPROFILE") ? import_node_path8.join(pickEnv(env, "USERPROFILE"), "AppData", "Local") : "");
10759
+ const localAppData = pickEnv(env, "LOCALAPPDATA") || (pickEnv(env, "USERPROFILE") ? import_node_path10.join(pickEnv(env, "USERPROFILE"), "AppData", "Local") : "");
10403
10760
  if (localAppData)
10404
- push(import_node_path8.join(localAppData, "opencode", "auth.json"));
10761
+ push(import_node_path10.join(localAppData, "opencode", "auth.json"));
10405
10762
  const userProfile = pickEnv(env, "USERPROFILE") || home;
10406
10763
  if (userProfile)
10407
- push(import_node_path8.join(userProfile, ".local", "share", "opencode", "auth.json"));
10764
+ push(import_node_path10.join(userProfile, ".local", "share", "opencode", "auth.json"));
10408
10765
  } else if (home) {
10409
- push(import_node_path8.join(home, ".local", "share", "opencode", "auth.json"));
10766
+ push(import_node_path10.join(home, ".local", "share", "opencode", "auth.json"));
10410
10767
  }
10411
10768
  return out;
10412
10769
  }
10413
10770
  function resolveOpencodeAuthFile() {
10414
- return resolveOpencodeAuthCandidates()[0] ?? import_node_path8.join(import_node_os6.homedir(), ".local", "share", "opencode", "auth.json");
10771
+ return resolveOpencodeAuthCandidates()[0] ?? import_node_path10.join(import_node_os7.homedir(), ".local", "share", "opencode", "auth.json");
10415
10772
  }
10416
10773
  function isValidOpencodeAuthFile(authFile) {
10417
10774
  try {
10418
- if (!authFile || !import_node_fs6.existsSync(authFile))
10775
+ if (!authFile || !import_node_fs9.existsSync(authFile))
10419
10776
  return false;
10420
- const raw = import_node_fs6.readFileSync(authFile, "utf8").trim();
10777
+ const raw = import_node_fs9.readFileSync(authFile, "utf8").trim();
10421
10778
  if (!raw)
10422
10779
  return false;
10423
10780
  const parsed = JSON.parse(raw);
@@ -10435,7 +10792,7 @@ function probeOpencodeAuth(overrides) {
10435
10792
  for (const candidate of candidates) {
10436
10793
  let exists = false;
10437
10794
  try {
10438
- exists = import_node_fs6.existsSync(candidate);
10795
+ exists = import_node_fs9.existsSync(candidate);
10439
10796
  } catch {
10440
10797
  exists = false;
10441
10798
  }
@@ -10448,10 +10805,10 @@ function probeOpencodeAuth(overrides) {
10448
10805
  validFile = candidate;
10449
10806
  }
10450
10807
  const authFile = validFile ?? firstExisting ?? candidates[0] ?? resolveOpencodeAuthFile();
10451
- const authDir = import_node_path8.dirname(authFile);
10808
+ const authDir = import_node_path10.dirname(authFile);
10452
10809
  let hasCodexHome = false;
10453
10810
  try {
10454
- hasCodexHome = import_node_fs6.existsSync(authDir);
10811
+ hasCodexHome = import_node_fs9.existsSync(authDir);
10455
10812
  } catch {
10456
10813
  hasCodexHome = false;
10457
10814
  }
@@ -10467,33 +10824,65 @@ function probeOpencodeAuth(overrides) {
10467
10824
  var opencodeAdapter = {
10468
10825
  id: "opencode",
10469
10826
  probeAuth: () => probeOpencodeAuth(),
10827
+ probeQuota: async () => probeOpencodeQuota(),
10828
+ orderAuthMethods: (methods) => methods,
10829
+ canSkipInteractiveAuth: () => false,
10830
+ tryDirectSessionFirst: true
10831
+ };
10832
+
10833
+ // src/runtimes/opencode-v2/index.ts
10834
+ var opencodeV2Adapter = {
10835
+ id: "opencode-v2",
10836
+ probeAuth: () => probeOpencodeAuth(),
10470
10837
  orderAuthMethods: (methods) => methods,
10471
10838
  canSkipInteractiveAuth: () => false,
10472
10839
  tryDirectSessionFirst: true
10473
10840
  };
10474
10841
 
10842
+ // src/runtimes/cursor/quota.ts
10843
+ async function probeCursorQuota() {
10844
+ const auth = probeCursorAuth();
10845
+ if (!auth.looksLoggedIn) {
10846
+ return {
10847
+ runtimeId: "cursor-cli",
10848
+ provider: "Cursor",
10849
+ status: "unauthorized",
10850
+ message: "未检测到 Cursor CLI 登录凭证",
10851
+ updatedAt: Date.now()
10852
+ };
10853
+ }
10854
+ return {
10855
+ runtimeId: "cursor-cli",
10856
+ provider: "Cursor",
10857
+ account: {
10858
+ plan: "Cursor Pro / Fast Requests"
10859
+ },
10860
+ status: "ok",
10861
+ updatedAt: Date.now()
10862
+ };
10863
+ }
10475
10864
  // src/runtimes/cursor/index.ts
10476
- var import_node_fs7 = require("node:fs");
10477
- var import_node_os7 = require("node:os");
10478
- var import_node_path9 = require("node:path");
10865
+ var import_node_fs10 = require("node:fs");
10866
+ var import_node_os8 = require("node:os");
10867
+ var import_node_path11 = require("node:path");
10479
10868
  function cursorLocalAppData(env) {
10480
10869
  const local = env.LOCALAPPDATA?.trim();
10481
10870
  if (local)
10482
10871
  return local;
10483
10872
  const profile = env.USERPROFILE?.trim();
10484
- return profile ? import_node_path9.join(profile, "AppData", "Local") : "";
10873
+ return profile ? import_node_path11.join(profile, "AppData", "Local") : "";
10485
10874
  }
10486
10875
  function isOnPath(command, env, platform) {
10487
10876
  const pathValue = env.PATH ?? env.Path ?? "";
10488
10877
  if (!pathValue.trim())
10489
10878
  return false;
10490
- const sep = platform === "win32" ? ";" : import_node_path9.delimiter;
10879
+ const sep = platform === "win32" ? ";" : import_node_path11.delimiter;
10491
10880
  for (const dir of pathValue.split(sep)) {
10492
10881
  const trimmed = dir.trim().replace(/^"|"$/g, "");
10493
10882
  if (!trimmed)
10494
10883
  continue;
10495
10884
  try {
10496
- if (import_node_fs7.existsSync(import_node_path9.join(trimmed, command)))
10885
+ if (import_node_fs10.existsSync(import_node_path11.join(trimmed, command)))
10497
10886
  return true;
10498
10887
  } catch {}
10499
10888
  }
@@ -10502,19 +10891,19 @@ function isOnPath(command, env, platform) {
10502
10891
  function resolveDirectCursorCommand(platform, env, home) {
10503
10892
  if (platform === "win32") {
10504
10893
  const localAppData = cursorLocalAppData(env);
10505
- return localAppData ? import_node_path9.join(localAppData, "cursor-agent", "agent.cmd") : "";
10894
+ return localAppData ? import_node_path11.join(localAppData, "cursor-agent", "agent.cmd") : "";
10506
10895
  }
10507
- return home ? import_node_path9.join(home, ".local", "bin", "agent") : "";
10896
+ return home ? import_node_path11.join(home, ".local", "bin", "agent") : "";
10508
10897
  }
10509
10898
  function resolveCursorSpawnCommand(overrides) {
10510
10899
  const args = ["acp"];
10511
10900
  const platform = overrides?.platform ?? process.platform;
10512
10901
  const env = overrides?.env ?? process.env;
10513
- const home = overrides?.home ?? import_node_os7.homedir();
10902
+ const home = overrides?.home ?? import_node_os8.homedir();
10514
10903
  const binary = platform === "win32" ? "agent.cmd" : "agent";
10515
10904
  const direct = resolveDirectCursorCommand(platform, env, home);
10516
10905
  try {
10517
- if (direct && import_node_fs7.existsSync(direct))
10906
+ if (direct && import_node_fs10.existsSync(direct))
10518
10907
  return { command: direct, args };
10519
10908
  } catch {}
10520
10909
  if (isOnPath(binary, env, platform))
@@ -10529,12 +10918,12 @@ function cursorRoamingAppData(env, home) {
10529
10918
  if (roaming)
10530
10919
  return roaming;
10531
10920
  const profile = pickEnv2(env, "USERPROFILE") || home;
10532
- return profile ? import_node_path9.join(profile, "AppData", "Roaming") : "";
10921
+ return profile ? import_node_path11.join(profile, "AppData", "Roaming") : "";
10533
10922
  }
10534
10923
  function resolveCursorAuthCandidates(overrides) {
10535
10924
  const platform = overrides?.platform ?? process.platform;
10536
10925
  const env = overrides?.env ?? process.env;
10537
- const home = overrides?.home ?? import_node_os7.homedir();
10926
+ const home = overrides?.home ?? import_node_os8.homedir();
10538
10927
  const seen = new Set;
10539
10928
  const out = [];
10540
10929
  const push = (p) => {
@@ -10545,16 +10934,16 @@ function resolveCursorAuthCandidates(overrides) {
10545
10934
  };
10546
10935
  const xdg = pickEnv2(env, "XDG_CONFIG_HOME");
10547
10936
  if (xdg)
10548
- push(import_node_path9.join(xdg, "cursor", "auth.json"));
10937
+ push(import_node_path11.join(xdg, "cursor", "auth.json"));
10549
10938
  if (platform === "win32") {
10550
10939
  const profile = pickEnv2(env, "USERPROFILE") || home;
10551
10940
  if (profile)
10552
- push(import_node_path9.join(profile, ".config", "cursor", "auth.json"));
10941
+ push(import_node_path11.join(profile, ".config", "cursor", "auth.json"));
10553
10942
  const roaming = cursorRoamingAppData(env, home);
10554
10943
  if (roaming)
10555
- push(import_node_path9.join(roaming, "Cursor", "User", "globalStorage", "storage.json"));
10944
+ push(import_node_path11.join(roaming, "Cursor", "User", "globalStorage", "storage.json"));
10556
10945
  } else if (home) {
10557
- push(import_node_path9.join(home, ".config", "cursor", "auth.json"));
10946
+ push(import_node_path11.join(home, ".config", "cursor", "auth.json"));
10558
10947
  }
10559
10948
  return out;
10560
10949
  }
@@ -10565,9 +10954,9 @@ function isValidCursorAuthFile(authFile) {
10565
10954
  try {
10566
10955
  if (!authFile || isStorageHintPath(authFile))
10567
10956
  return false;
10568
- if (!import_node_fs7.existsSync(authFile))
10957
+ if (!import_node_fs10.existsSync(authFile))
10569
10958
  return false;
10570
- const raw = import_node_fs7.readFileSync(authFile, "utf8").trim();
10959
+ const raw = import_node_fs10.readFileSync(authFile, "utf8").trim();
10571
10960
  if (!raw)
10572
10961
  return false;
10573
10962
  const parsed = JSON.parse(raw);
@@ -10585,9 +10974,9 @@ function isHintCursorStorageFile(authFile) {
10585
10974
  try {
10586
10975
  if (!authFile || !isStorageHintPath(authFile))
10587
10976
  return false;
10588
- if (!import_node_fs7.existsSync(authFile))
10977
+ if (!import_node_fs10.existsSync(authFile))
10589
10978
  return false;
10590
- const raw = import_node_fs7.readFileSync(authFile, "utf8").trim();
10979
+ const raw = import_node_fs10.readFileSync(authFile, "utf8").trim();
10591
10980
  if (!raw)
10592
10981
  return false;
10593
10982
  const parsed = JSON.parse(raw);
@@ -10603,7 +10992,7 @@ function isValidCursorCandidate(authFile) {
10603
10992
  }
10604
10993
  function probeCursorAuth(overrides) {
10605
10994
  const env = overrides?.env ?? process.env;
10606
- const home = overrides?.home ?? import_node_os7.homedir();
10995
+ const home = overrides?.home ?? import_node_os8.homedir();
10607
10996
  const hasApiKeyEnv = Boolean(env.CURSOR_API_KEY?.trim() || env.CURSOR_AUTH_TOKEN?.trim());
10608
10997
  const candidates = resolveCursorAuthCandidates(overrides);
10609
10998
  let firstExisting = null;
@@ -10611,7 +11000,7 @@ function probeCursorAuth(overrides) {
10611
11000
  for (const candidate of candidates) {
10612
11001
  let exists = false;
10613
11002
  try {
10614
- exists = import_node_fs7.existsSync(candidate);
11003
+ exists = import_node_fs10.existsSync(candidate);
10615
11004
  } catch {
10616
11005
  exists = false;
10617
11006
  }
@@ -10623,12 +11012,12 @@ function probeCursorAuth(overrides) {
10623
11012
  if (isValidCursorCandidate(candidate))
10624
11013
  validFile = candidate;
10625
11014
  }
10626
- const fallback = home ? import_node_path9.join(home, ".config", "cursor", "auth.json") : "";
11015
+ const fallback = home ? import_node_path11.join(home, ".config", "cursor", "auth.json") : "";
10627
11016
  const authFile = validFile ?? firstExisting ?? candidates[0] ?? fallback;
10628
- const authDir = authFile ? import_node_path9.dirname(authFile) : "";
11017
+ const authDir = authFile ? import_node_path11.dirname(authFile) : "";
10629
11018
  let hasCodexHome = false;
10630
11019
  try {
10631
- hasCodexHome = authDir ? import_node_fs7.existsSync(authDir) : false;
11020
+ hasCodexHome = authDir ? import_node_fs10.existsSync(authDir) : false;
10632
11021
  } catch {
10633
11022
  hasCodexHome = false;
10634
11023
  }
@@ -10643,6 +11032,7 @@ function probeCursorAuth(overrides) {
10643
11032
  var cursorAdapter = {
10644
11033
  id: "cursor-cli",
10645
11034
  probeAuth: () => probeCursorAuth(),
11035
+ probeQuota: async () => probeCursorQuota(),
10646
11036
  resolveSpawnCommand: () => resolveCursorSpawnCommand(),
10647
11037
  orderAuthMethods: (methods) => methods,
10648
11038
  canSkipInteractiveAuth: () => false,
@@ -10696,6 +11086,55 @@ var deepseekAdapter = {
10696
11086
  canSkipInteractiveAuth: () => false
10697
11087
  };
10698
11088
 
11089
+ // src/runtimes/agy/quota.ts
11090
+ var import_node_fs11 = require("node:fs");
11091
+ var import_node_path12 = require("node:path");
11092
+ function resolveGeminiHome2() {
11093
+ const home = process.env.USERPROFILE || process.env.HOME || "";
11094
+ return import_node_path12.join(home, ".gemini");
11095
+ }
11096
+ async function probeAgyQuota(options) {
11097
+ const geminiHome = resolveGeminiHome2();
11098
+ const hasAgyDir = import_node_fs11.existsSync(import_node_path12.join(geminiHome, "antigravity")) || import_node_fs11.existsSync(import_node_path12.join(geminiHome, "antigravity-cli"));
11099
+ const hasApiKey = Boolean(process.env.GEMINI_API_KEY || process.env.GOOGLE_API_KEY);
11100
+ const isAvailable = hasAgyDir || hasApiKey;
11101
+ if (!isAvailable) {
11102
+ return {
11103
+ runtimeId: "agy",
11104
+ provider: "Google Antigravity",
11105
+ status: "unauthorized",
11106
+ message: "wenjianlingu antigravity cli",
11107
+ updatedAt: Date.now()
11108
+ };
11109
+ }
11110
+ return {
11111
+ runtimeId: "agy",
11112
+ provider: "Google Antigravity",
11113
+ account: {
11114
+ plan: "Antigravity / Gemini",
11115
+ type: "gemini"
11116
+ },
11117
+ primaryWindow: {
11118
+ label: "5-Hour limit",
11119
+ percentLeft: 100,
11120
+ usedPercent: 0,
11121
+ windowDurationMins: 300
11122
+ },
11123
+ secondaryWindow: {
11124
+ label: "Weekly limit",
11125
+ percentLeft: 100,
11126
+ usedPercent: 0,
11127
+ windowDurationMins: 10080
11128
+ },
11129
+ credits: {
11130
+ unlimited: true,
11131
+ balance: "unlimited"
11132
+ },
11133
+ status: "ok",
11134
+ updatedAt: Date.now()
11135
+ };
11136
+ }
11137
+
10699
11138
  // src/runtimes/agy/index.ts
10700
11139
  function probeAgyAuth() {
10701
11140
  return {
@@ -10709,6 +11148,7 @@ function probeAgyAuth() {
10709
11148
  var agyAdapter = {
10710
11149
  id: "agy",
10711
11150
  probeAuth: () => probeAgyAuth(),
11151
+ probeQuota: (options) => probeAgyQuota(options),
10712
11152
  orderAuthMethods: (methods) => methods,
10713
11153
  canSkipInteractiveAuth: () => false,
10714
11154
  tryDirectSessionFirst: true
@@ -10728,6 +11168,8 @@ function getAcpRuntimeAdapter(runtimeId) {
10728
11168
  return copilotAdapter;
10729
11169
  case opencodeAdapter.id:
10730
11170
  return opencodeAdapter;
11171
+ case opencodeV2Adapter.id:
11172
+ return opencodeV2Adapter;
10731
11173
  case cursorAdapter.id:
10732
11174
  case "cursor":
10733
11175
  return cursorAdapter;
@@ -10934,17 +11376,17 @@ async function sdkRequest(agent, method, params, timeoutMs = ACP_SDK_REQUEST_TIM
10934
11376
 
10935
11377
  // src/client/acp-fs.ts
10936
11378
  var import_promises3 = require("node:fs/promises");
10937
- var import_node_path10 = require("node:path");
11379
+ var import_node_path13 = require("node:path");
10938
11380
  var import_promises4 = require("node:fs/promises");
10939
11381
  var MAX_READ_BYTES = 2 * 1024 * 1024;
10940
11382
  var BINARY_DOCUMENT_EXTENSIONS = new Set([".epub", ".mobi", ".azw", ".azw3", ".pdf"]);
10941
11383
  function isBinaryDocumentPath(filePath) {
10942
- return BINARY_DOCUMENT_EXTENSIONS.has(import_node_path10.extname(filePath).toLowerCase());
11384
+ return BINARY_DOCUMENT_EXTENSIONS.has(import_node_path13.extname(filePath).toLowerCase());
10943
11385
  }
10944
11386
  function assertPathInsideWorkspace(filePath, workspaceRoot) {
10945
- const root = import_node_path10.resolve(workspaceRoot);
10946
- const target = import_node_path10.resolve(filePath);
10947
- const rootWithSep = root.endsWith(import_node_path10.sep) ? root : root + import_node_path10.sep;
11387
+ const root = import_node_path13.resolve(workspaceRoot);
11388
+ const target = import_node_path13.resolve(filePath);
11389
+ const rootWithSep = root.endsWith(import_node_path13.sep) ? root : root + import_node_path13.sep;
10948
11390
  if (target !== root && !target.startsWith(rootWithSep)) {
10949
11391
  throw new Error(`路径不在工作区内: ${filePath}`);
10950
11392
  }
@@ -10975,7 +11417,7 @@ async function acpReadTextFile(params) {
10975
11417
  }
10976
11418
  async function acpWriteTextFile(params) {
10977
11419
  const abs = assertPathInsideWorkspace(params.path, params.workspaceRoot);
10978
- await import_promises4.mkdir(import_node_path10.dirname(abs), { recursive: true });
11420
+ await import_promises4.mkdir(import_node_path13.dirname(abs), { recursive: true });
10979
11421
  await import_promises3.writeFile(abs, params.content, "utf-8");
10980
11422
  return {};
10981
11423
  }
@@ -11620,8 +12062,8 @@ class AcpTerminalManager {
11620
12062
 
11621
12063
  // src/client/acp-proxy-service.ts
11622
12064
  var import_promises5 = require("node:fs/promises");
11623
- var import_node_fs8 = require("node:fs");
11624
- var import_node_path11 = require("node:path");
12065
+ var import_node_fs12 = require("node:fs");
12066
+ var import_node_path14 = require("node:path");
11625
12067
  var DEFAULT_ACP_PROXY_SETTINGS = {
11626
12068
  enabled: false,
11627
12069
  host: "127.0.0.1",
@@ -11630,11 +12072,11 @@ var DEFAULT_ACP_PROXY_SETTINGS = {
11630
12072
  var PROXY_ENV_KEYS = ["HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY"];
11631
12073
  var LOWERCASE_PROXY_ENV_KEYS = ["http_proxy", "https_proxy", "all_proxy", "no_proxy"];
11632
12074
  function proxyFilePath(dir) {
11633
- return import_node_path11.join(dir, "agent", "proxy.json");
12075
+ return import_node_path14.join(dir, "agent", "proxy.json");
11634
12076
  }
11635
12077
  async function readAcpProxySettings(dir = getDefaultAgentDataDir()) {
11636
12078
  const file = proxyFilePath(dir);
11637
- if (!import_node_fs8.existsSync(file))
12079
+ if (!import_node_fs12.existsSync(file))
11638
12080
  return { ...DEFAULT_ACP_PROXY_SETTINGS };
11639
12081
  try {
11640
12082
  const raw = JSON.parse(await import_promises5.readFile(file, "utf8"));
@@ -11697,6 +12139,12 @@ class AcpSessionHandle {
11697
12139
  async prompt(promptText, options) {
11698
12140
  return this.client.promptSession(this.sessionId, promptText, options);
11699
12141
  }
12142
+ get quota() {
12143
+ return this.client.getCachedQuota(this.sessionId);
12144
+ }
12145
+ async getQuota() {
12146
+ return this.client.getQuota(this.sessionId);
12147
+ }
11700
12148
  get availableCommands() {
11701
12149
  return this.client.getAvailableCommands(this.sessionId);
11702
12150
  }
@@ -11708,6 +12156,7 @@ class AcpSessionHandle {
11708
12156
  class AcpClient {
11709
12157
  status = "disconnected";
11710
12158
  commandsCache = new AvailableCommandsCache;
12159
+ quotaCache = new QuotaCache;
11711
12160
  runtimeInfo;
11712
12161
  adapter;
11713
12162
  workspaceRoot;
@@ -11818,6 +12267,7 @@ class AcpClient {
11818
12267
  },
11819
12268
  onSessionUpdate: (params) => {
11820
12269
  this.commandsCache.observe(params);
12270
+ this.quotaCache.observe(params, this.runtimeInfo.id);
11821
12271
  this.callbacks.onSessionUpdate?.(params);
11822
12272
  }
11823
12273
  };
@@ -11848,6 +12298,23 @@ class AcpClient {
11848
12298
  return err({ code: "ACP_PROTOCOL_ERROR", message });
11849
12299
  }
11850
12300
  }
12301
+ getCachedQuota(sessionId) {
12302
+ return this.quotaCache.get(sessionId, this.runtimeInfo.id);
12303
+ }
12304
+ async getQuota(sessionId) {
12305
+ const cached = this.getCachedQuota(sessionId);
12306
+ if (cached && Date.now() - cached.updatedAt < 30000) {
12307
+ return cached;
12308
+ }
12309
+ if (this.adapter.probeQuota) {
12310
+ const probed = await this.adapter.probeQuota({ sessionId });
12311
+ if (probed) {
12312
+ this.quotaCache.set(probed, sessionId);
12313
+ return probed;
12314
+ }
12315
+ }
12316
+ return cached ?? null;
12317
+ }
11851
12318
  getAvailableCommands(sessionId) {
11852
12319
  return this.commandsCache.get(sessionId);
11853
12320
  }
@@ -12675,6 +13142,20 @@ async function handleRpcRequest(id, method, params) {
12675
13142
  }
12676
13143
  break;
12677
13144
  }
13145
+ case "session/quota": {
13146
+ const { sessionId } = params ?? {};
13147
+ if (!client2) {
13148
+ sendError(id, -32002, "Client not connected");
13149
+ return;
13150
+ }
13151
+ try {
13152
+ const quota = await client2.getQuota(sessionId ? String(sessionId) : undefined);
13153
+ sendResponse(id, { sessionId, quota });
13154
+ } catch (err) {
13155
+ sendError(id, -32000, err instanceof Error ? err.message : String(err));
13156
+ }
13157
+ break;
13158
+ }
12678
13159
  case "session/commands": {
12679
13160
  const { sessionId } = params ?? {};
12680
13161
  if (!client2) {
@@ -12760,7 +13241,7 @@ function startSidecar() {
12760
13241
  process.exit(0);
12761
13242
  });
12762
13243
  sendNotification("ready", {
12763
- version: "0.1.2",
13244
+ version: ACP_CLIENT_VERSION,
12764
13245
  platform: process.platform,
12765
13246
  pid: process.pid
12766
13247
  });