@cortexkit/opencode-magic-context 0.49.0 → 0.49.1

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 (195) hide show
  1. package/dist/{announcement-fp14dw0n.js → announcement-hdbkt8v5.js} +1 -1
  2. package/dist/auto-search-worker.js +3 -3
  3. package/dist/config/{mural-model-deprecation.d.ts → deprecated-config.d.ts} +4 -1
  4. package/dist/config/deprecated-config.d.ts.map +1 -0
  5. package/dist/config/index.d.ts.map +1 -1
  6. package/dist/config/project-security.d.ts +2 -2
  7. package/dist/config/schema/magic-context.d.ts +4 -4
  8. package/dist/config/schema/magic-context.d.ts.map +1 -1
  9. package/dist/{conflict-warning-hook-kzx4dmk1.js → conflict-warning-hook-asnt6hfc.js} +3 -3
  10. package/dist/{context-nj5f293n.js → context-tfyhtdcs.js} +111 -45
  11. package/dist/{derive-budgets-qz5rrr08.js → derive-budgets-j4ry8j8n.js} +1 -1
  12. package/dist/{embedding-backfill-aetxv1vt.js → embedding-backfill-wyc3ykyf.js} +7 -7
  13. package/dist/embedding-worker-process.js +30 -0
  14. package/dist/embedding-worker.js +5 -5
  15. package/dist/features/magic-context/dreamer/task-registry.d.ts +2 -3
  16. package/dist/features/magic-context/dreamer/task-registry.d.ts.map +1 -1
  17. package/dist/features/magic-context/memory/embedding-worker-client.d.ts +8 -1
  18. package/dist/features/magic-context/memory/embedding-worker-client.d.ts.map +1 -1
  19. package/dist/features/magic-context/memory/embedding-worker-process.d.ts +2 -0
  20. package/dist/features/magic-context/memory/embedding-worker-process.d.ts.map +1 -0
  21. package/dist/features/magic-context/memory/onnx-telemetry.d.ts +3 -0
  22. package/dist/features/magic-context/memory/onnx-telemetry.d.ts.map +1 -0
  23. package/dist/features/magic-context/overflow-detection.d.ts +1 -2
  24. package/dist/features/magic-context/overflow-detection.d.ts.map +1 -1
  25. package/dist/features/magic-context/storage-session-tables.d.ts.map +1 -1
  26. package/dist/features/magic-context/transform-decision-log.d.ts +1 -1
  27. package/dist/features/magic-context/transform-decision-log.d.ts.map +1 -1
  28. package/dist/features/magic-context/user-memory/storage-user-memory.d.ts +1 -0
  29. package/dist/features/magic-context/user-memory/storage-user-memory.d.ts.map +1 -1
  30. package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
  31. package/dist/hooks/magic-context/final-wire-token-estimate.d.ts +1 -0
  32. package/dist/hooks/magic-context/final-wire-token-estimate.d.ts.map +1 -1
  33. package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
  34. package/dist/hooks/magic-context/hook.d.ts +1 -0
  35. package/dist/hooks/magic-context/hook.d.ts.map +1 -1
  36. package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
  37. package/dist/hooks/magic-context/lkg-measured-request.d.ts +3 -1
  38. package/dist/hooks/magic-context/lkg-measured-request.d.ts.map +1 -1
  39. package/dist/hooks/magic-context/lkg-persist.d.ts +8 -14
  40. package/dist/hooks/magic-context/lkg-persist.d.ts.map +1 -1
  41. package/dist/hooks/magic-context/lkg-recovery-fence.d.ts +62 -0
  42. package/dist/hooks/magic-context/lkg-recovery-fence.d.ts.map +1 -0
  43. package/dist/hooks/magic-context/lkg-recovery-prefix.d.ts +38 -0
  44. package/dist/hooks/magic-context/lkg-recovery-prefix.d.ts.map +1 -0
  45. package/dist/hooks/magic-context/lkg-replay.d.ts +3 -1
  46. package/dist/hooks/magic-context/lkg-replay.d.ts.map +1 -1
  47. package/dist/hooks/magic-context/lkg-slot.d.ts.map +1 -1
  48. package/dist/hooks/magic-context/opaque-thinking.d.ts +12 -0
  49. package/dist/hooks/magic-context/opaque-thinking.d.ts.map +1 -0
  50. package/dist/hooks/magic-context/pass-outcome.d.ts +2 -2
  51. package/dist/hooks/magic-context/pending-materialization.d.ts +8 -0
  52. package/dist/hooks/magic-context/pending-materialization.d.ts.map +1 -0
  53. package/dist/hooks/magic-context/read-session-db.d.ts +3 -0
  54. package/dist/hooks/magic-context/read-session-db.d.ts.map +1 -1
  55. package/dist/hooks/magic-context/recomp-orchestrator.d.ts.map +1 -1
  56. package/dist/hooks/magic-context/rust-mode-transform.d.ts +1 -0
  57. package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
  58. package/dist/hooks/magic-context/strip-content.d.ts +5 -2
  59. package/dist/hooks/magic-context/strip-content.d.ts.map +1 -1
  60. package/dist/hooks/magic-context/system-date-refresh.d.ts +29 -0
  61. package/dist/hooks/magic-context/system-date-refresh.d.ts.map +1 -0
  62. package/dist/hooks/magic-context/system-prompt-dates.d.ts +6 -0
  63. package/dist/hooks/magic-context/system-prompt-dates.d.ts.map +1 -0
  64. package/dist/hooks/magic-context/system-prompt-delivery.d.ts +47 -0
  65. package/dist/hooks/magic-context/system-prompt-delivery.d.ts.map +1 -0
  66. package/dist/hooks/magic-context/system-prompt-hash.d.ts +4 -0
  67. package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
  68. package/dist/hooks/magic-context/tag-messages.d.ts +8 -0
  69. package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
  70. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +2 -0
  71. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  72. package/dist/hooks/magic-context/transform.d.ts +6 -0
  73. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  74. package/dist/{index-9qjqq45k.js → index-0pjvpfkf.js} +21 -1
  75. package/dist/index-6m7rdv7y.js +733 -0
  76. package/dist/{index-1r0k9js3.js → index-6tfxmc4n.js} +10 -10
  77. package/dist/{index-gzcmtmar.js → index-7w18gg78.js} +25 -1
  78. package/dist/{index-nm6a8xpd.js → index-att4bfan.js} +1 -1
  79. package/dist/{index-ezmszwbd.js → index-eypn4ba6.js} +7 -4
  80. package/dist/{index-ha87j7a8.js → index-fdtkt5r1.js} +6 -6
  81. package/dist/{index-kp5qe690.js → index-fg00p1cg.js} +38 -36
  82. package/dist/{index-1bc61ans.js → index-fvnzcnww.js} +44 -1
  83. package/dist/index-gbmqa9x9.js +1170 -0
  84. package/dist/{index-pxwp2hjk.js → index-gzky5rva.js} +30 -53
  85. package/dist/{index-kq57tdf0.js → index-k6xvbj2e.js} +255 -1075
  86. package/dist/{index-0w56v4fm.js → index-mw7c950g.js} +1 -1
  87. package/dist/{index-1g30axtz.js → index-p0n5ryq8.js} +82 -900
  88. package/dist/{index-b7mv1jx3.js → index-p1hnwfd8.js} +1 -1
  89. package/dist/{index-peshmj6h.js → index-r2zcs71c.js} +6 -4
  90. package/dist/{index-kmpvemph.js → index-rafsaxac.js} +2 -2
  91. package/dist/{index-stbr4ce6.js → index-s7fc0fkn.js} +1 -1
  92. package/dist/{index-hj2q50k0.js → index-sfhndpcb.js} +463 -6
  93. package/dist/index-sv0bb7vg.js +6972 -0
  94. package/dist/{index-57mrqed8.js → index-w23dh319.js} +17 -258
  95. package/dist/{index-9rt53q79.js → index-xgrwmj82.js} +1 -1
  96. package/dist/{index-h2py7207.js → index-xnanvj3w.js} +765 -1255
  97. package/dist/{index-2jcbj7r1.js → index-zfzdpeq2.js} +2269 -3802
  98. package/dist/{index-s4j7t92z.js → index-zg8yq4ya.js} +29 -744
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js +209 -61
  101. package/dist/{message-index-bounded-h0mrd4pr.js → message-index-bounded-hqktkhdy.js} +7 -6
  102. package/dist/migration-worker.js +6 -5
  103. package/dist/plugin/hooks/create-session-hooks.d.ts +3 -1
  104. package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
  105. package/dist/plugin/messages-transform.d.ts.map +1 -1
  106. package/dist/plugin/rpc-handlers.d.ts.map +1 -1
  107. package/dist/{project-embedding-registry-rtt0djyb.js → project-embedding-registry-0gv3h6y8.js} +6 -6
  108. package/dist/raw-ordinal-warmup-worker.js +1 -1
  109. package/dist/{read-session-chunk-ty89v75e.js → read-session-chunk-5mh0bh8y.js} +5 -4
  110. package/dist/{recomp-orchestrator-4f1yyd1q.js → recomp-orchestrator-kpkhkjhq.js} +20 -19
  111. package/dist/{search-pz4f4wge.js → search-p9w39qv4.js} +15 -14
  112. package/dist/{send-session-notification-38cd5dqt.js → send-session-notification-xffh3bbe.js} +2 -2
  113. package/dist/shared/models-dev-cache.d.ts.map +1 -1
  114. package/dist/shared/storage-file-mutex.d.ts +9 -0
  115. package/dist/shared/storage-file-mutex.d.ts.map +1 -0
  116. package/dist/shared/storage-permissions.d.ts +6 -0
  117. package/dist/shared/storage-permissions.d.ts.map +1 -1
  118. package/dist/shared/window-geometry.d.ts +9 -66
  119. package/dist/shared/window-geometry.d.ts.map +1 -1
  120. package/dist/standalone-plugin-marker.d.ts +8 -0
  121. package/dist/standalone-plugin-marker.d.ts.map +1 -0
  122. package/dist/tools/ctx-reduce/constants.d.ts +1 -2
  123. package/dist/tools/ctx-reduce/constants.d.ts.map +1 -1
  124. package/dist/tools/ctx-reduce/tools.d.ts +1 -1
  125. package/dist/tools/ctx-reduce/tools.d.ts.map +1 -1
  126. package/dist/{transform-postprocess-phase-tck4g20s.js → transform-postprocess-phase-481j5a7z.js} +20 -19
  127. package/dist/v2/auto-search-worker.js +3 -3
  128. package/dist/v2/{context-crbt6p1y.js → context-gsdtha5v.js} +873 -2122
  129. package/dist/v2/{derive-budgets-fgej9j46.js → derive-budgets-enckmg7y.js} +2 -2
  130. package/dist/v2/{embedding-backfill-ph1qfyn3.js → embedding-backfill-dbvjbcmm.js} +8 -9
  131. package/dist/v2/embedding-worker-process.js +29 -0
  132. package/dist/v2/embedding-worker.js +3 -4
  133. package/dist/v2/hooks/context.d.ts.map +1 -1
  134. package/dist/v2/hooks/copied-tag-notation.d.ts +19 -0
  135. package/dist/v2/hooks/copied-tag-notation.d.ts.map +1 -0
  136. package/dist/v2/hooks/payload.d.ts.map +1 -1
  137. package/dist/v2/hooks/system-prompt-response.d.ts +5 -0
  138. package/dist/v2/hooks/system-prompt-response.d.ts.map +1 -0
  139. package/dist/v2/{message-index-bounded-xwqdywxg.js → message-index-bounded-p6v0n8qh.js} +8 -7
  140. package/dist/v2/migration-worker.js +6 -5
  141. package/dist/v2/{project-embedding-registry-d6m7tyxr.js → project-embedding-registry-nyq7z8y6.js} +7 -8
  142. package/dist/v2/raw-ordinal-warmup-worker.js +2 -2
  143. package/dist/v2/{read-session-chunk-8p5mdryx.js → read-session-chunk-fhyfe4qa.js} +6 -5
  144. package/dist/v2/{recomp-orchestrator-ckfgt6wq.js → recomp-orchestrator-5xy7w136.js} +22 -22
  145. package/dist/v2/{search-ym8rehhz.js → search-j7bakcwa.js} +17 -17
  146. package/dist/v2/{send-session-notification-5m0yapqx.js → send-session-notification-f6v698r5.js} +2 -2
  147. package/dist/v2/{server-jvxzm1jy.js → server-1fszbabv.js} +28 -28
  148. package/dist/v2/{server-3j4d00kf.js → server-2htmbqbv.js} +25 -1
  149. package/dist/v2/{server-c5rrgrcd.js → server-4c7jt8gq.js} +25 -1
  150. package/dist/v2/{server-ycw9qqcy.js → server-4enr7s6x.js} +1 -1
  151. package/dist/v2/{server-v4mewb78.js → server-6tcrjfw8.js} +1 -1
  152. package/dist/v2/{server-x4hscabv.js → server-7spkq1y6.js} +2257 -3746
  153. package/dist/v2/{server-sa8jvrfc.js → server-7vkj6zhb.js} +29 -744
  154. package/dist/v2/{server-xwz4dqh9.js → server-8xmq9h3f.js} +30 -53
  155. package/dist/v2/{server-1tk82krw.js → server-bgzy0phk.js} +463 -6
  156. package/dist/v2/server-c7n2ftng.js +6860 -0
  157. package/dist/v2/server-cvgn49tr.js +733 -0
  158. package/dist/v2/{server-zm570tr2.js → server-cw6521wn.js} +232 -7
  159. package/dist/v2/{server-pj4pjv02.js → server-czb2rkpk.js} +21 -1
  160. package/dist/v2/{server-19zjmn02.js → server-d6g4whc2.js} +20 -14
  161. package/dist/v2/{server-1bc61ans.js → server-fvnzcnww.js} +44 -1
  162. package/dist/v2/{server-w32kmdez.js → server-kh958yj8.js} +3 -3
  163. package/dist/v2/{server-q4ph9bwn.js → server-mqvtz7wz.js} +7 -7
  164. package/dist/v2/{server-2s6ayq3t.js → server-ras2sxnc.js} +133 -13
  165. package/dist/v2/{server-ss95ky04.js → server-s2st631p.js} +1 -1
  166. package/dist/v2/{server-2s9qz6n7.js → server-t528t8qm.js} +1 -1
  167. package/dist/v2/{server-8k2agx29.js → server-vb7pbd9p.js} +17 -258
  168. package/dist/v2/{server-zp53y8js.js → server-zbxjj2mz.js} +2 -2
  169. package/dist/v2/server.d.ts.map +1 -1
  170. package/dist/v2/server.js +149 -5
  171. package/dist/v2/{storage-tags-8vw924zn.js → storage-tags-5yxrvkaf.js} +1 -1
  172. package/dist/v2/{wrapup-orchestrator-a7efxaax.js → wrapup-orchestrator-yem5422s.js} +28 -28
  173. package/dist/{wrapup-orchestrator-barbc6h9.js → wrapup-orchestrator-xvrr27ws.js} +21 -20
  174. package/package.json +4 -4
  175. package/src/config/{mural-model-deprecation.ts → deprecated-config.ts} +19 -0
  176. package/src/config/index.test.ts +15 -37
  177. package/src/config/index.ts +2 -3
  178. package/src/config/project-security.ts +3 -3
  179. package/src/config/schema/magic-context.ts +11 -7
  180. package/src/features/magic-context/dreamer/task-registry.ts +2 -3
  181. package/src/shared/models-dev-cache.ts +1 -7
  182. package/src/shared/sqlite-640-review.test.ts +5 -1
  183. package/src/shared/storage-file-mutex-review.test.ts +162 -0
  184. package/src/shared/storage-file-mutex.ts +130 -0
  185. package/src/shared/storage-permissions.ts +46 -0
  186. package/src/shared/window-geometry.test.ts +102 -236
  187. package/src/shared/window-geometry.ts +23 -413
  188. package/dist/config/mural-model-deprecation.d.ts.map +0 -1
  189. package/dist/index-2jgwttpt.js +0 -3269
  190. package/dist/index-mfkzp7qj.js +0 -229
  191. package/dist/v2/server-4ez8mntn.js +0 -3213
  192. package/dist/v2/server-mfkzp7qj.js +0 -229
  193. package/src/shared/__fixtures__/window-overlay.v1.json +0 -337
  194. /package/dist/{index-2pp04pmg.js → index-69vas84q.js} +0 -0
  195. /package/dist/v2/{index-2pp04pmg.js → index-69vas84q.js} +0 -0
