@retaw106/mmc-oc 2.2.1 → 2.3.0

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 (211) hide show
  1. package/dist/cli.js +2 -2
  2. package/dist/config/deprecated-config.d.ts +4 -0
  3. package/dist/config/deprecated-config.d.ts.map +1 -0
  4. package/dist/config/index.d.ts.map +1 -1
  5. package/dist/config/project-security.d.ts +2 -2
  6. package/dist/config/schema/magic-context.d.ts +3 -3
  7. package/dist/config/schema/magic-context.d.ts.map +1 -1
  8. package/dist/config-init.js +2 -2
  9. package/dist/{context-mrvm92n8.js → context-wt7g4f8k.js} +1641 -1543
  10. package/dist/{derive-budgets-rjjz5f7y.js → derive-budgets-s1p37t2g.js} +2 -2
  11. package/dist/features/magic-context/compaction-marker.d.ts.map +1 -1
  12. package/dist/features/magic-context/historian-failure-reason.d.ts +7 -0
  13. package/dist/features/magic-context/historian-failure-reason.d.ts.map +1 -0
  14. package/dist/features/magic-context/message-index-async.d.ts +21 -3
  15. package/dist/features/magic-context/message-index-async.d.ts.map +1 -1
  16. package/dist/features/magic-context/message-index.d.ts +7 -1
  17. package/dist/features/magic-context/message-index.d.ts.map +1 -1
  18. package/dist/features/magic-context/migrations.d.ts.map +1 -1
  19. package/dist/features/magic-context/pi-content-decisions.d.ts +7 -1
  20. package/dist/features/magic-context/pi-content-decisions.d.ts.map +1 -1
  21. package/dist/features/magic-context/search.d.ts +29 -0
  22. package/dist/features/magic-context/search.d.ts.map +1 -1
  23. package/dist/features/magic-context/storage-clone.d.ts +2 -0
  24. package/dist/features/magic-context/storage-clone.d.ts.map +1 -1
  25. package/dist/features/magic-context/storage-compartment-history-version.d.ts +4 -0
  26. package/dist/features/magic-context/storage-compartment-history-version.d.ts.map +1 -0
  27. package/dist/features/magic-context/storage-db.d.ts +1 -1
  28. package/dist/features/magic-context/storage-db.d.ts.map +1 -1
  29. package/dist/features/magic-context/storage-historian-runs.d.ts.map +1 -1
  30. package/dist/features/magic-context/storage-meta-persisted.d.ts +23 -5
  31. package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
  32. package/dist/features/magic-context/storage-meta-session.d.ts +7 -1
  33. package/dist/features/magic-context/storage-meta-session.d.ts.map +1 -1
  34. package/dist/features/magic-context/storage-session-tables.d.ts +5 -1
  35. package/dist/features/magic-context/storage-session-tables.d.ts.map +1 -1
  36. package/dist/features/magic-context/storage-tag-identity-revision.d.ts +50 -0
  37. package/dist/features/magic-context/storage-tag-identity-revision.d.ts.map +1 -0
  38. package/dist/features/magic-context/storage-tags.d.ts +155 -5
  39. package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
  40. package/dist/features/magic-context/tagger.d.ts +2 -0
  41. package/dist/features/magic-context/tagger.d.ts.map +1 -1
  42. package/dist/features/magic-context/transform-decision-log.d.ts +3 -0
  43. package/dist/features/magic-context/transform-decision-log.d.ts.map +1 -1
  44. package/dist/hooks/magic-context/active-anthropic-turn.d.ts +2 -0
  45. package/dist/hooks/magic-context/active-anthropic-turn.d.ts.map +1 -1
  46. package/dist/hooks/magic-context/apply-operations.d.ts +7 -0
  47. package/dist/hooks/magic-context/apply-operations.d.ts.map +1 -1
  48. package/dist/hooks/magic-context/auto-search-runner.d.ts +2 -2
  49. package/dist/hooks/magic-context/auto-search-runner.d.ts.map +1 -1
  50. package/dist/hooks/magic-context/heuristic-cleanup.d.ts.map +1 -1
  51. package/dist/hooks/magic-context/history-boundary-repair.d.ts +11 -2
  52. package/dist/hooks/magic-context/history-boundary-repair.d.ts.map +1 -1
  53. package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
  54. package/dist/hooks/magic-context/lkg-measured-request.d.ts +3 -1
  55. package/dist/hooks/magic-context/lkg-measured-request.d.ts.map +1 -1
  56. package/dist/hooks/magic-context/lkg-persist.d.ts +10 -13
  57. package/dist/hooks/magic-context/lkg-persist.d.ts.map +1 -1
  58. package/dist/hooks/magic-context/lkg-recovery-fence.d.ts +62 -0
  59. package/dist/hooks/magic-context/lkg-recovery-fence.d.ts.map +1 -0
  60. package/dist/hooks/magic-context/lkg-recovery-prefix.d.ts +38 -0
  61. package/dist/hooks/magic-context/lkg-recovery-prefix.d.ts.map +1 -0
  62. package/dist/hooks/magic-context/lkg-replay.d.ts +16 -9
  63. package/dist/hooks/magic-context/lkg-replay.d.ts.map +1 -1
  64. package/dist/hooks/magic-context/lkg-slot.d.ts +141 -2
  65. package/dist/hooks/magic-context/lkg-slot.d.ts.map +1 -1
  66. package/dist/hooks/magic-context/opaque-thinking.d.ts +12 -0
  67. package/dist/hooks/magic-context/opaque-thinking.d.ts.map +1 -0
  68. package/dist/hooks/magic-context/pass-outcome.d.ts +1 -0
  69. package/dist/hooks/magic-context/pass-outcome.d.ts.map +1 -1
  70. package/dist/hooks/magic-context/pending-materialization.d.ts +8 -0
  71. package/dist/hooks/magic-context/pending-materialization.d.ts.map +1 -0
  72. package/dist/hooks/magic-context/postprocess-read-cache.d.ts.map +1 -1
  73. package/dist/hooks/magic-context/provider-visible-parts.d.ts +45 -0
  74. package/dist/hooks/magic-context/provider-visible-parts.d.ts.map +1 -0
  75. package/dist/hooks/magic-context/read-session-chunk.d.ts +22 -1
  76. package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
  77. package/dist/hooks/magic-context/read-session-db.d.ts +3 -0
  78. package/dist/hooks/magic-context/read-session-db.d.ts.map +1 -1
  79. package/dist/hooks/magic-context/read-session-formatting.d.ts +5 -0
  80. package/dist/hooks/magic-context/read-session-formatting.d.ts.map +1 -1
  81. package/dist/hooks/magic-context/read-session-raw.d.ts +123 -1
  82. package/dist/hooks/magic-context/read-session-raw.d.ts.map +1 -1
  83. package/dist/hooks/magic-context/read-session-true-raw-tokens.d.ts.map +1 -1
  84. package/dist/hooks/magic-context/reasoning-budget.d.ts.map +1 -1
  85. package/dist/hooks/magic-context/sentinel.d.ts +41 -1
  86. package/dist/hooks/magic-context/sentinel.d.ts.map +1 -1
  87. package/dist/hooks/magic-context/strict-thinking-prefix.d.ts +8 -0
  88. package/dist/hooks/magic-context/strict-thinking-prefix.d.ts.map +1 -0
  89. package/dist/hooks/magic-context/strip-content.d.ts +38 -24
  90. package/dist/hooks/magic-context/strip-content.d.ts.map +1 -1
  91. package/dist/hooks/magic-context/system-date-refresh.d.ts +29 -0
  92. package/dist/hooks/magic-context/system-date-refresh.d.ts.map +1 -0
  93. package/dist/hooks/magic-context/system-prompt-dates.d.ts +6 -0
  94. package/dist/hooks/magic-context/system-prompt-dates.d.ts.map +1 -0
  95. package/dist/hooks/magic-context/system-prompt-delivery.d.ts +47 -0
  96. package/dist/hooks/magic-context/system-prompt-delivery.d.ts.map +1 -0
  97. package/dist/hooks/magic-context/system-prompt-hash.d.ts +18 -5
  98. package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
  99. package/dist/hooks/magic-context/tag-messages.d.ts +19 -0
  100. package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
  101. package/dist/hooks/magic-context/tag-owner-warmup.d.ts +14 -0
  102. package/dist/hooks/magic-context/tag-owner-warmup.d.ts.map +1 -0
  103. package/dist/hooks/magic-context/token-count-exact.d.ts +35 -0
  104. package/dist/hooks/magic-context/token-count-exact.d.ts.map +1 -0
  105. package/dist/hooks/magic-context/tool-drop-target.d.ts +2 -0
  106. package/dist/hooks/magic-context/tool-drop-target.d.ts.map +1 -1
  107. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +7 -0
  108. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  109. package/dist/hooks/magic-context/transform.d.ts +21 -4
  110. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  111. package/dist/index-18yrysyj.js +1477 -0
  112. package/dist/{index-g2z2k5m4.js → index-3gj1ak4c.js} +2 -2
  113. package/dist/{index-5cep2r9n.js → index-5ty9rnbx.js} +60 -258
  114. package/dist/{index-amycb7b1.js → index-a5mw0xp3.js} +3 -3
  115. package/dist/{index-1j34a56j.js → index-czba8tw3.js} +266 -32
  116. package/dist/{index-qbkzdkk0.js → index-k59af64t.js} +6 -2
  117. package/dist/{index-53g38ggt.js → index-kmbme1v1.js} +1 -1
  118. package/dist/{index-5b7x80ec.js → index-kw21z5pe.js} +6055 -3973
  119. package/dist/{index-33gprt9g.js → index-yjv8dpht.js} +1 -1
  120. package/dist/{index-btp5tdc8.js → index-z2w1eq3y.js} +840 -456
  121. package/dist/index.d.ts.map +1 -1
  122. package/dist/index.js +114 -2
  123. package/dist/{message-time-backfill-phrwp2fz.js → message-time-backfill-sykevdax.js} +3 -3
  124. package/dist/plugin/rpc-handlers.d.ts.map +1 -1
  125. package/dist/{read-session-chunk-2xm4sc4y.js → read-session-chunk-863d6c06.js} +6 -4
  126. package/dist/recomp-orchestrator-wrjy3qym.js +21 -0
  127. package/dist/{safe-notification-target-ph3xd1ve.js → safe-notification-target-1jkf0m82.js} +2 -2
  128. package/dist/{send-session-notification-rnc4nrsr.js → send-session-notification-cz6ev088.js} +5 -5
  129. package/dist/shared/auto-search-lifecycle.d.ts +14 -0
  130. package/dist/shared/auto-search-lifecycle.d.ts.map +1 -1
  131. package/dist/shared/logger.d.ts.map +1 -1
  132. package/dist/shared/models-dev-cache.d.ts.map +1 -1
  133. package/dist/shared/models-dev-temperature.d.ts +18 -0
  134. package/dist/shared/models-dev-temperature.d.ts.map +1 -0
  135. package/dist/shared/processed-image-eligibility.d.ts +22 -0
  136. package/dist/shared/processed-image-eligibility.d.ts.map +1 -0
  137. package/dist/shared/project-directory-key.d.ts +16 -0
  138. package/dist/shared/project-directory-key.d.ts.map +1 -1
  139. package/dist/shared/recovery-reasoning-prefix.d.ts +9 -0
  140. package/dist/shared/recovery-reasoning-prefix.d.ts.map +1 -0
  141. package/dist/shared/sqlite.d.ts +33 -1
  142. package/dist/shared/sqlite.d.ts.map +1 -1
  143. package/dist/shared/stable-json.d.ts.map +1 -1
  144. package/dist/shared/storage-file-mutex.d.ts +9 -0
  145. package/dist/shared/storage-file-mutex.d.ts.map +1 -0
  146. package/dist/shared/storage-permissions.d.ts +6 -0
  147. package/dist/shared/storage-permissions.d.ts.map +1 -1
  148. package/dist/shared/subagent-temperature.d.ts +46 -0
  149. package/dist/shared/subagent-temperature.d.ts.map +1 -0
  150. package/dist/shared/tag-owner-id.d.ts +1 -0
  151. package/dist/shared/tag-owner-id.d.ts.map +1 -1
  152. package/dist/shared/tag-transcript.d.ts +9 -0
  153. package/dist/shared/tag-transcript.d.ts.map +1 -1
  154. package/dist/shared/window-geometry.d.ts +9 -66
  155. package/dist/shared/window-geometry.d.ts.map +1 -1
  156. package/dist/standalone-plugin-marker.d.ts +8 -0
  157. package/dist/standalone-plugin-marker.d.ts.map +1 -0
  158. package/dist/tools/ctx-expand/search-archive.d.ts +4 -0
  159. package/dist/tools/ctx-expand/search-archive.d.ts.map +1 -0
  160. package/dist/tools/ctx-expand/tools.d.ts.map +1 -1
  161. package/dist/tools/ctx-reduce/constants.d.ts +1 -2
  162. package/dist/tools/ctx-reduce/constants.d.ts.map +1 -1
  163. package/dist/tools/ctx-reduce/tools.d.ts +1 -1
  164. package/dist/tools/ctx-reduce/tools.d.ts.map +1 -1
  165. package/dist/v2/hooks/context.d.ts +1 -1
  166. package/dist/v2/hooks/context.d.ts.map +1 -1
  167. package/dist/v2/hooks/copied-tag-notation.d.ts +19 -0
  168. package/dist/v2/hooks/copied-tag-notation.d.ts.map +1 -0
  169. package/dist/v2/hooks/generate.d.ts +9 -2
  170. package/dist/v2/hooks/generate.d.ts.map +1 -1
  171. package/dist/v2/hooks/payload.d.ts.map +1 -1
  172. package/dist/v2/hooks/system-prompt-response.d.ts +5 -0
  173. package/dist/v2/hooks/system-prompt-response.d.ts.map +1 -0
  174. package/dist/v2/server.d.ts.map +1 -1
  175. package/dist/v2/server.js +34550 -30855
  176. package/dist/web/main.js +373 -19
  177. package/dist/{wrapup-orchestrator-yknks3ad.js → wrapup-orchestrator-bmybc5p5.js} +10 -10
  178. package/package.json +1 -1
  179. package/src/config/deprecated-config.ts +18 -0
  180. package/src/config/index.test.ts +13 -37
  181. package/src/config/index.ts +2 -2
  182. package/src/config/project-security.ts +3 -3
  183. package/src/config/schema/magic-context.ts +10 -6
  184. package/src/shared/auto-search-lifecycle.ts +43 -0
  185. package/src/shared/logger.ts +10 -2
  186. package/src/shared/models-dev-cache.ts +1 -7
  187. package/src/shared/models-dev-temperature.ts +107 -0
  188. package/src/shared/processed-image-eligibility.test.ts +68 -0
  189. package/src/shared/processed-image-eligibility.ts +41 -0
  190. package/src/shared/processed-image-position-review.json +20 -0
  191. package/src/shared/processed-image-position-review.test.ts +19 -0
  192. package/src/shared/project-directory-key.ts +20 -0
  193. package/src/shared/recovery-reasoning-prefix.test.ts +34 -0
  194. package/src/shared/recovery-reasoning-prefix.ts +35 -0
  195. package/src/shared/sqlite-acquisition-routing.test.ts +4 -3
  196. package/src/shared/sqlite-foreground-wait.test.ts +68 -0
  197. package/src/shared/sqlite-pass-scope.test.ts +4 -4
  198. package/src/shared/sqlite-writer-diagnostics.test.ts +52 -12
  199. package/src/shared/sqlite.ts +380 -39
  200. package/src/shared/stable-json.ts +37 -7
  201. package/src/shared/storage-file-mutex.test.ts +50 -0
  202. package/src/shared/storage-file-mutex.ts +130 -0
  203. package/src/shared/storage-permissions.ts +46 -0
  204. package/src/shared/subagent-temperature.ts +110 -0
  205. package/src/shared/tag-owner-id.ts +13 -0
  206. package/src/shared/tag-transcript.ts +118 -0
  207. package/src/shared/window-geometry.test.ts +102 -236
  208. package/src/shared/window-geometry.ts +23 -413
  209. package/dist/index-ramz5kkm.js +0 -514
  210. package/dist/recomp-orchestrator-frmwj9hz.js +0 -21
  211. package/src/shared/__fixtures__/window-overlay.v1.json +0 -337
