@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,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DEFAULT_LOCAL_EMBEDDING_MODEL
|
|
3
|
-
} from "./server-
|
|
3
|
+
} from "./server-cw6521wn.js";
|
|
4
4
|
import {
|
|
5
5
|
getHarness2
|
|
6
6
|
} from "./server-pavzsdc6.js";
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
writeStorageFileAsync,
|
|
22
22
|
writeStorageFileHandleAsync,
|
|
23
23
|
createStorageFileHandleAsync
|
|
24
|
-
} from "./server-
|
|
24
|
+
} from "./server-fvnzcnww.js";
|
|
25
25
|
|
|
26
26
|
// src/features/magic-context/memory/embedding-local.ts
|
|
27
27
|
import { readdirSync, statSync } from "node:fs";
|
|
@@ -238,29 +238,116 @@ function getEmbeddingProviderIdentity(config) {
|
|
|
238
238
|
}
|
|
239
239
|
|
|
240
240
|
// src/features/magic-context/memory/embedding-worker-client.ts
|
|
241
|
+
import { fork } from "node:child_process";
|
|
241
242
|
import { Worker } from "node:worker_threads";
|
|
243
|
+
|
|
244
|
+
// src/features/magic-context/memory/onnx-telemetry.ts
|
|
245
|
+
import { isMainThread } from "node:worker_threads";
|
|
246
|
+
var FFI_SPECIFIER = "bun:ffi";
|
|
247
|
+
async function prepareNativeOnnxTelemetry() {
|
|
248
|
+
if (process.platform === "win32")
|
|
249
|
+
return true;
|
|
250
|
+
if (!process.versions.bun) {
|
|
251
|
+
if (!isMainThread)
|
|
252
|
+
return false;
|
|
253
|
+
process.env.ORT_DISABLE_TELEMETRY = "1";
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
let ffi;
|
|
257
|
+
try {
|
|
258
|
+
ffi = await import(FFI_SPECIFIER);
|
|
259
|
+
} catch {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
const { dlopen, FFIType } = ffi;
|
|
263
|
+
const paths = process.platform === "darwin" ? ["/usr/lib/libSystem.B.dylib"] : ["libc.so.6", `/lib/ld-musl-${process.arch === "arm64" ? "aarch64" : "x86_64"}.so.1`];
|
|
264
|
+
for (const path of paths) {
|
|
265
|
+
try {
|
|
266
|
+
const library = dlopen(path, {
|
|
267
|
+
setenv: {
|
|
268
|
+
args: [FFIType.cstring, FFIType.cstring, FFIType.i32],
|
|
269
|
+
returns: FFIType.i32
|
|
270
|
+
},
|
|
271
|
+
getenv: { args: [FFIType.cstring], returns: FFIType.cstring }
|
|
272
|
+
});
|
|
273
|
+
try {
|
|
274
|
+
const name = Buffer.from("ORT_DISABLE_TELEMETRY\x00");
|
|
275
|
+
const value = Buffer.from("1\x00");
|
|
276
|
+
const disabled = library.symbols.setenv(name, value, 1) === 0 && String(library.symbols.getenv(name)) === "1";
|
|
277
|
+
if (disabled)
|
|
278
|
+
process.env.ORT_DISABLE_TELEMETRY = "1";
|
|
279
|
+
return disabled;
|
|
280
|
+
} finally {
|
|
281
|
+
library.close();
|
|
282
|
+
}
|
|
283
|
+
} catch {}
|
|
284
|
+
}
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// src/features/magic-context/memory/embedding-worker-client.ts
|
|
289
|
+
var warnedWindowsTelemetry = false;
|
|
290
|
+
|
|
242
291
|
class EmbeddingWorkerClient {
|
|
243
292
|
data;
|
|
244
293
|
entry;
|
|
245
294
|
timeoutMs;
|
|
295
|
+
prepareTelemetry;
|
|
246
296
|
worker = null;
|
|
297
|
+
startPromise = null;
|
|
247
298
|
nextId = 1;
|
|
248
299
|
pending = new Map;
|
|
249
300
|
disposed = false;
|
|
250
|
-
constructor(data, entry = new URL(new URL(import.meta.url).pathname.endsWith(".ts") ? "./embedding-worker.ts" : "./embedding-worker.js", import.meta.url), timeoutMs = 5 * 60000) {
|
|
301
|
+
constructor(data, entry = new URL(new URL(import.meta.url).pathname.endsWith(".ts") ? "./embedding-worker.ts" : "./embedding-worker.js", import.meta.url), timeoutMs = 5 * 60000, prepareTelemetry = prepareNativeOnnxTelemetry) {
|
|
251
302
|
this.data = data;
|
|
252
303
|
this.entry = entry;
|
|
253
304
|
this.timeoutMs = timeoutMs;
|
|
305
|
+
this.prepareTelemetry = prepareTelemetry;
|
|
254
306
|
}
|
|
255
307
|
start() {
|
|
308
|
+
if (this.startPromise)
|
|
309
|
+
return this.startPromise;
|
|
310
|
+
this.startPromise = this.startOwner().finally(() => {
|
|
311
|
+
this.startPromise = null;
|
|
312
|
+
});
|
|
313
|
+
return this.startPromise;
|
|
314
|
+
}
|
|
315
|
+
async startOwner() {
|
|
256
316
|
if (this.disposed)
|
|
257
317
|
throw new Error("embedding worker disposed");
|
|
258
318
|
if (this.worker)
|
|
259
319
|
return this.worker;
|
|
260
|
-
const
|
|
320
|
+
const compiledBun = process.versions.bun && globalThis.Bun?.isStandaloneExecutable;
|
|
321
|
+
const inProcess = !compiledBun && await this.prepareTelemetry();
|
|
322
|
+
if (this.disposed)
|
|
323
|
+
throw new Error("embedding worker disposed");
|
|
324
|
+
const worker = inProcess ? new Worker(this.entry, { workerData: this.data }) : fork(new URL(new URL(import.meta.url).pathname.endsWith(".ts") ? "./embedding-worker-process.ts" : "./embedding-worker-process.js", import.meta.url), [], {
|
|
325
|
+
env: {
|
|
326
|
+
...process.env,
|
|
327
|
+
ORT_DISABLE_TELEMETRY: "1",
|
|
328
|
+
...process.versions.bun ? { BUN_BE_BUN: "1" } : {}
|
|
329
|
+
},
|
|
330
|
+
execArgv: [],
|
|
331
|
+
serialization: "json",
|
|
332
|
+
...{ windowsHide: true },
|
|
333
|
+
stdio: ["ignore", "inherit", "inherit", "ipc"]
|
|
334
|
+
});
|
|
335
|
+
if (process.platform === "win32" && this.data.runtimePreference !== "wasm") {
|
|
336
|
+
if (!warnedWindowsTelemetry) {
|
|
337
|
+
warnedWindowsTelemetry = true;
|
|
338
|
+
const warning = "[magic-context] ORT_DISABLE_TELEMETRY=1 prevents ONNX uploads on POSIX. Windows native ONNX uses OS-controlled ETW diagnostics instead and exposes no JavaScript telemetry-disable API; Windows diagnostic settings and trace collectors govern collection.";
|
|
339
|
+
log2(warning);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
261
342
|
this.worker = worker;
|
|
262
343
|
worker.unref();
|
|
263
|
-
|
|
344
|
+
if (!(worker instanceof Worker))
|
|
345
|
+
worker.channel?.unref?.();
|
|
346
|
+
worker.on("message", (wire) => {
|
|
347
|
+
const reply = worker instanceof Worker ? wire : {
|
|
348
|
+
...wire,
|
|
349
|
+
vectors: wire.vectors?.map((vector) => vector === null ? null : new Float32Array(Uint8Array.from(Buffer.from(vector, "base64")).buffer))
|
|
350
|
+
};
|
|
264
351
|
if (this.worker !== worker)
|
|
265
352
|
return;
|
|
266
353
|
const request = this.pending.get(reply.id);
|
|
@@ -272,8 +359,11 @@ class EmbeddingWorkerClient {
|
|
|
272
359
|
request.reject(new Error(reply.error));
|
|
273
360
|
else
|
|
274
361
|
request.resolve(reply);
|
|
275
|
-
if (this.pending.size === 0)
|
|
362
|
+
if (this.pending.size === 0) {
|
|
276
363
|
worker.unref();
|
|
364
|
+
if (!(worker instanceof Worker))
|
|
365
|
+
worker.channel?.unref?.();
|
|
366
|
+
}
|
|
277
367
|
});
|
|
278
368
|
const fail = (error) => {
|
|
279
369
|
if (this.worker !== worker)
|
|
@@ -285,20 +375,29 @@ class EmbeddingWorkerClient {
|
|
|
285
375
|
}
|
|
286
376
|
this.pending.clear();
|
|
287
377
|
log2("[magic-context] embedding worker exited unexpectedly:", error);
|
|
288
|
-
worker
|
|
378
|
+
if (worker instanceof Worker)
|
|
379
|
+
worker.terminate();
|
|
380
|
+
else
|
|
381
|
+
worker.kill();
|
|
289
382
|
};
|
|
290
383
|
worker.on("error", fail);
|
|
291
|
-
worker.on("exit", (code) => fail(new Error(`embedding worker exited (${code})`)));
|
|
384
|
+
worker.on("exit", (code, signal) => fail(new Error(`embedding worker exited (${signal ?? code})`)));
|
|
385
|
+
if (!(worker instanceof Worker))
|
|
386
|
+
worker.send({ entry: this.entry.href, data: this.data });
|
|
292
387
|
return worker;
|
|
293
388
|
}
|
|
294
389
|
isRunning() {
|
|
295
390
|
return this.worker !== null;
|
|
296
391
|
}
|
|
297
|
-
request(texts, signal) {
|
|
392
|
+
async request(texts, signal) {
|
|
298
393
|
if (signal?.aborted)
|
|
299
394
|
return Promise.reject(new Error("embedding request aborted"));
|
|
395
|
+
const worker = await this.start();
|
|
396
|
+
if (this.disposed)
|
|
397
|
+
throw new Error("embedding worker disposed");
|
|
398
|
+
if (signal?.aborted)
|
|
399
|
+
throw new Error("embedding request aborted");
|
|
300
400
|
return new Promise((resolve, reject) => {
|
|
301
|
-
const worker = this.start();
|
|
302
401
|
const id = this.nextId++;
|
|
303
402
|
const timer = setTimeout(() => {
|
|
304
403
|
this.stop(new Error("embedding worker request timed out"));
|
|
@@ -308,8 +407,11 @@ class EmbeddingWorkerClient {
|
|
|
308
407
|
this.pending.delete(id);
|
|
309
408
|
signal?.removeEventListener("abort", abort);
|
|
310
409
|
reject(new Error("embedding request aborted"));
|
|
311
|
-
if (this.pending.size === 0)
|
|
410
|
+
if (this.pending.size === 0) {
|
|
312
411
|
worker.unref();
|
|
412
|
+
if (!(worker instanceof Worker))
|
|
413
|
+
worker.channel?.unref?.();
|
|
414
|
+
}
|
|
313
415
|
};
|
|
314
416
|
signal?.addEventListener("abort", abort, { once: true });
|
|
315
417
|
const cleanup = () => signal?.removeEventListener("abort", abort);
|
|
@@ -325,8 +427,16 @@ class EmbeddingWorkerClient {
|
|
|
325
427
|
}
|
|
326
428
|
});
|
|
327
429
|
worker.ref();
|
|
430
|
+
if (!(worker instanceof Worker))
|
|
431
|
+
worker.channel?.ref?.();
|
|
328
432
|
try {
|
|
329
|
-
worker
|
|
433
|
+
if (worker instanceof Worker)
|
|
434
|
+
worker.postMessage({ id, texts });
|
|
435
|
+
else
|
|
436
|
+
worker.send({ id, texts }, (error) => {
|
|
437
|
+
if (error && this.worker === worker)
|
|
438
|
+
this.stop(error);
|
|
439
|
+
});
|
|
330
440
|
} catch (error) {
|
|
331
441
|
this.stop(error instanceof Error ? error : new Error(String(error)));
|
|
332
442
|
}
|
|
@@ -340,10 +450,20 @@ class EmbeddingWorkerClient {
|
|
|
340
450
|
request.reject(error);
|
|
341
451
|
}
|
|
342
452
|
this.pending.clear();
|
|
343
|
-
|
|
453
|
+
if (worker instanceof Worker) {
|
|
454
|
+
await worker.terminate();
|
|
455
|
+
} else if (worker && worker.exitCode === null && worker.signalCode === null) {
|
|
456
|
+
worker.ref();
|
|
457
|
+
worker.channel?.ref?.();
|
|
458
|
+
await new Promise((resolve) => {
|
|
459
|
+
worker.once("exit", () => resolve());
|
|
460
|
+
worker.kill();
|
|
461
|
+
});
|
|
462
|
+
}
|
|
344
463
|
}
|
|
345
464
|
async dispose() {
|
|
346
465
|
this.disposed = true;
|
|
466
|
+
await this.startPromise?.catch(() => {});
|
|
347
467
|
await this.stop(new Error("embedding worker disposed"));
|
|
348
468
|
}
|
|
349
469
|
}
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
} from "./server-hb6xhh9q.js";
|
|
14
14
|
import {
|
|
15
15
|
messageFtsOrdinalRangeIsMapped
|
|
16
|
-
} from "./server-
|
|
16
|
+
} from "./server-2htmbqbv.js";
|
|
17
17
|
|
|
18
18
|
// src/features/magic-context/compartment-chunk-embedding.ts
|
|
19
19
|
import { createHash } from "node:crypto";
|
|
@@ -2,25 +2,21 @@ import {
|
|
|
2
2
|
getHarness2
|
|
3
3
|
} from "./server-pavzsdc6.js";
|
|
4
4
|
import {
|
|
5
|
-
getDataDir,
|
|
6
5
|
getMagicContextStorageDir,
|
|
7
6
|
sessionLog2
|
|
8
7
|
} from "./server-t4k4qexw.js";
|
|
9
8
|
import {
|
|
10
9
|
writeStorageFileAtomicSync
|
|
11
|
-
} from "./server-
|
|
10
|
+
} from "./server-fvnzcnww.js";
|
|
12
11
|
import {
|
|
13
12
|
modelRefLookupOrder
|
|
14
13
|
} from "./server-avwt563y.js";
|
|
15
14
|
|
|
16
15
|
// src/shared/models-dev-cache.ts
|
|
17
|
-
import { readFileSync as readFileSync2 } from "node:fs";
|
|
18
|
-
import { join as join2 } from "node:path";
|
|
19
|
-
|
|
20
|
-
// src/shared/window-geometry.ts
|
|
21
16
|
import { readFileSync } from "node:fs";
|
|
22
17
|
import { join } from "node:path";
|
|
23
|
-
|
|
18
|
+
|
|
19
|
+
// src/shared/window-geometry.ts
|
|
24
20
|
var PROMPT_WALL_MARGIN = 4096;
|
|
25
21
|
var PI_OUTPUT_FLOOR = 4096;
|
|
26
22
|
var OPENCODE_OUTPUT_CAP = 32000;
|
|
@@ -35,241 +31,10 @@ var PROVIDER_GEOMETRY = {
|
|
|
35
31
|
google: "separate",
|
|
36
32
|
"google-antigravity": "separate"
|
|
37
33
|
};
|
|
38
|
-
var GRADES = new Set([
|
|
39
|
-
"provider_asserted_runtime",
|
|
40
|
-
"measured",
|
|
41
|
-
"provider_asserted_doc",
|
|
42
|
-
"catalog",
|
|
43
|
-
"unknown"
|
|
44
|
-
]);
|
|
45
|
-
var UNITS = new Set(["provider", "estimate"]);
|
|
46
|
-
var BOUNDARIES = new Set(["Observed", "Asserted", "Corrected"]);
|
|
47
|
-
var UNKNOWN_REASONS = new Set([
|
|
48
|
-
"placeholder_output_equals_context",
|
|
49
|
-
"placeholder_zero",
|
|
50
|
-
"never_measured",
|
|
51
|
-
"not_single_valued_at_key",
|
|
52
|
-
"retracted"
|
|
53
|
-
]);
|
|
54
|
-
var NUMERIC_FACT_KEYS = new Set([
|
|
55
|
-
"window.advertised",
|
|
56
|
-
"window.enforced",
|
|
57
|
-
"output.advertised",
|
|
58
|
-
"output.enforced",
|
|
59
|
-
"output.default"
|
|
60
|
-
]);
|
|
61
|
-
var configuredOverlayPath;
|
|
62
|
-
var loadedOverlayPath;
|
|
63
|
-
var loadedOverlay;
|
|
64
34
|
var geometryClampLogSeen = new Set;
|
|
65
|
-
function isRecord(value) {
|
|
66
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
67
|
-
}
|
|
68
35
|
function isFinitePositive(value) {
|
|
69
36
|
return typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
70
37
|
}
|
|
71
|
-
function scalarizeFact(value) {
|
|
72
|
-
if (value.kind === "stated")
|
|
73
|
-
return isFinitePositive(value.value) ? value.value : undefined;
|
|
74
|
-
if (value.kind === "bracket") {
|
|
75
|
-
return isFinitePositive(value.at_least) ? value.at_least : undefined;
|
|
76
|
-
}
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
function parseFactValue(value) {
|
|
80
|
-
if (!isRecord(value) || typeof value.kind !== "string")
|
|
81
|
-
return;
|
|
82
|
-
if (value.kind === "stated") {
|
|
83
|
-
if ((typeof value.value !== "number" || !Number.isFinite(value.value)) && typeof value.value !== "string") {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
return { kind: "stated", value: value.value };
|
|
87
|
-
}
|
|
88
|
-
if (value.kind === "bracket") {
|
|
89
|
-
const atLeast = value.at_least;
|
|
90
|
-
const below = value.below;
|
|
91
|
-
if (atLeast === undefined && below === undefined)
|
|
92
|
-
return { kind: "bracket" };
|
|
93
|
-
if (atLeast !== undefined && !isFinitePositive(atLeast))
|
|
94
|
-
return;
|
|
95
|
-
if (below !== undefined && !isFinitePositive(below))
|
|
96
|
-
return;
|
|
97
|
-
if (isFinitePositive(atLeast) && isFinitePositive(below) && below <= atLeast) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
return {
|
|
101
|
-
kind: "bracket",
|
|
102
|
-
...isFinitePositive(atLeast) ? { at_least: atLeast } : {},
|
|
103
|
-
...isFinitePositive(below) ? { below } : {}
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
if (value.kind === "unknown" && UNKNOWN_REASONS.has(value.why)) {
|
|
107
|
-
return { kind: "unknown", why: value.why };
|
|
108
|
-
}
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
function parseFact(key, value) {
|
|
112
|
-
if (!isRecord(value))
|
|
113
|
-
return;
|
|
114
|
-
const parsedValue = parseFactValue(value.value);
|
|
115
|
-
if (!parsedValue || !GRADES.has(value.grade) || !UNITS.has(value.units) || !BOUNDARIES.has(value.boundary) || typeof value.source_ref !== "string" || value.source_ref.length === 0 || typeof value.observed_at !== "string" || value.observed_at.length === 0) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
if (NUMERIC_FACT_KEYS.has(key) && parsedValue.kind === "stated" && !isFinitePositive(parsedValue.value)) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
if (key === "geometry" && parsedValue.kind === "stated" && !["shared_upfront", "shared_truncating", "separate"].includes(String(parsedValue.value))) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
return {
|
|
125
|
-
...value,
|
|
126
|
-
value: parsedValue,
|
|
127
|
-
grade: value.grade,
|
|
128
|
-
units: value.units,
|
|
129
|
-
boundary: value.boundary,
|
|
130
|
-
source_ref: value.source_ref,
|
|
131
|
-
observed_at: value.observed_at
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
function parseWindowOverlay(value) {
|
|
135
|
-
if (!isRecord(value)) {
|
|
136
|
-
return { badCells: 0, refusal: "overlay root is not an object" };
|
|
137
|
-
}
|
|
138
|
-
if (value.schema !== WINDOW_OVERLAY_SCHEMA) {
|
|
139
|
-
return {
|
|
140
|
-
badCells: 0,
|
|
141
|
-
refusal: `unrecognized schema ${JSON.stringify(value.schema)}`
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
if (typeof value.generated_at !== "string" || !Array.isArray(value.minted_provider_ids) || !value.minted_provider_ids.every((id) => typeof id === "string" && id.length > 0) || !Array.isArray(value.cells)) {
|
|
145
|
-
return { badCells: 0, refusal: "invalid v1 envelope" };
|
|
146
|
-
}
|
|
147
|
-
const cells = [];
|
|
148
|
-
let badCells = 0;
|
|
149
|
-
for (const rawCell of value.cells) {
|
|
150
|
-
if (!isRecord(rawCell) || typeof rawCell.provider_id !== "string" || rawCell.provider_id.length === 0 || typeof rawCell.model_id !== "string" || rawCell.model_id.length === 0 || !isRecord(rawCell.facts)) {
|
|
151
|
-
badCells++;
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
const facts = {};
|
|
155
|
-
let valid = true;
|
|
156
|
-
for (const [key, rawFact] of Object.entries(rawCell.facts)) {
|
|
157
|
-
const fact = parseFact(key, rawFact);
|
|
158
|
-
if (!fact) {
|
|
159
|
-
valid = false;
|
|
160
|
-
break;
|
|
161
|
-
}
|
|
162
|
-
facts[key] = fact;
|
|
163
|
-
}
|
|
164
|
-
if (!valid) {
|
|
165
|
-
badCells++;
|
|
166
|
-
continue;
|
|
167
|
-
}
|
|
168
|
-
cells.push({
|
|
169
|
-
provider_id: rawCell.provider_id,
|
|
170
|
-
model_id: rawCell.model_id,
|
|
171
|
-
facts
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
return {
|
|
175
|
-
overlay: {
|
|
176
|
-
schema: WINDOW_OVERLAY_SCHEMA,
|
|
177
|
-
generated_at: value.generated_at,
|
|
178
|
-
minted_provider_ids: [...value.minted_provider_ids],
|
|
179
|
-
cells
|
|
180
|
-
},
|
|
181
|
-
badCells
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
function defaultWindowOverlayPath() {
|
|
185
|
-
return join(getDataDir(), "fusiform", "window-overlay.json");
|
|
186
|
-
}
|
|
187
|
-
function readWindowOverlayFile(path, log = (message) => sessionLog2("global", message)) {
|
|
188
|
-
let raw;
|
|
189
|
-
try {
|
|
190
|
-
raw = readFileSync(path, "utf8");
|
|
191
|
-
} catch (error) {
|
|
192
|
-
if (error.code === "ENOENT")
|
|
193
|
-
return;
|
|
194
|
-
log(`window-overlay: unable to read ${path}; overlay ignored`);
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
let decoded;
|
|
198
|
-
try {
|
|
199
|
-
decoded = JSON.parse(raw);
|
|
200
|
-
} catch {
|
|
201
|
-
log(`window-overlay: invalid JSON in ${path}; overlay ignored`);
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
const parsed = parseWindowOverlay(decoded);
|
|
205
|
-
if (parsed.refusal) {
|
|
206
|
-
log(`window-overlay: ${parsed.refusal} in ${path}; entire overlay ignored`);
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
if (parsed.badCells > 0) {
|
|
210
|
-
log(`window-overlay: skipped ${parsed.badCells} invalid cell(s) from ${path}`);
|
|
211
|
-
}
|
|
212
|
-
return parsed.overlay;
|
|
213
|
-
}
|
|
214
|
-
function setWindowOverlayPath(path) {
|
|
215
|
-
if (configuredOverlayPath === path)
|
|
216
|
-
return;
|
|
217
|
-
reloadWindowOverlay(path);
|
|
218
|
-
}
|
|
219
|
-
function reloadWindowOverlay(path) {
|
|
220
|
-
configuredOverlayPath = path;
|
|
221
|
-
loadedOverlayPath = undefined;
|
|
222
|
-
loadedOverlay = undefined;
|
|
223
|
-
}
|
|
224
|
-
function getWindowOverlay() {
|
|
225
|
-
const path = configuredOverlayPath ?? defaultWindowOverlayPath();
|
|
226
|
-
if (loadedOverlayPath === path && loadedOverlay !== undefined) {
|
|
227
|
-
return loadedOverlay ?? undefined;
|
|
228
|
-
}
|
|
229
|
-
loadedOverlayPath = path;
|
|
230
|
-
loadedOverlay = readWindowOverlayFile(path) ?? null;
|
|
231
|
-
return loadedOverlay ?? undefined;
|
|
232
|
-
}
|
|
233
|
-
function resolveWindowOverlayFacts(providerID, modelID, overlay = getWindowOverlay()) {
|
|
234
|
-
if (!overlay)
|
|
235
|
-
return;
|
|
236
|
-
const modelRefs = modelRefLookupOrder(`${providerID}/${modelID}`);
|
|
237
|
-
const providerCandidates = new Set(modelRefs.map((ref) => ref.slice(0, ref.indexOf("/"))));
|
|
238
|
-
const modelCandidates = new Set([
|
|
239
|
-
modelID,
|
|
240
|
-
...modelRefs.map((ref) => ref.slice(ref.indexOf("/") + 1))
|
|
241
|
-
]);
|
|
242
|
-
const colon = modelID.lastIndexOf(":");
|
|
243
|
-
if (colon > 0)
|
|
244
|
-
modelCandidates.add(modelID.slice(0, colon));
|
|
245
|
-
const wildcardFacts = {};
|
|
246
|
-
const specificFacts = {};
|
|
247
|
-
for (const cell of overlay.cells) {
|
|
248
|
-
if (!providerCandidates.has(cell.provider_id))
|
|
249
|
-
continue;
|
|
250
|
-
if (cell.model_id === "*")
|
|
251
|
-
Object.assign(wildcardFacts, cell.facts);
|
|
252
|
-
else if (modelCandidates.has(cell.model_id))
|
|
253
|
-
Object.assign(specificFacts, cell.facts);
|
|
254
|
-
}
|
|
255
|
-
const facts = { ...wildcardFacts, ...specificFacts };
|
|
256
|
-
return Object.keys(facts).length > 0 ? { facts } : undefined;
|
|
257
|
-
}
|
|
258
|
-
function numericOverlayFact(overlay, key) {
|
|
259
|
-
const fact = overlay?.facts[key];
|
|
260
|
-
return fact ? scalarizeFact(fact.value) : undefined;
|
|
261
|
-
}
|
|
262
|
-
function overlayGeometry(overlay) {
|
|
263
|
-
const fact = overlay?.facts.geometry;
|
|
264
|
-
if (fact === undefined)
|
|
265
|
-
return;
|
|
266
|
-
if (fact.value.kind === "unknown")
|
|
267
|
-
return { kind: "unknown" };
|
|
268
|
-
if (fact.value.kind !== "stated")
|
|
269
|
-
return;
|
|
270
|
-
const value = fact.value.value;
|
|
271
|
-
return value === "shared_upfront" || value === "shared_truncating" || value === "separate" ? { kind: "stated", value } : undefined;
|
|
272
|
-
}
|
|
273
38
|
function placeholderFilteredOutput(output, context) {
|
|
274
39
|
if (!isFinitePositive(output))
|
|
275
40
|
return;
|
|
@@ -277,8 +42,8 @@ function placeholderFilteredOutput(output, context) {
|
|
|
277
42
|
return;
|
|
278
43
|
return output;
|
|
279
44
|
}
|
|
280
|
-
function mergePositive(
|
|
281
|
-
return isFinitePositive(providerValue) ? providerValue :
|
|
45
|
+
function mergePositive(catalogValue, providerValue) {
|
|
46
|
+
return isFinitePositive(providerValue) ? providerValue : catalogValue;
|
|
282
47
|
}
|
|
283
48
|
function logGeometryClampOnce(key, message, log) {
|
|
284
49
|
if (geometryClampLogSeen.has(key))
|
|
@@ -292,10 +57,8 @@ function deriveWindowGeometry(providerID, modelID, catalogLimit, options = {}) {
|
|
|
292
57
|
const providerLimit = options.providerLimit;
|
|
293
58
|
const catalogContext = isFinitePositive(catalogLimit?.context) ? catalogLimit.context : undefined;
|
|
294
59
|
const providerContext = isFinitePositive(providerLimit?.context) ? providerLimit.context : undefined;
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
let softContext = mergePositive(enforced ?? advertised ?? catalogContext, providerContext);
|
|
298
|
-
let hardContext = mergePositive(enforced ?? softContext, providerContext);
|
|
60
|
+
let softContext = mergePositive(catalogContext, providerContext);
|
|
61
|
+
let hardContext = mergePositive(softContext, providerContext);
|
|
299
62
|
const contextCap = isFinitePositive(options.contextCap) ? options.contextCap : undefined;
|
|
300
63
|
const hasContextCap = contextCap !== undefined;
|
|
301
64
|
if (contextCap !== undefined) {
|
|
@@ -305,13 +68,10 @@ function deriveWindowGeometry(providerID, modelID, catalogLimit, options = {}) {
|
|
|
305
68
|
const input = mergePositive(isFinitePositive(catalogLimit?.input) ? catalogLimit.input : undefined, providerLimit?.input);
|
|
306
69
|
if (!isFinitePositive(softContext) && !isFinitePositive(input))
|
|
307
70
|
return;
|
|
308
|
-
const catalogOutput = options.
|
|
309
|
-
const overlayOutput = placeholderFilteredOutput(numericOverlayFact(options.overlay, "output.enforced") ?? numericOverlayFact(options.overlay, "output.default") ?? numericOverlayFact(options.overlay, "output.advertised"), softContext);
|
|
71
|
+
const catalogOutput = options.providerLimit === undefined ? isFinitePositive(catalogLimit?.output) ? catalogLimit.output : undefined : placeholderFilteredOutput(catalogLimit?.output, softContext);
|
|
310
72
|
const providerOutput = placeholderFilteredOutput(providerLimit?.output, softContext);
|
|
311
|
-
const output = providerOutput ??
|
|
312
|
-
const
|
|
313
|
-
const geometry = geometryFact?.kind === "stated" ? geometryFact.value : geometryFact?.kind === "unknown" ? "shared_upfront" : PROVIDER_GEOMETRY[providerID] ?? "shared_upfront";
|
|
314
|
-
const geometryOverride = geometryFact?.kind === "stated" ? geometryFact.value : undefined;
|
|
73
|
+
const output = providerOutput ?? catalogOutput;
|
|
74
|
+
const geometry = PROVIDER_GEOMETRY[providerID] ?? "shared_upfront";
|
|
315
75
|
const preCarvedInput = isFinitePositive(input) && (!isFinitePositive(softContext) || input < softContext);
|
|
316
76
|
const outputReserveOverride = typeof options.outputReserveOverride === "number" && Number.isFinite(options.outputReserveOverride) && options.outputReserveOverride >= 0 ? options.outputReserveOverride : undefined;
|
|
317
77
|
let derivationWindow = softContext ?? input;
|
|
@@ -339,14 +99,14 @@ function deriveWindowGeometry(providerID, modelID, catalogLimit, options = {}) {
|
|
|
339
99
|
reserveSource = "output_catalog";
|
|
340
100
|
}
|
|
341
101
|
} else if (isFinitePositive(softContext)) {
|
|
342
|
-
if (geometry === "separate"
|
|
102
|
+
if (geometry === "separate") {
|
|
343
103
|
softReserve = 0;
|
|
344
104
|
reserveSource = "none";
|
|
345
105
|
} else {
|
|
346
106
|
softReserve = output ?? 0;
|
|
347
107
|
reserveSource = output === undefined ? "none" : "output_catalog";
|
|
348
108
|
const cap = softContext * OUTPUT_RESERVE_CAP_RATIO;
|
|
349
|
-
softReserve = Math.min(softReserve,
|
|
109
|
+
softReserve = Math.min(softReserve, cap);
|
|
350
110
|
}
|
|
351
111
|
const floor = Math.max(MIN_PLAUSIBLE_CONTEXT_LIMIT, softContext * 0.5);
|
|
352
112
|
const flooredReserve = Math.min(softReserve, Math.max(0, softContext - floor));
|
|
@@ -361,7 +121,7 @@ function deriveWindowGeometry(providerID, modelID, catalogLimit, options = {}) {
|
|
|
361
121
|
const hardWindow = hardContext ?? softContext ?? input;
|
|
362
122
|
if (!isFinitePositive(hardWindow))
|
|
363
123
|
return;
|
|
364
|
-
const windowSource = hasContextCap ? "detected" : providerContext !== undefined ? "provider" :
|
|
124
|
+
const windowSource = hasContextCap ? "detected" : providerContext !== undefined ? "provider" : "catalog";
|
|
365
125
|
let usableHard;
|
|
366
126
|
if (geometry === "separate") {
|
|
367
127
|
usableHard = hardWindow;
|
|
@@ -377,7 +137,7 @@ function deriveWindowGeometry(providerID, modelID, catalogLimit, options = {}) {
|
|
|
377
137
|
}
|
|
378
138
|
usableHard = Math.max(MIN_PLAUSIBLE_CONTEXT_LIMIT, Math.floor(usableHard));
|
|
379
139
|
if (usableHard < usableSoft) {
|
|
380
|
-
logGeometryClampOnce(`${providerID}/${modelID}|${usableSoft}|${usableHard}`, `usable hard limit clamped for ${providerID}/${modelID}: ${usableHard} → ${usableSoft} (
|
|
140
|
+
logGeometryClampOnce(`${providerID}/${modelID}|${usableSoft}|${usableHard}`, `usable hard limit clamped for ${providerID}/${modelID}: ${usableHard} → ${usableSoft} (window limit inversion)`, options.log);
|
|
381
141
|
usableHard = usableSoft;
|
|
382
142
|
}
|
|
383
143
|
const resolvedWindow = derivationWindow ?? usableSoft;
|
|
@@ -444,14 +204,14 @@ var apiCache = null;
|
|
|
444
204
|
var apiLoadedAt = 0;
|
|
445
205
|
var persistSeedLoaded = false;
|
|
446
206
|
function persistFilePath() {
|
|
447
|
-
return
|
|
207
|
+
return join(getMagicContextStorageDir(), `model-context-limits-${getHarness2()}.json`);
|
|
448
208
|
}
|
|
449
209
|
function loadPersistedApiCacheOnce() {
|
|
450
210
|
if (persistSeedLoaded || apiCache !== null)
|
|
451
211
|
return;
|
|
452
212
|
persistSeedLoaded = true;
|
|
453
213
|
try {
|
|
454
|
-
const raw =
|
|
214
|
+
const raw = readFileSync(persistFilePath(), "utf-8");
|
|
455
215
|
const obj = JSON.parse(raw);
|
|
456
216
|
const map = new Map;
|
|
457
217
|
for (const [key, persisted] of Object.entries(obj)) {
|
|
@@ -641,7 +401,6 @@ function getSdkWindowGeometry(providerID, modelID, detectedContextLimit, options
|
|
|
641
401
|
input: metadata.inputLimit,
|
|
642
402
|
output: metadata.outputLimit
|
|
643
403
|
}, {
|
|
644
|
-
overlay: resolveWindowOverlayFacts(providerID, modelID, getWindowOverlay()),
|
|
645
404
|
outputReserveOverride: resolveOutputReserve(providerID, modelID),
|
|
646
405
|
harness: options?.harness ?? "opencode",
|
|
647
406
|
contextCap: promptOnlyDetected === undefined && isFinitePositive2(detectedContextLimit) ? detectedContextLimit : undefined
|
|
@@ -725,4 +484,4 @@ function getModelsDevCacheState() {
|
|
|
725
484
|
};
|
|
726
485
|
}
|
|
727
486
|
|
|
728
|
-
export { catalogOutputReserve,
|
|
487
|
+
export { catalogOutputReserve, hasTrustedAbsoluteWall, applyProvenInputFloor, isSaneLimit, setOutputReserveConfig, resolveLimit, refreshModelLimitsFromApi, getSdkWindowGeometry, getSdkContextLimit, modelSupportsVision, getSdkOutputLimit, getSdkInputLimit, getModelsDevCacheState };
|
|
@@ -14,10 +14,10 @@ import {
|
|
|
14
14
|
} from "./server-t4k4qexw.js";
|
|
15
15
|
import {
|
|
16
16
|
managedAuthorityNoteRow
|
|
17
|
-
} from "./server-
|
|
17
|
+
} from "./server-6tcrjfw8.js";
|
|
18
18
|
import {
|
|
19
19
|
embedTextForProject2
|
|
20
|
-
} from "./server-
|
|
20
|
+
} from "./server-1fszbabv.js";
|
|
21
21
|
import {
|
|
22
22
|
saveEmbeddingIfHashMatches
|
|
23
23
|
} from "./server-4dhv7mqz.js";
|
package/dist/v2/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/v2/server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/v2/server.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAK/C;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,SAAS,CAQ7E;AAED,wBAAsB,KAAK,CAAC,OAAO,EAAE,SAAS,gCA8B7C;;;;;AAED,wBAGE"}
|