@@ -1,11 +1,6 @@
1
- import { readFileSync } from "node:fs";
2
- import { join } from "node:path";
3
- import { getDataDir } from "./data-path";
4
- import { modelRefLookupOrder } from "./harness-provider-map";
5
1
  import { sessionLog } from "./logger";
6
2
  import type { ModelLimit } from "./models-dev-cache";
7
3
 
8
- export const WINDOW_OVERLAY_SCHEMA = "fusiform-window-overlay/v1";
9
4
  export const PROMPT_WALL_MARGIN = 4_096;
10
5
  export const PI_OUTPUT_FLOOR = 4_096;
11
6
  export const OPENCODE_OUTPUT_CAP = 32_000;
@@ -25,62 +20,7 @@ export function catalogOutputReserve(window: number, output: number | undefined)
25
20
 
26
21
  export type WindowGeometry = "shared_upfront" | "shared_truncating" | "separate";
27
22
  export type WindowReserveSource = "output_catalog" | "output_config" | "wall_margin" | "none";
28
- export type WindowOverlayGrade =
29
- | "provider_asserted_runtime"
30
- | "measured"
31
- | "provider_asserted_doc"
32
- | "catalog"
33
- | "unknown";
34
- export type WindowOverlayUnits = "provider" | "estimate";
35
- export type WindowOverlayBoundary = "Observed" | "Asserted" | "Corrected";
36
- export type WindowOverlayUnknownWhy =
37
- | "placeholder_output_equals_context"
38
- | "placeholder_zero"
39
- | "never_measured"
40
- // Asserts the KEY cannot hold one fact (e.g. a router samples heterogeneous
41
- // backends per request), so measurement cannot settle it and measured
42
- // reports must not be promoted into stated/bracket cells at this key.
43
- // Ratified terminal at fusiform 080e70208aad713d (2026-08-13), added without a schema bump: an
44
- // additive vocabulary value degrades per-cell for ignorant consumers,
45
- // whereas a version bump would trigger the file-level refusal rule.
46
- | "not_single_valued_at_key"
47
- | "retracted";
48
-
49
- export type WindowOverlayFactValue =
50
- | { kind: "stated"; value: number | string }
51
- | { kind: "bracket"; at_least?: number; below?: number }
52
- | { kind: "unknown"; why: WindowOverlayUnknownWhy };
53
-
54
- export interface WindowOverlayFact {
55
- value: WindowOverlayFactValue;
56
- grade: WindowOverlayGrade;
57
- units: WindowOverlayUnits;
58
- boundary: WindowOverlayBoundary;
59
- source_ref: string;
60
- observed_at: string;
61
- [unknownField: string]: unknown;
62
- }
63
-
64
- export interface WindowOverlayCell {
65
- provider_id: string;
66
- model_id: string;
67
- /** Unknown fact keys are retained so a newer producer can coexist with this v1 consumer. */
68
- facts: Record<string, WindowOverlayFact>;
69
- }
70
-
71
- export interface WindowOverlay {
72
- schema: typeof WINDOW_OVERLAY_SCHEMA;
73
- generated_at: string;
74
- minted_provider_ids: string[];
75
- cells: WindowOverlayCell[];
76
- }
77
-
78
- export interface ResolvedWindowOverlayFacts {
79
- /** Includes facts whose tagged value is explicitly unknown. */
80
- facts: Record<string, WindowOverlayFact>;
81
- }
82
-
83
- export type WindowLimitSource = "catalog" | "overlay" | "provider" | "detected";
23
+ export type WindowLimitSource = "catalog" | "provider" | "detected";
84
24
 
