@bitkyc08/opencodex 2.99.0 → 2.100.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 (258) hide show
  1. package/AGENTS_INSTALL.md +19 -1
  2. package/README.md +37 -33
  3. package/SPONSORS.md +5 -1
  4. package/bin/ocx.mjs +1 -1
  5. package/gui/dist/assets/{App-C1hGwaN1.css → App-COo8Yopd.css} +1 -1
  6. package/gui/dist/assets/App-CitvEefy.js +59 -0
  7. package/gui/dist/assets/Tray-CeKVWQyB.js +1 -0
  8. package/gui/dist/assets/{brand-mark-wzPe3R-J.js → brand-mark-M92UnxX2.js} +1 -1
  9. package/gui/dist/assets/index-BP47do6-.js +94 -0
  10. package/gui/dist/assets/index-DmDooSAG.css +2 -0
  11. package/gui/dist/assets/{segment-thumb-features-fYEMxBaW.js → segment-thumb-features-CcxZBnxv.js} +1 -1
  12. package/gui/dist/classic/assets/App-aYgIQMxI.js +58 -0
  13. package/gui/dist/classic/assets/{Tray-BqZueZOx.js → Tray-D8jfUXpQ.js} +1 -1
  14. package/gui/dist/classic/assets/index-CfGqHooN.js +94 -0
  15. package/gui/dist/classic/assets/quota-summary-R-ih7OlS.js +1 -0
  16. package/gui/dist/classic/index.html +1 -1
  17. package/gui/dist/index.html +2 -2
  18. package/native/ocx-child/Cargo.lock +215 -0
  19. package/native/ocx-child/Cargo.toml +31 -0
  20. package/native/ocx-child/src/cli.rs +1901 -0
  21. package/native/ocx-child/src/codex_home.rs +429 -0
  22. package/native/ocx-child/src/codex_settings.rs +231 -0
  23. package/native/ocx-child/src/daemon.rs +363 -0
  24. package/native/ocx-child/src/http_wire.rs +619 -0
  25. package/native/ocx-child/src/journal.rs +977 -0
  26. package/native/ocx-child/src/lib.rs +22 -0
  27. package/native/ocx-child/src/main.rs +9 -0
  28. package/native/ocx-child/src/parity.rs +102 -0
  29. package/native/ocx-child/src/platform.rs +1487 -0
  30. package/native/ocx-child/src/relay.rs +1288 -0
  31. package/native/ocx-child/src/relay_auth.rs +166 -0
  32. package/native/ocx-child/src/routes.rs +236 -0
  33. package/native/ocx-child/src/state.rs +190 -0
  34. package/native/ocx-child/src/test_hooks.rs +58 -0
  35. package/native/ocx-child/src/toml_surgeon.rs +1156 -0
  36. package/package.json +8 -2
  37. package/src/adapters/anthropic.ts +28 -2
  38. package/src/adapters/claude-cli/adapter.ts +5 -25
  39. package/src/adapters/claude-cli/instruction-images.ts +31 -0
  40. package/src/adapters/claude-cli/stable-replay.ts +42 -14
  41. package/src/adapters/claude-cli/usage-admission.ts +53 -64
  42. package/src/adapters/coding-agent/protocol.ts +1 -1
  43. package/src/adapters/devin/live-models.ts +3 -0
  44. package/src/adapters/google-http.ts +3 -0
  45. package/src/adapters/google-vertex-key-project.ts +10 -2
  46. package/src/adapters/google.ts +40 -8
  47. package/src/adapters/kiro/usage.ts +3 -13
  48. package/src/adapters/openai-responses/passthrough.ts +5 -2
  49. package/src/adapters/openai-responses/request-strips.ts +32 -0
  50. package/src/adapters/openai-responses/tool-schema.ts +9 -4
  51. package/src/chat/inbound.ts +1 -1
  52. package/src/claude/auth-detect.ts +26 -8
  53. package/src/claude/inbound-content-options.ts +18 -3
  54. package/src/claude/inbound.ts +5 -2
  55. package/src/cli/bundled-bun-diagnostic.ts +91 -0
  56. package/src/cli/capabilities-agents-routing.ts +2 -2
  57. package/src/cli/capabilities-observe-system.ts +60 -0
  58. package/src/cli/combo-input.ts +6 -0
  59. package/src/cli/combo-result.ts +1 -1
  60. package/src/cli/combo.ts +4 -0
  61. package/src/cli/config-command.ts +16 -2
  62. package/src/cli/connect.ts +12 -10
  63. package/src/cli/dispatch.ts +4 -0
  64. package/src/cli/doctor.ts +11 -0
  65. package/src/cli/help.ts +1 -0
  66. package/src/cli/init.ts +4 -0
  67. package/src/cli/link-enrollment.ts +152 -25
  68. package/src/cli/link-local-control.ts +49 -0
  69. package/src/cli/link.ts +37 -10
  70. package/src/cli/provider-lifecycle-runtime.ts +4 -2
  71. package/src/cli/registry.ts +13 -0
  72. package/src/cli/star-prompt.ts +2 -0
  73. package/src/cli/status.ts +1 -1
  74. package/src/cli/telemetry-profile.ts +206 -0
  75. package/src/cli/telemetry.ts +260 -0
  76. package/src/client/hub-relay.ts +26 -0
  77. package/src/client/machine-api.ts +3 -0
  78. package/src/clients/config-export/t3code.ts +44 -5
  79. package/src/clients/omo-role-models.ts +1 -1
  80. package/src/codex/catalog/bundled.ts +44 -2
  81. package/src/codex/runtime.ts +12 -0
  82. package/src/codex/shim-restore-lock.ts +67 -30
  83. package/src/combos/types.ts +21 -1
  84. package/src/config/atomic-write.ts +24 -1
  85. package/src/config/diagnostics.ts +15 -0
  86. package/src/config/live-reconcile.ts +17 -0
  87. package/src/config/load-degrade.ts +16 -0
  88. package/src/config/provider-validation.ts +29 -0
  89. package/src/config/schema/config-schema.ts +24 -0
  90. package/src/config/schema/leaf-validators.ts +17 -0
  91. package/src/config/telemetry-carry.ts +30 -0
  92. package/src/config.ts +13 -1
  93. package/src/generated/compatibility-version.json +405 -153
  94. package/src/generated/model-metadata.ts +3 -3
  95. package/src/integrations/aside-profiles.ts +7 -1
  96. package/src/integrations/owned-refresh.ts +9 -2
  97. package/src/lab/artifacts/secure-fs.ts +12 -11
  98. package/src/lab/fabric/scratch.ts +11 -9
  99. package/src/lab/public/community.ts +2 -3
  100. package/src/lab/public/file-safety.ts +18 -20
  101. package/src/lab/public/mutation-lock.ts +109 -337
  102. package/src/lab/public/private-file.ts +4 -3
  103. package/src/lib/bun-runtime-preflight.ts +1 -1
  104. package/src/lib/codex-catalog-read-only.ts +122 -0
  105. package/src/lib/config-ownership.ts +49 -18
  106. package/src/lib/errors.ts +11 -0
  107. package/src/lib/gcp-adc.ts +167 -48
  108. package/src/lib/jsonc.ts +4 -2
  109. package/src/lib/local-control-socket.ts +88 -0
  110. package/src/lib/privacy.ts +15 -0
  111. package/src/lib/provider-client-headers.ts +3 -0
  112. package/src/lib/token-estimate.ts +13 -2
  113. package/src/link/child-binary-source.ts +228 -0
  114. package/src/link/ephemeral-child.ts +45 -0
  115. package/src/link/remote-plant.ts +306 -0
  116. package/src/link/remote-windows.ts +59 -5
  117. package/src/link/ssh-argv.ts +71 -8
  118. package/src/link/status-projection.ts +2 -0
  119. package/src/link/store.ts +5 -1
  120. package/src/oauth/claude-keychain-read.ts +165 -0
  121. package/src/oauth/local-token-detect.ts +14 -17
  122. package/src/protocols/envelope.ts +20 -2
  123. package/src/providers/api-key-selection.ts +8 -2
  124. package/src/providers/claude-cli-usage-state.ts +93 -0
  125. package/src/providers/github-copilot-auto.ts +25 -5
  126. package/src/providers/meta-muse-plan-refusal.ts +94 -0
  127. package/src/providers/model-rename-fields.ts +3 -0
  128. package/src/providers/quota/vendor-probes-key.ts +23 -4
  129. package/src/providers/quota/vendor-probes-oauth.ts +59 -0
  130. package/src/providers/quota/workbuddy.ts +2 -2
  131. package/src/providers/quota.ts +25 -18
  132. package/src/providers/registry/entries-core.ts +7 -4
  133. package/src/providers/registry/entries-extended.ts +39 -7
  134. package/src/providers/registry/model-seeds.ts +10 -2
  135. package/src/providers/resolved-model-policy.ts +4 -0
  136. package/src/providers/routed-config.ts +30 -3
  137. package/src/providers/stale-no-vision-seed-migration.ts +7 -0
  138. package/src/providers/vertex-environment-authority.ts +50 -0
  139. package/src/providers/workbuddy-credit-balance.ts +38 -6
  140. package/src/quota-pool/assemble.ts +14 -6
  141. package/src/router.ts +1 -0
  142. package/src/server/adapter-resolve.ts +11 -6
  143. package/src/server/audio-dictation.ts +21 -7
  144. package/src/server/auth-cors.ts +19 -0
  145. package/src/server/background-lifecycle.ts +71 -0
  146. package/src/server/chat-completions.ts +2 -0
  147. package/src/server/claude-messages.ts +30 -3
  148. package/src/server/index/live-sideband.ts +15 -1
  149. package/src/server/index/local-control-listener.ts +515 -0
  150. package/src/server/index/optional-listeners.ts +21 -1
  151. package/src/server/index/serve-options.ts +4 -3
  152. package/src/server/index/websocket-handler.ts +2 -0
  153. package/src/server/index.ts +3 -0
  154. package/src/server/management/combo-routes.ts +6 -1
  155. package/src/server/management/context.ts +1 -0
  156. package/src/server/management/link-child-preflight.ts +74 -0
  157. package/src/server/management/link-enrollment.ts +190 -25
  158. package/src/server/management/link-route-state.ts +6 -1
  159. package/src/server/management/link-routes.ts +27 -9
  160. package/src/server/management/model-rows.ts +4 -0
  161. package/src/server/management/oauth-account-routes.ts +9 -4
  162. package/src/server/management/provider-overwrite-carry.ts +9 -2
  163. package/src/server/management/provider-routes.ts +14 -0
  164. package/src/server/management/provider-thinking-display-patch.ts +54 -0
  165. package/src/server/management/route-registry.ts +7 -0
  166. package/src/server/management/session-routes.ts +4 -1
  167. package/src/server/management/telemetry-routes.ts +37 -0
  168. package/src/server/management/usage-aggregate-cache.ts +290 -67
  169. package/src/server/management-api.ts +11 -2
  170. package/src/server/messages-native-preflight.ts +166 -0
  171. package/src/server/messages-native.ts +143 -43
  172. package/src/server/messages-shared.ts +14 -0
  173. package/src/server/proxy-liveness.ts +99 -6
  174. package/src/server/request-log-conversation.ts +18 -2
  175. package/src/server/request-log.ts +7 -2
  176. package/src/server/responses/adapter-continuation.ts +1 -0
  177. package/src/server/responses/adapter-dispatch.ts +11 -28
  178. package/src/server/responses/adapter-failure-message.ts +68 -0
  179. package/src/server/responses/combo-stream-preflight.ts +14 -2
  180. package/src/server/responses/core-auth.ts +26 -5
  181. package/src/server/responses/core-codex-account.ts +8 -1
  182. package/src/server/responses/core-combo-failure.ts +6 -1
  183. package/src/server/responses/core-combo-native.ts +150 -37
  184. package/src/server/responses/core-combo.ts +15 -9
  185. package/src/server/responses/core-normalize.ts +1 -0
  186. package/src/server/responses/core-options.ts +7 -1
  187. package/src/server/responses/core-pipeline.ts +21 -1
  188. package/src/server/responses/fetch-helpers.ts +5 -0
  189. package/src/server/responses/opengateway-completion-guard.ts +7 -3
  190. package/src/server/responses/passthrough-delivery.ts +8 -1
  191. package/src/server/responses/passthrough-error.ts +22 -0
  192. package/src/server/responses/request-prepare.ts +7 -1
  193. package/src/server/responses/request-transport.ts +28 -5
  194. package/src/server/responses/run-turn-execution.ts +13 -0
  195. package/src/server/sse-frame-buffer.ts +5 -0
  196. package/src/server/ws-bridge.ts +10 -0
  197. package/src/service/launchd.ts +78 -4
  198. package/src/telemetry/aggregate.ts +348 -0
  199. package/src/telemetry/consent.ts +128 -0
  200. package/src/telemetry/contract.ts +403 -0
  201. package/src/telemetry/disclosure.ts +19 -0
  202. package/src/telemetry/install-id.ts +226 -0
  203. package/src/telemetry/payload.ts +129 -0
  204. package/src/telemetry/profile/client.ts +150 -0
  205. package/src/telemetry/profile/contract.ts +288 -0
  206. package/src/telemetry/profile/disclosure.ts +14 -0
  207. package/src/telemetry/profile/paths.ts +13 -0
  208. package/src/telemetry/profile/routes.ts +99 -0
  209. package/src/telemetry/profile/service.ts +234 -0
  210. package/src/telemetry/profile/state.ts +189 -0
  211. package/src/telemetry/profile/sync.ts +276 -0
  212. package/src/telemetry/routes.ts +183 -0
  213. package/src/telemetry/scheduler.ts +386 -0
  214. package/src/telemetry/sender.ts +97 -0
  215. package/src/telemetry/state.ts +334 -0
  216. package/src/types/combo-jev-effort-mode.ts +11 -0
  217. package/src/types/config.ts +3 -0
  218. package/src/types/provider.ts +11 -1
  219. package/src/types/request.ts +2 -0
  220. package/src/types/telemetry.ts +15 -0
  221. package/src/types/wire.ts +10 -0
  222. package/src/types.ts +5 -0
  223. package/src/update/index.ts +7 -1
  224. package/src/update/minisign.d.mts +17 -0
  225. package/src/update/minisign.mjs +88 -0
  226. package/src/update/signed-supply.d.mts +59 -0
  227. package/src/update/signed-supply.mjs +289 -0
  228. package/src/update/trust-root.json +38 -0
  229. package/src/update/update-bounded-json.d.mts +4 -0
  230. package/src/update/update-bounded-json.mjs +113 -0
  231. package/src/update/update-bytes.d.mts +2 -0
  232. package/src/update/update-bytes.mjs +23 -0
  233. package/src/update/update-candidate-id.d.mts +2 -0
  234. package/src/update/update-candidate-id.mjs +23 -0
  235. package/src/update/update-checkpoint-codec.d.mts +33 -0
  236. package/src/update/update-checkpoint-codec.mjs +217 -0
  237. package/src/update/update-contracts.d.mts +24 -0
  238. package/src/update/update-contracts.mjs +207 -0
  239. package/src/update/update-signature-threshold.d.mts +12 -0
  240. package/src/update/update-signature-threshold.mjs +47 -0
  241. package/src/update/update-signed-version.d.mts +5 -0
  242. package/src/update/update-signed-version.mjs +25 -0
  243. package/src/update/update-trust-anchor.d.mts +2 -0
  244. package/src/update/update-trust-anchor.mjs +2 -0
  245. package/src/usage/cache-diagnostic.ts +195 -50
  246. package/src/usage/expected-prices.ts +20 -2
  247. package/src/usage/filter-index.ts +1469 -0
  248. package/src/usage/ledger-scanner.ts +245 -4
  249. package/src/usage/source-filter.ts +10 -2
  250. package/src/usage/summary.ts +16 -0
  251. package/src/web-search/parse.ts +244 -38
  252. package/gui/dist/assets/App-BepstgEN.js +0 -59
  253. package/gui/dist/assets/Tray-BinxbEZo.js +0 -1
  254. package/gui/dist/assets/index-C-9X2yaI.js +0 -94
  255. package/gui/dist/assets/index-bnUWypyz.css +0 -2
  256. package/gui/dist/classic/assets/App-DX88_GCW.js +0 -58
  257. package/gui/dist/classic/assets/index-fSP71pLB.js +0 -94
  258. package/gui/dist/classic/assets/quota-summary-y2fl0WBv.js +0 -1
