@vacbo/opencode-anthropic-fix 0.1.7 → 0.1.9

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 (107) hide show
  1. package/README.md +88 -88
  2. package/dist/opencode-anthropic-auth-cli.mjs +804 -507
  3. package/dist/opencode-anthropic-auth-plugin.js +4751 -4109
  4. package/package.json +67 -59
  5. package/src/__tests__/billing-edge-cases.test.ts +59 -59
  6. package/src/__tests__/bun-proxy.parallel.test.ts +388 -382
  7. package/src/__tests__/cc-comparison.test.ts +87 -87
  8. package/src/__tests__/cc-credentials.test.ts +254 -250
  9. package/src/__tests__/cch-drift-checker.test.ts +51 -51
  10. package/src/__tests__/cch-native-style.test.ts +56 -56
  11. package/src/__tests__/debug-gating.test.ts +42 -42
  12. package/src/__tests__/decomposition-smoke.test.ts +68 -68
  13. package/src/__tests__/fingerprint-regression.test.ts +575 -566
  14. package/src/__tests__/helpers/conversation-history.smoke.test.ts +271 -271
  15. package/src/__tests__/helpers/conversation-history.ts +119 -119
  16. package/src/__tests__/helpers/deferred.smoke.test.ts +103 -103
  17. package/src/__tests__/helpers/deferred.ts +69 -69
  18. package/src/__tests__/helpers/in-memory-storage.smoke.test.ts +155 -155
  19. package/src/__tests__/helpers/in-memory-storage.ts +88 -88
  20. package/src/__tests__/helpers/mock-bun-proxy.smoke.test.ts +68 -68
  21. package/src/__tests__/helpers/mock-bun-proxy.ts +189 -189
  22. package/src/__tests__/helpers/plugin-fetch-harness.smoke.test.ts +273 -273
  23. package/src/__tests__/helpers/plugin-fetch-harness.ts +288 -288
  24. package/src/__tests__/helpers/sse.smoke.test.ts +236 -236
  25. package/src/__tests__/helpers/sse.ts +209 -209
  26. package/src/__tests__/index.parallel.test.ts +605 -595
  27. package/src/__tests__/sanitization-regex.test.ts +112 -112
  28. package/src/__tests__/state-bounds.test.ts +90 -90
  29. package/src/account-identity.test.ts +197 -192
  30. package/src/account-identity.ts +69 -67
  31. package/src/account-state.test.ts +86 -86
  32. package/src/account-state.ts +25 -25
  33. package/src/accounts/matching.test.ts +335 -0
  34. package/src/accounts/matching.ts +167 -0
  35. package/src/accounts/persistence.test.ts +345 -0
  36. package/src/accounts/persistence.ts +432 -0
  37. package/src/accounts/repair.test.ts +276 -0
  38. package/src/accounts/repair.ts +407 -0
  39. package/src/accounts.dedup.test.ts +621 -621
  40. package/src/accounts.test.ts +933 -929
  41. package/src/accounts.ts +633 -989
  42. package/src/backoff.test.ts +345 -345
  43. package/src/backoff.ts +219 -219
  44. package/src/betas.ts +124 -124
  45. package/src/bun-fetch.test.ts +345 -342
  46. package/src/bun-fetch.ts +424 -424
  47. package/src/bun-proxy.test.ts +25 -25
  48. package/src/bun-proxy.ts +209 -209
  49. package/src/cc-credentials.ts +111 -111
  50. package/src/circuit-breaker.test.ts +184 -184
  51. package/src/circuit-breaker.ts +169 -169
  52. package/src/cli/commands/auth.ts +963 -0
  53. package/src/cli/commands/config.ts +547 -0
  54. package/src/cli/formatting.test.ts +406 -0
  55. package/src/cli/formatting.ts +219 -0
  56. package/src/cli.ts +255 -2022
  57. package/src/commands/handlers/betas.ts +100 -0
  58. package/src/commands/handlers/config.ts +99 -0
  59. package/src/commands/handlers/files.ts +375 -0
  60. package/src/commands/oauth-flow.ts +181 -166
  61. package/src/commands/prompts.ts +61 -61
  62. package/src/commands/router.test.ts +421 -0
  63. package/src/commands/router.ts +143 -635
  64. package/src/config.test.ts +482 -482
  65. package/src/config.ts +412 -404
  66. package/src/constants.ts +48 -48
  67. package/src/drift/cch-constants.ts +95 -95
  68. package/src/env.ts +111 -105
  69. package/src/headers/billing.ts +33 -33
  70. package/src/headers/builder.ts +130 -130
  71. package/src/headers/cch.ts +75 -75
  72. package/src/headers/stainless.ts +25 -25
  73. package/src/headers/user-agent.ts +23 -23
  74. package/src/index.ts +436 -828
  75. package/src/models.ts +27 -27
  76. package/src/oauth.test.ts +102 -102
  77. package/src/oauth.ts +178 -178
  78. package/src/parent-pid-watcher.test.ts +148 -148
  79. package/src/parent-pid-watcher.ts +69 -69
  80. package/src/plugin-helpers.ts +82 -82
  81. package/src/refresh-helpers.ts +145 -139
  82. package/src/refresh-lock.test.ts +94 -94
  83. package/src/refresh-lock.ts +93 -93
  84. package/src/request/body.history.test.ts +579 -571
  85. package/src/request/body.ts +255 -255
  86. package/src/request/metadata.ts +65 -65
  87. package/src/request/retry.test.ts +156 -156
  88. package/src/request/retry.ts +67 -67
  89. package/src/request/url.ts +21 -21
  90. package/src/request-orchestration-helpers.ts +648 -0
  91. package/src/response/index.ts +5 -5
  92. package/src/response/mcp.ts +58 -58
  93. package/src/response/streaming.test.ts +313 -311
  94. package/src/response/streaming.ts +412 -410
  95. package/src/rotation.test.ts +304 -301
  96. package/src/rotation.ts +205 -205
  97. package/src/storage.test.ts +547 -547
  98. package/src/storage.ts +315 -291
  99. package/src/system-prompt/builder.ts +38 -38
  100. package/src/system-prompt/index.ts +5 -5
  101. package/src/system-prompt/normalize.ts +60 -60
  102. package/src/system-prompt/sanitize.ts +30 -30
  103. package/src/thinking.ts +21 -20
  104. package/src/token-refresh.test.ts +265 -265
  105. package/src/token-refresh.ts +219 -214
  106. package/src/types.ts +30 -30
  107. package/dist/bun-proxy.mjs +0 -291
