@cortexkit/opencode-magic-context 0.49.38 → 0.49.40
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 +1 -1
- package/dist/{context-3vgc2dmf.js → context-8ktz4j2b.js} +35 -30
- package/dist/features/magic-context/auto-search-diagnostics.d.ts +3 -1
- package/dist/features/magic-context/auto-search-diagnostics.d.ts.map +1 -1
- package/dist/features/magic-context/search.d.ts.map +1 -1
- package/dist/{index-2rs7912w.js → index-9z4d2ha0.js} +34 -1
- package/dist/{index-7rn2x4gq.js → index-gfd41hm4.js} +10 -10
- package/dist/{index-dz48h1wx.js → index-hb76vdmm.js} +11 -5
- package/dist/{index-dfdg2cgg.js → index-hf771sk4.js} +7 -7
- package/dist/{index-8wztpf82.js → index-j5qma52p.js} +10 -9
- package/dist/{index-ys7j6679.js → index-m8v7nqgp.js} +1 -1
- package/dist/{index-4ks89h5a.js → index-ryz4pdvf.js} +1 -1
- package/dist/{index-9tdvbdv1.js → index-tr6vcwt0.js} +1 -1
- package/dist/{index-pp8vdn01.js → index-wk7x13qv.js} +2 -2
- package/dist/{index-prw8apnc.js → index-z7etaphs.js} +2 -2
- package/dist/index.js +13 -13
- package/dist/{message-index-bounded-wfk6aqxk.js → message-index-bounded-jqm3ezva.js} +1 -1
- package/dist/raw-ordinal-warmup-worker.js +3 -3
- package/dist/{recomp-orchestrator-wk509qkp.js → recomp-orchestrator-34mh19vm.js} +3 -3
- package/dist/{render-h1qarr8a.js → render-gqdq6t7f.js} +1 -1
- package/dist/{search-archive-q79hyqxs.js → search-archive-kfwpk73t.js} +2 -2
- package/dist/{search-v2twazx5.js → search-vqkmmy9c.js} +3 -3
- package/dist/shared/search-text.d.ts +2 -0
- package/dist/shared/search-text.d.ts.map +1 -1
- package/dist/{transform-postprocess-phase-4gj0mtcg.js → transform-postprocess-phase-61f7t9xq.js} +4 -4
- package/dist/v2/auto-search-worker.js +1 -1
- package/dist/v2/{context-m1te41ec.js → context-rdch08me.js} +33 -28
- package/dist/v2/fold/native-replay.d.ts.map +1 -1
- package/dist/v2/{message-index-bounded-w14496s9.js → message-index-bounded-dgd8a2x1.js} +1 -1
- package/dist/v2/raw-ordinal-warmup-worker.js +3 -3
- package/dist/v2/{recomp-orchestrator-9cjk6aej.js → recomp-orchestrator-x0r6sy3a.js} +2 -2
- package/dist/v2/{render-5dz1knf2.js → render-yyv8nv4p.js} +1 -1
- package/dist/v2/{search-archive-z6z9jqwf.js → search-archive-gagdnrb3.js} +2 -2
- package/dist/v2/{search-2n9zsqrm.js → search-cb1kdgqw.js} +2 -2
- package/dist/v2/{server-a9w5f0yw.js → server-2d01821b.js} +1 -1
- package/dist/v2/{server-e51xmr4d.js → server-2tp6y1qs.js} +2 -2
- package/dist/v2/{server-5by3vdzs.js → server-405ap0b0.js} +1 -1
- package/dist/v2/{server-dfq5vb8j.js → server-dt9b00ja.js} +34 -1
- package/dist/v2/{server-r0gdhz69.js → server-r4mmc670.js} +12 -6
- package/dist/v2/server.js +2 -2
- package/dist/v2/{v2-archive-reader-z7wr42ry.js → v2-archive-reader-2rv5dz7k.js} +1 -1
- package/dist/v2/{wrapup-orchestrator-j1v62bkj.js → wrapup-orchestrator-f8w3kcjf.js} +2 -2
- package/dist/{v2-archive-reader-028z6kck.js → v2-archive-reader-4hz9pnmy.js} +1 -1
- package/dist/{wrapup-orchestrator-xg9avt2p.js → wrapup-orchestrator-7dxwer1p.js} +4 -4
- package/package.json +1 -1
- package/src/shared/search-text.test.ts +36 -1
- package/src/shared/search-text.ts +48 -0
|
@@ -1,7 +1,42 @@
|
|
|
1
1
|
import { expect, test } from "bun:test";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
cleanSearchText,
|
|
4
|
+
hintKeywordRelevance,
|
|
5
|
+
keywordRelevance,
|
|
6
|
+
matchedSearchSnippet,
|
|
7
|
+
} from "./search-text";
|
|
3
8
|
import { removeSystemReminders } from "./system-directive";
|
|
4
9
|
|
|
10
|
+
test("hint scoring preserves exact English and other space-separated keyword scores", () => {
|
|
11
|
+
const cases: Array<[string, string, number]> = [
|
|
12
|
+
["explain historian cache wiring", "cache icons", 0.2],
|
|
13
|
+
["historian cache wiring", "historian cache wiring details", 0.8000000000000002],
|
|
14
|
+
["please explain cache wiring to me", "cache wiring", 0.5333333333333333],
|
|
15
|
+
["CACHE cache cache_timeout", "cache_timeout", 0.4],
|
|
16
|
+
["how are you", "how are you", 0],
|
|
17
|
+
["historian cache", "<task>historian cache</task>", 0],
|
|
18
|
+
["résumé über prüfen", "über prüfen", 0.5333333333333333],
|
|
19
|
+
["память кеш", "кеш", 0.4],
|
|
20
|
+
["ذاكرة تخزين", "تخزين", 0.4],
|
|
21
|
+
];
|
|
22
|
+
for (const [query, content, expected] of cases) {
|
|
23
|
+
expect(keywordRelevance(query, content)).toBe(expected);
|
|
24
|
+
expect(hintKeywordRelevance(query, content)).toBe(expected);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("only hint scoring splits unspaced CJK runs into overlapping character bigrams", () => {
|
|
29
|
+
expect(keywordRelevance("MC_Maze 残差怎样汇总?", "MC_Maze 残差按种子汇总。")).toBe(0.4);
|
|
30
|
+
expect(hintKeywordRelevance("残差", "残留")).toBe(0);
|
|
31
|
+
expect(hintKeywordRelevance("差", "残差")).toBe(0.8);
|
|
32
|
+
expect(hintKeywordRelevance("𠮷野家", "𠮷野川")).toBe(0.8);
|
|
33
|
+
expect(hintKeywordRelevance("かながき", "かながきです")).toBe(0.8);
|
|
34
|
+
expect(hintKeywordRelevance("カタカナ", "カタカナです")).toBe(0.8);
|
|
35
|
+
expect(hintKeywordRelevance("프로젝트캐시", "프로젝트의캐시")).toBe(0.8);
|
|
36
|
+
expect(hintKeywordRelevance("cache残差", "cache残差按种子汇总")).toBe(0.8);
|
|
37
|
+
expect(hintKeywordRelevance("差", "<task>残差</task> unrelated")).toBe(0);
|
|
38
|
+
});
|
|
39
|
+
|
|
5
40
|
test("nested reminder contents stay quarantined through the outer closing tag", () => {
|
|
6
41
|
expect(
|
|
7
42
|
removeSystemReminders(
|
|
@@ -35,6 +35,54 @@ export function keywordRelevance(query: string, content: string): number {
|
|
|
35
35
|
return (0.8 * needles.filter((term) => words.has(term)).length) / needles.length;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
const CJK_RUN = /^[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]+$/u;
|
|
39
|
+
const CJK_RUN_SPLIT = /([\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]+)/u;
|
|
40
|
+
|
|
41
|
+
function hintTerms(text: string): string[] {
|
|
42
|
+
return [
|
|
43
|
+
...new Set(
|
|
44
|
+
terms(text)
|
|
45
|
+
.flatMap((term) => term.split(CJK_RUN_SPLIT))
|
|
46
|
+
.filter((term) => term.length > 0 && !QUERY_STOP_WORDS.has(term)),
|
|
47
|
+
),
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function characterBigrams(run: string): string[] {
|
|
52
|
+
const characters = [...run];
|
|
53
|
+
return characters.length === 1
|
|
54
|
+
? characters
|
|
55
|
+
: characters.slice(1).map((character, index) => characters[index] + character);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Match unspaced clauses for hints without changing retrieval or snippet scoring. */
|
|
59
|
+
export function hintKeywordRelevance(query: string, content: string): number {
|
|
60
|
+
const needles = hintTerms(query);
|
|
61
|
+
if (needles.length === 0) return 0;
|
|
62
|
+
const words = new Set(hintTerms(cleanSearchText(content)));
|
|
63
|
+
const runs = [...words].filter((word) => CJK_RUN.test(word));
|
|
64
|
+
const bigrams = new Set(runs.flatMap(characterBigrams));
|
|
65
|
+
let matched = 0;
|
|
66
|
+
for (const needle of needles) {
|
|
67
|
+
if (!CJK_RUN.test(needle)) {
|
|
68
|
+
matched += Number(words.has(needle));
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const grams = characterBigrams(needle);
|
|
72
|
+
if ([...needle].length === 1) {
|
|
73
|
+
matched += Number(runs.some((run) => run.includes(needle)));
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
// Count each clause as one term so filler bigrams across word boundaries
|
|
77
|
+
// do not dilute it; require half coverage so shared function words alone do not pass.
|
|
78
|
+
matched += Math.min(
|
|
79
|
+
1,
|
|
80
|
+
grams.filter((gram) => bigrams.has(gram)).length / Math.ceil(grams.length / 2),
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
return (0.8 * matched) / needles.length;
|
|
84
|
+
}
|
|
85
|
+
|
|
38
86
|
/** Pick the densest matching passage before compression can discard the matched words. */
|
|
39
87
|
export function matchedSearchSnippet(content: string, query: string, cap = 220): string {
|
|
40
88
|
const text = cleanSearchText(content);
|