chompyy 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/README.md +11 -0
  2. package/dist/agentlimits.js +77 -0
  3. package/dist/agentusage.js +96 -0
  4. package/dist/appstate.js +63 -3
  5. package/dist/away.js +44 -5
  6. package/dist/blueprint.js +3 -7
  7. package/dist/board.js +1 -0
  8. package/dist/cli.js +263 -5
  9. package/dist/codexquota.js +106 -0
  10. package/dist/codexusage.js +10 -0
  11. package/dist/config.js +2 -0
  12. package/dist/context.js +30 -0
  13. package/dist/costs.js +1 -0
  14. package/dist/demon.js +20 -0
  15. package/dist/label.js +33 -0
  16. package/dist/menu.js +17 -0
  17. package/dist/nightcap.js +60 -0
  18. package/dist/nudge.js +47 -18
  19. package/dist/pacing.js +16 -1
  20. package/dist/questions.js +71 -0
  21. package/dist/recap.js +74 -0
  22. package/dist/receipt.js +48 -0
  23. package/dist/recipe.js +79 -0
  24. package/dist/stamps.js +14 -0
  25. package/dist/triggers.js +5 -0
  26. package/dist/usage.js +21 -1
  27. package/dist/vendor/codeburn/antigravity.js +309 -0
  28. package/dist/vendor/codeburn/codex.js +429 -0
  29. package/dist/vendor/codeburn/copilot.js +292 -0
  30. package/dist/vendor/codeburn/gemini.js +195 -0
  31. package/dist/vendor/codeburn/grokbot.js +182 -0
  32. package/dist/vendor/codeburn/kimi.js +178 -0
  33. package/dist/vendor/codeburn/shims/chalk.js +14 -0
  34. package/dist/vendor/codeburn/shims/strip-ansi.js +6 -0
  35. package/dist/vendor/codeburn/src/act/backup.js +83 -0
  36. package/dist/vendor/codeburn/src/act/model-defaults.js +151 -0
  37. package/dist/vendor/codeburn/src/act/types.js +37 -0
  38. package/dist/vendor/codeburn/src/bash-utils.js +204 -0
  39. package/dist/vendor/codeburn/src/behavioral-weight.js +47 -0
  40. package/dist/vendor/codeburn/src/cache-dir.js +26 -0
  41. package/dist/vendor/codeburn/src/cache-refresh-lock.js +543 -0
  42. package/dist/vendor/codeburn/src/cache-sweep.js +67 -0
  43. package/dist/vendor/codeburn/src/classifier.js +209 -0
  44. package/dist/vendor/codeburn/src/claude-identity.js +223 -0
  45. package/dist/vendor/codeburn/src/codex-cache.js +377 -0
  46. package/dist/vendor/codeburn/src/codex-fork-replay.js +232 -0
  47. package/dist/vendor/codeburn/src/codex-jsonl-fields.js +99 -0
  48. package/dist/vendor/codeburn/src/codex-session-index.js +113 -0
  49. package/dist/vendor/codeburn/src/codex-throughput.js +544 -0
  50. package/dist/vendor/codeburn/src/compare-stats.js +405 -0
  51. package/dist/vendor/codeburn/src/config.js +145 -0
  52. package/dist/vendor/codeburn/src/content-utils.js +56 -0
  53. package/dist/vendor/codeburn/src/context-tree-codex.js +329 -0
  54. package/dist/vendor/codeburn/src/context-tree.js +664 -0
  55. package/dist/vendor/codeburn/src/copilot-aiu.js +16 -0
  56. package/dist/vendor/codeburn/src/currency.js +189 -0
  57. package/dist/vendor/codeburn/src/cursor-cache.js +238 -0
  58. package/dist/vendor/codeburn/src/cursor-import.js +402 -0
  59. package/dist/vendor/codeburn/src/cursor-sync.js +256 -0
  60. package/dist/vendor/codeburn/src/daily-cache.js +2036 -0
  61. package/dist/vendor/codeburn/src/data/litellm-snapshot.json +1 -0
  62. package/dist/vendor/codeburn/src/data/pricing-fallback.json +1 -0
  63. package/dist/vendor/codeburn/src/day-aggregator.js +327 -0
  64. package/dist/vendor/codeburn/src/editor-data-dir.js +11 -0
  65. package/dist/vendor/codeburn/src/fetch-utils.js +18 -0
  66. package/dist/vendor/codeburn/src/format.js +118 -0
  67. package/dist/vendor/codeburn/src/fs-utils.js +270 -0
  68. package/dist/vendor/codeburn/src/git-origin.js +334 -0
  69. package/dist/vendor/codeburn/src/granular-history.js +328 -0
  70. package/dist/vendor/codeburn/src/hermes-session-ledger.js +512 -0
  71. package/dist/vendor/codeburn/src/launcher-homes.js +142 -0
  72. package/dist/vendor/codeburn/src/live-sessions.js +358 -0
  73. package/dist/vendor/codeburn/src/math-utils.js +8 -0
  74. package/dist/vendor/codeburn/src/menubar-json.js +294 -0
  75. package/dist/vendor/codeburn/src/models.js +1879 -0
  76. package/dist/vendor/codeburn/src/optimize-one-hour-cache.js +92 -0
  77. package/dist/vendor/codeburn/src/optimize.js +4110 -0
  78. package/dist/vendor/codeburn/src/parse-workers.js +219 -0
  79. package/dist/vendor/codeburn/src/parser.js +6953 -0
  80. package/dist/vendor/codeburn/src/path-privacy.js +26 -0
  81. package/dist/vendor/codeburn/src/plans.js +135 -0
  82. package/dist/vendor/codeburn/src/pr-signals.js +132 -0
  83. package/dist/vendor/codeburn/src/project-filter-warnings.js +33 -0
  84. package/dist/vendor/codeburn/src/provider-issues.js +30 -0
  85. package/dist/vendor/codeburn/src/providers/amp.js +286 -0
  86. package/dist/vendor/codeburn/src/providers/antigravity.js +1731 -0
  87. package/dist/vendor/codeburn/src/providers/claude.js +551 -0
  88. package/dist/vendor/codeburn/src/providers/cline-cli.js +401 -0
  89. package/dist/vendor/codeburn/src/providers/cline.js +63 -0
  90. package/dist/vendor/codeburn/src/providers/codebuff.js +336 -0
  91. package/dist/vendor/codeburn/src/providers/codewhale.js +442 -0
  92. package/dist/vendor/codeburn/src/providers/codex.js +1720 -0
  93. package/dist/vendor/codeburn/src/providers/command-code.js +196 -0
  94. package/dist/vendor/codeburn/src/providers/copilot.js +3278 -0
  95. package/dist/vendor/codeburn/src/providers/crush.js +226 -0
  96. package/dist/vendor/codeburn/src/providers/cursor-agent.js +837 -0
  97. package/dist/vendor/codeburn/src/providers/cursor.js +1163 -0
  98. package/dist/vendor/codeburn/src/providers/devin.js +569 -0
  99. package/dist/vendor/codeburn/src/providers/droid.js +324 -0
  100. package/dist/vendor/codeburn/src/providers/dsh.js +690 -0
  101. package/dist/vendor/codeburn/src/providers/forge.js +245 -0
  102. package/dist/vendor/codeburn/src/providers/gemini.js +230 -0
  103. package/dist/vendor/codeburn/src/providers/goose.js +252 -0
  104. package/dist/vendor/codeburn/src/providers/grok.js +581 -0
  105. package/dist/vendor/codeburn/src/providers/grokbot.js +290 -0
  106. package/dist/vendor/codeburn/src/providers/hermes.js +771 -0
  107. package/dist/vendor/codeburn/src/providers/ibm-bob.js +53 -0
  108. package/dist/vendor/codeburn/src/providers/index.js +360 -0
  109. package/dist/vendor/codeburn/src/providers/kilo-code.js +50 -0
  110. package/dist/vendor/codeburn/src/providers/kimi.js +363 -0
  111. package/dist/vendor/codeburn/src/providers/kimicode.js +402 -0
  112. package/dist/vendor/codeburn/src/providers/kiro.js +1174 -0
  113. package/dist/vendor/codeburn/src/providers/lingtai-tui.js +372 -0
  114. package/dist/vendor/codeburn/src/providers/mistral-vibe-unified.js +236 -0
  115. package/dist/vendor/codeburn/src/providers/mistral-vibe.js +405 -0
  116. package/dist/vendor/codeburn/src/providers/mux.js +242 -0
  117. package/dist/vendor/codeburn/src/providers/open-design.js +217 -0
  118. package/dist/vendor/codeburn/src/providers/openclaude.js +309 -0
  119. package/dist/vendor/codeburn/src/providers/openclaw.js +442 -0
  120. package/dist/vendor/codeburn/src/providers/opencode-file-parser.js +131 -0
  121. package/dist/vendor/codeburn/src/providers/opencode.js +91 -0
  122. package/dist/vendor/codeburn/src/providers/pi.js +429 -0
  123. package/dist/vendor/codeburn/src/providers/quickdesk.js +491 -0
  124. package/dist/vendor/codeburn/src/providers/qwen.js +193 -0
  125. package/dist/vendor/codeburn/src/providers/session-message.js +118 -0
  126. package/dist/vendor/codeburn/src/providers/sqlite-session-parser.js +457 -0
  127. package/dist/vendor/codeburn/src/providers/types.js +5 -0
  128. package/dist/vendor/codeburn/src/providers/vercel-gateway.js +135 -0
  129. package/dist/vendor/codeburn/src/providers/vscode-cline-parser.js +212 -0
  130. package/dist/vendor/codeburn/src/providers/warp.js +575 -0
  131. package/dist/vendor/codeburn/src/providers/zcode.js +249 -0
  132. package/dist/vendor/codeburn/src/providers/zed.js +187 -0
  133. package/dist/vendor/codeburn/src/providers/zerostack.js +139 -0
  134. package/dist/vendor/codeburn/src/quota/antigravity.js +310 -0
  135. package/dist/vendor/codeburn/src/quota/claude.js +244 -0
  136. package/dist/vendor/codeburn/src/quota/cursor.js +301 -0
  137. package/dist/vendor/codeburn/src/quota/security.js +299 -0
  138. package/dist/vendor/codeburn/src/quota/types.js +1 -0
  139. package/dist/vendor/codeburn/src/scan-facts.js +99 -0
  140. package/dist/vendor/codeburn/src/session-cache.js +3040 -0
  141. package/dist/vendor/codeburn/src/session-count-label.js +14 -0
  142. package/dist/vendor/codeburn/src/session-output.js +139 -0
  143. package/dist/vendor/codeburn/src/session-population.js +30 -0
  144. package/dist/vendor/codeburn/src/sessions-report.js +1342 -0
  145. package/dist/vendor/codeburn/src/sqlite.js +528 -0
  146. package/dist/vendor/codeburn/src/sync/otlp.js +420 -0
  147. package/dist/vendor/codeburn/src/telemetry-snapshot.js +244 -0
  148. package/dist/vendor/codeburn/src/token-estimate.js +5 -0
  149. package/dist/vendor/codeburn/src/types.js +16 -0
  150. package/dist/vendor/codeburn/src/work-units.js +126 -0
  151. package/dist/vendor/codeburn/src/workflow-insights.js +228 -0
  152. package/dist/vendor/codeburn/src/wsl.js +198 -0
  153. package/dist/vendor/codeburn/src/yield.js +666 -0
  154. package/package.json +1 -1