@@ -11,100 +11,100 @@ import { buildUserAgent } from "../headers/user-agent.js";
11
11
  import { buildSystemPromptBlocks } from "../system-prompt/builder.js";
12
12
 
13
13
  describe("CC 2.1.98 — Full request fingerprint comparison", () => {
14
- const CC_VERSION = "2.1.98";
15
- const signature = { enabled: true, claudeCliVersion: CC_VERSION, promptCompactionMode: "minimal" as const };
16
- const messages = [{ role: "user", content: "say the word hello" }];
14
+ const CC_VERSION = "2.1.98";
15
+ const signature = { enabled: true, claudeCliVersion: CC_VERSION, promptCompactionMode: "minimal" as const };
16
+ const messages = [{ role: "user", content: "say the word hello" }];
17
17
 
18
- it("prints the exact fingerprint the plugin would send", () => {
19
- // Simulate env
20
- process.env.CLAUDE_CODE_ATTRIBUTION_HEADER = "true";
21
- process.env.CLAUDE_CODE_ENTRYPOINT = "cli";
18
+ it("prints the exact fingerprint the plugin would send", () => {
19
+ // Simulate env
20
+ process.env.CLAUDE_CODE_ATTRIBUTION_HEADER = "true";
21
+ process.env.CLAUDE_CODE_ENTRYPOINT = "cli";
22
22
 
23
- const ua = buildUserAgent(CC_VERSION);
24
- const billing = buildAnthropicBillingHeader(CC_VERSION, messages);
25
- const betas = buildAnthropicBetaHeader(
26
- "",
27
- true,
28
- "claude-haiku-4-5",
29
- "anthropic",
30
- undefined,
31
- undefined,
32
- "/v1/messages",
33
- false,
34
- );
35
- const blocks = buildSystemPromptBlocks([], signature, messages);
23
+ const ua = buildUserAgent(CC_VERSION);
24
+ const billing = buildAnthropicBillingHeader(CC_VERSION, messages);
25
+ const betas = buildAnthropicBetaHeader(
26
+ "",
27
+ true,
28
+ "claude-haiku-4-5",
29
+ "anthropic",
30
+ undefined,
31
+ undefined,
32
+ "/v1/messages",
33
+ false,
34
+ );
35
+ const blocks = buildSystemPromptBlocks([], signature, messages);
36
36
 
37
- console.log("\n╔══════════════════════════════════════════════════════════╗");
38
- console.log("║ PLUGIN FINGERPRINT (what opencode sends) ║");
39
- console.log("╠══════════════════════════════════════════════════════════╣");
40
- console.log(`║ CLI version: ${FALLBACK_CLAUDE_CLI_VERSION}`);
41
- console.log(`║ User-Agent: ${ua}`);
42
- console.log(`║ anthropic-beta: ${betas}`);
43
- console.log(`║ Billing header: ${billing}`);
44
- console.log(`║ Identity: ${CLAUDE_CODE_IDENTITY_STRING}`);
45
- console.log("║");
46
- console.log("║ System prompt blocks:");
47
- for (const b of blocks) {
48
- const preview = b.text.length > 80 ? b.text.slice(0, 80) + "..." : b.text;
49
- console.log(`║ [${b.cache_control ? JSON.stringify(b.cache_control) : "no-cache"}] ${preview}`);
50
- }
51
- console.log("╠══════════════════════════════════════════════════════════╣");
52
- console.log("║ EXPECTED CC 2.1.98 VALUES (from source code) ║");
53
- console.log("╠══════════════════════════════════════════════════════════╣");
54
- console.log(`║ CLI version: 2.1.98`);
55
- console.log(`║ User-Agent: claude-cli/2.1.98 (external, cli)`);
56
- console.log(`║ SDK version: 0.81.0 (x-stainless-package-version)`);
57
- console.log(`║ Axios version: 1.13.6 (token endpoint UA)`);
58
- console.log(`║ anthropic-ver: 2023-06-01`);
59
- console.log(`║ x-app: cli`);
60
- console.log(`║ cch: 00000 placeholder → xxHash64(serialized body, seed 0x6E52736AC806831E)`);
61
- console.log(`║ Identity: You are Claude Code, Anthropic's official CLI for Claude.`);
62
- console.log(`║ Identity cache: {"type":"ephemeral","scope":"global","ttl":"1h"}`);
63
- console.log(`║ Client ID: 9d1c250a-e61b-44d9-88ed-5944d1962f5e`);
64
- console.log("╚══════════════════════════════════════════════════════════╝");
37
+ console.log("\n╔══════════════════════════════════════════════════════════╗");
38
+ console.log("║ PLUGIN FINGERPRINT (what opencode sends) ║");
39
+ console.log("╠══════════════════════════════════════════════════════════╣");
40
+ console.log(`║ CLI version: ${FALLBACK_CLAUDE_CLI_VERSION}`);
41
+ console.log(`║ User-Agent: ${ua}`);
42
+ console.log(`║ anthropic-beta: ${betas}`);
43
+ console.log(`║ Billing header: ${billing}`);
44
+ console.log(`║ Identity: ${CLAUDE_CODE_IDENTITY_STRING}`);
45
+ console.log("║");
46
+ console.log("║ System prompt blocks:");
47
+ for (const b of blocks) {
48
+ const preview = b.text.length > 80 ? b.text.slice(0, 80) + "..." : b.text;
49
+ console.log(`║ [${b.cache_control ? JSON.stringify(b.cache_control) : "no-cache"}] ${preview}`);
50
+ }
51
+ console.log("╠══════════════════════════════════════════════════════════╣");
52
+ console.log("║ EXPECTED CC 2.1.98 VALUES (from source code) ║");
53
+ console.log("╠══════════════════════════════════════════════════════════╣");
54
+ console.log(`║ CLI version: 2.1.98`);
55
+ console.log(`║ User-Agent: claude-cli/2.1.98 (external, cli)`);
56
+ console.log(`║ SDK version: 0.81.0 (x-stainless-package-version)`);
57
+ console.log(`║ Axios version: 1.13.6 (token endpoint UA)`);
58
+ console.log(`║ anthropic-ver: 2023-06-01`);
59
+ console.log(`║ x-app: cli`);
60
+ console.log(`║ cch: 00000 placeholder → xxHash64(serialized body, seed 0x6E52736AC806831E)`);
61
+ console.log(`║ Identity: You are Claude Code, Anthropic's official CLI for Claude.`);
62
+ console.log(`║ Identity cache: {"type":"ephemeral","scope":"global","ttl":"1h"}`);
63
+ console.log(`║ Client ID: 9d1c250a-e61b-44d9-88ed-5944d1962f5e`);
64
+ console.log("╚══════════════════════════════════════════════════════════╝");
65
65
 
66
- // Assertions
67
- expect(FALLBACK_CLAUDE_CLI_VERSION).toBe("2.1.98");
68
- expect(ua).toBe("claude-cli/2.1.98 (external, cli)");
69
- expect(billing).toMatch(/cch=[0-9a-f]{5};/);
70
- expect(billing).toContain("cc_entrypoint=cli;");
71
- expect(billing).toMatch(/cc_version=2\.1\.98\.[0-9a-f]{3}/);
72
- expect(betas.split(",")).toContain("oauth-2025-04-20");
73
- expect(CLAUDE_CODE_IDENTITY_STRING).toBe("You are Claude Code, Anthropic's official CLI for Claude.");
66
+ // Assertions
67
+ expect(FALLBACK_CLAUDE_CLI_VERSION).toBe("2.1.98");
68
+ expect(ua).toBe("claude-cli/2.1.98 (external, cli)");
69
+ expect(billing).toMatch(/cch=[0-9a-f]{5};/);
70
+ expect(billing).toContain("cc_entrypoint=cli;");
71
+ expect(billing).toMatch(/cc_version=2\.1\.98\.[0-9a-f]{3}/);
72
+ expect(betas.split(",")).toContain("oauth-2025-04-20");
73
+ expect(CLAUDE_CODE_IDENTITY_STRING).toBe("You are Claude Code, Anthropic's official CLI for Claude.");
74
74
 
75
- const identityBlock = blocks.find((b) => b.text === CLAUDE_CODE_IDENTITY_STRING);
76
- expect(identityBlock?.cache_control).toEqual({ type: "ephemeral" });
77
- });
75
+ const identityBlock = blocks.find((b) => b.text === CLAUDE_CODE_IDENTITY_STRING);
76
+ expect(identityBlock?.cache_control).toEqual({ type: "ephemeral" });
77
+ });
78
78
 
79
- it("builds full request headers matching CC", () => {
80
- process.env.CLAUDE_CODE_ENTRYPOINT = "cli";
79
+ it("builds full request headers matching CC", () => {
80
+ process.env.CLAUDE_CODE_ENTRYPOINT = "cli";
81
81
 
82
- const headers = buildRequestHeaders(
83
- "https://api.anthropic.com/v1/messages",
84
- { headers: {} },
85
- "test-access-token",
86
- JSON.stringify({ model: "claude-haiku-4-5", messages }),
87
- new URL("https://api.anthropic.com/v1/messages"),
88
- signature,
89
- );
82
+ const headers = buildRequestHeaders(
83
+ "https://api.anthropic.com/v1/messages",
84
+ { headers: {} },
85
+ "test-access-token",
86
+ JSON.stringify({ model: "claude-haiku-4-5", messages }),
87
+ new URL("https://api.anthropic.com/v1/messages"),
88
+ signature,
89
+ );
90
90
 
91
- console.log("\n╔══════════════════════════════════════════════════════════╗");
92
- console.log("║ FULL REQUEST HEADERS ║");
93
- console.log("╠══════════════════════════════════════════════════════════╣");
94
- headers.forEach((value, key) => {
95
- if (key === "authorization") value = "Bearer ***redacted***";
96
- console.log(`║ ${key}: ${value}`);
97
- });
98
- console.log("╚══════════════════════════════════════════════════════════╝");
91
+ console.log("\n╔══════════════════════════════════════════════════════════╗");
92
+ console.log("║ FULL REQUEST HEADERS ║");
93
+ console.log("╠══════════════════════════════════════════════════════════╣");
94
+ headers.forEach((value, key) => {
95
+ if (key === "authorization") value = "Bearer ***redacted***";
96
+ console.log(`║ ${key}: ${value}`);
97
+ });
98
+ console.log("╚══════════════════════════════════════════════════════════╝");
99
99
 
100
- expect(headers.get("user-agent")).toBe("claude-cli/2.1.98 (external, cli)");
101
- expect(headers.get("anthropic-version")).toBe("2023-06-01");
102
- expect(headers.get("x-app")).toBe("cli");
103
- expect(headers.get("x-stainless-lang")).toBe("js");
104
- expect(headers.get("x-stainless-runtime")).toBe("node");
105
- expect(headers.get("x-stainless-package-version")).toBe("0.81.0");
106
- expect(headers.get("x-stainless-timeout")).toBe("600");
107
- expect(headers.get("anthropic-dangerous-direct-browser-access")).toBe("true");
108
- expect(headers.get("anthropic-beta")).toContain("oauth-2025-04-20");
109
- });
100
+ expect(headers.get("user-agent")).toBe("claude-cli/2.1.98 (external, cli)");
101
+ expect(headers.get("anthropic-version")).toBe("2023-06-01");
102
+ expect(headers.get("x-app")).toBe("cli");
103
+ expect(headers.get("x-stainless-lang")).toBe("js");
104
+ expect(headers.get("x-stainless-runtime")).toBe("node");
105
+ expect(headers.get("x-stainless-package-version")).toBe("0.81.0");
106
+ expect(headers.get("x-stainless-timeout")).toBe("600");
107
+ expect(headers.get("anthropic-dangerous-direct-browser-access")).toBe("true");
108
+ expect(headers.get("anthropic-beta")).toContain("oauth-2025-04-20");
109
+ });
110
110
  });