opencode-cache-engine 0.4.1 → 0.4.2

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/README.md CHANGED
@@ -18,15 +18,30 @@ plugin under `~/.config/opencode/plugins/`. For released installs where
18
18
  reproducibility matters, pin an exact package version rather than relying on
19
19
  `@latest` resolution or a moving cache entry; see [Installation](#installation).
20
20
 
21
+ Quick Installation (TUI):
22
+ ``` text
23
+ opencode plugin opencode-cache-engine
24
+ ```
25
+
21
26
  `CacheEngine` is an OpenCode plugin designed for long-running agent sessions where prompt-cache efficiency affects both latency and cost. It keeps the harness conservative for providers whose cache behavior is already automatic, while applying provider-specific optimizations where the provider exposes useful cache controls or where prompt structure can be safely improved.
22
27
 
23
28
  The plugin currently has four cache-policy families:
24
29
 
25
30
  * **DeepSeek** — passive cache observability; request structure is preserved.
26
- * **GPT-5.6** — documented cache-key/options metadata, with prompt text unchanged.
31
+ * **GPT-5.6 and later** — documented cache-key/options metadata, with prompt text
32
+ unchanged. GPT-6 and future 5.6+/6+/7+ versions resolve through the same
33
+ documented boundary.
27
34
  * **GLM-5.3** — narrow, content-preserving `<env>` relocation and diagnostics.
28
35
  * **MiMo-V2.6** — narrow, content-preserving `<env>` relocation and diagnostics.
29
36
 
37
+ Family classification is not hard-coded in the runtime. A pure policy registry
38
+ and resolver in `src/cache-policy-core.mjs` returns a structured result
39
+ (`creator`, `family`, `baseline`, `overlays`, `transport`, `matchType`,
40
+ `matchReason`), and the hooks gate their behavior on that result. The registry is
41
+ the single runtime source of policy classification. The first-party research
42
+ behind each registry entry is recorded in
43
+ [docs/cache-policy-inventory.md](docs/cache-policy-inventory.md).
44
+
30
45
  For both MiMo-V2.6 and GLM-5.3, CacheEngine adds its deterministic
31
46
  `x-session-id` request header only when OpenCode identifies the actual provider
32
47
  as `openrouter`. It does not add that OpenRouter-specific header for
@@ -44,12 +59,12 @@ The plugin operates at the OpenCode harness level rather than implementing a pro
44
59
 
45
60
  It:
46
61
 
47
- 1. Detects the model/provider family in use.
48
- 2. Applies only the policy appropriate for that family.
62
+ 1. Resolves the model/provider policy through the registry resolver.
63
+ 2. Applies only the mutations registered for that policy.
49
64
  3. Observes system-prompt and tool-definition stability.
50
65
  4. Records provider-reported cache token usage.
51
66
  5. Adds a deterministic compaction continuation block.
52
- 6. Applies GPT-5.6 cache-control metadata.
67
+ 6. Applies GPT-5.6-and-later cache-control metadata.
53
68
  7. Applies the GLM-5.3 and MiMo-V2.6 volatile-environment relocation.
54
69
  8. Records diagnostics that help determine whether prompt-shape changes correlate with cache behavior.
55
70
  9. Records MiMo/GLM affinity outcomes and provider-identity changes.
@@ -115,7 +130,7 @@ DeepSeek:
115
130
 
116
131
  ### Policy: active cache control
117
132
 
118
- GPT-5.6 is the only current policy that actively injects cache-control request metadata.
133
+ GPT-5.6 and later is the only policy family that actively injects cache-control request metadata.
119
134
 
120
135
  The plugin adds:
121
136
 
@@ -405,7 +420,7 @@ and are reported diagnostically; the message content is left untouched.
405
420
  | Policy family | Detection | Prompt text changed? | Cache metadata changed? | OpenRouter affinity header | Primary cache signal |
406
421
  | ------------- | --------- | ------------------- | ----------------------- | -------------------------- | -------------------- |
407
422
  | DeepSeek | `deepseek` | No | No | None | provider `cache.read` / `cache.write` |
408
- | GPT-5.6 | `gpt-5.6*` on OpenAI-ish endpoints | No | Yes: `prompt_cache_key` + options | None | provider cache tokens |
423
+ | GPT-5.6 and later | version boundary `gpt-<major>[.<minor>] ≥ 5.6` on OpenAI-ish endpoints (includes GPT-6) | No | Yes: `prompt_cache_key` + options | None | provider cache tokens |
409
424
  | GLM-5.3 | `glm-5.3*` | Yes, narrowly (`<env>` tail) | No provider cache key | `x-session-id` on OpenRouter only | provider cache tokens (GLM ratio) |
410
425
  | MiMo-V2.6 | Flash / Pro only | Yes, narrowly (`<env>` tail) | No: implicit caching only | `x-session-id` on OpenRouter only | `cached_tokens / prompt_tokens` |
411
426
 
@@ -923,7 +938,7 @@ The model detector recognizes:
923
938
  * GLM-5.3 variants
924
939
  * MiMo-V2.6 Flash and Pro (`xiaomi/mimo-v2.6-flash`, `mimo-v2.6-pro`, ...)
925
940
 
926
- GPT-5.6 has an additional OpenAI/Azure-context check so a string containing `gpt-5.6` does not automatically cause GPT-specific fields to be sent to an unrelated endpoint.
941
+ The GPT-5.6-and-later family has an additional OpenAI/Azure-context check, so a string containing a qualifying GPT version (for example `gpt-5.6` or `gpt-6`) does not automatically cause GPT-specific fields to be sent to an unrelated endpoint.
927
942
 
928
943
  MiMo detection targets exactly Flash and Pro: it excludes `mimo-v2.5`,
929
944
  `mimo-v2.5-pro`, and `mimo-v2.6-pro-ultraspeed`.
@@ -953,7 +968,8 @@ For that reason, a stable provider route is preferable when your goal is to meas
953
968
 
954
969
  # Architecture
955
970
 
956
- The implementation is split into two layers.
971
+ The implementation is split across a hook entry point, a pure logic core, and a
972
+ pure policy registry.
957
973
 
958
974
  ## `cache-engine.ts`
959
975
 
@@ -989,7 +1005,7 @@ This contains dependency-light pure logic.
989
1005
 
990
1006
  It owns:
991
1007
 
992
- * provider classification
1008
+ * the legacy `detectPolicy()` compatibility wrapper (delegating to the registry)
993
1009
  * configuration parsing
994
1010
  * hashing
995
1011
  * canonicalization
@@ -1006,6 +1022,42 @@ Keeping these functions in plain JavaScript allows the logic to be tested indepe
1006
1022
 
1007
1023
  ---
1008
1024
 
1025
+ ## `cache-policy-core.mjs`
1026
+
1027
+ This is the pure policy registry and resolver. It separates cache policy from
1028
+ request mutation:
1029
+
1030
+ * creator / family classification
1031
+ * baseline cache-policy descriptors (documented facts)
1032
+ * model-specific overlays (for example GLM/MiMo `<env>` relocation)
1033
+ * transport capabilities (for example OpenRouter `x-session-id` affinity)
1034
+ * explicit, inventory-traceable inheritance (`inheritsFrom`)
1035
+ * safe neutral fallback for unknown or future models
1036
+
1037
+ `resolvePolicy(model)` returns `creator`, `family`, `baseline`, `overlays`,
1038
+ `transport`, `matchType`, and `matchReason`. `resolveRuntimePolicy(model)`
1039
+ returns the runtime-facing descriptor the hooks consume: the legacy policy
1040
+ string plus explicit capability flags.
1041
+
1042
+ Only registry entries marked `legacy` enable runtime behavior; documented but
1043
+ non-legacy entries (for example `mimo-v2.6-pro-ultraspeed`) and all unknown
1044
+ models resolve to a neutral runtime. A newer or unknown model therefore never
1045
+ inherits a current model's mutation unless the registry explicitly registers it.
1046
+ The GPT family is a documented exception in the sense that its boundary is
1047
+ version-based (`GPT-5.6 and later`), so GPT-6 and future 5.6+/6+/7+ versions are
1048
+ covered by the registered boundary rather than by an exact-model list.
1049
+
1050
+ Transport is kept separate from cache policy: OpenRouter affinity is a transport
1051
+ capability, not part of a creator's cache semantics. Overlays are also explicit,
1052
+ so being classified into a family does not by itself enable a prompt
1053
+ transformation.
1054
+
1055
+ The module is pure: no network calls and no runtime documentation lookups. The
1056
+ legacy `detectPolicy()` in `cache-engine-core.mjs` remains a thin compatibility
1057
+ wrapper over the resolver's legacy path.
1058
+
1059
+ ---
1060
+
1009
1061
  ## Tests
1010
1062
 
1011
1063
  The repository's test suite validates the provider-independent and provider-specific logic.
@@ -1013,6 +1065,7 @@ The repository's test suite validates the provider-independent and provider-spec
1013
1065
  Coverage includes:
1014
1066
 
1015
1067
  * model detection
1068
+ * policy registry resolution and runtime-policy equivalence
1016
1069
  * GPT cache-key stability
1017
1070
  * GPT cache-option defaults
1018
1071
  * protection against overwriting existing cache options
@@ -1176,11 +1229,14 @@ opencode-cache-engine/
1176
1229
  ├── src/
1177
1230
  │ ├── cache-engine.ts
1178
1231
  │ ├── cache-engine-core.mjs
1232
+ │ ├── cache-policy-core.mjs
1179
1233
  │ └── tui.mjs
1180
1234
  ├── test/
1181
1235
  │ └── cache-engine.test.mjs
1182
1236
  ├── examples/
1183
1237
  │ └── cache-engine.json
1238
+ ├── docs/
1239
+ │ └── cache-policy-inventory.md
1184
1240
  ├── package.json
1185
1241
  ├── README.md
1186
1242
  └── LICENSE
@@ -1219,7 +1275,7 @@ release, use:
1219
1275
  ```json
1220
1276
  {
1221
1277
  "plugin": [
1222
- "opencode-cache-engine@0.3.6"
1278
+ "opencode-cache-engine@0.4.1"
1223
1279
  ]
1224
1280
  }
1225
1281
  ```
@@ -1286,7 +1342,7 @@ A prefix change is a diagnostic signal, not automatic proof of a cache miss.
1286
1342
 
1287
1343
  ## GPT-5.6 cache options are missing
1288
1344
 
1289
- Verify that the model is actually classified as GPT-5.6 and that the endpoint is recognized as OpenAI/Azure-compatible.
1345
+ Verify that the model is within the documented GPT-5.6-and-later boundary (for example `gpt-5.6-*` or `gpt-6-*`) and that the endpoint is recognized as OpenAI/Azure-compatible.
1290
1346
 
1291
1347
  The detector intentionally rejects ambiguous OpenAI-compatible providers rather than guessing.
1292
1348
 
@@ -32,22 +32,47 @@ Caching behavior is never inferred from pricing alone, from one SDK's type
32
32
  declarations, or from a third-party blog when first-party documentation exists.
33
33
  "unknown — first-party docs insufficient" is used instead of a guess.
34
34
 
35
+ ## Runtime integration
36
+
37
+ This inventory is the research input for the policy registry in
38
+ `src/cache-policy-core.mjs`. As of **v0.4.1** the runtime hooks consume
39
+ `resolveRuntimePolicy(model)` and gate behavior on the registry's explicit
40
+ capabilities, so the "CacheEngine current treatment" column below describes
41
+ resolver-driven behavior.
42
+
43
+ Two guarantees follow from that migration:
44
+
45
+ - `resolveRuntimePolicy(model).policy` equals the legacy `detectPolicy(model)`
46
+ string, so telemetry and gating are unchanged for every model supported in
47
+ v0.3.6.
48
+ - Registry entries marked non-`legacy` (for example
49
+ `mimo-v2.6-pro-ultraspeed`) and all unknown models resolve to a neutral
50
+ runtime, so no documented-but-unwired model gains a current model's mutation.
51
+
52
+ The runtime reads the registry at classification time only; there are no network
53
+ calls and no runtime documentation lookups.
54
+
35
55
  ## CacheEngine current treatment (baseline for the matrix)
36
56
 
37
- Source: `src/cache-engine-core.mjs` (detection, transforms) and
38
- `src/cache-engine.ts` (hooks), revision `19b87f2`.
57
+ Source: the pure registry/resolver (`src/cache-policy-core.mjs`) and the hook
58
+ entry (`src/cache-engine.ts`), as wired in v0.4.1. The behavior described here is
59
+ the same as at the pre-resolver revision `19b87f2`; only the classification
60
+ source changed.
39
61
 
40
62
  | Family | Detection (verbatim) | Current treatment | Affinity header |
41
63
  | --- | --- | --- | --- |
42
64
  | DeepSeek | `/deepseek/i` on `${apiID} ${modelID}` or `providerID` | Passive; no mutation | none |
43
- | GPT-5.6 | `/gpt-5\.6(?![\d.])/i` on slug **and** `isOpenAIish` (provider `openai`/`azure`, slug `openai/`/`azure/`, or npm `@ai-sdk/openai`/`@ai-sdk/azure`) | Inject missing `promptCacheKey` + `promptCacheOptions` (`implicit`, `30m`) | none |
65
+ | GPT-5.6 | version boundary `gpt-<major>[.<minor>] ≥ 5.6` on slug **and** `isOpenAIish` (provider `openai`/`azure`, slug `openai/`/`azure/`, or npm `@ai-sdk/openai`/`@ai-sdk/azure`); since v0.4.2 covers GPT-6 and later | Inject missing `promptCacheKey` + `promptCacheOptions` (`implicit`, `30m`) | none |
44
66
  | GLM-5.3 | `/glm-5\.3(?![\d.])/i` on slug | Relocate identifiable `<env>` block to system tail | `x-session-id` only when `providerID === "openrouter"` |
45
67
  | MiMo-V2.6 | `/mimo-v2\.6-(flash\|pro)(?![\w-])/i` on slug | Relocate identifiable `<env>` block to system tail; provider-change telemetry | `x-session-id` only when `providerID === "openrouter"` |
46
68
  | Neutral | everything else | Byte-untouched | none |
47
69
 
48
70
  Detection consequences worth stating explicitly:
49
71
 
50
- - `gpt-6*` / `gpt-6-*` is **not** matched → neutral. **[O]**
72
+ - `gpt-6` / `gpt-6-*` (and any future 5.6+/6+/7+ version) is matched by the
73
+ documented GPT-5.6-and-later boundary → GPT policy. **[O]** (v0.4.2)
74
+ - `gpt-5.5`, `gpt-5.2`, `gpt-4o`, and the malformed `gpt-5.60` are **not**
75
+ matched → neutral. **[O]**
51
76
  - `deepseek-v5` (or any future `*deepseek*` id) matches the passive DeepSeek
52
77
  branch because the regex is a bare substring test. **[O]**
53
78
  - `mimo-v2.6-pro-ultraspeed` is **not** matched: the `(?![\w-])` lookahead fails
@@ -95,8 +120,10 @@ catch-all "earlier models". [D]
95
120
  baseline: it injects only `promptCacheKey` + `promptCacheOptions{mode:implicit,
96
121
  ttl:"30m"}`, preserves runtime-supplied values, and never sets context/output
97
122
  limits. It does not use explicit breakpoints or `prewarm`, which is a subset of
98
- the documented capability. GPT-6 is **not** classified and therefore gets no GPT
99
- cache metadata — a documented-scope gap, not a documented incompatibility.
123
+ the documented capability. Since v0.4.2 the policy resolves by the documented
124
+ "GPT-5.6 and later" boundary, so GPT-6 (astra/sol/luna) receives the same
125
+ baseline; no GPT-6 cache-control exception is documented (OpenAI *Prompt
126
+ caching* guide, re-verified 2026-09-27), and none is coded.
100
127
 
101
128
  ---
102
129
 
@@ -254,7 +281,7 @@ made here); **hold** = do not inherit without first-party evidence.
254
281
  | Creator | Model / example pattern | Cache policy (documented) | CacheEngine current treatment | Recommended family inheritance | Recommended exact-model exception | Confidence | Source | Verified |