@@ -0,0 +1,334 @@
1
+ import { lstatSync, mkdirSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { atomicWriteFileNoFollow } from "../config/atomic-write";
4
+ import { getConfigDir } from "../config/paths";
5
+ import { recordOwnedConfigPath } from "../lib/config-ownership";
6
+ import type { OcxConfig, OcxTelemetryConfig } from "../types";
7
+ import { parseCalendarUtcDayMs } from "./contract";
8
+ import { deleteTelemetryInstallId } from "./install-id";
9
+
10
+ /**
11
+ * `telemetry-state.json`: sent days, opt-out bookkeeping and the pending decision. Kept apart from
12
+ * the scheduler so the server's background lifecycle can record an env opt-out without loading the
13
+ * scheduler, aggregation, payload and sender modules.
14
+ */
15
+
16
+ export const TELEMETRY_STATE_FILE = "telemetry-state.json";
17
+ const DAY_MS = 86_400_000;
18
+ const STATE_RETENTION_DAYS = 30;
19
+ /**
20
+ * How often a proxy running under an env opt-out records itself again, so a state file rebuilt after
21
+ * corruption (which forgets every owner) learns that the proxy is still opted out.
22
+ */
23
+ export const TELEMETRY_ENV_OPT_OUT_REFRESH_MS = 6 * 60 * 60 * 1000;
24
+
25
+ /** A proxy that started under an env opt-out and has not stopped cleanly yet. */
26
+ export interface TelemetryEnvOptOutOwner {
27
+ pid: number;
28
+ since: string;
29
+ }
30
+ export interface TelemetryState {
31
+ version: 1;
32
+ sentDays: Record<string, string>;
33
+ lastSentDay: string | null;
34
+ lastSentAt: string | null;
35
+ ineligibleThroughDay: string | null;
36
+ retryAfterUntil: string | null;
37
+ /**
38
+ * Set whenever an env opt-out is observed and cleared only by a clean opted-out shutdown or by the
39
+ * next tick that runs without the opt-out. While it is set, every day up to the current one is
40
+ * ineligible, because a proxy started under `OCX_TELEMETRY=0` reads the env once and runs no ticks
41
+ * that could keep `ineligibleThroughDay` current (D2).
42
+ */
43
+ envOptOutActiveSince?: string | null;
44
+ /**
45
+ * Proxies running under an env opt-out. A tick without the opt-out ends the period only once all
46
+ * of them have exited, so a second proxy sharing the home cannot reopen days the first still covers.
47
+ */
48
+ envOptOutOwners?: TelemetryEnvOptOutOwner[];
49
+ /**
50
+ * A decision made before `config.json` exists (the Windows installer opt-out, `ocx telemetry
51
+ * disable` or the dashboard on a fresh install). Writing the config would turn the install into a
52
+ * configured one and make `ocx init` skip setup, so the decision waits here and applies until a
53
+ * decision is written into the config.
54
+ */
55
+ pendingDecision?: OcxTelemetryConfig | null;
56
+ /** Set once any report was accepted, so an id minted after an opt-out is not counted as a new install. */
57
+ everReported?: boolean;
58
+ }
59
+
60
+ export function telemetryStatePath(configDir = getConfigDir()): string {
61
+ return join(configDir, TELEMETRY_STATE_FILE);
62
+ }
63
+
64
+ function emptyState(): TelemetryState {
65
+ return {
66
+ version: 1,
67
+ sentDays: {},
68
+ lastSentDay: null,
69
+ lastSentAt: null,
70
+ ineligibleThroughDay: null,
71
+ retryAfterUntil: null,
72
+ envOptOutActiveSince: null,
73
+ envOptOutOwners: [],
74
+ pendingDecision: null,
75
+ everReported: false,
76
+ };
77
+ }
78
+
79
+ function parseOwners(raw: unknown): TelemetryEnvOptOutOwner[] {
80
+ if (!Array.isArray(raw)) return [];
81
+ const owners: TelemetryEnvOptOutOwner[] = [];
82
+ for (const entry of raw.slice(0, 64)) {
83
+ if (!entry || typeof entry !== "object") continue;
84
+ const { pid, since } = entry as Record<string, unknown>;
85
+ if (typeof pid === "number" && Number.isSafeInteger(pid) && pid > 0 && typeof since === "string" && !Number.isNaN(Date.parse(since))) {
86
+ owners.push({ pid, since });
87
+ }
88
+ }
89
+ return owners;
90
+ }
91
+
92
+ function ownersAreValid(raw: unknown): boolean {
93
+ return Array.isArray(raw) && raw.length <= 64 && raw.every(entry => {
94
+ if (!entry || typeof entry !== "object") return false;
95
+ const { pid, since } = entry as Record<string, unknown>;
96
+ return typeof pid === "number" && Number.isSafeInteger(pid) && pid > 0 && typeof since === "string" && !Number.isNaN(Date.parse(since));
97
+ });
98
+ }
99
+
100
+ /** A held decision that is present but cannot be trusted returns "invalid", which blocks sending. */
101
+ function parsePendingDecision(raw: unknown, fileTime: Date): OcxTelemetryConfig | null | "invalid" {
102
+ if (raw === undefined || raw === null) return null;
103
+ if (typeof raw !== "object" || Array.isArray(raw)) return "invalid";
104
+ const value = raw as Record<string, unknown>;
105
+ if (value.decision !== "accepted" && value.decision !== "declined") return "invalid";
106
+ const stamp = (key: string): string | null =>
107
+ typeof value[key] === "string" && !Number.isNaN(Date.parse(value[key] as string)) ? (value[key] as string) : null;
108
+ const decidedAt = stamp("decidedAt");
109
+ if (!decidedAt) {
110
+ // A decline needs no date to apply; dropping it could let a notice-only config send.
111
+ if (value.decision !== "declined") return "invalid";
112
+ const at = stamp("noticeShownAt") ?? fileTime.toISOString();
113
+ return { decision: "declined", decidedAt: at, noticeShownAt: at };
114
+ }
115
+ return { decision: value.decision, decidedAt, noticeShownAt: stamp("noticeShownAt") ?? decidedAt };
116
+ }
117
+
118
+ /**
119
+ * Read the state, noting whether a file exists but cannot be trusted (a symlink, oversized or
120
+ * malformed, or with an opt-out field that is present but invalid). Such a file must not be read as
121
+ * empty: that would forget opt-out days. Only a file that does not exist reads as empty.
122
+ */
123
+ export function readTelemetryStateFile(configDir = getConfigDir()): { state: TelemetryState; unreadable: boolean } {
124
+ const path = telemetryStatePath(configDir);
125
+ let stat;
126
+ try {
127
+ stat = lstatSync(path);
128
+ } catch (error) {
129
+ const missing = (error as NodeJS.ErrnoException)?.code === "ENOENT";
130
+ return { state: emptyState(), unreadable: !missing };
131
+ }
132
+ try {
133
+ if (!stat.isFile() || stat.isSymbolicLink() || stat.size > 64 * 1024) return { state: emptyState(), unreadable: true };
134
+ const raw = JSON.parse(readFileSync(path, "utf8")) as Record<string, unknown>;
135
+ if (raw?.version !== 1 || !raw.sentDays || typeof raw.sentDays !== "object" || Array.isArray(raw.sentDays)) {
136
+ return { state: emptyState(), unreadable: true };
137
+ }
138
+ const sentDays: Record<string, string> = {};
139
+ for (const [day, at] of Object.entries(raw.sentDays as Record<string, unknown>)) {
140
+ if (/^\d{4}-\d{2}-\d{2}$/.test(day) && typeof at === "string") {
141
+ sentDays[day] = at;
142
+ }
143
+ }
144
+ // Opt-out fields may be absent or null; present but invalid means the file cannot be trusted.
145
+ const present = (value: unknown) => value !== undefined && value !== null;
146
+ if (present(raw.ineligibleThroughDay)
147
+ && !(typeof raw.ineligibleThroughDay === "string" && parseCalendarUtcDayMs(raw.ineligibleThroughDay) !== null)) {
148
+ return { state: emptyState(), unreadable: true };
149
+ }
150
+ if (present(raw.envOptOutActiveSince)
151
+ && !(typeof raw.envOptOutActiveSince === "string" && !Number.isNaN(Date.parse(raw.envOptOutActiveSince)))) {
152
+ return { state: emptyState(), unreadable: true };
153
+ }
154
+ if (present(raw.envOptOutOwners) && !ownersAreValid(raw.envOptOutOwners)) {
155
+ return { state: emptyState(), unreadable: true };
156
+ }
157
+ const pendingDecision = parsePendingDecision(raw.pendingDecision, stat.mtime);
158
+ if (pendingDecision === "invalid") return { state: emptyState(), unreadable: true };
159
+ const ineligibleThroughDay = typeof raw.ineligibleThroughDay === "string" ? raw.ineligibleThroughDay : null;
160
+ const retryAfterUntil =
161
+ typeof raw.retryAfterUntil === "string" && !Number.isNaN(Date.parse(raw.retryAfterUntil))
162
+ ? raw.retryAfterUntil
163
+ : null;
164
+ const envOptOutActiveSince = typeof raw.envOptOutActiveSince === "string" ? raw.envOptOutActiveSince : null;
165
+ return { unreadable: false, state: {
166
+ version: 1,
167
+ sentDays,
168
+ lastSentDay: typeof raw.lastSentDay === "string" ? raw.lastSentDay : null,
169
+ lastSentAt: typeof raw.lastSentAt === "string" ? raw.lastSentAt : null,
170
+ ineligibleThroughDay,
171
+ retryAfterUntil,
172
+ envOptOutActiveSince,
173
+ envOptOutOwners: parseOwners(raw.envOptOutOwners),
174
+ pendingDecision,
175
+ everReported: raw.everReported === true,
176
+ } };
177
+ } catch {
178
+ return { state: emptyState(), unreadable: true };
179
+ }
180
+ }
181
+
182
+ export function readTelemetryState(configDir = getConfigDir()): TelemetryState {
183
+ return readTelemetryStateFile(configDir).state;
184
+ }
185
+
186
+ /**
187
+ * Read the state for a rewrite. A file that exists but cannot be read may have held opt-out days
188
+ * or sent days and opted-out proxies that are still running, so the rewrite starts from "nothing
189
+ * may be sent through the UTC day those proxies have recorded themselves again by".
190
+ */
191
+ function readTelemetryStateForWrite(configDir: string, now: number): TelemetryState {
192
+ const { state, unreadable } = readTelemetryStateFile(configDir);
193
+ if (unreadable) extendIneligibleThroughToday(state, now + TELEMETRY_ENV_OPT_OUT_REFRESH_MS);
194
+ return state;
195
+ }
196
+
197
+ export function writeTelemetryState(state: TelemetryState, configDir = getConfigDir(), now = Date.now()): void {
198
+ mkdirSync(configDir, { recursive: true, mode: 0o700 });
199
+ const path = telemetryStatePath(configDir);
200
+ try { recordOwnedConfigPath(configDir, path); } catch { /* best-effort */ }
201
+ const minKeepDay = formatUtcDay(utcMidnightMs(now) - STATE_RETENTION_DAYS * DAY_MS);
202
+ const prunedSentDays: Record<string, string> = {};
203
+ for (const [day, at] of Object.entries(state.sentDays ?? {})) {
204
+ if (day >= minKeepDay) prunedSentDays[day] = at;
205
+ }
206
+ const payload: TelemetryState = {
207
+ version: 1,
208
+ sentDays: prunedSentDays,
209
+ lastSentDay: state.lastSentDay ?? null,
210
+ lastSentAt: state.lastSentAt ?? null,
211
+ ineligibleThroughDay: state.ineligibleThroughDay ?? null,
212
+ retryAfterUntil: state.retryAfterUntil ?? null,
213
+ envOptOutActiveSince: state.envOptOutActiveSince ?? null,
214
+ envOptOutOwners: state.envOptOutOwners ?? [],
215
+ pendingDecision: state.pendingDecision ?? null,
216
+ everReported: state.everReported === true,
217
+ };
218
+ atomicWriteFileNoFollow(path, `${JSON.stringify(payload, null, 2)}\n`);
219
+ }
220
+
221
+ /** Hold a decision made before `config.json` exists. */
222
+ export function recordPendingTelemetryDecision(
223
+ decision: OcxTelemetryConfig,
224
+ configDir = getConfigDir(),
225
+ now = Date.now(),
226
+ ): void {
227
+ const state = readTelemetryStateForWrite(configDir, now);
228
+ state.pendingDecision = structuredClone(decision);
229
+ writeTelemetryState(state, configDir, now);
230
+ }
231
+
232
+ /**
233
+ * Drop the pending decision once a decision is written into `config.json`. A person's decision also
234
+ * rebuilds an unreadable state file, which otherwise pauses sending for good.
235
+ */
236
+ export function clearPendingTelemetryDecision(configDir = getConfigDir(), now = Date.now()): void {
237
+ const { state: current, unreadable } = readTelemetryStateFile(configDir);
238
+ if (unreadable) {
239
+ // Best effort: the decision is already saved. If the rebuild fails, the file stays unreadable,
240
+ // which keeps sending blocked.
241
+ try {
242
+ const rebuilt = readTelemetryStateForWrite(configDir, now);
243
+ rebuilt.pendingDecision = null;
244
+ writeTelemetryState(rebuilt, configDir, now);
245
+ } catch { /* keep the unreadable file */ }
246
+ return;
247
+ }
248
+ if (!current.pendingDecision) return;
249
+ current.pendingDecision = null;
250
+ writeTelemetryState(current, configDir, now);
251
+ }
252
+
253
+ /**
254
+ * The telemetry block consent is resolved from: the config's own decision when it has one,
255
+ * otherwise a decision held from before `config.json` existed, otherwise whatever the config says.
256
+ */
257
+ export function withPendingTelemetryDecision<T extends Pick<OcxConfig, "telemetry">>(
258
+ config: T | null | undefined,
259
+ configDir = getConfigDir(),
260
+ ): Pick<OcxConfig, "telemetry"> | null | undefined {
261
+ if (config?.telemetry?.decision) return config;
262
+ const pending = readTelemetryState(configDir).pendingDecision;
263
+ if (!pending) return config;
264
+ return { ...(config ?? {}), telemetry: structuredClone(pending) };
265
+ }
266
+
267
+ function isProcessAlive(pid: number): boolean {
268
+ try {
269
+ process.kill(pid, 0);
270
+ return true;
271
+ } catch (error) {
272
+ return (error as NodeJS.ErrnoException)?.code === "EPERM";
273
+ }
274
+ }
275
+
276
+ function extendIneligibleThroughToday(state: TelemetryState, now: number): void {
277
+ const todayDay = formatUtcDay(utcMidnightMs(now));
278
+ if (!state.ineligibleThroughDay || state.ineligibleThroughDay < todayDay) {
279
+ state.ineligibleThroughDay = todayDay;
280
+ }
281
+ }
282
+
283
+ /**
284
+ * Persist `ineligibleThroughDay = today's UTC day` and the active opt-out marker in
285
+ * `telemetry-state.json` (atomic no-follow) and delete `telemetry-id.json` whenever an
286
+ * `OCX_TELEMETRY` or `DO_NOT_TRACK` opt-out is observed. A proxy that runs under the opt-out
287
+ * passes its pid as `owner`; a one-off observation (a CLI command, a tick) passes none.
288
+ */
289
+ export function recordTelemetryEnvOptOut(configDir = getConfigDir(), now = Date.now(), owner?: number): void {
290
+ const state = readTelemetryStateForWrite(configDir, now);
291
+ extendIneligibleThroughToday(state, now);
292
+ if (owner === undefined) {
293
+ state.envOptOutActiveSince ??= new Date(now).toISOString();
294
+ } else {
295
+ // Drop owners that have exited (their days through today are covered above) and stay within the
296
+ // 64 entries a reader accepts.
297
+ const owners = (state.envOptOutOwners ?? [])
298
+ .filter(entry => entry.pid !== owner && isProcessAlive(entry.pid))
299
+ .slice(-63);
300
+ state.envOptOutOwners = [...owners, { pid: owner, since: new Date(now).toISOString() }];
301
+ }
302
+ writeTelemetryState(state, configDir, now);
303
+ deleteTelemetryInstallId(configDir);
304
+ }
305
+
306
+ /**
307
+ * Close an env opt-out period so only days strictly after today can be sent. A clean stop of an
308
+ * opted-out proxy passes its pid and always covers its stop day. A tick passes none: it ends the
309
+ * period only when no recorded opted-out proxy is still running, and otherwise extends
310
+ * `ineligibleThroughDay` to today. Returns true while an opted-out proxy is still running.
311
+ */
312
+ export function endTelemetryEnvOptOut(configDir = getConfigDir(), now = Date.now(), owner?: number): boolean {
313
+ const state = readTelemetryStateForWrite(configDir, now);
314
+ const recorded = state.envOptOutOwners ?? [];
315
+ const others = owner === undefined ? recorded : recorded.filter(entry => entry.pid !== owner);
316
+ const running = others.filter(entry => isProcessAlive(entry.pid));
317
+ if (owner === undefined && !state.envOptOutActiveSince && recorded.length === 0) return false;
318
+ extendIneligibleThroughToday(state, now);
319
+ state.envOptOutOwners = running;
320
+ if (running.length === 0) state.envOptOutActiveSince = null;
321
+ writeTelemetryState(state, configDir, now);
322
+ deleteTelemetryInstallId(configDir);
323
+ return running.length > 0;
324
+ }
325
+
326
+
327
+ export function utcMidnightMs(epochMs: number): number {
328
+ const d = new Date(epochMs);
329
+ return Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
330
+ }
331
+
332
+ export function formatUtcDay(epochMs: number): string {
333
+ return new Date(epochMs).toISOString().slice(0, 10);
334
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Who owns the wire effort on a JEV combo (`jevEffortMode` in config.json).
3
+ *
4
+ * `decide` (default) lets the decision set the effort and override the caller, which is what
5
+ * a capability-routing combo wants. `client` takes only the decision's target choice and
6
+ * leaves effort to ordinary Combo policy (caller effort, target ladder, `defaultEffort` and
7
+ * `defaultEffortMode`), for providers that must hold one tier to keep their prompt cache
8
+ * warm: one whose effort swaps the upstream model id per tier pays a cache miss on every
9
+ * re-tier. Rationale: `structure/decisions/ADR-8041-jev-effort-mode.md`.
10
+ */
11
+ export type OcxComboJevEffortMode = "decide" | "client";
@@ -3,6 +3,7 @@ import type { CodexAccount } from "./accounts";
3
3
  import type { AnthropicAccountPoolConfig, OcxAccountPoolRotationStrategy } from "./anthropic-account-pool";
4
4
  import type { AnthropicInstanceId } from "../providers/anthropic-instance-id";
5
5
  import type { OcxFallbackConfig } from "./fallback";
6
+ import type { OcxTelemetryConfig } from "./telemetry";
6
7
  export type { AnthropicAccountPoolConfig, AnthropicModelRoute, OcxAccountPoolRotationStrategy, OcxAccountPoolQuotaWindow } from "./anthropic-account-pool";
7
8
  export type { OcxFallbackConfig, OcxFallbackDeviceConfig, OcxFallbackKind, OcxFallbackSwitches } from "./fallback";
8
9
 
@@ -574,6 +575,7 @@ export interface OcxConfig {
574
575
  skills?: OcxSkillsConfig;
575
576
  /** Opt-in process-local aggregate request metrics on the authenticated management plane. */
576
577
  metricsExport?: { enabled?: boolean };
578
+ telemetry?: OcxTelemetryConfig;
577
579
  /**
578
580
  * Opt-in recovery of a managed service proxy that stays alive but stops answering /healthz:
579
581
  * a separate sentinel process terminates it so its supervisor restarts it (#6671).
@@ -1538,6 +1540,7 @@ export interface OcxComboConfig {
1538
1540
  * explicitly empty target ladder suppresses the whole combo's effort control.
1539
1541
  */
1540
1542
  reasoningEffortMode?: OcxComboReasoningEffortMode;
1543
+ jevEffortMode?: import("./combo-jev-effort-mode").OcxComboJevEffortMode; // wire-effort owner on a `jev` combo; omitted = "decide"
1541
1544
  /**
1542
1545
  * Disable image input even when every target supports it.
1543
1546
  * Omitted / `"auto"` keeps automatic capability derivation (default: enabled when
@@ -1,4 +1,4 @@
1
- import type { UpstreamHttpVersion, ReasoningSummaryDelivery, CodexAccountMode } from "./wire";
1
+ import type { UpstreamHttpVersion, ReasoningSummaryDelivery, CodexAccountMode, ThinkingDisplayPolicy } from "./wire";
2
2
  import type { AccountAutoPausePolicy, AccountPauseDetails } from "./account-auto-pause";
3
3
  import type { AnthropicAccountPoolConfig } from "./anthropic-account-pool";
4
4
 
@@ -490,6 +490,8 @@ export interface OcxProviderConfig {
490
490
  * reasoning output items when they are sent back on a continuation.
491
491
  */
492
492
  dropResponsesReasoningItems?: boolean;
493
+ /** Exact Ark Kimi endpoint IDs requiring the narrow stateless Responses replay projection. */
494
+ arkKimiResponsesModels?: string[];
493
495
  /**
494
496
  * Explicit opt-in for a relay that genuinely fronts OpenAI and can decode native
495
497
  * compaction blobs. Absent or false degrades foreign blobs to an opaque note.
@@ -841,6 +843,14 @@ export interface OcxProviderConfig {
841
843
  * Presence also advertises reasoning-summary support for that routed model.
842
844
  */
843
845
  modelReasoningSummaryDelivery?: Record<string, ReasoningSummaryDelivery>;
846
+ /**
847
+ * Anthropic adaptive `thinking.display` policy for this provider (#8363). `auto` and omission
848
+ * keep the built-in selection: native Opus 5.5 progress updates, summarized thinking elsewhere.
849
+ * `updates` is only sendable to native Opus 5.5 and degrades to `auto` for other models.
850
+ */
851
+ thinkingDisplay?: ThinkingDisplayPolicy;
852
+ /** Per-model override of `thinkingDisplay`, keyed by the exact upstream model id. */
853
+ modelThinkingDisplay?: Record<string, ThinkingDisplayPolicy>;
844
854
  /**
845
855
  * Exact-model hosted tools that win collisions with Codex client tool declarations.
846
856
  * Use for non-forward Responses gateways that reserve a hosted tool namespace server-side.
@@ -67,6 +67,8 @@ export interface OcxParsedRequest {
67
67
  stream: boolean;
68
68
  options: OcxRequestOptions;
69
69
  _rawBody?: unknown;
70
+ /** Trusted ingress provenance: preserve Chat's tool defaults only on the final Responses wire. */
71
+ _chatCompletionsInput?: boolean;
70
72
  /** Claude replay tags, retained only until each route binding verifies them. */
71
73
  _nativeReasoningReplay?: ReadonlyMap<string, string>;
72
74
  _nativeReasoningBoundOwner?: NativeReasoningOwner;
@@ -0,0 +1,15 @@
1
+ export type OcxTelemetryDecision = "accepted" | "declined";
2
+
3
+ /**
4
+ * Anonymous product telemetry consent state.
5
+ *
6
+ * Absence of `decision` means undecided. No payload is sent until either `decision` is
7
+ * `"accepted"` or a human has seen the disclosure (`noticeShownAt` recorded via interactive
8
+ * TTY or dashboard consent session). The collector endpoint is a code constant and is never
9
+ * persisted here.
10
+ */
11
+ export interface OcxTelemetryConfig {
12
+ decision?: OcxTelemetryDecision;
13
+ decidedAt?: string;
14
+ noticeShownAt?: string;
15
+ }
package/src/types/wire.ts CHANGED
@@ -25,6 +25,16 @@ export const REASONING_SUMMARY_DELIVERY_VALUES = [
25
25
 
26
26
  export type ReasoningSummaryDelivery = typeof REASONING_SUMMARY_DELIVERY_VALUES[number];
27
27
 
28
+ /**
29
+ * Anthropic adaptive `thinking.display` policy (#8363). `auto` is the built-in behavior:
30
+ * native Opus 5.5 progress updates, summarized thinking elsewhere unless the caller hides it.
31
+ * `updates` is only sendable to native Opus 5.5 and degrades to `auto` for every other model.
32
+ * `omitted` sends adaptive thinking with no display field, matching hidden thinking.
33
+ */
34
+ export const THINKING_DISPLAY_VALUES = ["auto", "summarized", "updates", "omitted"] as const;
35
+
36
+ export type ThinkingDisplayPolicy = (typeof THINKING_DISPLAY_VALUES)[number];
37
+
28
38
  /** Trusted runtime ownership for Codex-account credentials. Never persisted per provider. */
29
39
  export type CodexAccountMode = "direct" | "pool";
30
40
 
package/src/types.ts CHANGED
@@ -24,12 +24,15 @@ export {
24
24
  } from "./types/tools";
25
25
 
26
26
  export type { UpstreamHttpVersion, ReasoningSummaryDelivery, CodexAccountMode } from "./types/wire";
27
+ export type { ThinkingDisplayPolicy } from "./types/wire";
27
28
  export type { AnthropicInstanceId } from "./providers/anthropic-instance-id";
28
29
  export { ANTHROPIC_INSTANCE_IDS, ANTHROPIC_PRIMARY_INSTANCE, ANTHROPIC_POOL2_INSTANCE, isAnthropicInstanceId } from "./providers/anthropic-instance-id";
29
30
  export type { AnthropicAccountPoolConfig, AnthropicModelRoute } from "./types/anthropic-account-pool";
31
+ export type { OcxComboJevEffortMode } from "./types/combo-jev-effort-mode";
30
32
  export {
31
33
  UPSTREAM_HTTP_VERSION_VALUES,
32
34
  REASONING_SUMMARY_DELIVERY_VALUES,
35
+ THINKING_DISPLAY_VALUES,
33
36
  OPENAI_PROVIDER_TIER_VERSION,
34
37
  MODEL_ADAPTER_OVERRIDE_ALLOWED,
35
38
  captureWireAdapterHardPins,
@@ -146,3 +149,5 @@ export type {
146
149
  CodexAccountCredentials,
147
150
  CodexAccountCredentialRecord,
148
151
  } from "./types/accounts";
152
+
153
+ export type { OcxTelemetryConfig, OcxTelemetryDecision } from "./types/telemetry";
@@ -364,7 +364,13 @@ export function updateCommand(installer: Installer, tag: Channel, resolvedVersio
364
364
  return { bin: "pnpm", args: ["add", "-g", "--allow-build=bun", `${PKG}@${target}`] };
365
365
  }
366
366
  const bin = "npm";
367
- const args = ["install", "-g", `${PKG}@${target}`];
367
+ // npm 12 blocks dependency lifecycle scripts by default, and bun's postinstall is what
368
+ // copies the selected @oven/bun-* executable into bun/bin. Without this narrow approval
369
+ // the install succeeds but leaves bun's un-downloaded placeholder, so the next `ocx`
370
+ // cannot start (#8361). npm 6 through 11 run bun's postinstall anyway and install with the
371
+ // flag on global installs, so it is unconditional rather than version-gated; some npm 11
372
+ // releases print an "Unknown cli config" warning for it and still install.
373
+ const args = ["install", "-g", "--allow-scripts=bun", `${PKG}@${target}`];
368
374
  return { bin, args };
369
375
  }
370
376
 
@@ -0,0 +1,17 @@
1
+ import type { KeyObject } from "node:crypto";
2
+
3
+ export interface MinisignKey {
4
+ keyId: string;
5
+ publicKey: KeyObject;
6
+ fingerprint: string;
7
+ }
8
+
9
+ export interface MinisignVerification {
10
+ keyId: string;
11
+ fingerprint: string;
12
+ trustedComment: string;
13
+ }
14
+
15
+ export function decodePublicKey(text: string): MinisignKey;
16
+ export function verifyMinisignBytes(bytes: Uint8Array, signatureBox: string, key: MinisignKey): MinisignVerification;
17
+ export function verifyLegacyMinisignBytes(bytes: Uint8Array, signatureBox: string, key: Pick<MinisignKey, "keyId" | "publicKey">): Omit<MinisignVerification, "fingerprint">;
@@ -0,0 +1,88 @@
1
+ // Offline minisign primitives. These results prove only cryptographic validity;
2
+ // update authority is assigned separately by the signed-supply policy.
3
+ import { createHash, createPublicKey, verify } from "node:crypto";
4
+ import { snapshotUpdateBytes } from "./update-bytes.mjs";
5
+
6
+ const ED25519_SPKI_PREFIX = Buffer.from("302a300506032b6570032100", "hex");
7
+ const TRUSTED_PREFIX = "trusted comment: ";
8
+
9
+ function decodeBase64(text, what, expectedBytes) {
10
+ const payload = Buffer.from(text, "base64");
11
+ if (!text || payload.toString("base64") !== text
12
+ || (expectedBytes !== undefined && payload.length !== expectedBytes)) {
13
+ throw new Error(`Malformed ${what}: invalid base64 or decoded length`);
14
+ }
15
+ return payload;
16
+ }
17
+
18
+ function boxLines(text) {
19
+ return text.replace(/\r\n/g, "\n").replace(/\n$/, "").split("\n");
20
+ }
21
+
22
+ /** Decode the text form of a minisign public key; this does not establish trust. */
23
+ export function decodePublicKey(text) {
24
+ const lines = boxLines(text);
25
+ if (lines.length !== 2 || !lines[0].startsWith("untrusted comment: ")) {
26
+ throw new Error("Malformed minisign public key box");
27
+ }
28
+ const packet = decodeBase64(lines[1], "minisign public key", 42);
29
+ const algorithm = packet.subarray(0, 2).toString("utf8");
30
+ if (algorithm !== "Ed") {
31
+ throw new Error(`Unsupported minisign public key algorithm: ${JSON.stringify(algorithm)}`);
32
+ }
33
+ const raw = packet.subarray(10);
34
+ return Object.freeze({
35
+ keyId: packet.subarray(2, 10).toString("hex"),
36
+ publicKey: createPublicKey({ key: Buffer.concat([ED25519_SPKI_PREFIX, raw]), format: "der", type: "spki" }),
37
+ fingerprint: createHash("sha256").update(raw).digest("hex"),
38
+ });
39
+ }
40
+
41
+ function verifyBox(bytes, signatureBox, key, legacy) {
42
+ // The historical release adapter accepts surrounding transport whitespace.
43
+ const outer = legacy ? signatureBox.trim() : signatureBox;
44
+ if (!legacy && outer.length > 5464) throw new Error("Malformed Tauri signature: box exceeds limit");
45
+ const encoded = decodeBase64(outer, "Tauri signature");
46
+ if (!legacy && encoded.length > 4096) throw new Error("Malformed Tauri signature: box exceeds limit");
47
+ const text = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(encoded);
48
+ const lines = boxLines(text);
49
+ if (lines.length !== 4 || !lines[0].startsWith("untrusted comment: ")
50
+ || !lines[2].startsWith(TRUSTED_PREFIX)) {
51
+ throw new Error("Malformed signature box");
52
+ }
53
+ const packet = decodeBase64(lines[1], "signature packet", 74);
54
+ const commentSignature = decodeBase64(lines[3], "comment signature", 64);
55
+ const algorithm = packet.subarray(0, 2).toString("utf8");
56
+ if (algorithm !== "ED") throw new Error(`Unsupported signature algorithm: ${JSON.stringify(algorithm)}`);
57
+ const keyId = packet.subarray(2, 10).toString("hex");
58
+ const expectedKeyId = key.keyId;
59
+ if (keyId !== expectedKeyId) throw new Error(`Signature was made by key ${keyId}, not the pinned updater key ${expectedKeyId}`);
60
+ // Capture one public-key representation, then reconstruct a private verifier
61
+ // so caller-controlled accessors cannot change the signer between checks.
62
+ let publicKeyDer;
63
+ try { publicKeyDer = snapshotUpdateBytes(key.publicKey.export({ format: "der", type: "spki" }), 44); }
64
+ catch { throw new Error("Malformed minisign public key"); }
65
+ if (publicKeyDer.length !== 44 || !Buffer.from(publicKeyDer.subarray(0, 12)).equals(ED25519_SPKI_PREFIX)) {
66
+ throw new Error("Malformed minisign public key");
67
+ }
68
+ const publicKey = createPublicKey({ key: Buffer.from(publicKeyDer), format: "der", type: "spki" });
69
+ const signature = packet.subarray(10);
70
+ const digest = createHash("blake2b512").update(bytes).digest();
71
+ if (!verify(null, digest, publicKey, signature)) throw new Error("Signature verification failed");
72
+ const exactComment = lines[2].slice(TRUSTED_PREFIX.length);
73
+ const trustedComment = legacy ? exactComment.trim() : exactComment;
74
+ const message = Buffer.concat([signature, Buffer.from(trustedComment, "utf8")]);
75
+ if (!verify(null, message, publicKey, commentSignature)) throw new Error("Comment signature verification failed");
76
+ const fingerprint = createHash("sha256").update(publicKeyDer.subarray(-32)).digest("hex");
77
+ return { keyId, fingerprint, trustedComment };
78
+ }
79
+
80
+ /** Verify both signatures using the exact trusted-comment bytes. */
81
+ export function verifyMinisignBytes(bytes, signatureBox, key) {
82
+ return verifyBox(bytes, signatureBox, key, false);
83
+ }
84
+
85
+ /** Compatibility-only adapter for the existing release verifier's trimmed comment. */
86
+ export function verifyLegacyMinisignBytes(bytes, signatureBox, key) {
87
+ return verifyBox(bytes, signatureBox, key, true);
88
+ }
@@ -0,0 +1,59 @@
1
+ declare const rootEvidence: unique symbol;
2
+ declare const rootTransition: unique symbol;
3
+ declare const releaseEvidence: unique symbol;
4
+ declare const targetEvidence: unique symbol;
5
+ declare const artifactEvidence: unique symbol;
6
+ declare const receiptEvidence: unique symbol;
7
+ declare const treeEvidence: unique symbol;
8
+ declare const capabilityEvidence: unique symbol;
9
+
10
+ /** In-process module-owned root handle; parsing a document does not create one. */
11
+ export interface RootEvidence { readonly [rootEvidence]: never }
12
+ export interface VerifiedRootTransition { readonly [rootTransition]: never }
13
+ export type RootBasis = RootEvidence | VerifiedRootTransition;
14
+ export interface ReleaseEvidence { readonly [releaseEvidence]: never }
15
+ export interface TargetEvidence { readonly [targetEvidence]: never; readonly candidateId: string }
16
+ export interface ArtifactEvidence { readonly [artifactEvidence]: never }
17
+ export interface ReceiptEvidence { readonly [receiptEvidence]: never }
18
+ export interface TreeEvidence { readonly [treeEvidence]: never }
19
+ export interface CapabilityEvidence { readonly [capabilityEvidence]: never }
20
+ export interface TransitionSummary { readonly predecessorDigest: string; readonly predecessorRevision: number; readonly successorDigest: string; readonly successorRevision: number }
21
+ export interface UpdateSelection {
22
+ platform: "macos" | "linux" | "windows";
23
+ arch: "x64" | "arm64";
24
+ owner: "desktop" | "npm" | "pnpm" | "bun" | "standalone";
25
+ artifactKind: "tauri" | "tree" | "standalone" | "guardian";
26
+ bundleKind: "app-tar-gz" | "msi" | "appimage" | "deb" | "zip" | "tar-gz" | "binary";
27
+ }
28
+ /** Detached diagnostic data; none of these shapes is an evidence handle. */
29
+ export interface SnapshotBasis { readonly basisDigest: string; readonly basisRevision: number }
30
+ export interface SnapshotTargetBinding extends SnapshotBasis { readonly releaseDigest: string; readonly targetId: string; readonly candidateId: string }
31
+ export interface RootEvidenceSnapshot { readonly kind: "root"; readonly rootBytes: Uint8Array; readonly rootDigest: string; readonly rootRevision: number; readonly anchorDigest: string }
32
+ export interface TransitionEvidenceSnapshot { readonly kind: "transition"; readonly rootBytes: Uint8Array; readonly envelopeBytes: Uint8Array; readonly rootDigest: string; readonly rootRevision: number; readonly predecessorDigest: string; readonly predecessorRevision: number }
33
+ export interface ReleaseEvidenceSnapshot extends SnapshotBasis { readonly kind: "release"; readonly releaseBytes: Uint8Array; readonly envelopeBytes: Uint8Array; readonly releaseDigest: string; readonly channel: "latest" | "preview" | "nightly" }
34
+ export interface TargetEvidenceSnapshot extends SnapshotTargetBinding { readonly kind: "target"; readonly selection: Readonly<UpdateSelection> }
35
+ export interface ArtifactEvidenceSnapshot extends SnapshotTargetBinding { readonly kind: "artifact"; readonly artifactDigest: string; readonly artifactSize: number; readonly signatureBox: string; readonly signerFingerprint: string }
36
+ export interface ReceiptEvidenceSnapshot extends SnapshotTargetBinding { readonly kind: "receipt"; readonly receiptBytes: Uint8Array; readonly receiptDigest: string; readonly receiptSize: number }
37
+ export interface TreeEvidenceSnapshot extends SnapshotTargetBinding { readonly kind: "tree"; readonly treeBytes: Uint8Array; readonly envelopeBytes: Uint8Array; readonly treeDigest: string; readonly treeSize: number; readonly envelopeDigest: string; readonly envelopeSize: number; readonly receiptDigest: string }
38
+ export interface CapabilityEvidenceSnapshot extends SnapshotTargetBinding { readonly kind: "capability"; readonly capabilityBytes: Uint8Array; readonly capabilityDigest: string; readonly capabilitySize: number; readonly receiptDigest: string }
39
+ export type EvidenceHandle = RootBasis | ReleaseEvidence | TargetEvidence | ArtifactEvidence | ReceiptEvidence | TreeEvidence | CapabilityEvidence;
40
+ export type EvidenceSnapshot = RootEvidenceSnapshot | TransitionEvidenceSnapshot | ReleaseEvidenceSnapshot | TargetEvidenceSnapshot | ArtifactEvidenceSnapshot | ReceiptEvidenceSnapshot | TreeEvidenceSnapshot | CapabilityEvidenceSnapshot;
41
+
42
+ export function bootstrapEmbeddedRoot(bytes: Uint8Array, nowMs: number): RootEvidence;
43
+ export function verifyRootTransition(predecessorBasis: RootBasis, bytes: Uint8Array, envelopeBytes: Uint8Array, nowMs: number): VerifiedRootTransition;
44
+ export function inspectTransition(transition: VerifiedRootTransition): TransitionSummary;
45
+ export function verifyReleaseEvidence(bytes: Uint8Array, envelopeBytes: Uint8Array, rootBasis: RootBasis, expectedChannel: "latest" | "preview" | "nightly", nowMs: number): ReleaseEvidence;
46
+ export function selectTargetEvidence(releaseEvidence: ReleaseEvidence, selection: UpdateSelection): TargetEvidence;
47
+ export function verifyArtifactEvidence(target: TargetEvidence, bytes: Uint8Array, basis: RootBasis, nowMs: number): ArtifactEvidence;
48
+ export function verifyExternalMetadataEvidence(target: TargetEvidence, input: { kind: "receipt"; bytes: Uint8Array }, basis: RootBasis, nowMs: number): ReceiptEvidence;
49
+ export function verifyExternalMetadataEvidence(target: TargetEvidence, input: { kind: "tree"; bytes: Uint8Array; signatureEnvelopeBytes: Uint8Array; receiptEvidence: ReceiptEvidence }, basis: RootBasis, nowMs: number): TreeEvidence;
50
+ export function verifyExternalMetadataEvidence(target: TargetEvidence, input: { kind: "capability"; bytes: Uint8Array; receiptEvidence: ReceiptEvidence }, basis: RootBasis, nowMs: number): CapabilityEvidence;
51
+ export function snapshotEvidence(handle: RootEvidence): RootEvidenceSnapshot;
52
+ export function snapshotEvidence(handle: VerifiedRootTransition): TransitionEvidenceSnapshot;
53
+ export function snapshotEvidence(handle: ReleaseEvidence): ReleaseEvidenceSnapshot;
54
+ export function snapshotEvidence(handle: TargetEvidence): TargetEvidenceSnapshot;
55
+ export function snapshotEvidence(handle: ArtifactEvidence): ArtifactEvidenceSnapshot;
56
+ export function snapshotEvidence(handle: ReceiptEvidence): ReceiptEvidenceSnapshot;
57
+ export function snapshotEvidence(handle: TreeEvidence): TreeEvidenceSnapshot;
58
+ export function snapshotEvidence(handle: CapabilityEvidence): CapabilityEvidenceSnapshot;
59
+ export function snapshotEvidence(handle: EvidenceHandle): EvidenceSnapshot;