@cortexkit/opencode-magic-context 0.49.79 → 0.49.81
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/{conflict-warning-hook-m8yezwdj.js → conflict-warning-hook-8s8r0c0v.js} +2 -2
- package/dist/{context-gb3gjahp.js → context-359s1ncq.js} +182 -75
- 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/hooks/magic-context/inject-compartments.d.ts +16 -0
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/{index-16h5fhem.js → index-177yv84k.js} +4 -6
- package/dist/{index-sy5wbbw6.js → index-1rx9bfrk.js} +7 -4
- package/dist/{index-2dadxknq.js → index-6sckwxjj.js} +13 -17
- package/dist/{index-tvkzkk4s.js → index-726b5jh5.js} +2 -2
- package/dist/{index-pzvdf7sr.js → index-7jefmy0g.js} +1 -1
- package/dist/{index-jfs6k0xk.js → index-9554nr2q.js} +6 -6
- 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-ma258g0g.js} +2 -2
- package/dist/{index-esqcwes7.js → index-nxxzeq4y.js} +4 -2
- package/dist/{index-ngwmx6nt.js → index-tky3j43e.js} +47 -5
- package/dist/{index-enpatj5k.js → index-v0epndb8.js} +7 -7
- package/dist/{index-f619wjj9.js → index-wwzamy3j.js} +2 -2
- package/dist/{index-m0tbtzqh.js → index-zpd4pxnp.js} +10 -5
- package/dist/index.js +18 -18
- package/dist/raw-ordinal-warmup-worker.js +2 -2
- package/dist/{recomp-orchestrator-jf60eef6.js → recomp-orchestrator-ar3xw3f4.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/conflict-detector.d.ts +6 -0
- package/dist/shared/conflict-detector.d.ts.map +1 -1
- package/dist/shared/conflict-fixer.d.ts +1 -0
- package/dist/shared/conflict-fixer.d.ts.map +1 -1
- 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-6kyqctnq.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-dpe94zcx.js} +186 -85
- 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 +10 -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-7t6fkpbb.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-1svqwm7m.js → server-a1zp7exh.js} +11 -8
- package/dist/v2/{server-9sf3qp02.js → server-bj779zmp.js} +1 -1
- 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-c0bwb0wa.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-548q5y55.js} +6 -6
- package/package.json +1 -1
- package/src/shared/conflict-detector.ts +35 -2
- package/src/shared/conflict-fixer.ts +10 -6
- package/src/shared/fold-render-lock-fence.test.ts +2 -0
- package/src/shared/models-dev-cache.test.ts +67 -1
- package/src/shared/models-dev-cache.ts +71 -4
|
@@ -72,7 +72,7 @@ import {
|
|
|
72
72
|
sanitizeFtsQuery,
|
|
73
73
|
searchMemoriesFTS,
|
|
74
74
|
searchMemoriesFTSUnion
|
|
75
|
-
} from "./server-
|
|
75
|
+
} from "./server-25qtxt4d.js";
|
|
76
76
|
import {
|
|
77
77
|
ModuleMemoryAuthorityError2,
|
|
78
78
|
getMemoriesByProject2,
|
|
@@ -81,7 +81,7 @@ import {
|
|
|
81
81
|
} from "./server-jjvbk92s.js";
|
|
82
82
|
import {
|
|
83
83
|
ensureMemoryEmbeddings2
|
|
84
|
-
} from "./server-
|
|
84
|
+
} from "./server-x8ksqcw7.js";
|
|
85
85
|
import {
|
|
86
86
|
MESSAGE_FTS_SESSION_FILTER_SQL,
|
|
87
87
|
withMessageFtsSessionFilter
|
|
@@ -2471,17 +2471,19 @@ async function getSemanticScores(args) {
|
|
|
2471
2471
|
if (!args.queryEmbedding || args.memories.length === 0 || !args.queryModelId || args.queryModelId === "off") {
|
|
2472
2472
|
return semanticScores;
|
|
2473
2473
|
}
|
|
2474
|
+
const expectedEmbedding = { modelId: args.queryModelId, generation: args.queryGeneration };
|
|
2474
2475
|
if (!args.workspace?.isWorkspaced) {
|
|
2475
2476
|
const cachedEmbeddings = getProjectEmbeddings2(args.db, args.projectPath, args.queryModelId);
|
|
2476
2477
|
const embeddings = args.backfillMemoryEmbeddings === false ? cachedEmbeddings : await ensureMemoryEmbeddings2({
|
|
2477
2478
|
db: args.db,
|
|
2478
2479
|
projectIdentity: args.projectPath,
|
|
2479
2480
|
memories: args.memories,
|
|
2480
|
-
existingEmbeddings: cachedEmbeddings
|
|
2481
|
+
existingEmbeddings: cachedEmbeddings,
|
|
2482
|
+
expectedEmbedding
|
|
2481
2483
|
});
|
|
2482
2484
|
for (const memory of args.memories) {
|
|
2483
2485
|
const memoryEmbedding = embeddings.get(memory.id);
|
|
2484
|
-
if (!memoryEmbedding) {
|
|
2486
|
+
if (!memoryEmbedding || memoryEmbedding.modelId !== args.queryModelId) {
|
|
2485
2487
|
continue;
|
|
2486
2488
|
}
|
|
2487
2489
|
semanticScores.set(memory.id, normalizeCosineScore(cosineSimilarity(args.queryEmbedding, memoryEmbedding.embedding)));
|
|
@@ -2505,7 +2507,8 @@ async function getSemanticScores(args) {
|
|
|
2505
2507
|
db: args.db,
|
|
2506
2508
|
projectIdentity: args.projectPath,
|
|
2507
2509
|
memories: ownMemories,
|
|
2508
|
-
existingEmbeddings: ownEmbeddings
|
|
2510
|
+
existingEmbeddings: ownEmbeddings,
|
|
2511
|
+
expectedEmbedding
|
|
2509
2512
|
});
|
|
2510
2513
|
}
|
|
2511
2514
|
for (const identity of workspace.identities) {
|
|
@@ -2633,6 +2636,7 @@ async function searchMemories(args) {
|
|
|
2633
2636
|
backfillMemoryEmbeddings: args.backfillMemoryEmbeddings,
|
|
2634
2637
|
queryEmbedding: args.queryEmbedding,
|
|
2635
2638
|
queryModelId: args.queryModelId,
|
|
2639
|
+
queryGeneration: args.queryGeneration,
|
|
2636
2640
|
workspace: args.workspace
|
|
2637
2641
|
});
|
|
2638
2642
|
const sourceNameByMemoryId = sourceNamesForSearchMemories({
|
|
@@ -3535,6 +3539,7 @@ async function unifiedSearch2(db, sessionId, projectPath, query, options = {}) {
|
|
|
3535
3539
|
memoryEnabled: true,
|
|
3536
3540
|
queryEmbedding,
|
|
3537
3541
|
queryModelId: embeddingModelId && embeddingModelId !== "off" ? embeddingModelId : null,
|
|
3542
|
+
queryGeneration: queryContract?.generation ?? embeddingSnapshot?.generation,
|
|
3538
3543
|
workspace,
|
|
3539
3544
|
visibleMemoryIds: options.visibleMemoryIds,
|
|
3540
3545
|
backfillMemoryEmbeddings: options.backfillMemoryEmbeddings,
|
|
@@ -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.81",
|
|
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-dpe94zcx.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-a1zp7exh.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-726b5jh5.js";
|
|
4
|
+
import"./index-wwzamy3j.js";
|
|
5
|
+
import"./index-1rx9bfrk.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,6 +1,7 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
1
2
|
import { homedir } from "node:os";
|
|
2
3
|
import { join } from "node:path";
|
|
3
|
-
import { readJsoncFile } from "./jsonc-parser";
|
|
4
|
+
import { parseJsonc, readJsoncFile } from "./jsonc-parser";
|
|
4
5
|
import { log } from "./logger";
|
|
5
6
|
import { getOpenCodeConfigDirs, getOpenCodeGlobalConfigDir } from "./opencode-config-dir";
|
|
6
7
|
import type { OpenCodeHostGeneration } from "./opencode-db-path";
|
|
@@ -8,6 +9,7 @@ import type { OpenCodeHostGeneration } from "./opencode-db-path";
|
|
|
8
9
|
interface OpenCodeConfig {
|
|
9
10
|
compaction?: {
|
|
10
11
|
auto?: boolean;
|
|
12
|
+
background?: boolean;
|
|
11
13
|
prune?: boolean;
|
|
12
14
|
keep?: { tokens?: number };
|
|
13
15
|
buffer?: number;
|
|
@@ -461,18 +463,20 @@ type CompactionBlock = NonNullable<OpenCodeConfig["compaction"]>;
|
|
|
461
463
|
function readCompactionFromConfigFiles(
|
|
462
464
|
directory: string,
|
|
463
465
|
hostGeneration: OpenCodeHostGeneration,
|
|
466
|
+
readConfig = readJsoncFile<OpenCodeConfig>,
|
|
464
467
|
): CompactionBlock {
|
|
465
468
|
const merged: CompactionBlock = {};
|
|
466
469
|
for (const filePath of openCodeConfigFileChain(directory, hostGeneration)) {
|
|
467
470
|
let block: CompactionBlock | undefined;
|
|
468
471
|
try {
|
|
469
|
-
block =
|
|
472
|
+
block = readConfig(filePath)?.compaction;
|
|
470
473
|
} catch {
|
|
471
474
|
// Intentional: each config read is best-effort. An unreadable file
|
|
472
475
|
// leaves the chain inconclusive rather than failing detection.
|
|
473
476
|
}
|
|
474
477
|
if (!block || typeof block !== "object") continue;
|
|
475
478
|
if (block.auto !== undefined) merged.auto = block.auto;
|
|
479
|
+
if (block.background !== undefined) merged.background = block.background;
|
|
476
480
|
if (block.prune !== undefined) merged.prune = block.prune;
|
|
477
481
|
if (block.buffer !== undefined) merged.buffer = block.buffer;
|
|
478
482
|
if (block.keep !== undefined) merged.keep = { ...merged.keep, ...block.keep };
|
|
@@ -480,6 +484,35 @@ function readCompactionFromConfigFiles(
|
|
|
480
484
|
return merged;
|
|
481
485
|
}
|
|
482
486
|
|
|
487
|
+
/** File-based input to doctor's advisory finding; never used to block plugin boot. */
|
|
488
|
+
export function readOpenCode2BackgroundCompaction(directory: string): {
|
|
489
|
+
enabled: boolean;
|
|
490
|
+
backgroundSource: string | undefined;
|
|
491
|
+
unreadable: string[];
|
|
492
|
+
} {
|
|
493
|
+
let backgroundSource: string | undefined;
|
|
494
|
+
const unreadable: string[] = [];
|
|
495
|
+
const compaction = readCompactionFromConfigFiles(directory, "v2", (path) => {
|
|
496
|
+
try {
|
|
497
|
+
const text = readFileSync(path, "utf-8").replace(/^\uFEFF/, "");
|
|
498
|
+
const config = parseJsonc<OpenCodeConfig>(text);
|
|
499
|
+
if (!config || typeof config !== "object" || Array.isArray(config)) {
|
|
500
|
+
throw new Error("Expected an OpenCode config object");
|
|
501
|
+
}
|
|
502
|
+
if (config.compaction?.background !== undefined) backgroundSource = path;
|
|
503
|
+
return config;
|
|
504
|
+
} catch (error) {
|
|
505
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") unreadable.push(path);
|
|
506
|
+
return null;
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
return {
|
|
510
|
+
enabled: compaction.auto !== false && compaction.background !== false,
|
|
511
|
+
backgroundSource,
|
|
512
|
+
unreadable,
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
|
|
483
516
|
/** Whether a merged block carries any key this host generation acts on. */
|
|
484
517
|
function isRelevantCompactionBlock(
|
|
485
518
|
block: CompactionBlock,
|
|
@@ -69,6 +69,15 @@ function resolveUserOpenCodeConfigPath(): string {
|
|
|
69
69
|
return paths.configJson;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
export function projectOpenCodeConfigPaths(directory: string): string[] {
|
|
73
|
+
return [
|
|
74
|
+
join(directory, ".opencode", "opencode.jsonc"),
|
|
75
|
+
join(directory, ".opencode", "opencode.json"),
|
|
76
|
+
join(directory, "opencode.jsonc"),
|
|
77
|
+
join(directory, "opencode.json"),
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
|
|
72
81
|
function collectOpenCodeConfigPaths(directory: string): string[] {
|
|
73
82
|
const paths = new Set<string>();
|
|
74
83
|
const userConfig = resolveUserOpenCodeConfigPath();
|
|
@@ -77,12 +86,7 @@ function collectOpenCodeConfigPaths(directory: string): string[] {
|
|
|
77
86
|
paths.add(userConfig);
|
|
78
87
|
}
|
|
79
88
|
|
|
80
|
-
for (const filePath of
|
|
81
|
-
join(directory, ".opencode", "opencode.jsonc"),
|
|
82
|
-
join(directory, ".opencode", "opencode.json"),
|
|
83
|
-
join(directory, "opencode.jsonc"),
|
|
84
|
-
join(directory, "opencode.json"),
|
|
85
|
-
]) {
|
|
89
|
+
for (const filePath of projectOpenCodeConfigPaths(directory)) {
|
|
86
90
|
if (existsSync(filePath)) {
|
|
87
91
|
paths.add(filePath);
|
|
88
92
|
}
|
|
@@ -27,8 +27,10 @@ for (const [host, path, functions] of [
|
|
|
27
27
|
const inspected: string[] = [];
|
|
28
28
|
const violations: string[] = [];
|
|
29
29
|
function visit(node: ts.Node): void {
|
|
30
|
+
// Overload signatures have no body; only the implementation is checked.
|
|
30
31
|
if (
|
|
31
32
|
ts.isFunctionDeclaration(node) &&
|
|
33
|
+
node.body &&
|
|
32
34
|
node.name &&
|
|
33
35
|
functions.some((name) => name === node.name?.text)
|
|
34
36
|
) {
|
|
@@ -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
|
}
|