255
282
  | --- | --- | --- | --- | --- | --- | --- | --- | --- |
256
283
  | OpenAI | `gpt-5.6`, `gpt-5.6-*` (sol/terra/luna/cyber) | "GPT-5.6 and later": implicit default, optional explicit breakpoints, min 1,024, TTL 30m, write 1.25×/read 0.1× | GPT policy: inject `promptCacheKey` + `promptCacheOptions{implicit,30m}` | keep | none documented; CacheEngine's subset is valid | High (docs) / Medium (treatment) | OpenAI *Prompt caching*; *GPT-5.6 Sol* | 2026-09-26 |
257
- | OpenAI | GPT-6 / current later GPT family: `gpt-6`, `gpt-6-*` (astra/sol/luna) | Inherits the GPT-5.6-and-later policy | **Not matched** → neutral (no GPT metadata) | **extend**: docs classify GPT-6 as "later", so it inherits the same policy | none documented | High (docs) / High (gap) | OpenAI *Using GPT-6*; *GPT-6 Astra*; *Prompt caching* | 2026-09-26 |
284
+ | OpenAI | GPT-6 / current later GPT family: `gpt-6`, `gpt-6-*` (astra/sol/luna) | Inherits the GPT-5.6-and-later policy | **GPT policy** via the GPT-5.6-and-later boundary (v0.4.2) | **keep** — covered by the boundary predicate; no exact-model entry needed | none documented | High (docs) / High (treatment) | OpenAI *Using GPT-6*; *GPT-6 Astra*; *Prompt caching* | 2026-09-27 |
258
285
  | OpenAI | pre-5.6 negative controls: `gpt-5.5`, `gpt-5.4`, `gpt-5.2`, `gpt-5.1`, `gpt-5`, `gpt-4.1`, `gpt-4o` | Implicit only; different min-length class; `in_memory`/`24h` retention; `prompt_cache_key` for routing | neutral | **hold** — do not inherit 5.6 policy | n/a | High | OpenAI *Prompt caching*; *Pricing* | 2026-09-26 |
