@bitkyc08/opencodex 2.12.0 → 2.13.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 (173) hide show
  1. package/README.md +1 -1
  2. package/gui/dist/assets/index-BHldBl6_.js +76 -0
  3. package/gui/dist/index.html +1 -1
  4. package/package.json +1 -1
  5. package/src/adapters/anthropic-output-schema.ts +137 -0
  6. package/src/adapters/anthropic.ts +15 -0
  7. package/src/adapters/google-antigravity-replay.ts +269 -5
  8. package/src/adapters/openai-chat.ts +25 -18
  9. package/src/adapters/openai-responses.ts +63 -17
  10. package/src/bridge.ts +11 -5
  11. package/src/claude/inbound.ts +24 -3
  12. package/src/cli/account-api.ts +2 -0
  13. package/src/cli/account-extended.ts +262 -1
  14. package/src/cli/account.ts +3 -1
  15. package/src/cli/dispatch.ts +532 -0
  16. package/src/cli/doctor.ts +26 -21
  17. package/src/cli/help.ts +9 -278
  18. package/src/cli/index.ts +45 -506
  19. package/src/cli/lab.ts +171 -65
  20. package/src/cli/registry.ts +384 -0
  21. package/src/cli/root.ts +86 -0
  22. package/src/cli/status.ts +9 -2
  23. package/src/cli/v2.ts +37 -2
  24. package/src/codex/account-label.ts +14 -1
  25. package/src/codex/account-store.ts +12 -1
  26. package/src/codex/admission.ts +2 -1
  27. package/src/codex/auth-api.ts +3 -2
  28. package/src/codex/catalog/metadata.ts +6 -4
  29. package/src/codex/catalog/parsing.ts +31 -7
  30. package/src/codex/catalog/provider-fetch.ts +2 -1
  31. package/src/codex/catalog/sync.ts +65 -11
  32. package/src/codex/features.ts +437 -31
  33. package/src/codex/history-job.ts +6 -11
  34. package/src/codex/history-provider.ts +10 -9
  35. package/src/codex/inject.ts +14 -1
  36. package/src/codex/native-profile-startup.ts +49 -3
  37. package/src/codex/native-residue.ts +14 -2
  38. package/src/codex/paths.ts +75 -1
  39. package/src/codex/reset-credit-recovery.ts +1044 -0
  40. package/src/codex/shim.ts +876 -16
  41. package/src/codex/sync.ts +27 -2
  42. package/src/config.ts +148 -10
  43. package/src/generated/compatibility-version.json +2572 -0
  44. package/src/images/loop.ts +1 -1
  45. package/src/lab/artifacts/sanitize.ts +3 -3
  46. package/src/lab/automation/budgets.ts +78 -0
  47. package/src/lab/automation/config-persistence.ts +256 -0
  48. package/src/lab/automation/constants.ts +39 -0
  49. package/src/lab/automation/cooldown.ts +103 -0
  50. package/src/lab/automation/dispatch.ts +211 -0
  51. package/src/lab/automation/index.ts +13 -0
  52. package/src/lab/automation/orchestrator.ts +480 -0
  53. package/src/lab/automation/persistence.ts +512 -0
  54. package/src/lab/automation/planner.ts +371 -0
  55. package/src/lab/automation/policy.ts +136 -0
  56. package/src/lab/automation/queue.ts +191 -0
  57. package/src/lab/automation/recovery.ts +24 -0
  58. package/src/lab/automation/route-context.ts +21 -0
  59. package/src/lab/automation/run-key.ts +44 -0
  60. package/src/lab/automation/runs-query.ts +34 -0
  61. package/src/lab/automation/types.ts +160 -0
  62. package/src/lab/conformance/types.ts +23 -0
  63. package/src/lab/events/types.ts +2 -1
  64. package/src/lab/events/validate.ts +2 -1
  65. package/src/lab/fabric/constants.ts +40 -0
  66. package/src/lab/fabric/executor.ts +492 -0
  67. package/src/lab/fabric/index.ts +80 -0
  68. package/src/lab/fabric/manifest.ts +222 -0
  69. package/src/lab/fabric/observe.ts +454 -0
  70. package/src/lab/fabric/patch.ts +79 -0
  71. package/src/lab/fabric/producer-child.ts +139 -0
  72. package/src/lab/fabric/producer-isolate.ts +276 -0
  73. package/src/lab/fabric/producer-protocol.ts +61 -0
  74. package/src/lab/fabric/scratch.ts +439 -0
  75. package/src/lab/fabric/subject.ts +106 -0
  76. package/src/lab/fabric/types.ts +134 -0
  77. package/src/lab/fabric/verifier.ts +98 -0
  78. package/src/lab/index.ts +2 -0
  79. package/src/lab/ledger/store.ts +173 -0
  80. package/src/lab/live/executor.ts +29 -4
  81. package/src/lab/live/transport.ts +3 -1
  82. package/src/lab/observe/from-conformance.ts +12 -57
  83. package/src/lab/observe/from-live.ts +9 -1
  84. package/src/lab/paths.ts +74 -9
  85. package/src/lab/projection/schema.ts +14 -1
  86. package/src/lab/projection/verdicts.ts +89 -53
  87. package/src/lab/projection/verification.ts +83 -3
  88. package/src/lab/query/catalog.ts +34 -5
  89. package/src/lab/query/freshness.ts +53 -0
  90. package/src/lab/query/index.ts +11 -0
  91. package/src/lab/query/latest-observation.ts +59 -0
  92. package/src/lab/query/passive-production.ts +159 -0
  93. package/src/lab/subject/installation-salt.ts +24 -4
  94. package/src/lab/subject/protocol-subject.ts +80 -0
  95. package/src/lab/subject/route-subject.ts +2 -1
  96. package/src/lib/fabric-task-execution-authority.ts +7 -0
  97. package/src/lib/fabric-task-host.ts +29 -0
  98. package/src/lib/lab-live-route-production.ts +130 -0
  99. package/src/lib/local-management-capability.ts +100 -0
  100. package/src/lib/server-resource-ownership.ts +71 -0
  101. package/src/lib/windows-elevation.ts +8 -1
  102. package/src/lib/windows-user-principal.ts +62 -2
  103. package/src/lib/winsw.ts +8 -2
  104. package/src/oauth/account-import/google-antigravity-adapter.ts +74 -0
  105. package/src/oauth/account-import/index.ts +15 -0
  106. package/src/oauth/account-import/parser.ts +83 -0
  107. package/src/oauth/account-import/registry.ts +18 -0
  108. package/src/oauth/account-import/service.ts +75 -0
  109. package/src/oauth/account-import/types.ts +91 -0
  110. package/src/oauth/anthropic.ts +12 -1
  111. package/src/oauth/callback-server.ts +8 -2
  112. package/src/oauth/chatgpt.ts +12 -1
  113. package/src/oauth/google-antigravity.ts +27 -0
  114. package/src/oauth/health.ts +12 -48
  115. package/src/oauth/index.ts +122 -0
  116. package/src/oauth/kimi.ts +16 -2
  117. package/src/oauth/nous.ts +749 -0
  118. package/src/oauth/store.ts +56 -3
  119. package/src/providers/codex-capacity.ts +1 -0
  120. package/src/providers/registry.ts +161 -16
  121. package/src/responses/custom-tool-compat.ts +182 -0
  122. package/src/responses/parser.ts +22 -0
  123. package/src/responses/reasoning-replay-cache.ts +168 -11
  124. package/src/responses/schema.ts +1 -1
  125. package/src/router.ts +5 -20
  126. package/src/routing/capability.ts +9 -3
  127. package/src/routing/compatibility/assemble.ts +159 -0
  128. package/src/routing/compatibility/behavior.ts +224 -0
  129. package/src/routing/compatibility/catalog.ts +99 -0
  130. package/src/routing/compatibility/endpoint.ts +52 -0
  131. package/src/routing/compatibility/policy.ts +181 -0
  132. package/src/routing/compatibility/reader.ts +110 -0
  133. package/src/routing/compatibility/subject.ts +191 -0
  134. package/src/routing/compatibility/types.ts +64 -0
  135. package/src/routing/compatibility/version.ts +104 -0
  136. package/src/routing/evaluator.ts +27 -32
  137. package/src/routing/profile.ts +118 -4
  138. package/src/routing/trace.ts +82 -28
  139. package/src/server/auth-cors.ts +7 -0
  140. package/src/server/background-lifecycle.ts +20 -7
  141. package/src/server/chat-completions.ts +2 -2
  142. package/src/server/claude-messages.ts +6 -3
  143. package/src/server/direct-local-http.ts +343 -0
  144. package/src/server/index.ts +80 -18
  145. package/src/server/lifecycle.ts +12 -4
  146. package/src/server/local-management-read-client.ts +90 -0
  147. package/src/server/management/agent-settings-routes.ts +27 -3
  148. package/src/server/management/lab-automation-routes.ts +206 -0
  149. package/src/server/management/lab-routes.ts +13 -0
  150. package/src/server/management/logs-usage-routes.ts +1 -0
  151. package/src/server/management/oauth-account-routes.ts +57 -1
  152. package/src/server/management/provider-routes.ts +16 -0
  153. package/src/server/management/routing-profile-routes.ts +12 -24
  154. package/src/server/management-api.ts +2 -0
  155. package/src/server/management-auth.ts +68 -3
  156. package/src/server/proxy-liveness.ts +3 -2
  157. package/src/server/request-decompress.ts +9 -3
  158. package/src/server/request-log.ts +53 -4
  159. package/src/server/responses/collaboration.ts +93 -17
  160. package/src/server/responses/compact.ts +3 -0
  161. package/src/server/responses/core.ts +202 -15
  162. package/src/server/responses/policy-fallback.ts +1 -0
  163. package/src/server/responses-custom-tool-repair.ts +280 -0
  164. package/src/server/responses-terminal-repair.ts +342 -0
  165. package/src/server/startup-action-control.ts +8 -1
  166. package/src/service.ts +278 -12
  167. package/src/types.ts +49 -3
  168. package/src/usage/expected-prices.ts +30 -0
  169. package/src/usage/log.ts +30 -4
  170. package/src/usage/summary.ts +153 -2
  171. package/src/web-search/loop.ts +1 -1
  172. package/gui/dist/assets/index-Cw1_mxO8.js +0 -70
  173. package/src/cli/internal-dispatch.ts +0 -20
