@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.
- package/dist/{announcement-fp14dw0n.js → announcement-hdbkt8v5.js} +1 -1
- package/dist/auto-search-worker.js +3 -3
- package/dist/config/{mural-model-deprecation.d.ts → deprecated-config.d.ts} +4 -1
- package/dist/config/deprecated-config.d.ts.map +1 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/project-security.d.ts +2 -2
- package/dist/config/schema/magic-context.d.ts +4 -4
- package/dist/config/schema/magic-context.d.ts.map +1 -1
- package/dist/{conflict-warning-hook-kzx4dmk1.js → conflict-warning-hook-asnt6hfc.js} +3 -3
- package/dist/{context-nj5f293n.js → context-tfyhtdcs.js} +111 -45
- package/dist/{derive-budgets-qz5rrr08.js → derive-budgets-j4ry8j8n.js} +1 -1
- package/dist/{embedding-backfill-aetxv1vt.js → embedding-backfill-wyc3ykyf.js} +7 -7
- package/dist/embedding-worker-process.js +30 -0
- package/dist/embedding-worker.js +5 -5
- package/dist/features/magic-context/dreamer/task-registry.d.ts +2 -3
- package/dist/features/magic-context/dreamer/task-registry.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-worker-client.d.ts +8 -1
- package/dist/features/magic-context/memory/embedding-worker-client.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-worker-process.d.ts +2 -0
- package/dist/features/magic-context/memory/embedding-worker-process.d.ts.map +1 -0
- package/dist/features/magic-context/memory/onnx-telemetry.d.ts +3 -0
- package/dist/features/magic-context/memory/onnx-telemetry.d.ts.map +1 -0
- package/dist/features/magic-context/overflow-detection.d.ts +1 -2
- package/dist/features/magic-context/overflow-detection.d.ts.map +1 -1
- package/dist/features/magic-context/storage-session-tables.d.ts.map +1 -1
- package/dist/features/magic-context/transform-decision-log.d.ts +1 -1
- package/dist/features/magic-context/transform-decision-log.d.ts.map +1 -1
- package/dist/features/magic-context/user-memory/storage-user-memory.d.ts +1 -0
- package/dist/features/magic-context/user-memory/storage-user-memory.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/final-wire-token-estimate.d.ts +1 -0
- package/dist/hooks/magic-context/final-wire-token-estimate.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts +1 -0
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-measured-request.d.ts +3 -1
- package/dist/hooks/magic-context/lkg-measured-request.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-persist.d.ts +8 -14
- package/dist/hooks/magic-context/lkg-persist.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-recovery-fence.d.ts +62 -0
- package/dist/hooks/magic-context/lkg-recovery-fence.d.ts.map +1 -0
- package/dist/hooks/magic-context/lkg-recovery-prefix.d.ts +38 -0
- package/dist/hooks/magic-context/lkg-recovery-prefix.d.ts.map +1 -0
- package/dist/hooks/magic-context/lkg-replay.d.ts +3 -1
- package/dist/hooks/magic-context/lkg-replay.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-slot.d.ts.map +1 -1
- package/dist/hooks/magic-context/opaque-thinking.d.ts +12 -0
- package/dist/hooks/magic-context/opaque-thinking.d.ts.map +1 -0
- package/dist/hooks/magic-context/pass-outcome.d.ts +2 -2
- package/dist/hooks/magic-context/pending-materialization.d.ts +8 -0
- package/dist/hooks/magic-context/pending-materialization.d.ts.map +1 -0
- package/dist/hooks/magic-context/read-session-db.d.ts +3 -0
- package/dist/hooks/magic-context/read-session-db.d.ts.map +1 -1
- package/dist/hooks/magic-context/recomp-orchestrator.d.ts.map +1 -1
- package/dist/hooks/magic-context/rust-mode-transform.d.ts +1 -0
- package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/strip-content.d.ts +5 -2
- package/dist/hooks/magic-context/strip-content.d.ts.map +1 -1
- package/dist/hooks/magic-context/system-date-refresh.d.ts +29 -0
- package/dist/hooks/magic-context/system-date-refresh.d.ts.map +1 -0
- package/dist/hooks/magic-context/system-prompt-dates.d.ts +6 -0
- package/dist/hooks/magic-context/system-prompt-dates.d.ts.map +1 -0
- package/dist/hooks/magic-context/system-prompt-delivery.d.ts +47 -0
- package/dist/hooks/magic-context/system-prompt-delivery.d.ts.map +1 -0
- package/dist/hooks/magic-context/system-prompt-hash.d.ts +4 -0
- package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
- package/dist/hooks/magic-context/tag-messages.d.ts +8 -0
- package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +2 -0
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +6 -0
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-9qjqq45k.js → index-0pjvpfkf.js} +21 -1
- package/dist/index-6m7rdv7y.js +733 -0
- package/dist/{index-1r0k9js3.js → index-6tfxmc4n.js} +10 -10
- package/dist/{index-gzcmtmar.js → index-7w18gg78.js} +25 -1
- package/dist/{index-nm6a8xpd.js → index-att4bfan.js} +1 -1
- package/dist/{index-ezmszwbd.js → index-eypn4ba6.js} +7 -4
- package/dist/{index-ha87j7a8.js → index-fdtkt5r1.js} +6 -6
- package/dist/{index-kp5qe690.js → index-fg00p1cg.js} +38 -36
- package/dist/{index-1bc61ans.js → index-fvnzcnww.js} +44 -1
- package/dist/index-gbmqa9x9.js +1170 -0
- package/dist/{index-pxwp2hjk.js → index-gzky5rva.js} +30 -53
- package/dist/{index-kq57tdf0.js → index-k6xvbj2e.js} +255 -1075
- package/dist/{index-0w56v4fm.js → index-mw7c950g.js} +1 -1
- package/dist/{index-1g30axtz.js → index-p0n5ryq8.js} +82 -900
- package/dist/{index-b7mv1jx3.js → index-p1hnwfd8.js} +1 -1
- package/dist/{index-peshmj6h.js → index-r2zcs71c.js} +6 -4
- package/dist/{index-kmpvemph.js → index-rafsaxac.js} +2 -2
- package/dist/{index-stbr4ce6.js → index-s7fc0fkn.js} +1 -1
- package/dist/{index-hj2q50k0.js → index-sfhndpcb.js} +463 -6
- package/dist/index-sv0bb7vg.js +6972 -0
- package/dist/{index-57mrqed8.js → index-w23dh319.js} +17 -258
- package/dist/{index-9rt53q79.js → index-xgrwmj82.js} +1 -1
- package/dist/{index-h2py7207.js → index-xnanvj3w.js} +765 -1255
- package/dist/{index-2jcbj7r1.js → index-zfzdpeq2.js} +2269 -3802
- package/dist/{index-s4j7t92z.js → index-zg8yq4ya.js} +29 -744
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +209 -61
- package/dist/{message-index-bounded-h0mrd4pr.js → message-index-bounded-hqktkhdy.js} +7 -6
- package/dist/migration-worker.js +6 -5
- package/dist/plugin/hooks/create-session-hooks.d.ts +3 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/plugin/messages-transform.d.ts.map +1 -1
- package/dist/plugin/rpc-handlers.d.ts.map +1 -1
- package/dist/{project-embedding-registry-rtt0djyb.js → project-embedding-registry-0gv3h6y8.js} +6 -6
- package/dist/raw-ordinal-warmup-worker.js +1 -1
- package/dist/{read-session-chunk-ty89v75e.js → read-session-chunk-5mh0bh8y.js} +5 -4
- package/dist/{recomp-orchestrator-4f1yyd1q.js → recomp-orchestrator-kpkhkjhq.js} +20 -19
- package/dist/{search-pz4f4wge.js → search-p9w39qv4.js} +15 -14
- package/dist/{send-session-notification-38cd5dqt.js → send-session-notification-xffh3bbe.js} +2 -2
- package/dist/shared/models-dev-cache.d.ts.map +1 -1
- package/dist/shared/storage-file-mutex.d.ts +9 -0
- package/dist/shared/storage-file-mutex.d.ts.map +1 -0
- package/dist/shared/storage-permissions.d.ts +6 -0
- package/dist/shared/storage-permissions.d.ts.map +1 -1
- package/dist/shared/window-geometry.d.ts +9 -66
- package/dist/shared/window-geometry.d.ts.map +1 -1
- package/dist/standalone-plugin-marker.d.ts +8 -0
- package/dist/standalone-plugin-marker.d.ts.map +1 -0
- package/dist/tools/ctx-reduce/constants.d.ts +1 -2
- package/dist/tools/ctx-reduce/constants.d.ts.map +1 -1
- package/dist/tools/ctx-reduce/tools.d.ts +1 -1
- package/dist/tools/ctx-reduce/tools.d.ts.map +1 -1
- package/dist/{transform-postprocess-phase-tck4g20s.js → transform-postprocess-phase-481j5a7z.js} +20 -19
- package/dist/v2/auto-search-worker.js +3 -3
- package/dist/v2/{context-crbt6p1y.js → context-gsdtha5v.js} +873 -2122
- package/dist/v2/{derive-budgets-fgej9j46.js → derive-budgets-enckmg7y.js} +2 -2
- package/dist/v2/{embedding-backfill-ph1qfyn3.js → embedding-backfill-dbvjbcmm.js} +8 -9
- package/dist/v2/embedding-worker-process.js +29 -0
- package/dist/v2/embedding-worker.js +3 -4
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/copied-tag-notation.d.ts +19 -0
- package/dist/v2/hooks/copied-tag-notation.d.ts.map +1 -0
- package/dist/v2/hooks/payload.d.ts.map +1 -1
- package/dist/v2/hooks/system-prompt-response.d.ts +5 -0
- package/dist/v2/hooks/system-prompt-response.d.ts.map +1 -0
- package/dist/v2/{message-index-bounded-xwqdywxg.js → message-index-bounded-p6v0n8qh.js} +8 -7
- package/dist/v2/migration-worker.js +6 -5
- package/dist/v2/{project-embedding-registry-d6m7tyxr.js → project-embedding-registry-nyq7z8y6.js} +7 -8
- package/dist/v2/raw-ordinal-warmup-worker.js +2 -2
- package/dist/v2/{read-session-chunk-8p5mdryx.js → read-session-chunk-fhyfe4qa.js} +6 -5
- package/dist/v2/{recomp-orchestrator-ckfgt6wq.js → recomp-orchestrator-5xy7w136.js} +22 -22
- package/dist/v2/{search-ym8rehhz.js → search-j7bakcwa.js} +17 -17
- package/dist/v2/{send-session-notification-5m0yapqx.js → send-session-notification-f6v698r5.js} +2 -2
- package/dist/v2/{server-jvxzm1jy.js → server-1fszbabv.js} +28 -28
- package/dist/v2/{server-3j4d00kf.js → server-2htmbqbv.js} +25 -1
- package/dist/v2/{server-c5rrgrcd.js → server-4c7jt8gq.js} +25 -1
- package/dist/v2/{server-ycw9qqcy.js → server-4enr7s6x.js} +1 -1
- package/dist/v2/{server-v4mewb78.js → server-6tcrjfw8.js} +1 -1
- package/dist/v2/{server-x4hscabv.js → server-7spkq1y6.js} +2257 -3746
- package/dist/v2/{server-sa8jvrfc.js → server-7vkj6zhb.js} +29 -744
- package/dist/v2/{server-xwz4dqh9.js → server-8xmq9h3f.js} +30 -53
- package/dist/v2/{server-1tk82krw.js → server-bgzy0phk.js} +463 -6
- package/dist/v2/server-c7n2ftng.js +6860 -0
- package/dist/v2/server-cvgn49tr.js +733 -0
- package/dist/v2/{server-zm570tr2.js → server-cw6521wn.js} +232 -7
- package/dist/v2/{server-pj4pjv02.js → server-czb2rkpk.js} +21 -1
- package/dist/v2/{server-19zjmn02.js → server-d6g4whc2.js} +20 -14
- package/dist/v2/{server-1bc61ans.js → server-fvnzcnww.js} +44 -1
- package/dist/v2/{server-w32kmdez.js → server-kh958yj8.js} +3 -3
- package/dist/v2/{server-q4ph9bwn.js → server-mqvtz7wz.js} +7 -7
- package/dist/v2/{server-2s6ayq3t.js → server-ras2sxnc.js} +133 -13
- package/dist/v2/{server-ss95ky04.js → server-s2st631p.js} +1 -1
- package/dist/v2/{server-2s9qz6n7.js → server-t528t8qm.js} +1 -1
- package/dist/v2/{server-8k2agx29.js → server-vb7pbd9p.js} +17 -258
- package/dist/v2/{server-zp53y8js.js → server-zbxjj2mz.js} +2 -2
- package/dist/v2/server.d.ts.map +1 -1
- package/dist/v2/server.js +149 -5
- package/dist/v2/{storage-tags-8vw924zn.js → storage-tags-5yxrvkaf.js} +1 -1
- package/dist/v2/{wrapup-orchestrator-a7efxaax.js → wrapup-orchestrator-yem5422s.js} +28 -28
- package/dist/{wrapup-orchestrator-barbc6h9.js → wrapup-orchestrator-xvrr27ws.js} +21 -20
- package/package.json +4 -4
- package/src/config/{mural-model-deprecation.ts → deprecated-config.ts} +19 -0
- package/src/config/index.test.ts +15 -37
- package/src/config/index.ts +2 -3
- package/src/config/project-security.ts +3 -3
- package/src/config/schema/magic-context.ts +11 -7
- package/src/features/magic-context/dreamer/task-registry.ts +2 -3
- package/src/shared/models-dev-cache.ts +1 -7
- package/src/shared/sqlite-640-review.test.ts +5 -1
- package/src/shared/storage-file-mutex-review.test.ts +162 -0
- package/src/shared/storage-file-mutex.ts +130 -0
- package/src/shared/storage-permissions.ts +46 -0
- package/src/shared/window-geometry.test.ts +102 -236
- package/src/shared/window-geometry.ts +23 -413
- package/dist/config/mural-model-deprecation.d.ts.map +0 -1
- package/dist/index-2jgwttpt.js +0 -3269
- package/dist/index-mfkzp7qj.js +0 -229
- package/dist/v2/server-4ez8mntn.js +0 -3213
- package/dist/v2/server-mfkzp7qj.js +0 -229
- package/src/shared/__fixtures__/window-overlay.v1.json +0 -337
- /package/dist/{index-2pp04pmg.js → index-69vas84q.js} +0 -0
- /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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
78
|
+
catalogValue: number | undefined,
|
|
443
79
|
providerValue: number | undefined,
|
|
444
80
|
): number | undefined {
|
|
445
|
-
return isFinitePositive(providerValue) ? providerValue :
|
|
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
|
-
|
|
469
|
-
|
|
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.
|
|
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 ??
|
|
502
|
-
const
|
|
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
|
-
:
|
|
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} (
|
|
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
|
|
652
|
-
*
|
|
653
|
-
*
|
|
654
|
-
*
|
|
655
|
-
*
|
|
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"}
|