@yitom/acp-client 0.1.4 → 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/index.js CHANGED
@@ -65,6 +65,7 @@ var CODEX_ACP_NPM_PACKAGE = "@agentclientprotocol/codex-acp";
65
65
  var CLAUDE_ACP_NPM_PACKAGE = "@agentclientprotocol/claude-agent-acp";
66
66
  var DEEPSEEK_DSH_NPM_PACKAGE = "@deepseek-ai/dsh";
67
67
  var AGY_ACP_NPM_PACKAGE = "@yitom/agy-acp-map";
68
+ var OPENCODE_CLI_NPM_PACKAGE = "@opencode/cli";
68
69
  var LEGACY_ZED_CODEX_ACP_NPM_PACKAGE = "@zed-industries/codex-acp";
69
70
  var DEFAULT_ACP_RUNTIME_ID = "codex-acp";
70
71
  function isWindowsPlatform() {
@@ -117,6 +118,15 @@ var BUILTIN_ACP_RUNTIMES = [
117
118
  args: ["acp"],
118
119
  requiredEnvKeys: []
119
120
  },
121
+ {
122
+ id: "opencode-v2",
123
+ name: "OpenCode v2",
124
+ description: "通过 npx 启动独立产品线 @opencode/cli v2(acp);与 1.x 共存,复用 v2 SQLite 登录态",
125
+ authHint: "v2 登录态在 SQLite(auth.json 仅兼容残留);未登录先用 v2 二进制跑 opencode auth login",
126
+ command: "npx",
127
+ args: ["-y", OPENCODE_CLI_NPM_PACKAGE, "acp"],
128
+ requiredEnvKeys: []
129
+ },
120
130
  {
121
131
  id: "cursor-cli",
122
132
  name: "Cursor",
@@ -149,7 +159,7 @@ function findBuiltinAcpRuntime(id) {
149
159
  return BUILTIN_ACP_RUNTIMES.find((item) => item.id === id);
150
160
  }
151
161
  // src/version.ts
152
- var ACP_CLIENT_VERSION = "0.1.4";
162
+ var ACP_CLIENT_VERSION = "0.1.5";
153
163
  // src/session/available-commands.ts
154
164
  function normalizeCommand(raw) {
155
165
  if (!raw || typeof raw !== "object")
@@ -238,43 +248,169 @@ class AvailableCommandsCache {
238
248
  }
239
249
  }
240
250
 
251
+ // src/session/quota.ts
252
+ function parseRateLimitsFromStatusText(text, runtimeId = "unknown") {
253
+ if (!text || typeof text !== "string")
254
+ return null;
255
+ const lines = text.split(/\r?\n/);
256
+ let account;
257
+ const windows = [];
258
+ let credits;
259
+ let status = "ok";
260
+ let message;
261
+ if (/account (?:disabled|banned|suspended)|suspended|banned/i.test(text)) {
262
+ status = "banned";
263
+ message = "账号已封禁或暂停使用 (Account banned / suspended)";
264
+ } else if (/RESOURCE_EXHAUSTED|quota reached|rate limit exceeded|429/i.test(text)) {
265
+ status = "exhausted";
266
+ message = "额度已用尽 (Quota / Rate limit reached)";
267
+ } else if (/unauthorized|authentication failed|invalid api key/i.test(text)) {
268
+ status = "unauthorized";
269
+ message = "认证失效 (Unauthorized / Invalid credentials)";
270
+ }
271
+ for (const rawLine of lines) {
272
+ const line = rawLine.replace(/\*\*/g, "").trim();
273
+ if (!line)
274
+ continue;
275
+ const accMatch = line.match(/^Account\s*[::]\s*([^()]+?)(?:\s*\(([^)]+)\))?$/i);
276
+ if (accMatch) {
277
+ account = {
278
+ plan: accMatch[1].trim(),
279
+ email: accMatch[2]?.trim()
280
+ };
281
+ continue;
282
+ }
283
+ const credMatch = line.match(/(?:\b|^)(?:[\w\s-]*?credits?)\s*[::]\s*(unlimited|[\d.]+)/i);
284
+ if (credMatch) {
285
+ const val = credMatch[1].trim();
286
+ credits = val.toLowerCase() === "unlimited" ? { unlimited: true, balance: "unlimited" } : { balance: Number(val) || val, unlimited: false };
287
+ continue;
288
+ }
289
+ 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);
290
+ if (winMatch) {
291
+ const label = winMatch[1].trim();
292
+ const pct = parseFloat(winMatch[2]);
293
+ const resetsAt = (winMatch[3] || winMatch[4] || "").trim() || undefined;
294
+ let windowDurationMins;
295
+ const lower = label.toLowerCase();
296
+ if (/5h|5-hour/i.test(lower))
297
+ windowDurationMins = 300;
298
+ else if (/week/i.test(lower))
299
+ windowDurationMins = 10080;
300
+ else if (/month/i.test(lower))
301
+ windowDurationMins = 43200;
302
+ else if (/day|24h/i.test(lower))
303
+ windowDurationMins = 1440;
304
+ else if (/(\d+)\s*h/i.test(lower)) {
305
+ const m = lower.match(/(\d+)\s*h/);
306
+ if (m)
307
+ windowDurationMins = parseInt(m[1], 10) * 60;
308
+ }
309
+ windows.push({
310
+ label,
311
+ percentLeft: pct,
312
+ usedPercent: Math.max(0, 100 - pct),
313
+ resetsAt,
314
+ windowDurationMins
315
+ });
316
+ continue;
317
+ }
318
+ const fastMatch = line.match(/(?:fast requests?|requests?)\s*[::]\s*(\d+)\s*\/\s*(\d+)/i);
319
+ if (fastMatch) {
320
+ const used = parseInt(fastMatch[1], 10);
321
+ const total = parseInt(fastMatch[2], 10);
322
+ const left = Math.max(0, total - used);
323
+ const pct = total > 0 ? Math.round(left / total * 100) : 0;
324
+ windows.push({
325
+ label: "Fast requests",
326
+ percentLeft: pct,
327
+ usedPercent: total > 0 ? Math.round(used / total * 100) : 0,
328
+ used,
329
+ total
330
+ });
331
+ continue;
332
+ }
333
+ }
334
+ if (!windows.length && !credits && !account && status === "ok") {
335
+ return null;
336
+ }
337
+ const primary = windows.find((w) => /5h|5-hour|hour|primary|fast/i.test(w.label)) || windows[0];
338
+ const secondary = windows.find((w) => w !== primary && /week|month|secondary/i.test(w.label)) || windows.find((w) => w !== primary);
339
+ const extraWindows = windows.filter((w) => w !== primary && w !== secondary);
340
+ if (primary && primary.percentLeft <= 10 && status === "ok") {
341
+ status = "warning";
342
+ }
343
+ return {
344
+ runtimeId,
345
+ account,
346
+ primaryWindow: primary,
347
+ secondaryWindow: secondary,
348
+ extraWindows: extraWindows.length ? extraWindows : undefined,
349
+ credits,
350
+ status,
351
+ message,
352
+ rawText: text,
353
+ updatedAt: Date.now()
354
+ };
355
+ }
356
+
357
+ class QuotaCache {
358
+ bySession = new Map;
359
+ byRuntime = new Map;
360
+ observe(params, defaultRuntimeId = "unknown") {
361
+ if (!params || typeof params !== "object")
362
+ return null;
363
+ const p = params;
364
+ const sessionId = typeof p.sessionId === "string" ? p.sessionId : undefined;
365
+ let textToParse = "";
366
+ if (p.update?.content && p.update.content.type === "text" && typeof p.update.content.text === "string") {
367
+ textToParse = p.update.content.text;
368
+ } else if (p.update?.message?.content && Array.isArray(p.update.message.content)) {
369
+ textToParse = p.update.message.content.filter((c) => c && c.type === "text" && typeof c.text === "string").map((c) => c.text).join(`
370
+ `);
371
+ }
372
+ if (!textToParse)
373
+ return null;
374
+ if (!/(?:limit|credits?|Account:|5h|resets|banned|suspended|quota)/i.test(textToParse)) {
375
+ return null;
376
+ }
377
+ const quota = parseRateLimitsFromStatusText(textToParse, defaultRuntimeId);
378
+ if (quota) {
379
+ if (sessionId)
380
+ this.bySession.set(sessionId, quota);
381
+ this.byRuntime.set(defaultRuntimeId, quota);
382
+ return quota;
383
+ }
384
+ return null;
385
+ }
386
+ set(quota, sessionId) {
387
+ if (sessionId)
388
+ this.bySession.set(sessionId, quota);
389
+ this.byRuntime.set(quota.runtimeId, quota);
390
+ }
391
+ get(sessionId, runtimeId) {
392
+ if (sessionId && this.bySession.has(sessionId)) {
393
+ return this.bySession.get(sessionId);
394
+ }
395
+ if (runtimeId && this.byRuntime.has(runtimeId)) {
396
+ return this.byRuntime.get(runtimeId);
397
+ }
398
+ return;
399
+ }
400
+ clear() {
401
+ this.bySession.clear();
402
+ this.byRuntime.clear();
403
+ }
404
+ }
405
+
241
406
  // src/client/acp-client.ts
