@vacbo/opencode-anthropic-fix 0.1.8 → 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 (106) 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 -67
  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
package/README.md CHANGED
@@ -82,11 +82,11 @@ Control the feature via `~/.config/opencode/anthropic-auth.json`:
82
82
 
83
83
  ```jsonc
84
84
  {
85
- "cc_credential_reuse": {
86
- "enabled": true, // Enable/disable the feature (default: true)
87
- "auto_detect": true, // Auto-load on plugin startup (default: true)
88
- "prefer_over_oauth": true, // Use CC credentials first when available (default: true)
89
- },
85
+ "cc_credential_reuse": {
86
+ "enabled": true, // Enable/disable the feature (default: true)
87
+ "auto_detect": true, // Auto-load on plugin startup (default: true)
88
+ "prefer_over_oauth": true, // Use CC credentials first when available (default: true)
89
+ },
90
90
  }
91
91
  ```
92
92
 
@@ -132,7 +132,7 @@ Add to your `opencode.json`:
132
132
 
133
133
  ```json
134
134
  {
135
- "plugins": ["opencode-anthropic-fix@latest"]
135
+ "plugins": ["opencode-anthropic-fix@latest"]
136
136
  }
137
137
  ```
138
138
 
@@ -390,10 +390,10 @@ Supported formats: PDF, DOCX, TXT, CSV, Excel, Markdown, images (max 350 MB per
390
390
 
391
391
  - `/anthropic files list` (no `--account`) queries **all** enabled accounts, labeling each file with its owner email
392
392
  - Use `--account <email|index>` to target a specific account for any action:
393
- ```text
394
- /anthropic files list --account alice@example.com
395
- /anthropic files upload ./data.csv --account 2
396
- ```
393
+ ```text
394
+ /anthropic files list --account alice@example.com
395
+ /anthropic files upload ./data.csv --account 2
396
+ ```
397
397
  - **Auto-pinning:** When you upload or list files, the plugin remembers which account owns each `file_id`. If a subsequent Messages API request references that `file_id`, the plugin automatically routes it to the correct account — even with round-robin or hybrid strategies.
398
398
 
399
399
  ### OAuth flows from slash command
@@ -469,84 +469,84 @@ Configuration is stored at `~/.config/opencode/anthropic-auth.json`. All setting
469
469
 
470
470
  ```jsonc
471
471
  {
472
- // Account selection strategy: "sticky" | "round-robin" | "hybrid"
473
- "account_selection_strategy": "sticky",
474
-
475
- // Seconds before consecutive failure count resets (60-7200)
476
- "failure_ttl_seconds": 3600,
477
-
478
- // Enable debug logging
479
- "debug": false,
480
-
481
- // Claude Code signature emulation behavior
482
- "signature_emulation": {
483
- // Enable Claude-style attribution/stainless headers and betas
484
- "enabled": true,
485
- // Resolve latest @anthropic-ai/claude-code version once on plugin startup
486
- "fetch_claude_code_version_on_startup": true,
487
- // Compact long injected system instructions to reduce token usage.
488
- // In "minimal" mode, repeated/contained blocks are deduplicated and title-generator
489
- // requests are replaced with a compact dedicated prompt.
490
- // "minimal" | "off"
491
- "prompt_compaction": "minimal",
492
- // Run the legacy regex-based sanitizer that rewrites OpenCode / Sisyphus /
493
- // morph_edit identifiers in system prompt text. Default false because the
494
- // plugin's primary defense is now aggressive relocation: non-CC blocks are
495
- // moved into the first user message wrapped in <system-instructions>, and
496
- // CC's system prompt is kept byte-for-byte pristine. Set this to true if
497
- // you want belt-and-suspenders rewriting on top of relocation. The new
498
- // regex uses negative lookarounds for [\w\-/] so hyphenated identifiers
499
- // and file paths survive verbatim.
472
+ // Account selection strategy: "sticky" | "round-robin" | "hybrid"
473
+ "account_selection_strategy": "sticky",
474
+
475
+ // Seconds before consecutive failure count resets (60-7200)
476
+ "failure_ttl_seconds": 3600,
477
+
478
+ // Enable debug logging
479
+ "debug": false,
480
+
481
+ // Claude Code signature emulation behavior
482
+ "signature_emulation": {
483
+ // Enable Claude-style attribution/stainless headers and betas
484
+ "enabled": true,
485
+ // Resolve latest @anthropic-ai/claude-code version once on plugin startup
486
+ "fetch_claude_code_version_on_startup": true,
487
+ // Compact long injected system instructions to reduce token usage.
488
+ // In "minimal" mode, repeated/contained blocks are deduplicated and title-generator
489
+ // requests are replaced with a compact dedicated prompt.
490
+ // "minimal" | "off"
491
+ "prompt_compaction": "minimal",
492
+ // Run the legacy regex-based sanitizer that rewrites OpenCode / Sisyphus /
493
+ // morph_edit identifiers in system prompt text. Default false because the
494
+ // plugin's primary defense is now aggressive relocation: non-CC blocks are
495
+ // moved into the first user message wrapped in <system-instructions>, and
496
+ // CC's system prompt is kept byte-for-byte pristine. Set this to true if
497
+ // you want belt-and-suspenders rewriting on top of relocation. The new
498
+ // regex uses negative lookarounds for [\w\-/] so hyphenated identifiers
499
+ // and file paths survive verbatim.
500
+ "sanitize_system_prompt": false,
501
+ },
502
+
503
+ // Top-level alias for signature_emulation.sanitize_system_prompt. When set,
504
+ // takes precedence over the nested value. Provided so you can flip the
505
+ // sanitizer without learning the nested schema.
500
506
  "sanitize_system_prompt": false,
501
- },
502
-
503
- // Top-level alias for signature_emulation.sanitize_system_prompt. When set,
504
- // takes precedence over the nested value. Provided so you can flip the
505
- // sanitizer without learning the nested schema.
506
- "sanitize_system_prompt": false,
507
-
508
- // Context limit override for 1M-window models.
509
- // Prevents OpenCode from compacting too early when models.dev hasn't been
510
- // updated yet (e.g. claude-opus-4-6 and any *-1m model variants).
511
- // Only applied for OAuth (Max Plan) sessions — API key users use the
512
- // context-1m-2025-08-07 beta header instead.
513
- "override_model_limits": {
514
- // Enable/disable the override (default: off — enable if you need 1M context)
515
- "enabled": false,
516
- // Context window to inject (tokens). Default: 1_000_000.
517
- "context": 1000000,
518
- // Max output tokens to inject. 0 = leave the model's default unchanged.
519
- "output": 0,
520
- },
521
-
522
- // Health score tuning (0-100 scale)
523
- "health_score": {
524
- "initial": 70,
525
- "success_reward": 1,
526
- "rate_limit_penalty": -10,
527
- "failure_penalty": -20,
528
- "recovery_rate_per_hour": 2,
529
- "min_usable": 50,
530
- "max_score": 100,
531
- },
532
-
533
- // Client-side rate limiting (token bucket)
534
- "token_bucket": {
535
- "max_tokens": 50,
536
- "regeneration_rate_per_minute": 6,
537
- "initial_tokens": 50,
538
- },
539
-
540
- // Custom beta headers (added to every request via /anthropic betas add)
541
- "custom_betas": [],
542
-
543
- // Toast notification settings
544
- "toasts": {
545
- // Suppress non-error toasts (account status, switching)
546
- "quiet": false,
547
- // Minimum seconds between account-switch toasts (0-300)
548
- "debounce_seconds": 30,
549
- },
507
+
508
+ // Context limit override for 1M-window models.
509
+ // Prevents OpenCode from compacting too early when models.dev hasn't been
510
+ // updated yet (e.g. claude-opus-4-6 and any *-1m model variants).
511
+ // Only applied for OAuth (Max Plan) sessions — API key users use the
512
+ // context-1m-2025-08-07 beta header instead.
513
+ "override_model_limits": {
514
+ // Enable/disable the override (default: off — enable if you need 1M context)
515
+ "enabled": false,
516
+ // Context window to inject (tokens). Default: 1_000_000.
517
+ "context": 1000000,
518
+ // Max output tokens to inject. 0 = leave the model's default unchanged.
519
+ "output": 0,
520
+ },
521
+
522
+ // Health score tuning (0-100 scale)
523
+ "health_score": {
524
+ "initial": 70,
525
+ "success_reward": 1,
526
+ "rate_limit_penalty": -10,
527
+ "failure_penalty": -20,
528
+ "recovery_rate_per_hour": 2,
529
+ "min_usable": 50,
530
+ "max_score": 100,
531
+ },
532
+
533
+ // Client-side rate limiting (token bucket)
534
+ "token_bucket": {
535
+ "max_tokens": 50,
536
+ "regeneration_rate_per_minute": 6,
537
+ "initial_tokens": 50,
538
+ },
539
+
540
+ // Custom beta headers (added to every request via /anthropic betas add)
541
+ "custom_betas": [],
542
+
543
+ // Toast notification settings
544
+ "toasts": {
545
+ // Suppress non-error toasts (account status, switching)
546
+ "quiet": false,
547
+ // Minimum seconds between account-switch toasts (0-300)
548
+ "debounce_seconds": 30,
549
+ },
550
550
  }
551
551
  ```
552
552
 
@@ -675,7 +675,7 @@ To suppress non-error toasts, set `quiet` mode in your config:
675
675
  ```jsonc
676
676
  // ~/.config/opencode/anthropic-auth.json
677
677
  {
678
- "toasts": { "quiet": true },
678
+ "toasts": { "quiet": true },
679
679
  }
680
680
  ```
681
681