@@ -1,8 +1,8 @@
1
1
  import { baseProviderLabel } from "../providers/label";
2
2
  import { canonicalAntigravityUsageModel } from "../providers/antigravity-models";
3
3
  import { usageDisplayTotalTokens } from "./totals";
4
- import type { PersistedUsageEntry, UsageStatus } from "./log";
5
- import { estimateComboCost, estimateRequestCost, serviceTierContext } from "./cost";
4
+ import { isCodexUsageAccountLogLabel, type PersistedUsageEntry, type UsageStatus } from "./log";
5
+ import { estimateAttemptCost, estimateComboCost, estimateRequestCost, serviceTierContext } from "./cost";
6
6
 
7
7
  export type UsageRange = "7d" | "30d" | "all";
8
8
  export type UsageSurface = "all" | "codex" | "claude" | "grok";
@@ -79,6 +79,28 @@ export interface UsageProvider {
79
79
  estimatedCostUsd?: number;
80
80
  }
81
81
 
82
+ export interface UsageAccount {
83
+ accountLogLabel: string;
84
+ ambiguous: boolean;
85
+ requests: number;
86
+ attemptCount: number;
87
+ measuredAttempts: number;
88
+ reportedAttempts: number;
89
+ estimatedAttempts: number;
90
+ unmeteredAttempts: number;
91
+ inputTokens: number;
92
+ outputTokens: number;
93
+ cacheReadInputTokens: number;
94
+ cacheCreationInputTokens: number;
95
+ reasoningOutputTokens: number;
96
+ totalTokens: number;
97
+ usageCoverageRatio: number;
98
+ estimatedCostUsd?: number;
99
+ pricedAttempts: number;
100
+ unpricedAttempts: number;
101
+ priceCoverageRatio: number;
102
+ }
103
+
82
104
  export interface UsageSummary {
83
105
  range: UsageRange;
84
106
  surface: UsageSurface;
@@ -88,6 +110,7 @@ export interface UsageSummary {
88
110
  days: UsageDay[];
89
111
  models: UsageModel[];
90
112
  providers: UsageProvider[];
113
+ accounts: UsageAccount[];
91
114
  }
92
115
 
93
116
  const DAY_MS = 86_400_000;
@@ -547,6 +570,133 @@ function buildProviders(entries: PersistedUsageEntry[], totalTokens: number): Us
547
570
  return providers.sort((a, b) => b.requests - a.requests);
548
571
  }