242
407
  import {
243
408
  methods as methods2
244
409
  } from "@agentclientprotocol/sdk";
245
410
 
246
- // src/runtimes/codex/index.ts
247
- import { mkdir as mkdir2, writeFile as writeFile2 } from "node:fs/promises";
248
- import { join as join4 } from "node:path";
249
-
250
- // src/runtimes/codex/codex-provider-home.ts
251
- var INKDOWN_PROVIDER_ID = "inkdown-custom";
252
- var INKDOWN_PROVIDER_API_KEY_ENV = "INKDOWN_PROVIDER_API_KEY";
253
- function tomlEscape(value) {
254
- return value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
255
- }
256
- function buildCustomProviderConfigToml(config) {
257
- const name = config.name?.trim() || "自定义 API";
258
- const wireApi = config.wireApi === "responses" ? "responses" : "chat";
259
- return [
260
- `model_provider = "${INKDOWN_PROVIDER_ID}"`,
261
- `model = "${tomlEscape(config.model.trim())}"`,
262
- "",
263
- `[model_providers.${INKDOWN_PROVIDER_ID}]`,
264
- `name = "${tomlEscape(name)}"`,
265
- `base_url = "${tomlEscape(config.baseUrl.trim())}"`,
266
- `env_key = "${INKDOWN_PROVIDER_API_KEY_ENV}"`,
267
- `wire_api = "${wireApi}"`,
268
- ""
269
- ].join(`
270
- `);
271
- }
272
- function buildCustomProviderSpawnEnv(config, apiKey, codexHome) {
273
- return {
274
- CODEX_HOME: codexHome,
275
- [INKDOWN_PROVIDER_API_KEY_ENV]: apiKey
276
- };
277
- }
411
+ // src/runtimes/codex/quota.ts
412
+ import { existsSync as existsSync2, readFileSync } from "node:fs";
413
+ import { join as join2 } from "node:path";
278
414
 
279
415
  // src/runtimes/codex/codex-auth-preflight.ts
280
416
  import { existsSync } from "node:fs";
@@ -312,14 +448,114 @@ function probeCodexAuth() {
312
448
  };
313
449
  }
314
450
 
451
+ // src/runtimes/codex/quota.ts
452
+ function decodeJwtPayload(token) {
453
+ try {
454
+ const parts = token.split(".");
455
+ if (parts.length < 2)
456
+ return null;
457
+ const json = Buffer.from(parts[1], "base64").toString("utf8");
458
+ return JSON.parse(json);
459
+ } catch {
460
+ return null;
461
+ }
462
+ }
463
+ async function probeCodexQuota(options) {
464
+ const codexHome = resolveCodexHome();
465
+ const authPath = join2(codexHome, "auth.json");
466
+ let accountEmail;
467
+ let accountPlan = "Codex Free / Local";
468
+ let isLoggedIn = false;
469
+ if (existsSync2(authPath)) {
470
+ try {
471
+ const authData = JSON.parse(readFileSync(authPath, "utf8"));
472
+ if (authData.OPENAI_API_KEY) {
473
+ isLoggedIn = true;
474
+ accountPlan = "OpenAI API Key";
475
+ }
476
+ if (authData.tokens?.id_token) {
477
+ isLoggedIn = true;
478
+ const payload = decodeJwtPayload(authData.tokens.id_token);
479
+ if (payload) {
480
+ if (typeof payload.email === "string")
481
+ accountEmail = payload.email;
482
+ const authObj = payload["https://api.openai.com/auth"];
483
+ if (authObj && typeof authObj.chatgpt_plan_type === "string") {
484
+ accountPlan = `ChatGPT ${authObj.chatgpt_plan_type}`;
485
+ }
486
+ }
487
+ } else if (authData.tokens?.access_token) {
488
+ isLoggedIn = true;
489
+ }
490
+ } catch {}
491
+ }
492
+ if (process.env.CODEX_API_KEY || process.env.OPENAI_API_KEY) {
493
+ isLoggedIn = true;
494
+ accountPlan = "API Key (Env)";
495
+ }
496
+ if (!isLoggedIn) {
497
+ return {
498
+ runtimeId: "codex-acp",
499
+ provider: "OpenAI / Codex",
500
+ status: "unauthorized",
501
+ message: "未登录 Codex (Not logged in)",
502
+ updatedAt: Date.now()
503
+ };
504
+ }
505
+ return {
506
+ runtimeId: "codex-acp",
507
+ provider: "OpenAI / Codex",
508
+ account: {
509
+ email: accountEmail,
510
+ plan: accountPlan,
511
+ type: "chatgpt"
512
+ },
513
+ status: "ok",
514
+ updatedAt: Date.now()
515
+ };
516
+ }
517
+
518
+ // src/runtimes/codex/index.ts
519
+ import { mkdir as mkdir2, writeFile as writeFile2 } from "node:fs/promises";
520
+ import { join as join5 } from "node:path";
521
+
522
+ // src/runtimes/codex/codex-provider-home.ts
523
+ var INKDOWN_PROVIDER_ID = "inkdown-custom";
524
+ var INKDOWN_PROVIDER_API_KEY_ENV = "INKDOWN_PROVIDER_API_KEY";
525
+ function tomlEscape(value) {
526
+ return value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
527
+ }
528
+ function buildCustomProviderConfigToml(config) {
529
+ const name = config.name?.trim() || "自定义 API";
530
+ const wireApi = config.wireApi === "responses" ? "responses" : "chat";
531
+ return [
532
+ `model_provider = "${INKDOWN_PROVIDER_ID}"`,
533
+ `model = "${tomlEscape(config.model.trim())}"`,
534
+ "",
535
+ `[model_providers.${INKDOWN_PROVIDER_ID}]`,
536
+ `name = "${tomlEscape(name)}"`,
537
+ `base_url = "${tomlEscape(config.baseUrl.trim())}"`,
538
+ `env_key = "${INKDOWN_PROVIDER_API_KEY_ENV}"`,
539
+ `wire_api = "${wireApi}"`,
540
+ ""
541
+ ].join(`
542
+ `);
543
+ }
544
+ function buildCustomProviderSpawnEnv(config, apiKey, codexHome) {
545
+ return {
546
+ CODEX_HOME: codexHome,
547
+ [INKDOWN_PROVIDER_API_KEY_ENV]: apiKey
548
+ };
549
+ }
550
+
315
551
  // src/runtimes/codex/codex-provider.ts
