clawmoney 0.15.66 → 0.15.67

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.
@@ -1060,20 +1060,34 @@ function ensureClaudeCodeShell(body, fingerprint) {
1060
1060
  // Position: right after the billing header slot (idx 1), or right
1061
1061
  // after any buyer-prefixed system blocks (at head) if we're also
1062
1062
  // inserting the billing header.
1063
+ //
1064
+ // Anthropic has a hard ordering rule within the system array: any
1065
+ // cache_control block with `ttl="1h"` MUST come before any block with
1066
+ // `ttl="5m"`. Our injected marker uses the default ephemeral TTL
1067
+ // (5m), so if the buyer's original system array contains a 1h block
1068
+ // further down, naively inserting at index 1 puts the 1h block AFTER
1069
+ // our 5m block and Anthropic 400s with
1070
+ // system.N.cache_control.ttl: a ttl='1h' cache_control block must
1071
+ // not come after a ttl='5m' cache_control block.
1072
+ // Walk from the end to find the last 1h block; if one exists, drop
1073
+ // the marker immediately after it so the 1h-before-5m invariant
1074
+ // holds. Otherwise fall back to the original "index 1 (or 0)" slot.
1063
1075
  if (!hasCcMarker) {
1064
1076
  const markerBlock = {
1065
1077
  type: "text",
1066
1078
  text: `${CLAUDE_CODE_SYSTEM_PROMPT_LEAD}\n\n${RELAY_INSTRUCTIONS}`,
1067
1079
  cache_control: { type: "ephemeral" },
1068
1080
  };
1069
- // Insert at index 1 (slot after billing header), or 0 if we'll be
1070
- // unshifting the billing header next.
1071
- if (hasBillingHeaderFirst) {
1072
- system.splice(1, 0, markerBlock);
1073
- }
1074
- else {
1075
- system.unshift(markerBlock);
1081
+ let insertAt = hasBillingHeaderFirst ? 1 : 0;
1082
+ for (let i = system.length - 1; i >= 0; i--) {
1083
+ const cc = system[i]
1084
+ ?.cache_control;
1085
+ if (cc && typeof cc === "object" && cc.ttl === "1h") {
1086
+ insertAt = i + 1;
1087
+ break;
1088
+ }
1076
1089
  }
1090
+ system.splice(insertAt, 0, markerBlock);
1077
1091
  }
1078
1092
  // ── Update or inject billing header at index 0 ──
1079
1093
  if (hasBillingHeaderFirst) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clawmoney",
3
- "version": "0.15.66",
3
+ "version": "0.15.67",
4
4
  "description": "ClawMoney CLI -- Earn rewards with your AI agent",
5
5
  "type": "module",
6
6
  "bin": {