259
286
  | DeepSeek | V4: `deepseek-v4-pro`, legacy `deepseek-v4-flash` | Provider-wide automatic disk cache; implicit; prefix-unit matching; hit/miss token fields | Passive (no mutation) | keep | none | High | DeepSeek *Context Caching*; *Models & Pricing* | 2026-09-26 |
260
287
  | DeepSeek | V4.1 / current V4-family: `deepseek-flash` (MODEL VERSION "DeepSeek-V4.1-Flash") | Same provider-wide automatic policy; cache-hit pricing listed for both current models | Passive | keep (creator/family baseline) | none documented | High | DeepSeek *Models & Pricing*; *news260910* | 2026-09-26 |
@@ -311,3 +338,27 @@ a newer model inherits an older policy. They must not be resolved by guessing.
311
338
  - The existing test suite was run only to confirm the repository remains green
312
339
  (116/116).
313
340
  - This release contains research and documentation only.
341
+
342
+ ### Follow-up: v0.4.1 runtime integration
343
+
344
+ - v0.4.0 added the registry (`src/cache-policy-core.mjs`) without wiring it.
345
+ - v0.4.1 wired the runtime to `resolveRuntimePolicy()` and preserved behavior:
346
+ every model supported in v0.3.6 keeps its prior treatment, and non-legacy or
347
+ unknown models remain neutral.
348
+ - The v0.4.0 research statements above are unchanged; only the runtime now reads
349
+ this registry as its single source of policy classification.
350
+
351
+ ### Follow-up: v0.4.2 GPT-5.6-and-later boundary
352
+
353
+ - OpenAI's documented "GPT-5.6 and later" boundary was re-verified against the
354
+ first-party *Prompt caching* guide and *Using GPT-6* guide on **2026-09-27**.
355
+ GPT-6 (astra/sol/luna) is documented in the same cache regime with no
356
+ cache-control exception.
357
+ - v0.4.2 replaces the exact `gpt-5.6` string match with a version-boundary
358
+ predicate (`gpt-<major>[.<minor>] ≥ 5.6`), still gated on the OpenAI-ish
359
+ provider check. GPT-6 and future 5.6+/6+/7+ models therefore need no
360
+ exact-model registry entry, while `gpt-5.5` and earlier and malformed ids such
361
+ as `gpt-5.60` stay neutral.
362
+ - The only OpenAI cache controls injected remain `promptCacheKey` +
363
+ `promptCacheOptions{implicit,30m}`; no breakpoint or prewarm behavior was
364
+ added. DeepSeek, GLM, MiMo, and OpenRouter affinity behavior are unchanged.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-cache-engine",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "private": false,
5
5
  "description": "Provider-aware prompt-cache optimization and telemetry for OpenCode",