@@ -0,0 +1,309 @@
1
+ // Live Antigravity quota from LOCAL surfaces only - the Antigravity app's own
2
+ // language server or a signed-in `agy` CLI's embedded server. The local
3
+ // Antigravity language-server protocol is undocumented and
4
+ // experimental). No Google OAuth fallback in v1: when no local server answers,
5
+ // the provider reports disconnected and the UI shows its Connect affordance.
6
+ //
7
+ // Endpoints (localhost only, Connect-RPC JSON):
8
+ // - POST https://127.0.0.1:<port>/exa.language_server_pb.LanguageServerService/RetrieveUserQuotaSummary
9
+ // (preferred windows; the tier and fallback windows come from)
10
+ // - POST https://127.0.0.1:<port>/exa.language_server_pb.LanguageServerService/GetUserStatus
11
+ //
12
+ // Discovery lists processes to find candidates (app language servers need a
13
+ // CSRF token, from `--csrf_token` or a daemon file; the `agy` CLI needs none), then lists each
14
+ // pid's listening TCP ports: `ps` and `lsof` on POSIX, Win32_Process and
15
+ // `netstat` on Windows, which has neither. Local HTTPS uses a self-signed cert,
16
+ // so TLS verification is relaxed ONLY for the 127.0.0.1 loopback probes.
17
+ import { execFile } from 'node:child_process';
18
+ import { readdirSync, readFileSync, statSync } from 'node:fs';
19
+ import http from 'node:http';
20
+ import https from 'node:https';
21
+ import { homedir } from 'node:os';
22
+ import { join } from 'node:path';
23
+ import { promisify } from 'node:util';
24
+ import { fraction, sanitizeError } from './security.js';
25
+ const SUMMARY_PATH = '/exa.language_server_pb.LanguageServerService/RetrieveUserQuotaSummary';
26
+ const STATUS_PATH = '/exa.language_server_pb.LanguageServerService/GetUserStatus';
27
+ const LOCAL_TIMEOUT_MS = 3_000;
28
+ const execFileAsync = promisify(execFile);
29
+ function postLocal(port, tls, pathName, body, csrf) {
30
+ return new Promise(resolve => {
31
+ const request = (tls ? https : http).request({
32
+ host: '127.0.0.1',
33
+ port,
34
+ method: 'POST',
35
+ path: pathName,
36
+ ...(tls ? { rejectUnauthorized: false } : {}),
37
+ headers: {
38
+ 'Content-Type': 'application/json',
39
+ 'Connect-Protocol-Version': '1',
40
+ ...(csrf ? { 'X-Codeium-Csrf-Token': csrf } : {}),
41
+ },
42
+ timeout: LOCAL_TIMEOUT_MS,
43
+ }, response => {
44
+ let text = '';
45
+ response.setEncoding('utf8');
46
+ response.on('data', chunk => { text += chunk; });
47
+ response.on('end', () => resolve({ status: response.statusCode ?? 0, text }));
48
+ });
49
+ request.on('timeout', () => { request.destroy(); resolve(null); });
50
+ request.on('error', () => resolve(null));
51
+ request.end(body);
52
+ });
53
+ }
54
+ const defaults = {
55
+ execFile: execFileAsync,
56
+ request: postLocal,
57
+ platform: process.platform,
58
+ };
59
+ function empty(connection) {
60
+ return { provider: 'antigravity', connection, primary: null, details: [], planLabel: null, footerLines: [] };
61
+ }
62
+ // Process kinds distinguish the app language server from standalone processes.
63
+ // carries richer quota data than the IDE variant, so IDE matches are skipped;
64
+ // a CLI (`agy`) match is accepted because its tokenless server exposes the
65
+ // same summary payload.
66
+ const LANGUAGE_SERVER = /language[_-]server(_macos)?(_arm)?/;
67
+ const IDE_MARKER = /antigravity[-_]ide/i;
68
+ const CLI_MARKER = /antigravity[-_]cli/i;
69
+ const AGY_BINARY = /(^|\/|\s)agy(\s|$)/;
70
+ const APP_MARKER = /--app_data_dir[= ]"?antigravity(?![\w-])|\/antigravity\//i;
71
+ function flagValue(line, flag) {
72
+ const match = line.match(new RegExp(`${flag}[= ]([^\\s]+)`));
73
+ return match?.[1];
74
+ }
75
+ /// Newer app servers keep the token off the command line and write it, with their pid, to
76
+ /// `hub_<port>.json` here. Files from exited servers stay behind, so only the newest one
77
+ /// naming this pid counts.
78
+ export function daemonHub(pid, dir = join(homedir(), '.gemini', 'antigravity', 'daemon')) {
79
+ let names;
80
+ try {
81
+ names = readdirSync(dir);
82
+ }
83
+ catch {
84
+ return undefined;
85
+ }
86
+ let found;
87
+ let newest = -Infinity;
88
+ for (const name of names) {
89
+ if (!/^hub_\d+\.json$/.test(name))
90
+ continue;
91
+ try {
92
+ const file = join(dir, name);
93
+ const hub = JSON.parse(readFileSync(file, 'utf8'));
94
+ const modified = statSync(file).mtimeMs;
95
+ if (hub?.pid !== Number(pid) || typeof hub.csrfToken !== 'string' || !/^[\w-]+$/.test(hub.csrfToken) || modified <= newest)
96
+ continue;
97
+ found = { csrfToken: hub.csrfToken, httpsPort: Number(hub.httpsPort) };
98
+ newest = modified;
99
+ }
100
+ catch { /* unreadable or malformed */ }
101
+ }
102
+ return found;
103
+ }
104
+ export function classifyProcessLine(line, daemonDir) {
105
+ const isServer = LANGUAGE_SERVER.test(line);
106
+ const isCli = !isServer && (CLI_MARKER.test(line) || AGY_BINARY.test(line));
107
+ if (!isServer && !isCli)
108
+ return null;
109
+ const pid = line.trim().match(/^(\d+)/)?.[1];
110
+ if (!pid)
111
+ return null;
112
+ // A desktop language server with no token anywhere is skipped so a later,
113
+ // valid server can be found; the CLI exposes no CSRF flag and needs none. IDE
114
+ // language servers are excluded too - their payloads lack the weekly groups.
115
+ if (!isCli && (!APP_MARKER.test(line) || IDE_MARKER.test(line)))
116
+ return null;
117
+ const csrf = flagValue(line, '--csrf_token') ?? (isCli ? undefined : daemonHub(pid, daemonDir)?.csrfToken);
118
+ if (!isCli && !csrf)
119
+ return null;
120
+ const extPort = Number(flagValue(line, '--extension_server_port'));
121
+ return { pid, cli: isCli, csrf, extPort: Number.isFinite(extPort) && extPort > 0 ? extPort : undefined };
122
+ }
123
+ /// Windows has no `ps`, and asking for one is a spawn failure rather than an empty answer:
124
+ /// every quota poll there printed `ps: unknown option -- x` and reported a transient failure.
125
+ /// Win32_Process is the same listing by another name, and it is already how
126
+ /// src/providers/antigravity.ts finds these servers. The Where-Object is only a prefilter to
127
+ /// keep the output small; `classifyProcessLine` still decides what counts.
128
+ const WINDOWS_PROCESS_SCRIPT = [
129
+ "$ErrorActionPreference = 'SilentlyContinue'",
130
+ '[Console]::OutputEncoding = [System.Text.Encoding]::UTF8',
131
+ 'Get-CimInstance Win32_Process'
132
+ + " | Where-Object { $_.CommandLine -and ($_.CommandLine -like '*antigravity*'"
133
+ + " -or $_.CommandLine -like '*language_server*' -or $_.CommandLine -like '*agy*') }"
134
+ + ' | ForEach-Object { "$($_.ProcessId) $($_.CommandLine)" }',
135
+ ].join('; ');
136
+ /// Windows searches the current directory before PATH, so a system tool by bare name lets
137
+ /// anything dropped beside the caller answer for it.
138
+ function system32(exe, env = process.env) {
139
+ const root = env.SystemRoot;
140
+ const base = root && /^[a-zA-Z]:[\\/]/.test(root) ? root.replace(/[\\/]+$/, '') : 'C:\\Windows';
141
+ return `${base}\\System32\\${exe}`;
142
+ }
143
+ /// One line per process, `<pid> <command line>`, on every platform.
144
+ async function listProcesses(deps) {
145
+ if (deps.platform === 'win32') {
146
+ const { stdout } = await deps.execFile(system32('WindowsPowerShell\\v1.0\\powershell.exe'), [
147
+ '-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-Command', WINDOWS_PROCESS_SCRIPT,
148
+ ]);
149
+ return stdout;
150
+ }
151
+ const { stdout } = await deps.execFile('ps', ['-ax', '-o', 'pid=,command=']);
152
+ return stdout;
153
+ }
154
+ /// `netstat -ano` rows are `Proto Local Foreign State PID`. The state word is localized,
155
+ /// so it is not matched on: a row for this pid that is not listening only gives a port the
156
+ /// probe then fails to reach, which costs one refused connection and no wrong answer.
157
+ export function parseNetstatPorts(stdout, pid) {
158
+ const ports = new Set();
159
+ for (const line of stdout.split(/\r?\n/)) {
160
+ const parts = line.trim().split(/\s+/);
161
+ if (parts.length < 5 || !/^TCP$/i.test(parts[0]) || parts[parts.length - 1] !== pid)
162
+ continue;
163
+ const port = Number(parts[1].split(':').pop());
164
+ if (Number.isFinite(port) && port > 0)
165
+ ports.add(port);
166
+ }
167
+ return [...ports];
168
+ }
169
+ async function discoverCandidates(deps) {
170
+ const stdout = await listProcesses(deps);
171
+ const seen = new Set();
172
+ const candidates = [];
173
+ for (const line of stdout.split('\n')) {
174
+ const candidate = classifyProcessLine(line);
175
+ if (!candidate || seen.has(candidate.pid))
176
+ continue;
177
+ seen.add(candidate.pid);
178
+ candidates.push(candidate);
179
+ }
180
+ // The app source ranks above the CLI: richer quota data beats availability.
181
+ return candidates.sort((a, b) => Number(a.cli) - Number(b.cli));
182
+ }
183
+ async function listeningPorts(deps, pid) {
184
+ try {
185
+ // No lsof on Windows either; netstat is the listing that ships with it.
186
+ if (deps.platform === 'win32') {
187
+ const { stdout } = await deps.execFile(system32('netstat.exe'), ['-ano', '-p', 'TCP']);
188
+ return parseNetstatPorts(stdout, pid);
189
+ }
190
+ const { stdout } = await deps.execFile('lsof', ['-nP', '-iTCP', '-sTCP:LISTEN', '-a', '-p', pid]);
191
+ const ports = [...stdout.matchAll(/:(\d+)\s/g)].map(match => Number(match[1]));
192
+ return [...new Set(ports)].filter(port => Number.isFinite(port) && port > 0);
193
+ }
194
+ catch {
195
+ return [];
196
+ }
197
+ }
198
+ function resetTimeOf(value) {
199
+ if (typeof value === 'number' && Number.isFinite(value)) {
200
+ const date = new Date(value > 1e12 ? value : value * 1000);
201
+ return Number.isNaN(date.getTime()) ? null : date.toISOString();
202
+ }
203
+ if (typeof value === 'string' && !Number.isNaN(Date.parse(value)))
204
+ return new Date(value).toISOString();
205
+ return null;
206
+ }
207
+ function windowOf(label, remainingFraction, resetTime) {
208
+ const remaining = fraction(typeof remainingFraction === 'number' ? (1 - remainingFraction) * 100 : NaN);
209
+ if (remaining === null)
210
+ return null;
211
+ return { label, percent: remaining, resetsAt: resetTimeOf(resetTime ?? null) };
212
+ }
213
+ /** Preferred payload: two named quota groups of model buckets. */
214
+ export function decodeAntigravitySummary(body) {
215
+ const data = body && typeof body === 'object' ? body : {};
216
+ // 2.16+ wraps the groups in `response`; older local servers return them directly.
217
+ const groups = Array.isArray(data.response?.groups) ? data.response.groups : data.groups;
218
+ const windows = [];
219
+ for (const group of Array.isArray(groups) ? groups : []) {
220
+ const groupName = typeof group?.displayName === 'string' ? group.displayName : '';
221
+ for (const bucket of Array.isArray(group?.buckets) ? group.buckets : []) {
222
+ const name = [groupName, typeof bucket?.displayName === 'string' ? bucket.displayName : bucket?.bucketId]
223
+ .filter(Boolean).join(' · ');
224
+ if (!name)
225
+ continue;
226
+ const window = windowOf(name, bucket?.remainingFraction ?? bucket?.remaining?.remainingFraction, bucket?.resetTime ?? bucket?.remaining?.resetTime);
227
+ if (window)
228
+ windows.push(window);
229
+ }
230
+ }
231
+ return windows;
232
+ }
233
+ /** Legacy payload: flat per-model quota rows under GetUserStatus. */
234
+ export function decodeAntigravityStatus(body) {
235
+ const data = body && typeof body === 'object' ? body : {};
236
+ const configs = data.userStatus?.cascadeModelConfigData?.clientModelConfigs;
237
+ const windows = [];
238
+ for (const config of Array.isArray(configs) ? configs : []) {
239
+ // Current servers expose the display name as `label`, not `modelName`.
240
+ const name = typeof config?.label === 'string' && config.label.trim() ? config.label
241
+ : typeof config?.modelName === 'string' ? config.modelName : '';
242
+ if (!name)
243
+ continue;
244
+ const window = windowOf(name, config?.quotaInfo?.remainingFraction, config?.quotaInfo?.resetTime);
245
+ if (window)
246
+ windows.push(window);
247
+ }
248
+ return windows;
249
+ }
250
+ function planFromStatus(body) {
251
+ const data = body && typeof body === 'object' ? body : {};
252
+ // userTier is the Google subscription; planStatus.planInfo.planName says "Pro" even on the free tier.
253
+ const plan = [data.userStatus?.userTier?.name, data.planName, data.userStatus?.planName, data.account_plan]
254
+ .find(value => typeof value === 'string' && value.trim());
255
+ return plan ? plan.trim() : null;
256
+ }
257
+ async function probePort(deps, port, csrf) {
258
+ const body = JSON.stringify({});
259
+ for (const tls of [true, false]) {
260
+ const summary = await deps.request(port, tls, SUMMARY_PATH, body, csrf);
261
+ const summaryWindows = summary?.status === 200 ? decodeAntigravitySummary(parseJson(summary.text)) : [];
262
+ // The summary payload carries no tier, so GetUserStatus is asked either way.
263
+ const status = await deps.request(port, tls, STATUS_PATH, body, csrf);
264
+ const parsed = status?.status === 200 ? parseJson(status.text) : null;
265
+ const windows = summaryWindows.length > 0 ? summaryWindows : decodeAntigravityStatus(parsed);
266
+ if (windows.length > 0)
267
+ return { windows, planLabel: planFromStatus(parsed) };
268
+ }
269
+ return null;
270
+ }
271
+ function parseJson(text) {
272
+ try {
273
+ return JSON.parse(text);
274
+ }
275
+ catch {
276
+ return null;
277
+ }
278
+ }
279
+ export async function fetchAntigravityQuota(deps = {}) {
280
+ const resolved = { ...defaults, ...deps };
281
+ try {
282
+ const candidates = await discoverCandidates(resolved);
283
+ if (candidates.length === 0)
284
+ return empty('disconnected');
285
+ for (const candidate of candidates) {
286
+ const ports = await listeningPorts(resolved, candidate.pid);
287
+ if (candidate.extPort !== undefined && !ports.includes(candidate.extPort))
288
+ ports.push(candidate.extPort);
289
+ for (const port of ports) {
290
+ const found = await probePort(resolved, port, candidate.csrf);
291
+ if (found) {
292
+ const windows = [...found.windows].sort((a, b) => b.percent - a.percent);
293
+ return {
294
+ provider: 'antigravity', connection: 'connected',
295
+ primary: windows[0] ?? null,
296
+ details: windows,
297
+ planLabel: found.planLabel,
298
+ footerLines: [],
299
+ };
300
+ }
301
+ }
302
+ }
303
+ return empty('disconnected');
304
+ }
305
+ catch (error) {
306
+ console.warn(`Antigravity quota unavailable: ${sanitizeError(error)}`);
307
+ return empty('transientFailure');
308
+ }
309
+ }