@tormentalabs/claude-code-wire-compat 0.1.0-rc.10

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 (85) hide show
  1. package/CHANGELOG.md +312 -0
  2. package/LICENSE +674 -0
  3. package/NOTICE +16 -0
  4. package/README.md +39 -0
  5. package/dist/anti-verbosity.d.ts +58 -0
  6. package/dist/anti-verbosity.d.ts.map +1 -0
  7. package/dist/anti-verbosity.js +174 -0
  8. package/dist/anti-verbosity.js.map +1 -0
  9. package/dist/beta-registry.d.ts +119 -0
  10. package/dist/beta-registry.d.ts.map +1 -0
  11. package/dist/beta-registry.js +125 -0
  12. package/dist/beta-registry.js.map +1 -0
  13. package/dist/betas.d.ts +11 -0
  14. package/dist/betas.d.ts.map +1 -0
  15. package/dist/betas.js +68 -0
  16. package/dist/betas.js.map +1 -0
  17. package/dist/build-request.d.ts +24 -0
  18. package/dist/build-request.d.ts.map +1 -0
  19. package/dist/build-request.js +1008 -0
  20. package/dist/build-request.js.map +1 -0
  21. package/dist/contracts.d.ts +717 -0
  22. package/dist/contracts.d.ts.map +1 -0
  23. package/dist/contracts.js +36 -0
  24. package/dist/contracts.js.map +1 -0
  25. package/dist/count-tokens.d.ts +42 -0
  26. package/dist/count-tokens.d.ts.map +1 -0
  27. package/dist/count-tokens.js +61 -0
  28. package/dist/count-tokens.js.map +1 -0
  29. package/dist/fingerprint.d.ts +4 -0
  30. package/dist/fingerprint.d.ts.map +1 -0
  31. package/dist/fingerprint.js +59 -0
  32. package/dist/fingerprint.js.map +1 -0
  33. package/dist/headers.d.ts +4 -0
  34. package/dist/headers.d.ts.map +1 -0
  35. package/dist/headers.js +255 -0
  36. package/dist/headers.js.map +1 -0
  37. package/dist/index.d.ts +17 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +6 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/metadata.d.ts +4 -0
  42. package/dist/metadata.d.ts.map +1 -0
  43. package/dist/metadata.js +192 -0
  44. package/dist/metadata.js.map +1 -0
  45. package/dist/model-capabilities.d.ts +103 -0
  46. package/dist/model-capabilities.d.ts.map +1 -0
  47. package/dist/model-capabilities.js +263 -0
  48. package/dist/model-capabilities.js.map +1 -0
  49. package/dist/model-identity.d.ts +11 -0
  50. package/dist/model-identity.d.ts.map +1 -0
  51. package/dist/model-identity.js +64 -0
  52. package/dist/model-identity.js.map +1 -0
  53. package/dist/models.d.ts +9 -0
  54. package/dist/models.d.ts.map +1 -0
  55. package/dist/models.js +25 -0
  56. package/dist/models.js.map +1 -0
  57. package/dist/profiles/claude-code-2.1.195.d.ts +3 -0
  58. package/dist/profiles/claude-code-2.1.195.d.ts.map +1 -0
  59. package/dist/profiles/claude-code-2.1.195.js +150 -0
  60. package/dist/profiles/claude-code-2.1.195.js.map +1 -0
  61. package/dist/redaction.d.ts +16 -0
  62. package/dist/redaction.d.ts.map +1 -0
  63. package/dist/redaction.js +364 -0
  64. package/dist/redaction.js.map +1 -0
  65. package/dist/request-body.d.ts +19 -0
  66. package/dist/request-body.d.ts.map +1 -0
  67. package/dist/request-body.js +1658 -0
  68. package/dist/request-body.js.map +1 -0
  69. package/dist/sha256.d.ts +9 -0
  70. package/dist/sha256.d.ts.map +1 -0
  71. package/dist/sha256.js +104 -0
  72. package/dist/sha256.js.map +1 -0
  73. package/dist/system-prompt.d.ts +4 -0
  74. package/dist/system-prompt.d.ts.map +1 -0
  75. package/dist/system-prompt.js +157 -0
  76. package/dist/system-prompt.js.map +1 -0
  77. package/dist/thinking.d.ts +91 -0
  78. package/dist/thinking.d.ts.map +1 -0
  79. package/dist/thinking.js +132 -0
  80. package/dist/thinking.js.map +1 -0
  81. package/dist/unicode.d.ts +10 -0
  82. package/dist/unicode.d.ts.map +1 -0
  83. package/dist/unicode.js +19 -0
  84. package/dist/unicode.js.map +1 -0
  85. package/package.json +72 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,312 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [0.1.0-rc.10] - Unreleased