6
6
  "keywords": [
@@ -56,6 +56,31 @@ export function isOpenAIish(s) {
56
56
  return false
57
57
  }
58
58
 
59
+ // The documented OpenAI cache-policy boundary is the generation phrase
60
+ // "GPT-5.6 and later" (docs/cache-policy-inventory.md §1; OpenAI *Prompt
61
+ // caching* guide, re-verified 2026-09-27). This matcher expresses that boundary
62
+ // by version rather than by an exact-model string, so future 5.6+/6+/7+ models
63
+ // need no registry entry:
64
+ // - major > 5 -> in family
65
+ // - major === 5 && minor >= 6 -> in family
66
+ // - everything else -> out
67
+ // The token must be followed by a non-digit/non-dot boundary, so malformed ids
68
+ // such as "gpt-5.60" and "gpt-5.6.1" do not match (same guard as pre-v0.4.2).
69
+ // OpenAI minor versions are single-digit, so a multi-digit minor is treated as
70
+ // malformed rather than as a higher version.
71
+ export function isGpt56OrLater(slug) {
72
+ const text = String(slug ?? "").toLowerCase()
73
+ const re = /gpt-(\d{1,3})(?:\.(\d))?(?![\d.])/g
74
+ let m
75
+ while ((m = re.exec(text)) !== null) {
76
+ const major = Number(m[1])
77
+ const minor = m[2] === undefined ? 0 : Number(m[2])
78
+ if (major > 5) return true
79
+ if (major === 5 && minor >= 6) return true
80
+ }
81
+ return false
82
+ }
83
+
59
84
  // Candidate ids for exact/alias lookup. Includes the raw apiID/modelID, the
60
85
  // lower-cased forms, and a single stripped transport/vendor prefix
61
86
  // (e.g. "openai/gpt-5.6-luna" -> "gpt-5.6-luna", "xiaomi/mimo-v2.6-flash" ->
@@ -251,33 +276,32 @@ const rt = (policy, overrides = {}) => ({
251
276
 
252
277
  export const POLICY_REGISTRY = [
253
278
  {
254
- id: "openai.gpt-5.6",
279
+ // v0.4.2: one documented GPT-5.6-and-later family, matched by the version
280
+ // boundary rather than an exact model string. GPT-6 (astra/sol/luna) is
281
+ // documented in the same regime with no cache-control exception, so it
282
+ // inherits this baseline and overlay. Future 5.6+/6+/7+ models resolve here
283
+ // without a new registry entry.
284
+ id: "openai.gpt-5.6-plus",
255
285
  creator: "openai",
256
286
  family: "gpt-5.6",
257
287
  kind: "family",
258
- pattern: /gpt-5\.6(?![\d.])/i,
288
+ predicate: isGpt56OrLater,
259
289
  requiresOpenAIish: true,
260
- exactIds: ["gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna", "gpt-5.6-cyber"],
290
+ exactIds: [
291
+ "gpt-5.6-sol",
292
+ "gpt-5.6-terra",
293
+ "gpt-5.6-luna",
294
+ "gpt-5.6-cyber",
295
+ "gpt-6-astra",
296
+ "gpt-6-sol",
297
+ "gpt-6-luna",
298
+ ],
261
299
  baseline: "openai.gpt56.cache",
262
300
  overlays: ["gpt56.prompt-cache-options"],
263
301
  legacy: true,
264
302
  runtime: rt("gpt56", { gptCacheMetadata: true }),
265
- inventoryRef: "§1 OpenAI",
266
- },
267
- {
268
- id: "openai.gpt-6",
269
- creator: "openai",
270
- family: "gpt-6",
271
- kind: "family",
272
- pattern: /gpt-6(?![\d.])/i,
273
- requiresOpenAIish: true,
274
- exactIds: ["gpt-6-astra", "gpt-6-sol", "gpt-6-luna"],
275
- baseline: "openai.gpt56.cache",
276
- inheritsFrom: "gpt-5.6",
277
- overlays: [],
278
- legacy: false,
279
- runtime: rt("neutral"),
280
- note: "Documented inheritance of the GPT-5.6-and-later baseline. No CacheEngine overlay is registered for gpt-6 yet, so the runtime stays neutral.",
303
+ boundary: "GPT-5.6 and later",
304
+ note: "Documented boundary 'GPT-5.6 and later' (OpenAI Prompt caching guide, re-verified 2026-09-27) includes GPT-6 with no documented cache-control exception. No explicit breakpoint or prewarm behavior is registered.",
281
305
  inventoryRef: "§1 OpenAI",
282
306
  },
283
307
  {
@@ -387,6 +411,12 @@ function overlaysFor(ids) {
387
411
  return (ids ?? []).map((id) => OVERLAYS[id]).filter(Boolean)
388
412
  }
389
413
 
414
+ // A family entry matches by regex `pattern` or by a pure `predicate(slug)`.
415
+ function familyMatches(entry, slug) {
416
+ if (typeof entry.predicate === "function") return entry.predicate(slug)
417
+ return entry.pattern ? entry.pattern.test(slug) : false
418
+ }
419
+
390
420
  // Only legacy entries carry runtime capabilities. A non-legacy entry (gpt-6,
391
421
  // Pro UltraSpeed) resolves for information but stays neutral at runtime.
392
422
  function runtimeForEntry(entry) {
@@ -454,17 +484,20 @@ export function resolvePolicy(model) {
454
484
  return resultFromFamily(alias.family, alias.creator, "exact", reason, id, alias.inventoryRef, alias.status ?? null, transport, alias.legacy)
455
485
  }
456
486
 
457
- // 2. Exact model ids (documented models).
487
+ // 2. Exact model ids (documented models). The entry's context gate still
488
+ // applies, so an exact OpenAI id on a non-OpenAI endpoint is never guessed.
458
489
  for (const entry of POLICY_REGISTRY) {
459
490
  if (!entry.exactIds || entry.exactIds.length === 0) continue
460
491
  const hit = ids.find((id) => entry.exactIds.includes(id))
461
- if (hit) return resultFromEntry(entry, "exact", `exact-id:${hit}`, hit, transport)
492
+ if (!hit) continue
493
+ if (entry.requiresOpenAIish && !isOpenAIish(s)) continue
494
+ return resultFromEntry(entry, "exact", `exact-id:${hit}`, hit, transport)
462
495
  }
463
496
 
464
- // 3. Model family / range patterns.
497
+ // 3. Model family / range matchers (regex pattern or version predicate).
465
498
  for (const entry of POLICY_REGISTRY) {
466
- if (entry.kind !== "family" || !entry.pattern) continue
467
- if (!entry.pattern.test(s.slug)) continue
499
+ if (entry.kind !== "family") continue
500
+ if (!familyMatches(entry, s.slug)) continue
468
501
  if (entry.requiresOpenAIish && !isOpenAIish(s)) continue
469
502
  return resultFromEntry(entry, "family", `family-pattern:${entry.id}`, null, transport)
470
503
  }
@@ -498,7 +531,7 @@ export function resolveLegacyFamily(model) {
498
531
  for (const entry of POLICY_REGISTRY) {
499
532
  if (!entry.legacy) continue
500
533
  if (entry.kind === "family") {
501
- if (!entry.pattern.test(s.slug)) continue
534
+ if (!familyMatches(entry, s.slug)) continue
502
535
  if (entry.requiresOpenAIish && !isOpenAIish(s)) continue
503
536
  return entry.family
504
537
  }
@@ -53,6 +53,7 @@ import {
53
53
  MODEL_ALIASES,
54
54
  OVERLAYS,
55
55
  POLICY_REGISTRY,
56
+ isGpt56OrLater,
56
57
  resolveLegacyFamily,
57
58
  resolvePolicy,
58
59
  resolveRuntimePolicy,
@@ -1359,26 +1360,27 @@ test("resolvePolicy: GPT-5.6 exact + inventory aliases resolve to the gpt-5.6 fa
1359
1360
  assert.equal(orVariant.matchType, "exact")
1360
1361
  })
1361
1362
 
1362
- test("resolvePolicy: GPT-6 resolves via explicit documented inheritance, with no overlay", () => {
1363
+ test("v0.4.2: GPT-6 resolves through the documented GPT-5.6-and-later boundary", () => {
1363
1364
  const r = resolvePolicy(M("openrouter", "openai/gpt-6-luna"))
1364
1365
  assert.equal(r.creator, "openai")
1365
- assert.equal(r.family, "gpt-6")
1366
+ assert.equal(r.family, "gpt-5.6")
1366
1367
  assert.equal(baseId(r), "openai.gpt56.cache")
1367
- assert.deepEqual(overlayIds(r), [])
1368
- assert.equal(resolvePolicy(M("openai", "gpt-6-astra")).family, "gpt-6")
1368
+ // GPT-6 is documented in the same cache regime, so it gets the same overlay.
1369
+ assert.deepEqual(overlayIds(r), ["gpt56.prompt-cache-options"])
1370
+ assert.equal(resolvePolicy(M("openai", "gpt-6-astra")).family, "gpt-5.6")
1369
1371
 
1370
- // Inheritance is explicit, not "newer means same": the registry records it.
1371
- const gpt6 = POLICY_REGISTRY.find((e) => e.family === "gpt-6")
1372
- assert.equal(gpt6.inheritsFrom, "gpt-5.6")
1373
- assert.ok(gpt6.inventoryRef)
1374
- // And no overlay is implied by that inheritance.
1375
- assert.deepEqual(gpt6.overlays, [])
1372
+ // The boundary is version-based, not an exact-model list.
1373
+ const entry = POLICY_REGISTRY.find((e) => e.id === "openai.gpt-5.6-plus")
1374
+ assert.equal(entry.boundary, "GPT-5.6 and later")
1375
+ assert.equal(typeof entry.predicate, "function")
1376
+ assert.ok(entry.inventoryRef)
1376
1377
  })
1377
1378
 
1378
- test("resolvePolicy: GPT-6 is not classified by the legacy detectPolicy wrapper", () => {
1379
- // Intentional: the new layer knows gpt-6, the compatibility wrapper does not.
1380
- assert.equal(detectPolicy(M("openai", "gpt-6-astra")), POLICY_NEUTRAL)
1381
- assert.equal(resolvePolicy(M("openai", "gpt-6-astra")).family, "gpt-6")
1379
+ test("v0.4.2: the legacy detectPolicy wrapper follows the same boundary", () => {
1380
+ assert.equal(detectPolicy(M("openai", "gpt-6-astra")), POLICY_GPT56)
1381
+ assert.equal(detectPolicy(M("openai", "gpt-5.6")), POLICY_GPT56)
1382
+ assert.equal(detectPolicy(M("openai", "gpt-5.5")), POLICY_NEUTRAL)
1383
+ assert.equal(detectPolicy(M("openai", "gpt-5.60")), POLICY_NEUTRAL)
1382
1384
  })
1383
1385
 
1384
1386
  test("resolvePolicy: pre-5.6 GPT negative controls are neutral with no overlays", () => {
@@ -1632,7 +1634,10 @@ async function runPolicyMigrationProbe() {
1632
1634
  const CASES = [
1633
1635
  { name: "gpt-5.6", model: { providerID: "openai", id: "gpt-5.6", api: { id: "gpt-5.6", npm: "@ai-sdk/openai" } }, expect: { policy: "gpt56", env: false, gpt: true, header: false } },
1634
1636
  { name: "gpt-5.6-openrouter", model: { providerID: "openrouter", id: "openai/gpt-5.6-sol", api: { id: "openai/gpt-5.6-sol" } }, expect: { policy: "gpt56", env: false, gpt: true, header: false } },
1635
- { name: "gpt-6-astra", model: { providerID: "openai", id: "gpt-6-astra", api: { id: "gpt-6-astra", npm: "@ai-sdk/openai" } }, expect: { policy: "neutral", env: false, gpt: false, header: false } },
1637
+ { name: "gpt-6-astra", model: { providerID: "openai", id: "gpt-6-astra", api: { id: "gpt-6-astra", npm: "@ai-sdk/openai" } }, expect: { policy: "gpt56", env: false, gpt: true, header: false } },
1638
+ { name: "gpt-6-openrouter", model: { providerID: "openrouter", id: "openai/gpt-6-luna", api: { id: "openai/gpt-6-luna" } }, expect: { policy: "gpt56", env: false, gpt: true, header: false } },
1639
+ { name: "gpt-6-openai-compatible", model: { providerID: "openai-compatible", id: "gpt-6-astra", api: { id: "gpt-6-astra" } }, expect: { policy: "neutral", env: false, gpt: false, header: false } },
1640
+ { name: "gpt-5.60-malformed", model: { providerID: "openai", id: "gpt-5.60", api: { id: "gpt-5.60", npm: "@ai-sdk/openai" } }, expect: { policy: "neutral", env: false, gpt: false, header: false } },
1636
1641
  { name: "gpt-5.5", model: { providerID: "openai", id: "gpt-5.5", api: { id: "gpt-5.5", npm: "@ai-sdk/openai" } }, expect: { policy: "neutral", env: false, gpt: false, header: false } },
1637
1642
  { name: "gpt-daybreak-alias", model: { providerID: "openai", id: "gpt-daybreak-blue-latest", api: { id: "gpt-daybreak-blue-latest", npm: "@ai-sdk/openai" } }, expect: { policy: "neutral", env: false, gpt: false, header: false } },
1638
1643
  { name: "deepseek-v4-pro", model: { providerID: "deepseek", id: "deepseek-v4-pro", api: { id: "deepseek-v4-pro" } }, expect: { policy: "deepseek", env: false, gpt: false, header: false } },
@@ -1717,9 +1722,10 @@ test("v0.4.1: GPT-5.6 keeps promptCacheOptions implicit/30m through the resolver
1717
1722
  test("v0.4.1: future-looking and unknown models gain no mutation", async () => {
1718
1723
  const { results } = await policyMigrationResults()
1719
1724
  const noMutation = [
1720
- "gpt-6-astra",
1721
1725
  "gpt-daybreak-alias",
1722
1726
  "gpt-5.5",
1727
+ "gpt-6-openai-compatible",
1728
+ "gpt-5.60-malformed",
1723
1729
  "glm-5.2",
1724
1730
  "mimo-v2.6-pro-ultraspeed",
1725
1731
  "mimo-v2.5",
@@ -1741,3 +1747,75 @@ test("v0.4.1: non-OpenRouter models never receive the OpenRouter header", async
1741
1747
  assert.equal(r.affinityHeaderAttached, false, `${name}: no affinity header off OpenRouter`)
1742
1748
  }
1743
1749
  })
1750
+
1751
+ // ===========================================================================
1752
+ // v0.4.2 GPT-5.6-and-later boundary
1753
+ //
1754
+ // Source: OpenAI *Prompt caching* guide, "GPT-5.6 and later" generation
1755
+ // boundary, re-verified 2026-09-27 (docs/cache-policy-inventory.md §1). GPT-6
1756
+ // is documented in the same regime with no cache-control exception.
1757
+ // ===========================================================================
1758
+
1759
+ test("v0.4.2: isGpt56OrLater matches the documented boundary by version", () => {
1760
+ const inFamily = [
1761
+ "gpt-5.6",
1762
+ "gpt-5.6-luna",
1763
+ "openai/gpt-5.6-sol",
1764
+ "gpt-6",
1765
+ "gpt-6-astra",
1766
+ "gpt-6-sol",
1767
+ "gpt-6-luna",
1768
+ "gpt-5.7",
1769
+ "gpt-7",
1770
+ "gpt-6.1",
1771
+ ]
1772
+ for (const id of inFamily) assert.equal(isGpt56OrLater(id), true, `${id} is in family`)
1773
+ const outOfFamily = [
1774
+ "gpt-5.5",
1775
+ "gpt-5.4",
1776
+ "gpt-5.2",
1777
+ "gpt-5.1",
1778
+ "gpt-5",
1779
+ "gpt-4.1",
1780
+ "gpt-4o",
1781
+ "gpt-5.60",
1782
+ "gpt-5.6.1",
1783
+ "gpt-4",
1784
+ "claude-sonnet-4-5",
1785
+ ]
1786
+ for (const id of outOfFamily) assert.equal(isGpt56OrLater(id), false, `${id} is out of family`)
1787
+ })
1788
+
1789
+ test("v0.4.2: GPT boundary respects OpenAI/provider gating", () => {
1790
+ assert.equal(resolveRuntimePolicy(M("openai", "gpt-5.6")).gptCacheMetadata, true)
1791
+ assert.equal(resolveRuntimePolicy(M("openai", "gpt-6-astra")).gptCacheMetadata, true)
1792
+ assert.equal(resolveRuntimePolicy(M("azure", "gpt-6-sol")).gptCacheMetadata, true)
1793
+ assert.equal(resolveRuntimePolicy(M("openrouter", "openai/gpt-6-luna")).gptCacheMetadata, true)
1794
+ assert.equal(resolveRuntimePolicy(M("openai-compatible", "gpt-6-astra")).gptCacheMetadata, false)
1795
+ assert.equal(resolveRuntimePolicy(M("llama.cpp", "gpt-5.6")).gptCacheMetadata, false)
1796
+ assert.equal(resolveRuntimePolicy(M("openai", "gpt-5.5")).gptCacheMetadata, false)
1797
+ assert.equal(resolveRuntimePolicy(M("openai", "gpt-5.60")).gptCacheMetadata, false)
1798
+ })
1799
+
1800
+ test("v0.4.2: covered later GPT requests receive the same documented baseline at runtime", async () => {
1801
+ const { results } = await policyMigrationResults()
1802
+ const gpt6 = results.find((r) => r.name === "gpt-6-astra")
1803
+ assert.equal(gpt6.runtimePolicy, "gpt56")
1804
+ assert.equal(gpt6.gptOptionInjected, true)
1805
+ assert.deepEqual(gpt6.gptOptions, { mode: "implicit", ttl: "30m" })
1806
+ // Same baseline as GPT-5.6, no new mechanism.
1807
+ const gpt56 = results.find((r) => r.name === "gpt-5.6")
1808
+ assert.deepEqual(gpt6.gptOptions, gpt56.gptOptions)
1809
+ // No prompt transformation or affinity was introduced for gpt-6.
1810
+ assert.equal(gpt6.systemRelocated, false)
1811
+ assert.equal(gpt6.affinityHeaderAttached, false)
1812
+ })
1813
+
1814
+ test("v0.4.2: pre-5.6 and out-of-family GPT ids get no GPT options", async () => {
1815
+ const { results } = await policyMigrationResults()
1816
+ for (const name of ["gpt-5.5", "gpt-5.60-malformed", "gpt-6-openai-compatible"]) {
1817
+ const r = results.find((x) => x.name === name)
1818
+ assert.equal(r.gptOptionInjected, false, `${name}: no GPT options`)
1819
+ assert.equal(r.runtimePolicy, "neutral", `${name}: neutral runtime`)
1820
+ }
1821
+ })