316
552
  import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
317
- import { existsSync as existsSync2 } from "node:fs";
318
- import { join as join3 } from "node:path";
553
+ import { existsSync as existsSync3 } from "node:fs";
554
+ import { join as join4 } from "node:path";
319
555
 
320
556
  // src/client/acp-paths.ts
321
557
  import { homedir as homedir2 } from "node:os";
322
- import { join as join2 } from "node:path";
558
+ import { join as join3 } from "node:path";
323
559
  function getDefaultAgentDataDir() {
324
560
  if (process.env.INKDOWN_DATA_DIR) {
325
561
  return process.env.INKDOWN_DATA_DIR;
@@ -328,20 +564,20 @@ function getDefaultAgentDataDir() {
328
564
  return process.env.ACP_DATA_DIR;
329
565
  }
330
566
  if (process.platform === "win32") {
331
- return process.env.LOCALAPPDATA || process.env.APPDATA || join2(homedir2(), "AppData", "Local", "inkdown");
567
+ return process.env.LOCALAPPDATA || process.env.APPDATA || join3(homedir2(), "AppData", "Local", "inkdown");
332
568
  }
333
569
  if (process.platform === "darwin") {
334
- return join2(homedir2(), "Library", "Application Support", "inkdown");
570
+ return join3(homedir2(), "Library", "Application Support", "inkdown");
335
571
  }
336
- return process.env.XDG_DATA_HOME || join2(homedir2(), ".local", "share", "inkdown");
572
+ return process.env.XDG_DATA_HOME || join3(homedir2(), ".local", "share", "inkdown");
337
573
  }
338
574
 
339
575
  // src/runtimes/codex/codex-provider.ts
340
576
  function providerFilePath(dir) {
341
- return join3(dir, "agent", "provider.json");
577
+ return join4(dir, "agent", "provider.json");
342
578
  }
343
579
  function providerHomePath(dir) {
344
- return join3(dir, "agent", "codex-home");
580
+ return join4(dir, "agent", "codex-home");
345
581
  }
346
582
  function toStatus(stored) {
347
583
  if (!stored)
@@ -367,7 +603,7 @@ function validate(payload) {
367
603
  }
368
604
  async function readStoredAcpProvider(dir = getDefaultAgentDataDir()) {
369
605
  const file = providerFilePath(dir);
370
- if (!existsSync2(file))
606
+ if (!existsSync3(file))
371
607
  return null;
372
608
  try {
373
609
  const raw = JSON.parse(await readFile(file, "utf8"));
@@ -396,7 +632,7 @@ async function saveAcpProvider(payload, dir = getDefaultAgentDataDir()) {
396
632
  const apiKey = payload.apiKey.trim() || (await readStoredAcpProvider(dir))?.apiKey || "";
397
633
  if (!apiKey)
398
634
  return err({ code: "INVALID_ARGUMENT", message: "API Key 不能为空" });
399
- await mkdir(join3(dir, "agent"), { recursive: true });
635
+ await mkdir(join4(dir, "agent"), { recursive: true });
400
636
  const stored = {
401
637
  name: payload.name?.trim() || undefined,
402
638
  baseUrl: payload.baseUrl.trim(),
@@ -419,7 +655,7 @@ function getAcpProviderCodexHome(dir = getDefaultAgentDataDir()) {
419
655
  async function provisionCustomProviderCodexHome(provider, codexHome) {
420
656
  try {
421
657
  await mkdir2(codexHome, { recursive: true });
422
- await writeFile2(join4(codexHome, "config.toml"), buildCustomProviderConfigToml(provider), "utf8");
658
+ await writeFile2(join5(codexHome, "config.toml"), buildCustomProviderConfigToml(provider), "utf8");
423
659
  return true;
424
660
  } catch (error) {
425
661
  console.error("[acp] 自定义供应商 config.toml 写入失败,回落本机登录", error);
@@ -428,6 +664,7 @@ async function provisionCustomProviderCodexHome(provider, codexHome) {
428
664
  }
429
665
  var codexAdapter = {
430
666
  id: "codex-acp",
667
+ probeQuota: async (options) => probeCodexQuota(options),
431
668
  probeAuth: () => {
432
669
  return probeCodexAuth();
433
670
  },
@@ -444,20 +681,86 @@ var codexAdapter = {
444
681
  }
445
682
  };
446
683
 
447
- // src/runtimes/claude/index.ts
448
- import { existsSync as existsSync3 } from "node:fs";
684
+ // src/runtimes/claude/quota.ts
685
+ import { existsSync as existsSync4, readFileSync as readFileSync2 } from "node:fs";
449
686
  import { homedir as homedir3 } from "node:os";
450
- import { join as join5 } from "node:path";
687
+ import { join as join6 } from "node:path";
688
+ async function probeClaudeQuota(options) {
689
+ const claudeHome = resolveClaudeHome();
690
+ const claudeJsonPath = join6(homedir3(), ".claude.json");
691
+ const credsPath = join6(claudeHome, ".credentials.json");
692
+ let isLoggedIn = false;
693
+ let isBanned = false;
694
+ let accountEmail;
695
+ let plan = "Claude Free / Default";
696
+ if (existsSync4(claudeJsonPath)) {
697
+ try {
698
+ const data = JSON.parse(readFileSync2(claudeJsonPath, "utf8"));
699
+ if (data.oauthAccount) {
700
+ isLoggedIn = true;
701
+ accountEmail = data.oauthAccount.emailAddress;
702
+ plan = data.oauthAccount.subscriptionTier || "Claude Pro";
703
+ }
704
+ if (data.isBanned || data.accountSuspended || data.status === "banned") {
705
+ isBanned = true;
706
+ }
707
+ } catch {}
708
+ }
709
+ if (existsSync4(credsPath)) {
710
+ try {
711
+ const creds = JSON.parse(readFileSync2(credsPath, "utf8"));
712
+ if (creds.accessToken || creds.sessionKey)
713
+ isLoggedIn = true;
714
+ } catch {}
715
+ }
716
+ if (process.env.ANTHROPIC_API_KEY || process.env.CLAUDE_CODE_OAUTH_TOKEN) {
717
+ isLoggedIn = true;
718
+ plan = "API Key (Env)";
719
+ }
720
+ if (isBanned) {
721
+ return {
722
+ runtimeId: "claude",
723
+ provider: "Anthropic / Claude Code",
724
+ status: "banned",
725
+ message: "账号已被封禁或暂停使用 (Account suspended / banned)",
726
+ updatedAt: Date.now()
727
+ };
728
+ }
729
+ if (!isLoggedIn) {
730
+ return {
731
+ runtimeId: "claude",
732
+ provider: "Anthropic / Claude Code",
733
+ status: "unauthorized",
734
+ message: "未登录 Claude Code 或凭据无效 (Unauthorized)",
735
+ updatedAt: Date.now()
736
+ };
737
+ }
738
+ return {
739
+ runtimeId: "claude",
740
+ provider: "Anthropic / Claude Code",
741
+ account: {
742
+ email: accountEmail,
743
+ plan
744
+ },
745
+ status: "ok",
746
+ updatedAt: Date.now()
747
+ };
748
+ }
749
+
750
+ // src/runtimes/claude/index.ts
751
+ import { existsSync as existsSync5 } from "node:fs";
752
+ import { homedir as homedir4 } from "node:os";
753
+ import { join as join7 } from "node:path";
451
754
  function resolveClaudeHome() {
452
755
  const fromEnv = process.env.CLAUDE_CONFIG_DIR?.trim();
453
756
  if (fromEnv)
454
757
  return fromEnv;
455
- return join5(homedir3(), ".claude");
758
+ return join7(homedir4(), ".claude");
456
759
  }
457
760
  function probeClaudeAuth() {
458
761
  const claudeHome = resolveClaudeHome();
459
- const hasCodexHome = existsSync3(claudeHome);
460
- const hasAuthFile = existsSync3(join5(homedir3(), ".claude.json")) || existsSync3(join5(claudeHome, ".credentials.json"));
762
+ const hasCodexHome = existsSync5(claudeHome);
763
+ const hasAuthFile = existsSync5(join7(homedir4(), ".claude.json")) || existsSync5(join7(claudeHome, ".credentials.json"));
461
764
  const hasApiKeyEnv = Boolean(process.env.ANTHROPIC_API_KEY?.trim() || process.env.CLAUDE_CODE_OAUTH_TOKEN?.trim());
462
765
  return {
463
766
  codexHome: claudeHome,
@@ -470,21 +773,22 @@ function probeClaudeAuth() {
470
773
  var claudeAdapter = {
471
774
  id: "claude",
472
775
  probeAuth: () => probeClaudeAuth(),
776
+ probeQuota: async (options) => probeClaudeQuota(options),
473
777
  orderAuthMethods: (methods) => methods,
474
778
  canSkipInteractiveAuth: () => false
475
779
  };
476
780
 
477
781
  // src/runtimes/gemini/index.ts
478
- import { existsSync as existsSync4 } from "node:fs";
479
- import { homedir as homedir4 } from "node:os";
480
- import { join as join6 } from "node:path";
782
+ import { existsSync as existsSync6 } from "node:fs";
783
+ import { homedir as homedir5 } from "node:os";
784
+ import { join as join8 } from "node:path";
481
785
  function resolveGeminiHome() {
482
- return join6(homedir4(), ".gemini");
786
+ return join8(homedir5(), ".gemini");
483
787
  }
484
788
  function probeGeminiAuth() {
485
789
  const geminiHome = resolveGeminiHome();
486
- const hasCodexHome = existsSync4(geminiHome);
487
- const hasAuthFile = existsSync4(join6(geminiHome, "oauth_creds.json")) || Boolean(process.env.GOOGLE_APPLICATION_CREDENTIALS?.trim());
790
+ const hasCodexHome = existsSync6(geminiHome);
791
+ const hasAuthFile = existsSync6(join8(geminiHome, "oauth_creds.json")) || Boolean(process.env.GOOGLE_APPLICATION_CREDENTIALS?.trim());
488
792
  const hasApiKeyEnv = Boolean(process.env.GEMINI_API_KEY?.trim() || process.env.GOOGLE_API_KEY?.trim());
489
793
  return {
490
794
  codexHome: geminiHome,
@@ -502,18 +806,18 @@ var geminiAdapter = {
502
806
  };
503
807
 
504
808
  // src/runtimes/copilot/index.ts
505
- import { existsSync as existsSync5, readFileSync } from "node:fs";
506
- import { homedir as homedir5 } from "node:os";
507
- import { join as join7 } from "node:path";
809
+ import { existsSync as existsSync7, readFileSync as readFileSync3 } from "node:fs";
810
+ import { homedir as homedir6 } from "node:os";
811
+ import { join as join9 } from "node:path";
508
812
  function resolveCopilotHome() {
509
813
  const fromEnv = process.env.COPILOT_HOME?.trim();
510
814
  if (fromEnv)
511
815
  return fromEnv;
512
- return join7(homedir5(), ".copilot");
816
+ return join9(homedir6(), ".copilot");
513
817
  }
514
818
  function hasCopilotLogin(home) {
515
819
  try {
516
- const raw = readFileSync(join7(home, "config.json"), "utf8");
820
+ const raw = readFileSync3(join9(home, "config.json"), "utf8");
517
821
  const parsed = JSON.parse(raw);
518
822
  return Array.isArray(parsed.loggedInUsers) && parsed.loggedInUsers.length > 0;
519
823
  } catch {
@@ -522,7 +826,7 @@ function hasCopilotLogin(home) {
522
826
  }
523
827
  function probeCopilotAuth() {
524
828
  const copilotHome = resolveCopilotHome();
525
- const hasCodexHome = existsSync5(copilotHome);
829
+ const hasCodexHome = existsSync7(copilotHome);
526
830
  const hasAuthFile = hasCopilotLogin(copilotHome);
527
831
  const hasApiKeyEnv = Boolean(process.env.COPILOT_GITHUB_TOKEN?.trim() || process.env.GH_TOKEN?.trim() || process.env.GITHUB_TOKEN?.trim());
528
832
  return {
@@ -540,17 +844,68 @@ var copilotAdapter = {
540
844
  canSkipInteractiveAuth: () => false
541
845
  };
542
846
 
847
+ // src/runtimes/opencode/quota.ts
848
+ import { existsSync as existsSync8, readFileSync as readFileSync4 } from "node:fs";
849
+ function resolveOpencodeAuthPath() {
850
+ const candidates = resolveOpencodeAuthCandidates();
851
+ for (const c of candidates) {
852
+ if (existsSync8(c))
853
+ return c;
854
+ }
855
+ return candidates[0] ?? null;
856
+ }
857
+ async function probeOpencodeQuota(runtimeId = "opencode") {
858
+ const authPath = resolveOpencodeAuthPath();
859
+ let isLoggedIn = false;
860
+ let accountEmail;
861
+ let plan = "OpenCode Community";
862
+ if (authPath && existsSync8(authPath)) {
863
+ try {
864
+ const data = JSON.parse(readFileSync4(authPath, "utf8"));
865
+ if (data && typeof data === "object") {
866
+ const keys = Object.keys(data);
867
+ if (keys.length > 0) {
868
+ isLoggedIn = true;
869
+ if (data.email)
870
+ accountEmail = String(data.email);
871
+ if (data.plan)
872
+ plan = String(data.plan);
873
+ }
874
+ }
875
+ } catch {}
876
+ }
877
+ if (!isLoggedIn) {
878
+ return {
879
+ runtimeId,
880
+ provider: "OpenCode",
881
+ status: "unauthorized",
882
+ message: "未检测到 OpenCode 登录凭证 (auth.json / SQLite)",
883
+ updatedAt: Date.now()
884
+ };
885
+ }
886
+ return {
887
+ runtimeId,
888
+ provider: "OpenCode",
889
+ account: {
890
+ email: accountEmail,
891
+ plan
892
+ },
893
+ status: "ok",
894
+ updatedAt: Date.now()
895
+ };
896
+ }
897
+
543
898
  // src/runtimes/opencode/index.ts
544
- import { existsSync as existsSync6, readFileSync as readFileSync2 } from "node:fs";
545
- import { homedir as homedir6 } from "node:os";
546
- import { dirname, join as join8 } from "node:path";
899
+ import { existsSync as existsSync9, readFileSync as readFileSync5 } from "node:fs";
900
+ import { homedir as homedir7 } from "node:os";
901
+ import { dirname, join as join10 } from "node:path";
547
902
  function pickEnv(env, key) {
548
903
  return env?.[key]?.trim() ?? "";
549
904
  }
550
905
  function resolveOpencodeAuthCandidates(overrides) {
551
906
  const platform = overrides?.platform ?? process.platform;
552
907
  const env = overrides?.env ?? process.env;
553
- const home = overrides?.home ?? homedir6();
908
+ const home = overrides?.home ?? homedir7();
554
909
  const seen = new Set;
555
910
  const out = [];
556
911
  const push = (p) => {
@@ -561,27 +916,27 @@ function resolveOpencodeAuthCandidates(overrides) {
561
916
  };
562
917
  const xdg = pickEnv(env, "XDG_DATA_HOME");
563
918
  if (xdg)
564
- push(join8(xdg, "opencode", "auth.json"));
919
+ push(join10(xdg, "opencode", "auth.json"));
565
920
  if (platform === "win32") {
566
- const localAppData = pickEnv(env, "LOCALAPPDATA") || (pickEnv(env, "USERPROFILE") ? join8(pickEnv(env, "USERPROFILE"), "AppData", "Local") : "");
921
+ const localAppData = pickEnv(env, "LOCALAPPDATA") || (pickEnv(env, "USERPROFILE") ? join10(pickEnv(env, "USERPROFILE"), "AppData", "Local") : "");
567
922
  if (localAppData)
568
- push(join8(localAppData, "opencode", "auth.json"));
923
+ push(join10(localAppData, "opencode", "auth.json"));
569
924
  const userProfile = pickEnv(env, "USERPROFILE") || home;
570
925
  if (userProfile)
571
- push(join8(userProfile, ".local", "share", "opencode", "auth.json"));
926
+ push(join10(userProfile, ".local", "share", "opencode", "auth.json"));
572
927
  } else if (home) {
573
- push(join8(home, ".local", "share", "opencode", "auth.json"));
928
+ push(join10(home, ".local", "share", "opencode", "auth.json"));
574
929
  }
575
930
  return out;
576
931
  }
577
932
  function resolveOpencodeAuthFile() {
578
- return resolveOpencodeAuthCandidates()[0] ?? join8(homedir6(), ".local", "share", "opencode", "auth.json");
933
+ return resolveOpencodeAuthCandidates()[0] ?? join10(homedir7(), ".local", "share", "opencode", "auth.json");
579
934
  }
580
935
  function isValidOpencodeAuthFile(authFile) {
581
936
  try {
582
- if (!authFile || !existsSync6(authFile))
937
+ if (!authFile || !existsSync9(authFile))
583
938
  return false;
584
- const raw = readFileSync2(authFile, "utf8").trim();
939
+ const raw = readFileSync5(authFile, "utf8").trim();
585
940
  if (!raw)
586
941
  return false;
587
942
  const parsed = JSON.parse(raw);
@@ -599,7 +954,7 @@ function probeOpencodeAuth(overrides) {
599
954
  for (const candidate of candidates) {
600
955
  let exists = false;
601
956
  try {
602
- exists = existsSync6(candidate);
957
+ exists = existsSync9(candidate);
603
958
  } catch {
604
959
  exists = false;
605
960
  }
@@ -615,7 +970,7 @@ function probeOpencodeAuth(overrides) {
615
970
  const authDir = dirname(authFile);
616
971
  let hasCodexHome = false;
617
972
  try {
618
- hasCodexHome = existsSync6(authDir);
973
+ hasCodexHome = existsSync9(authDir);
619
974
  } catch {
620
975
  hasCodexHome = false;
621
976
  }
@@ -631,22 +986,55 @@ function probeOpencodeAuth(overrides) {
631
986
  var opencodeAdapter = {
632
987
  id: "opencode",
633
988
  probeAuth: () => probeOpencodeAuth(),
989
+ probeQuota: async () => probeOpencodeQuota(),
990
+ orderAuthMethods: (methods) => methods,
991
+ canSkipInteractiveAuth: () => false,
992
+ tryDirectSessionFirst: true
993
+ };
994
+
995
+ // src/runtimes/opencode-v2/index.ts
996
+ var opencodeV2Adapter = {
997
+ id: "opencode-v2",
998
+ probeAuth: () => probeOpencodeAuth(),
634
999
  orderAuthMethods: (methods) => methods,
635
1000
  canSkipInteractiveAuth: () => false,
636
1001
  tryDirectSessionFirst: true
637
1002
  };
638
1003
 
1004
+ // src/runtimes/cursor/quota.ts
1005
+ async function probeCursorQuota() {
1006
+ const auth = probeCursorAuth();
1007
+ if (!auth.looksLoggedIn) {
1008
+ return {
1009
+ runtimeId: "cursor-cli",
1010
+ provider: "Cursor",
1011
+ status: "unauthorized",
1012
+ message: "未检测到 Cursor CLI 登录凭证",
1013
+ updatedAt: Date.now()
1014
+ };
1015
+ }
1016
+ return {
1017
+ runtimeId: "cursor-cli",
1018
+ provider: "Cursor",
1019
+ account: {
1020
+ plan: "Cursor Pro / Fast Requests"
1021
+ },
1022
+ status: "ok",
1023
+ updatedAt: Date.now()
1024
+ };
1025
+ }
1026
+
639
1027
  // src/runtimes/cursor/index.ts
640
1028
  import { spawnSync } from "node:child_process";
641
- import { existsSync as existsSync7, readFileSync as readFileSync3 } from "node:fs";
642
- import { homedir as homedir7 } from "node:os";
643
- import { delimiter, dirname as dirname2, join as join9 } from "node:path";
1029
+ import { existsSync as existsSync10, readFileSync as readFileSync6 } from "node:fs";
1030
+ import { homedir as homedir8 } from "node:os";
1031
+ import { delimiter, dirname as dirname2, join as join11 } from "node:path";
644
1032
  function cursorLocalAppData(env) {
645
1033
  const local = env.LOCALAPPDATA?.trim();
646
1034
  if (local)
647
1035
  return local;
648
1036
  const profile = env.USERPROFILE?.trim();
649
- return profile ? join9(profile, "AppData", "Local") : "";
1037
+ return profile ? join11(profile, "AppData", "Local") : "";
650
1038
  }
651
1039
  function isOnPath(command, env, platform) {
652
1040
  const pathValue = env.PATH ?? env.Path ?? "";
@@ -658,7 +1046,7 @@ function isOnPath(command, env, platform) {
658
1046
  if (!trimmed)
659
1047
  continue;
660
1048
  try {
661
- if (existsSync7(join9(trimmed, command)))
1049
+ if (existsSync10(join11(trimmed, command)))
662
1050
  return true;
663
1051
  } catch {}
664
1052
  }
@@ -667,24 +1055,24 @@ function isOnPath(command, env, platform) {
667
1055
  function resolveDirectCursorCommand(platform, env, home) {
668
1056
  if (platform === "win32") {
669
1057
  const localAppData = cursorLocalAppData(env);
670
- return localAppData ? join9(localAppData, "cursor-agent", "agent.cmd") : "";
1058
+ return localAppData ? join11(localAppData, "cursor-agent", "agent.cmd") : "";
671
1059
  }
672
- return home ? join9(home, ".local", "bin", "agent") : "";
1060
+ return home ? join11(home, ".local", "bin", "agent") : "";
673
1061
  }
674
1062
  function resolveCursorCommand(overrides) {
675
1063
  const args = ["acp"];
676
1064
  const platform = overrides?.platform ?? process.platform;
677
1065
  const env = overrides?.env ?? process.env;
678
- const home = overrides?.home ?? homedir7();
1066
+ const home = overrides?.home ?? homedir8();
679
1067
  if (platform === "win32") {
680
1068
  const directCmd = resolveDirectCursorCommand(platform, env, home);
681
- if (directCmd && existsSync7(directCmd)) {
1069
+ if (directCmd && existsSync10(directCmd)) {
682
1070
  return { command: directCmd, args };
683
1071
  }
684
1072
  return { command: "agent.cmd", args };
685
1073
  }
686
1074
  const directBin = resolveDirectCursorCommand(platform, env, home);
687
- if (directBin && existsSync7(directBin)) {
1075
+ if (directBin && existsSync10(directBin)) {
688
1076
  return { command: directBin, args };
689
1077
  }
690
1078
  return { command: "agent", args };
@@ -693,11 +1081,11 @@ function resolveCursorSpawnCommand(overrides) {
693
1081
  const args = ["acp"];
694
1082
  const platform = overrides?.platform ?? process.platform;
695
1083
  const env = overrides?.env ?? process.env;
696
- const home = overrides?.home ?? homedir7();
1084
+ const home = overrides?.home ?? homedir8();
697
1085
  const binary = platform === "win32" ? "agent.cmd" : "agent";
698
1086
  const direct = resolveDirectCursorCommand(platform, env, home);
699
1087
  try {
700
- if (direct && existsSync7(direct))
1088
+ if (direct && existsSync10(direct))
701
1089
  return { command: direct, args };
702
1090
  } catch {}
703
1091
  if (isOnPath(binary, env, platform))
@@ -719,12 +1107,12 @@ function cursorRoamingAppData(env, home) {
719
1107
  if (roaming)
720
1108
  return roaming;
721
1109
  const profile = pickEnv2(env, "USERPROFILE") || home;
722
- return profile ? join9(profile, "AppData", "Roaming") : "";
1110
+ return profile ? join11(profile, "AppData", "Roaming") : "";
723
1111
  }
724
1112
  function resolveCursorAuthCandidates(overrides) {
725
1113
  const platform = overrides?.platform ?? process.platform;
726
1114
  const env = overrides?.env ?? process.env;
727
- const home = overrides?.home ?? homedir7();
1115
+ const home = overrides?.home ?? homedir8();
728
1116
  const seen = new Set;
729
1117
  const out = [];
730
1118
  const push = (p) => {
@@ -735,16 +1123,16 @@ function resolveCursorAuthCandidates(overrides) {
735
1123
  };
736
1124
  const xdg = pickEnv2(env, "XDG_CONFIG_HOME");
737
1125
  if (xdg)
738
- push(join9(xdg, "cursor", "auth.json"));
1126
+ push(join11(xdg, "cursor", "auth.json"));
739
1127
  if (platform === "win32") {
740
1128
  const profile = pickEnv2(env, "USERPROFILE") || home;
741
1129
  if (profile)
742
- push(join9(profile, ".config", "cursor", "auth.json"));
1130
+ push(join11(profile, ".config", "cursor", "auth.json"));
743
1131
  const roaming = cursorRoamingAppData(env, home);
744
1132
  if (roaming)
745
- push(join9(roaming, "Cursor", "User", "globalStorage", "storage.json"));
1133
+ push(join11(roaming, "Cursor", "User", "globalStorage", "storage.json"));
746
1134
  } else if (home) {
747
- push(join9(home, ".config", "cursor", "auth.json"));
1135
+ push(join11(home, ".config", "cursor", "auth.json"));
748
1136
  }
749
1137
  return out;
750
1138
  }
@@ -755,9 +1143,9 @@ function isValidCursorAuthFile(authFile) {
755
1143
  try {
756
1144
  if (!authFile || isStorageHintPath(authFile))
757
1145
  return false;
758
- if (!existsSync7(authFile))
1146
+ if (!existsSync10(authFile))
759
1147
  return false;
760
- const raw = readFileSync3(authFile, "utf8").trim();
1148
+ const raw = readFileSync6(authFile, "utf8").trim();
761
1149
  if (!raw)
762
1150
  return false;
763
1151
  const parsed = JSON.parse(raw);
@@ -775,9 +1163,9 @@ function isHintCursorStorageFile(authFile) {
775
1163
  try {
776
1164
  if (!authFile || !isStorageHintPath(authFile))
777
1165
  return false;
778
- if (!existsSync7(authFile))
1166
+ if (!existsSync10(authFile))
779
1167
  return false;
780
- const raw = readFileSync3(authFile, "utf8").trim();
1168
+ const raw = readFileSync6(authFile, "utf8").trim();
781
1169
  if (!raw)
782
1170
  return false;
783
1171
  const parsed = JSON.parse(raw);
@@ -793,7 +1181,7 @@ function isValidCursorCandidate(authFile) {
793
1181
  }
794
1182
  function probeCursorAuth(overrides) {
795
1183
  const env = overrides?.env ?? process.env;
796
- const home = overrides?.home ?? homedir7();
1184
+ const home = overrides?.home ?? homedir8();
797
1185
  const hasApiKeyEnv = Boolean(env.CURSOR_API_KEY?.trim() || env.CURSOR_AUTH_TOKEN?.trim());
798
1186
  const candidates = resolveCursorAuthCandidates(overrides);
799
1187
  let firstExisting = null;
@@ -801,7 +1189,7 @@ function probeCursorAuth(overrides) {
801
1189
  for (const candidate of candidates) {
802
1190
  let exists = false;
803
1191
  try {
804
- exists = existsSync7(candidate);
1192
+ exists = existsSync10(candidate);
805
1193
  } catch {
806
1194
  exists = false;
807
1195
  }
@@ -813,12 +1201,12 @@ function probeCursorAuth(overrides) {
813
1201
  if (isValidCursorCandidate(candidate))
814
1202
  validFile = candidate;
815
1203
  }
816
- const fallback = home ? join9(home, ".config", "cursor", "auth.json") : "";
1204
+ const fallback = home ? join11(home, ".config", "cursor", "auth.json") : "";
817
1205
  const authFile = validFile ?? firstExisting ?? candidates[0] ?? fallback;
818
1206
  const authDir = authFile ? dirname2(authFile) : "";
819
1207
  let hasCodexHome = false;
820
1208
  try {
821
- hasCodexHome = authDir ? existsSync7(authDir) : false;
1209
+ hasCodexHome = authDir ? existsSync10(authDir) : false;
822
1210
  } catch {
823
1211
  hasCodexHome = false;
824
1212
  }
@@ -833,6 +1221,7 @@ function probeCursorAuth(overrides) {
833
1221
  var cursorAdapter = {
834
1222
  id: "cursor-cli",
835
1223
  probeAuth: () => probeCursorAuth(),
1224
+ probeQuota: async () => probeCursorQuota(),
836
1225
  resolveSpawnCommand: () => resolveCursorSpawnCommand(),
837
1226
  orderAuthMethods: (methods) => methods,
838
1227
  canSkipInteractiveAuth: () => false,
@@ -951,6 +1340,55 @@ var deepseekAdapter = {
951
1340
  canSkipInteractiveAuth: () => false
952
1341
  };
953
1342
 
1343
+ // src/runtimes/agy/quota.ts
1344
+ import { existsSync as existsSync11 } from "node:fs";
1345
+ import { join as join12 } from "node:path";
1346
+ function resolveGeminiHome2() {
1347
+ const home = process.env.USERPROFILE || process.env.HOME || "";
1348
+ return join12(home, ".gemini");
1349
+ }
1350
+ async function probeAgyQuota(options) {
1351
+ const geminiHome = resolveGeminiHome2();
1352
+ const hasAgyDir = existsSync11(join12(geminiHome, "antigravity")) || existsSync11(join12(geminiHome, "antigravity-cli"));
1353
+ const hasApiKey = Boolean(process.env.GEMINI_API_KEY || process.env.GOOGLE_API_KEY);
1354
+ const isAvailable = hasAgyDir || hasApiKey;
1355
+ if (!isAvailable) {
1356
+ return {
1357
+ runtimeId: "agy",
1358
+ provider: "Google Antigravity",
1359
+ status: "unauthorized",
1360
+ message: "wenjianlingu antigravity cli",
1361
+ updatedAt: Date.now()
1362
+ };
1363
+ }
1364
+ return {
1365
+ runtimeId: "agy",
1366
+ provider: "Google Antigravity",
1367
+ account: {
1368
+ plan: "Antigravity / Gemini",
1369
+ type: "gemini"
1370
+ },
1371
+ primaryWindow: {
1372
+ label: "5-Hour limit",
1373
+ percentLeft: 100,
1374
+ usedPercent: 0,
1375
+ windowDurationMins: 300
1376
+ },
1377
+ secondaryWindow: {
1378
+ label: "Weekly limit",
1379
+ percentLeft: 100,
1380
+ usedPercent: 0,
1381
+ windowDurationMins: 10080
1382
+ },
1383
+ credits: {
1384
+ unlimited: true,
1385
+ balance: "unlimited"
1386
+ },
1387
+ status: "ok",
1388
+ updatedAt: Date.now()
1389
+ };
1390
+ }
1391
+
954
1392
  // src/runtimes/agy/index.ts
955
1393
  function probeAgyAuth() {
956
1394
  return {
@@ -964,6 +1402,7 @@ function probeAgyAuth() {
964
1402
  var agyAdapter = {
965
1403
  id: "agy",
966
1404
  probeAuth: () => probeAgyAuth(),
1405
+ probeQuota: (options) => probeAgyQuota(options),
967
1406
  orderAuthMethods: (methods) => methods,
968
1407
  canSkipInteractiveAuth: () => false,
969
1408
  tryDirectSessionFirst: true
@@ -983,6 +1422,8 @@ function getAcpRuntimeAdapter(runtimeId) {
983
1422
  return copilotAdapter;
984
1423
  case opencodeAdapter.id:
985
1424
  return opencodeAdapter;
1425
+ case opencodeV2Adapter.id:
1426
+ return opencodeV2Adapter;
986
1427
  case cursorAdapter.id:
987
1428
  case "cursor":
988
1429
  return cursorAdapter;
@@ -1962,8 +2403,8 @@ class AcpTerminalManager {
1962
2403
 
1963
2404
  // src/client/acp-proxy-service.ts
1964
2405
  import { mkdir as mkdir4, readFile as readFile3, writeFile as writeFile4 } from "node:fs/promises";
1965
- import { existsSync as existsSync8 } from "node:fs";
1966
- import { join as join10 } from "node:path";
2406
+ import { existsSync as existsSync12 } from "node:fs";
2407
+ import { join as join13 } from "node:path";
1967
2408
  var DEFAULT_ACP_PROXY_SETTINGS = {
1968
2409
  enabled: false,
1969
2410
  host: "127.0.0.1",
@@ -1972,7 +2413,7 @@ var DEFAULT_ACP_PROXY_SETTINGS = {
1972
2413
  var PROXY_ENV_KEYS = ["HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY"];
1973
2414
  var LOWERCASE_PROXY_ENV_KEYS = ["http_proxy", "https_proxy", "all_proxy", "no_proxy"];
1974
2415
  function proxyFilePath(dir) {
1975
- return join10(dir, "agent", "proxy.json");
2416
+ return join13(dir, "agent", "proxy.json");
1976
2417
  }
1977
2418
  function validate2(settings) {
1978
2419
  if (!settings.host.trim())
@@ -1984,7 +2425,7 @@ function validate2(settings) {
1984
2425
  }
1985
2426
  async function readAcpProxySettings(dir = getDefaultAgentDataDir()) {
1986
2427
  const file = proxyFilePath(dir);
1987
- if (!existsSync8(file))
2428
+ if (!existsSync12(file))
1988
2429
  return { ...DEFAULT_ACP_PROXY_SETTINGS };
1989
2430
  try {
1990
2431
  const raw = JSON.parse(await readFile3(file, "utf8"));
@@ -2006,7 +2447,7 @@ async function saveAcpProxySettings(payload, dir = getDefaultAgentDataDir()) {
2006
2447
  host: payload.host.trim() || DEFAULT_ACP_PROXY_SETTINGS.host,
2007
2448
  port: payload.port
2008
2449
  };
2009
- await mkdir4(join10(dir, "agent"), { recursive: true });
2450
+ await mkdir4(join13(dir, "agent"), { recursive: true });
2010
2451
  await writeFile4(proxyFilePath(dir), JSON.stringify(stored, null, 2), "utf8");
2011
2452
  return ok(stored);
2012
2453
  }
@@ -2074,6 +2515,12 @@ class AcpSessionHandle {
2074
2515
  async prompt(promptText, options) {
2075
2516
  return this.client.promptSession(this.sessionId, promptText, options);
2076
2517
  }
2518
+ get quota() {
2519
+ return this.client.getCachedQuota(this.sessionId);
2520
+ }
2521
+ async getQuota() {
2522
+ return this.client.getQuota(this.sessionId);
2523
+ }
2077
2524
  get availableCommands() {
2078
2525
  return this.client.getAvailableCommands(this.sessionId);
2079
2526
  }
@@ -2085,6 +2532,7 @@ class AcpSessionHandle {
2085
2532
  class AcpClient {
2086
2533
  status = "disconnected";
2087
2534
  commandsCache = new AvailableCommandsCache;
2535
+ quotaCache = new QuotaCache;
2088
2536
  runtimeInfo;
2089
2537
  adapter;
2090
2538
  workspaceRoot;
@@ -2195,6 +2643,7 @@ class AcpClient {
2195
2643
  },
2196
2644
  onSessionUpdate: (params) => {
2197
2645
  this.commandsCache.observe(params);
2646
+ this.quotaCache.observe(params, this.runtimeInfo.id);
2198
2647
  this.callbacks.onSessionUpdate?.(params);
2199
2648
  }
2200
2649
  };
@@ -2225,6 +2674,23 @@ class AcpClient {
2225
2674
  return err({ code: "ACP_PROTOCOL_ERROR", message });
2226
2675
  }
2227
2676
  }
2677
+ getCachedQuota(sessionId) {
2678
+ return this.quotaCache.get(sessionId, this.runtimeInfo.id);
2679
+ }
2680
+ async getQuota(sessionId) {
2681
+ const cached = this.getCachedQuota(sessionId);
2682
+ if (cached && Date.now() - cached.updatedAt < 30000) {
2683
+ return cached;
2684
+ }
2685
+ if (this.adapter.probeQuota) {
2686
+ const probed = await this.adapter.probeQuota({ sessionId });
2687
+ if (probed) {
2688
+ this.quotaCache.set(probed, sessionId);
2689
+ return probed;
2690
+ }
2691
+ }
2692
+ return cached ?? null;
2693
+ }
2228
2694
  getAvailableCommands(sessionId) {
2229
2695
  return this.commandsCache.get(sessionId);
2230
2696
  }
@@ -3257,6 +3723,8 @@ export {
3257
3723
  INKDOWN_VIRTUAL_DIR,
3258
3724
  INKDOWN_VIRTUAL_RESOURCES,
3259
3725
  LEGACY_ZED_CODEX_ACP_NPM_PACKAGE,
3726
+ OPENCODE_CLI_NPM_PACKAGE,
3727
+ QuotaCache,
3260
3728
  acpReadTextFile,
3261
3729
  acpWriteTextFile,
3262
3730
  agyAdapter,
@@ -3315,6 +3783,7 @@ export {
3315
3783
  mergeTopLevelModelsIntoConfigOptions,
3316
3784
  ok,
3317
3785
  opencodeAdapter,
3786
+ opencodeV2Adapter,
3318
3787
  orderSilentAuthMethodIds,
3319
3788
  parseAcpConfigOptions,
3320
3789
  parseCursorCatalogOutput,
@@ -3322,16 +3791,21 @@ export {
3322
3791
  parseLoadSessionSupported,
3323
3792
  parseMcpHttpSupported,
3324
3793
  parsePromptCapabilities,
3794
+ parseRateLimitsFromStatusText,
3325
3795
  parseResumeSessionSupported,
3326
3796
  pickAllowOptionId,
3327
3797
  probeAgyAuth,
3328
3798
  probeClaudeAuth,
3799
+ probeClaudeQuota,
3329
3800
  probeCodexAuth,
3801
+ probeCodexQuota,
3330
3802
  probeCopilotAuth,
3331
3803
  probeCursorAuth,
3804
+ probeCursorQuota,
3332
3805
  probeDeepseekAuth,
3333
3806
  probeGeminiAuth,
3334
3807
  probeOpencodeAuth,
3808
+ probeOpencodeQuota,
3335
3809
  provisionCustomProviderCodexHome,
3336
3810
  readAcpProxySettings,
3337
3811
  readStoredAcpProvider,
@@ -3348,6 +3822,7 @@ export {
3348
3822
  resolveGeminiHome,
3349
3823
  resolveOpencodeAuthCandidates,
3350
3824
  resolveOpencodeAuthFile,
3825
+ resolveOpencodeAuthPath,
3351
3826
  restoreOrCreateAcpSession,
3352
3827
  runConnectAuthGate,
3353
3828
  saveAcpProvider,