549
572
 
573
+ const LEGACY_AMBIGUOUS_ACCOUNT_LABEL = "legacy-ambiguous";
574
+
575
+ function legacyCodexAccountLabel(provider: string): string | null {
576
+ if (baseProviderLabel(provider) !== "openai") return null;
577
+ const suffix = provider.match(/-(main|p[a-f0-9]{6})$/)?.[1];
578
+ return suffix ?? LEGACY_AMBIGUOUS_ACCOUNT_LABEL;
579
+ }
580
+
581
+ function accountLabelForAttribution(provider: string, explicit: unknown): string | null {
582
+ if (isCodexUsageAccountLogLabel(explicit)) return explicit;
583
+ return legacyCodexAccountLabel(provider);
584
+ }
585
+
586
+ function buildAccounts(entries: PersistedUsageEntry[]): UsageAccount[] {
587
+ const byLabel = new Map<string, UsageAccount>();
588
+ const requestIds = new Map<string, Set<string>>();
589
+
590
+ const add = (input: {
591
+ requestId: string;
592
+ provider: string;
593
+ accountLogLabel?: string;
594
+ usageStatus: UsageStatus;
595
+ usage?: PersistedUsageEntry["usage"];
596
+ totalTokens?: number;
597
+ estimate: ReturnType<typeof estimateRequestCost>;
598
+ }): void => {
599
+ const label = accountLabelForAttribution(input.provider, input.accountLogLabel);
600
+ if (!label) return;
601
+ let row = byLabel.get(label);
602
+ if (!row) {
603
+ row = {
604
+ accountLogLabel: label,
605
+ ambiguous: label === LEGACY_AMBIGUOUS_ACCOUNT_LABEL,
606
+ requests: 0,
607
+ attemptCount: 0,
608
+ measuredAttempts: 0,
609
+ reportedAttempts: 0,
610
+ estimatedAttempts: 0,
611
+ unmeteredAttempts: 0,
612
+ inputTokens: 0,
613
+ outputTokens: 0,
614
+ cacheReadInputTokens: 0,
615
+ cacheCreationInputTokens: 0,
616
+ reasoningOutputTokens: 0,
617
+ totalTokens: 0,
618
+ usageCoverageRatio: 0,
619
+ pricedAttempts: 0,
620
+ unpricedAttempts: 0,
621
+ priceCoverageRatio: 0,
622
+ };
623
+ byLabel.set(label, row);
624
+ requestIds.set(label, new Set());
625
+ }
626
+ requestIds.get(label)!.add(input.requestId);
627
+ row.requests = requestIds.get(label)!.size;
628
+ row.attemptCount += 1;
629
+ const measured = input.usage !== undefined && isMeasuredStatus(input.usageStatus);
630
+ if (!measured) {
631
+ row.unmeteredAttempts += 1;
632
+ return;
633
+ }
634
+
635
+ row.measuredAttempts += 1;
636
+ if (input.usageStatus === "reported") row.reportedAttempts += 1;
637
+ else if (input.usageStatus === "estimated") row.estimatedAttempts += 1;
638
+ row.inputTokens += input.usage!.inputTokens;
639
+ row.outputTokens += input.usage!.outputTokens;
640
+ const creation = input.usage!.cacheCreationInputTokens;
641
+ const read = typeof input.usage!.cacheReadInputTokens === "number"
642
+ ? input.usage!.cacheReadInputTokens
643
+ : typeof input.usage!.cachedInputTokens === "number" && typeof creation === "number"
644
+ ? Math.max(0, input.usage!.cachedInputTokens - creation)
645
+ : input.usage!.cachedInputTokens;
646
+ if (typeof read === "number") row.cacheReadInputTokens += read;
647
+ if (typeof creation === "number") row.cacheCreationInputTokens += creation;
648
+ if (typeof input.usage!.reasoningOutputTokens === "number") {
649
+ row.reasoningOutputTokens += input.usage!.reasoningOutputTokens;
650
+ }
651
+ row.totalTokens += usageDisplayTotalTokens(input.usage, input.totalTokens) ?? 0;
652
+ if (input.estimate) {
653
+ row.pricedAttempts += 1;
654
+ row.estimatedCostUsd = (row.estimatedCostUsd ?? 0) + input.estimate.cost.total;
655
+ } else {
656
+ row.unpricedAttempts += 1;
657
+ }
658
+ };
659
+
660
+ for (const entry of entries) {
661
+ const tier = serviceTierContext(entry);
662
+ if (entry.attempts?.length) {
663
+ for (const attempt of entry.attempts) {
664
+ add({
665
+ requestId: entry.requestId,
666
+ provider: attempt.provider,
667
+ ...(attempt.accountLogLabel ? { accountLogLabel: attempt.accountLogLabel } : {}),
668
+ usageStatus: attempt.usageStatus,
669
+ ...(attempt.usage ? { usage: attempt.usage } : {}),
670
+ ...(attempt.totalTokens !== undefined ? { totalTokens: attempt.totalTokens } : {}),
671
+ estimate: estimateAttemptCost(attempt, undefined, tier),
672
+ });
673
+ }
674
+ continue;
675
+ }
676
+ add({
677
+ requestId: entry.requestId,
678
+ provider: entry.provider,
679
+ ...(entry.accountLogLabel ? { accountLogLabel: entry.accountLogLabel } : {}),
680
+ usageStatus: entry.usageStatus,
681
+ ...(entry.usage ? { usage: entry.usage } : {}),
682
+ ...(entry.totalTokens !== undefined ? { totalTokens: entry.totalTokens } : {}),
683
+ estimate: estimateRequestCost({
684
+ provider: entry.provider,
685
+ model: entry.model,
686
+ usage: entry.usage,
687
+ usageStatus: entry.usageStatus,
688
+ serviceTier: tier,
689
+ }),
690
+ });
691
+ }
692
+
693
+ for (const row of byLabel.values()) {
694
+ row.usageCoverageRatio = row.attemptCount === 0 ? 0 : row.measuredAttempts / row.attemptCount;
695
+ row.priceCoverageRatio = row.measuredAttempts === 0 ? 0 : row.pricedAttempts / row.measuredAttempts;
696
+ }
697
+ return [...byLabel.values()].sort((a, b) => b.totalTokens - a.totalTokens);
698
+ }
699
+
550
700
  export function summarizeUsage(
551
701
  entries: PersistedUsageEntry[],
552
702
  range: UsageRange,
@@ -581,5 +731,6 @@ export function summarizeUsage(
581
731
  days: buildDayGrid(range, since, now, filteredEntries),
582
732
  models: buildModels(filteredEntries, totals.totalTokens),
583
733
  providers: buildProviders(filteredEntries, totals.totalTokens),
734
+ accounts: buildAccounts(filteredEntries),
584
735
  };
585
736
  }
@@ -781,7 +781,7 @@ export async function runWithWebSearch(deps: WebSearchLoopDeps): Promise<Respons
781
781
  }, undefined,
782
782
  {
783
783
  translatorBudget,
784
- replayCacheScope: parsed._clientThreadId ?? "global",
784
+ replayCacheScope: parsed._reasoningReplayScope,
785
785
  ...(deps.forceEmptyResponseId ? { responseId: "" } : {}),
786
786
  hideThinkingSummary: parsed.options.hideThinkingSummary,
787
787
  ...(deps.stallTimeoutSec !== undefined ? { stallTimeoutSec: deps.stallTimeoutSec } : {}),