opencode-anthropic-fix 0.1.11 → 0.1.13

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/index.mjs CHANGED
@@ -7424,7 +7424,17 @@ function transformRequestBody(body, signature, runtime, betaHeader, config) {
7424
7424
  const tes = runtime?.tokenEconomySession;
7425
7425
  const isMainRole = runtime?.requestRole === "main" || runtime?.requestRole == null;
7426
7426
 
7427
- if (isMainRole && Array.isArray(parsed.messages) && tes) {
7427
+ // `conservative` (default ON) disables all history-rewriting and tool-array
7428
+ // transforms. These optimizations shrink each request body but cause the
7429
+ // prompt-cache prefix to change turn-to-turn, invalidating the 1h cache
7430
+ // and forcing a fresh cache_write each turn — which costs 2x base input
7431
+ // tokens. For long opencode sessions, cache reuse dominates; flip to
7432
+ // `false` only if you have measurements showing otherwise. Adaptive
7433
+ // thinking zero-out remains active (affects only the thinking budget,
7434
+ // not cached content).
7435
+ const conservative = te.conservative !== false;
7436
+
7437
+ if (!conservative && isMainRole && Array.isArray(parsed.messages) && tes) {
7428
7438
  // (1) TTL-based thinking strip
7429
7439
  if (te.ttl_thinking_strip !== false) {
7430
7440
  const ttlMs = signature?.cachePolicy?.ttl === "5m" ? 5 * 60_000 : 60 * 60_000;
@@ -7474,7 +7484,7 @@ function transformRequestBody(body, signature, runtime, betaHeader, config) {
7474
7484
  }
7475
7485
 
7476
7486
  // === Token economy: tool-array transforms (stable ordering, deferral) ===
7477
- if (isMainRole && Array.isArray(parsed.tools)) {
7487
+ if (!conservative && isMainRole && Array.isArray(parsed.tools)) {
7478
7488
  if (te.stable_tool_ordering !== false) {
7479
7489
  parsed.tools = applyStableToolOrdering(parsed.tools);
7480
7490
  }
package/lib/config.mjs CHANGED
@@ -201,6 +201,17 @@ export const DEFAULT_CONFIG = {
201
201
  * classified as "main-thread" (see classifyRequestRole). */
202
202
  context_hint: false,
203
203
 
204
+ /** Conservative mode (default ON). Disables every history-rewriting and
205
+ * tool-array transform below that can invalidate the prompt-cache prefix
206
+ * turn-to-turn. Rationale: every rewrite risks breaking the 1h cache,
207
+ * forcing a fresh cache_write (2x base input cost). For long opencode
208
+ * sessions, cache reuse dominates per-turn cost — the optimizations below
209
+ * save kB in the request body but cost much more in cache misses.
210
+ * Affects: ttl_thinking_strip, proactive_microcompact, trailing_summary_trim,
211
+ * tool_result_dedupe, stable_tool_ordering, deferred_tool_names.
212
+ * Unaffected: adaptive_thinking_zero_simple (only changes thinking budget). */
213
+ conservative: true,
214
+
204
215
  /** TTL-based thinking strip (CC parity). When the time since the last
205
216
  * thinking strip exceeds the cache TTL, drop all `thinking` /
206
217
  * `redacted_thinking` blocks from prior assistant messages. Mirrors CC's
@@ -250,7 +261,7 @@ export const DEFAULT_CONFIG = {
250
261
  * `auto_mode`). Everything else falls back to the 5m tier, which is
251
262
  * cheaper to write. Matches by classifying request role: main → 1h (or
252
263
  * whatever signature.cachePolicy.ttl is configured as), else → 5m. */
253
- role_scoped_cache_ttl: true,
264
+ role_scoped_cache_ttl: false,
254
265
 
255
266
  /** Lean system prompt for non-main requests. For title-gen / small /
256
267
  * subagent-shaped requests, strip billing identity + CC identity
@@ -644,6 +655,7 @@ function validateConfig(raw) {
644
655
  redact_thinking:
645
656
  typeof te.redact_thinking === "boolean" ? te.redact_thinking : DEFAULT_CONFIG.token_economy.redact_thinking,
646
657
  context_hint: typeof te.context_hint === "boolean" ? te.context_hint : DEFAULT_CONFIG.token_economy.context_hint,
658
+ conservative: typeof te.conservative === "boolean" ? te.conservative : DEFAULT_CONFIG.token_economy.conservative,
647
659
  ttl_thinking_strip:
648
660
  typeof te.ttl_thinking_strip === "boolean"
649
661
  ? te.ttl_thinking_strip
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-anthropic-fix",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "license": "GPL-3.0-or-later",
5
5
  "main": "./index.mjs",
6
6
  "files": [