6
+
7
+ This release rebuilds the request model against the genuine client's own
8
+ predicates rather than against a reimplementation of them. Several `0.1.0-rc.9`
9
+ decisions are reversed below; where they are, the reversal is the corrected one.
10
+
11
+ ### Removed
12
+
13
+ - `UNSUPPORTED_MODEL` and the hand-written alias table. The genuine client never
14
+ rejects a model identifier: it lowercases the string, runs an ordered
15
+ `includes()` chain to classify it, and sends the caller's string on the wire.
16
+ Rejecting `claude-sonnet-4-5-20250929` and silently rewriting `opus-4.5` onto
17
+ `claude-opus-4-5` were both divergences, and the rewrite put a different
18
+ identifier on the wire than the caller asked for.
19
+ - `contextHint` from `ClaudeCodeCapabilities`. It was never a model capability
20
+ upstream — the client gates it on host state and a feature flag, never on the
21
+ model — and nothing read the per-model value.
22
+ - `defaultCapabilities` from the protocol profile, replaced by
23
+ `contextHintEnabled` and `betaPolicy`.
24
+ - `orderedBetas` from the profile and from `profileOverride`. A flat ordered
25
+ array cannot express the client's beta selection, which is emergent from
26
+ seventeen guarded pushes. Protocol drift is now detected by checking upstream's
27
+ beta identifiers against the 28-entry registry instead of against an ordering.
28
+
29
+ ### Changed
30
+
31
+ - The model identifier reaches the wire verbatim, minus any `[1m]`/`[2m]`
32
+ marker, exactly as the client sends it. Classification into a known identifier
33
+ still happens, but only to resolve capabilities.
34
+ - `ClaudeCodeCapabilities` carries nine booleans instead of four:
35
+ `thinking`, `adaptiveThinking`, `interleavedThinking`, `effort`, `maxEffort`,
36
+ `xhighEffort`, `contextManagement`, `temperature` and
37
+ `rejectsDisabledThinking`. Each is a port of one client predicate, cited by
38
+ name and byte offset in the source.
39
+ - **`claude-opus-4-5` is effort-capable again**, reversing `0.1.0-rc.9`. That
40
+ release read catalogue membership as the whole rule. It is only one of four
41
+ tests in the client's predicate, and the fallback returns true on the
42
+ first-party provider, so the model reaches effort support without a catalogue
43
+ grant. The predicates governing effort and temperature use different exclusion
44
+ lists, and `claude-opus-4-5` appears in one but not the other.
45
+ - **The model family union regains `mythos` and gains `unknown`**, reversing
46
+ `0.1.0-rc.9`. `claude-mythos-5` has no catalogue entry but is recognised by the
47
+ client's classifier and named in six of its predicates.
48
+ - `temperature` is now model-gated. The client emits it only when extended
49
+ thinking is inactive _and_ the model is on an allowlist, so Opus 4.7, Opus 4.8,
50
+ Fable 5 and Mythos 5 never receive it. A caller value supplied outside that
51
+ window is discarded rather than rejected, matching the client.
52
+ - Extended thinking now resolves the way the client resolves it. Whether a
53
+ request becomes `adaptive` or `enabled` is decided by the model's capability,
54
+ not by the caller's `type`; a caller asking for `enabled` on an
55
+ adaptive-capable model gets `adaptive` and their `budgetTokens` is discarded.
56
+ Budgets are clamped to `max_tokens - 1`.
57
+ - `thinking` accepts `disabled` and an optional `display` of `summarized` or
58
+ `omitted`. `budgetTokens` is now optional on `enabled`.
59
+ - `tool_choice` of type `tool` is demoted to `auto` while extended thinking is
60
+ active.
61
+ - Beta identifiers are emitted in the client's push order, which is emergent and
62
+ must not be sorted. `claude-code-20250219` is no longer sent for Haiku models,
63
+ and `web-search-2025-03-05` is no longer sent at all, because the client
64
+ pushes it only on Vertex and Foundry.
65
+ - `extended-cache-ttl-2025-04-11` is now conditional on a one-hour cache TTL.
66
+
67
+ ### Added
68
+
69
+ - `buildClaudeCodeCountTokensRequest`, targeting
70
+ `/v1/messages/count_tokens?beta=true`. Its beta set is the intersection of the
71
+ request beta set with the four the client's transport permits, and the
72
+ transport's own `token-counting-2024-11-01` is appended to the header. It
73
+ applies the same input canonicalisation and the same fail-closed guarantees as
74
+ the messages endpoint.
75
+ - `selectAntiVerbositySection` and `antiVerbosityText`, exposing the client's
76
+ three-way anti-verbosity prompt selection. The prompt text is extracted
77
+ byte-exactly from the client and is never injected into a request; callers
78
+ assemble their own system prompt.
79
+ - `betaPolicy` on the profile: eleven booleans, each standing for one upstream
80
+ gate that depends on host state this package cannot observe, each pinned to its
81
+ default first-party value and overridable.
82
+ - The pinned catalogue now carries each entry's `context` object and
83
+ `defaultEffort`. `defaultEffort` is exposed, never applied — the client reads
84
+ it only in its model picker, not in its request builder.
85
+ - `xhigh` joins the effort union.
86
+
87
+ ### Fixed
88
+
89
+ - The publish workflow passes the npm auth token to the publish step. Without it
90
+ the token placeholder expanded empty and the registry answered `E404` on a
91
+ scoped package rather than `E401`, which is what failed the `0.1.0-rc.8` and
92
+ `0.1.0-rc.9` publishes.
93
+
94
+ ## [0.1.0-rc.9] - 2026-07-26
95
+
96
+ ### Fixed
97
+
98
+ - The pinned model table is now transcribed from the genuine client's own
99
+ generated model catalogue instead of being derived from a public model
100
+ index. Seven identifiers that the client does not carry were removed
101
+ (`claude-opus-5`, `claude-sonnet-5`, `claude-mythos-5`, and the four dated
102
+ snapshots `claude-opus-4-5-20251101`, `claude-opus-4-1-20250805`,
103
+ `claude-sonnet-4-5-20250929`, `claude-haiku-4-5-20251001`). Dated forms are
104
+ provider identifiers, not aliases; carrying them as aliases rewrote a
105
+ caller's model onto a different identifier.
106
+ - `claude-opus-4-5` no longer advertises the effort capability. The catalogue
107
+ grants it only context management, so an effort request on that model now
108
+ fails closed instead of emitting an unsupported beta.
109
+
110
+ ### Added
111
+
112
+ - `claude-3-5-haiku`, `claude-3-5-sonnet` and `claude-3-7-sonnet` are
113
+ supported again. They are genuine catalogue entries with an empty
114
+ capability list, so all four capability flags are false.
115
+
116
+ ### Changed
117
+
118
+ - The model family union no longer includes `mythos`. It is now `haiku`,
119
+ `sonnet`, `opus` and `fable`.
120
+ - The pinned table is ordered to match the catalogue.
121
+
122
+ ## [0.1.0-rc.8] - 2026-07-26
123
+
124
+ ### Fixed
125
+
126
+ - The five `claude-3` entries added in `0.1.0-rc.7` are removed. They were wrong twice over. Their
127
+ canonical keys were invented spellings rather than real wire identifiers, and because
128
+ `resolveModel` rewrites the outgoing `model` field to the canonical key, a caller sending
129
+ `claude-3-5-haiku-latest` would have had that field silently replaced with `claude-3-5-haiku`,
130
+ discarding the snapshot it named. Independently of that, the pinned endpoint does not serve any
131
+ `claude-3` identifier at all: those models are reachable only through gateway and cloud providers,
132
+ each of which prefixes the identifier differently, and those endpoints are out of scope for this
133
+ profile. `claude-3` identifiers therefore fail closed with `UNSUPPORTED_MODEL` again.
134
+ - The `claude-fable-5` aliases `claude-fable-5-experimental` and `fable_5-preview`, and the
135
+ `claude-mythos-5` alias `mythos.5-preview`, are removed. No evidence establishes that they name the
136
+ same model as the identifier they canonicalised onto, and canonicalisation would have rerouted them
137
+ silently.
138
+
139
+ ### Added
140
+
141
+ - Seven first-party model identifiers join the pinned allowlist, taking it from sixteen entries to
142
+ eighteen: `claude-opus-5`, `claude-opus-4-5`, `claude-opus-4-5-20251101`,
143
+ `claude-opus-4-1-20250805`, `claude-sonnet-5`, `claude-sonnet-4-5-20250929` and
144
+ `claude-haiku-4-5-20251001`. The allowlist now covers every model the pinned endpoint advertises.
145
+ Four of them declare `effort` without `adaptiveThinking`, a combination no earlier entry carried;
146
+ the two upstream predicates are independent.
147
+ - Every canonical key is a real wire identifier and every alias is a non-wire spelling that
148
+ canonicalises onto one. That invariant is now stated in the profile, because `resolveModel` rewrites
149
+ the outgoing `model` field to the canonical key and an alias that names a distinct model would
150
+ silently reroute the request.
151
+
152
+ ## [0.1.0-rc.7] - 2026-07-26
153
+
154
+ ### Added
155
+
156
+ - Seven model identifiers join the pinned allowlist, taking it from nine entries to sixteen:
157
+ `claude-3-7-sonnet`, `claude-3-5-sonnet`, `claude-3-5-haiku`, `claude-3-haiku`, `claude-3-opus`,
158
+ `claude-fable-5` and `claude-mythos-5`, together with fourteen aliases covering the dotted, dated
159
+ and vendor-prefixed spellings observed in consumer code. The five `claude-3` entries declare every
160
+ capability as unsupported, because upstream gates interleaved thinking and the context hint on a
161
+ non-`claude-3` predicate; `claude-fable-5` and `claude-mythos-5` declare adaptive thinking and
162
+ effort, matching the upstream predicates that accept them.
163
+ - `ClaudeCodeModelFamily` is now an exported type. It names the model family union and gains two
164
+ members, `fable` and `mythos`. The family is evidence-only: it reaches
165
+ `RedactedRequestEvidence.modelFamily` and never any header, body field or body hash.
166
+
167
+ ### Changed
168
+
169
+ - The four declaration sites that repeated the inline `"haiku" | "sonnet" | "opus"` union now refer
170
+ to `ClaudeCodeModelFamily`, and the three runtime validators that guard it accept the two new
171
+ members.
172
+
173
+ ### Fixed
174
+
175
+ - A model entry may now declare an empty `aliases` array. Non-empty was enforced, which made the
176
+ pinned profile fail its own validation when a consumer passed `supportedModels` back through
177
+ `profileOverride` — the documented way to widen the allowlist, because an override replaces the
178
+ model map rather than merging into it. The non-empty rule still applies to `orderedBetas`.
179
+
180
+ ## [0.1.0-rc.6] - 2026-07-26
181
+
182
+ ### Fixed
183
+
184
+ - Restored the pinned cache marker on the Claude Code identity system block when a
185
+ caller supplies `cacheControl`. The caller-directed placement introduced in
186
+ `0.1.0-rc.5` removed that marker, which changed the static prefix cache boundary of
187
+ every built request. The identity marker is protocol identity owned by this package
188
+ and is now emitted unconditionally, independently of caller-directed breakpoints.
189
+
190
+ ## [0.1.0-rc.5] - 2026-07-26
191
+
192
+ ### Changed
193
+
194
+ - Consecutive caller system blocks with structurally equal `cache_control` values, including when
195
+ both are absent, are now joined into one wire block, with their texts joined in order by a single
196
+ newline. This mirrors the genuine Claude Code client, which emits one newline-joined caller block
197
+ rather than one block per caller entry. Blocks whose `cache_control` differs remain separate.
198
+
199
+ ### Added
200
+
201
+ - A new optional top-level `cacheControl` input object (`ClaudeCodeCacheControlInput`) lets the
202
+ caller direct cache-breakpoint placement through `enabled`, `ttl`, `systemBreakpoint`,
203
+ `toolBreakpoint`, and `messageBreakpoint`. Omission preserves existing behaviour. One TTL is
204
+ shared across system, tools, and messages. Explicit `ttl: null` emits an ephemeral marker with no
205
+ `ttl` member. Incoming non-thinking markers are stripped before placement, and the message
206
+ breakpoint lands on the literal last block of the last user message, including when that block is
207
+ a `tool_result`. Unknown keys are rejected with `INVALID_INPUT`.
208
+
209
+ ## [0.1.0-rc.4] - 2026-07-26
210
+
211
+ ### Added
212
+
213
+ - A fail-closed protocol profile override. The new optional `profileOverride` member on
214
+ `ClaudeCodeRequestInput` accepts a `ClaudeCodeProfileOverride` whose eleven optional members
215
+ (`id`, `cliVersion`, `sdkVersion`, `entrypoint`, `userAgent`, `buildTime`, `gitSha`,
216
+ `attributionHeaderEnabled`, `defaultCapabilities`, `supportedModels`, `orderedBetas`) replace the
217
+ pinned profile field by field. It lets a consumer ship an emergency protocol update for a new
218
+ Claude Code release without waiting for a package release.
219
+
220
+ ### Security
221
+
222
+ - The request destination is not overridable. `endpoint`, `provider` and `anthropicVersion` are
223
+ absent from `ClaudeCodeProfileOverride` by construction, so supplying any of them is rejected with
224
+ `INVALID_INPUT` rather than silently ignored. An override that changes `cliVersion` or `sdkVersion`
225
+ without a matching `userAgent` is rejected, because a body and a user agent announcing different
226
+ versions is a detectable client inconsistency.
227
+
228
+ ### Changed
229
+
230
+ - `RedactedRequestEvidence.profileId` is now `string` rather than the pinned literal type, and
231
+ reports the effective profile identifier, so evidence cannot attribute a request to the pinned
232
+ profile when an override built it.
233
+
234
+ ## [0.1.0-rc.3] - 2026-07-25
235
+
236
+ ### Added
237
+
238
+ - Full beta message content block union: `thinking`, `redacted_thinking`, `image`,
239
+ `document`, `search_result`, and nested `tool_reference` blocks, with the multimodal
240
+ `tool_result` content union.
241
+ - Full beta tool definition union: `cache_control` and `defer_loading` on tool
242
+ definitions, plus the built-in and server tool shapes that carry no ordinary
243
+ `input_schema`.
244
+ - Top-level request fields `context_management`, `output_config`, `speed`,
245
+ `service_tier`, `output_format`, `tool_choice`, `top_p`, `top_k`, `stop_sequences`,
246
+ `stream`, and `temperature`.
247
+ - Validated header seam `extraHeaders` and the dynamic headers `x-app`,
248
+ `x-stainless-retry-count`, `x-stainless-helper`, `x-claude-remote-container-id`,
249
+ `x-claude-remote-session-id`, `x-client-app`, and
250
+ `x-anthropic-additional-protection`.
251
+ - Validated body-level extension envelope `experimentalBodyFields`, so a caller can
252
+ emit a newly shipped protocol field without waiting for a package release.
253
+
254
+ ### Changed
255
+
256
+ - Request body JSON now preserves the caller's key insertion order. The previous
257
+ recursive alphabetical sort rewrote the bytes of prior conversation turns, which is
258
+ the prefix the upstream prompt cache is keyed on.
259
+ - The public metadata value type accepts nested JSON rather than only primitives.
260
+ - Unknown properties on nested request shapes are now rejected with `INVALID_INPUT`
261
+ instead of being silently dropped, making the contract fail-closed at every level.
262
+
263
+ ### Fixed
264
+
265
+ - Nested JSON metadata was rejected on the public build path even though the
266
+ published type declared it as accepted.
267
+
268
+ ## [0.1.0-rc.2] - 2026-07-25
269
+
270
+ ### Fixed
271
+
272
+ - The public `ClaudeCodeRequestInput` type now declares the required `clientRequestId` field and
273
+ optional `crypto` provider field. These fields were enforced at runtime but missing from the
274
+ published type declarations, so TypeScript consumers could not construct a valid input without
275
+ a type error.
276
+
277
+ ## [0.1.0-rc.1] - 2026-07-25
278
+
279
+ First release candidate. Published as a GitHub prerelease only; this version is deliberately not
280
+ published to npm.
281
+
282
+ ### Added
283
+
284
+ - GPL-3.0-or-later governance and upstream attribution.
285
+ - ESM-only TypeScript package, testing, linting, and build skeleton.
286
+ - Continuous integration and provenance-based publication workflow skeletons.
287
+ - Frozen public contract surface and typed `ClaudeCodeWireError` with safe, deny-by-default
288
+ details.
289
+ - Pinned `claude-code-2.1.195-sdk-0.94.0` protocol profile, exported from the
290
+ `./profiles/claude-code-2.1.195` subpath, with context hint disabled by default and a fail-closed
291
+ supported-model table.
292
+ - Normalized public protocol golden fixtures containing no credentials, account identifiers, or
293
+ private prompt text.
294
+ - Source-to-contract provenance trace at `docs/source-trace.md`.
295
+ - `buildClaudeCodeRequest` and `parseBuiltClaudeCodeRequest`, constructing a canonical Claude Code
296
+ Messages request with deterministic byte output and an evidence digest.
297
+ - Canonical request body serialization, canonical system-block ordering, and ordered safe headers.
298
+ - Billing fingerprint derived from the first user message, with validated Web Crypto digests.
299
+ - Correlated request metadata, model resolution, and beta capability negotiation over the pinned
300
+ allowlist.
301
+ - Deny-by-default redaction of error details, so no prompt text, credential, or account identifier
302
+ can reach a thrown error.
303
+ - Offline protocol drift verifier (`npm run drift:check`) and a fixture-driven drift suite.
304
+ - Conformance, property, adversarial, and input-validation suites.
305
+ - Packed-tarball verification proving identical output digests across Node, Bun, and workerd.
306
+
307
+ ### Security
308
+
309
+ - Rejects lone surrogates in all validated string inputs, so hashed bytes cannot diverge from
310
+ transmitted bytes.
311
+ - Validates the shape and length of injected Web Crypto digest results, replacing silent wire
312
+ corruption with a typed `CRYPTO_UNAVAILABLE` failure.