johns-harness 2026.10.17 → 2026.10.19
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/CHANGELOG.md +18 -0
- package/README.md +1 -1
- package/dist/pi-embedded-helpers-B7bn2aDM.js +5 -1
- package/dist/pi-embedded-helpers-CGK9ncQY.js +5 -1
- package/dist/pi-embedded-helpers-CkWXaNFn.js +5 -1
- package/dist/pi-embedded-helpers-DLLQ3MsR.js +5 -1
- package/dist/plugin-sdk/pi-embedded-helpers-B89Z8pGU.js +5 -1
- package/dist/plugin-sdk/pi-embedded-helpers-BDFUaaiY.js +5 -1
- package/dist/plugin-sdk/pi-embedded-helpers-BnFhV3or.js +5 -1
- package/dist/plugin-sdk/pi-embedded-helpers-CRUVFL1T.js +5 -1
- package/dist/plugin-sdk/pi-embedded-helpers-CY7PsNpl.js +5 -1
- package/dist/plugin-sdk/pi-embedded-helpers-Dira0ZRW.js +5 -1
- package/docs/PATCHES.md +35 -1
- package/node_modules/@mariozechner/pi-ai/dist/providers/anthropic.js +53 -3
- package/package.json +1 -1
- package/vendor/patched-deps/@mariozechner/pi-ai/dist/providers/anthropic.js +53 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2026.10.19
|
|
4
|
+
|
|
5
|
+
- **Claude subscription turns now draw from the plan's included limits, not extra usage.** John's requirement: "I don't want it to use extra usage, I want it to use the real subscription. Make it emulate Claude code if necessary." Anthropic decides per request, from content, whether a subscription turn is first party (plan limits) or third party (the organization's Extra usage). The harness prompt plus its tool list scored as third party, so with Extra usage off every turn was HTTP 400 and fell back to the API key. Real Claude Code 2.1.292 was captured on the wire and 2.1.304 was read from the binary: Claude Code sends an attribution system block first, `x-anthropic-billing-header: cc_version=<version>.<hash>; cc_entrypoint=sdk-cli; cch=00000;`, then its identity line. With that block first, the full harness prompt and 28 tools are served from plan limits.
|
|
6
|
+
- **What changed (subscription tokens only):** the vendored and installed pi-ai Anthropic adapter prefixes subscription requests with that block (uncached, Claude Code's own `cc_version` hash from the first user message), uses the Agent SDK identity line "You are Claude Code, Anthropic's official CLI for Claude, running within the Claude Agent SDK." and the user-agent `claude-cli/2.1.304 (external, sdk-cli)`. Harness instructions and tools are untouched. API-key requests are byte-identical to before. The Family 87 failover stays as the safety net.
|
|
7
|
+
- **Live proof through the harness run loop (isolated state, no API key present):** Opus 5.5 multi-turn session with `exec` tool calls and one Sonnet 5.5 turn with a tool call: every response HTTP 200, `anthropic-ratelimit-unified-5h-status: allowed`, `7d-status: allowed`, `overage-status: rejected` (extra usage off and not used), every turn $0.
|
|
8
|
+
- **Validation:** Family 88 exact replay (`--check` read-only, `--dependency-only`), the hash algorithm reproduced against the captured real request, block order and cache placement through the real adapter SSE path, API-key path unchanged, older hash-pinned families strip and re-layer Family 88, 549 verifier checks, full suite.
|
|
9
|
+
- **No org setting needed.** Extra usage can stay off for the Decision Team org.
|
|
10
|
+
- **Rollback:** `npm i -g johns-harness@2026.10.18`.
|
|
11
|
+
|
|
12
|
+
## 2026.10.18
|
|
13
|
+
|
|
14
|
+
- **Claude subscription proven live and fixed to fail over:** a real Decision Team credential (john.rood@decision.com) completed `johnness login claude` on 2026.10.17 end to end: hCaptcha, magic link, consent, `code#state`, token exchange, atomic `anthropic:subscription` storage. Through the harness's own Anthropic adapter, Opus 5.5 answered HTTP 200 with streaming, one tool call and `anthropic-ratelimit-unified-*` headers (`5h-status: allowed`), every subscription turn cost $0, and a forced refresh rotated both tokens through the real resolver. Two things broke on the way, both fixed here.
|
|
15
|
+
- **Current Claude Code user-agent floor:** Anthropic now rejects `claude-cli/2.1.62` for current models with HTTP 400 `claude_code_version_too_old` ("version 2.1.280 or newer is required"). The vendored and installed adapter send `claude-cli/2.1.304` for subscription tokens only; API-key requests are unchanged.
|
|
16
|
+
- **Subscription rejections fail over to the API key:** when an organization has extra usage switched off, Anthropic answers the harness's full request with HTTP 400 "Third-party apps now draw from extra usage, not plan limits" (`anthropic-ratelimit-unified-overage-disabled-reason: org_level_disabled`). The stock classifier treated that 400 as a format error and ended the turn. It and the version rejection are now billing failures in all ten helper bundles: the subscription profile is disabled for the billing backoff and the paid API profile answers the same turn. Verified live: subscription 400, then API-key 200 with the tool call and a normal reply, with the subscription usage still recorded at $0 and the API turns priced normally.
|
|
17
|
+
- **What John or a Decision admin may still toggle:** Anthropic bills third-party apps against the organization's Extra usage, not the included plan limits. With Extra usage off for the Decision Team org, every full harness turn on the subscription falls back to the API key. Turn on Extra usage (Claude admin settings, billing) to have subscription turns served; a bare Claude Code request already succeeds, so the credential and Team entitlement are fine.
|
|
18
|
+
- **Validation:** Family 87 exact replay (adapter + 10 helper copies, `--check` read-only, `--dependency-only`), classifier tests on the verbatim Anthropic messages, real adapter user-agent and $0 tests, older hash-pinned families (67, 78, 81, 82) strip and re-layer Family 87 with Family 86, 543 verifier checks, full suite 1,192 tests (1,187 pass, 5 skip).
|
|
19
|
+
- **Rollback:** `npm i -g johns-harness@2026.10.17`.
|
|
20
|
+
|
|
3
21
|
## 2026.10.17
|
|
4
22
|
|
|
5
23
|
- **Named subscription login:** bare `/login` lists options; `/login chatgpt` (alias `gpt`, case-insensitive) preserves the existing ChatGPT device flow. `/login claude` adds a browser/URL plus complete-code handoff, PKCE and state checks, a 15-minute window and owner-only native dispatch. CLI equivalents are `johnness login [chatgpt|claude]` and `johnness models auth login [chatgpt|claude]`; `--no-browser` supports remote Claude sign-in, and the existing `--device` shortcut still signs in to ChatGPT.
|
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ Send `/login` to list subscription choices. Use `/login chatgpt` (or `/login gpt
|
|
|
51
51
|
|
|
52
52
|
For **ChatGPT**, open the link, sign in, enter the device code on that page and tap Approve. In Telegram, tap the code to copy it. Enable "Device code authorization for Codex" once in chatgpt.com > Settings > Security; then send `/login chatgpt` for a fresh code. The existing device flow is unchanged.
|
|
53
53
|
|
|
54
|
-
For **Claude**, open the link, sign in to your subscription account, approve, then copy the complete code (including `#state`) from the callback page. Send `/login claude <complete code>` in the same chat. This uses the Claude Code OAuth client and request envelope, not a new third-party Anthropic client. Eligible Pro, Max and Team accounts use subscription limits first, with your existing Anthropic API-key profile as fallback on rate limits, authentication failures or quota exhaustion. Subscription turns record $0; API fallback turns keep normal API pricing. Tokens refresh automatically. Sign-in does not edit gateway configuration.
|
|
54
|
+
For **Claude**, open the link, sign in to your subscription account, approve, then copy the complete code (including `#state`) from the callback page. Send `/login claude <complete code>` in the same chat. This uses the Claude Code OAuth client and request envelope, not a new third-party Anthropic client. Eligible Pro, Max and Team accounts use subscription limits first, with your existing Anthropic API-key profile as fallback on rate limits, authentication failures or quota exhaustion. Subscription turns record $0; API fallback turns keep normal API pricing. Tokens refresh automatically. Sign-in does not edit gateway configuration. Subscription turns are served from your plan's included limits: the adapter sends Claude Code's own request attribution (the same first system block and Agent SDK identity line Claude Code sends), so the full harness prompt and tools are not billed as third-party extra usage. If Anthropic ever answers "Third-party apps now draw from extra usage", the harness falls back to the API key on that turn.
|
|
55
55
|
|
|
56
56
|
In a terminal, run `johnness login` to list choices, `johnness login chatgpt` or `johnness login claude`. Claude opens the browser and asks for the complete code; use `--no-browser` on a remote host to print the link instead. The equivalent commands are `johnness models auth login chatgpt` and `johnness models auth login claude`. Existing `johnness models auth login --device` remains a ChatGPT shortcut.
|
|
57
57
|
|
|
@@ -226,7 +226,11 @@ const ERROR_PATTERNS = {
|
|
|
226
226
|
/insufficient[_ ]quota/i,
|
|
227
227
|
"credit balance",
|
|
228
228
|
"plans & billing",
|
|
229
|
-
"insufficient balance"
|
|
229
|
+
"insufficient balance",
|
|
230
|
+
// JOHNNESS_PATCH_SUBSCRIPTION_FAILOVER_87: Claude subscription credentials that cannot serve this request.
|
|
231
|
+
"draw from extra usage",
|
|
232
|
+
"claude_code_version_too_old",
|
|
233
|
+
/claude code [0-9.]+ does not support this model/i
|
|
230
234
|
],
|
|
231
235
|
authPermanent: [
|
|
232
236
|
/api[_ ]?key[_ ]?(?:revoked|invalid|deactivated|deleted)/i,
|
|
@@ -226,7 +226,11 @@ const ERROR_PATTERNS = {
|
|
|
226
226
|
/insufficient[_ ]quota/i,
|
|
227
227
|
"credit balance",
|
|
228
228
|
"plans & billing",
|
|
229
|
-
"insufficient balance"
|
|
229
|
+
"insufficient balance",
|
|
230
|
+
// JOHNNESS_PATCH_SUBSCRIPTION_FAILOVER_87: Claude subscription credentials that cannot serve this request.
|
|
231
|
+
"draw from extra usage",
|
|
232
|
+
"claude_code_version_too_old",
|
|
233
|
+
/claude code [0-9.]+ does not support this model/i
|
|
230
234
|
],
|
|
231
235
|
authPermanent: [
|
|
232
236
|
/api[_ ]?key[_ ]?(?:revoked|invalid|deactivated|deleted)/i,
|
|
@@ -8785,7 +8785,11 @@ const ERROR_PATTERNS = {
|
|
|
8785
8785
|
/insufficient[_ ]quota/i,
|
|
8786
8786
|
"credit balance",
|
|
8787
8787
|
"plans & billing",
|
|
8788
|
-
"insufficient balance"
|
|
8788
|
+
"insufficient balance",
|
|
8789
|
+
// JOHNNESS_PATCH_SUBSCRIPTION_FAILOVER_87: Claude subscription credentials that cannot serve this request.
|
|
8790
|
+
"draw from extra usage",
|
|
8791
|
+
"claude_code_version_too_old",
|
|
8792
|
+
/claude code [0-9.]+ does not support this model/i
|
|
8789
8793
|
],
|
|
8790
8794
|
authPermanent: [
|
|
8791
8795
|
/api[_ ]?key[_ ]?(?:revoked|invalid|deactivated|deleted)/i,
|
|
@@ -8788,7 +8788,11 @@ const ERROR_PATTERNS = {
|
|
|
8788
8788
|
/insufficient[_ ]quota/i,
|
|
8789
8789
|
"credit balance",
|
|
8790
8790
|
"plans & billing",
|
|
8791
|
-
"insufficient balance"
|
|
8791
|
+
"insufficient balance",
|
|
8792
|
+
// JOHNNESS_PATCH_SUBSCRIPTION_FAILOVER_87: Claude subscription credentials that cannot serve this request.
|
|
8793
|
+
"draw from extra usage",
|
|
8794
|
+
"claude_code_version_too_old",
|
|
8795
|
+
/claude code [0-9.]+ does not support this model/i
|
|
8792
8796
|
],
|
|
8793
8797
|
authPermanent: [
|
|
8794
8798
|
/api[_ ]?key[_ ]?(?:revoked|invalid|deactivated|deleted)/i,
|
|
@@ -8782,7 +8782,11 @@ const ERROR_PATTERNS = {
|
|
|
8782
8782
|
/insufficient[_ ]quota/i,
|
|
8783
8783
|
"credit balance",
|
|
8784
8784
|
"plans & billing",
|
|
8785
|
-
"insufficient balance"
|
|
8785
|
+
"insufficient balance",
|
|
8786
|
+
// JOHNNESS_PATCH_SUBSCRIPTION_FAILOVER_87: Claude subscription credentials that cannot serve this request.
|
|
8787
|
+
"draw from extra usage",
|
|
8788
|
+
"claude_code_version_too_old",
|
|
8789
|
+
/claude code [0-9.]+ does not support this model/i
|
|
8786
8790
|
],
|
|
8787
8791
|
authPermanent: [
|
|
8788
8792
|
/api[_ ]?key[_ ]?(?:revoked|invalid|deactivated|deleted)/i,
|
|
@@ -8782,7 +8782,11 @@ const ERROR_PATTERNS = {
|
|
|
8782
8782
|
/insufficient[_ ]quota/i,
|
|
8783
8783
|
"credit balance",
|
|
8784
8784
|
"plans & billing",
|
|
8785
|
-
"insufficient balance"
|
|
8785
|
+
"insufficient balance",
|
|
8786
|
+
// JOHNNESS_PATCH_SUBSCRIPTION_FAILOVER_87: Claude subscription credentials that cannot serve this request.
|
|
8787
|
+
"draw from extra usage",
|
|
8788
|
+
"claude_code_version_too_old",
|
|
8789
|
+
/claude code [0-9.]+ does not support this model/i
|
|
8786
8790
|
],
|
|
8787
8791
|
authPermanent: [
|
|
8788
8792
|
/api[_ ]?key[_ ]?(?:revoked|invalid|deactivated|deleted)/i,
|
|
@@ -8782,7 +8782,11 @@ const ERROR_PATTERNS = {
|
|
|
8782
8782
|
/insufficient[_ ]quota/i,
|
|
8783
8783
|
"credit balance",
|
|
8784
8784
|
"plans & billing",
|
|
8785
|
-
"insufficient balance"
|
|
8785
|
+
"insufficient balance",
|
|
8786
|
+
// JOHNNESS_PATCH_SUBSCRIPTION_FAILOVER_87: Claude subscription credentials that cannot serve this request.
|
|
8787
|
+
"draw from extra usage",
|
|
8788
|
+
"claude_code_version_too_old",
|
|
8789
|
+
/claude code [0-9.]+ does not support this model/i
|
|
8786
8790
|
],
|
|
8787
8791
|
authPermanent: [
|
|
8788
8792
|
/api[_ ]?key[_ ]?(?:revoked|invalid|deactivated|deleted)/i,
|
|
@@ -8782,7 +8782,11 @@ const ERROR_PATTERNS = {
|
|
|
8782
8782
|
/insufficient[_ ]quota/i,
|
|
8783
8783
|
"credit balance",
|
|
8784
8784
|
"plans & billing",
|
|
8785
|
-
"insufficient balance"
|
|
8785
|
+
"insufficient balance",
|
|
8786
|
+
// JOHNNESS_PATCH_SUBSCRIPTION_FAILOVER_87: Claude subscription credentials that cannot serve this request.
|
|
8787
|
+
"draw from extra usage",
|
|
8788
|
+
"claude_code_version_too_old",
|
|
8789
|
+
/claude code [0-9.]+ does not support this model/i
|
|
8786
8790
|
],
|
|
8787
8791
|
authPermanent: [
|
|
8788
8792
|
/api[_ ]?key[_ ]?(?:revoked|invalid|deactivated|deleted)/i,
|
|
@@ -8782,7 +8782,11 @@ const ERROR_PATTERNS = {
|
|
|
8782
8782
|
/insufficient[_ ]quota/i,
|
|
8783
8783
|
"credit balance",
|
|
8784
8784
|
"plans & billing",
|
|
8785
|
-
"insufficient balance"
|
|
8785
|
+
"insufficient balance",
|
|
8786
|
+
// JOHNNESS_PATCH_SUBSCRIPTION_FAILOVER_87: Claude subscription credentials that cannot serve this request.
|
|
8787
|
+
"draw from extra usage",
|
|
8788
|
+
"claude_code_version_too_old",
|
|
8789
|
+
/claude code [0-9.]+ does not support this model/i
|
|
8786
8790
|
],
|
|
8787
8791
|
authPermanent: [
|
|
8788
8792
|
/api[_ ]?key[_ ]?(?:revoked|invalid|deactivated|deleted)/i,
|
|
@@ -8775,7 +8775,11 @@ const ERROR_PATTERNS = {
|
|
|
8775
8775
|
/insufficient[_ ]quota/i,
|
|
8776
8776
|
"credit balance",
|
|
8777
8777
|
"plans & billing",
|
|
8778
|
-
"insufficient balance"
|
|
8778
|
+
"insufficient balance",
|
|
8779
|
+
// JOHNNESS_PATCH_SUBSCRIPTION_FAILOVER_87: Claude subscription credentials that cannot serve this request.
|
|
8780
|
+
"draw from extra usage",
|
|
8781
|
+
"claude_code_version_too_old",
|
|
8782
|
+
/claude code [0-9.]+ does not support this model/i
|
|
8779
8783
|
],
|
|
8780
8784
|
authPermanent: [
|
|
8781
8785
|
/api[_ ]?key[_ ]?(?:revoked|invalid|deactivated|deleted)/i,
|
package/docs/PATCHES.md
CHANGED
|
@@ -17,7 +17,7 @@ they predate ~2026-06-06).
|
|
|
17
17
|
|
|
18
18
|
## Index
|
|
19
19
|
|
|
20
|
-
Current addition: [
|
|
20
|
+
Current addition: [88 - Subscription plan limits](#88---subscription-plan-limits-2026-10-20).
|
|
21
21
|
|
|
22
22
|
Family 01 is retired. Families 02 through 41, 43 through 81, including the 65.1 amendment, are live on `main`; the `latest` and `extended` release lines converged at 2026.9.24. Family 42 is omitted; native Codex OAuth ownership is Family 58.
|
|
23
23
|
|
|
@@ -112,6 +112,8 @@ Family 01 is retired. Families 02 through 41, 43 through 81, including the 65.1
|
|
|
112
112
|
82. **82, daily model integration:** Claude Sonnet 5.5 (`claude-sonnet-5-5`) registered; `sonnet` moves to it with `sonnet5` kept on Sonnet 5. Since 2026.9.37 every Sonnet runs on its full native 1M window. [Details](#82---sonnet-5-5-2026-09-29)
|
|
113
113
|
|
|
114
114
|
86. **86, named subscription login:** `/login chatgpt` preserves ChatGPT device sign-in; `/login claude` adds current Claude Code OAuth, subscription-first auth, API fallback and credential-specific $0 accounting. [Details](#86---named-subscription-login-2026-10-20)
|
|
115
|
+
87. **87, subscription failover:** current Claude Code user-agent floor (`claude-cli/2.1.304`) for subscription tokens, and Anthropic's extra-usage and version rejections rotate the subscription profile to the paid API key instead of ending the turn. [Details](#87---subscription-failover-2026-10-20)
|
|
116
|
+
88. **88, subscription plan limits:** subscription turns carry Claude Code's attribution system block (first, uncached, `cc_entrypoint=sdk-cli`, Claude Code's own `cc_version` hash) and the Agent SDK identity line, so Anthropic serves the full harness prompt and tools from the plan's included limits instead of billing third-party extra usage. API-key requests are unchanged. [Details](#88---subscription-plan-limits-2026-10-20)
|
|
115
117
|
|
|
116
118
|
---
|
|
117
119
|
|
|
@@ -2965,3 +2967,35 @@ NO_REPLY, failed sends, block streaming, exact replay, idempotence and drift ref
|
|
|
2965
2967
|
**Replay:** `patches/subscription-login-86/changes.json`, `scripts/patch-subscription-login-86.py` and `scripts/subscription_login_layer.py`. All reviewed hunks preflight before any writes; owned new files are exact pinned content. `--check` is read-only; `--present-only` supports historical fixture subsets. Earlier hash-pinned families strip only reviewed Family 86 hunks and re-layer them after reconstruction. The postinstall vendor overlay copies both the OAuth and Anthropic provider changes to the pinned pi-ai dependency. Historical unified-diff fixture tests reverse this layer explicitly, rather than relaxing equality checks.
|
|
2966
2968
|
|
|
2967
2969
|
**Tests:** `tests/subscription-login.test.mjs`, updated device/registry and postinstall tests, and the full suite. Synthetic tests exercise current endpoints, callback state validation, PKCE, owner/route isolation, atomic storage, locked native refresh persistence, all ten picker copies, error classification and the real SSE adapter's Claude Code envelope with $0 subscription versus paid API usage. A browser smoke reached Claude's account subscription gate using the current URL; that browser was on a different account, and no consent or credential exchange was completed. The owner must finish sign-in to prove their Team entitlement. Rollback: `npm i -g johns-harness@2026.10.16`.
|
|
2970
|
+
|
|
2971
|
+
## 87 - Subscription failover (2026-10-20)
|
|
2972
|
+
|
|
2973
|
+
**Intent:** make the Claude subscription path from Family 86 survive what Anthropic actually returns to a real Team credential, and prove the whole path live.
|
|
2974
|
+
|
|
2975
|
+
**Live proof (john.rood@decision.com, Decision Team, isolated `/tmp` state only):** `johnness login claude --no-browser` on 2026.10.17 produced the authorize URL; the owner's agent completed the hCaptcha, magic link, consent and callback; the harness's `startClaudeLogin`/`saveClaudeCredential` exchanged `code#state` and stored `anthropic:subscription` (mode 0600, refresh present, 8-hour access). Through the harness's own pi-ai Anthropic adapter: Opus 5.5 HTTP 200, streaming, one tool call plus tool-result round trip, `anthropic-ratelimit-unified-5h-status: allowed`, `anthropic-ratelimit-unified-7d-status: allowed`, cost `{0,0,0,0}` on both turns. A forced expiry drove the real resolver through `platform.claude.com/v1/oauth/token` (`refresh_token`, 200), rotated access and refresh, persisted them, and the rotated token answered 200.
|
|
2976
|
+
|
|
2977
|
+
**Fix 1, user-agent floor:** the adapter advertised `claude-cli/2.1.62`. Anthropic returned HTTP 400 `{"error_code":"claude_code_version_too_old"}` "Claude Code 2.1.62 does not support this model; version 2.1.280 or newer is required" for `claude-opus-5-5`. `claude-cli/2.1.304` (npm latest `@anthropic-ai/claude-code` that day) returned 200. The constant is the only change in the adapter; it applies to subscription (`sk-ant-oat`) requests only.
|
|
2978
|
+
|
|
2979
|
+
**Fix 2, failover classification:** with the harness's full system prompt, Anthropic returns HTTP 400 "Third-party apps now draw from extra usage, not plan limits. Ask your workspace admin to add more and keep going." and `anthropic-ratelimit-unified-overage-disabled-reason: org_level_disabled`. A bare Claude Code system prompt on the same token returns 200, so this is Anthropic's third-party classification billed against the organization's Extra usage, which the Decision org has off. The stock classifier mapped that 400 to `format`, so the turn ended with "LLM request rejected" and the API key never ran. The ten compiled `pi-embedded-helpers` copies now list `draw from extra usage`, `claude_code_version_too_old` and `Claude Code <v> does not support this model` under billing patterns. Verified live with the real run loop: subscription 400, profile disabled for the billing backoff (`disabledReason: billing`), API-key 200 with the tool call and reply, subscription attempts recorded at $0 and API turns at normal price. Ordinary 400 shape errors still classify as null.
|
|
2980
|
+
|
|
2981
|
+
**Org setting:** Claude admin settings, billing: turn on Extra usage for the Decision Team organization. Until then every full harness turn falls back to the API key; the subscription credential itself is valid and entitled.
|
|
2982
|
+
|
|
2983
|
+
**Replay:** `patches/subscription-failover-87/changes.json`, `scripts/patch-subscription-failover-87.py` (`--check`, `--present-only`, `--dependency-only`, `--record`). `scripts/subscription_login_layer.py` and `tests/helpers/subscription-login-layer.mjs` strip and re-layer Family 87 together with Family 86 so Families 67, 78, 81 and 82 keep exact replay. Verifier checks 87.1 to 87.4.
|
|
2984
|
+
|
|
2985
|
+
**Tests:** `tests/subscription-failover-87.test.mjs` (manifest coverage, user-agent floor, verbatim-message classification in all ten copies, billing backoff path, idempotent replay and drift refusal, real adapter user-agent and $0 on the extra-usage 400). Full suite 1,192 tests, 1,187 pass, 5 skip. Rollback: `npm i -g johns-harness@2026.10.17`.
|
|
2986
|
+
|
|
2987
|
+
## 88 - Subscription plan limits (2026-10-20)
|
|
2988
|
+
|
|
2989
|
+
**Intent:** John's requirement, verbatim: "I don't want it to use extra usage, I want it to use the real subscription. Make it emulate Claude code if necessary." Family 87 proved the credential and made the extra-usage rejection fail over to the API key; this family makes the subscription turn itself be served from the plan's included limits.
|
|
2990
|
+
|
|
2991
|
+
**What Anthropic keys on (bisected live, john.rood@decision.com, Decision Team, isolated `/tmp` state only):** the decision is per request and content-based. Same token, same headers: a bare Claude Code identity line with no tools is served from plan limits; the harness system prompt alone is HTTP 400 "Third-party apps now draw from extra usage, not plan limits"; the Claude Code identity line plus the harness's 28 tool definitions is also 400, but no single tool is (pairs such as `agents_list` + `sessions_list` or `sessions_spawn` + `subagents` are), so it is a scored classifier, not a keyword list. Claude Code's own headers (`x-stainless-*`, session and request ids, the full beta list, `?beta=true`) and `metadata.user_id` did not change the verdict on their own.
|
|
2992
|
+
|
|
2993
|
+
**What flips it:** real Claude Code 2.1.292 was captured on this machine through a local logging proxy (API-key auth; the request shape is the same for OAuth). Its first system block, uncached, is `x-anthropic-billing-header: cc_version=2.1.292.db5; cc_entrypoint=sdk-cli; cch=438b8; cc_prompt_id=...; cc_turn_origin=sdk; cc_prompt_index=0; cc_turn_index=1;`, followed by the identity line and then its instructions. Prefixing the full harness payload (prompt + 28 tools) with `x-anthropic-billing-header: cc_version=<v>; cc_entrypoint=sdk-cli; cch=00000;` returns 200 with `anthropic-ratelimit-unified-5h-status: allowed` on Opus 5.5 and Sonnet 5.5. `cch` is not checked (00000, the literal the 2.1.304 binary sends, and arbitrary values all pass). `cc_entrypoint` is checked: `sdk-cli` passes; `cli`, `cli-bg`, `sdk-ts`, `sdk-py` and `unknown` are 400. The block must be the first system entry (second or last is 400); a bare `x-anthropic-billing-header:` prefix is rejected as reserved. The `cc_version` hash is Claude Code's own, read from the 2.1.304 binary: sha256(salt + characters 4, 7 and 20 of the first user message text, `0` when absent + version), first three hex characters; the constant salt reproduces the captured `db5`.
|
|
2994
|
+
|
|
2995
|
+
**Change (vendored and installed pi-ai Anthropic adapter, subscription tokens only):** `buildParams` emits `[attribution block (uncached), "You are Claude Code, Anthropic's official CLI for Claude, running within the Claude Agent SDK." (cached), ...harness system blocks (Family 36 split)]`; the user-agent becomes `claude-cli/2.1.304 (external, sdk-cli)`. The harness's instructions and tool list are untouched. API-key requests are byte-identical to before (no attribution, no identity line, stock user-agent, paid). The version constant from Family 87 feeds the tag, so a future floor bump changes both.
|
|
2996
|
+
|
|
2997
|
+
**Live proof through the harness's own run loop (no API key in the environment, subscription only):** Opus 5.5 multi-turn session with `exec` tool calls (four requests, `req_011CgE71mWWXLnZaxCfoTayo`, `req_011CgE723NznBDQDfFyv4nzF`, `req_011CgE73rPG1MWx6NZL47p1w`, `req_011CgE744L77nvyzKJHrJGqu`) and one Sonnet 5.5 turn with a tool call (`req_011CgE77ksyDpBtVrADf5DHM`, `req_011CgE77uoVy6sKzVmwKJb83`): every response HTTP 200, `anthropic-ratelimit-unified-status: allowed`, `5h-status: allowed` (utilization 0.01 to 0.02), `7d-status: allowed`, `overage-status: rejected` with `overage-disabled-reason: org_level_disabled` (extra usage still off and not used), every session record cost `{0,0,0,0,0}`.
|
|
2998
|
+
|
|
2999
|
+
**Replay:** `patches/subscription-plan-limits-88/changes.json`, `scripts/patch-subscription-plan-limits-88.py` (`--check`, `--present-only`, `--dependency-only`, `--record`). `scripts/subscription_login_layer.py` and `tests/helpers/subscription-login-layer.mjs` strip and re-layer Family 88 with 86 and 87 so Families 67, 78, 81 and 82 keep exact replay. Verifier checks 88.1 to 88.6.
|
|
3000
|
+
|
|
3001
|
+
**Tests:** `tests/subscription-plan-limits-88.test.mjs` (manifest coverage, hash algorithm against the captured real request, block order and cache placement through the real adapter's SSE path, hash follows the first user message, API-key request unchanged, idempotent replay and drift refusal, strip/re-layer), Family 36 and 87 tests updated for the new first block and user-agent. Rollback: `npm i -g johns-harness@2026.10.18`.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Anthropic from "@anthropic-ai/sdk";
|
|
2
|
+
import { createHash } from "node:crypto"; // JOHNNESS_PATCH_SUBSCRIPTION_PLAN_LIMITS_88
|
|
2
3
|
import { getEnvApiKey } from "../env-api-keys.js";
|
|
3
4
|
import { calculateCost } from "../models.js";
|
|
4
5
|
import { AssistantMessageEventStream } from "../utils/event-stream.js";
|
|
@@ -63,7 +64,54 @@ function getCacheControl(baseUrl, cacheRetention) {
|
|
|
63
64
|
};
|
|
64
65
|
}
|
|
65
66
|
// Stealth mode: Mimic Claude Code's tool naming exactly
|
|
66
|
-
|
|
67
|
+
// JOHNNESS_PATCH_SUBSCRIPTION_FAILOVER_87: Anthropic rejects older Claude Code versions per model (claude_code_version_too_old).
|
|
68
|
+
const claudeCodeVersion = "2.1.304";
|
|
69
|
+
/* JOHNNESS_PATCH_SUBSCRIPTION_PLAN_LIMITS_88: Claude Code's request attribution for subscription tokens.
|
|
70
|
+
* Anthropic decides per request whether a subscription (sk-ant-oat) turn is served from the plan's
|
|
71
|
+
* included limits or billed as third-party "extra usage". Bisected live on 2026-10-20 with a Team
|
|
72
|
+
* credential: the harness system prompt plus its tool list scores as third party and, with extra
|
|
73
|
+
* usage off for the organization, every full turn was HTTP 400 "Third-party apps now draw from extra
|
|
74
|
+
* usage, not plan limits". Claude Code 2.1.304 (and the Claude Agent SDK, which is what the Agent SDK
|
|
75
|
+
* entrypoint of the same binary sends) prefixes every request with an attribution system block:
|
|
76
|
+
* "x-anthropic-billing-header: cc_version=<version>.<hash>; cc_entrypoint=sdk-cli; cch=00000;"
|
|
77
|
+
* followed by its identity line. With that block first, the same harness prompt and tools are
|
|
78
|
+
* served from plan limits (200, anthropic-ratelimit-unified-5h-status: allowed, $0). The version
|
|
79
|
+
* hash is Claude Code's own: sha256(salt + chars 4, 7 and 20 of the first user message + version),
|
|
80
|
+
* first three hex characters; the salt is the constant Claude Code 2.1.304 ships. The block must be
|
|
81
|
+
* the first system entry and is never cached. Applies to subscription tokens only; API-key requests
|
|
82
|
+
* are byte-identical to before. */
|
|
83
|
+
const claudeCodeAttributionSalt = "59cf53e54c78";
|
|
84
|
+
const claudeCodeAttributionEntrypoint = "sdk-cli";
|
|
85
|
+
const claudeCodeSdkIdentity = "You are Claude Code, Anthropic's official CLI for Claude, running within the Claude Agent SDK.";
|
|
86
|
+
function claudeCodeFirstUserText(messages) {
|
|
87
|
+
const first = messages?.find((message) => message?.role === "user");
|
|
88
|
+
if (!first)
|
|
89
|
+
return "";
|
|
90
|
+
const content = first.content;
|
|
91
|
+
if (typeof content === "string")
|
|
92
|
+
return content;
|
|
93
|
+
if (Array.isArray(content)) {
|
|
94
|
+
const text = content.find((block) => block?.type === "text");
|
|
95
|
+
if (text && typeof text.text === "string")
|
|
96
|
+
return text.text;
|
|
97
|
+
}
|
|
98
|
+
return "";
|
|
99
|
+
}
|
|
100
|
+
function claudeCodeVersionTag(messages) {
|
|
101
|
+
const text = claudeCodeFirstUserText(messages);
|
|
102
|
+
const sample = [4, 7, 20].map((index) => text[index] || "0").join("");
|
|
103
|
+
const digest = createHash("sha256").update(`${claudeCodeAttributionSalt}${sample}${claudeCodeVersion}`).digest("hex").slice(0, 3);
|
|
104
|
+
return `${claudeCodeVersion}.${digest}`;
|
|
105
|
+
}
|
|
106
|
+
function claudeCodeAttributionBlock(messages) {
|
|
107
|
+
return {
|
|
108
|
+
type: "text",
|
|
109
|
+
text: `x-anthropic-billing-header: cc_version=${claudeCodeVersionTag(messages)}; cc_entrypoint=${claudeCodeAttributionEntrypoint}; cch=00000;`,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function claudeCodeUserAgent() {
|
|
113
|
+
return `claude-cli/${claudeCodeVersion} (external, ${claudeCodeAttributionEntrypoint})`;
|
|
114
|
+
}
|
|
67
115
|
// Claude Code 2.x tool names (canonical casing)
|
|
68
116
|
// Source: https://cchistory.mariozechner.at/data/prompts-2.1.11.md
|
|
69
117
|
// To update: https://github.com/badlogic/cchistory
|
|
@@ -475,7 +523,7 @@ function createClient(model, apiKey, interleavedThinking, optionsHeaders, dynami
|
|
|
475
523
|
accept: "application/json",
|
|
476
524
|
"anthropic-dangerous-direct-browser-access": "true",
|
|
477
525
|
"anthropic-beta": `claude-code-20250219,oauth-2025-04-20,${betaFeatures.join(",")}`,
|
|
478
|
-
"user-agent":
|
|
526
|
+
"user-agent": claudeCodeUserAgent(), // JOHNNESS_PATCH_SUBSCRIPTION_PLAN_LIMITS_88
|
|
479
527
|
"x-app": "cli",
|
|
480
528
|
}, model.headers, optionsHeaders),
|
|
481
529
|
});
|
|
@@ -548,9 +596,11 @@ function buildParams(model, context, isOAuthToken, options) {
|
|
|
548
596
|
// For OAuth tokens, we MUST include Claude Code identity
|
|
549
597
|
if (isOAuthToken) {
|
|
550
598
|
params.system = [
|
|
599
|
+
// JOHNNESS_PATCH_SUBSCRIPTION_PLAN_LIMITS_88: attribution first, uncached, then the identity line.
|
|
600
|
+
claudeCodeAttributionBlock(params.messages),
|
|
551
601
|
{
|
|
552
602
|
type: "text",
|
|
553
|
-
text:
|
|
603
|
+
text: claudeCodeSdkIdentity,
|
|
554
604
|
...(cacheControl ? { cache_control: cacheControl } : {}),
|
|
555
605
|
},
|
|
556
606
|
];
|
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Anthropic from "@anthropic-ai/sdk";
|
|
2
|
+
import { createHash } from "node:crypto"; // JOHNNESS_PATCH_SUBSCRIPTION_PLAN_LIMITS_88
|
|
2
3
|
import { getEnvApiKey } from "../env-api-keys.js";
|
|
3
4
|
import { calculateCost } from "../models.js";
|
|
4
5
|
import { AssistantMessageEventStream } from "../utils/event-stream.js";
|
|
@@ -63,7 +64,54 @@ function getCacheControl(baseUrl, cacheRetention) {
|
|
|
63
64
|
};
|
|
64
65
|
}
|
|
65
66
|
// Stealth mode: Mimic Claude Code's tool naming exactly
|
|
66
|
-
|
|
67
|
+
// JOHNNESS_PATCH_SUBSCRIPTION_FAILOVER_87: Anthropic rejects older Claude Code versions per model (claude_code_version_too_old).
|
|
68
|
+
const claudeCodeVersion = "2.1.304";
|
|
69
|
+
/* JOHNNESS_PATCH_SUBSCRIPTION_PLAN_LIMITS_88: Claude Code's request attribution for subscription tokens.
|
|
70
|
+
* Anthropic decides per request whether a subscription (sk-ant-oat) turn is served from the plan's
|
|
71
|
+
* included limits or billed as third-party "extra usage". Bisected live on 2026-10-20 with a Team
|
|
72
|
+
* credential: the harness system prompt plus its tool list scores as third party and, with extra
|
|
73
|
+
* usage off for the organization, every full turn was HTTP 400 "Third-party apps now draw from extra
|
|
74
|
+
* usage, not plan limits". Claude Code 2.1.304 (and the Claude Agent SDK, which is what the Agent SDK
|
|
75
|
+
* entrypoint of the same binary sends) prefixes every request with an attribution system block:
|
|
76
|
+
* "x-anthropic-billing-header: cc_version=<version>.<hash>; cc_entrypoint=sdk-cli; cch=00000;"
|
|
77
|
+
* followed by its identity line. With that block first, the same harness prompt and tools are
|
|
78
|
+
* served from plan limits (200, anthropic-ratelimit-unified-5h-status: allowed, $0). The version
|
|
79
|
+
* hash is Claude Code's own: sha256(salt + chars 4, 7 and 20 of the first user message + version),
|
|
80
|
+
* first three hex characters; the salt is the constant Claude Code 2.1.304 ships. The block must be
|
|
81
|
+
* the first system entry and is never cached. Applies to subscription tokens only; API-key requests
|
|
82
|
+
* are byte-identical to before. */
|
|
83
|
+
const claudeCodeAttributionSalt = "59cf53e54c78";
|
|
84
|
+
const claudeCodeAttributionEntrypoint = "sdk-cli";
|
|
85
|
+
const claudeCodeSdkIdentity = "You are Claude Code, Anthropic's official CLI for Claude, running within the Claude Agent SDK.";
|
|
86
|
+
function claudeCodeFirstUserText(messages) {
|
|
87
|
+
const first = messages?.find((message) => message?.role === "user");
|
|
88
|
+
if (!first)
|
|
89
|
+
return "";
|
|
90
|
+
const content = first.content;
|
|
91
|
+
if (typeof content === "string")
|
|
92
|
+
return content;
|
|
93
|
+
if (Array.isArray(content)) {
|
|
94
|
+
const text = content.find((block) => block?.type === "text");
|
|
95
|
+
if (text && typeof text.text === "string")
|
|
96
|
+
return text.text;
|
|
97
|
+
}
|
|
98
|
+
return "";
|
|
99
|
+
}
|
|
100
|
+
function claudeCodeVersionTag(messages) {
|
|
101
|
+
const text = claudeCodeFirstUserText(messages);
|
|
102
|
+
const sample = [4, 7, 20].map((index) => text[index] || "0").join("");
|
|
103
|
+
const digest = createHash("sha256").update(`${claudeCodeAttributionSalt}${sample}${claudeCodeVersion}`).digest("hex").slice(0, 3);
|
|
104
|
+
return `${claudeCodeVersion}.${digest}`;
|
|
105
|
+
}
|
|
106
|
+
function claudeCodeAttributionBlock(messages) {
|
|
107
|
+
return {
|
|
108
|
+
type: "text",
|
|
109
|
+
text: `x-anthropic-billing-header: cc_version=${claudeCodeVersionTag(messages)}; cc_entrypoint=${claudeCodeAttributionEntrypoint}; cch=00000;`,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function claudeCodeUserAgent() {
|
|
113
|
+
return `claude-cli/${claudeCodeVersion} (external, ${claudeCodeAttributionEntrypoint})`;
|
|
114
|
+
}
|
|
67
115
|
// Claude Code 2.x tool names (canonical casing)
|
|
68
116
|
// Source: https://cchistory.mariozechner.at/data/prompts-2.1.11.md
|
|
69
117
|
// To update: https://github.com/badlogic/cchistory
|
|
@@ -475,7 +523,7 @@ function createClient(model, apiKey, interleavedThinking, optionsHeaders, dynami
|
|
|
475
523
|
accept: "application/json",
|
|
476
524
|
"anthropic-dangerous-direct-browser-access": "true",
|
|
477
525
|
"anthropic-beta": `claude-code-20250219,oauth-2025-04-20,${betaFeatures.join(",")}`,
|
|
478
|
-
"user-agent":
|
|
526
|
+
"user-agent": claudeCodeUserAgent(), // JOHNNESS_PATCH_SUBSCRIPTION_PLAN_LIMITS_88
|
|
479
527
|
"x-app": "cli",
|
|
480
528
|
}, model.headers, optionsHeaders),
|
|
481
529
|
});
|
|
@@ -548,9 +596,11 @@ function buildParams(model, context, isOAuthToken, options) {
|
|
|
548
596
|
// For OAuth tokens, we MUST include Claude Code identity
|
|
549
597
|
if (isOAuthToken) {
|
|
550
598
|
params.system = [
|
|
599
|
+
// JOHNNESS_PATCH_SUBSCRIPTION_PLAN_LIMITS_88: attribution first, uncached, then the identity line.
|
|
600
|
+
claudeCodeAttributionBlock(params.messages),
|
|
551
601
|
{
|
|
552
602
|
type: "text",
|
|
553
|
-
text:
|
|
603
|
+
text: claudeCodeSdkIdentity,
|
|
554
604
|
...(cacheControl ? { cache_control: cacheControl } : {}),
|
|
555
605
|
},
|
|
556
606
|
];
|