@bitkyc08/opencodex 2.7.43-preview.20260728 → 2.8.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.
- package/README.md +8 -1
- package/bin/ocx.mjs +47 -22
- package/gui/dist/assets/index-BDjpkcRN.js +67 -0
- package/gui/dist/assets/index-BHsKRFh9.css +1 -0
- package/gui/dist/index.html +2 -2
- package/package.json +1 -1
- package/src/AGENTS.md +28 -0
- package/src/adapters/anthropic.ts +15 -6
- package/src/adapters/cursor/discovery.ts +4 -1
- package/src/adapters/cursor/effort-map.ts +3 -0
- package/src/adapters/cursor/native-exec-shell.ts +18 -6
- package/src/adapters/cursor/protobuf-events.ts +24 -2
- package/src/adapters/cursor/protobuf-request.ts +1 -2
- package/src/adapters/cursor/tool-definitions.ts +68 -29
- package/src/adapters/google-wire-compiler.ts +4 -0
- package/src/adapters/google.ts +128 -2
- package/src/adapters/identity.ts +12 -2
- package/src/adapters/kiro.ts +64 -7
- package/src/adapters/mimo-free.ts +2 -0
- package/src/adapters/openai-responses.ts +246 -59
- package/src/claude/agents-inject.ts +5 -0
- package/src/claude/alias.ts +94 -14
- package/src/claude/inbound.ts +26 -9
- package/src/claude/outbound.ts +6 -3
- package/src/cli/account-auth.ts +1 -1
- package/src/cli/agent-driven.ts +37 -0
- package/src/cli/catalog-prewarm.ts +24 -0
- package/src/cli/claude.ts +35 -10
- package/src/cli/doctor.ts +71 -19
- package/src/cli/help.ts +42 -6
- package/src/cli/index.ts +93 -19
- package/src/cli/interactive-confirm.ts +133 -0
- package/src/cli/opencode.ts +701 -0
- package/src/cli/provider-runtime.ts +3 -0
- package/src/cli/provider.ts +31 -10
- package/src/cli/star-prompt.ts +79 -18
- package/src/cli/status.ts +47 -13
- package/src/cli/v2.ts +10 -1
- package/src/codex/account-id.ts +34 -0
- package/src/codex/account-lifecycle.ts +4 -1
- package/src/codex/account-namespace-match.ts +63 -0
- package/src/codex/account-namespaces.ts +149 -0
- package/src/codex/account-pause.ts +20 -0
- package/src/codex/account-store.ts +2 -0
- package/src/codex/account-usability.ts +6 -1
- package/src/codex/app-server-processes.ts +511 -0
- package/src/codex/auth-api.ts +293 -34
- package/src/codex/auth-collision.ts +2 -1
- package/src/codex/auth-context.ts +60 -17
- package/src/codex/catalog/bundled.ts +9 -2
- package/src/codex/catalog/parsing.ts +42 -2
- package/src/codex/catalog/provider-fetch.ts +264 -70
- package/src/codex/catalog/sync.ts +45 -8
- package/src/codex/catalog.ts +2 -2
- package/src/codex/features.ts +524 -5
- package/src/codex/history-provider.ts +145 -1
- package/src/codex/inject.ts +114 -14
- package/src/codex/main-account.ts +2 -8
- package/src/codex/pool-rotation.ts +186 -0
- package/src/codex/quota.ts +92 -2
- package/src/codex/routing.ts +695 -106
- package/src/codex/runtime.ts +10 -1
- package/src/codex/shim.ts +4 -1
- package/src/codex/subagent-defaults.ts +550 -0
- package/src/codex/subagent-model-fallback.ts +2 -0
- package/src/codex/sync.ts +3 -0
- package/src/config.ts +574 -25
- package/src/generated/jawcode-model-metadata.ts +12 -12
- package/src/github/star-state.ts +191 -0
- package/src/images/artifacts.ts +516 -0
- package/src/images/fulfill-video.ts +163 -0
- package/src/images/fulfill.ts +111 -0
- package/src/images/index.ts +4 -0
- package/src/images/loop.ts +789 -0
- package/src/images/plan.ts +133 -0
- package/src/images/synthetic-tool.ts +133 -0
- package/src/images/types.ts +41 -0
- package/src/images/xai-client.ts +141 -0
- package/src/images/xai-video-client.ts +163 -0
- package/src/lib/admin-secrets.ts +25 -0
- package/src/lib/bun-binary-validator.d.mts +3 -0
- package/src/lib/bun-binary-validator.mjs +18 -0
- package/src/lib/bun-runtime.ts +6 -20
- package/src/lib/config-ownership.ts +327 -0
- package/src/lib/crash-guard.ts +2 -0
- package/src/lib/destination-policy.ts +132 -7
- package/src/lib/pinned-http.ts +151 -0
- package/src/lib/process-control.ts +2 -2
- package/src/lib/provider-outbound.ts +167 -0
- package/src/lib/provider-url.ts +14 -0
- package/src/lib/proxy-env.ts +18 -0
- package/src/lib/shadow-call.ts +30 -0
- package/src/lib/test-home-guard.ts +90 -0
- package/src/lib/win-exec.ts +12 -2
- package/src/lib/windows-elevation.ts +81 -3
- package/src/lib/windows-secret-acl.ts +189 -12
- package/src/lib/winsw.ts +2 -0
- package/src/oauth/anthropic-routing.ts +570 -0
- package/src/oauth/health.ts +6 -0
- package/src/oauth/index.ts +310 -75
- package/src/oauth/key-providers.ts +38 -8
- package/src/oauth/kimi.ts +2 -0
- package/src/oauth/kiro-credentials.ts +373 -12
- package/src/oauth/kiro.ts +424 -43
- package/src/oauth/login-cli.ts +33 -6
- package/src/oauth/store.ts +56 -4
- package/src/oauth/types.ts +11 -0
- package/src/providers/alibaba-region-migration.ts +16 -3
- package/src/providers/antigravity-models.ts +3 -0
- package/src/providers/api-keys.ts +13 -6
- package/src/providers/derive.ts +8 -2
- package/src/providers/key-failover.ts +24 -4
- package/src/providers/model-discovery.ts +356 -0
- package/src/providers/quota.ts +233 -29
- package/src/providers/registry.ts +125 -3
- package/src/responses/parser.ts +11 -0
- package/src/responses/state.ts +22 -8
- package/src/responses/tool-groups.ts +19 -0
- package/src/router.ts +19 -7
- package/src/server/auth-cors.ts +114 -24
- package/src/server/claude-messages.ts +8 -1
- package/src/server/gui-static.ts +30 -6
- package/src/server/images.ts +303 -9
- package/src/server/index.ts +77 -9
- package/src/server/lifecycle.ts +25 -1
- package/src/server/live.ts +75 -25
- package/src/server/management/agent-settings-routes.ts +106 -8
- package/src/server/management/combo-routes.ts +7 -0
- package/src/server/management/config-routes.ts +22 -7
- package/src/server/management/context.ts +11 -1
- package/src/server/management/logs-usage-routes.ts +167 -3
- package/src/server/management/model-routes.ts +46 -13
- package/src/server/management/oauth-account-routes.ts +163 -17
- package/src/server/management/provider-routes.ts +73 -10
- package/src/server/management/shared.ts +2 -2
- package/src/server/management/sidebar-routes.ts +39 -0
- package/src/server/management/system-restart.ts +172 -0
- package/src/server/management/system-routes.ts +33 -10
- package/src/server/management-api.ts +5 -3
- package/src/server/management-auth.ts +216 -0
- package/src/server/proxy-liveness.ts +14 -3
- package/src/server/responses/compact.ts +21 -13
- package/src/server/responses/core.ts +614 -172
- package/src/server/responses/upstream-error.ts +48 -0
- package/src/server/responses-image-gen-repair.ts +118 -0
- package/src/server/responses-item-id-repair.ts +10 -85
- package/src/server/sse-payload-rewrite.ts +116 -0
- package/src/server/startup-action-control.ts +30 -14
- package/src/server/system-env.ts +28 -10
- package/src/service.ts +284 -19
- package/src/storage/cleanup-job.ts +57 -0
- package/src/storage/cleanup.ts +1504 -28
- package/src/storage/policy-job.ts +387 -0
- package/src/storage/policy-scheduler.ts +40 -0
- package/src/storage/policy-worker.ts +53 -0
- package/src/storage/policy.ts +522 -0
- package/src/storage/restore-job.ts +253 -0
- package/src/storage/restore-worker.ts +52 -0
- package/src/storage/storage-mutation-coordinator.ts +109 -0
- package/src/storage/worker-lifecycle.ts +81 -0
- package/src/tray/windows.ts +34 -4
- package/src/types.ts +107 -1
- package/src/update/badge.ts +72 -0
- package/src/update/index.ts +36 -18
- package/src/update/job.ts +111 -16
- package/src/update/npm-invocation.d.mts +23 -0
- package/src/update/npm-invocation.mjs +94 -0
- package/src/usage/debug.ts +2 -0
- package/src/usage/expected-prices.ts +6 -5
- package/src/usage/log.ts +12 -0
- package/src/web-search/loop.ts +57 -16
- package/gui/dist/assets/index-CjKFJHSC.js +0 -65
- package/gui/dist/assets/index-DfVGuN88.css +0 -1
package/src/codex/quota.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { existsSync, readFileSync, unlinkSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { atomicWriteFile, getConfigDir } from "../config";
|
|
4
|
+
|
|
1
5
|
export type StoredAccountQuota = {
|
|
2
6
|
weeklyPercent?: number;
|
|
3
7
|
monthlyPercent?: number;
|
|
@@ -7,6 +11,20 @@ export type StoredAccountQuota = {
|
|
|
7
11
|
updatedAt: number;
|
|
8
12
|
};
|
|
9
13
|
|
|
14
|
+
/** Disk snapshot under OPENCODEX_HOME — usage percents only (no emails/tokens). */
|
|
15
|
+
const QUOTA_CACHE_FILENAME = "codex-quota-cache.json";
|
|
16
|
+
/** Keep last-known bars across restarts; WHAM still refreshes on TTL in live/prime paths. */
|
|
17
|
+
const QUOTA_DISK_MAX_AGE_MS = 6 * 60 * 60_000;
|
|
18
|
+
const QUOTA_PERSIST_DEBOUNCE_MS = 250;
|
|
19
|
+
|
|
20
|
+
type QuotaDiskFile = {
|
|
21
|
+
version: 1;
|
|
22
|
+
quotas: Record<string, StoredAccountQuota>;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
let diskHydrated = false;
|
|
26
|
+
let persistTimer: ReturnType<typeof setTimeout> | null = null;
|
|
27
|
+
|
|
10
28
|
export type WhamUsageResponse = {
|
|
11
29
|
email?: string | null;
|
|
12
30
|
plan_type?: string | null;
|
|
@@ -33,6 +51,21 @@ const MONTHLY_WINDOW_MIN_MINUTES = MONTHLY_WINDOW_MIN_SECONDS / 60;
|
|
|
33
51
|
const accountQuota = new Map<string, StoredAccountQuota>();
|
|
34
52
|
|
|
35
53
|
export const CODEX_UNKNOWN_USAGE_SCORE = 100;
|
|
54
|
+
export const CODEX_EXHAUSTED_USAGE_PERCENT = 100;
|
|
55
|
+
|
|
56
|
+
export function isCodexQuotaExhausted(
|
|
57
|
+
quota: Pick<StoredAccountQuota, "weeklyPercent" | "monthlyPercent"> | null,
|
|
58
|
+
plan?: string | null,
|
|
59
|
+
): boolean {
|
|
60
|
+
if (!quota) return false;
|
|
61
|
+
const normalizedPlan = plan?.trim().toLowerCase();
|
|
62
|
+
const values = normalizedPlan === "go" || normalizedPlan === "free"
|
|
63
|
+
? [quota.monthlyPercent]
|
|
64
|
+
: [quota.weeklyPercent, quota.monthlyPercent];
|
|
65
|
+
return values.some(value => typeof value === "number"
|
|
66
|
+
&& Number.isFinite(value)
|
|
67
|
+
&& value >= CODEX_EXHAUSTED_USAGE_PERCENT);
|
|
68
|
+
}
|
|
36
69
|
|
|
37
70
|
export function normalizeUsagePercent(value: unknown): number | undefined {
|
|
38
71
|
const numeric = typeof value === "number"
|
|
@@ -105,6 +138,7 @@ export function setAccountQuotaFromParsed(
|
|
|
105
138
|
if (existing?.monthlyResetAt !== undefined) next.monthlyResetAt = existing.monthlyResetAt;
|
|
106
139
|
next.resetCredits = quota.resetCredits;
|
|
107
140
|
accountQuota.set(accountId, next);
|
|
141
|
+
schedulePersistAccountQuotas();
|
|
108
142
|
return;
|
|
109
143
|
}
|
|
110
144
|
|
|
@@ -130,6 +164,7 @@ export function setAccountQuotaFromParsed(
|
|
|
130
164
|
else if (existing?.resetCredits !== undefined) next.resetCredits = existing.resetCredits;
|
|
131
165
|
|
|
132
166
|
accountQuota.set(accountId, next);
|
|
167
|
+
schedulePersistAccountQuotas();
|
|
133
168
|
}
|
|
134
169
|
|
|
135
170
|
export function parseUpstreamQuotaHeaders(headers: Headers): Omit<StoredAccountQuota, "updatedAt"> | null {
|
|
@@ -220,19 +255,74 @@ export function updateAccountQuota(
|
|
|
220
255
|
if (resetCredits !== undefined) quota.resetCredits = resetCredits;
|
|
221
256
|
|
|
222
257
|
accountQuota.set(accountId, quota);
|
|
258
|
+
schedulePersistAccountQuotas();
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function hydrateAccountQuotasFromDisk(): void {
|
|
262
|
+
if (diskHydrated) return;
|
|
263
|
+
diskHydrated = true;
|
|
264
|
+
try {
|
|
265
|
+
const path = join(getConfigDir(), QUOTA_CACHE_FILENAME);
|
|
266
|
+
if (!existsSync(path)) return;
|
|
267
|
+
const raw = readFileSync(path, "utf8");
|
|
268
|
+
const parsed = JSON.parse(raw) as QuotaDiskFile;
|
|
269
|
+
if (!parsed || parsed.version !== 1 || !parsed.quotas || typeof parsed.quotas !== "object") return;
|
|
270
|
+
const now = Date.now();
|
|
271
|
+
for (const [accountId, quota] of Object.entries(parsed.quotas)) {
|
|
272
|
+
if (!quota || typeof quota !== "object" || typeof quota.updatedAt !== "number") continue;
|
|
273
|
+
if (now - quota.updatedAt > QUOTA_DISK_MAX_AGE_MS) continue;
|
|
274
|
+
if (!accountQuota.has(accountId)) accountQuota.set(accountId, quota);
|
|
275
|
+
}
|
|
276
|
+
} catch {
|
|
277
|
+
// Corrupt/missing cache must never block routing or the dashboard.
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function schedulePersistAccountQuotas(): void {
|
|
282
|
+
if (persistTimer) clearTimeout(persistTimer);
|
|
283
|
+
persistTimer = setTimeout(() => {
|
|
284
|
+
persistTimer = null;
|
|
285
|
+
try {
|
|
286
|
+
const quotas: Record<string, StoredAccountQuota> = {};
|
|
287
|
+
for (const [accountId, quota] of accountQuota.entries()) {
|
|
288
|
+
quotas[accountId] = quota;
|
|
289
|
+
}
|
|
290
|
+
const body: QuotaDiskFile = { version: 1, quotas };
|
|
291
|
+
atomicWriteFile(join(getConfigDir(), QUOTA_CACHE_FILENAME), `${JSON.stringify(body)}\n`);
|
|
292
|
+
} catch {
|
|
293
|
+
// Best-effort persistence only.
|
|
294
|
+
}
|
|
295
|
+
}, QUOTA_PERSIST_DEBOUNCE_MS);
|
|
223
296
|
}
|
|
224
297
|
|
|
225
298
|
export function getAccountQuota(accountId: string): StoredAccountQuota | null {
|
|
299
|
+
hydrateAccountQuotasFromDisk();
|
|
226
300
|
return accountQuota.get(accountId) ?? null;
|
|
227
301
|
}
|
|
228
302
|
|
|
229
303
|
export function listAccountQuotas(): IterableIterator<[string, StoredAccountQuota]> {
|
|
304
|
+
hydrateAccountQuotasFromDisk();
|
|
230
305
|
return accountQuota.entries();
|
|
231
306
|
}
|
|
232
307
|
|
|
233
308
|
export function clearAccountQuota(accountId?: string): void {
|
|
234
|
-
if (accountId)
|
|
235
|
-
|
|
309
|
+
if (accountId) {
|
|
310
|
+
accountQuota.delete(accountId);
|
|
311
|
+
schedulePersistAccountQuotas();
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
accountQuota.clear();
|
|
315
|
+
diskHydrated = false;
|
|
316
|
+
if (persistTimer) {
|
|
317
|
+
clearTimeout(persistTimer);
|
|
318
|
+
persistTimer = null;
|
|
319
|
+
}
|
|
320
|
+
try {
|
|
321
|
+
const path = join(getConfigDir(), QUOTA_CACHE_FILENAME);
|
|
322
|
+
if (existsSync(path)) unlinkSync(path);
|
|
323
|
+
} catch {
|
|
324
|
+
// Best-effort; memory is already cleared.
|
|
325
|
+
}
|
|
236
326
|
}
|
|
237
327
|
|
|
238
328
|
export function parseUsageQuota(data: WhamUsageResponse): Omit<StoredAccountQuota, "updatedAt"> | null {
|