85
25
  export interface WindowDerivation {
86
26
  window: number;
@@ -101,10 +41,9 @@ export interface WindowGeometryResult {
101
41
  }
102
42
 
103
43
  export interface DeriveWindowGeometryOptions {
104
- overlay?: ResolvedWindowOverlayFacts;
105
- /** A provider/auth hook has higher precedence than the overlay, field by field. */
44
+ /** Live provider limits override potentially stale catalog metadata, field by field. */
106
45
  providerLimit?: ModelLimit;
107
- /** Resolved user override; higher precedence than catalog, overlay, and geometry defaults. */
46
+ /** Resolved user override; higher precedence than catalog metadata and geometry defaults. */
108
47
  outputReserveOverride?: number;
109
48
  harness?: "opencode" | "pi";
110
49
  /** Detected overflow remains the final downward cap regardless of other sources. */
@@ -119,315 +58,12 @@ const PROVIDER_GEOMETRY: Readonly<Record<string, WindowGeometry>> = {
119
58
  "google-antigravity": "separate",
120
59
  };
121
60
 
122
- const GRADES = new Set<WindowOverlayGrade>([
123
- "provider_asserted_runtime",
124
- "measured",
125
- "provider_asserted_doc",
126
- "catalog",
127
- "unknown",
128
- ]);
129
- const UNITS = new Set<WindowOverlayUnits>(["provider", "estimate"]);
130
- const BOUNDARIES = new Set<WindowOverlayBoundary>(["Observed", "Asserted", "Corrected"]);
131
- const UNKNOWN_REASONS = new Set<WindowOverlayUnknownWhy>([
132
- "placeholder_output_equals_context",
133
- "placeholder_zero",
134
- "never_measured",
135
- "not_single_valued_at_key",
136
- "retracted",
137
- ]);
138
- const NUMERIC_FACT_KEYS = new Set([
139
- "window.advertised",
140
- "window.enforced",
141
- "output.advertised",
142
- "output.enforced",
143
- "output.default",
144
- ]);
145
-
146
- let configuredOverlayPath: string | undefined;
147
- let loadedOverlayPath: string | undefined;
148
- let loadedOverlay: WindowOverlay | null | undefined;
149
61
  const geometryClampLogSeen = new Set<string>();
150
62
 
151
- function isRecord(value: unknown): value is Record<string, unknown> {
152
- return typeof value === "object" && value !== null && !Array.isArray(value);
153
- }
154
-
155
63
  function isFinitePositive(value: unknown): value is number {
156
64
  return typeof value === "number" && Number.isFinite(value) && value > 0;
157
65
  }
158
66
 
159
- /** Convert the ratified tagged numeric union into the conservative scalar used by derivation. */
160
- export function scalarizeFact(value: WindowOverlayFactValue): number | undefined {
161
- if (value.kind === "stated") return isFinitePositive(value.value) ? value.value : undefined;
162
- if (value.kind === "bracket") {
163
- return isFinitePositive(value.at_least) ? value.at_least : undefined;
164
- }
165
- return undefined;
166
- }
167
-
168
- function parseFactValue(value: unknown): WindowOverlayFactValue | undefined {
169
- if (!isRecord(value) || typeof value.kind !== "string") return undefined;
170
- if (value.kind === "stated") {
171
- if (
172
- (typeof value.value !== "number" || !Number.isFinite(value.value)) &&
173
- typeof value.value !== "string"
174
- ) {
175
- return undefined;
176
- }
177
- return { kind: "stated", value: value.value };
178
- }
179
- if (value.kind === "bracket") {
180
- const atLeast = value.at_least;
181
- const below = value.below;
182
- if (atLeast === undefined && below === undefined) return { kind: "bracket" };
183
- if (atLeast !== undefined && !isFinitePositive(atLeast)) return undefined;
184
- if (below !== undefined && !isFinitePositive(below)) return undefined;
185
- if (isFinitePositive(atLeast) && isFinitePositive(below) && below <= atLeast) {
186
- return undefined;
187
- }
188
- return {
189
- kind: "bracket",
190
- ...(isFinitePositive(atLeast) ? { at_least: atLeast } : {}),
191
- ...(isFinitePositive(below) ? { below } : {}),
192
- };
193
- }
194
- if (value.kind === "unknown" && UNKNOWN_REASONS.has(value.why as WindowOverlayUnknownWhy)) {
195
- return { kind: "unknown", why: value.why as WindowOverlayUnknownWhy };
196
- }
197
- return undefined;
198
- }
199
-
200
- function parseFact(key: string, value: unknown): WindowOverlayFact | undefined {
201
- if (!isRecord(value)) return undefined;
202
- const parsedValue = parseFactValue(value.value);
203
- if (
204
- !parsedValue ||
205
- !GRADES.has(value.grade as WindowOverlayGrade) ||
206
- !UNITS.has(value.units as WindowOverlayUnits) ||
207
- !BOUNDARIES.has(value.boundary as WindowOverlayBoundary) ||
208
- typeof value.source_ref !== "string" ||
209
- value.source_ref.length === 0 ||
210
- typeof value.observed_at !== "string" ||
211
- value.observed_at.length === 0
212
- ) {
213
- return undefined;
214
- }
215
- if (
216
- NUMERIC_FACT_KEYS.has(key) &&
217
- parsedValue.kind === "stated" &&
218
- !isFinitePositive(parsedValue.value)
219
- ) {
220
- return undefined;
221
- }
222
- if (
223
- key === "geometry" &&
224
- parsedValue.kind === "stated" &&
225
- !["shared_upfront", "shared_truncating", "separate"].includes(String(parsedValue.value))
226
- ) {
227
- return undefined;
228
- }
229
- return {
230
- ...value,
231
- value: parsedValue,
232
- grade: value.grade as WindowOverlayGrade,
233
- units: value.units as WindowOverlayUnits,
234
- boundary: value.boundary as WindowOverlayBoundary,
235
- source_ref: value.source_ref,
236
- observed_at: value.observed_at,
237
- } as WindowOverlayFact;
238
- }
239
-
240
- export function parseWindowOverlay(value: unknown): {
241
- overlay?: WindowOverlay;
242
- badCells: number;
243
- refusal?: string;
244
- } {
245
- if (!isRecord(value)) {
246
- return { badCells: 0, refusal: "overlay root is not an object" };
247
- }
248
- if (value.schema !== WINDOW_OVERLAY_SCHEMA) {
249
- return {
250
- badCells: 0,
251
- refusal: `unrecognized schema ${JSON.stringify(value.schema)}`,
252
- };
253
- }
254
- if (
255
- typeof value.generated_at !== "string" ||
256
- !Array.isArray(value.minted_provider_ids) ||
257
- !value.minted_provider_ids.every((id) => typeof id === "string" && id.length > 0) ||
258
- !Array.isArray(value.cells)
259
- ) {
260
- return { badCells: 0, refusal: "invalid v1 envelope" };
261
- }
262
-
263
- const cells: WindowOverlayCell[] = [];
264
- let badCells = 0;
265
- for (const rawCell of value.cells) {
266
- if (
267
- !isRecord(rawCell) ||
268
- typeof rawCell.provider_id !== "string" ||
269
- rawCell.provider_id.length === 0 ||
270
- typeof rawCell.model_id !== "string" ||
271
- rawCell.model_id.length === 0 ||
272
- !isRecord(rawCell.facts)
273
- ) {
274
- badCells++;
275
- continue;
276
- }
277
- const facts: Record<string, WindowOverlayFact> = {};
278
- let valid = true;
279
- for (const [key, rawFact] of Object.entries(rawCell.facts)) {
280
- const fact = parseFact(key, rawFact);
281
- if (!fact) {
282
- valid = false;
283
- break;
284
- }
285
- facts[key] = fact;
286
- }
287
- if (!valid) {
288
- badCells++;
289
- continue;
290
- }
291
- cells.push({
292
- provider_id: rawCell.provider_id,
293
- model_id: rawCell.model_id,
294
- facts,
295
- });
296
- }
297
-
298
- return {
299
- overlay: {
300
- schema: WINDOW_OVERLAY_SCHEMA,
301
- generated_at: value.generated_at,
302
- minted_provider_ids: [...value.minted_provider_ids],
303
- cells,
304
- },
305
- badCells,
306
- };
307
- }
308
-
309
- export function defaultWindowOverlayPath(): string {
310
- return join(getDataDir(), "fusiform", "window-overlay.json");
311
- }
312
-
313
- export function readWindowOverlayFile(
314
- path: string,
315
- log: (message: string) => void = (message) => sessionLog("global", message),
316
- ): WindowOverlay | undefined {
317
- let raw: string;
318
- try {
319
- raw = readFileSync(path, "utf8");
320
- } catch (error) {
321
- if ((error as NodeJS.ErrnoException).code === "ENOENT") return undefined;
322
- log(`window-overlay: unable to read ${path}; overlay ignored`);
323
- return undefined;
324
- }
325
- let decoded: unknown;
326
- try {
327
- decoded = JSON.parse(raw);
328
- } catch {
329
- log(`window-overlay: invalid JSON in ${path}; overlay ignored`);
330
- return undefined;
331
- }
332
- const parsed = parseWindowOverlay(decoded);
333
- if (parsed.refusal) {
334
- log(`window-overlay: ${parsed.refusal} in ${path}; entire overlay ignored`);
335
- return undefined;
336
- }
337
- if (parsed.badCells > 0) {
338
- log(`window-overlay: skipped ${parsed.badCells} invalid cell(s) from ${path}`);
339
- }
340
- return parsed.overlay;
341
- }
342
-
343
- /** Set the user-tier overlay path. Undefined restores the Fusiform data-dir default. */
344
- export function setWindowOverlayPath(path: string | undefined): void {
345
- // Runtime hooks may resolve unchanged config more than once. Preserve the
346
- // process snapshot unless the configured path actually changes, so an
347
- // external same-path rewrite cannot alter geometry between turns.
348
- if (configuredOverlayPath === path) return;
349
- reloadWindowOverlay(path);
350
- }
351
-
352
- /** Start a new overlay snapshot at an explicit plugin/extension reload boundary. */
353
- export function reloadWindowOverlay(path: string | undefined): void {
354
- configuredOverlayPath = path;
355
- loadedOverlayPath = undefined;
356
- loadedOverlay = undefined;
357
- }
358
-
359
- export function clearWindowOverlayCacheForTest(): void {
360
- loadedOverlayPath = undefined;
361
- loadedOverlay = undefined;
362
- geometryClampLogSeen.clear();
363
- }
364
-
365
- export function getWindowOverlay(): WindowOverlay | undefined {
366
- const path = configuredOverlayPath ?? defaultWindowOverlayPath();
367
- if (loadedOverlayPath === path && loadedOverlay !== undefined) {
368
- return loadedOverlay ?? undefined;
369
- }
370
- loadedOverlayPath = path;
371
- loadedOverlay = readWindowOverlayFile(path) ?? null;
372
- return loadedOverlay ?? undefined;
373
- }
374
-
375
- export function resolveWindowOverlayFacts(
376
- providerID: string,
377
- modelID: string,
378
- overlay: WindowOverlay | undefined = getWindowOverlay(),
379
- ): ResolvedWindowOverlayFacts | undefined {
380
- if (!overlay) return undefined;
381
- const modelRefs = modelRefLookupOrder(`${providerID}/${modelID}`);
382
- const providerCandidates = new Set(modelRefs.map((ref) => ref.slice(0, ref.indexOf("/"))));
383
- const modelCandidates = new Set([
384
- modelID,
385
- ...modelRefs.map((ref) => ref.slice(ref.indexOf("/") + 1)),
386
- ]);
387
- const colon = modelID.lastIndexOf(":");
388
- if (colon > 0) modelCandidates.add(modelID.slice(0, colon));
389
-
390
- const wildcardFacts: Record<string, WindowOverlayFact> = {};
391
- const specificFacts: Record<string, WindowOverlayFact> = {};
392
- for (const cell of overlay.cells) {
393
- if (!providerCandidates.has(cell.provider_id)) continue;
394
- if (cell.model_id === "*") Object.assign(wildcardFacts, cell.facts);
395
- else if (modelCandidates.has(cell.model_id)) Object.assign(specificFacts, cell.facts);
396
- }
397
- const facts = { ...wildcardFacts, ...specificFacts };
398
- return Object.keys(facts).length > 0 ? { facts } : undefined;
399
- }
400
-
401
- function numericOverlayFact(
402
- overlay: ResolvedWindowOverlayFacts | undefined,
403
- key: string,
404
- ): number | undefined {
405
- const fact = overlay?.facts[key];
406
- return fact ? scalarizeFact(fact.value) : undefined;
407
- }
408
-
409
- /**
410
- * Three-state geometry resolution from the overlay. The absent-vs-unknown
411
- * distinction is ratified contract semantics: a fact ABSENT from the cell was
412
- * never considered (our static provider table still applies), while a fact
413
- * present with kind "unknown" was considered and has no answer — the dataset
414
- * owner checked the primary source and found the usual inference unsupported
415
- * (e.g. Google's own docs contradict the separate-quota reading), so the
416
- * static assumption built on that same inference must NOT apply either.
417
- */
418
- function overlayGeometry(
419
- overlay: ResolvedWindowOverlayFacts | undefined,
420
- ): { kind: "stated"; value: WindowGeometry } | { kind: "unknown" } | undefined {
421
- const fact = overlay?.facts.geometry;
422
- if (fact === undefined) return undefined;
423
- if (fact.value.kind === "unknown") return { kind: "unknown" };
424
- if (fact.value.kind !== "stated") return undefined;
425
- const value = fact.value.value;
426
- return value === "shared_upfront" || value === "shared_truncating" || value === "separate"
427
- ? { kind: "stated", value }
428
- : undefined;
429
- }
430
-
431
67
  /** Placeholder filtering is deliberately per output field, never a row-level rejection. */
432
68
  export function placeholderFilteredOutput(
433
69
  output: number | undefined,
@@ -439,10 +75,10 @@ export function placeholderFilteredOutput(
439
75
  }
440
76
 
441
77
  function mergePositive(
442
- overlayValue: number | undefined,
78
+ catalogValue: number | undefined,
443
79
  providerValue: number | undefined,
444
80
  ): number | undefined {
445
- return isFinitePositive(providerValue) ? providerValue : overlayValue;
81
+ return isFinitePositive(providerValue) ? providerValue : catalogValue;
446
82
  }
447
83
 
448
84
  function logGeometryClampOnce(key: string, message: string, log?: (message: string) => void): void {
@@ -451,6 +87,10 @@ function logGeometryClampOnce(key: string, message: string, log?: (message: stri
451
87
  (log ?? ((entry) => sessionLog("global", `window-geometry: ${entry}`)))(message);
452
88
  }
453
89
 
90
+ export function clearWindowGeometryLogForTest(): void {
91
+ geometryClampLogSeen.clear();
92
+ }
93
+
454
94
  export function deriveWindowGeometry(
455
95
  providerID: string,
456
96
  modelID: string,
@@ -465,10 +105,8 @@ export function deriveWindowGeometry(
465
105
  const providerContext = isFinitePositive(providerLimit?.context)
466
106
  ? providerLimit.context
467
107
  : undefined;
468
- const advertised = numericOverlayFact(options.overlay, "window.advertised");
469
- const enforced = numericOverlayFact(options.overlay, "window.enforced");
470
- let softContext = mergePositive(enforced ?? advertised ?? catalogContext, providerContext);
471
- let hardContext = mergePositive(enforced ?? softContext, providerContext);
108
+ let softContext = mergePositive(catalogContext, providerContext);
109
+ let hardContext = mergePositive(softContext, providerContext);
472
110
  const contextCap = isFinitePositive(options.contextCap) ? options.contextCap : undefined;
473
111
  const hasContextCap = contextCap !== undefined;
474
112
  if (contextCap !== undefined) {
@@ -486,30 +124,14 @@ export function deriveWindowGeometry(
486
124
  if (!isFinitePositive(softContext) && !isFinitePositive(input)) return undefined;
487
125
 
488
126
  const catalogOutput =
489
- options.overlay === undefined && options.providerLimit === undefined
127
+ options.providerLimit === undefined
490
128
  ? isFinitePositive(catalogLimit?.output)
491
129
  ? catalogLimit.output
492
130
  : undefined
493
131
  : placeholderFilteredOutput(catalogLimit?.output, softContext);
494
- const overlayOutput = placeholderFilteredOutput(
495
- numericOverlayFact(options.overlay, "output.enforced") ??
496
- numericOverlayFact(options.overlay, "output.default") ??
497
- numericOverlayFact(options.overlay, "output.advertised"),
498
- softContext,
499
- );
500
132
  const providerOutput = placeholderFilteredOutput(providerLimit?.output, softContext);
501
- const output = providerOutput ?? overlayOutput ?? catalogOutput;
502
- const geometryFact = overlayGeometry(options.overlay);
503
- // Considered-unknown demotes to shared_upfront — the conservative geometry
504
- // in both directions (largest soft reserve, lowest hard wall) — until a
505
- // measurement settles the cell. Absence falls through to the static table.
506
- const geometry =
507
- geometryFact?.kind === "stated"
508
- ? geometryFact.value
509
- : geometryFact?.kind === "unknown"
510
- ? "shared_upfront"
511
- : (PROVIDER_GEOMETRY[providerID] ?? "shared_upfront");
512
- const geometryOverride = geometryFact?.kind === "stated" ? geometryFact.value : undefined;
133
+ const output = providerOutput ?? catalogOutput;
134
+ const geometry = PROVIDER_GEOMETRY[providerID] ?? "shared_upfront";
513
135
 
514
136
  const preCarvedInput =
515
137
  isFinitePositive(input) && (!isFinitePositive(softContext) || input < softContext);
@@ -550,24 +172,14 @@ export function deriveWindowGeometry(
550
172
  reserveSource = "output_catalog";
551
173
  }
552
174
  } else if (isFinitePositive(softContext)) {
553
- if (
554
- geometry === "separate" &&
555
- (options.overlay === undefined ||
556
- options.harness === "pi" ||
557
- geometryOverride !== undefined)
558
- ) {
175
+ if (geometry === "separate") {
559
176
  softReserve = 0;
560
177
  reserveSource = "none";
561
178
  } else {
562
179
  softReserve = output ?? 0;
563
180
  reserveSource = output === undefined ? "none" : "output_catalog";
564
181
  const cap = softContext * OUTPUT_RESERVE_CAP_RATIO;
565
- softReserve = Math.min(
566
- softReserve,
567
- options.harness === "pi" || options.overlay === undefined
568
- ? cap
569
- : Math.min(cap, OPENCODE_OUTPUT_CAP),
570
- );
182
+ softReserve = Math.min(softReserve, cap);
571
183
  }
572
184
  const floor = Math.max(MIN_PLAUSIBLE_CONTEXT_LIMIT, softContext * 0.5);
573
185
  const flooredReserve = Math.min(softReserve, Math.max(0, softContext - floor));
@@ -595,9 +207,7 @@ export function deriveWindowGeometry(
595
207
  ? "detected"
596
208
  : providerContext !== undefined
597
209
  ? "provider"
598
- : enforced !== undefined || advertised !== undefined
599
- ? "overlay"
600
- : "catalog";
210
+ : "catalog";
601
211
  let usableHard: number;
602
212
  if (geometry === "separate") {
603
213
  usableHard = hardWindow;
@@ -615,7 +225,7 @@ export function deriveWindowGeometry(
615
225
  if (usableHard < usableSoft) {
616
226
  logGeometryClampOnce(
617
227
  `${providerID}/${modelID}|${usableSoft}|${usableHard}`,
618
- `usable hard limit clamped for ${providerID}/${modelID}: ${usableHard} → ${usableSoft} (overlay/provider inversion)`,
228
+ `usable hard limit clamped for ${providerID}/${modelID}: ${usableHard} → ${usableSoft} (window limit inversion)`,
619
229
  options.log,
620
230
  );
621
231
  usableHard = usableSoft;
@@ -648,11 +258,11 @@ export function hasTrustedAbsoluteWall(geometry: WindowGeometryResult): boolean
648
258
 
649
259
  /**
650
260
  * Successful requests can disprove static catalog metadata, but do not widen a
651
- * provider, overlay, or observed-overflow wall here. A provider or overlay wall
652
- * is the configured limit: a reading beyond it is real pressure against that
653
- * limit (the usage handlers count it in full), not proof that the geometry
654
- * should grow. An observed-overflow wall that a larger accepted request
655
- * disproves is cleared by the usage handlers instead.
261
+ * provider or observed-overflow wall here. A provider wall is the configured
262
+ * limit: a reading beyond it is real pressure against that limit (the usage
263
+ * handlers count it in full), not proof that the geometry should grow. An
264
+ * observed-overflow wall that a larger accepted request disproves is cleared by
265
+ * the usage handlers instead.
656
266
  */
657
267
  export function applyProvenInputFloor(
658
268
  geometry: WindowGeometryResult,
@@ -1 +0,0 @@
1
- {"version":3,"file":"mural-model-deprecation.d.ts","sourceRoot":"","sources":["../../src/config/mural-model-deprecation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,+BAA+B,6QACkO,CAAC;AAE/Q;;;;GAIG;AACH,wBAAgB,wBAAwB,CACpC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,QAAQ,EAAE,MAAM,EAAE,GACnB,IAAI,CAKN"}