johns-harness 2026.10.18 → 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 CHANGED
@@ -1,5 +1,14 @@
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
+
3
12
  ## 2026.10.18
4
13
 
5
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.
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. If Anthropic answers "Third-party apps now draw from extra usage", your organization has Extra usage switched off; the harness falls back to the API key on that turn, and an org admin can turn Extra usage on in Claude admin billing settings to have subscription turns served.
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
 
package/docs/PATCHES.md CHANGED
@@ -17,7 +17,7 @@ they predate ~2026-06-06).
17
17
 
18
18
  ## Index
19
19
 
20
- Current addition: [85 - Distinct final replies after messaging-tool sends](#85--distinct-final-replies-after-messaging-tool-sends-2026-10-16).
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
 
@@ -113,6 +113,7 @@ Family 01 is retired. Families 02 through 41, 43 through 81, including the 65.1
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
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)
116
117
 
117
118
  ---
118
119
 
@@ -2982,3 +2983,19 @@ NO_REPLY, failed sends, block streaming, exact replay, idempotence and drift ref
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.
2983
2984
 
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";
@@ -65,6 +66,52 @@ function getCacheControl(baseUrl, cacheRetention) {
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).
67
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
+ }
68
115
  // Claude Code 2.x tool names (canonical casing)
69
116
  // Source: https://cchistory.mariozechner.at/data/prompts-2.1.11.md
70
117
  // To update: https://github.com/badlogic/cchistory
@@ -476,7 +523,7 @@ function createClient(model, apiKey, interleavedThinking, optionsHeaders, dynami
476
523
  accept: "application/json",
477
524
  "anthropic-dangerous-direct-browser-access": "true",
478
525
  "anthropic-beta": `claude-code-20250219,oauth-2025-04-20,${betaFeatures.join(",")}`,
479
- "user-agent": `claude-cli/${claudeCodeVersion}`,
526
+ "user-agent": claudeCodeUserAgent(), // JOHNNESS_PATCH_SUBSCRIPTION_PLAN_LIMITS_88
480
527
  "x-app": "cli",
481
528
  }, model.headers, optionsHeaders),
482
529
  });
@@ -549,9 +596,11 @@ function buildParams(model, context, isOAuthToken, options) {
549
596
  // For OAuth tokens, we MUST include Claude Code identity
550
597
  if (isOAuthToken) {
551
598
  params.system = [
599
+ // JOHNNESS_PATCH_SUBSCRIPTION_PLAN_LIMITS_88: attribution first, uncached, then the identity line.
600
+ claudeCodeAttributionBlock(params.messages),
552
601
  {
553
602
  type: "text",
554
- text: "You are Claude Code, Anthropic's official CLI for Claude.",
603
+ text: claudeCodeSdkIdentity,
555
604
  ...(cacheControl ? { cache_control: cacheControl } : {}),
556
605
  },
557
606
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "johns-harness",
3
- "version": "2026.10.18",
3
+ "version": "2026.10.19",
4
4
  "description": "John's Harness: a production agent harness that runs autonomous coding agents as one cooperative swarm.",
5
5
  "keywords": [
6
6
  "ai-agents",
@@ -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";
@@ -65,6 +66,52 @@ function getCacheControl(baseUrl, cacheRetention) {
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).
67
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
+ }
68
115
  // Claude Code 2.x tool names (canonical casing)
69
116
  // Source: https://cchistory.mariozechner.at/data/prompts-2.1.11.md
70
117
  // To update: https://github.com/badlogic/cchistory
@@ -476,7 +523,7 @@ function createClient(model, apiKey, interleavedThinking, optionsHeaders, dynami
476
523
  accept: "application/json",
477
524
  "anthropic-dangerous-direct-browser-access": "true",
478
525
  "anthropic-beta": `claude-code-20250219,oauth-2025-04-20,${betaFeatures.join(",")}`,
479
- "user-agent": `claude-cli/${claudeCodeVersion}`,
526
+ "user-agent": claudeCodeUserAgent(), // JOHNNESS_PATCH_SUBSCRIPTION_PLAN_LIMITS_88
480
527
  "x-app": "cli",
481
528
  }, model.headers, optionsHeaders),
482
529
  });
@@ -549,9 +596,11 @@ function buildParams(model, context, isOAuthToken, options) {
549
596
  // For OAuth tokens, we MUST include Claude Code identity
550
597
  if (isOAuthToken) {
551
598
  params.system = [
599
+ // JOHNNESS_PATCH_SUBSCRIPTION_PLAN_LIMITS_88: attribution first, uncached, then the identity line.
600
+ claudeCodeAttributionBlock(params.messages),
552
601
  {
553
602
  type: "text",
554
- text: "You are Claude Code, Anthropic's official CLI for Claude.",
603
+ text: claudeCodeSdkIdentity,
555
604
  ...(cacheControl ? { cache_control: cacheControl } : {}),
556
605
  },
557
606
  ];