@@ -1,180 +1,13 @@
1
- import { afterEach, describe, expect, test } from "bun:test";
2
- import { readFileSync, rmSync, writeFileSync } from "node:fs";
3
- import { tmpdir } from "node:os";
4
- import { join } from "node:path";
1
+ import { describe, expect, test } from "bun:test";
5
2
  import { resolveLimit, resolveOutputReserve } from "./models-dev-cache";
6
- import { createTestTempDirFromPath } from "./test-temp-dir";
7
3
  import {
8
4
  applyProvenInputFloor,
9
5
  deriveWindowGeometry,
10
6
  formatCompactTokens,
11
7
  formatWindowDerivationLine,
12
- parseWindowOverlay,
13
8
  placeholderFilteredOutput,
14
- readWindowOverlayFile,
15
- resolveWindowOverlayFacts,
16
- scalarizeFact,
17
- type WindowOverlay,
18
- type WindowOverlayFact,
19
9
  } from "./window-geometry";
20
10
 
21
- const fixture = JSON.parse(
22
- readFileSync(new URL("./__fixtures__/window-overlay.v1.json", import.meta.url), "utf8"),
23
- ) as unknown;
24
- const parsedFixture = parseWindowOverlay(fixture).overlay as WindowOverlay;
25
- const tempDirs: string[] = [];
26
-
27
- function fact(
28
- value: WindowOverlayFact["value"],
29
- overrides: Partial<WindowOverlayFact> = {},
30
- ): WindowOverlayFact {
31
- return {
32
- value,
33
- grade: "measured",
34
- units: "provider",
35
- boundary: "Observed",
36
- source_ref: "test",
37
- observed_at: "2026-08-13T00:00:00Z",
38
- ...overrides,
39
- };
40
- }
41
-
42
- function overlay(
43
- provider: string,
44
- model: string,
45
- facts: Record<string, WindowOverlayFact>,
46
- ): WindowOverlay {
47
- return {
48
- schema: "fusiform-window-overlay/v1",
49
- generated_at: "2026-08-13T00:00:00Z",
50
- minted_provider_ids: [],
51
- cells: [{ provider_id: provider, model_id: model, facts }],
52
- };
53
- }
54
-
55
- afterEach(() => {
56
- for (const path of tempDirs.splice(0)) rmSync(path, { recursive: true, force: true });
57
- });
58
-
59
- describe("Fusiform overlay v1", () => {
60
- test("scalarizes every tagged union conservatively", () => {
61
- expect(scalarizeFact({ kind: "stated", value: 272_000 })).toBe(272_000);
62
- expect(scalarizeFact({ kind: "bracket", at_least: 340_000, below: 372_001 })).toBe(340_000);
63
- expect(scalarizeFact({ kind: "bracket", below: 372_001 })).toBeUndefined();
64
- expect(scalarizeFact({ kind: "unknown", why: "never_measured" })).toBeUndefined();
65
- });
66
-
67
- test("preserves a half-open bracket and derives exactly from at_least", () => {
68
- const halfOpen = parseWindowOverlay({
69
- schema: "fusiform-window-overlay/v1",
70
- generated_at: "2026-08-13T00:00:00Z",
71
- minted_provider_ids: [],
72
- cells: [
73
- {
74
- provider_id: "openai-chatgpt-oauth",
75
- model_id: "gpt-5.6-sol",
76
- facts: {
77
- "window.advertised": fact({ kind: "stated", value: 272_000 }),
78
- "window.enforced": fact({ kind: "bracket", at_least: 340_000 }),
79
- },
80
- },
81
- ],
82
- }).overlay;
83
- const parsedValue = halfOpen?.cells[0]?.facts["window.enforced"]?.value;
84
- expect(parsedValue).toEqual({ kind: "bracket", at_least: 340_000 });
85
- expect(parsedValue && "below" in parsedValue).toBe(false);
86
- const halfOpenResult = deriveWindowGeometry(
87
- "openai-chatgpt-oauth",
88
- "gpt-5.6-sol",
89
- { context: 272_000, output: 128_000 },
90
- {
91
- overlay: resolveWindowOverlayFacts("openai-chatgpt-oauth", "gpt-5.6-sol", halfOpen),
92
- },
93
- );
94
- const statedResult = deriveWindowGeometry(
95
- "openai-chatgpt-oauth",
96
- "gpt-5.6-sol",
97
- { context: 272_000, output: 128_000 },
98
- {
99
- overlay: resolveWindowOverlayFacts(
100
- "openai-chatgpt-oauth",
101
- "gpt-5.6-sol",
102
- overlay("openai-chatgpt-oauth", "gpt-5.6-sol", {
103
- "window.enforced": fact({ kind: "stated", value: 340_000 }),
104
- }),
105
- ),
106
- },
107
- );
108
- expect(halfOpenResult).toEqual(statedResult);
109
- });
110
-
111
- test("specific cells override wildcard facts per fact", () => {
112
- const data: WindowOverlay = {
113
- schema: "fusiform-window-overlay/v1",
114
- generated_at: "2026-08-13T00:00:00Z",
115
- minted_provider_ids: [],
116
- cells: [
117
- {
118
- provider_id: "ollama-cloud",
119
- model_id: "*",
120
- facts: {
121
- "output.enforced": fact({ kind: "stated", value: 65_536 }),
122
- geometry: fact({ kind: "stated", value: "shared_upfront" }),
123
- },
124
- },
125
- {
126
- provider_id: "ollama-cloud",
127
- model_id: "deepseek-v4",
128
- facts: {
129
- "output.enforced": fact({ kind: "stated", value: 32_000 }),
130
- },
131
- },
132
- ],
133
- };
134
- const facts = resolveWindowOverlayFacts("ollama-cloud", "deepseek-v4", data)?.facts;
135
- expect(scalarizeFact(facts?.["output.enforced"]?.value as never)).toBe(32_000);
136
- expect(facts?.geometry?.value).toEqual({ kind: "stated", value: "shared_upfront" });
137
- });
138
-
139
- test("refuses an unrecognized schema before considering familiar cells", () => {
140
- const v2 = {
141
- ...(fixture as Record<string, unknown>),
142
- schema: "fusiform-window-overlay/v2",
143
- };
144
- const parsed = parseWindowOverlay(v2);
145
- expect(parsed.overlay).toBeUndefined();
146
- expect(parsed.refusal).toContain("unrecognized schema");
147
- });
148
-
149
- test("skips bad cells once and keeps valid cells", () => {
150
- const badCell = {
151
- provider_id: "bad",
152
- model_id: "model",
153
- facts: { "window.enforced": { value: { kind: "stated", value: 1_000_000 } } },
154
- };
155
- const parsed = parseWindowOverlay({
156
- ...(fixture as Record<string, unknown>),
157
- cells: [badCell, ...(fixture as { cells: unknown[] }).cells],
158
- });
159
- expect(parsed.badCells).toBe(1);
160
- expect(parsed.overlay?.cells.length).toBe(parsedFixture.cells.length);
161
- });
162
-
163
- test("a missing file is silent and a bad file logs one summary", () => {
164
- const dir = createTestTempDirFromPath(join(tmpdir(), "window-overlay-test-"));
165
- tempDirs.push(dir);
166
- const logs: string[] = [];
167
- expect(
168
- readWindowOverlayFile(join(dir, "missing.json"), (message) => logs.push(message)),
169
- ).toBeUndefined();
170
- expect(logs).toEqual([]);
171
- const path = join(dir, "bad.json");
172
- writeFileSync(path, JSON.stringify({ ...(fixture as object), schema: "v2" }));
173
- expect(readWindowOverlayFile(path, (message) => logs.push(message))).toBeUndefined();
174
- expect(logs).toHaveLength(1);
175
- });
176
- });
177
-
178
11
  describe("window geometry", () => {
179
12
  test("filters placeholders independently in both directions", () => {
180
13
  expect(placeholderFilteredOutput(0, 1_000_000)).toBeUndefined();
@@ -190,63 +23,106 @@ describe("window geometry", () => {
190
23
  ).toBe(300_000);
191
24
  });
192
25
 
193
- test("fixture table yields the 65% execution bases from the spec", () => {
26
+ test("preserves catalog geometry for representative models", () => {
194
27
  const cases = [
195
- ["openai-chatgpt-oauth", "gpt-5.6", 272_000, 128_000, 200_200],
196
- ["anthropic", "claude-opus-5", 1_000_000, 128_000, 629_200],
197
- // Producer batch downgraded google's geometry to considered-unknown
198
- // (Google's docs contradict the separate-quota reading), so the
199
- // derivation demotes to shared_upfront and reserves OpenCode's
200
- // actual request cap B = min(65_536, 32_000):
201
- // floor(0.65 * (1_048_576 - 32_000)) — not the no-reserve 681_574.
202
- ["google", "gemini-3.5-flash", 1_048_576, 65_536, 660_774],
203
- ["xai", "grok-4.6", 500_000, 500_000, 304_200],
204
- ["ollama-cloud", "deepseek-v4-flash", 1_048_576, 384_000, 660_774],
205
- ["moonshotai", "kimi-k3", 1_048_576, 1_048_576, 660_774],
206
- ] as const;
207
- for (const [provider, model, context, output, expectedExecute] of cases) {
208
- const result = deriveWindowGeometry(
209
- provider,
210
- model,
211
- { context, output },
212
- {
213
- overlay: resolveWindowOverlayFacts(provider, model, parsedFixture),
28
+ {
29
+ provider: "openai",
30
+ model: "gpt-4o",
31
+ limit: { context: 128_000, output: 16_384 },
32
+ expected: {
33
+ usableSoft: 111_616,
34
+ usableHard: 111_616,
35
+ geometry: "shared_upfront",
36
+ derivation: {
37
+ window: 128_000,
38
+ reserve: 16_384,
39
+ reserveSource: "output_catalog",
40
+ geometry: "shared_upfront",
41
+ windowSource: "catalog",
42
+ absoluteWall: 128_000,
43
+ },
214
44
  },
215
- );
216
- expect(Math.floor((result?.usableSoft ?? 0) * 0.65)).toBe(expectedExecute);
217
- }
218
- });
219
-
220
- test("grok derives from geometry, window, and default output without an enforced output", () => {
221
- const facts = resolveWindowOverlayFacts("xai", "grok-4.6", parsedFixture);
222
- expect(facts?.facts["output.enforced"]).toBeUndefined();
223
- const result = deriveWindowGeometry(
224
- "xai",
225
- "grok-4.6",
226
- { context: 500_000, output: 500_000 },
227
- { overlay: facts },
228
- );
229
- expect(result?.geometry).toBe("shared_truncating");
230
- expect(result?.usableSoft).toBe(468_000);
231
- });
232
-
233
- test("kimi reserves its default output instead of placeholder advertised output", () => {
234
- const result = deriveWindowGeometry(
235
- "moonshotai",
236
- "kimi-k3",
237
- { context: 1_048_576, output: 1_048_576 },
45
+ },
238
46
  {
239
- overlay: resolveWindowOverlayFacts("moonshotai", "kimi-k3", parsedFixture),
47
+ provider: "anthropic",
48
+ model: "claude-3-7-sonnet",
49
+ limit: { context: 200_000, output: 64_000 },
50
+ expected: {
51
+ usableSoft: 150_000,
52
+ usableHard: 195_904,
53
+ geometry: "shared_truncating",
54
+ derivation: {
55
+ window: 200_000,
56
+ reserve: 50_000,
57
+ reserveSource: "output_catalog",
58
+ geometry: "shared_truncating",
59
+ windowSource: "catalog",
60
+ absoluteWall: 200_000,
61
+ },
62
+ },
240
63
  },
241
- );
242
- expect(result?.derivation.reserve).toBe(32_000);
243
- expect(result?.usableSoft).toBe(1_016_576);
64
+ {
65
+ provider: "google",
66
+ model: "gemini-2.5-pro",
67
+ limit: { context: 1_000_000, output: 65_536 },
68
+ expected: {
69
+ usableSoft: 1_000_000,
70
+ usableHard: 1_000_000,
71
+ geometry: "separate",
72
+ derivation: {
73
+ window: 1_000_000,
74
+ reserve: 0,
75
+ reserveSource: "none",
76
+ geometry: "separate",
77
+ windowSource: "catalog",
78
+ absoluteWall: 1_000_000,
79
+ },
80
+ },
81
+ },
82
+ {
83
+ provider: "xai",
84
+ model: "grok-3",
85
+ limit: { context: 131_072, output: 32_768 },
86
+ expected: {
87
+ usableSoft: 98_304,
88
+ usableHard: 126_976,
89
+ geometry: "shared_truncating",
90
+ derivation: {
91
+ window: 131_072,
92
+ reserve: 32_768,
93
+ reserveSource: "output_catalog",
94
+ geometry: "shared_truncating",
95
+ windowSource: "catalog",
96
+ absoluteWall: 131_072,
97
+ },
98
+ },
99
+ },
100
+ {
101
+ provider: "openai-codex",
102
+ model: "gpt-5.6-sol",
103
+ limit: { context: 272_000, output: 128_000 },
104
+ expected: {
105
+ usableSoft: 204_000,
106
+ usableHard: 240_000,
107
+ geometry: "shared_upfront",
108
+ derivation: {
109
+ window: 272_000,
110
+ reserve: 68_000,
111
+ reserveSource: "output_catalog",
112
+ geometry: "shared_upfront",
113
+ windowSource: "catalog",
114
+ absoluteWall: 272_000,
115
+ },
116
+ },
117
+ },
118
+ ] as const;
119
+
120
+ for (const { provider, model, limit, expected } of cases) {
121
+ expect(deriveWindowGeometry(provider, model, limit)).toEqual(expected);
122
+ }
244
123
  });
245
124
 
246
- test("output_reserve forms override a pre-carved input and overlay output facts", () => {
247
- const data = overlay("openai-codex", "gpt-5.6-sol", {
248
- "output.enforced": fact({ kind: "stated", value: 68_000 }),
249
- });
125
+ test("output_reserve forms override a pre-carved input and catalog output", () => {
250
126
  const cases = [
251
127
  16_384,
252
128
  { default: 16_384 },
@@ -259,7 +135,6 @@ describe("window geometry", () => {
259
135
  "gpt-5.6-sol",
260
136
  { context: 400_000, input: 272_000, output: 128_000 },
261
137
  {
262
- overlay: resolveWindowOverlayFacts("openai-codex", "gpt-5.6-sol", data),
263
138
  outputReserveOverride: resolveOutputReserve(
264
139
  "openai-codex",
265
140
  "gpt-5.6-sol",
@@ -276,27 +151,18 @@ describe("window geometry", () => {
276
151
  }
277
152
  });
278
153
 
279
- test("provider hook wins over overlay, while overlay beats catalog", () => {
280
- const data = overlay("provider", "model", {
281
- "window.enforced": fact({ kind: "stated", value: 300_000 }),
282
- "output.enforced": fact({ kind: "stated", value: 20_000 }),
154
+ test("provider hook overrides catalog limits field by field", () => {
155
+ const catalog = deriveWindowGeometry("provider", "model", {
156
+ context: 200_000,
157
+ output: 10_000,
283
158
  });
284
- const overlayOnly = deriveWindowGeometry(
285
- "provider",
286
- "model",
287
- { context: 200_000, output: 10_000 },
288
- { overlay: resolveWindowOverlayFacts("provider", "model", data) },
289
- );
290
159
  const hooked = deriveWindowGeometry(
291
160
  "provider",
292
161
  "model",
293
162
  { context: 200_000, output: 10_000 },
294
- {
295
- overlay: resolveWindowOverlayFacts("provider", "model", data),
296
- providerLimit: { context: 400_000, output: 30_000 },
297
- },
163
+ { providerLimit: { context: 400_000, output: 30_000 } },
298
164
  );
299
- expect(overlayOnly?.derivation.window).toBe(300_000);
165
+ expect(catalog?.derivation.window).toBe(200_000);
300
166
  expect(hooked?.derivation.window).toBe(400_000);
301
167
  expect(hooked?.derivation.reserve).toBe(30_000);
302
168
  });
@@ -360,7 +226,7 @@ describe("window geometry", () => {
360
226
  expect(logs[0]).toContain("clamped");
361
227
  });
362
228
 
363
- test("keeps no-overlay usableSoft byte-identical to legacy resolveLimit", () => {
229
+ test("catalog usableSoft matches the legacy resolver", () => {
364
230
  const corpus = [
365
231
  ["openai", "real", { context: 200_000, output: 32_000 }],
366
232
  ["openai", "zero", { context: 200_000, output: 0 }],