@cortexkit/opencode-magic-context 0.49.79 → 0.49.80
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/auto-search-worker.js +2 -2
- package/dist/{context-gb3gjahp.js → context-7rkrv5q8.js} +155 -61
- package/dist/{derive-budgets-def8genf.js → derive-budgets-2z6xxm7e.js} +1 -1
- package/dist/{embedding-backfill-rrmzvg7n.js → embedding-backfill-0tvprmrn.js} +1 -1
- package/dist/features/magic-context/memory/embedding-backfill.d.ts +4 -0
- package/dist/features/magic-context/memory/embedding-backfill.d.ts.map +1 -1
- package/dist/features/magic-context/search.d.ts.map +1 -1
- package/dist/{index-16h5fhem.js → index-177yv84k.js} +4 -6
- package/dist/{index-jfs6k0xk.js → index-9554nr2q.js} +6 -6
- package/dist/{index-sy5wbbw6.js → index-exvsw656.js} +2 -2
- package/dist/{index-tvkzkk4s.js → index-ezgeq2z7.js} +2 -2
- package/dist/{index-f619wjj9.js → index-hpmx99e9.js} +2 -2
- package/dist/{index-hgdkwp21.js → index-jhhkb4jv.js} +1 -1
- package/dist/{index-v8x07j6c.js → index-m4q6ptgz.js} +2 -2
- package/dist/{index-8ykmp4jv.js → index-mgvj4vkb.js} +2 -2
- package/dist/{index-ngwmx6nt.js → index-tky3j43e.js} +47 -5
- package/dist/{index-enpatj5k.js → index-v0epndb8.js} +7 -7
- package/dist/{index-2dadxknq.js → index-xjpemea9.js} +13 -17
- package/dist/{index-m0tbtzqh.js → index-zpd4pxnp.js} +10 -5
- package/dist/index.js +14 -14
- package/dist/raw-ordinal-warmup-worker.js +2 -2
- package/dist/{recomp-orchestrator-jf60eef6.js → recomp-orchestrator-n7h0a0tn.js} +5 -5
- package/dist/{search-archive-a60k0x2n.js → search-archive-p3jhx9wc.js} +2 -2
- package/dist/{search-mpde08f1.js → search-z56487n8.js} +3 -3
- package/dist/shared/models-dev-cache.d.ts +2 -0
- package/dist/shared/models-dev-cache.d.ts.map +1 -1
- package/dist/{store-j5rvve3v.js → store-8trkpmtx.js} +3 -1
- package/dist/{transform-postprocess-phase-m1be339w.js → transform-postprocess-phase-f0wssyce.js} +5 -5
- package/dist/v2/auto-search-worker.js +2 -2
- package/dist/v2/chunk-embedding-write-worker.js +2 -2
- package/dist/v2/{context-fzp6ynz4.js → context-r1swhysg.js} +156 -70
- package/dist/v2/{derive-budgets-z93fdnp7.js → derive-budgets-2eam671q.js} +2 -2
- package/dist/v2/{embedding-backfill-g9scycm5.js → embedding-backfill-qnaswpmb.js} +1 -1
- package/dist/v2/fold/native-replay.d.ts.map +1 -1
- package/dist/v2/fold/owner.d.ts +2 -4
- package/dist/v2/fold/owner.d.ts.map +1 -1
- package/dist/v2/fold/partial-boundary.d.ts +25 -0
- package/dist/v2/fold/partial-boundary.d.ts.map +1 -0
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/migration-worker.js +2 -2
- package/dist/v2/raw-ordinal-warmup-worker.js +2 -2
- package/dist/v2/{recomp-orchestrator-4r63zen2.js → recomp-orchestrator-4w2w4kd4.js} +8 -8
- package/dist/v2/{render-7tr9d67f.js → render-hwqk0d8t.js} +2 -2
- package/dist/v2/{search-archive-2ck9sbsc.js → search-archive-mdxzvgpm.js} +2 -2
- package/dist/v2/{search-y01mww69.js → search-eftsvbg7.js} +3 -3
- package/dist/v2/{server-kmaxv4g3.js → server-25qtxt4d.js} +6 -6
- package/dist/v2/{server-wc0bb04b.js → server-34pvhvxt.js} +8 -8
- package/dist/v2/{server-468mya5v.js → server-39bcszk4.js} +47 -1
- package/dist/v2/{server-r9xsgnez.js → server-76v5y7zm.js} +1 -1
- package/dist/v2/{server-9sf3qp02.js → server-bj779zmp.js} +1 -1
- package/dist/v2/{server-1svqwm7m.js → server-fqnty3nk.js} +6 -6
- package/dist/v2/{server-qpnjsg1v.js → server-ma9jwnas.js} +3 -3
- package/dist/v2/{server-2adwe0be.js → server-nqdzv8b7.js} +47 -5
- package/dist/v2/{server-tkznm2j9.js → server-pxdpwycq.js} +10 -5
- package/dist/v2/{server-aewxmvnf.js → server-rp52f40v.js} +1 -1
- package/dist/v2/{server-10af6m7d.js → server-x8ksqcw7.js} +4 -6
- package/dist/v2/{server-d7dbk2h6.js → server-zw1e3wq5.js} +1 -1
- package/dist/v2/server.js +4 -4
- package/dist/v2/{store-1fax2zhj.js → store-m3zny7q2.js} +4 -2
- package/dist/v2/{v2-archive-reader-jatkdt2s.js → v2-archive-reader-p89x05hj.js} +1 -1
- package/dist/v2/{wrapup-orchestrator-z91sebhb.js → wrapup-orchestrator-0f4nwpbv.js} +8 -8
- package/dist/{v2-archive-reader-sw01917z.js → v2-archive-reader-vzmzb245.js} +1 -1
- package/dist/{wrapup-orchestrator-1k48hzxg.js → wrapup-orchestrator-5k9hgb3t.js} +6 -6
- package/package.json +1 -1
- package/src/shared/models-dev-cache.test.ts +67 -1
- package/src/shared/models-dev-cache.ts +71 -4
|
@@ -22,7 +22,8 @@ async function ensureMemoryEmbeddings2(args) {
|
|
|
22
22
|
if (isEmbeddingHostBusy2())
|
|
23
23
|
return args.existingEmbeddings;
|
|
24
24
|
const snapshot = getProjectEmbeddingSnapshot2(args.projectIdentity);
|
|
25
|
-
|
|
25
|
+
const expected = args.expectedEmbedding;
|
|
26
|
+
if (!snapshot?.enabled || expected && (snapshot.modelId !== expected.modelId || expected.generation !== undefined && snapshot.generation !== expected.generation)) {
|
|
26
27
|
return args.existingEmbeddings;
|
|
27
28
|
}
|
|
28
29
|
const missing = args.memories.filter((memory) => !args.existingEmbeddings.has(memory.id)).sort((a, b) => a.id - b.id);
|
|
@@ -40,7 +41,8 @@ async function ensureMemoryEmbeddings2(args) {
|
|
|
40
41
|
text: memory.content,
|
|
41
42
|
contentSha256: contentSha2562(memory.content)
|
|
42
43
|
})), undefined, args.db, args.projectIdentity, { maxItemsPerCall: SEARCH_BACKFILL_REQUEST_SIZE });
|
|
43
|
-
|
|
44
|
+
const currentSnapshot = getProjectEmbeddingSnapshot2(args.projectIdentity);
|
|
45
|
+
if (!result || result.modelId !== snapshot.modelId || result.generation !== snapshot.generation || currentSnapshot?.generation !== snapshot.generation) {
|
|
44
46
|
return args.existingEmbeddings;
|
|
45
47
|
}
|
|
46
48
|
const staged = new Map;
|
|
@@ -56,10 +58,6 @@ async function ensureMemoryEmbeddings2(args) {
|
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
60
|
}).immediate();
|
|
59
|
-
const currentSnapshot = getProjectEmbeddingSnapshot2(args.projectIdentity);
|
|
60
|
-
if (!currentSnapshot || currentSnapshot.generation !== result.generation) {
|
|
61
|
-
return args.existingEmbeddings;
|
|
62
|
-
}
|
|
63
61
|
if (capped && (cursor !== undefined || result.vectors.size < missingMemories.length)) {
|
|
64
62
|
const nextCursor = start + missingMemories.length < missing.length ? missingMemories.at(-1)?.id : undefined;
|
|
65
63
|
writeSearchBackfillCursor2(args.projectIdentity, snapshot.generation, cursor, nextCursor);
|
package/dist/v2/server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
loadPluginConfigDetailed
|
|
3
|
-
} from "./server-
|
|
3
|
+
} from "./server-bj779zmp.js";
|
|
4
4
|
import {
|
|
5
5
|
setHarness2
|
|
6
6
|
} from "./server-pavzsdc6.js";
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
flushLogger2
|
|
14
14
|
} from "./server-j8376q08.js";
|
|
15
15
|
import"./server-z4p0ry94.js";
|
|
16
|
-
import"./server-
|
|
16
|
+
import"./server-nqdzv8b7.js";
|
|
17
17
|
import {
|
|
18
18
|
string,
|
|
19
19
|
unknown,
|
|
@@ -7875,7 +7875,7 @@ var require_src2 = __commonJS(function(exports, module) {
|
|
|
7875
7875
|
// package.json
|
|
7876
7876
|
var package_default = {
|
|
7877
7877
|
name: "@cortexkit/opencode-magic-context",
|
|
7878
|
-
version: "0.49.
|
|
7878
|
+
version: "0.49.80",
|
|
7879
7879
|
type: "module",
|
|
7880
7880
|
description: "OpenCode plugin for Magic Context — cross-session memory and context management",
|
|
7881
7881
|
main: "dist/index.js",
|
|
@@ -8196,7 +8196,7 @@ async function setup(context) {
|
|
|
8196
8196
|
if (claimStorageBackupWarningCheck() && isMagicContextStorageOutsideEngram(storageDir)) {
|
|
8197
8197
|
log2(`[magic-context] Magic Context storage is at ${storageDir}, outside the folder Engram backs up (~/.local/share/cortexkit/magic-context). It is not included in CortexKit backups.`);
|
|
8198
8198
|
}
|
|
8199
|
-
const { registerContext } = await import("./context-
|
|
8199
|
+
const { registerContext } = await import("./context-r1swhysg.js");
|
|
8200
8200
|
setHarness2("opencode2");
|
|
8201
8201
|
bindStaleBuildNotice({}, import.meta.url, "opencode2");
|
|
8202
8202
|
const duties = await registerContext(context);
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
|
+
rawMessagePage2,
|
|
2
3
|
servedBoundaryRow2,
|
|
3
4
|
resolveV2BoundaryUserMessage2,
|
|
4
5
|
readAllV2RawMessagesForConversion2,
|
|
5
6
|
readV2RawMessagePagesForConversion2,
|
|
6
7
|
createV2RawMessageReader2,
|
|
7
8
|
createV2RawMessageProvider2
|
|
8
|
-
} from "./server-
|
|
9
|
+
} from "./server-34pvhvxt.js";
|
|
9
10
|
import"./server-rthnpmbp.js";
|
|
10
|
-
import"./server-
|
|
11
|
+
import"./server-39bcszk4.js";
|
|
11
12
|
import"./server-2ra6pwf3.js";
|
|
12
13
|
import"./server-gzy5w8ya.js";
|
|
13
14
|
import"./server-z4p0ry94.js";
|
|
14
15
|
export {
|
|
15
16
|
createV2RawMessageProvider2 as createV2RawMessageProvider,
|
|
16
17
|
createV2RawMessageReader2 as createV2RawMessageReader,
|
|
18
|
+
rawMessagePage2 as rawMessagePage,
|
|
17
19
|
readAllV2RawMessagesForConversion2 as readAllV2RawMessagesForConversion,
|
|
18
20
|
readV2RawMessagePagesForConversion2 as readV2RawMessagePagesForConversion,
|
|
19
21
|
resolveV2BoundaryUserMessage2 as resolveV2BoundaryUserMessage,
|
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
clearEmergencyRecovery
|
|
36
36
|
} from "./server-xdh4r20h.js";
|
|
37
37
|
import"./server-xepx8t43.js";
|
|
38
|
-
import"./server-
|
|
38
|
+
import"./server-76v5y7zm.js";
|
|
39
39
|
import"./server-1zx87sdm.js";
|
|
40
40
|
import"./server-rz6g5xne.js";
|
|
41
41
|
import"./server-2ra6pwf3.js";
|
|
@@ -48,7 +48,7 @@ import"./server-jn4pktdk.js";
|
|
|
48
48
|
import"./server-afsz3cmx.js";
|
|
49
49
|
import"./server-rthnpmbp.js";
|
|
50
50
|
import"./server-fb3zxn06.js";
|
|
51
|
-
import"./server-
|
|
51
|
+
import"./server-39bcszk4.js";
|
|
52
52
|
import"./server-rbtx6q5v.js";
|
|
53
53
|
import {
|
|
54
54
|
pushNotification2
|
|
@@ -64,18 +64,18 @@ import {
|
|
|
64
64
|
registerActiveCompartmentRun,
|
|
65
65
|
setRecompStarting2,
|
|
66
66
|
setRecompTerminal2
|
|
67
|
-
} from "./server-
|
|
67
|
+
} from "./server-fqnty3nk.js";
|
|
68
68
|
import"./server-qt1qqasc.js";
|
|
69
69
|
import"./server-mhrgymcs.js";
|
|
70
70
|
import"./server-jtq03rkb.js";
|
|
71
71
|
import"./server-4dhv7mqz.js";
|
|
72
72
|
import"./server-d706s5xn.js";
|
|
73
|
-
import"./server-
|
|
74
|
-
import"./server-
|
|
73
|
+
import"./server-25qtxt4d.js";
|
|
74
|
+
import"./server-x8ksqcw7.js";
|
|
75
75
|
import"./server-jjvbk92s.js";
|
|
76
|
-
import"./server-
|
|
77
|
-
import"./server-
|
|
78
|
-
import"./server-
|
|
76
|
+
import"./server-bj779zmp.js";
|
|
77
|
+
import"./server-nqdzv8b7.js";
|
|
78
|
+
import"./server-rp52f40v.js";
|
|
79
79
|
import"./server-npdey91q.js";
|
|
80
80
|
import {
|
|
81
81
|
sendStatusNotification2
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
runManagedWrapup2
|
|
3
|
-
} from "./index-
|
|
4
|
-
import"./index-
|
|
5
|
-
import"./index-
|
|
3
|
+
} from "./index-ezgeq2z7.js";
|
|
4
|
+
import"./index-hpmx99e9.js";
|
|
5
|
+
import"./index-exvsw656.js";
|
|
6
6
|
import"./index-832w615x.js";
|
|
7
7
|
import"./index-sd3egckz.js";
|
|
8
|
-
import"./index-
|
|
9
|
-
import"./index-
|
|
8
|
+
import"./index-9554nr2q.js";
|
|
9
|
+
import"./index-177yv84k.js";
|
|
10
10
|
import"./index-jjvbk92s.js";
|
|
11
11
|
import"./index-yfn52pb6.js";
|
|
12
12
|
import"./index-4dhv7mqz.js";
|
|
@@ -15,7 +15,7 @@ import"./index-tebcx987.js";
|
|
|
15
15
|
import"./index-zzvd4a9z.js";
|
|
16
16
|
import"./index-2amn2s73.js";
|
|
17
17
|
import"./index-6athgjba.js";
|
|
18
|
-
import"./index-
|
|
18
|
+
import"./index-tky3j43e.js";
|
|
19
19
|
import"./index-1sq1krqw.js";
|
|
20
20
|
import"./index-qt1qqasc.js";
|
|
21
21
|
import"./index-2q0t43fy.js";
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, spyOn, test } from "bun:test";
|
|
2
2
|
import { rmSync } from "node:fs";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
historianProducerReserve,
|
|
11
11
|
producerInputTokenLimit,
|
|
12
12
|
} from "../hooks/magic-context/producer-window-guard";
|
|
13
|
+
import * as harnessState from "./harness";
|
|
13
14
|
import {
|
|
14
15
|
clearModelsDevCache,
|
|
15
16
|
getModelsDevCacheState,
|
|
@@ -21,6 +22,7 @@ import {
|
|
|
21
22
|
resetAuthRewarmLatchForTest,
|
|
22
23
|
resolveLimit,
|
|
23
24
|
setOutputReserveConfig,
|
|
25
|
+
useV2DraftModelLimits,
|
|
24
26
|
} from "./models-dev-cache";
|
|
25
27
|
import { createTestTempDirFromPath } from "./test-temp-dir";
|
|
26
28
|
|
|
@@ -169,6 +171,70 @@ describe("models-dev-cache (SDK-only)", () => {
|
|
|
169
171
|
clearModelsDevCache();
|
|
170
172
|
});
|
|
171
173
|
|
|
174
|
+
test("a draft fills only its own OpenCode 2 window until the next full catalog refresh", async () => {
|
|
175
|
+
const host = spyOn(harnessState, "getHarness").mockReturnValue("opencode2");
|
|
176
|
+
try {
|
|
177
|
+
await refreshModelLimitsFromApi(
|
|
178
|
+
makeClient([
|
|
179
|
+
{
|
|
180
|
+
id: "custom",
|
|
181
|
+
models: {
|
|
182
|
+
complete: { limit: { context: 80_000, input: 40_000, output: 8000 } },
|
|
183
|
+
partial: { limit: { context: 80_000 } },
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
]),
|
|
187
|
+
);
|
|
188
|
+
const window = (model: string) => getSdkContextLimit("custom", model);
|
|
189
|
+
expect(
|
|
190
|
+
useV2DraftModelLimits("custom", "complete", { context: 90_000, input: 50_000 }),
|
|
191
|
+
).toBe(true);
|
|
192
|
+
expect(window("complete")).toBe(40_000);
|
|
193
|
+
expect(useV2DraftModelLimits("custom", "complete", { context: 30_000 })).toBe(false);
|
|
194
|
+
expect(window("complete")).toBe(40_000);
|
|
195
|
+
|
|
196
|
+
expect(
|
|
197
|
+
useV2DraftModelLimits("custom", "partial", { context: 80_000, input: 30_000 }),
|
|
198
|
+
).toBe(true);
|
|
199
|
+
expect(window("partial")).toBe(30_000);
|
|
200
|
+
expect(window("partial:tag")).toBe(80_000);
|
|
201
|
+
expect(window("complete")).toBe(40_000);
|
|
202
|
+
for (const harness of ["pi", "opencode"] as const) {
|
|
203
|
+
host.mockReturnValue(harness);
|
|
204
|
+
expect(window("partial")).toBe(80_000);
|
|
205
|
+
}
|
|
206
|
+
host.mockReturnValue("opencode2");
|
|
207
|
+
|
|
208
|
+
await refreshModelLimitsFromApi(
|
|
209
|
+
makeClient([{ id: "custom", models: { partial: { limit: { context: 90_000 } } } }]),
|
|
210
|
+
);
|
|
211
|
+
expect(window("partial")).toBe(90_000);
|
|
212
|
+
expect(window("complete")).toBeUndefined();
|
|
213
|
+
} finally {
|
|
214
|
+
host.mockRestore();
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test("a later failed lookup removes an overlay when the draft no longer fills any cached field", async () => {
|
|
219
|
+
const host = spyOn(harnessState, "getHarness").mockReturnValue("opencode2");
|
|
220
|
+
try {
|
|
221
|
+
await refreshModelLimitsFromApi(
|
|
222
|
+
makeClient([
|
|
223
|
+
{ id: "custom", models: { selected: { limit: { context: 80_000 } } } },
|
|
224
|
+
]),
|
|
225
|
+
);
|
|
226
|
+
expect(
|
|
227
|
+
useV2DraftModelLimits("custom", "selected", { context: 80_000, input: 30_000 }),
|
|
228
|
+
).toBe(true);
|
|
229
|
+
expect(getSdkContextLimit("custom", "selected")).toBe(30_000);
|
|
230
|
+
|
|
231
|
+
expect(useV2DraftModelLimits("custom", "selected", { context: 80_000 })).toBe(true);
|
|
232
|
+
expect(getSdkContextLimit("custom", "selected")).toBe(80_000);
|
|
233
|
+
} finally {
|
|
234
|
+
host.mockRestore();
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
|
|
172
238
|
test("honors the reporter's default output_reserve on the SDK geometry path", async () => {
|
|
173
239
|
await refreshModelLimitsFromApi(
|
|
174
240
|
makeClient([
|
|
@@ -105,6 +105,10 @@ const reserveClampLogSeen = new Set<string>();
|
|
|
105
105
|
*/
|
|
106
106
|
let apiCache: Map<string, CachedModelMetadata> | null = null;
|
|
107
107
|
let apiLoadedAt = 0;
|
|
108
|
+
// An OpenCode 2 draft is evidence for that exact model's window, not a new
|
|
109
|
+
// catalog snapshot or evidence about another model's capabilities.
|
|
110
|
+
const v2DraftModelLimits = new Map<string, CachedModelMetadata>();
|
|
111
|
+
const v2DraftModelLimitLogged = new Set<string>();
|
|
108
112
|
|
|
109
113
|
// Persisted last-known-good apiCache (OpenCode). Survives restart so a cold
|
|
110
114
|
// start uses the real limit instantly instead of falling to the disk file or the
|
|
@@ -443,6 +447,7 @@ async function refreshModelLimitsOnce(client: OpencodeClientLike): Promise<boole
|
|
|
443
447
|
|
|
444
448
|
const previousSize = apiCache?.size ?? null;
|
|
445
449
|
apiCache = map;
|
|
450
|
+
v2DraftModelLimits.clear();
|
|
446
451
|
apiLoadedAt = Date.now();
|
|
447
452
|
// Persist the freshly-resolved (sane-filtered) limits so the next process
|
|
448
453
|
// cold-starts with the real values instead of the 128k default.
|
|
@@ -470,6 +475,69 @@ async function refreshModelLimitsOnce(client: OpencodeClientLike): Promise<boole
|
|
|
470
475
|
}
|
|
471
476
|
}
|
|
472
477
|
|
|
478
|
+
/** Supply window metadata for the selected OpenCode 2 model during a catalog failure. */
|
|
479
|
+
export function useV2DraftModelLimits(
|
|
480
|
+
providerID: string,
|
|
481
|
+
modelID: string,
|
|
482
|
+
limit: ModelLimit | undefined,
|
|
483
|
+
): boolean {
|
|
484
|
+
loadPersistedApiCacheOnce();
|
|
485
|
+
const key = `${providerID}/${modelID}`;
|
|
486
|
+
const cached = lookupMetadataWithTagFallback(apiCache, providerID, modelID);
|
|
487
|
+
const valid = (value: number | undefined) =>
|
|
488
|
+
isFinitePositive(value) && value <= MAX_SANE_LIMIT ? value : undefined;
|
|
489
|
+
const draft = {
|
|
490
|
+
context: valid(limit?.context),
|
|
491
|
+
input: valid(limit?.input),
|
|
492
|
+
output: valid(limit?.output),
|
|
493
|
+
};
|
|
494
|
+
const geometry = (raw: ModelLimit) =>
|
|
495
|
+
deriveWindowGeometry(providerID, modelID, raw, {
|
|
496
|
+
outputReserveOverride: resolveOutputReserve(providerID, modelID),
|
|
497
|
+
harness: "opencode",
|
|
498
|
+
})?.usableSoft;
|
|
499
|
+
const draftWindow = geometry(draft);
|
|
500
|
+
const merged: ModelLimit = {
|
|
501
|
+
context: cached?.contextLimit ?? draft.context ?? cached?.limit,
|
|
502
|
+
input: cached?.inputLimit ?? draft.input,
|
|
503
|
+
output: cached?.outputLimit ?? draft.output,
|
|
504
|
+
};
|
|
505
|
+
const window = geometry(merged);
|
|
506
|
+
// Keep authoritative values, but do not admit a turn on a stale window
|
|
507
|
+
// that is wider than the current draft can support.
|
|
508
|
+
if (window === undefined || window <= 0 || (draftWindow !== undefined && window > draftWindow))
|
|
509
|
+
return false;
|
|
510
|
+
|
|
511
|
+
if (
|
|
512
|
+
merged.context !== (cached?.contextLimit ?? cached?.limit) ||
|
|
513
|
+
merged.input !== cached?.inputLimit ||
|
|
514
|
+
merged.output !== cached?.outputLimit
|
|
515
|
+
) {
|
|
516
|
+
v2DraftModelLimits.set(key, {
|
|
517
|
+
contextLimit: merged.context,
|
|
518
|
+
inputLimit: merged.input,
|
|
519
|
+
outputLimit: merged.output,
|
|
520
|
+
});
|
|
521
|
+
} else v2DraftModelLimits.delete(key);
|
|
522
|
+
if (!v2DraftModelLimitLogged.has(key)) {
|
|
523
|
+
v2DraftModelLimitLogged.add(key);
|
|
524
|
+
sessionLog(
|
|
525
|
+
"global",
|
|
526
|
+
`v2 model catalog lookup failed for ${key}; using selected model limits`,
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
return true;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
function windowMetadata(providerID: string, modelID: string): CachedModelMetadata | undefined {
|
|
533
|
+
loadPersistedApiCacheOnce();
|
|
534
|
+
return (
|
|
535
|
+
(getHarness() === "opencode2"
|
|
536
|
+
? v2DraftModelLimits.get(`${providerID}/${modelID}`)
|
|
537
|
+
: undefined) ?? lookupMetadataWithTagFallback(apiCache, providerID, modelID)
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
|
|
473
541
|
/**
|
|
474
542
|
* Resolve a model's prompt limit from OpenCode's SDK (`config.providers()`),
|
|
475
543
|
* the single source of truth: it already merges models.dev + compiled-in
|
|
@@ -499,8 +567,7 @@ export function getSdkWindowGeometry(
|
|
|
499
567
|
harness?: "opencode" | "pi";
|
|
500
568
|
},
|
|
501
569
|
): WindowGeometryResult | undefined {
|
|
502
|
-
|
|
503
|
-
const metadata = lookupMetadataWithTagFallback(apiCache, providerID, modelID);
|
|
570
|
+
const metadata = windowMetadata(providerID, modelID);
|
|
504
571
|
if (!metadata) return undefined;
|
|
505
572
|
const rawContext = metadata.contextLimit ?? metadata.limit;
|
|
506
573
|
const promptOnlyDetected =
|
|
@@ -551,8 +618,7 @@ export function getSdkContextLimit(
|
|
|
551
618
|
detectedLimitProvenance: options?.detectedLimitProvenance,
|
|
552
619
|
})?.usableSoft;
|
|
553
620
|
}
|
|
554
|
-
|
|
555
|
-
const metadata = lookupMetadataWithTagFallback(apiCache, providerID, modelID);
|
|
621
|
+
const metadata = windowMetadata(providerID, modelID);
|
|
556
622
|
if (!metadata) return undefined;
|
|
557
623
|
const rawContext = metadata.contextLimit ?? metadata.limit;
|
|
558
624
|
const promptOnlyDetected =
|
|
@@ -643,6 +709,7 @@ function lookupMetadataWithTagFallback(
|
|
|
643
709
|
/** Clear in-memory caches (for testing and the regression-recovery refetch). */
|
|
644
710
|
export function clearModelsDevCache(): void {
|
|
645
711
|
apiCache = null;
|
|
712
|
+
v2DraftModelLimits.clear();
|
|
646
713
|
apiLoadedAt = 0;
|
|
647
714
|
persistSeedLoaded = false;
|
|
648
715
|
}
|